1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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_Tss
; use Exp_Tss
;
33 with Exp_Util
; use Exp_Util
;
34 with Fname
; use Fname
;
35 with Freeze
; use Freeze
;
37 with Lib
.Xref
; use Lib
.Xref
;
38 with Nlists
; use Nlists
;
39 with Output
; use Output
;
41 with Rtsfind
; use Rtsfind
;
42 with Scans
; use Scans
;
45 with Sem_Attr
; use Sem_Attr
;
46 with Sem_Ch6
; use Sem_Ch6
;
47 with Sem_Ch8
; use Sem_Ch8
;
48 with Sem_Eval
; use Sem_Eval
;
49 with Sem_Res
; use Sem_Res
;
50 with Sem_Type
; use Sem_Type
;
51 with Sinfo
; use Sinfo
;
52 with Sinput
; use Sinput
;
53 with Snames
; use Snames
;
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 package body Sem_Util
is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 function Build_Component_Subtype
73 T
: Entity_Id
) return Node_Id
;
74 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
75 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
76 -- Loc is the source location, T is the original subtype.
78 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
79 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
80 -- with discriminants whose default values are static, examine only the
81 -- components in the selected variant to determine whether all of them
84 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
85 -- T is a derived tagged type. Check whether the type extension is null.
86 -- If the parent type is fully initialized, T can be treated as such.
88 ------------------------------
89 -- Abstract_Interface_List --
90 ------------------------------
92 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
96 if Is_Concurrent_Type
(Typ
) then
98 -- If we are dealing with a synchronized subtype, go to the base
99 -- type, whose declaration has the interface list.
101 -- Shouldn't this be Declaration_Node???
103 Nod
:= Parent
(Base_Type
(Typ
));
105 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
106 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
107 Nod
:= Type_Definition
(Parent
(Typ
));
109 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
110 if Present
(Full_View
(Typ
)) then
111 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
113 -- If the full-view is not available we cannot do anything else
114 -- here (the source has errors).
120 -- Support for generic formals with interfaces is still missing ???
122 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
127 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
131 elsif Ekind
(Typ
) = E_Record_Subtype
then
132 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
134 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
136 -- Recurse, because parent may still be a private extension
138 return Abstract_Interface_List
(Etype
(Full_View
(Typ
)));
140 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
141 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
142 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
144 Nod
:= Type_Definition
(Parent
(Typ
));
148 return Interface_List
(Nod
);
149 end Abstract_Interface_List
;
151 --------------------------------
152 -- Add_Access_Type_To_Process --
153 --------------------------------
155 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
159 Ensure_Freeze_Node
(E
);
160 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
164 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
168 end Add_Access_Type_To_Process
;
170 ----------------------------
171 -- Add_Global_Declaration --
172 ----------------------------
174 procedure Add_Global_Declaration
(N
: Node_Id
) is
175 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
178 if No
(Declarations
(Aux_Node
)) then
179 Set_Declarations
(Aux_Node
, New_List
);
182 Append_To
(Declarations
(Aux_Node
), N
);
184 end Add_Global_Declaration
;
186 -----------------------
187 -- Alignment_In_Bits --
188 -----------------------
190 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
192 return Alignment
(E
) * System_Storage_Unit
;
193 end Alignment_In_Bits
;
195 -----------------------------------------
196 -- Apply_Compile_Time_Constraint_Error --
197 -----------------------------------------
199 procedure Apply_Compile_Time_Constraint_Error
202 Reason
: RT_Exception_Code
;
203 Ent
: Entity_Id
:= Empty
;
204 Typ
: Entity_Id
:= Empty
;
205 Loc
: Source_Ptr
:= No_Location
;
206 Rep
: Boolean := True;
207 Warn
: Boolean := False)
209 Stat
: constant Boolean := Is_Static_Expression
(N
);
220 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
226 -- Now we replace the node by an N_Raise_Constraint_Error node
227 -- This does not need reanalyzing, so set it as analyzed now.
230 Make_Raise_Constraint_Error
(Sloc
(N
),
232 Set_Analyzed
(N
, True);
234 Set_Raises_Constraint_Error
(N
);
236 -- If the original expression was marked as static, the result is
237 -- still marked as static, but the Raises_Constraint_Error flag is
238 -- always set so that further static evaluation is not attempted.
241 Set_Is_Static_Expression
(N
);
243 end Apply_Compile_Time_Constraint_Error
;
245 --------------------------
246 -- Build_Actual_Subtype --
247 --------------------------
249 function Build_Actual_Subtype
251 N
: Node_Or_Entity_Id
) return Node_Id
254 -- Normally Sloc (N), but may point to corresponding body in some cases
256 Constraints
: List_Id
;
262 Disc_Type
: Entity_Id
;
268 if Nkind
(N
) = N_Defining_Identifier
then
269 Obj
:= New_Reference_To
(N
, Loc
);
271 -- If this is a formal parameter of a subprogram declaration, and
272 -- we are compiling the body, we want the declaration for the
273 -- actual subtype to carry the source position of the body, to
274 -- prevent anomalies in gdb when stepping through the code.
276 if Is_Formal
(N
) then
278 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
280 if Nkind
(Decl
) = N_Subprogram_Declaration
281 and then Present
(Corresponding_Body
(Decl
))
283 Loc
:= Sloc
(Corresponding_Body
(Decl
));
292 if Is_Array_Type
(T
) then
293 Constraints
:= New_List
;
294 for J
in 1 .. Number_Dimensions
(T
) loop
296 -- Build an array subtype declaration with the nominal subtype and
297 -- the bounds of the actual. Add the declaration in front of the
298 -- local declarations for the subprogram, for analysis before any
299 -- reference to the formal in the body.
302 Make_Attribute_Reference
(Loc
,
304 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
305 Attribute_Name
=> Name_First
,
306 Expressions
=> New_List
(
307 Make_Integer_Literal
(Loc
, J
)));
310 Make_Attribute_Reference
(Loc
,
312 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
313 Attribute_Name
=> Name_Last
,
314 Expressions
=> New_List
(
315 Make_Integer_Literal
(Loc
, J
)));
317 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
320 -- If the type has unknown discriminants there is no constrained
321 -- subtype to build. This is never called for a formal or for a
322 -- lhs, so returning the type is ok ???
324 elsif Has_Unknown_Discriminants
(T
) then
328 Constraints
:= New_List
;
330 if Is_Private_Type
(T
) and then No
(Full_View
(T
)) then
332 -- Type is a generic derived type. Inherit discriminants from
335 Disc_Type
:= Etype
(Base_Type
(T
));
340 Discr
:= First_Discriminant
(Disc_Type
);
341 while Present
(Discr
) loop
342 Append_To
(Constraints
,
343 Make_Selected_Component
(Loc
,
345 Duplicate_Subexpr_No_Checks
(Obj
),
346 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
347 Next_Discriminant
(Discr
);
352 Make_Defining_Identifier
(Loc
,
353 Chars
=> New_Internal_Name
('S'));
354 Set_Is_Internal
(Subt
);
357 Make_Subtype_Declaration
(Loc
,
358 Defining_Identifier
=> Subt
,
359 Subtype_Indication
=>
360 Make_Subtype_Indication
(Loc
,
361 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
363 Make_Index_Or_Discriminant_Constraint
(Loc
,
364 Constraints
=> Constraints
)));
366 Mark_Rewrite_Insertion
(Decl
);
368 end Build_Actual_Subtype
;
370 ---------------------------------------
371 -- Build_Actual_Subtype_Of_Component --
372 ---------------------------------------
374 function Build_Actual_Subtype_Of_Component
376 N
: Node_Id
) return Node_Id
378 Loc
: constant Source_Ptr
:= Sloc
(N
);
379 P
: constant Node_Id
:= Prefix
(N
);
382 Indx_Type
: Entity_Id
;
384 Deaccessed_T
: Entity_Id
;
385 -- This is either a copy of T, or if T is an access type, then it is
386 -- the directly designated type of this access type.
388 function Build_Actual_Array_Constraint
return List_Id
;
389 -- If one or more of the bounds of the component depends on
390 -- discriminants, build actual constraint using the discriminants
393 function Build_Actual_Record_Constraint
return List_Id
;
394 -- Similar to previous one, for discriminated components constrained
395 -- by the discriminant of the enclosing object.
397 -----------------------------------
398 -- Build_Actual_Array_Constraint --
399 -----------------------------------
401 function Build_Actual_Array_Constraint
return List_Id
is
402 Constraints
: constant List_Id
:= New_List
;
410 Indx
:= First_Index
(Deaccessed_T
);
411 while Present
(Indx
) loop
412 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
413 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
415 if Denotes_Discriminant
(Old_Lo
) then
417 Make_Selected_Component
(Loc
,
418 Prefix
=> New_Copy_Tree
(P
),
419 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
422 Lo
:= New_Copy_Tree
(Old_Lo
);
424 -- The new bound will be reanalyzed in the enclosing
425 -- declaration. For literal bounds that come from a type
426 -- declaration, the type of the context must be imposed, so
427 -- insure that analysis will take place. For non-universal
428 -- types this is not strictly necessary.
430 Set_Analyzed
(Lo
, False);
433 if Denotes_Discriminant
(Old_Hi
) then
435 Make_Selected_Component
(Loc
,
436 Prefix
=> New_Copy_Tree
(P
),
437 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
440 Hi
:= New_Copy_Tree
(Old_Hi
);
441 Set_Analyzed
(Hi
, False);
444 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
449 end Build_Actual_Array_Constraint
;
451 ------------------------------------
452 -- Build_Actual_Record_Constraint --
453 ------------------------------------
455 function Build_Actual_Record_Constraint
return List_Id
is
456 Constraints
: constant List_Id
:= New_List
;
461 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
462 while Present
(D
) loop
463 if Denotes_Discriminant
(Node
(D
)) then
464 D_Val
:= Make_Selected_Component
(Loc
,
465 Prefix
=> New_Copy_Tree
(P
),
466 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
469 D_Val
:= New_Copy_Tree
(Node
(D
));
472 Append
(D_Val
, Constraints
);
477 end Build_Actual_Record_Constraint
;
479 -- Start of processing for Build_Actual_Subtype_Of_Component
482 if In_Default_Expression
then
485 elsif Nkind
(N
) = N_Explicit_Dereference
then
486 if Is_Composite_Type
(T
)
487 and then not Is_Constrained
(T
)
488 and then not (Is_Class_Wide_Type
(T
)
489 and then Is_Constrained
(Root_Type
(T
)))
490 and then not Has_Unknown_Discriminants
(T
)
492 -- If the type of the dereference is already constrained, it
493 -- is an actual subtype.
495 if Is_Array_Type
(Etype
(N
))
496 and then Is_Constrained
(Etype
(N
))
500 Remove_Side_Effects
(P
);
501 return Build_Actual_Subtype
(T
, N
);
508 if Ekind
(T
) = E_Access_Subtype
then
509 Deaccessed_T
:= Designated_Type
(T
);
514 if Ekind
(Deaccessed_T
) = E_Array_Subtype
then
515 Id
:= First_Index
(Deaccessed_T
);
516 while Present
(Id
) loop
517 Indx_Type
:= Underlying_Type
(Etype
(Id
));
519 if Denotes_Discriminant
(Type_Low_Bound
(Indx_Type
)) or else
520 Denotes_Discriminant
(Type_High_Bound
(Indx_Type
))
522 Remove_Side_Effects
(P
);
524 Build_Component_Subtype
(
525 Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
531 elsif Is_Composite_Type
(Deaccessed_T
)
532 and then Has_Discriminants
(Deaccessed_T
)
533 and then not Has_Unknown_Discriminants
(Deaccessed_T
)
535 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
536 while Present
(D
) loop
537 if Denotes_Discriminant
(Node
(D
)) then
538 Remove_Side_Effects
(P
);
540 Build_Component_Subtype
(
541 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
548 -- If none of the above, the actual and nominal subtypes are the same
551 end Build_Actual_Subtype_Of_Component
;
553 -----------------------------
554 -- Build_Component_Subtype --
555 -----------------------------
557 function Build_Component_Subtype
560 T
: Entity_Id
) return Node_Id
566 -- Unchecked_Union components do not require component subtypes
568 if Is_Unchecked_Union
(T
) then
573 Make_Defining_Identifier
(Loc
,
574 Chars
=> New_Internal_Name
('S'));
575 Set_Is_Internal
(Subt
);
578 Make_Subtype_Declaration
(Loc
,
579 Defining_Identifier
=> Subt
,
580 Subtype_Indication
=>
581 Make_Subtype_Indication
(Loc
,
582 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
584 Make_Index_Or_Discriminant_Constraint
(Loc
,
587 Mark_Rewrite_Insertion
(Decl
);
589 end Build_Component_Subtype
;
591 ---------------------------
592 -- Build_Default_Subtype --
593 ---------------------------
595 function Build_Default_Subtype
597 N
: Node_Id
) return Entity_Id
599 Loc
: constant Source_Ptr
:= Sloc
(N
);
603 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
607 Disc
:= First_Discriminant
(T
);
609 if No
(Discriminant_Default_Value
(Disc
)) then
614 Act
: constant Entity_Id
:=
615 Make_Defining_Identifier
(Loc
,
616 Chars
=> New_Internal_Name
('S'));
618 Constraints
: constant List_Id
:= New_List
;
622 while Present
(Disc
) loop
623 Append_To
(Constraints
,
624 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
625 Next_Discriminant
(Disc
);
629 Make_Subtype_Declaration
(Loc
,
630 Defining_Identifier
=> Act
,
631 Subtype_Indication
=>
632 Make_Subtype_Indication
(Loc
,
633 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
635 Make_Index_Or_Discriminant_Constraint
(Loc
,
636 Constraints
=> Constraints
)));
638 Insert_Action
(N
, Decl
);
642 end Build_Default_Subtype
;
644 --------------------------------------------
645 -- Build_Discriminal_Subtype_Of_Component --
646 --------------------------------------------
648 function Build_Discriminal_Subtype_Of_Component
649 (T
: Entity_Id
) return Node_Id
651 Loc
: constant Source_Ptr
:= Sloc
(T
);
655 function Build_Discriminal_Array_Constraint
return List_Id
;
656 -- If one or more of the bounds of the component depends on
657 -- discriminants, build actual constraint using the discriminants
660 function Build_Discriminal_Record_Constraint
return List_Id
;
661 -- Similar to previous one, for discriminated components constrained
662 -- by the discriminant of the enclosing object.
664 ----------------------------------------
665 -- Build_Discriminal_Array_Constraint --
666 ----------------------------------------
668 function Build_Discriminal_Array_Constraint
return List_Id
is
669 Constraints
: constant List_Id
:= New_List
;
677 Indx
:= First_Index
(T
);
678 while Present
(Indx
) loop
679 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
680 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
682 if Denotes_Discriminant
(Old_Lo
) then
683 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
686 Lo
:= New_Copy_Tree
(Old_Lo
);
689 if Denotes_Discriminant
(Old_Hi
) then
690 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
693 Hi
:= New_Copy_Tree
(Old_Hi
);
696 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
701 end Build_Discriminal_Array_Constraint
;
703 -----------------------------------------
704 -- Build_Discriminal_Record_Constraint --
705 -----------------------------------------
707 function Build_Discriminal_Record_Constraint
return List_Id
is
708 Constraints
: constant List_Id
:= New_List
;
713 D
:= First_Elmt
(Discriminant_Constraint
(T
));
714 while Present
(D
) loop
715 if Denotes_Discriminant
(Node
(D
)) then
717 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
720 D_Val
:= New_Copy_Tree
(Node
(D
));
723 Append
(D_Val
, Constraints
);
728 end Build_Discriminal_Record_Constraint
;
730 -- Start of processing for Build_Discriminal_Subtype_Of_Component
733 if Ekind
(T
) = E_Array_Subtype
then
734 Id
:= First_Index
(T
);
735 while Present
(Id
) loop
736 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
737 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
739 return Build_Component_Subtype
740 (Build_Discriminal_Array_Constraint
, Loc
, T
);
746 elsif Ekind
(T
) = E_Record_Subtype
747 and then Has_Discriminants
(T
)
748 and then not Has_Unknown_Discriminants
(T
)
750 D
:= First_Elmt
(Discriminant_Constraint
(T
));
751 while Present
(D
) loop
752 if Denotes_Discriminant
(Node
(D
)) then
753 return Build_Component_Subtype
754 (Build_Discriminal_Record_Constraint
, Loc
, T
);
761 -- If none of the above, the actual and nominal subtypes are the same
764 end Build_Discriminal_Subtype_Of_Component
;
766 ------------------------------
767 -- Build_Elaboration_Entity --
768 ------------------------------
770 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
771 Loc
: constant Source_Ptr
:= Sloc
(N
);
773 Elab_Ent
: Entity_Id
;
775 procedure Set_Package_Name
(Ent
: Entity_Id
);
776 -- Given an entity, sets the fully qualified name of the entity in
777 -- Name_Buffer, with components separated by double underscores. This
778 -- is a recursive routine that climbs the scope chain to Standard.
780 ----------------------
781 -- Set_Package_Name --
782 ----------------------
784 procedure Set_Package_Name
(Ent
: Entity_Id
) is
786 if Scope
(Ent
) /= Standard_Standard
then
787 Set_Package_Name
(Scope
(Ent
));
790 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
792 Name_Buffer
(Name_Len
+ 1) := '_';
793 Name_Buffer
(Name_Len
+ 2) := '_';
794 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
795 Name_Len
:= Name_Len
+ Nam
'Length + 2;
799 Get_Name_String
(Chars
(Ent
));
801 end Set_Package_Name
;
803 -- Start of processing for Build_Elaboration_Entity
806 -- Ignore if already constructed
808 if Present
(Elaboration_Entity
(Spec_Id
)) then
812 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
813 -- name with dots replaced by double underscore. We have to manually
814 -- construct this name, since it will be elaborated in the outer scope,
815 -- and thus will not have the unit name automatically prepended.
817 Set_Package_Name
(Spec_Id
);
821 Name_Buffer
(Name_Len
+ 1) := '_';
822 Name_Buffer
(Name_Len
+ 2) := 'E';
823 Name_Len
:= Name_Len
+ 2;
825 -- Create elaboration flag
828 Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
829 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
832 Make_Object_Declaration
(Loc
,
833 Defining_Identifier
=> Elab_Ent
,
835 New_Occurrence_Of
(Standard_Boolean
, Loc
),
837 New_Occurrence_Of
(Standard_False
, Loc
));
839 Push_Scope
(Standard_Standard
);
840 Add_Global_Declaration
(Decl
);
843 -- Reset True_Constant indication, since we will indeed assign a value
844 -- to the variable in the binder main. We also kill the Current_Value
845 -- and Last_Assignment fields for the same reason.
847 Set_Is_True_Constant
(Elab_Ent
, False);
848 Set_Current_Value
(Elab_Ent
, Empty
);
849 Set_Last_Assignment
(Elab_Ent
, Empty
);
851 -- We do not want any further qualification of the name (if we did
852 -- not do this, we would pick up the name of the generic package
853 -- in the case of a library level generic instantiation).
855 Set_Has_Qualified_Name
(Elab_Ent
);
856 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
857 end Build_Elaboration_Entity
;
859 -----------------------------------
860 -- Cannot_Raise_Constraint_Error --
861 -----------------------------------
863 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
865 if Compile_Time_Known_Value
(Expr
) then
868 elsif Do_Range_Check
(Expr
) then
871 elsif Raises_Constraint_Error
(Expr
) then
879 when N_Expanded_Name
=>
882 when N_Selected_Component
=>
883 return not Do_Discriminant_Check
(Expr
);
885 when N_Attribute_Reference
=>
886 if Do_Overflow_Check
(Expr
) then
889 elsif No
(Expressions
(Expr
)) then
897 N
:= First
(Expressions
(Expr
));
898 while Present
(N
) loop
899 if Cannot_Raise_Constraint_Error
(N
) then
910 when N_Type_Conversion
=>
911 if Do_Overflow_Check
(Expr
)
912 or else Do_Length_Check
(Expr
)
913 or else Do_Tag_Check
(Expr
)
918 Cannot_Raise_Constraint_Error
(Expression
(Expr
));
921 when N_Unchecked_Type_Conversion
=>
922 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
925 if Do_Overflow_Check
(Expr
) then
929 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
936 if Do_Division_Check
(Expr
)
937 or else Do_Overflow_Check
(Expr
)
942 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
944 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
963 N_Op_Shift_Right_Arithmetic |
967 if Do_Overflow_Check
(Expr
) then
971 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
973 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
980 end Cannot_Raise_Constraint_Error
;
982 --------------------------
983 -- Check_Fully_Declared --
984 --------------------------
986 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
988 if Ekind
(T
) = E_Incomplete_Type
then
990 -- Ada 2005 (AI-50217): If the type is available through a limited
991 -- with_clause, verify that its full view has been analyzed.
993 if From_With_Type
(T
)
994 and then Present
(Non_Limited_View
(T
))
995 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
997 -- The non-limited view is fully declared
1002 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1005 elsif Has_Private_Component
(T
)
1006 and then not Is_Generic_Type
(Root_Type
(T
))
1007 and then not In_Default_Expression
1010 -- Special case: if T is the anonymous type created for a single
1011 -- task or protected object, use the name of the source object.
1013 if Is_Concurrent_Type
(T
)
1014 and then not Comes_From_Source
(T
)
1015 and then Nkind
(N
) = N_Object_Declaration
1017 Error_Msg_NE
("type of& has incomplete component", N
,
1018 Defining_Identifier
(N
));
1022 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1025 end Check_Fully_Declared
;
1027 -------------------------
1028 -- Check_Nested_Access --
1029 -------------------------
1031 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
1032 Scop
: constant Entity_Id
:= Current_Scope
;
1033 Current_Subp
: Entity_Id
;
1036 -- Currently only enabled for VM back-ends for efficiency, should we
1037 -- enable it more systematically ???
1039 if VM_Target
/= No_VM
1040 and then (Ekind
(Ent
) = E_Variable
1042 Ekind
(Ent
) = E_Constant
1044 Ekind
(Ent
) = E_Loop_Parameter
)
1045 and then Scope
(Ent
) /= Empty
1046 and then not Is_Library_Level_Entity
(Ent
)
1048 if Is_Subprogram
(Scop
)
1049 or else Is_Generic_Subprogram
(Scop
)
1050 or else Is_Entry
(Scop
)
1052 Current_Subp
:= Scop
;
1054 Current_Subp
:= Current_Subprogram
;
1057 if Enclosing_Subprogram
(Ent
) /= Current_Subp
then
1058 Set_Has_Up_Level_Access
(Ent
, True);
1061 end Check_Nested_Access
;
1063 ------------------------------------------
1064 -- Check_Potentially_Blocking_Operation --
1065 ------------------------------------------
1067 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
1070 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1071 -- When pragma Detect_Blocking is active, the run time will raise
1072 -- Program_Error. Here we only issue a warning, since we generally
1073 -- support the use of potentially blocking operations in the absence
1076 -- Indirect blocking through a subprogram call cannot be diagnosed
1077 -- statically without interprocedural analysis, so we do not attempt
1080 S
:= Scope
(Current_Scope
);
1081 while Present
(S
) and then S
/= Standard_Standard
loop
1082 if Is_Protected_Type
(S
) then
1084 ("potentially blocking operation in protected operation?", N
);
1091 end Check_Potentially_Blocking_Operation
;
1097 procedure Check_VMS
(Construct
: Node_Id
) is
1099 if not OpenVMS_On_Target
then
1101 ("this construct is allowed only in Open'V'M'S", Construct
);
1105 ---------------------------------
1106 -- Collect_Abstract_Interfaces --
1107 ---------------------------------
1109 procedure Collect_Abstract_Interfaces
1111 Ifaces_List
: out Elist_Id
;
1112 Exclude_Parent_Interfaces
: Boolean := False;
1113 Use_Full_View
: Boolean := True)
1115 procedure Add_Interface
(Iface
: Entity_Id
);
1116 -- Add the interface it if is not already in the list
1118 procedure Collect
(Typ
: Entity_Id
);
1119 -- Subsidiary subprogram used to traverse the whole list
1120 -- of directly and indirectly implemented interfaces
1122 function Interface_Present_In_Parent
1124 Iface
: Entity_Id
) return Boolean;
1125 -- Typ must be a tagged record type/subtype and Iface must be an
1126 -- abstract interface type. This function is used to check if Typ
1127 -- or some parent of Typ implements Iface.
1133 procedure Add_Interface
(Iface
: Entity_Id
) is
1137 Elmt
:= First_Elmt
(Ifaces_List
);
1138 while Present
(Elmt
) and then Node
(Elmt
) /= Iface
loop
1143 Append_Elmt
(Iface
, Ifaces_List
);
1151 procedure Collect
(Typ
: Entity_Id
) is
1152 Ancestor
: Entity_Id
;
1154 Iface_List
: List_Id
;
1161 -- Handle private types
1164 and then Is_Private_Type
(Typ
)
1165 and then Present
(Full_View
(Typ
))
1167 Full_T
:= Full_View
(Typ
);
1170 Iface_List
:= Abstract_Interface_List
(Full_T
);
1172 -- Include the ancestor if we are generating the whole list of
1173 -- abstract interfaces.
1175 -- In concurrent types the ancestor interface (if any) is the
1176 -- first element of the list of interface types.
1178 if Is_Concurrent_Type
(Full_T
)
1179 or else Is_Concurrent_Record_Type
(Full_T
)
1181 if Is_Non_Empty_List
(Iface_List
) then
1182 Ancestor
:= Etype
(First
(Iface_List
));
1185 if not Exclude_Parent_Interfaces
then
1186 Add_Interface
(Ancestor
);
1190 elsif Etype
(Full_T
) /= Typ
1192 -- Protect the frontend against wrong sources. For example:
1195 -- type A is tagged null record;
1196 -- type B is new A with private;
1197 -- type C is new A with private;
1199 -- type B is new C with null record;
1200 -- type C is new B with null record;
1203 and then Etype
(Full_T
) /= T
1205 Ancestor
:= Etype
(Full_T
);
1208 if Is_Interface
(Ancestor
)
1209 and then not Exclude_Parent_Interfaces
1211 Add_Interface
(Ancestor
);
1215 -- Traverse the graph of ancestor interfaces
1217 if Is_Non_Empty_List
(Iface_List
) then
1218 Id
:= First
(Iface_List
);
1220 -- In concurrent types the ancestor interface (if any) is the
1221 -- first element of the list of interface types and we have
1222 -- already processed them while climbing to the root type.
1224 if Is_Concurrent_Type
(Full_T
)
1225 or else Is_Concurrent_Record_Type
(Full_T
)
1230 while Present
(Id
) loop
1231 Iface
:= Etype
(Id
);
1233 -- Protect against wrong uses. For example:
1234 -- type I is interface;
1235 -- type O is tagged null record;
1236 -- type Wrong is new I and O with null record; -- ERROR
1238 if Is_Interface
(Iface
) then
1239 if Exclude_Parent_Interfaces
1240 and then Interface_Present_In_Parent
(T
, Iface
)
1245 Add_Interface
(Iface
);
1254 ---------------------------------
1255 -- Interface_Present_In_Parent --
1256 ---------------------------------
1258 function Interface_Present_In_Parent
1260 Iface
: Entity_Id
) return Boolean
1262 Aux
: Entity_Id
:= Typ
;
1263 Iface_List
: List_Id
;
1266 if Is_Concurrent_Type
(Typ
)
1267 or else Is_Concurrent_Record_Type
(Typ
)
1269 Iface_List
:= Abstract_Interface_List
(Typ
);
1271 if Is_Non_Empty_List
(Iface_List
) then
1272 Aux
:= Etype
(First
(Iface_List
));
1278 return Interface_Present_In_Ancestor
(Aux
, Iface
);
1279 end Interface_Present_In_Parent
;
1281 -- Start of processing for Collect_Abstract_Interfaces
1284 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
1285 Ifaces_List
:= New_Elmt_List
;
1287 end Collect_Abstract_Interfaces
;
1289 ----------------------------------
1290 -- Collect_Interface_Components --
1291 ----------------------------------
1293 procedure Collect_Interface_Components
1294 (Tagged_Type
: Entity_Id
;
1295 Components_List
: out Elist_Id
)
1297 procedure Collect
(Typ
: Entity_Id
);
1298 -- Subsidiary subprogram used to climb to the parents
1304 procedure Collect
(Typ
: Entity_Id
) is
1305 Tag_Comp
: Entity_Id
;
1308 if Etype
(Typ
) /= Typ
1310 -- Protect the frontend against wrong sources. For example:
1313 -- type A is tagged null record;
1314 -- type B is new A with private;
1315 -- type C is new A with private;
1317 -- type B is new C with null record;
1318 -- type C is new B with null record;
1321 and then Etype
(Typ
) /= Tagged_Type
1323 Collect
(Etype
(Typ
));
1326 -- Collect the components containing tags of secondary dispatch
1329 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
1330 while Present
(Tag_Comp
) loop
1331 pragma Assert
(Present
(Related_Interface
(Tag_Comp
)));
1332 Append_Elmt
(Tag_Comp
, Components_List
);
1334 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
1338 -- Start of processing for Collect_Interface_Components
1341 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
1342 and then Is_Tagged_Type
(Tagged_Type
));
1344 Components_List
:= New_Elmt_List
;
1345 Collect
(Tagged_Type
);
1346 end Collect_Interface_Components
;
1348 -----------------------------
1349 -- Collect_Interfaces_Info --
1350 -----------------------------
1352 procedure Collect_Interfaces_Info
1354 Ifaces_List
: out Elist_Id
;
1355 Components_List
: out Elist_Id
;
1356 Tags_List
: out Elist_Id
)
1358 Comps_List
: Elist_Id
;
1359 Comp_Elmt
: Elmt_Id
;
1360 Comp_Iface
: Entity_Id
;
1361 Iface_Elmt
: Elmt_Id
;
1364 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
1365 -- Search for the secondary tag associated with the interface type
1366 -- Iface that is implemented by T.
1372 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
1376 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
1378 and then Ekind
(Node
(ADT
)) = E_Constant
1379 and then Related_Interface
(Node
(ADT
)) /= Iface
1384 pragma Assert
(Ekind
(Node
(ADT
)) = E_Constant
);
1388 -- Start of processing for Collect_Interfaces_Info
1391 Collect_Abstract_Interfaces
(T
, Ifaces_List
);
1392 Collect_Interface_Components
(T
, Comps_List
);
1394 -- Search for the record component and tag associated with each
1395 -- interface type of T.
1397 Components_List
:= New_Elmt_List
;
1398 Tags_List
:= New_Elmt_List
;
1400 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1401 while Present
(Iface_Elmt
) loop
1402 Iface
:= Node
(Iface_Elmt
);
1404 -- Associate the primary tag component and the primary dispatch table
1405 -- with all the interfaces that are parents of T
1407 if Is_Parent
(Iface
, T
) then
1408 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
1409 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
1411 -- Otherwise search for the tag component and secondary dispatch
1415 Comp_Elmt
:= First_Elmt
(Comps_List
);
1416 while Present
(Comp_Elmt
) loop
1417 Comp_Iface
:= Related_Interface
(Node
(Comp_Elmt
));
1419 if Comp_Iface
= Iface
1420 or else Is_Parent
(Iface
, Comp_Iface
)
1422 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
1423 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
1427 Next_Elmt
(Comp_Elmt
);
1429 pragma Assert
(Present
(Comp_Elmt
));
1432 Next_Elmt
(Iface_Elmt
);
1434 end Collect_Interfaces_Info
;
1436 ----------------------------------
1437 -- Collect_Primitive_Operations --
1438 ----------------------------------
1440 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
1441 B_Type
: constant Entity_Id
:= Base_Type
(T
);
1442 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
1443 B_Scope
: Entity_Id
:= Scope
(B_Type
);
1447 Formal_Derived
: Boolean := False;
1451 -- For tagged types, the primitive operations are collected as they
1452 -- are declared, and held in an explicit list which is simply returned.
1454 if Is_Tagged_Type
(B_Type
) then
1455 return Primitive_Operations
(B_Type
);
1457 -- An untagged generic type that is a derived type inherits the
1458 -- primitive operations of its parent type. Other formal types only
1459 -- have predefined operators, which are not explicitly represented.
1461 elsif Is_Generic_Type
(B_Type
) then
1462 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
1463 and then Nkind
(Formal_Type_Definition
(B_Decl
))
1464 = N_Formal_Derived_Type_Definition
1466 Formal_Derived
:= True;
1468 return New_Elmt_List
;
1472 Op_List
:= New_Elmt_List
;
1474 if B_Scope
= Standard_Standard
then
1475 if B_Type
= Standard_String
then
1476 Append_Elmt
(Standard_Op_Concat
, Op_List
);
1478 elsif B_Type
= Standard_Wide_String
then
1479 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
1485 elsif (Is_Package_Or_Generic_Package
(B_Scope
)
1487 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
1489 or else Is_Derived_Type
(B_Type
)
1491 -- The primitive operations appear after the base type, except
1492 -- if the derivation happens within the private part of B_Scope
1493 -- and the type is a private type, in which case both the type
1494 -- and some primitive operations may appear before the base
1495 -- type, and the list of candidates starts after the type.
1497 if In_Open_Scopes
(B_Scope
)
1498 and then Scope
(T
) = B_Scope
1499 and then In_Private_Part
(B_Scope
)
1501 Id
:= Next_Entity
(T
);
1503 Id
:= Next_Entity
(B_Type
);
1506 while Present
(Id
) loop
1508 -- Note that generic formal subprograms are not
1509 -- considered to be primitive operations and thus
1510 -- are never inherited.
1512 if Is_Overloadable
(Id
)
1513 and then Nkind
(Parent
(Parent
(Id
)))
1514 not in N_Formal_Subprogram_Declaration
1518 if Base_Type
(Etype
(Id
)) = B_Type
then
1521 Formal
:= First_Formal
(Id
);
1522 while Present
(Formal
) loop
1523 if Base_Type
(Etype
(Formal
)) = B_Type
then
1527 elsif Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
1529 (Designated_Type
(Etype
(Formal
))) = B_Type
1535 Next_Formal
(Formal
);
1539 -- For a formal derived type, the only primitives are the
1540 -- ones inherited from the parent type. Operations appearing
1541 -- in the package declaration are not primitive for it.
1544 and then (not Formal_Derived
1545 or else Present
(Alias
(Id
)))
1547 Append_Elmt
(Id
, Op_List
);
1553 -- For a type declared in System, some of its operations
1554 -- may appear in the target-specific extension to System.
1557 and then Chars
(B_Scope
) = Name_System
1558 and then Scope
(B_Scope
) = Standard_Standard
1559 and then Present_System_Aux
1561 B_Scope
:= System_Aux_Id
;
1562 Id
:= First_Entity
(System_Aux_Id
);
1568 end Collect_Primitive_Operations
;
1570 -----------------------------------
1571 -- Compile_Time_Constraint_Error --
1572 -----------------------------------
1574 function Compile_Time_Constraint_Error
1577 Ent
: Entity_Id
:= Empty
;
1578 Loc
: Source_Ptr
:= No_Location
;
1579 Warn
: Boolean := False) return Node_Id
1581 Msgc
: String (1 .. Msg
'Length + 2);
1582 -- Copy of message, with room for possible ? and ! at end
1592 -- A static constraint error in an instance body is not a fatal error.
1593 -- we choose to inhibit the message altogether, because there is no
1594 -- obvious node (for now) on which to post it. On the other hand the
1595 -- offending node must be replaced with a constraint_error in any case.
1597 -- No messages are generated if we already posted an error on this node
1599 if not Error_Posted
(N
) then
1600 if Loc
/= No_Location
then
1606 Msgc
(1 .. Msg
'Length) := Msg
;
1609 -- Message is a warning, even in Ada 95 case
1611 if Msg
(Msg
'Last) = '?' then
1614 -- In Ada 83, all messages are warnings. In the private part and
1615 -- the body of an instance, constraint_checks are only warnings.
1616 -- We also make this a warning if the Warn parameter is set.
1619 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
1625 elsif In_Instance_Not_Visible
then
1630 -- Otherwise we have a real error message (Ada 95 static case)
1631 -- and we make this an unconditional message. Note that in the
1632 -- warning case we do not make the message unconditional, it seems
1633 -- quite reasonable to delete messages like this (about exceptions
1634 -- that will be raised) in dead code.
1642 -- Should we generate a warning? The answer is not quite yes. The
1643 -- very annoying exception occurs in the case of a short circuit
1644 -- operator where the left operand is static and decisive. Climb
1645 -- parents to see if that is the case we have here. Conditional
1646 -- expressions with decisive conditions are a similar situation.
1654 -- And then with False as left operand
1656 if Nkind
(P
) = N_And_Then
1657 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1658 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
1663 -- OR ELSE with True as left operand
1665 elsif Nkind
(P
) = N_Or_Else
1666 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1667 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
1672 -- Conditional expression
1674 elsif Nkind
(P
) = N_Conditional_Expression
then
1676 Cond
: constant Node_Id
:= First
(Expressions
(P
));
1677 Texp
: constant Node_Id
:= Next
(Cond
);
1678 Fexp
: constant Node_Id
:= Next
(Texp
);
1681 if Compile_Time_Known_Value
(Cond
) then
1683 -- Condition is True and we are in the right operand
1685 if Is_True
(Expr_Value
(Cond
))
1686 and then OldP
= Fexp
1691 -- Condition is False and we are in the left operand
1693 elsif Is_False
(Expr_Value
(Cond
))
1694 and then OldP
= Texp
1702 -- Special case for component association in aggregates, where
1703 -- we want to keep climbing up to the parent aggregate.
1705 elsif Nkind
(P
) = N_Component_Association
1706 and then Nkind
(Parent
(P
)) = N_Aggregate
1710 -- Keep going if within subexpression
1713 exit when Nkind
(P
) not in N_Subexpr
;
1718 if Present
(Ent
) then
1719 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
1721 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
1725 if Inside_Init_Proc
then
1727 ("\?& will be raised for objects of this type",
1728 N
, Standard_Constraint_Error
, Eloc
);
1731 ("\?& will be raised at run time",
1732 N
, Standard_Constraint_Error
, Eloc
);
1737 ("\static expression fails Constraint_Check", Eloc
);
1738 Set_Error_Posted
(N
);
1744 end Compile_Time_Constraint_Error
;
1746 -----------------------
1747 -- Conditional_Delay --
1748 -----------------------
1750 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
1752 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
1753 Set_Has_Delayed_Freeze
(New_Ent
);
1755 end Conditional_Delay
;
1757 --------------------
1758 -- Current_Entity --
1759 --------------------
1761 -- The currently visible definition for a given identifier is the
1762 -- one most chained at the start of the visibility chain, i.e. the
1763 -- one that is referenced by the Node_Id value of the name of the
1764 -- given identifier.
1766 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
1768 return Get_Name_Entity_Id
(Chars
(N
));
1771 -----------------------------
1772 -- Current_Entity_In_Scope --
1773 -----------------------------
1775 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
1777 CS
: constant Entity_Id
:= Current_Scope
;
1779 Transient_Case
: constant Boolean := Scope_Is_Transient
;
1782 E
:= Get_Name_Entity_Id
(Chars
(N
));
1784 and then Scope
(E
) /= CS
1785 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
1791 end Current_Entity_In_Scope
;
1797 function Current_Scope
return Entity_Id
is
1799 if Scope_Stack
.Last
= -1 then
1800 return Standard_Standard
;
1803 C
: constant Entity_Id
:=
1804 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
1809 return Standard_Standard
;
1815 ------------------------
1816 -- Current_Subprogram --
1817 ------------------------
1819 function Current_Subprogram
return Entity_Id
is
1820 Scop
: constant Entity_Id
:= Current_Scope
;
1823 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
1826 return Enclosing_Subprogram
(Scop
);
1828 end Current_Subprogram
;
1830 ---------------------
1831 -- Defining_Entity --
1832 ---------------------
1834 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
1835 K
: constant Node_Kind
:= Nkind
(N
);
1836 Err
: Entity_Id
:= Empty
;
1841 N_Subprogram_Declaration |
1842 N_Abstract_Subprogram_Declaration |
1844 N_Package_Declaration |
1845 N_Subprogram_Renaming_Declaration |
1846 N_Subprogram_Body_Stub |
1847 N_Generic_Subprogram_Declaration |
1848 N_Generic_Package_Declaration |
1849 N_Formal_Subprogram_Declaration
1851 return Defining_Entity
(Specification
(N
));
1854 N_Component_Declaration |
1855 N_Defining_Program_Unit_Name |
1856 N_Discriminant_Specification |
1858 N_Entry_Declaration |
1859 N_Entry_Index_Specification |
1860 N_Exception_Declaration |
1861 N_Exception_Renaming_Declaration |
1862 N_Formal_Object_Declaration |
1863 N_Formal_Package_Declaration |
1864 N_Formal_Type_Declaration |
1865 N_Full_Type_Declaration |
1866 N_Implicit_Label_Declaration |
1867 N_Incomplete_Type_Declaration |
1868 N_Loop_Parameter_Specification |
1869 N_Number_Declaration |
1870 N_Object_Declaration |
1871 N_Object_Renaming_Declaration |
1872 N_Package_Body_Stub |
1873 N_Parameter_Specification |
1874 N_Private_Extension_Declaration |
1875 N_Private_Type_Declaration |
1877 N_Protected_Body_Stub |
1878 N_Protected_Type_Declaration |
1879 N_Single_Protected_Declaration |
1880 N_Single_Task_Declaration |
1881 N_Subtype_Declaration |
1884 N_Task_Type_Declaration
1886 return Defining_Identifier
(N
);
1889 return Defining_Entity
(Proper_Body
(N
));
1892 N_Function_Instantiation |
1893 N_Function_Specification |
1894 N_Generic_Function_Renaming_Declaration |
1895 N_Generic_Package_Renaming_Declaration |
1896 N_Generic_Procedure_Renaming_Declaration |
1898 N_Package_Instantiation |
1899 N_Package_Renaming_Declaration |
1900 N_Package_Specification |
1901 N_Procedure_Instantiation |
1902 N_Procedure_Specification
1905 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
1908 if Nkind
(Nam
) in N_Entity
then
1911 -- For Error, make up a name and attach to declaration
1912 -- so we can continue semantic analysis
1914 elsif Nam
= Error
then
1916 Make_Defining_Identifier
(Sloc
(N
),
1917 Chars
=> New_Internal_Name
('T'));
1918 Set_Defining_Unit_Name
(N
, Err
);
1921 -- If not an entity, get defining identifier
1924 return Defining_Identifier
(Nam
);
1928 when N_Block_Statement
=>
1929 return Entity
(Identifier
(N
));
1932 raise Program_Error
;
1935 end Defining_Entity
;
1937 --------------------------
1938 -- Denotes_Discriminant --
1939 --------------------------
1941 function Denotes_Discriminant
1943 Check_Concurrent
: Boolean := False) return Boolean
1947 if not Is_Entity_Name
(N
)
1948 or else No
(Entity
(N
))
1955 -- If we are checking for a protected type, the discriminant may have
1956 -- been rewritten as the corresponding discriminal of the original type
1957 -- or of the corresponding concurrent record, depending on whether we
1958 -- are in the spec or body of the protected type.
1960 return Ekind
(E
) = E_Discriminant
1963 and then Ekind
(E
) = E_In_Parameter
1964 and then Present
(Discriminal_Link
(E
))
1966 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
1968 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
1970 end Denotes_Discriminant
;
1972 -----------------------------
1973 -- Depends_On_Discriminant --
1974 -----------------------------
1976 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
1981 Get_Index_Bounds
(N
, L
, H
);
1982 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
1983 end Depends_On_Discriminant
;
1985 -------------------------
1986 -- Designate_Same_Unit --
1987 -------------------------
1989 function Designate_Same_Unit
1991 Name2
: Node_Id
) return Boolean
1993 K1
: constant Node_Kind
:= Nkind
(Name1
);
1994 K2
: constant Node_Kind
:= Nkind
(Name2
);
1996 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
1997 -- Returns the parent unit name node of a defining program unit name
1998 -- or the prefix if N is a selected component or an expanded name.
2000 function Select_Node
(N
: Node_Id
) return Node_Id
;
2001 -- Returns the defining identifier node of a defining program unit
2002 -- name or the selector node if N is a selected component or an
2009 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
2011 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2023 function Select_Node
(N
: Node_Id
) return Node_Id
is
2025 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2026 return Defining_Identifier
(N
);
2029 return Selector_Name
(N
);
2033 -- Start of processing for Designate_Next_Unit
2036 if (K1
= N_Identifier
or else
2037 K1
= N_Defining_Identifier
)
2039 (K2
= N_Identifier
or else
2040 K2
= N_Defining_Identifier
)
2042 return Chars
(Name1
) = Chars
(Name2
);
2045 (K1
= N_Expanded_Name
or else
2046 K1
= N_Selected_Component
or else
2047 K1
= N_Defining_Program_Unit_Name
)
2049 (K2
= N_Expanded_Name
or else
2050 K2
= N_Selected_Component
or else
2051 K2
= N_Defining_Program_Unit_Name
)
2054 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
2056 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
2061 end Designate_Same_Unit
;
2063 ----------------------------
2064 -- Enclosing_Generic_Body --
2065 ----------------------------
2067 function Enclosing_Generic_Body
2068 (N
: Node_Id
) return Node_Id
2076 while Present
(P
) loop
2077 if Nkind
(P
) = N_Package_Body
2078 or else Nkind
(P
) = N_Subprogram_Body
2080 Spec
:= Corresponding_Spec
(P
);
2082 if Present
(Spec
) then
2083 Decl
:= Unit_Declaration_Node
(Spec
);
2085 if Nkind
(Decl
) = N_Generic_Package_Declaration
2086 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2097 end Enclosing_Generic_Body
;
2099 ----------------------------
2100 -- Enclosing_Generic_Unit --
2101 ----------------------------
2103 function Enclosing_Generic_Unit
2104 (N
: Node_Id
) return Node_Id
2112 while Present
(P
) loop
2113 if Nkind
(P
) = N_Generic_Package_Declaration
2114 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
2118 elsif Nkind
(P
) = N_Package_Body
2119 or else Nkind
(P
) = N_Subprogram_Body
2121 Spec
:= Corresponding_Spec
(P
);
2123 if Present
(Spec
) then
2124 Decl
:= Unit_Declaration_Node
(Spec
);
2126 if Nkind
(Decl
) = N_Generic_Package_Declaration
2127 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2138 end Enclosing_Generic_Unit
;
2140 -------------------------------
2141 -- Enclosing_Lib_Unit_Entity --
2142 -------------------------------
2144 function Enclosing_Lib_Unit_Entity
return Entity_Id
is
2145 Unit_Entity
: Entity_Id
;
2148 -- Look for enclosing library unit entity by following scope links.
2149 -- Equivalent to, but faster than indexing through the scope stack.
2151 Unit_Entity
:= Current_Scope
;
2152 while (Present
(Scope
(Unit_Entity
))
2153 and then Scope
(Unit_Entity
) /= Standard_Standard
)
2154 and not Is_Child_Unit
(Unit_Entity
)
2156 Unit_Entity
:= Scope
(Unit_Entity
);
2160 end Enclosing_Lib_Unit_Entity
;
2162 -----------------------------
2163 -- Enclosing_Lib_Unit_Node --
2164 -----------------------------
2166 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
2167 Current_Node
: Node_Id
;
2171 while Present
(Current_Node
)
2172 and then Nkind
(Current_Node
) /= N_Compilation_Unit
2174 Current_Node
:= Parent
(Current_Node
);
2177 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
2181 return Current_Node
;
2182 end Enclosing_Lib_Unit_Node
;
2184 --------------------------
2185 -- Enclosing_Subprogram --
2186 --------------------------
2188 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
2189 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
2192 if Dynamic_Scope
= Standard_Standard
then
2195 elsif Dynamic_Scope
= Empty
then
2198 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
2199 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
2201 elsif Ekind
(Dynamic_Scope
) = E_Block
2202 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
2204 return Enclosing_Subprogram
(Dynamic_Scope
);
2206 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
2207 return Get_Task_Body_Procedure
(Dynamic_Scope
);
2209 elsif Convention
(Dynamic_Scope
) = Convention_Protected
then
2210 return Protected_Body_Subprogram
(Dynamic_Scope
);
2213 return Dynamic_Scope
;
2215 end Enclosing_Subprogram
;
2217 ------------------------
2218 -- Ensure_Freeze_Node --
2219 ------------------------
2221 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
2225 if No
(Freeze_Node
(E
)) then
2226 FN
:= Make_Freeze_Entity
(Sloc
(E
));
2227 Set_Has_Delayed_Freeze
(E
);
2228 Set_Freeze_Node
(E
, FN
);
2229 Set_Access_Types_To_Process
(FN
, No_Elist
);
2230 Set_TSS_Elist
(FN
, No_Elist
);
2233 end Ensure_Freeze_Node
;
2239 procedure Enter_Name
(Def_Id
: Entity_Id
) is
2240 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
2241 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
2242 S
: constant Entity_Id
:= Current_Scope
;
2244 function Is_Private_Component_Renaming
(N
: Node_Id
) return Boolean;
2245 -- Recognize a renaming declaration that is introduced for private
2246 -- components of a protected type. We treat these as weak declarations
2247 -- so that they are overridden by entities with the same name that
2248 -- come from source, such as formals or local variables of a given
2249 -- protected declaration.
2251 -----------------------------------
2252 -- Is_Private_Component_Renaming --
2253 -----------------------------------
2255 function Is_Private_Component_Renaming
(N
: Node_Id
) return Boolean is
2257 return not Comes_From_Source
(N
)
2258 and then not Comes_From_Source
(Current_Scope
)
2259 and then Nkind
(N
) = N_Object_Renaming_Declaration
;
2260 end Is_Private_Component_Renaming
;
2262 -- Start of processing for Enter_Name
2265 Generate_Definition
(Def_Id
);
2267 -- Add new name to current scope declarations. Check for duplicate
2268 -- declaration, which may or may not be a genuine error.
2272 -- Case of previous entity entered because of a missing declaration
2273 -- or else a bad subtype indication. Best is to use the new entity,
2274 -- and make the previous one invisible.
2276 if Etype
(E
) = Any_Type
then
2277 Set_Is_Immediately_Visible
(E
, False);
2279 -- Case of renaming declaration constructed for package instances.
2280 -- if there is an explicit declaration with the same identifier,
2281 -- the renaming is not immediately visible any longer, but remains
2282 -- visible through selected component notation.
2284 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
2285 and then not Comes_From_Source
(E
)
2287 Set_Is_Immediately_Visible
(E
, False);
2289 -- The new entity may be the package renaming, which has the same
2290 -- same name as a generic formal which has been seen already.
2292 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
2293 and then not Comes_From_Source
(Def_Id
)
2295 Set_Is_Immediately_Visible
(E
, False);
2297 -- For a fat pointer corresponding to a remote access to subprogram,
2298 -- we use the same identifier as the RAS type, so that the proper
2299 -- name appears in the stub. This type is only retrieved through
2300 -- the RAS type and never by visibility, and is not added to the
2301 -- visibility list (see below).
2303 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
2304 and then Present
(Corresponding_Remote_Type
(Def_Id
))
2308 -- A controller component for a type extension overrides the
2309 -- inherited component.
2311 elsif Chars
(E
) = Name_uController
then
2314 -- Case of an implicit operation or derived literal. The new entity
2315 -- hides the implicit one, which is removed from all visibility,
2316 -- i.e. the entity list of its scope, and homonym chain of its name.
2318 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
2319 or else Is_Internal
(E
)
2323 Prev_Vis
: Entity_Id
;
2324 Decl
: constant Node_Id
:= Parent
(E
);
2327 -- If E is an implicit declaration, it cannot be the first
2328 -- entity in the scope.
2330 Prev
:= First_Entity
(Current_Scope
);
2331 while Present
(Prev
)
2332 and then Next_Entity
(Prev
) /= E
2339 -- If E is not on the entity chain of the current scope,
2340 -- it is an implicit declaration in the generic formal
2341 -- part of a generic subprogram. When analyzing the body,
2342 -- the generic formals are visible but not on the entity
2343 -- chain of the subprogram. The new entity will become
2344 -- the visible one in the body.
2347 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
2351 Set_Next_Entity
(Prev
, Next_Entity
(E
));
2353 if No
(Next_Entity
(Prev
)) then
2354 Set_Last_Entity
(Current_Scope
, Prev
);
2357 if E
= Current_Entity
(E
) then
2361 Prev_Vis
:= Current_Entity
(E
);
2362 while Homonym
(Prev_Vis
) /= E
loop
2363 Prev_Vis
:= Homonym
(Prev_Vis
);
2367 if Present
(Prev_Vis
) then
2369 -- Skip E in the visibility chain
2371 Set_Homonym
(Prev_Vis
, Homonym
(E
));
2374 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
2379 -- This section of code could use a comment ???
2381 elsif Present
(Etype
(E
))
2382 and then Is_Concurrent_Type
(Etype
(E
))
2387 elsif Is_Private_Component_Renaming
(Parent
(Def_Id
)) then
2390 -- In the body or private part of an instance, a type extension
2391 -- may introduce a component with the same name as that of an
2392 -- actual. The legality rule is not enforced, but the semantics
2393 -- of the full type with two components of the same name are not
2394 -- clear at this point ???
2396 elsif In_Instance_Not_Visible
then
2399 -- When compiling a package body, some child units may have become
2400 -- visible. They cannot conflict with local entities that hide them.
2402 elsif Is_Child_Unit
(E
)
2403 and then In_Open_Scopes
(Scope
(E
))
2404 and then not Is_Immediately_Visible
(E
)
2408 -- Conversely, with front-end inlining we may compile the parent
2409 -- body first, and a child unit subsequently. The context is now
2410 -- the parent spec, and body entities are not visible.
2412 elsif Is_Child_Unit
(Def_Id
)
2413 and then Is_Package_Body_Entity
(E
)
2414 and then not In_Package_Body
(Current_Scope
)
2418 -- Case of genuine duplicate declaration
2421 Error_Msg_Sloc
:= Sloc
(E
);
2423 -- If the previous declaration is an incomplete type declaration
2424 -- this may be an attempt to complete it with a private type.
2425 -- The following avoids confusing cascaded errors.
2427 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
2428 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
2431 ("incomplete type cannot be completed" &
2432 " with a private declaration",
2434 Set_Is_Immediately_Visible
(E
, False);
2435 Set_Full_View
(E
, Def_Id
);
2437 elsif Ekind
(E
) = E_Discriminant
2438 and then Present
(Scope
(Def_Id
))
2439 and then Scope
(Def_Id
) /= Current_Scope
2441 -- An inherited component of a record conflicts with
2442 -- a new discriminant. The discriminant is inserted first
2443 -- in the scope, but the error should be posted on it, not
2444 -- on the component.
2446 Error_Msg_Sloc
:= Sloc
(Def_Id
);
2447 Error_Msg_N
("& conflicts with declaration#", E
);
2450 -- If the name of the unit appears in its own context clause,
2451 -- a dummy package with the name has already been created, and
2452 -- the error emitted. Try to continue quietly.
2454 elsif Error_Posted
(E
)
2455 and then Sloc
(E
) = No_Location
2456 and then Nkind
(Parent
(E
)) = N_Package_Specification
2457 and then Current_Scope
= Standard_Standard
2459 Set_Scope
(Def_Id
, Current_Scope
);
2463 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
2465 -- Avoid cascaded messages with duplicate components in
2468 if Ekind
(E
) = E_Component
2469 or else Ekind
(E
) = E_Discriminant
2475 if Nkind
(Parent
(Parent
(Def_Id
)))
2476 = N_Generic_Subprogram_Declaration
2478 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
2480 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
2483 -- If entity is in standard, then we are in trouble, because
2484 -- it means that we have a library package with a duplicated
2485 -- name. That's hard to recover from, so abort!
2487 if S
= Standard_Standard
then
2488 raise Unrecoverable_Error
;
2490 -- Otherwise we continue with the declaration. Having two
2491 -- identical declarations should not cause us too much trouble!
2499 -- If we fall through, declaration is OK , or OK enough to continue
2501 -- If Def_Id is a discriminant or a record component we are in the
2502 -- midst of inheriting components in a derived record definition.
2503 -- Preserve their Ekind and Etype.
2505 if Ekind
(Def_Id
) = E_Discriminant
2506 or else Ekind
(Def_Id
) = E_Component
2510 -- If a type is already set, leave it alone (happens whey a type
2511 -- declaration is reanalyzed following a call to the optimizer)
2513 elsif Present
(Etype
(Def_Id
)) then
2516 -- Otherwise, the kind E_Void insures that premature uses of the entity
2517 -- will be detected. Any_Type insures that no cascaded errors will occur
2520 Set_Ekind
(Def_Id
, E_Void
);
2521 Set_Etype
(Def_Id
, Any_Type
);
2524 -- Inherited discriminants and components in derived record types are
2525 -- immediately visible. Itypes are not.
2527 if Ekind
(Def_Id
) = E_Discriminant
2528 or else Ekind
(Def_Id
) = E_Component
2529 or else (No
(Corresponding_Remote_Type
(Def_Id
))
2530 and then not Is_Itype
(Def_Id
))
2532 Set_Is_Immediately_Visible
(Def_Id
);
2533 Set_Current_Entity
(Def_Id
);
2536 Set_Homonym
(Def_Id
, C
);
2537 Append_Entity
(Def_Id
, S
);
2538 Set_Public_Status
(Def_Id
);
2540 -- Warn if new entity hides an old one
2542 if Warn_On_Hiding
and then Present
(C
)
2544 -- Don't warn for record components since they always have a well
2545 -- defined scope which does not confuse other uses. Note that in
2546 -- some cases, Ekind has not been set yet.
2548 and then Ekind
(C
) /= E_Component
2549 and then Ekind
(C
) /= E_Discriminant
2550 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
2551 and then Ekind
(Def_Id
) /= E_Component
2552 and then Ekind
(Def_Id
) /= E_Discriminant
2553 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
2555 -- Don't warn for one character variables. It is too common to use
2556 -- such variables as locals and will just cause too many false hits.
2558 and then Length_Of_Name
(Chars
(C
)) /= 1
2560 -- Don't warn for non-source eneities
2562 and then Comes_From_Source
(C
)
2563 and then Comes_From_Source
(Def_Id
)
2565 -- Don't warn unless entity in question is in extended main source
2567 and then In_Extended_Main_Source_Unit
(Def_Id
)
2569 -- Finally, the hidden entity must be either immediately visible
2570 -- or use visible (from a used package)
2573 (Is_Immediately_Visible
(C
)
2575 Is_Potentially_Use_Visible
(C
))
2577 Error_Msg_Sloc
:= Sloc
(C
);
2578 Error_Msg_N
("declaration hides &#?", Def_Id
);
2582 --------------------------
2583 -- Explain_Limited_Type --
2584 --------------------------
2586 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
2590 -- For array, component type must be limited
2592 if Is_Array_Type
(T
) then
2593 Error_Msg_Node_2
:= T
;
2595 ("\component type& of type& is limited", N
, Component_Type
(T
));
2596 Explain_Limited_Type
(Component_Type
(T
), N
);
2598 elsif Is_Record_Type
(T
) then
2600 -- No need for extra messages if explicit limited record
2602 if Is_Limited_Record
(Base_Type
(T
)) then
2606 -- Otherwise find a limited component. Check only components that
2607 -- come from source, or inherited components that appear in the
2608 -- source of the ancestor.
2610 C
:= First_Component
(T
);
2611 while Present
(C
) loop
2612 if Is_Limited_Type
(Etype
(C
))
2614 (Comes_From_Source
(C
)
2616 (Present
(Original_Record_Component
(C
))
2618 Comes_From_Source
(Original_Record_Component
(C
))))
2620 Error_Msg_Node_2
:= T
;
2621 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
2622 Explain_Limited_Type
(Etype
(C
), N
);
2629 -- The type may be declared explicitly limited, even if no component
2630 -- of it is limited, in which case we fall out of the loop.
2633 end Explain_Limited_Type
;
2635 ----------------------
2636 -- Find_Actual_Mode --
2637 ----------------------
2639 procedure Find_Actual_Mode
2641 Kind
: out Entity_Kind
;
2644 Parnt
: constant Node_Id
:= Parent
(N
);
2649 if (Nkind
(Parnt
) = N_Indexed_Component
2651 Nkind
(Parnt
) = N_Selected_Component
)
2652 and then N
= Prefix
(Parnt
)
2654 Find_Actual_Mode
(Parnt
, Kind
, Call
);
2657 elsif Nkind
(Parnt
) = N_Parameter_Association
2658 and then N
= Explicit_Actual_Parameter
(Parnt
)
2660 Call
:= Parent
(Parnt
);
2662 elsif Nkind
(Parnt
) = N_Procedure_Call_Statement
then
2671 -- If we have a call to a subprogram look for the parametere
2673 if Is_Entity_Name
(Name
(Call
))
2674 and then Present
(Entity
(Name
(Call
)))
2675 and then Is_Overloadable
(Entity
(Name
(Call
)))
2677 -- Fall here if we are definitely a parameter
2679 Actual
:= First_Actual
(Call
);
2680 Formal
:= First_Formal
(Entity
(Name
(Call
)));
2681 while Present
(Formal
) and then Present
(Actual
) loop
2683 Kind
:= Ekind
(Formal
);
2686 Actual
:= Next_Actual
(Actual
);
2687 Formal
:= Next_Formal
(Formal
);
2692 -- Fall through here if we did not find matching actual
2696 end Find_Actual_Mode
;
2698 -------------------------------------
2699 -- Find_Corresponding_Discriminant --
2700 -------------------------------------
2702 function Find_Corresponding_Discriminant
2704 Typ
: Entity_Id
) return Entity_Id
2706 Par_Disc
: Entity_Id
;
2707 Old_Disc
: Entity_Id
;
2708 New_Disc
: Entity_Id
;
2711 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
2713 -- The original type may currently be private, and the discriminant
2714 -- only appear on its full view.
2716 if Is_Private_Type
(Scope
(Par_Disc
))
2717 and then not Has_Discriminants
(Scope
(Par_Disc
))
2718 and then Present
(Full_View
(Scope
(Par_Disc
)))
2720 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
2722 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
2725 if Is_Class_Wide_Type
(Typ
) then
2726 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
2728 New_Disc
:= First_Discriminant
(Typ
);
2731 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
2732 if Old_Disc
= Par_Disc
then
2735 Next_Discriminant
(Old_Disc
);
2736 Next_Discriminant
(New_Disc
);
2740 -- Should always find it
2742 raise Program_Error
;
2743 end Find_Corresponding_Discriminant
;
2745 --------------------------
2746 -- Find_Overlaid_Object --
2747 --------------------------
2749 function Find_Overlaid_Object
(N
: Node_Id
) return Entity_Id
is
2753 -- We are looking for one of the two following forms:
2755 -- for X'Address use Y'Address
2759 -- Const : constant Address := expr;
2761 -- for X'Address use Const;
2763 -- In the second case, the expr is either Y'Address, or recursively a
2764 -- constant that eventually references Y'Address.
2766 if Nkind
(N
) = N_Attribute_Definition_Clause
2767 and then Chars
(N
) = Name_Address
2769 -- This loop checks the form of the expression for Y'Address where Y
2770 -- is an object entity name. The first loop checks the original
2771 -- expression in the attribute definition clause. Subsequent loops
2772 -- check referenced constants.
2774 Expr
:= Expression
(N
);
2776 -- Check for Y'Address where Y is an object entity
2778 if Nkind
(Expr
) = N_Attribute_Reference
2779 and then Attribute_Name
(Expr
) = Name_Address
2780 and then Is_Entity_Name
(Prefix
(Expr
))
2781 and then Is_Object
(Entity
(Prefix
(Expr
)))
2783 return Entity
(Prefix
(Expr
));
2785 -- Check for Const where Const is a constant entity
2787 elsif Is_Entity_Name
(Expr
)
2788 and then Ekind
(Entity
(Expr
)) = E_Constant
2790 Expr
:= Constant_Value
(Entity
(Expr
));
2792 -- Anything else does not need checking
2801 end Find_Overlaid_Object
;
2803 --------------------------------------------
2804 -- Find_Overridden_Synchronized_Primitive --
2805 --------------------------------------------
2807 function Find_Overridden_Synchronized_Primitive
2808 (Def_Id
: Entity_Id
;
2809 First_Hom
: Entity_Id
;
2810 Ifaces_List
: Elist_Id
;
2811 In_Scope
: Boolean) return Entity_Id
2813 Candidate
: Entity_Id
:= Empty
;
2814 Hom
: Entity_Id
:= Empty
;
2815 Iface_Typ
: Entity_Id
;
2816 Subp
: Entity_Id
:= Empty
;
2817 Tag_Typ
: Entity_Id
;
2819 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
;
2820 -- Return the type of a formal parameter as determined by its
2823 function Has_Correct_Formal_Mode
(Subp
: Entity_Id
) return Boolean;
2824 -- For an overridden subprogram Subp, check whether the mode of its
2825 -- first parameter is correct depending on the kind of Tag_Typ.
2827 function Matches_Prefixed_View_Profile
2828 (Prim_Params
: List_Id
;
2829 Iface_Params
: List_Id
) return Boolean;
2830 -- Determine whether a subprogram's parameter profile Prim_Params
2831 -- matches that of a potentially overriden interface subprogram
2832 -- Iface_Params. Also determine if the type of first parameter of
2833 -- Iface_Params is an implemented interface.
2835 -------------------------
2836 -- Find_Parameter_Type --
2837 -------------------------
2839 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
2841 pragma Assert
(Nkind
(Param
) = N_Parameter_Specification
);
2843 if Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
2844 return Etype
(Subtype_Mark
(Parameter_Type
(Param
)));
2847 return Etype
(Parameter_Type
(Param
));
2849 end Find_Parameter_Type
;
2851 -----------------------------
2852 -- Has_Correct_Formal_Mode --
2853 -----------------------------
2855 function Has_Correct_Formal_Mode
(Subp
: Entity_Id
) return Boolean is
2859 Param
:= First_Formal
(Subp
);
2861 -- In order for an entry or a protected procedure to override, the
2862 -- first parameter of the overridden routine must be of mode "out",
2863 -- "in out" or access-to-variable.
2865 if (Ekind
(Subp
) = E_Entry
2866 or else Ekind
(Subp
) = E_Procedure
)
2867 and then Is_Protected_Type
(Tag_Typ
)
2868 and then Ekind
(Param
) /= E_In_Out_Parameter
2869 and then Ekind
(Param
) /= E_Out_Parameter
2870 and then Nkind
(Parameter_Type
(Parent
(Param
))) /=
2876 -- All other cases are OK since a task entry or routine does not
2877 -- have a restriction on the mode of the first parameter of the
2878 -- overridden interface routine.
2881 end Has_Correct_Formal_Mode
;
2883 -----------------------------------
2884 -- Matches_Prefixed_View_Profile --
2885 -----------------------------------
2887 function Matches_Prefixed_View_Profile
2888 (Prim_Params
: List_Id
;
2889 Iface_Params
: List_Id
) return Boolean
2891 Iface_Id
: Entity_Id
;
2892 Iface_Param
: Node_Id
;
2893 Iface_Typ
: Entity_Id
;
2894 Prim_Id
: Entity_Id
;
2895 Prim_Param
: Node_Id
;
2896 Prim_Typ
: Entity_Id
;
2898 function Is_Implemented
(Iface
: Entity_Id
) return Boolean;
2899 -- Determine if Iface is implemented by the current task or
2902 --------------------
2903 -- Is_Implemented --
2904 --------------------
2906 function Is_Implemented
(Iface
: Entity_Id
) return Boolean is
2907 Iface_Elmt
: Elmt_Id
;
2910 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
2911 while Present
(Iface_Elmt
) loop
2912 if Node
(Iface_Elmt
) = Iface
then
2916 Next_Elmt
(Iface_Elmt
);
2922 -- Start of processing for Matches_Prefixed_View_Profile
2925 Iface_Param
:= First
(Iface_Params
);
2926 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
2927 Prim_Param
:= First
(Prim_Params
);
2929 -- The first parameter of the potentially overriden subprogram
2930 -- must be an interface implemented by Prim.
2932 if not Is_Interface
(Iface_Typ
)
2933 or else not Is_Implemented
(Iface_Typ
)
2938 -- The checks on the object parameters are done, move onto the rest
2939 -- of the parameters.
2941 if not In_Scope
then
2942 Prim_Param
:= Next
(Prim_Param
);
2945 Iface_Param
:= Next
(Iface_Param
);
2946 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
2947 Iface_Id
:= Defining_Identifier
(Iface_Param
);
2948 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
2949 Prim_Id
:= Defining_Identifier
(Prim_Param
);
2950 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
2952 -- Case of multiple interface types inside a parameter profile
2954 -- (Obj_Param : in out Iface; ...; Param : Iface)
2956 -- If the interface type is implemented, then the matching type
2957 -- in the primitive should be the implementing record type.
2959 if Ekind
(Iface_Typ
) = E_Record_Type
2960 and then Is_Interface
(Iface_Typ
)
2961 and then Is_Implemented
(Iface_Typ
)
2963 if Prim_Typ
/= Tag_Typ
then
2967 -- The two parameters must be both mode and subtype conformant
2969 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
2971 not Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
2980 -- One of the two lists contains more parameters than the other
2982 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
2987 end Matches_Prefixed_View_Profile
;
2989 -- Start of processing for Find_Overridden_Synchronized_Primitive
2992 -- At this point the caller should have collected the interfaces
2993 -- implemented by the synchronized type.
2995 pragma Assert
(Present
(Ifaces_List
));
2997 -- Find the tagged type to which subprogram Def_Id is primitive. If the
2998 -- subprogram was declared within a protected or a task type, the type
2999 -- is the scope itself, otherwise it is the type of the first parameter.
3002 Tag_Typ
:= Scope
(Def_Id
);
3004 elsif Present
(First_Formal
(Def_Id
)) then
3005 Tag_Typ
:= Find_Parameter_Type
(Parent
(First_Formal
(Def_Id
)));
3007 -- A parameterless subprogram which is declared outside a synchronized
3008 -- type cannot act as a primitive, thus it cannot override anything.
3014 -- Traverse the homonym chain, looking at a potentially overriden
3015 -- subprogram that belongs to an implemented interface.
3018 while Present
(Hom
) loop
3021 -- Entries can override abstract or null interface procedures
3023 if Ekind
(Def_Id
) = E_Entry
3024 and then Ekind
(Subp
) = E_Procedure
3025 and then Nkind
(Parent
(Subp
)) = N_Procedure_Specification
3026 and then (Is_Abstract_Subprogram
(Subp
)
3027 or else Null_Present
(Parent
(Subp
)))
3029 while Present
(Alias
(Subp
)) loop
3030 Subp
:= Alias
(Subp
);
3033 if Matches_Prefixed_View_Profile
3034 (Parameter_Specifications
(Parent
(Def_Id
)),
3035 Parameter_Specifications
(Parent
(Subp
)))
3041 if Has_Correct_Formal_Mode
(Candidate
) then
3046 -- Procedures can override abstract or null interface procedures
3048 elsif Ekind
(Def_Id
) = E_Procedure
3049 and then Ekind
(Subp
) = E_Procedure
3050 and then Nkind
(Parent
(Subp
)) = N_Procedure_Specification
3051 and then (Is_Abstract_Subprogram
(Subp
)
3052 or else Null_Present
(Parent
(Subp
)))
3053 and then Matches_Prefixed_View_Profile
3054 (Parameter_Specifications
(Parent
(Def_Id
)),
3055 Parameter_Specifications
(Parent
(Subp
)))
3061 if Has_Correct_Formal_Mode
(Candidate
) then
3065 -- Functions can override abstract interface functions
3067 elsif Ekind
(Def_Id
) = E_Function
3068 and then Ekind
(Subp
) = E_Function
3069 and then Nkind
(Parent
(Subp
)) = N_Function_Specification
3070 and then Is_Abstract_Subprogram
(Subp
)
3071 and then Matches_Prefixed_View_Profile
3072 (Parameter_Specifications
(Parent
(Def_Id
)),
3073 Parameter_Specifications
(Parent
(Subp
)))
3074 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
3075 Etype
(Result_Definition
(Parent
(Subp
)))
3080 Hom
:= Homonym
(Hom
);
3083 -- After examining all candidates for overriding, we are left with
3084 -- the best match which is a mode incompatible interface routine.
3085 -- Do not emit an error if the Expander is active since this error
3086 -- will be detected later on after all concurrent types are expanded
3087 -- and all wrappers are built. This check is meant for spec-only
3090 if Present
(Candidate
)
3091 and then not Expander_Active
3093 Iface_Typ
:= Find_Parameter_Type
(Parent
(First_Formal
(Candidate
)));
3095 -- Def_Id is primitive of a protected type, declared inside the type,
3096 -- and the candidate is primitive of a limited or synchronized
3100 and then Is_Protected_Type
(Tag_Typ
)
3102 (Is_Limited_Interface
(Iface_Typ
)
3103 or else Is_Protected_Interface
(Iface_Typ
)
3104 or else Is_Synchronized_Interface
(Iface_Typ
)
3105 or else Is_Task_Interface
(Iface_Typ
))
3107 -- Must reword this message, comma before to in -gnatj mode ???
3110 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
3111 "access-to-variable", Tag_Typ
, Candidate
);
3113 ("\to be overridden by protected procedure or entry " &
3114 "(RM 9.4(11.9/2))", Tag_Typ
);
3119 end Find_Overridden_Synchronized_Primitive
;
3121 -----------------------------
3122 -- Find_Static_Alternative --
3123 -----------------------------
3125 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
3126 Expr
: constant Node_Id
:= Expression
(N
);
3127 Val
: constant Uint
:= Expr_Value
(Expr
);
3132 Alt
:= First
(Alternatives
(N
));
3135 if Nkind
(Alt
) /= N_Pragma
then
3136 Choice
:= First
(Discrete_Choices
(Alt
));
3137 while Present
(Choice
) loop
3139 -- Others choice, always matches
3141 if Nkind
(Choice
) = N_Others_Choice
then
3144 -- Range, check if value is in the range
3146 elsif Nkind
(Choice
) = N_Range
then
3148 Val
>= Expr_Value
(Low_Bound
(Choice
))
3150 Val
<= Expr_Value
(High_Bound
(Choice
));
3152 -- Choice is a subtype name. Note that we know it must
3153 -- be a static subtype, since otherwise it would have
3154 -- been diagnosed as illegal.
3156 elsif Is_Entity_Name
(Choice
)
3157 and then Is_Type
(Entity
(Choice
))
3159 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
));
3161 -- Choice is a subtype indication
3163 elsif Nkind
(Choice
) = N_Subtype_Indication
then
3165 C
: constant Node_Id
:= Constraint
(Choice
);
3166 R
: constant Node_Id
:= Range_Expression
(C
);
3170 Val
>= Expr_Value
(Low_Bound
(R
))
3172 Val
<= Expr_Value
(High_Bound
(R
));
3175 -- Choice is a simple expression
3178 exit Search
when Val
= Expr_Value
(Choice
);
3186 pragma Assert
(Present
(Alt
));
3189 -- The above loop *must* terminate by finding a match, since
3190 -- we know the case statement is valid, and the value of the
3191 -- expression is known at compile time. When we fall out of
3192 -- the loop, Alt points to the alternative that we know will
3193 -- be selected at run time.
3196 end Find_Static_Alternative
;
3202 function First_Actual
(Node
: Node_Id
) return Node_Id
is
3206 if No
(Parameter_Associations
(Node
)) then
3210 N
:= First
(Parameter_Associations
(Node
));
3212 if Nkind
(N
) = N_Parameter_Association
then
3213 return First_Named_Actual
(Node
);
3219 -------------------------
3220 -- Full_Qualified_Name --
3221 -------------------------
3223 function Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3225 pragma Warnings
(Off
, Res
);
3227 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
;
3228 -- Compute recursively the qualified name without NUL at the end
3230 ----------------------------------
3231 -- Internal_Full_Qualified_Name --
3232 ----------------------------------
3234 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3235 Ent
: Entity_Id
:= E
;
3236 Parent_Name
: String_Id
:= No_String
;
3239 -- Deals properly with child units
3241 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
3242 Ent
:= Defining_Identifier
(Ent
);
3245 -- Compute qualification recursively (only "Standard" has no scope)
3247 if Present
(Scope
(Scope
(Ent
))) then
3248 Parent_Name
:= Internal_Full_Qualified_Name
(Scope
(Ent
));
3251 -- Every entity should have a name except some expanded blocks
3252 -- don't bother about those.
3254 if Chars
(Ent
) = No_Name
then
3258 -- Add a period between Name and qualification
3260 if Parent_Name
/= No_String
then
3261 Start_String
(Parent_Name
);
3262 Store_String_Char
(Get_Char_Code
('.'));
3268 -- Generates the entity name in upper case
3270 Get_Decoded_Name_String
(Chars
(Ent
));
3272 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3274 end Internal_Full_Qualified_Name
;
3276 -- Start of processing for Full_Qualified_Name
3279 Res
:= Internal_Full_Qualified_Name
(E
);
3280 Store_String_Char
(Get_Char_Code
(ASCII
.nul
));
3282 end Full_Qualified_Name
;
3284 -----------------------
3285 -- Gather_Components --
3286 -----------------------
3288 procedure Gather_Components
3290 Comp_List
: Node_Id
;
3291 Governed_By
: List_Id
;
3293 Report_Errors
: out Boolean)
3297 Discrete_Choice
: Node_Id
;
3298 Comp_Item
: Node_Id
;
3300 Discrim
: Entity_Id
;
3301 Discrim_Name
: Node_Id
;
3302 Discrim_Value
: Node_Id
;
3305 Report_Errors
:= False;
3307 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
3310 elsif Present
(Component_Items
(Comp_List
)) then
3311 Comp_Item
:= First
(Component_Items
(Comp_List
));
3317 while Present
(Comp_Item
) loop
3319 -- Skip the tag of a tagged record, the interface tags, as well
3320 -- as all items that are not user components (anonymous types,
3321 -- rep clauses, Parent field, controller field).
3323 if Nkind
(Comp_Item
) = N_Component_Declaration
then
3325 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
3327 if not Is_Tag
(Comp
)
3328 and then Chars
(Comp
) /= Name_uParent
3329 and then Chars
(Comp
) /= Name_uController
3331 Append_Elmt
(Comp
, Into
);
3339 if No
(Variant_Part
(Comp_List
)) then
3342 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
3343 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3346 -- Look for the discriminant that governs this variant part.
3347 -- The discriminant *must* be in the Governed_By List
3349 Assoc
:= First
(Governed_By
);
3350 Find_Constraint
: loop
3351 Discrim
:= First
(Choices
(Assoc
));
3352 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
3353 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
3355 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
3356 = Chars
(Discrim_Name
))
3357 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
3358 = Chars
(Discrim_Name
);
3360 if No
(Next
(Assoc
)) then
3361 if not Is_Constrained
(Typ
)
3362 and then Is_Derived_Type
(Typ
)
3363 and then Present
(Stored_Constraint
(Typ
))
3365 -- If the type is a tagged type with inherited discriminants,
3366 -- use the stored constraint on the parent in order to find
3367 -- the values of discriminants that are otherwise hidden by an
3368 -- explicit constraint. Renamed discriminants are handled in
3371 -- If several parent discriminants are renamed by a single
3372 -- discriminant of the derived type, the call to obtain the
3373 -- Corresponding_Discriminant field only retrieves the last
3374 -- of them. We recover the constraint on the others from the
3375 -- Stored_Constraint as well.
3382 D
:= First_Discriminant
(Etype
(Typ
));
3383 C
:= First_Elmt
(Stored_Constraint
(Typ
));
3384 while Present
(D
) and then Present
(C
) loop
3385 if Chars
(Discrim_Name
) = Chars
(D
) then
3386 if Is_Entity_Name
(Node
(C
))
3387 and then Entity
(Node
(C
)) = Entity
(Discrim
)
3389 -- D is renamed by Discrim, whose value is given in
3396 Make_Component_Association
(Sloc
(Typ
),
3398 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
3399 Duplicate_Subexpr_No_Checks
(Node
(C
)));
3401 exit Find_Constraint
;
3404 Next_Discriminant
(D
);
3411 if No
(Next
(Assoc
)) then
3412 Error_Msg_NE
(" missing value for discriminant&",
3413 First
(Governed_By
), Discrim_Name
);
3414 Report_Errors
:= True;
3419 end loop Find_Constraint
;
3421 Discrim_Value
:= Expression
(Assoc
);
3423 if not Is_OK_Static_Expression
(Discrim_Value
) then
3425 ("value for discriminant & must be static!",
3426 Discrim_Value
, Discrim
);
3427 Why_Not_Static
(Discrim_Value
);
3428 Report_Errors
:= True;
3432 Search_For_Discriminant_Value
: declare
3438 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
3441 Find_Discrete_Value
: while Present
(Variant
) loop
3442 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
3443 while Present
(Discrete_Choice
) loop
3445 exit Find_Discrete_Value
when
3446 Nkind
(Discrete_Choice
) = N_Others_Choice
;
3448 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
3450 UI_Low
:= Expr_Value
(Low
);
3451 UI_High
:= Expr_Value
(High
);
3453 exit Find_Discrete_Value
when
3454 UI_Low
<= UI_Discrim_Value
3456 UI_High
>= UI_Discrim_Value
;
3458 Next
(Discrete_Choice
);
3461 Next_Non_Pragma
(Variant
);
3462 end loop Find_Discrete_Value
;
3463 end Search_For_Discriminant_Value
;
3465 if No
(Variant
) then
3467 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
3468 Report_Errors
:= True;
3472 -- If we have found the corresponding choice, recursively add its
3473 -- components to the Into list.
3475 Gather_Components
(Empty
,
3476 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
3477 end Gather_Components
;
3479 ------------------------
3480 -- Get_Actual_Subtype --
3481 ------------------------
3483 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
3484 Typ
: constant Entity_Id
:= Etype
(N
);
3485 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
3494 -- If what we have is an identifier that references a subprogram
3495 -- formal, or a variable or constant object, then we get the actual
3496 -- subtype from the referenced entity if one has been built.
3498 if Nkind
(N
) = N_Identifier
3500 (Is_Formal
(Entity
(N
))
3501 or else Ekind
(Entity
(N
)) = E_Constant
3502 or else Ekind
(Entity
(N
)) = E_Variable
)
3503 and then Present
(Actual_Subtype
(Entity
(N
)))
3505 return Actual_Subtype
(Entity
(N
));
3507 -- Actual subtype of unchecked union is always itself. We never need
3508 -- the "real" actual subtype. If we did, we couldn't get it anyway
3509 -- because the discriminant is not available. The restrictions on
3510 -- Unchecked_Union are designed to make sure that this is OK.
3512 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
3515 -- Here for the unconstrained case, we must find actual subtype
3516 -- No actual subtype is available, so we must build it on the fly.
3518 -- Checking the type, not the underlying type, for constrainedness
3519 -- seems to be necessary. Maybe all the tests should be on the type???
3521 elsif (not Is_Constrained
(Typ
))
3522 and then (Is_Array_Type
(Utyp
)
3523 or else (Is_Record_Type
(Utyp
)
3524 and then Has_Discriminants
(Utyp
)))
3525 and then not Has_Unknown_Discriminants
(Utyp
)
3526 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
3528 -- Nothing to do if in default expression
3530 if In_Default_Expression
then
3533 elsif Is_Private_Type
(Typ
)
3534 and then not Has_Discriminants
(Typ
)
3536 -- If the type has no discriminants, there is no subtype to
3537 -- build, even if the underlying type is discriminated.
3541 -- Else build the actual subtype
3544 Decl
:= Build_Actual_Subtype
(Typ
, N
);
3545 Atyp
:= Defining_Identifier
(Decl
);
3547 -- If Build_Actual_Subtype generated a new declaration then use it
3551 -- The actual subtype is an Itype, so analyze the declaration,
3552 -- but do not attach it to the tree, to get the type defined.
3554 Set_Parent
(Decl
, N
);
3555 Set_Is_Itype
(Atyp
);
3556 Analyze
(Decl
, Suppress
=> All_Checks
);
3557 Set_Associated_Node_For_Itype
(Atyp
, N
);
3558 Set_Has_Delayed_Freeze
(Atyp
, False);
3560 -- We need to freeze the actual subtype immediately. This is
3561 -- needed, because otherwise this Itype will not get frozen
3562 -- at all, and it is always safe to freeze on creation because
3563 -- any associated types must be frozen at this point.
3565 Freeze_Itype
(Atyp
, N
);
3568 -- Otherwise we did not build a declaration, so return original
3575 -- For all remaining cases, the actual subtype is the same as
3576 -- the nominal type.
3581 end Get_Actual_Subtype
;
3583 -------------------------------------
3584 -- Get_Actual_Subtype_If_Available --
3585 -------------------------------------
3587 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
3588 Typ
: constant Entity_Id
:= Etype
(N
);
3591 -- If what we have is an identifier that references a subprogram
3592 -- formal, or a variable or constant object, then we get the actual
3593 -- subtype from the referenced entity if one has been built.
3595 if Nkind
(N
) = N_Identifier
3597 (Is_Formal
(Entity
(N
))
3598 or else Ekind
(Entity
(N
)) = E_Constant
3599 or else Ekind
(Entity
(N
)) = E_Variable
)
3600 and then Present
(Actual_Subtype
(Entity
(N
)))
3602 return Actual_Subtype
(Entity
(N
));
3604 -- Otherwise the Etype of N is returned unchanged
3609 end Get_Actual_Subtype_If_Available
;
3611 -------------------------------
3612 -- Get_Default_External_Name --
3613 -------------------------------
3615 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
3617 Get_Decoded_Name_String
(Chars
(E
));
3619 if Opt
.External_Name_Imp_Casing
= Uppercase
then
3620 Set_Casing
(All_Upper_Case
);
3622 Set_Casing
(All_Lower_Case
);
3626 Make_String_Literal
(Sloc
(E
),
3627 Strval
=> String_From_Name_Buffer
);
3628 end Get_Default_External_Name
;
3630 ---------------------------
3631 -- Get_Enum_Lit_From_Pos --
3632 ---------------------------
3634 function Get_Enum_Lit_From_Pos
3637 Loc
: Source_Ptr
) return Node_Id
3642 -- In the case where the literal is of type Character, Wide_Character
3643 -- or Wide_Wide_Character or of a type derived from them, there needs
3644 -- to be some special handling since there is no explicit chain of
3645 -- literals to search. Instead, an N_Character_Literal node is created
3646 -- with the appropriate Char_Code and Chars fields.
3648 if Root_Type
(T
) = Standard_Character
3649 or else Root_Type
(T
) = Standard_Wide_Character
3650 or else Root_Type
(T
) = Standard_Wide_Wide_Character
3652 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
3654 Make_Character_Literal
(Loc
,
3656 Char_Literal_Value
=> Pos
);
3658 -- For all other cases, we have a complete table of literals, and
3659 -- we simply iterate through the chain of literal until the one
3660 -- with the desired position value is found.
3664 Lit
:= First_Literal
(Base_Type
(T
));
3665 for J
in 1 .. UI_To_Int
(Pos
) loop
3669 return New_Occurrence_Of
(Lit
, Loc
);
3671 end Get_Enum_Lit_From_Pos
;
3673 ------------------------
3674 -- Get_Generic_Entity --
3675 ------------------------
3677 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
3678 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
3680 if Present
(Renamed_Object
(Ent
)) then
3681 return Renamed_Object
(Ent
);
3685 end Get_Generic_Entity
;
3687 ----------------------
3688 -- Get_Index_Bounds --
3689 ----------------------
3691 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
3692 Kind
: constant Node_Kind
:= Nkind
(N
);
3696 if Kind
= N_Range
then
3698 H
:= High_Bound
(N
);
3700 elsif Kind
= N_Subtype_Indication
then
3701 R
:= Range_Expression
(Constraint
(N
));
3709 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
3710 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
3713 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
3714 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
3718 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
3719 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
3722 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
3723 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
3727 -- N is an expression, indicating a range with one value
3732 end Get_Index_Bounds
;
3734 ----------------------------------
3735 -- Get_Library_Unit_Name_string --
3736 ----------------------------------
3738 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
3739 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
3742 Get_Unit_Name_String
(Unit_Name_Id
);
3744 -- Remove seven last character (" (spec)" or " (body)")
3746 Name_Len
:= Name_Len
- 7;
3747 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
3748 end Get_Library_Unit_Name_String
;
3750 ------------------------
3751 -- Get_Name_Entity_Id --
3752 ------------------------
3754 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
3756 return Entity_Id
(Get_Name_Table_Info
(Id
));
3757 end Get_Name_Entity_Id
;
3759 ---------------------------
3760 -- Get_Referenced_Object --
3761 ---------------------------
3763 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
3768 while Is_Entity_Name
(R
)
3769 and then Present
(Renamed_Object
(Entity
(R
)))
3771 R
:= Renamed_Object
(Entity
(R
));
3775 end Get_Referenced_Object
;
3777 ------------------------
3778 -- Get_Renamed_Entity --
3779 ------------------------
3781 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
3786 while Present
(Renamed_Entity
(R
)) loop
3787 R
:= Renamed_Entity
(R
);
3791 end Get_Renamed_Entity
;
3793 -------------------------
3794 -- Get_Subprogram_Body --
3795 -------------------------
3797 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
3801 Decl
:= Unit_Declaration_Node
(E
);
3803 if Nkind
(Decl
) = N_Subprogram_Body
then
3806 -- The below comment is bad, because it is possible for
3807 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3809 else -- Nkind (Decl) = N_Subprogram_Declaration
3811 if Present
(Corresponding_Body
(Decl
)) then
3812 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
3814 -- Imported subprogram case
3820 end Get_Subprogram_Body
;
3822 ---------------------------
3823 -- Get_Subprogram_Entity --
3824 ---------------------------
3826 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
3831 if Nkind
(Nod
) = N_Accept_Statement
then
3832 Nam
:= Entry_Direct_Name
(Nod
);
3834 -- For an entry call, the prefix of the call is a selected component.
3835 -- Need additional code for internal calls ???
3837 elsif Nkind
(Nod
) = N_Entry_Call_Statement
then
3838 if Nkind
(Name
(Nod
)) = N_Selected_Component
then
3839 Nam
:= Entity
(Selector_Name
(Name
(Nod
)));
3848 if Nkind
(Nam
) = N_Explicit_Dereference
then
3849 Proc
:= Etype
(Prefix
(Nam
));
3850 elsif Is_Entity_Name
(Nam
) then
3851 Proc
:= Entity
(Nam
);
3856 if Is_Object
(Proc
) then
3857 Proc
:= Etype
(Proc
);
3860 if Ekind
(Proc
) = E_Access_Subprogram_Type
then
3861 Proc
:= Directly_Designated_Type
(Proc
);
3864 if not Is_Subprogram
(Proc
)
3865 and then Ekind
(Proc
) /= E_Subprogram_Type
3871 end Get_Subprogram_Entity
;
3873 -----------------------------
3874 -- Get_Task_Body_Procedure --
3875 -----------------------------
3877 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
3879 -- Note: A task type may be the completion of a private type with
3880 -- discriminants. when performing elaboration checks on a task
3881 -- declaration, the current view of the type may be the private one,
3882 -- and the procedure that holds the body of the task is held in its
3885 -- This is an odd function, why not have Task_Body_Procedure do
3886 -- the following digging???
3888 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
3889 end Get_Task_Body_Procedure
;
3891 -----------------------------
3892 -- Has_Abstract_Interfaces --
3893 -----------------------------
3895 function Has_Abstract_Interfaces
3896 (Tagged_Type
: Entity_Id
;
3897 Use_Full_View
: Boolean := True) return Boolean
3902 pragma Assert
(Is_Record_Type
(Tagged_Type
)
3903 and then Is_Tagged_Type
(Tagged_Type
));
3905 -- Handle concurrent record types
3907 if Is_Concurrent_Record_Type
(Tagged_Type
)
3908 and then Is_Non_Empty_List
(Abstract_Interface_List
(Tagged_Type
))
3915 -- Handle private types
3918 and then Present
(Full_View
(Tagged_Type
))
3920 Typ
:= Full_View
(Tagged_Type
);
3924 if Is_Interface
(Typ
)
3926 (Is_Record_Type
(Typ
)
3927 and then Present
(Abstract_Interfaces
(Typ
))
3928 and then not Is_Empty_Elmt_List
(Abstract_Interfaces
(Typ
)))
3933 exit when Etype
(Typ
) = Typ
3935 -- Handle private types
3937 or else (Present
(Full_View
(Etype
(Typ
)))
3938 and then Full_View
(Etype
(Typ
)) = Typ
)
3940 -- Protect the frontend against wrong source with cyclic
3943 or else Etype
(Typ
) = Tagged_Type
;
3945 -- Climb to the ancestor type handling private types
3947 if Present
(Full_View
(Etype
(Typ
))) then
3948 Typ
:= Full_View
(Etype
(Typ
));
3955 end Has_Abstract_Interfaces
;
3957 -----------------------
3958 -- Has_Access_Values --
3959 -----------------------
3961 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
3962 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
3965 -- Case of a private type which is not completed yet. This can only
3966 -- happen in the case of a generic format type appearing directly, or
3967 -- as a component of the type to which this function is being applied
3968 -- at the top level. Return False in this case, since we certainly do
3969 -- not know that the type contains access types.
3974 elsif Is_Access_Type
(Typ
) then
3977 elsif Is_Array_Type
(Typ
) then
3978 return Has_Access_Values
(Component_Type
(Typ
));
3980 elsif Is_Record_Type
(Typ
) then
3985 Comp
:= First_Component_Or_Discriminant
(Typ
);
3986 while Present
(Comp
) loop
3987 if Has_Access_Values
(Etype
(Comp
)) then
3991 Next_Component_Or_Discriminant
(Comp
);
4000 end Has_Access_Values
;
4002 ------------------------------
4003 -- Has_Compatible_Alignment --
4004 ------------------------------
4006 function Has_Compatible_Alignment
4008 Expr
: Node_Id
) return Alignment_Result
4010 function Has_Compatible_Alignment_Internal
4013 Default
: Alignment_Result
) return Alignment_Result
;
4014 -- This is the internal recursive function that actually does the work.
4015 -- There is one additional parameter, which says what the result should
4016 -- be if no alignment information is found, and there is no definite
4017 -- indication of compatible alignments. At the outer level, this is set
4018 -- to Unknown, but for internal recursive calls in the case where types
4019 -- are known to be correct, it is set to Known_Compatible.
4021 ---------------------------------------
4022 -- Has_Compatible_Alignment_Internal --
4023 ---------------------------------------
4025 function Has_Compatible_Alignment_Internal
4028 Default
: Alignment_Result
) return Alignment_Result
4030 Result
: Alignment_Result
:= Known_Compatible
;
4031 -- Set to result if Problem_Prefix or Problem_Offset returns True.
4032 -- Note that once a value of Known_Incompatible is set, it is sticky
4033 -- and does not get changed to Unknown (the value in Result only gets
4034 -- worse as we go along, never better).
4036 procedure Check_Offset
(Offs
: Uint
);
4037 -- Called when Expr is a selected or indexed component with Offs set
4038 -- to resp Component_First_Bit or Component_Size. Checks that if the
4039 -- offset is specified it is compatible with the object alignment
4040 -- requirements. The value in Result is modified accordingly.
4042 procedure Check_Prefix
;
4043 -- Checks the prefix recursively in the case where the expression
4044 -- is an indexed or selected component.
4046 procedure Set_Result
(R
: Alignment_Result
);
4047 -- If R represents a worse outcome (unknown instead of known
4048 -- compatible, or known incompatible), then set Result to R.
4054 procedure Check_Offset
(Offs
: Uint
) is
4056 -- Unspecified or zero offset is always OK
4058 if Offs
= No_Uint
or else Offs
= Uint_0
then
4061 -- If we do not know required alignment, any non-zero offset is
4062 -- a potential problem (but certainly may be OK, so result is
4065 elsif Unknown_Alignment
(Obj
) then
4066 Set_Result
(Unknown
);
4068 -- If we know the required alignment, see if offset is compatible
4071 if Offs
mod (System_Storage_Unit
* Alignment
(Obj
)) /= 0 then
4072 Set_Result
(Known_Incompatible
);
4081 procedure Check_Prefix
is
4083 -- The subtlety here is that in doing a recursive call to check
4084 -- the prefix, we have to decide what to do in the case where we
4085 -- don't find any specific indication of an alignment problem.
4087 -- At the outer level, we normally set Unknown as the result in
4088 -- this case, since we can only set Known_Compatible if we really
4089 -- know that the alignment value is OK, but for the recursive
4090 -- call, in the case where the types match, and we have not
4091 -- specified a peculiar alignment for the object, we are only
4092 -- concerned about suspicious rep clauses, the default case does
4093 -- not affect us, since the compiler will, in the absence of such
4094 -- rep clauses, ensure that the alignment is correct.
4096 if Default
= Known_Compatible
4098 (Etype
(Obj
) = Etype
(Expr
)
4099 and then (Unknown_Alignment
(Obj
)
4101 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
4104 (Has_Compatible_Alignment_Internal
4105 (Obj
, Prefix
(Expr
), Known_Compatible
));
4107 -- In all other cases, we need a full check on the prefix
4111 (Has_Compatible_Alignment_Internal
4112 (Obj
, Prefix
(Expr
), Unknown
));
4120 procedure Set_Result
(R
: Alignment_Result
) is
4127 -- Start of processing for Has_Compatible_Alignment_Internal
4130 -- If Expr is a selected component, we must make sure there is no
4131 -- potentially troublesome component clause, and that the record is
4134 if Nkind
(Expr
) = N_Selected_Component
then
4136 -- Packed record always generate unknown alignment
4138 if Is_Packed
(Etype
(Prefix
(Expr
))) then
4139 Set_Result
(Unknown
);
4142 -- Check possible bad component offset and check prefix
4145 (Component_Bit_Offset
(Entity
(Selector_Name
(Expr
))));
4148 -- If Expr is an indexed component, we must make sure there is no
4149 -- potentially troublesome Component_Size clause and that the array
4150 -- is not bit-packed.
4152 elsif Nkind
(Expr
) = N_Indexed_Component
then
4154 -- Bit packed array always generates unknown alignment
4156 if Is_Bit_Packed_Array
(Etype
(Prefix
(Expr
))) then
4157 Set_Result
(Unknown
);
4160 -- Check possible bad component size and check prefix
4162 Check_Offset
(Component_Size
(Etype
(Prefix
(Expr
))));
4166 -- Case where we know the alignment of the object
4168 if Known_Alignment
(Obj
) then
4170 ObjA
: constant Uint
:= Alignment
(Obj
);
4171 ExpA
: Uint
:= No_Uint
;
4172 SizA
: Uint
:= No_Uint
;
4175 -- If alignment of Obj is 1, then we are always OK
4178 Set_Result
(Known_Compatible
);
4180 -- Alignment of Obj is greater than 1, so we need to check
4183 -- See if Expr is an object with known alignment
4185 if Is_Entity_Name
(Expr
)
4186 and then Known_Alignment
(Entity
(Expr
))
4188 ExpA
:= Alignment
(Entity
(Expr
));
4190 -- Otherwise, we can use the alignment of the type of
4191 -- Expr given that we already checked for
4192 -- discombobulating rep clauses for the cases of indexed
4193 -- and selected components above.
4195 elsif Known_Alignment
(Etype
(Expr
)) then
4196 ExpA
:= Alignment
(Etype
(Expr
));
4199 -- If we got an alignment, see if it is acceptable
4201 if ExpA
/= No_Uint
then
4203 Set_Result
(Known_Incompatible
);
4206 -- Case of Expr alignment unknown
4209 Set_Result
(Default
);
4212 -- See if size is given. If so, check that it is not too
4213 -- small for the required alignment.
4214 -- See if Expr is an object with known alignment
4216 if Is_Entity_Name
(Expr
)
4217 and then Known_Static_Esize
(Entity
(Expr
))
4219 SizA
:= Esize
(Entity
(Expr
));
4221 -- Otherwise, we check the object size of the Expr type
4223 elsif Known_Static_Esize
(Etype
(Expr
)) then
4224 SizA
:= Esize
(Etype
(Expr
));
4227 -- If we got a size, see if it is a multiple of the Obj
4228 -- alignment, if not, then the alignment cannot be
4229 -- acceptable, since the size is always a multiple of the
4232 if SizA
/= No_Uint
then
4233 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
4234 Set_Result
(Known_Incompatible
);
4240 -- If we can't find the result by direct comparison of alignment
4241 -- values, then there is still one case that we can determine known
4242 -- result, and that is when we can determine that the types are the
4243 -- same, and no alignments are specified. Then we known that the
4244 -- alignments are compatible, even if we don't know the alignment
4245 -- value in the front end.
4247 elsif Etype
(Obj
) = Etype
(Expr
) then
4249 -- Types are the same, but we have to check for possible size
4250 -- and alignments on the Expr object that may make the alignment
4251 -- different, even though the types are the same.
4253 if Is_Entity_Name
(Expr
) then
4255 -- First check alignment of the Expr object. Any alignment less
4256 -- than Maximum_Alignment is worrisome since this is the case
4257 -- where we do not know the alignment of Obj.
4259 if Known_Alignment
(Entity
(Expr
))
4261 UI_To_Int
(Alignment
(Entity
(Expr
)))
4262 < Ttypes
.Maximum_Alignment
4264 Set_Result
(Unknown
);
4266 -- Now check size of Expr object. Any size that is not an
4267 -- even multiple of Maxiumum_Alignment is also worrisome
4268 -- since it may cause the alignment of the object to be less
4269 -- than the alignment of the type.
4271 elsif Known_Static_Esize
(Entity
(Expr
))
4273 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
4274 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
4277 Set_Result
(Unknown
);
4279 -- Otherwise same type is decisive
4282 Set_Result
(Known_Compatible
);
4286 -- Another case to deal with is when there is an explicit size or
4287 -- alignment clause when the types are not the same. If so, then the
4288 -- result is Unknown. We don't need to do this test if the Default is
4289 -- Unknown, since that result will be set in any case.
4291 elsif Default
/= Unknown
4292 and then (Has_Size_Clause
(Etype
(Expr
))
4294 Has_Alignment_Clause
(Etype
(Expr
)))
4296 Set_Result
(Unknown
);
4298 -- If no indication found, set default
4301 Set_Result
(Default
);
4304 -- Return worst result found
4307 end Has_Compatible_Alignment_Internal
;
4309 -- Start of processing for Has_Compatible_Alignment
4312 -- If Obj has no specified alignment, then set alignment from the type
4313 -- alignment. Perhaps we should always do this, but for sure we should
4314 -- do it when there is an address clause since we can do more if the
4315 -- alignment is known.
4317 if Unknown_Alignment
(Obj
) then
4318 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
4321 -- Now do the internal call that does all the work
4323 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
4324 end Has_Compatible_Alignment
;
4326 ----------------------
4327 -- Has_Declarations --
4328 ----------------------
4330 function Has_Declarations
(N
: Node_Id
) return Boolean is
4331 K
: constant Node_Kind
:= Nkind
(N
);
4333 return K
= N_Accept_Statement
4334 or else K
= N_Block_Statement
4335 or else K
= N_Compilation_Unit_Aux
4336 or else K
= N_Entry_Body
4337 or else K
= N_Package_Body
4338 or else K
= N_Protected_Body
4339 or else K
= N_Subprogram_Body
4340 or else K
= N_Task_Body
4341 or else K
= N_Package_Specification
;
4342 end Has_Declarations
;
4344 -------------------------------------------
4345 -- Has_Discriminant_Dependent_Constraint --
4346 -------------------------------------------
4348 function Has_Discriminant_Dependent_Constraint
4349 (Comp
: Entity_Id
) return Boolean
4351 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
4352 Subt_Indic
: constant Node_Id
:=
4353 Subtype_Indication
(Component_Definition
(Comp_Decl
));
4358 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
4359 Constr
:= Constraint
(Subt_Indic
);
4361 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
4362 Assn
:= First
(Constraints
(Constr
));
4363 while Present
(Assn
) loop
4364 case Nkind
(Assn
) is
4365 when N_Subtype_Indication |
4369 if Depends_On_Discriminant
(Assn
) then
4373 when N_Discriminant_Association
=>
4374 if Depends_On_Discriminant
(Expression
(Assn
)) then
4389 end Has_Discriminant_Dependent_Constraint
;
4391 --------------------
4392 -- Has_Infinities --
4393 --------------------
4395 function Has_Infinities
(E
: Entity_Id
) return Boolean is
4398 Is_Floating_Point_Type
(E
)
4399 and then Nkind
(Scalar_Range
(E
)) = N_Range
4400 and then Includes_Infinities
(Scalar_Range
(E
));
4403 ------------------------
4404 -- Has_Null_Exclusion --
4405 ------------------------
4407 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
4410 when N_Access_Definition |
4411 N_Access_Function_Definition |
4412 N_Access_Procedure_Definition |
4413 N_Access_To_Object_Definition |
4415 N_Derived_Type_Definition |
4416 N_Function_Specification |
4417 N_Subtype_Declaration
=>
4418 return Null_Exclusion_Present
(N
);
4420 when N_Component_Definition |
4421 N_Formal_Object_Declaration |
4422 N_Object_Renaming_Declaration
=>
4423 if Present
(Subtype_Mark
(N
)) then
4424 return Null_Exclusion_Present
(N
);
4425 else pragma Assert
(Present
(Access_Definition
(N
)));
4426 return Null_Exclusion_Present
(Access_Definition
(N
));
4429 when N_Discriminant_Specification
=>
4430 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
4431 return Null_Exclusion_Present
(Discriminant_Type
(N
));
4433 return Null_Exclusion_Present
(N
);
4436 when N_Object_Declaration
=>
4437 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
4438 return Null_Exclusion_Present
(Object_Definition
(N
));
4440 return Null_Exclusion_Present
(N
);
4443 when N_Parameter_Specification
=>
4444 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
4445 return Null_Exclusion_Present
(Parameter_Type
(N
));
4447 return Null_Exclusion_Present
(N
);
4454 end Has_Null_Exclusion
;
4456 ------------------------
4457 -- Has_Null_Extension --
4458 ------------------------
4460 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
4461 B
: constant Entity_Id
:= Base_Type
(T
);
4466 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
4467 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
4469 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
4471 if Present
(Ext
) then
4472 if Null_Present
(Ext
) then
4475 Comps
:= Component_List
(Ext
);
4477 -- The null component list is rewritten during analysis to
4478 -- include the parent component. Any other component indicates
4479 -- that the extension was not originally null.
4481 return Null_Present
(Comps
)
4482 or else No
(Next
(First
(Component_Items
(Comps
))));
4491 end Has_Null_Extension
;
4493 --------------------------------------
4494 -- Has_Preelaborable_Initialization --
4495 --------------------------------------
4497 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
4500 procedure Check_Components
(E
: Entity_Id
);
4501 -- Check component/discriminant chain, sets Has_PE False if a component
4502 -- or discriminant does not meet the preelaborable initialization rules.
4504 ----------------------
4505 -- Check_Components --
4506 ----------------------
4508 procedure Check_Components
(E
: Entity_Id
) is
4512 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
4513 -- Returns True if and only if the expression denoted by N does not
4514 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4516 ---------------------------------
4517 -- Is_Preelaborable_Expression --
4518 ---------------------------------
4520 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
4524 Comp_Type
: Entity_Id
;
4525 Is_Array_Aggr
: Boolean;
4528 if Is_Static_Expression
(N
) then
4531 elsif Nkind
(N
) = N_Null
then
4534 elsif Nkind
(N
) = N_Attribute_Reference
4536 (Attribute_Name
(N
) = Name_Access
4538 Attribute_Name
(N
) = Name_Unchecked_Access
4540 Attribute_Name
(N
) = Name_Unrestricted_Access
)
4544 elsif Nkind
(N
) = N_Qualified_Expression
then
4545 return Is_Preelaborable_Expression
(Expression
(N
));
4547 -- For aggregates we have to check that each of the associations
4548 -- is preelaborable.
4550 elsif Nkind
(N
) = N_Aggregate
4551 or else Nkind
(N
) = N_Extension_Aggregate
4553 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
4555 if Is_Array_Aggr
then
4556 Comp_Type
:= Component_Type
(Etype
(N
));
4559 -- Check the ancestor part of extension aggregates, which must
4560 -- be either the name of a type that has preelaborable init or
4561 -- an expression that is preelaborable.
4563 if Nkind
(N
) = N_Extension_Aggregate
then
4565 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
4568 if Is_Entity_Name
(Anc_Part
)
4569 and then Is_Type
(Entity
(Anc_Part
))
4571 if not Has_Preelaborable_Initialization
4577 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
4583 -- Check positional associations
4585 Exp
:= First
(Expressions
(N
));
4586 while Present
(Exp
) loop
4587 if not Is_Preelaborable_Expression
(Exp
) then
4594 -- Check named associations
4596 Assn
:= First
(Component_Associations
(N
));
4597 while Present
(Assn
) loop
4598 Choice
:= First
(Choices
(Assn
));
4599 while Present
(Choice
) loop
4600 if Is_Array_Aggr
then
4601 if Nkind
(Choice
) = N_Others_Choice
then
4604 elsif Nkind
(Choice
) = N_Range
then
4605 if not Is_Static_Range
(Choice
) then
4609 elsif not Is_Static_Expression
(Choice
) then
4614 Comp_Type
:= Etype
(Choice
);
4620 -- If the association has a <> at this point, then we have
4621 -- to check whether the component's type has preelaborable
4622 -- initialization. Note that this only occurs when the
4623 -- association's corresponding component does not have a
4624 -- default expression, the latter case having already been
4625 -- expanded as an expression for the association.
4627 if Box_Present
(Assn
) then
4628 if not Has_Preelaborable_Initialization
(Comp_Type
) then
4632 -- In the expression case we check whether the expression
4633 -- is preelaborable.
4636 not Is_Preelaborable_Expression
(Expression
(Assn
))
4644 -- If we get here then aggregate as a whole is preelaborable
4648 -- All other cases are not preelaborable
4653 end Is_Preelaborable_Expression
;
4655 -- Start of processing for Check_Components
4658 -- Loop through entities of record or protected type
4661 while Present
(Ent
) loop
4663 -- We are interested only in components and discriminants
4665 if Ekind
(Ent
) = E_Component
4667 Ekind
(Ent
) = E_Discriminant
4669 -- Get default expression if any. If there is no declaration
4670 -- node, it means we have an internal entity. The parent and
4671 -- tag fields are examples of such entitires. For these cases,
4672 -- we just test the type of the entity.
4674 if Present
(Declaration_Node
(Ent
)) then
4675 Exp
:= Expression
(Declaration_Node
(Ent
));
4680 -- A component has PI if it has no default expression and the
4681 -- component type has PI.
4684 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
4689 -- Require the default expression to be preelaborable
4691 elsif not Is_Preelaborable_Expression
(Exp
) then
4699 end Check_Components
;
4701 -- Start of processing for Has_Preelaborable_Initialization
4704 -- Immediate return if already marked as known preelaborable init. This
4705 -- covers types for which this function has already been called once
4706 -- and returned True (in which case the result is cached), and also
4707 -- types to which a pragma Preelaborable_Initialization applies.
4709 if Known_To_Have_Preelab_Init
(E
) then
4713 -- If the type is a subtype representing a generic actual type, then
4714 -- test whether its base type has preelaborable initialization since
4715 -- the subtype representing the actual does not inherit this attribute
4716 -- from the actual or formal. (but maybe it should???)
4718 if Is_Generic_Actual_Type
(E
) then
4719 return Has_Preelaborable_Initialization
(Base_Type
(E
));
4722 -- Other private types never have preelaborable initialization
4724 if Is_Private_Type
(E
) then
4728 -- Here for all non-private view
4730 -- All elementary types have preelaborable initialization
4732 if Is_Elementary_Type
(E
) then
4735 -- Array types have PI if the component type has PI
4737 elsif Is_Array_Type
(E
) then
4738 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
4740 -- A derived type has preelaborable initialization if its parent type
4741 -- has preelaborable initialization and (in the case of a derived record
4742 -- extension) if the non-inherited components all have preelaborable
4743 -- initialization. However, a user-defined controlled type with an
4744 -- overriding Initialize procedure does not have preelaborable
4747 elsif Is_Derived_Type
(E
) then
4749 -- First check whether ancestor type has preelaborable initialization
4751 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
4753 -- If OK, check extension components (if any)
4755 if Has_PE
and then Is_Record_Type
(E
) then
4756 Check_Components
(First_Entity
(E
));
4759 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4760 -- with a user defined Initialize procedure does not have PI.
4763 and then Is_Controlled
(E
)
4764 and then Present
(Primitive_Operations
(E
))
4770 P
:= First_Elmt
(Primitive_Operations
(E
));
4771 while Present
(P
) loop
4772 if Chars
(Node
(P
)) = Name_Initialize
4773 and then Comes_From_Source
(Node
(P
))
4784 -- Record type has PI if it is non private and all components have PI
4786 elsif Is_Record_Type
(E
) then
4788 Check_Components
(First_Entity
(E
));
4790 -- Protected types must not have entries, and components must meet
4791 -- same set of rules as for record components.
4793 elsif Is_Protected_Type
(E
) then
4794 if Has_Entries
(E
) then
4798 Check_Components
(First_Entity
(E
));
4799 Check_Components
(First_Private_Entity
(E
));
4802 -- Type System.Address always has preelaborable initialization
4804 elsif Is_RTE
(E
, RE_Address
) then
4807 -- In all other cases, type does not have preelaborable initialization
4813 -- If type has preelaborable initialization, cache result
4816 Set_Known_To_Have_Preelab_Init
(E
);
4820 end Has_Preelaborable_Initialization
;
4822 ---------------------------
4823 -- Has_Private_Component --
4824 ---------------------------
4826 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
4827 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
4828 Component
: Entity_Id
;
4831 if Error_Posted
(Type_Id
)
4832 or else Error_Posted
(Btype
)
4837 if Is_Class_Wide_Type
(Btype
) then
4838 Btype
:= Root_Type
(Btype
);
4841 if Is_Private_Type
(Btype
) then
4843 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
4846 if No
(Full_View
(Btype
)) then
4847 return not Is_Generic_Type
(Btype
)
4848 and then not Is_Generic_Type
(Root_Type
(Btype
));
4850 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
4853 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
4857 elsif Is_Array_Type
(Btype
) then
4858 return Has_Private_Component
(Component_Type
(Btype
));
4860 elsif Is_Record_Type
(Btype
) then
4861 Component
:= First_Component
(Btype
);
4862 while Present
(Component
) loop
4863 if Has_Private_Component
(Etype
(Component
)) then
4867 Next_Component
(Component
);
4872 elsif Is_Protected_Type
(Btype
)
4873 and then Present
(Corresponding_Record_Type
(Btype
))
4875 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
4880 end Has_Private_Component
;
4886 function Has_Stream
(T
: Entity_Id
) return Boolean is
4893 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
4896 elsif Is_Array_Type
(T
) then
4897 return Has_Stream
(Component_Type
(T
));
4899 elsif Is_Record_Type
(T
) then
4900 E
:= First_Component
(T
);
4901 while Present
(E
) loop
4902 if Has_Stream
(Etype
(E
)) then
4911 elsif Is_Private_Type
(T
) then
4912 return Has_Stream
(Underlying_Type
(T
));
4919 --------------------------
4920 -- Has_Tagged_Component --
4921 --------------------------
4923 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
4927 if Is_Private_Type
(Typ
)
4928 and then Present
(Underlying_Type
(Typ
))
4930 return Has_Tagged_Component
(Underlying_Type
(Typ
));
4932 elsif Is_Array_Type
(Typ
) then
4933 return Has_Tagged_Component
(Component_Type
(Typ
));
4935 elsif Is_Tagged_Type
(Typ
) then
4938 elsif Is_Record_Type
(Typ
) then
4939 Comp
:= First_Component
(Typ
);
4940 while Present
(Comp
) loop
4941 if Has_Tagged_Component
(Etype
(Comp
)) then
4945 Comp
:= Next_Component
(Typ
);
4953 end Has_Tagged_Component
;
4959 function In_Instance
return Boolean is
4960 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
4966 and then S
/= Standard_Standard
4968 if (Ekind
(S
) = E_Function
4969 or else Ekind
(S
) = E_Package
4970 or else Ekind
(S
) = E_Procedure
)
4971 and then Is_Generic_Instance
(S
)
4973 -- A child instance is always compiled in the context of a parent
4974 -- instance. Nevertheless, the actuals are not analyzed in an
4975 -- instance context. We detect this case by examining the current
4976 -- compilation unit, which must be a child instance, and checking
4977 -- that it is not currently on the scope stack.
4979 if Is_Child_Unit
(Curr_Unit
)
4981 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
4982 = N_Package_Instantiation
4983 and then not In_Open_Scopes
(Curr_Unit
)
4997 ----------------------
4998 -- In_Instance_Body --
4999 ----------------------
5001 function In_Instance_Body
return Boolean is
5007 and then S
/= Standard_Standard
5009 if (Ekind
(S
) = E_Function
5010 or else Ekind
(S
) = E_Procedure
)
5011 and then Is_Generic_Instance
(S
)
5015 elsif Ekind
(S
) = E_Package
5016 and then In_Package_Body
(S
)
5017 and then Is_Generic_Instance
(S
)
5026 end In_Instance_Body
;
5028 -----------------------------
5029 -- In_Instance_Not_Visible --
5030 -----------------------------
5032 function In_Instance_Not_Visible
return Boolean is
5038 and then S
/= Standard_Standard
5040 if (Ekind
(S
) = E_Function
5041 or else Ekind
(S
) = E_Procedure
)
5042 and then Is_Generic_Instance
(S
)
5046 elsif Ekind
(S
) = E_Package
5047 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
5048 and then Is_Generic_Instance
(S
)
5057 end In_Instance_Not_Visible
;
5059 ------------------------------
5060 -- In_Instance_Visible_Part --
5061 ------------------------------
5063 function In_Instance_Visible_Part
return Boolean is
5069 and then S
/= Standard_Standard
5071 if Ekind
(S
) = E_Package
5072 and then Is_Generic_Instance
(S
)
5073 and then not In_Package_Body
(S
)
5074 and then not In_Private_Part
(S
)
5083 end In_Instance_Visible_Part
;
5085 ----------------------
5086 -- In_Packiage_Body --
5087 ----------------------
5089 function In_Package_Body
return Boolean is
5095 and then S
/= Standard_Standard
5097 if Ekind
(S
) = E_Package
5098 and then In_Package_Body
(S
)
5107 end In_Package_Body
;
5109 --------------------------------------
5110 -- In_Subprogram_Or_Concurrent_Unit --
5111 --------------------------------------
5113 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
5118 -- Use scope chain to check successively outer scopes
5124 if K
in Subprogram_Kind
5125 or else K
in Concurrent_Kind
5126 or else K
in Generic_Subprogram_Kind
5130 elsif E
= Standard_Standard
then
5136 end In_Subprogram_Or_Concurrent_Unit
;
5138 ---------------------
5139 -- In_Visible_Part --
5140 ---------------------
5142 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
5145 Is_Package_Or_Generic_Package
(Scope_Id
)
5146 and then In_Open_Scopes
(Scope_Id
)
5147 and then not In_Package_Body
(Scope_Id
)
5148 and then not In_Private_Part
(Scope_Id
);
5149 end In_Visible_Part
;
5151 ---------------------------------
5152 -- Insert_Explicit_Dereference --
5153 ---------------------------------
5155 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
5156 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
5157 Ent
: Entity_Id
:= Empty
;
5164 Save_Interps
(N
, New_Prefix
);
5166 Make_Explicit_Dereference
(Sloc
(N
),
5167 Prefix
=> New_Prefix
));
5169 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
5171 if Is_Overloaded
(New_Prefix
) then
5173 -- The deference is also overloaded, and its interpretations are the
5174 -- designated types of the interpretations of the original node.
5176 Set_Etype
(N
, Any_Type
);
5178 Get_First_Interp
(New_Prefix
, I
, It
);
5179 while Present
(It
.Nam
) loop
5182 if Is_Access_Type
(T
) then
5183 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
5186 Get_Next_Interp
(I
, It
);
5192 -- Prefix is unambiguous: mark the original prefix (which might
5193 -- Come_From_Source) as a reference, since the new (relocated) one
5194 -- won't be taken into account.
5196 if Is_Entity_Name
(New_Prefix
) then
5197 Ent
:= Entity
(New_Prefix
);
5199 -- For a retrieval of a subcomponent of some composite object,
5200 -- retrieve the ultimate entity if there is one.
5202 elsif Nkind
(New_Prefix
) = N_Selected_Component
5203 or else Nkind
(New_Prefix
) = N_Indexed_Component
5205 Pref
:= Prefix
(New_Prefix
);
5206 while Present
(Pref
)
5208 (Nkind
(Pref
) = N_Selected_Component
5209 or else Nkind
(Pref
) = N_Indexed_Component
)
5211 Pref
:= Prefix
(Pref
);
5214 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
5215 Ent
:= Entity
(Pref
);
5219 if Present
(Ent
) then
5220 Generate_Reference
(Ent
, New_Prefix
);
5223 end Insert_Explicit_Dereference
;
5229 function Is_AAMP_Float
(E
: Entity_Id
) return Boolean is
5230 pragma Assert
(Is_Type
(E
));
5232 return AAMP_On_Target
5233 and then Is_Floating_Point_Type
(E
)
5234 and then E
= Base_Type
(E
);
5237 -------------------------
5238 -- Is_Actual_Parameter --
5239 -------------------------
5241 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
5242 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
5246 when N_Parameter_Association
=>
5247 return N
= Explicit_Actual_Parameter
(Parent
(N
));
5249 when N_Function_Call | N_Procedure_Call_Statement
=>
5250 return Is_List_Member
(N
)
5252 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
5257 end Is_Actual_Parameter
;
5259 ---------------------
5260 -- Is_Aliased_View --
5261 ---------------------
5263 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
5267 if Is_Entity_Name
(Obj
) then
5275 or else (Present
(Renamed_Object
(E
))
5276 and then Is_Aliased_View
(Renamed_Object
(E
)))))
5278 or else ((Is_Formal
(E
)
5279 or else Ekind
(E
) = E_Generic_In_Out_Parameter
5280 or else Ekind
(E
) = E_Generic_In_Parameter
)
5281 and then Is_Tagged_Type
(Etype
(E
)))
5283 or else (Is_Concurrent_Type
(E
)
5284 and then In_Open_Scopes
(E
))
5286 -- Current instance of type, either directly or as rewritten
5287 -- reference to the current object.
5289 or else (Is_Entity_Name
(Original_Node
(Obj
))
5290 and then Present
(Entity
(Original_Node
(Obj
)))
5291 and then Is_Type
(Entity
(Original_Node
(Obj
))))
5293 or else (Is_Type
(E
) and then E
= Current_Scope
)
5295 or else (Is_Incomplete_Or_Private_Type
(E
)
5296 and then Full_View
(E
) = Current_Scope
);
5298 elsif Nkind
(Obj
) = N_Selected_Component
then
5299 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
5301 elsif Nkind
(Obj
) = N_Indexed_Component
then
5302 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
5304 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
5306 Has_Aliased_Components
5307 (Designated_Type
(Etype
(Prefix
(Obj
)))));
5309 elsif Nkind
(Obj
) = N_Unchecked_Type_Conversion
5310 or else Nkind
(Obj
) = N_Type_Conversion
5312 return Is_Tagged_Type
(Etype
(Obj
))
5313 and then Is_Aliased_View
(Expression
(Obj
));
5315 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
5316 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
5321 end Is_Aliased_View
;
5323 -------------------------
5324 -- Is_Ancestor_Package --
5325 -------------------------
5327 function Is_Ancestor_Package
5329 E2
: Entity_Id
) return Boolean
5336 and then Par
/= Standard_Standard
5346 end Is_Ancestor_Package
;
5348 ----------------------
5349 -- Is_Atomic_Object --
5350 ----------------------
5352 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
5354 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
5355 -- Determines if given object has atomic components
5357 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
5358 -- If prefix is an implicit dereference, examine designated type
5360 ----------------------
5361 -- Is_Atomic_Prefix --
5362 ----------------------
5364 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
5366 if Is_Access_Type
(Etype
(N
)) then
5368 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
5370 return Object_Has_Atomic_Components
(N
);
5372 end Is_Atomic_Prefix
;
5374 ----------------------------------
5375 -- Object_Has_Atomic_Components --
5376 ----------------------------------
5378 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
5380 if Has_Atomic_Components
(Etype
(N
))
5381 or else Is_Atomic
(Etype
(N
))
5385 elsif Is_Entity_Name
(N
)
5386 and then (Has_Atomic_Components
(Entity
(N
))
5387 or else Is_Atomic
(Entity
(N
)))
5391 elsif Nkind
(N
) = N_Indexed_Component
5392 or else Nkind
(N
) = N_Selected_Component
5394 return Is_Atomic_Prefix
(Prefix
(N
));
5399 end Object_Has_Atomic_Components
;
5401 -- Start of processing for Is_Atomic_Object
5404 if Is_Atomic
(Etype
(N
))
5405 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
5409 elsif Nkind
(N
) = N_Indexed_Component
5410 or else Nkind
(N
) = N_Selected_Component
5412 return Is_Atomic_Prefix
(Prefix
(N
));
5417 end Is_Atomic_Object
;
5419 -------------------------
5420 -- Is_Coextension_Root --
5421 -------------------------
5423 function Is_Coextension_Root
(N
: Node_Id
) return Boolean is
5426 Nkind
(N
) = N_Allocator
5427 and then Present
(Coextensions
(N
))
5429 -- Anonymous access discriminants carry a list of all nested
5430 -- controlled coextensions.
5432 and then not Is_Dynamic_Coextension
(N
)
5433 and then not Is_Static_Coextension
(N
);
5434 end Is_Coextension_Root
;
5436 --------------------------------------
5437 -- Is_Controlling_Limited_Procedure --
5438 --------------------------------------
5440 function Is_Controlling_Limited_Procedure
5441 (Proc_Nam
: Entity_Id
) return Boolean
5443 Param_Typ
: Entity_Id
:= Empty
;
5446 if Ekind
(Proc_Nam
) = E_Procedure
5447 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
5449 Param_Typ
:= Etype
(Parameter_Type
(First
(
5450 Parameter_Specifications
(Parent
(Proc_Nam
)))));
5452 -- In this case where an Itype was created, the procedure call has been
5455 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
5456 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
5458 Present
(Parameter_Associations
5459 (Associated_Node_For_Itype
(Proc_Nam
)))
5462 Etype
(First
(Parameter_Associations
5463 (Associated_Node_For_Itype
(Proc_Nam
))));
5466 if Present
(Param_Typ
) then
5468 Is_Interface
(Param_Typ
)
5469 and then Is_Limited_Record
(Param_Typ
);
5473 end Is_Controlling_Limited_Procedure
;
5475 ----------------------------------------------
5476 -- Is_Dependent_Component_Of_Mutable_Object --
5477 ----------------------------------------------
5479 function Is_Dependent_Component_Of_Mutable_Object
5480 (Object
: Node_Id
) return Boolean
5483 Prefix_Type
: Entity_Id
;
5484 P_Aliased
: Boolean := False;
5487 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
5488 -- Returns True if and only if Comp is declared within a variant part
5490 --------------------------------
5491 -- Is_Declared_Within_Variant --
5492 --------------------------------
5494 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
5495 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
5496 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
5498 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
5499 end Is_Declared_Within_Variant
;
5501 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5504 if Is_Variable
(Object
) then
5506 if Nkind
(Object
) = N_Selected_Component
then
5507 P
:= Prefix
(Object
);
5508 Prefix_Type
:= Etype
(P
);
5510 if Is_Entity_Name
(P
) then
5512 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
5513 Prefix_Type
:= Base_Type
(Prefix_Type
);
5516 if Is_Aliased
(Entity
(P
)) then
5520 -- A discriminant check on a selected component may be
5521 -- expanded into a dereference when removing side-effects.
5522 -- Recover the original node and its type, which may be
5525 elsif Nkind
(P
) = N_Explicit_Dereference
5526 and then not (Comes_From_Source
(P
))
5528 P
:= Original_Node
(P
);
5529 Prefix_Type
:= Etype
(P
);
5532 -- Check for prefix being an aliased component ???
5537 -- A heap object is constrained by its initial value
5539 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5540 -- the dereferenced case, since the access value might denote an
5541 -- unconstrained aliased object, whereas in Ada 95 the designated
5542 -- object is guaranteed to be constrained. A worst-case assumption
5543 -- has to apply in Ada 2005 because we can't tell at compile time
5544 -- whether the object is "constrained by its initial value"
5545 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5546 -- semantic rules -- these rules are acknowledged to need fixing).
5548 if Ada_Version
< Ada_05
then
5549 if Is_Access_Type
(Prefix_Type
)
5550 or else Nkind
(P
) = N_Explicit_Dereference
5555 elsif Ada_Version
>= Ada_05
then
5556 if Is_Access_Type
(Prefix_Type
) then
5557 Prefix_Type
:= Designated_Type
(Prefix_Type
);
5562 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
5564 -- As per AI-0017, the renaming is illegal in a generic body,
5565 -- even if the subtype is indefinite.
5567 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5569 if not Is_Constrained
(Prefix_Type
)
5570 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
5572 (Is_Generic_Type
(Prefix_Type
)
5573 and then Ekind
(Current_Scope
) = E_Generic_Package
5574 and then In_Package_Body
(Current_Scope
)))
5576 and then (Is_Declared_Within_Variant
(Comp
)
5577 or else Has_Discriminant_Dependent_Constraint
(Comp
))
5578 and then (not P_Aliased
or else Ada_Version
>= Ada_05
)
5584 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5588 elsif Nkind
(Object
) = N_Indexed_Component
5589 or else Nkind
(Object
) = N_Slice
5591 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5593 -- A type conversion that Is_Variable is a view conversion:
5594 -- go back to the denoted object.
5596 elsif Nkind
(Object
) = N_Type_Conversion
then
5598 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
5603 end Is_Dependent_Component_Of_Mutable_Object
;
5605 ---------------------
5606 -- Is_Dereferenced --
5607 ---------------------
5609 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
5610 P
: constant Node_Id
:= Parent
(N
);
5613 (Nkind
(P
) = N_Selected_Component
5615 Nkind
(P
) = N_Explicit_Dereference
5617 Nkind
(P
) = N_Indexed_Component
5619 Nkind
(P
) = N_Slice
)
5620 and then Prefix
(P
) = N
;
5621 end Is_Dereferenced
;
5623 ----------------------
5624 -- Is_Descendent_Of --
5625 ----------------------
5627 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
5632 pragma Assert
(Nkind
(T1
) in N_Entity
);
5633 pragma Assert
(Nkind
(T2
) in N_Entity
);
5635 T
:= Base_Type
(T1
);
5637 -- Immediate return if the types match
5642 -- Comment needed here ???
5644 elsif Ekind
(T
) = E_Class_Wide_Type
then
5645 return Etype
(T
) = T2
;
5653 -- Done if we found the type we are looking for
5658 -- Done if no more derivations to check
5665 -- Following test catches error cases resulting from prev errors
5667 elsif No
(Etyp
) then
5670 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
5673 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
5677 T
:= Base_Type
(Etyp
);
5681 raise Program_Error
;
5682 end Is_Descendent_Of
;
5688 function Is_False
(U
: Uint
) return Boolean is
5693 ---------------------------
5694 -- Is_Fixed_Model_Number --
5695 ---------------------------
5697 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
5698 S
: constant Ureal
:= Small_Value
(T
);
5699 M
: Urealp
.Save_Mark
;
5703 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
5706 end Is_Fixed_Model_Number
;
5708 -------------------------------
5709 -- Is_Fully_Initialized_Type --
5710 -------------------------------
5712 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
5714 if Is_Scalar_Type
(Typ
) then
5717 elsif Is_Access_Type
(Typ
) then
5720 elsif Is_Array_Type
(Typ
) then
5721 if Is_Fully_Initialized_Type
(Component_Type
(Typ
)) then
5725 -- An interesting case, if we have a constrained type one of whose
5726 -- bounds is known to be null, then there are no elements to be
5727 -- initialized, so all the elements are initialized!
5729 if Is_Constrained
(Typ
) then
5732 Indx_Typ
: Entity_Id
;
5736 Indx
:= First_Index
(Typ
);
5737 while Present
(Indx
) loop
5738 if Etype
(Indx
) = Any_Type
then
5741 -- If index is a range, use directly
5743 elsif Nkind
(Indx
) = N_Range
then
5744 Lbd
:= Low_Bound
(Indx
);
5745 Hbd
:= High_Bound
(Indx
);
5748 Indx_Typ
:= Etype
(Indx
);
5750 if Is_Private_Type
(Indx_Typ
) then
5751 Indx_Typ
:= Full_View
(Indx_Typ
);
5754 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
5757 Lbd
:= Type_Low_Bound
(Indx_Typ
);
5758 Hbd
:= Type_High_Bound
(Indx_Typ
);
5762 if Compile_Time_Known_Value
(Lbd
)
5763 and then Compile_Time_Known_Value
(Hbd
)
5765 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
5775 -- If no null indexes, then type is not fully initialized
5781 elsif Is_Record_Type
(Typ
) then
5782 if Has_Discriminants
(Typ
)
5784 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
5785 and then Is_Fully_Initialized_Variant
(Typ
)
5790 -- Controlled records are considered to be fully initialized if
5791 -- there is a user defined Initialize routine. This may not be
5792 -- entirely correct, but as the spec notes, we are guessing here
5793 -- what is best from the point of view of issuing warnings.
5795 if Is_Controlled
(Typ
) then
5797 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5800 if Present
(Utyp
) then
5802 Init
: constant Entity_Id
:=
5804 (Underlying_Type
(Typ
), Name_Initialize
));
5808 and then Comes_From_Source
(Init
)
5810 Is_Predefined_File_Name
5811 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
5815 elsif Has_Null_Extension
(Typ
)
5817 Is_Fully_Initialized_Type
5818 (Etype
(Base_Type
(Typ
)))
5827 -- Otherwise see if all record components are initialized
5833 Ent
:= First_Entity
(Typ
);
5834 while Present
(Ent
) loop
5835 if Chars
(Ent
) = Name_uController
then
5838 elsif Ekind
(Ent
) = E_Component
5839 and then (No
(Parent
(Ent
))
5840 or else No
(Expression
(Parent
(Ent
))))
5841 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
5843 -- Special VM case for uTag component, which needs to be
5844 -- defined in this case, but is never initialized as VMs
5845 -- are using other dispatching mechanisms. Ignore this
5846 -- uninitialized case.
5848 and then (VM_Target
= No_VM
5849 or else Chars
(Ent
) /= Name_uTag
)
5858 -- No uninitialized components, so type is fully initialized.
5859 -- Note that this catches the case of no components as well.
5863 elsif Is_Concurrent_Type
(Typ
) then
5866 elsif Is_Private_Type
(Typ
) then
5868 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5874 return Is_Fully_Initialized_Type
(U
);
5881 end Is_Fully_Initialized_Type
;
5883 ----------------------------------
5884 -- Is_Fully_Initialized_Variant --
5885 ----------------------------------
5887 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
5888 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5889 Constraints
: constant List_Id
:= New_List
;
5890 Components
: constant Elist_Id
:= New_Elmt_List
;
5891 Comp_Elmt
: Elmt_Id
;
5893 Comp_List
: Node_Id
;
5895 Discr_Val
: Node_Id
;
5897 Report_Errors
: Boolean;
5898 pragma Warnings
(Off
, Report_Errors
);
5901 if Serious_Errors_Detected
> 0 then
5905 if Is_Record_Type
(Typ
)
5906 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
5907 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
5909 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
5911 Discr
:= First_Discriminant
(Typ
);
5912 while Present
(Discr
) loop
5913 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
5914 Discr_Val
:= Expression
(Parent
(Discr
));
5916 if Present
(Discr_Val
)
5917 and then Is_OK_Static_Expression
(Discr_Val
)
5919 Append_To
(Constraints
,
5920 Make_Component_Association
(Loc
,
5921 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
5922 Expression
=> New_Copy
(Discr_Val
)));
5930 Next_Discriminant
(Discr
);
5935 Comp_List
=> Comp_List
,
5936 Governed_By
=> Constraints
,
5938 Report_Errors
=> Report_Errors
);
5940 -- Check that each component present is fully initialized
5942 Comp_Elmt
:= First_Elmt
(Components
);
5943 while Present
(Comp_Elmt
) loop
5944 Comp_Id
:= Node
(Comp_Elmt
);
5946 if Ekind
(Comp_Id
) = E_Component
5947 and then (No
(Parent
(Comp_Id
))
5948 or else No
(Expression
(Parent
(Comp_Id
))))
5949 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
5954 Next_Elmt
(Comp_Elmt
);
5959 elsif Is_Private_Type
(Typ
) then
5961 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5967 return Is_Fully_Initialized_Variant
(U
);
5973 end Is_Fully_Initialized_Variant
;
5975 ----------------------------
5976 -- Is_Inherited_Operation --
5977 ----------------------------
5979 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
5980 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
5982 pragma Assert
(Is_Overloadable
(E
));
5983 return Kind
= N_Full_Type_Declaration
5984 or else Kind
= N_Private_Extension_Declaration
5985 or else Kind
= N_Subtype_Declaration
5986 or else (Ekind
(E
) = E_Enumeration_Literal
5987 and then Is_Derived_Type
(Etype
(E
)));
5988 end Is_Inherited_Operation
;
5990 -----------------------------
5991 -- Is_Library_Level_Entity --
5992 -----------------------------
5994 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
5996 -- The following is a small optimization, and it also properly handles
5997 -- discriminals, which in task bodies might appear in expressions before
5998 -- the corresponding procedure has been created, and which therefore do
5999 -- not have an assigned scope.
6001 if Ekind
(E
) in Formal_Kind
then
6005 -- Normal test is simply that the enclosing dynamic scope is Standard
6007 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
6008 end Is_Library_Level_Entity
;
6010 ---------------------------------
6011 -- Is_Local_Variable_Reference --
6012 ---------------------------------
6014 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
6016 if not Is_Entity_Name
(Expr
) then
6021 Ent
: constant Entity_Id
:= Entity
(Expr
);
6022 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
6024 if Ekind
(Ent
) /= E_Variable
6026 Ekind
(Ent
) /= E_In_Out_Parameter
6030 return Present
(Sub
) and then Sub
= Current_Subprogram
;
6034 end Is_Local_Variable_Reference
;
6036 -------------------------
6037 -- Is_Object_Reference --
6038 -------------------------
6040 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
6042 if Is_Entity_Name
(N
) then
6043 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
6047 when N_Indexed_Component | N_Slice
=>
6049 Is_Object_Reference
(Prefix
(N
))
6050 or else Is_Access_Type
(Etype
(Prefix
(N
)));
6052 -- In Ada95, a function call is a constant object; a procedure
6055 when N_Function_Call
=>
6056 return Etype
(N
) /= Standard_Void_Type
;
6058 -- A reference to the stream attribute Input is a function call
6060 when N_Attribute_Reference
=>
6061 return Attribute_Name
(N
) = Name_Input
;
6063 when N_Selected_Component
=>
6065 Is_Object_Reference
(Selector_Name
(N
))
6067 (Is_Object_Reference
(Prefix
(N
))
6068 or else Is_Access_Type
(Etype
(Prefix
(N
))));
6070 when N_Explicit_Dereference
=>
6073 -- A view conversion of a tagged object is an object reference
6075 when N_Type_Conversion
=>
6076 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
6077 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
6078 and then Is_Object_Reference
(Expression
(N
));
6080 -- An unchecked type conversion is considered to be an object if
6081 -- the operand is an object (this construction arises only as a
6082 -- result of expansion activities).
6084 when N_Unchecked_Type_Conversion
=>
6091 end Is_Object_Reference
;
6093 -----------------------------------
6094 -- Is_OK_Variable_For_Out_Formal --
6095 -----------------------------------
6097 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
6099 Note_Possible_Modification
(AV
);
6101 -- We must reject parenthesized variable names. The check for
6102 -- Comes_From_Source is present because there are currently
6103 -- cases where the compiler violates this rule (e.g. passing
6104 -- a task object to its controlled Initialize routine).
6106 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
6109 -- A variable is always allowed
6111 elsif Is_Variable
(AV
) then
6114 -- Unchecked conversions are allowed only if they come from the
6115 -- generated code, which sometimes uses unchecked conversions for out
6116 -- parameters in cases where code generation is unaffected. We tell
6117 -- source unchecked conversions by seeing if they are rewrites of an
6118 -- original Unchecked_Conversion function call, or of an explicit
6119 -- conversion of a function call.
6121 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
6122 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
6125 elsif Comes_From_Source
(AV
)
6126 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
6130 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
6131 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
6137 -- Normal type conversions are allowed if argument is a variable
6139 elsif Nkind
(AV
) = N_Type_Conversion
then
6140 if Is_Variable
(Expression
(AV
))
6141 and then Paren_Count
(Expression
(AV
)) = 0
6143 Note_Possible_Modification
(Expression
(AV
));
6146 -- We also allow a non-parenthesized expression that raises
6147 -- constraint error if it rewrites what used to be a variable
6149 elsif Raises_Constraint_Error
(Expression
(AV
))
6150 and then Paren_Count
(Expression
(AV
)) = 0
6151 and then Is_Variable
(Original_Node
(Expression
(AV
)))
6155 -- Type conversion of something other than a variable
6161 -- If this node is rewritten, then test the original form, if that is
6162 -- OK, then we consider the rewritten node OK (for example, if the
6163 -- original node is a conversion, then Is_Variable will not be true
6164 -- but we still want to allow the conversion if it converts a variable).
6166 elsif Original_Node
(AV
) /= AV
then
6167 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
6169 -- All other non-variables are rejected
6174 end Is_OK_Variable_For_Out_Formal
;
6182 E2
: Entity_Id
) return Boolean
6184 Iface_List
: List_Id
;
6185 T
: Entity_Id
:= E2
;
6188 if Is_Concurrent_Type
(T
)
6189 or else Is_Concurrent_Record_Type
(T
)
6191 Iface_List
:= Abstract_Interface_List
(E2
);
6193 if Is_Empty_List
(Iface_List
) then
6197 T
:= Etype
(First
(Iface_List
));
6200 return Is_Ancestor
(E1
, T
);
6203 -----------------------------------
6204 -- Is_Partially_Initialized_Type --
6205 -----------------------------------
6207 function Is_Partially_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
6209 if Is_Scalar_Type
(Typ
) then
6212 elsif Is_Access_Type
(Typ
) then
6215 elsif Is_Array_Type
(Typ
) then
6217 -- If component type is partially initialized, so is array type
6219 if Is_Partially_Initialized_Type
(Component_Type
(Typ
)) then
6222 -- Otherwise we are only partially initialized if we are fully
6223 -- initialized (this is the empty array case, no point in us
6224 -- duplicating that code here).
6227 return Is_Fully_Initialized_Type
(Typ
);
6230 elsif Is_Record_Type
(Typ
) then
6232 -- A discriminated type is always partially initialized
6234 if Has_Discriminants
(Typ
) then
6237 -- A tagged type is always partially initialized
6239 elsif Is_Tagged_Type
(Typ
) then
6242 -- Case of non-discriminated record
6248 Component_Present
: Boolean := False;
6249 -- Set True if at least one component is present. If no
6250 -- components are present, then record type is fully
6251 -- initialized (another odd case, like the null array).
6254 -- Loop through components
6256 Ent
:= First_Entity
(Typ
);
6257 while Present
(Ent
) loop
6258 if Ekind
(Ent
) = E_Component
then
6259 Component_Present
:= True;
6261 -- If a component has an initialization expression then
6262 -- the enclosing record type is partially initialized
6264 if Present
(Parent
(Ent
))
6265 and then Present
(Expression
(Parent
(Ent
)))
6269 -- If a component is of a type which is itself partially
6270 -- initialized, then the enclosing record type is also.
6272 elsif Is_Partially_Initialized_Type
(Etype
(Ent
)) then
6280 -- No initialized components found. If we found any components
6281 -- they were all uninitialized so the result is false.
6283 if Component_Present
then
6286 -- But if we found no components, then all the components are
6287 -- initialized so we consider the type to be initialized.
6295 -- Concurrent types are always fully initialized
6297 elsif Is_Concurrent_Type
(Typ
) then
6300 -- For a private type, go to underlying type. If there is no underlying
6301 -- type then just assume this partially initialized. Not clear if this
6302 -- can happen in a non-error case, but no harm in testing for this.
6304 elsif Is_Private_Type
(Typ
) then
6306 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6311 return Is_Partially_Initialized_Type
(U
);
6315 -- For any other type (are there any?) assume partially initialized
6320 end Is_Partially_Initialized_Type
;
6322 ------------------------------------
6323 -- Is_Potentially_Persistent_Type --
6324 ------------------------------------
6326 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
6331 -- For private type, test corrresponding full type
6333 if Is_Private_Type
(T
) then
6334 return Is_Potentially_Persistent_Type
(Full_View
(T
));
6336 -- Scalar types are potentially persistent
6338 elsif Is_Scalar_Type
(T
) then
6341 -- Record type is potentially persistent if not tagged and the types of
6342 -- all it components are potentially persistent, and no component has
6343 -- an initialization expression.
6345 elsif Is_Record_Type
(T
)
6346 and then not Is_Tagged_Type
(T
)
6347 and then not Is_Partially_Initialized_Type
(T
)
6349 Comp
:= First_Component
(T
);
6350 while Present
(Comp
) loop
6351 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
6360 -- Array type is potentially persistent if its component type is
6361 -- potentially persistent and if all its constraints are static.
6363 elsif Is_Array_Type
(T
) then
6364 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
6368 Indx
:= First_Index
(T
);
6369 while Present
(Indx
) loop
6370 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
6379 -- All other types are not potentially persistent
6384 end Is_Potentially_Persistent_Type
;
6386 -----------------------------
6387 -- Is_RCI_Pkg_Spec_Or_Body --
6388 -----------------------------
6390 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
6392 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
6393 -- Return True if the unit of Cunit is an RCI package declaration
6395 ---------------------------
6396 -- Is_RCI_Pkg_Decl_Cunit --
6397 ---------------------------
6399 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
6400 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
6403 if Nkind
(The_Unit
) /= N_Package_Declaration
then
6407 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
6408 end Is_RCI_Pkg_Decl_Cunit
;
6410 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6413 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
6415 (Nkind
(Unit
(Cunit
)) = N_Package_Body
6416 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
6417 end Is_RCI_Pkg_Spec_Or_Body
;
6419 -----------------------------------------
6420 -- Is_Remote_Access_To_Class_Wide_Type --
6421 -----------------------------------------
6423 function Is_Remote_Access_To_Class_Wide_Type
6424 (E
: Entity_Id
) return Boolean
6428 function Comes_From_Limited_Private_Type_Declaration
6429 (E
: Entity_Id
) return Boolean;
6430 -- Check that the type is declared by a limited type declaration,
6431 -- or else is derived from a Remote_Type ancestor through private
6434 -------------------------------------------------
6435 -- Comes_From_Limited_Private_Type_Declaration --
6436 -------------------------------------------------
6438 function Comes_From_Limited_Private_Type_Declaration
6439 (E
: Entity_Id
) return Boolean
6441 N
: constant Node_Id
:= Declaration_Node
(E
);
6444 if Nkind
(N
) = N_Private_Type_Declaration
6445 and then Limited_Present
(N
)
6450 if Nkind
(N
) = N_Private_Extension_Declaration
then
6452 Comes_From_Limited_Private_Type_Declaration
(Etype
(E
))
6454 (Is_Remote_Types
(Etype
(E
))
6455 and then Is_Limited_Record
(Etype
(E
))
6456 and then Has_Private_Declaration
(Etype
(E
)));
6460 end Comes_From_Limited_Private_Type_Declaration
;
6462 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6465 if not (Is_Remote_Call_Interface
(E
)
6466 or else Is_Remote_Types
(E
))
6467 or else Ekind
(E
) /= E_General_Access_Type
6472 D
:= Designated_Type
(E
);
6474 if Ekind
(D
) /= E_Class_Wide_Type
then
6478 return Comes_From_Limited_Private_Type_Declaration
6479 (Defining_Identifier
(Parent
(D
)));
6480 end Is_Remote_Access_To_Class_Wide_Type
;
6482 -----------------------------------------
6483 -- Is_Remote_Access_To_Subprogram_Type --
6484 -----------------------------------------
6486 function Is_Remote_Access_To_Subprogram_Type
6487 (E
: Entity_Id
) return Boolean
6490 return (Ekind
(E
) = E_Access_Subprogram_Type
6491 or else (Ekind
(E
) = E_Record_Type
6492 and then Present
(Corresponding_Remote_Type
(E
))))
6493 and then (Is_Remote_Call_Interface
(E
)
6494 or else Is_Remote_Types
(E
));
6495 end Is_Remote_Access_To_Subprogram_Type
;
6497 --------------------
6498 -- Is_Remote_Call --
6499 --------------------
6501 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
6503 if Nkind
(N
) /= N_Procedure_Call_Statement
6504 and then Nkind
(N
) /= N_Function_Call
6506 -- An entry call cannot be remote
6510 elsif Nkind
(Name
(N
)) in N_Has_Entity
6511 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
6513 -- A subprogram declared in the spec of a RCI package is remote
6517 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
6518 and then Is_Remote_Access_To_Subprogram_Type
6519 (Etype
(Prefix
(Name
(N
))))
6521 -- The dereference of a RAS is a remote call
6525 elsif Present
(Controlling_Argument
(N
))
6526 and then Is_Remote_Access_To_Class_Wide_Type
6527 (Etype
(Controlling_Argument
(N
)))
6529 -- Any primitive operation call with a controlling argument of
6530 -- a RACW type is a remote call.
6535 -- All other calls are local calls
6540 ----------------------
6541 -- Is_Renamed_Entry --
6542 ----------------------
6544 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
6545 Orig_Node
: Node_Id
:= Empty
;
6546 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
6548 function Is_Entry
(Nam
: Node_Id
) return Boolean;
6549 -- Determine whether Nam is an entry. Traverse selectors
6550 -- if there are nested selected components.
6556 function Is_Entry
(Nam
: Node_Id
) return Boolean is
6558 if Nkind
(Nam
) = N_Selected_Component
then
6559 return Is_Entry
(Selector_Name
(Nam
));
6562 return Ekind
(Entity
(Nam
)) = E_Entry
;
6565 -- Start of processing for Is_Renamed_Entry
6568 if Present
(Alias
(Proc_Nam
)) then
6569 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
6572 -- Look for a rewritten subprogram renaming declaration
6574 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
6575 and then Present
(Original_Node
(Subp_Decl
))
6577 Orig_Node
:= Original_Node
(Subp_Decl
);
6580 -- The rewritten subprogram is actually an entry
6582 if Present
(Orig_Node
)
6583 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
6584 and then Is_Entry
(Name
(Orig_Node
))
6590 end Is_Renamed_Entry
;
6592 ----------------------
6593 -- Is_Selector_Name --
6594 ----------------------
6596 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
6598 if not Is_List_Member
(N
) then
6600 P
: constant Node_Id
:= Parent
(N
);
6601 K
: constant Node_Kind
:= Nkind
(P
);
6604 (K
= N_Expanded_Name
or else
6605 K
= N_Generic_Association
or else
6606 K
= N_Parameter_Association
or else
6607 K
= N_Selected_Component
)
6608 and then Selector_Name
(P
) = N
;
6613 L
: constant List_Id
:= List_Containing
(N
);
6614 P
: constant Node_Id
:= Parent
(L
);
6616 return (Nkind
(P
) = N_Discriminant_Association
6617 and then Selector_Names
(P
) = L
)
6619 (Nkind
(P
) = N_Component_Association
6620 and then Choices
(P
) = L
);
6623 end Is_Selector_Name
;
6629 function Is_Statement
(N
: Node_Id
) return Boolean is
6632 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
6633 or else Nkind
(N
) = N_Procedure_Call_Statement
;
6636 ---------------------------------
6637 -- Is_Synchronized_Tagged_Type --
6638 ---------------------------------
6640 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
6641 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
6644 -- A task or protected type derived from an interface is a tagged type.
6645 -- Such a tagged type is called a synchronized tagged type, as are
6646 -- synchronized interfaces and private extensions whose declaration
6647 -- includes the reserved word synchronized.
6649 return (Is_Tagged_Type
(E
)
6650 and then (Kind
= E_Task_Type
6651 or else Kind
= E_Protected_Type
))
6654 and then Is_Synchronized_Interface
(E
))
6656 (Ekind
(E
) = E_Record_Type_With_Private
6657 and then (Synchronized_Present
(Parent
(E
))
6658 or else Is_Synchronized_Interface
(Etype
(E
))));
6659 end Is_Synchronized_Tagged_Type
;
6665 function Is_Transfer
(N
: Node_Id
) return Boolean is
6666 Kind
: constant Node_Kind
:= Nkind
(N
);
6669 if Kind
= N_Simple_Return_Statement
6671 Kind
= N_Extended_Return_Statement
6673 Kind
= N_Goto_Statement
6675 Kind
= N_Raise_Statement
6677 Kind
= N_Requeue_Statement
6681 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
6682 and then No
(Condition
(N
))
6686 elsif Kind
= N_Procedure_Call_Statement
6687 and then Is_Entity_Name
(Name
(N
))
6688 and then Present
(Entity
(Name
(N
)))
6689 and then No_Return
(Entity
(Name
(N
)))
6693 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
6705 function Is_True
(U
: Uint
) return Boolean is
6714 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
6716 return VM_Target
= CLI_Target
6717 and then Chars
(T
) /= No_Name
6718 and then Get_Name_String
(Chars
(T
)) = "valuetype";
6725 function Is_Variable
(N
: Node_Id
) return Boolean is
6727 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
6728 -- We do the test on the original node, since this is basically a
6729 -- test of syntactic categories, so it must not be disturbed by
6730 -- whatever rewriting might have occurred. For example, an aggregate,
6731 -- which is certainly NOT a variable, could be turned into a variable
6734 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
6735 -- Within a protected function, the private components of the
6736 -- enclosing protected type are constants. A function nested within
6737 -- a (protected) procedure is not itself protected.
6739 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
6740 -- Prefixes can involve implicit dereferences, in which case we
6741 -- must test for the case of a reference of a constant access
6742 -- type, which can never be a variable.
6744 ---------------------------
6745 -- In_Protected_Function --
6746 ---------------------------
6748 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
6749 Prot
: constant Entity_Id
:= Scope
(E
);
6753 if not Is_Protected_Type
(Prot
) then
6757 while Present
(S
) and then S
/= Prot
loop
6758 if Ekind
(S
) = E_Function
6759 and then Scope
(S
) = Prot
6769 end In_Protected_Function
;
6771 ------------------------
6772 -- Is_Variable_Prefix --
6773 ------------------------
6775 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
6777 if Is_Access_Type
(Etype
(P
)) then
6778 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
6780 -- For the case of an indexed component whose prefix has a packed
6781 -- array type, the prefix has been rewritten into a type conversion.
6782 -- Determine variable-ness from the converted expression.
6784 elsif Nkind
(P
) = N_Type_Conversion
6785 and then not Comes_From_Source
(P
)
6786 and then Is_Array_Type
(Etype
(P
))
6787 and then Is_Packed
(Etype
(P
))
6789 return Is_Variable
(Expression
(P
));
6792 return Is_Variable
(P
);
6794 end Is_Variable_Prefix
;
6796 -- Start of processing for Is_Variable
6799 -- Definitely OK if Assignment_OK is set. Since this is something that
6800 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6802 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
6805 -- Normally we go to the original node, but there is one exception
6806 -- where we use the rewritten node, namely when it is an explicit
6807 -- dereference. The generated code may rewrite a prefix which is an
6808 -- access type with an explicit dereference. The dereference is a
6809 -- variable, even though the original node may not be (since it could
6810 -- be a constant of the access type).
6812 -- In Ada 2005 we have a further case to consider: the prefix may be
6813 -- a function call given in prefix notation. The original node appears
6814 -- to be a selected component, but we need to examine the call.
6816 elsif Nkind
(N
) = N_Explicit_Dereference
6817 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
6818 and then Present
(Etype
(Orig_Node
))
6819 and then Is_Access_Type
(Etype
(Orig_Node
))
6821 return Is_Variable_Prefix
(Original_Node
(Prefix
(N
)))
6823 (Nkind
(Orig_Node
) = N_Function_Call
6824 and then not Is_Access_Constant
(Etype
(Prefix
(N
))));
6826 -- A function call is never a variable
6828 elsif Nkind
(N
) = N_Function_Call
then
6831 -- All remaining checks use the original node
6833 elsif Is_Entity_Name
(Orig_Node
)
6834 and then Present
(Entity
(Orig_Node
))
6837 E
: constant Entity_Id
:= Entity
(Orig_Node
);
6838 K
: constant Entity_Kind
:= Ekind
(E
);
6841 return (K
= E_Variable
6842 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
6843 or else (K
= E_Component
6844 and then not In_Protected_Function
(E
))
6845 or else K
= E_Out_Parameter
6846 or else K
= E_In_Out_Parameter
6847 or else K
= E_Generic_In_Out_Parameter
6849 -- Current instance of type:
6851 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
6852 or else (Is_Incomplete_Or_Private_Type
(E
)
6853 and then In_Open_Scopes
(Full_View
(E
)));
6857 case Nkind
(Orig_Node
) is
6858 when N_Indexed_Component | N_Slice
=>
6859 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
6861 when N_Selected_Component
=>
6862 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
6863 and then Is_Variable
(Selector_Name
(Orig_Node
));
6865 -- For an explicit dereference, the type of the prefix cannot
6866 -- be an access to constant or an access to subprogram.
6868 when N_Explicit_Dereference
=>
6870 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
6872 return Is_Access_Type
(Typ
)
6873 and then not Is_Access_Constant
(Root_Type
(Typ
))
6874 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
6877 -- The type conversion is the case where we do not deal with the
6878 -- context dependent special case of an actual parameter. Thus
6879 -- the type conversion is only considered a variable for the
6880 -- purposes of this routine if the target type is tagged. However,
6881 -- a type conversion is considered to be a variable if it does not
6882 -- come from source (this deals for example with the conversions
6883 -- of expressions to their actual subtypes).
6885 when N_Type_Conversion
=>
6886 return Is_Variable
(Expression
(Orig_Node
))
6888 (not Comes_From_Source
(Orig_Node
)
6890 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
6892 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
6894 -- GNAT allows an unchecked type conversion as a variable. This
6895 -- only affects the generation of internal expanded code, since
6896 -- calls to instantiations of Unchecked_Conversion are never
6897 -- considered variables (since they are function calls).
6898 -- This is also true for expression actions.
6900 when N_Unchecked_Type_Conversion
=>
6901 return Is_Variable
(Expression
(Orig_Node
));
6909 ------------------------
6910 -- Is_Volatile_Object --
6911 ------------------------
6913 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
6915 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
6916 -- Determines if given object has volatile components
6918 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
6919 -- If prefix is an implicit dereference, examine designated type
6921 ------------------------
6922 -- Is_Volatile_Prefix --
6923 ------------------------
6925 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
6926 Typ
: constant Entity_Id
:= Etype
(N
);
6929 if Is_Access_Type
(Typ
) then
6931 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
6934 return Is_Volatile
(Dtyp
)
6935 or else Has_Volatile_Components
(Dtyp
);
6939 return Object_Has_Volatile_Components
(N
);
6941 end Is_Volatile_Prefix
;
6943 ------------------------------------
6944 -- Object_Has_Volatile_Components --
6945 ------------------------------------
6947 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
6948 Typ
: constant Entity_Id
:= Etype
(N
);
6951 if Is_Volatile
(Typ
)
6952 or else Has_Volatile_Components
(Typ
)
6956 elsif Is_Entity_Name
(N
)
6957 and then (Has_Volatile_Components
(Entity
(N
))
6958 or else Is_Volatile
(Entity
(N
)))
6962 elsif Nkind
(N
) = N_Indexed_Component
6963 or else Nkind
(N
) = N_Selected_Component
6965 return Is_Volatile_Prefix
(Prefix
(N
));
6970 end Object_Has_Volatile_Components
;
6972 -- Start of processing for Is_Volatile_Object
6975 if Is_Volatile
(Etype
(N
))
6976 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
6980 elsif Nkind
(N
) = N_Indexed_Component
6981 or else Nkind
(N
) = N_Selected_Component
6983 return Is_Volatile_Prefix
(Prefix
(N
));
6988 end Is_Volatile_Object
;
6990 -------------------------
6991 -- Kill_Current_Values --
6992 -------------------------
6994 procedure Kill_Current_Values
6996 Last_Assignment_Only
: Boolean := False)
6999 if Is_Assignable
(Ent
) then
7000 Set_Last_Assignment
(Ent
, Empty
);
7003 if not Last_Assignment_Only
and then Is_Object
(Ent
) then
7005 Set_Current_Value
(Ent
, Empty
);
7007 if not Can_Never_Be_Null
(Ent
) then
7008 Set_Is_Known_Non_Null
(Ent
, False);
7011 Set_Is_Known_Null
(Ent
, False);
7013 end Kill_Current_Values
;
7015 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
7018 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
7019 -- Clear current value for entity E and all entities chained to E
7021 ------------------------------------------
7022 -- Kill_Current_Values_For_Entity_Chain --
7023 ------------------------------------------
7025 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
7029 while Present
(Ent
) loop
7030 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
7033 end Kill_Current_Values_For_Entity_Chain
;
7035 -- Start of processing for Kill_Current_Values
7038 -- Kill all saved checks, a special case of killing saved values
7040 if not Last_Assignment_Only
then
7044 -- Loop through relevant scopes, which includes the current scope and
7045 -- any parent scopes if the current scope is a block or a package.
7050 -- Clear current values of all entities in current scope
7052 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
7054 -- If scope is a package, also clear current values of all
7055 -- private entities in the scope.
7057 if Ekind
(S
) = E_Package
7059 Ekind
(S
) = E_Generic_Package
7061 Is_Concurrent_Type
(S
)
7063 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
7066 -- If this is a not a subprogram, deal with parents
7068 if not Is_Subprogram
(S
) then
7070 exit Scope_Loop
when S
= Standard_Standard
;
7074 end loop Scope_Loop
;
7075 end Kill_Current_Values
;
7077 --------------------------
7078 -- Kill_Size_Check_Code --
7079 --------------------------
7081 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
7083 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
7084 and then Present
(Size_Check_Code
(E
))
7086 Remove
(Size_Check_Code
(E
));
7087 Set_Size_Check_Code
(E
, Empty
);
7089 end Kill_Size_Check_Code
;
7091 --------------------------
7092 -- Known_To_Be_Assigned --
7093 --------------------------
7095 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
7096 P
: constant Node_Id
:= Parent
(N
);
7101 -- Test left side of assignment
7103 when N_Assignment_Statement
=>
7104 return N
= Name
(P
);
7106 -- Function call arguments are never lvalues
7108 when N_Function_Call
=>
7111 -- Positional parameter for procedure or accept call
7113 when N_Procedure_Call_Statement |
7122 Proc
:= Get_Subprogram_Entity
(P
);
7128 -- If we are not a list member, something is strange, so
7129 -- be conservative and return False.
7131 if not Is_List_Member
(N
) then
7135 -- We are going to find the right formal by stepping forward
7136 -- through the formals, as we step backwards in the actuals.
7138 Form
:= First_Formal
(Proc
);
7141 -- If no formal, something is weird, so be conservative
7142 -- and return False.
7153 return Ekind
(Form
) /= E_In_Parameter
;
7156 -- Named parameter for procedure or accept call
7158 when N_Parameter_Association
=>
7164 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7170 -- Loop through formals to find the one that matches
7172 Form
:= First_Formal
(Proc
);
7174 -- If no matching formal, that's peculiar, some kind of
7175 -- previous error, so return False to be conservative.
7181 -- Else test for match
7183 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7184 return Ekind
(Form
) /= E_In_Parameter
;
7191 -- Test for appearing in a conversion that itself appears
7192 -- in an lvalue context, since this should be an lvalue.
7194 when N_Type_Conversion
=>
7195 return Known_To_Be_Assigned
(P
);
7197 -- All other references are definitely not knwon to be modifications
7203 end Known_To_Be_Assigned
;
7209 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
7210 P
: constant Node_Id
:= Parent
(N
);
7215 -- Test left side of assignment
7217 when N_Assignment_Statement
=>
7218 return N
= Name
(P
);
7220 -- Test prefix of component or attribute
7222 when N_Attribute_Reference
=>
7223 return N
= Prefix
(P
)
7224 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
7226 when N_Expanded_Name |
7227 N_Explicit_Dereference |
7228 N_Indexed_Component |
7230 N_Selected_Component |
7232 return N
= Prefix
(P
);
7234 -- Function call arguments are never lvalues
7236 when N_Function_Call
=>
7239 -- Positional parameter for procedure, entry, or accept call
7241 when N_Procedure_Call_Statement |
7242 N_Entry_Call_Statement |
7251 Proc
:= Get_Subprogram_Entity
(P
);
7257 -- If we are not a list member, something is strange, so
7258 -- be conservative and return True.
7260 if not Is_List_Member
(N
) then
7264 -- We are going to find the right formal by stepping forward
7265 -- through the formals, as we step backwards in the actuals.
7267 Form
:= First_Formal
(Proc
);
7270 -- If no formal, something is weird, so be conservative
7282 return Ekind
(Form
) /= E_In_Parameter
;
7285 -- Named parameter for procedure or accept call
7287 when N_Parameter_Association
=>
7293 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7299 -- Loop through formals to find the one that matches
7301 Form
:= First_Formal
(Proc
);
7303 -- If no matching formal, that's peculiar, some kind of
7304 -- previous error, so return True to be conservative.
7310 -- Else test for match
7312 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7313 return Ekind
(Form
) /= E_In_Parameter
;
7320 -- Test for appearing in a conversion that itself appears
7321 -- in an lvalue context, since this should be an lvalue.
7323 when N_Type_Conversion
=>
7324 return May_Be_Lvalue
(P
);
7326 -- Test for appearence in object renaming declaration
7328 when N_Object_Renaming_Declaration
=>
7331 -- All other references are definitely not Lvalues
7339 -----------------------
7340 -- Mark_Coextensions --
7341 -----------------------
7343 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
7344 Is_Dynamic
: Boolean := False;
7346 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
7347 -- Recognize an allocator node and label it as a dynamic coextension
7349 --------------------
7350 -- Mark_Allocator --
7351 --------------------
7353 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
7355 if Nkind
(N
) = N_Allocator
then
7357 Set_Is_Dynamic_Coextension
(N
);
7359 Set_Is_Static_Coextension
(N
);
7366 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
7368 -- Start of processing Mark_Coextensions
7371 case Nkind
(Context_Nod
) is
7372 when N_Assignment_Statement |
7373 N_Simple_Return_Statement
=>
7374 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
7376 when N_Object_Declaration
=>
7377 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
;
7379 -- This routine should not be called for constructs which may not
7380 -- contain coextensions.
7383 raise Program_Error
;
7386 Mark_Allocators
(Root_Nod
);
7387 end Mark_Coextensions
;
7389 ----------------------
7390 -- Needs_One_Actual --
7391 ----------------------
7393 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
7397 if Ada_Version
>= Ada_05
7398 and then Present
(First_Formal
(E
))
7400 Formal
:= Next_Formal
(First_Formal
(E
));
7401 while Present
(Formal
) loop
7402 if No
(Default_Value
(Formal
)) then
7406 Next_Formal
(Formal
);
7414 end Needs_One_Actual
;
7416 -------------------------
7417 -- New_External_Entity --
7418 -------------------------
7420 function New_External_Entity
7421 (Kind
: Entity_Kind
;
7422 Scope_Id
: Entity_Id
;
7423 Sloc_Value
: Source_Ptr
;
7424 Related_Id
: Entity_Id
;
7426 Suffix_Index
: Nat
:= 0;
7427 Prefix
: Character := ' ') return Entity_Id
7429 N
: constant Entity_Id
:=
7430 Make_Defining_Identifier
(Sloc_Value
,
7432 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
7435 Set_Ekind
(N
, Kind
);
7436 Set_Is_Internal
(N
, True);
7437 Append_Entity
(N
, Scope_Id
);
7438 Set_Public_Status
(N
);
7440 if Kind
in Type_Kind
then
7441 Init_Size_Align
(N
);
7445 end New_External_Entity
;
7447 -------------------------
7448 -- New_Internal_Entity --
7449 -------------------------
7451 function New_Internal_Entity
7452 (Kind
: Entity_Kind
;
7453 Scope_Id
: Entity_Id
;
7454 Sloc_Value
: Source_Ptr
;
7455 Id_Char
: Character) return Entity_Id
7457 N
: constant Entity_Id
:=
7458 Make_Defining_Identifier
(Sloc_Value
, New_Internal_Name
(Id_Char
));
7461 Set_Ekind
(N
, Kind
);
7462 Set_Is_Internal
(N
, True);
7463 Append_Entity
(N
, Scope_Id
);
7465 if Kind
in Type_Kind
then
7466 Init_Size_Align
(N
);
7470 end New_Internal_Entity
;
7476 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
7480 -- If we are pointing at a positional parameter, it is a member of
7481 -- a node list (the list of parameters), and the next parameter
7482 -- is the next node on the list, unless we hit a parameter
7483 -- association, in which case we shift to using the chain whose
7484 -- head is the First_Named_Actual in the parent, and then is
7485 -- threaded using the Next_Named_Actual of the Parameter_Association.
7486 -- All this fiddling is because the original node list is in the
7487 -- textual call order, and what we need is the declaration order.
7489 if Is_List_Member
(Actual_Id
) then
7490 N
:= Next
(Actual_Id
);
7492 if Nkind
(N
) = N_Parameter_Association
then
7493 return First_Named_Actual
(Parent
(Actual_Id
));
7499 return Next_Named_Actual
(Parent
(Actual_Id
));
7503 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
7505 Actual_Id
:= Next_Actual
(Actual_Id
);
7508 -----------------------
7509 -- Normalize_Actuals --
7510 -----------------------
7512 -- Chain actuals according to formals of subprogram. If there are no named
7513 -- associations, the chain is simply the list of Parameter Associations,
7514 -- since the order is the same as the declaration order. If there are named
7515 -- associations, then the First_Named_Actual field in the N_Function_Call
7516 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7517 -- node for the parameter that comes first in declaration order. The
7518 -- remaining named parameters are then chained in declaration order using
7519 -- Next_Named_Actual.
7521 -- This routine also verifies that the number of actuals is compatible with
7522 -- the number and default values of formals, but performs no type checking
7523 -- (type checking is done by the caller).
7525 -- If the matching succeeds, Success is set to True and the caller proceeds
7526 -- with type-checking. If the match is unsuccessful, then Success is set to
7527 -- False, and the caller attempts a different interpretation, if there is
7530 -- If the flag Report is on, the call is not overloaded, and a failure to
7531 -- match can be reported here, rather than in the caller.
7533 procedure Normalize_Actuals
7537 Success
: out Boolean)
7539 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7540 Actual
: Node_Id
:= Empty
;
7542 Last
: Node_Id
:= Empty
;
7543 First_Named
: Node_Id
:= Empty
;
7546 Formals_To_Match
: Integer := 0;
7547 Actuals_To_Match
: Integer := 0;
7549 procedure Chain
(A
: Node_Id
);
7550 -- Add named actual at the proper place in the list, using the
7551 -- Next_Named_Actual link.
7553 function Reporting
return Boolean;
7554 -- Determines if an error is to be reported. To report an error, we
7555 -- need Report to be True, and also we do not report errors caused
7556 -- by calls to init procs that occur within other init procs. Such
7557 -- errors must always be cascaded errors, since if all the types are
7558 -- declared correctly, the compiler will certainly build decent calls!
7564 procedure Chain
(A
: Node_Id
) is
7568 -- Call node points to first actual in list
7570 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
7573 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
7577 Set_Next_Named_Actual
(Last
, Empty
);
7584 function Reporting
return Boolean is
7589 elsif not Within_Init_Proc
then
7592 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
7600 -- Start of processing for Normalize_Actuals
7603 if Is_Access_Type
(S
) then
7605 -- The name in the call is a function call that returns an access
7606 -- to subprogram. The designated type has the list of formals.
7608 Formal
:= First_Formal
(Designated_Type
(S
));
7610 Formal
:= First_Formal
(S
);
7613 while Present
(Formal
) loop
7614 Formals_To_Match
:= Formals_To_Match
+ 1;
7615 Next_Formal
(Formal
);
7618 -- Find if there is a named association, and verify that no positional
7619 -- associations appear after named ones.
7621 if Present
(Actuals
) then
7622 Actual
:= First
(Actuals
);
7625 while Present
(Actual
)
7626 and then Nkind
(Actual
) /= N_Parameter_Association
7628 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7632 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
7634 -- Most common case: positional notation, no defaults
7639 elsif Actuals_To_Match
> Formals_To_Match
then
7641 -- Too many actuals: will not work
7644 if Is_Entity_Name
(Name
(N
)) then
7645 Error_Msg_N
("too many arguments in call to&", Name
(N
));
7647 Error_Msg_N
("too many arguments in call", N
);
7655 First_Named
:= Actual
;
7657 while Present
(Actual
) loop
7658 if Nkind
(Actual
) /= N_Parameter_Association
then
7660 ("positional parameters not allowed after named ones", Actual
);
7665 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7671 if Present
(Actuals
) then
7672 Actual
:= First
(Actuals
);
7675 Formal
:= First_Formal
(S
);
7676 while Present
(Formal
) loop
7678 -- Match the formals in order. If the corresponding actual
7679 -- is positional, nothing to do. Else scan the list of named
7680 -- actuals to find the one with the right name.
7683 and then Nkind
(Actual
) /= N_Parameter_Association
7686 Actuals_To_Match
:= Actuals_To_Match
- 1;
7687 Formals_To_Match
:= Formals_To_Match
- 1;
7690 -- For named parameters, search the list of actuals to find
7691 -- one that matches the next formal name.
7693 Actual
:= First_Named
;
7695 while Present
(Actual
) loop
7696 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
7699 Actuals_To_Match
:= Actuals_To_Match
- 1;
7700 Formals_To_Match
:= Formals_To_Match
- 1;
7708 if Ekind
(Formal
) /= E_In_Parameter
7709 or else No
(Default_Value
(Formal
))
7712 if (Comes_From_Source
(S
)
7713 or else Sloc
(S
) = Standard_Location
)
7714 and then Is_Overloadable
(S
)
7718 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
7720 (Nkind
(Parent
(N
)) = N_Function_Call
7722 Nkind
(Parent
(N
)) = N_Parameter_Association
))
7723 and then Ekind
(S
) /= E_Function
7725 Set_Etype
(N
, Etype
(S
));
7727 Error_Msg_Name_1
:= Chars
(S
);
7728 Error_Msg_Sloc
:= Sloc
(S
);
7730 ("missing argument for parameter & " &
7731 "in call to % declared #", N
, Formal
);
7734 elsif Is_Overloadable
(S
) then
7735 Error_Msg_Name_1
:= Chars
(S
);
7737 -- Point to type derivation that generated the
7740 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
7743 ("missing argument for parameter & " &
7744 "in call to % (inherited) #", N
, Formal
);
7748 ("missing argument for parameter &", N
, Formal
);
7756 Formals_To_Match
:= Formals_To_Match
- 1;
7761 Next_Formal
(Formal
);
7764 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
7771 -- Find some superfluous named actual that did not get
7772 -- attached to the list of associations.
7774 Actual
:= First
(Actuals
);
7775 while Present
(Actual
) loop
7776 if Nkind
(Actual
) = N_Parameter_Association
7777 and then Actual
/= Last
7778 and then No
(Next_Named_Actual
(Actual
))
7780 Error_Msg_N
("unmatched actual & in call",
7781 Selector_Name
(Actual
));
7792 end Normalize_Actuals
;
7794 --------------------------------
7795 -- Note_Possible_Modification --
7796 --------------------------------
7798 procedure Note_Possible_Modification
(N
: Node_Id
) is
7799 Modification_Comes_From_Source
: constant Boolean :=
7800 Comes_From_Source
(Parent
(N
));
7806 -- Loop to find referenced entity, if there is one
7813 if Is_Entity_Name
(Exp
) then
7814 Ent
:= Entity
(Exp
);
7816 -- If the entity is missing, it is an undeclared identifier,
7817 -- and there is nothing to annotate.
7823 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
7825 P
: constant Node_Id
:= Prefix
(Exp
);
7828 if Nkind
(P
) = N_Selected_Component
7830 Entry_Formal
(Entity
(Selector_Name
(P
))))
7832 -- Case of a reference to an entry formal
7834 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
7836 elsif Nkind
(P
) = N_Identifier
7837 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
7838 and then Present
(Expression
(Parent
(Entity
(P
))))
7839 and then Nkind
(Expression
(Parent
(Entity
(P
))))
7842 -- Case of a reference to a value on which side effects have
7845 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
7854 elsif Nkind
(Exp
) = N_Type_Conversion
7855 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
7857 Exp
:= Expression
(Exp
);
7860 elsif Nkind
(Exp
) = N_Slice
7861 or else Nkind
(Exp
) = N_Indexed_Component
7862 or else Nkind
(Exp
) = N_Selected_Component
7864 Exp
:= Prefix
(Exp
);
7871 -- Now look for entity being referenced
7873 if Present
(Ent
) then
7874 if Is_Object
(Ent
) then
7875 if Comes_From_Source
(Exp
)
7876 or else Modification_Comes_From_Source
7878 Set_Never_Set_In_Source
(Ent
, False);
7881 Set_Is_True_Constant
(Ent
, False);
7882 Set_Current_Value
(Ent
, Empty
);
7883 Set_Is_Known_Null
(Ent
, False);
7885 if not Can_Never_Be_Null
(Ent
) then
7886 Set_Is_Known_Non_Null
(Ent
, False);
7889 -- Follow renaming chain
7891 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
7892 and then Present
(Renamed_Object
(Ent
))
7894 Exp
:= Renamed_Object
(Ent
);
7898 -- Generate a reference only if the assignment comes from
7899 -- source. This excludes, for example, calls to a dispatching
7900 -- assignment operation when the left-hand side is tagged.
7902 if Modification_Comes_From_Source
then
7903 Generate_Reference
(Ent
, Exp
, 'm');
7906 Check_Nested_Access
(Ent
);
7913 end Note_Possible_Modification
;
7915 -------------------------
7916 -- Object_Access_Level --
7917 -------------------------
7919 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
7922 -- Returns the static accessibility level of the view denoted
7923 -- by Obj. Note that the value returned is the result of a
7924 -- call to Scope_Depth. Only scope depths associated with
7925 -- dynamic scopes can actually be returned. Since only
7926 -- relative levels matter for accessibility checking, the fact
7927 -- that the distance between successive levels of accessibility
7928 -- is not always one is immaterial (invariant: if level(E2) is
7929 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7931 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
7932 -- An explicit dereference is created when removing side-effects
7933 -- from expressions for constraint checking purposes. In this case
7934 -- a local access type is created for it. The correct access level
7935 -- is that of the original source node. We detect this case by
7936 -- noting that the prefix of the dereference is created by an object
7937 -- declaration whose initial expression is a reference.
7943 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
7944 Pref
: constant Node_Id
:= Prefix
(Obj
);
7946 if Is_Entity_Name
(Pref
)
7947 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
7948 and then Present
(Expression
(Parent
(Entity
(Pref
))))
7949 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
7951 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
7957 -- Start of processing for Object_Access_Level
7960 if Is_Entity_Name
(Obj
) then
7963 -- If E is a type then it denotes a current instance.
7964 -- For this case we add one to the normal accessibility
7965 -- level of the type to ensure that current instances
7966 -- are treated as always being deeper than than the level
7967 -- of any visible named access type (see 3.10.2(21)).
7970 return Type_Access_Level
(E
) + 1;
7972 elsif Present
(Renamed_Object
(E
)) then
7973 return Object_Access_Level
(Renamed_Object
(E
));
7975 -- Similarly, if E is a component of the current instance of a
7976 -- protected type, any instance of it is assumed to be at a deeper
7977 -- level than the type. For a protected object (whose type is an
7978 -- anonymous protected type) its components are at the same level
7979 -- as the type itself.
7981 elsif not Is_Overloadable
(E
)
7982 and then Ekind
(Scope
(E
)) = E_Protected_Type
7983 and then Comes_From_Source
(Scope
(E
))
7985 return Type_Access_Level
(Scope
(E
)) + 1;
7988 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
7991 elsif Nkind
(Obj
) = N_Selected_Component
then
7992 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
7993 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
7995 return Object_Access_Level
(Prefix
(Obj
));
7998 elsif Nkind
(Obj
) = N_Indexed_Component
then
7999 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
8000 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8002 return Object_Access_Level
(Prefix
(Obj
));
8005 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
8007 -- If the prefix is a selected access discriminant then
8008 -- we make a recursive call on the prefix, which will
8009 -- in turn check the level of the prefix object of
8010 -- the selected discriminant.
8012 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
8013 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
8015 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
8017 return Object_Access_Level
(Prefix
(Obj
));
8019 elsif not (Comes_From_Source
(Obj
)) then
8021 Ref
: constant Node_Id
:= Reference_To
(Obj
);
8023 if Present
(Ref
) then
8024 return Object_Access_Level
(Ref
);
8026 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8031 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8034 elsif Nkind
(Obj
) = N_Type_Conversion
8035 or else Nkind
(Obj
) = N_Unchecked_Type_Conversion
8037 return Object_Access_Level
(Expression
(Obj
));
8039 -- Function results are objects, so we get either the access level
8040 -- of the function or, in the case of an indirect call, the level of
8041 -- of the access-to-subprogram type.
8043 elsif Nkind
(Obj
) = N_Function_Call
then
8044 if Is_Entity_Name
(Name
(Obj
)) then
8045 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
8047 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
8050 -- For convenience we handle qualified expressions, even though
8051 -- they aren't technically object names.
8053 elsif Nkind
(Obj
) = N_Qualified_Expression
then
8054 return Object_Access_Level
(Expression
(Obj
));
8056 -- Otherwise return the scope level of Standard.
8057 -- (If there are cases that fall through
8058 -- to this point they will be treated as
8059 -- having global accessibility for now. ???)
8062 return Scope_Depth
(Standard_Standard
);
8064 end Object_Access_Level
;
8066 -----------------------
8067 -- Private_Component --
8068 -----------------------
8070 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
8071 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
8073 function Trace_Components
8075 Check
: Boolean) return Entity_Id
;
8076 -- Recursive function that does the work, and checks against circular
8077 -- definition for each subcomponent type.
8079 ----------------------
8080 -- Trace_Components --
8081 ----------------------
8083 function Trace_Components
8085 Check
: Boolean) return Entity_Id
8087 Btype
: constant Entity_Id
:= Base_Type
(T
);
8088 Component
: Entity_Id
;
8090 Candidate
: Entity_Id
:= Empty
;
8093 if Check
and then Btype
= Ancestor
then
8094 Error_Msg_N
("circular type definition", Type_Id
);
8098 if Is_Private_Type
(Btype
)
8099 and then not Is_Generic_Type
(Btype
)
8101 if Present
(Full_View
(Btype
))
8102 and then Is_Record_Type
(Full_View
(Btype
))
8103 and then not Is_Frozen
(Btype
)
8105 -- To indicate that the ancestor depends on a private type,
8106 -- the current Btype is sufficient. However, to check for
8107 -- circular definition we must recurse on the full view.
8109 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
8111 if Candidate
= Any_Type
then
8121 elsif Is_Array_Type
(Btype
) then
8122 return Trace_Components
(Component_Type
(Btype
), True);
8124 elsif Is_Record_Type
(Btype
) then
8125 Component
:= First_Entity
(Btype
);
8126 while Present
(Component
) loop
8128 -- Skip anonymous types generated by constrained components
8130 if not Is_Type
(Component
) then
8131 P
:= Trace_Components
(Etype
(Component
), True);
8134 if P
= Any_Type
then
8142 Next_Entity
(Component
);
8150 end Trace_Components
;
8152 -- Start of processing for Private_Component
8155 return Trace_Components
(Type_Id
, False);
8156 end Private_Component
;
8158 -----------------------
8159 -- Process_End_Label --
8160 -----------------------
8162 procedure Process_End_Label
8170 Label_Ref
: Boolean;
8171 -- Set True if reference to end label itself is required
8174 -- Gets set to the operator symbol or identifier that references
8175 -- the entity Ent. For the child unit case, this is the identifier
8176 -- from the designator. For other cases, this is simply Endl.
8178 procedure Generate_Parent_Ref
(N
: Node_Id
);
8179 -- N is an identifier node that appears as a parent unit reference
8180 -- in the case where Ent is a child unit. This procedure generates
8181 -- an appropriate cross-reference entry.
8183 -------------------------
8184 -- Generate_Parent_Ref --
8185 -------------------------
8187 procedure Generate_Parent_Ref
(N
: Node_Id
) is
8188 Parent_Ent
: Entity_Id
;
8191 -- Search up scope stack. The reason we do this is that normal
8192 -- visibility analysis would not work for two reasons. First in
8193 -- some subunit cases, the entry for the parent unit may not be
8194 -- visible, and in any case there can be a local entity that
8195 -- hides the scope entity.
8197 Parent_Ent
:= Current_Scope
;
8198 while Present
(Parent_Ent
) loop
8199 if Chars
(Parent_Ent
) = Chars
(N
) then
8201 -- Generate the reference. We do NOT consider this as a
8202 -- reference for unreferenced symbol purposes, but we do
8203 -- force a cross-reference even if the end line does not
8204 -- come from source (the caller already generated the
8205 -- appropriate Typ for this situation).
8208 (Parent_Ent
, N
, 'r', Set_Ref
=> False, Force
=> True);
8209 Style
.Check_Identifier
(N
, Parent_Ent
);
8213 Parent_Ent
:= Scope
(Parent_Ent
);
8216 -- Fall through means entity was not found -- that's odd, but
8217 -- the appropriate thing is simply to ignore and not generate
8218 -- any cross-reference for this entry.
8221 end Generate_Parent_Ref
;
8223 -- Start of processing for Process_End_Label
8226 -- If no node, ignore. This happens in some error situations,
8227 -- and also for some internally generated structures where no
8228 -- end label references are required in any case.
8234 -- Nothing to do if no End_Label, happens for internally generated
8235 -- constructs where we don't want an end label reference anyway.
8236 -- Also nothing to do if Endl is a string literal, which means
8237 -- there was some prior error (bad operator symbol)
8239 Endl
:= End_Label
(N
);
8241 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
8245 -- Reference node is not in extended main source unit
8247 if not In_Extended_Main_Source_Unit
(N
) then
8249 -- Generally we do not collect references except for the
8250 -- extended main source unit. The one exception is the 'e'
8251 -- entry for a package spec, where it is useful for a client
8252 -- to have the ending information to define scopes.
8260 -- For this case, we can ignore any parent references,
8261 -- but we need the package name itself for the 'e' entry.
8263 if Nkind
(Endl
) = N_Designator
then
8264 Endl
:= Identifier
(Endl
);
8268 -- Reference is in extended main source unit
8273 -- For designator, generate references for the parent entries
8275 if Nkind
(Endl
) = N_Designator
then
8277 -- Generate references for the prefix if the END line comes
8278 -- from source (otherwise we do not need these references)
8280 if Comes_From_Source
(Endl
) then
8282 while Nkind
(Nam
) = N_Selected_Component
loop
8283 Generate_Parent_Ref
(Selector_Name
(Nam
));
8284 Nam
:= Prefix
(Nam
);
8287 Generate_Parent_Ref
(Nam
);
8290 Endl
:= Identifier
(Endl
);
8294 -- If the end label is not for the given entity, then either we have
8295 -- some previous error, or this is a generic instantiation for which
8296 -- we do not need to make a cross-reference in this case anyway. In
8297 -- either case we simply ignore the call.
8299 if Chars
(Ent
) /= Chars
(Endl
) then
8303 -- If label was really there, then generate a normal reference
8304 -- and then adjust the location in the end label to point past
8305 -- the name (which should almost always be the semicolon).
8309 if Comes_From_Source
(Endl
) then
8311 -- If a label reference is required, then do the style check
8312 -- and generate an l-type cross-reference entry for the label
8316 Style
.Check_Identifier
(Endl
, Ent
);
8318 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
8321 -- Set the location to point past the label (normally this will
8322 -- mean the semicolon immediately following the label). This is
8323 -- done for the sake of the 'e' or 't' entry generated below.
8325 Get_Decoded_Name_String
(Chars
(Endl
));
8326 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
8329 -- Now generate the e/t reference
8331 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
8333 -- Restore Sloc, in case modified above, since we have an identifier
8334 -- and the normal Sloc should be left set in the tree.
8336 Set_Sloc
(Endl
, Loc
);
8337 end Process_End_Label
;
8343 -- We do the conversion to get the value of the real string by using
8344 -- the scanner, see Sinput for details on use of the internal source
8345 -- buffer for scanning internal strings.
8347 function Real_Convert
(S
: String) return Node_Id
is
8348 Save_Src
: constant Source_Buffer_Ptr
:= Source
;
8352 Source
:= Internal_Source_Ptr
;
8355 for J
in S
'Range loop
8356 Source
(Source_Ptr
(J
)) := S
(J
);
8359 Source
(S
'Length + 1) := EOF
;
8361 if Source
(Scan_Ptr
) = '-' then
8363 Scan_Ptr
:= Scan_Ptr
+ 1;
8371 Set_Realval
(Token_Node
, UR_Negate
(Realval
(Token_Node
)));
8378 ---------------------
8379 -- Rep_To_Pos_Flag --
8380 ---------------------
8382 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
8384 return New_Occurrence_Of
8385 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
8386 end Rep_To_Pos_Flag
;
8388 --------------------
8389 -- Require_Entity --
8390 --------------------
8392 procedure Require_Entity
(N
: Node_Id
) is
8394 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
8395 if Total_Errors_Detected
/= 0 then
8396 Set_Entity
(N
, Any_Id
);
8398 raise Program_Error
;
8403 ------------------------------
8404 -- Requires_Transient_Scope --
8405 ------------------------------
8407 -- A transient scope is required when variable-sized temporaries are
8408 -- allocated in the primary or secondary stack, or when finalization
8409 -- actions must be generated before the next instruction.
8411 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
8412 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
8414 -- Start of processing for Requires_Transient_Scope
8417 -- This is a private type which is not completed yet. This can only
8418 -- happen in a default expression (of a formal parameter or of a
8419 -- record component). Do not expand transient scope in this case
8424 -- Do not expand transient scope for non-existent procedure return
8426 elsif Typ
= Standard_Void_Type
then
8429 -- Elementary types do not require a transient scope
8431 elsif Is_Elementary_Type
(Typ
) then
8434 -- Generally, indefinite subtypes require a transient scope, since the
8435 -- back end cannot generate temporaries, since this is not a valid type
8436 -- for declaring an object. It might be possible to relax this in the
8437 -- future, e.g. by declaring the maximum possible space for the type.
8439 elsif Is_Indefinite_Subtype
(Typ
) then
8442 -- Functions returning tagged types may dispatch on result so their
8443 -- returned value is allocated on the secondary stack. Controlled
8444 -- type temporaries need finalization.
8446 elsif Is_Tagged_Type
(Typ
)
8447 or else Has_Controlled_Component
(Typ
)
8449 return not Is_Value_Type
(Typ
);
8453 elsif Is_Record_Type
(Typ
) then
8457 Comp
:= First_Entity
(Typ
);
8458 while Present
(Comp
) loop
8459 if Ekind
(Comp
) = E_Component
8460 and then Requires_Transient_Scope
(Etype
(Comp
))
8471 -- String literal types never require transient scope
8473 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
8476 -- Array type. Note that we already know that this is a constrained
8477 -- array, since unconstrained arrays will fail the indefinite test.
8479 elsif Is_Array_Type
(Typ
) then
8481 -- If component type requires a transient scope, the array does too
8483 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
8486 -- Otherwise, we only need a transient scope if the size is not
8487 -- known at compile time.
8490 return not Size_Known_At_Compile_Time
(Typ
);
8493 -- All other cases do not require a transient scope
8498 end Requires_Transient_Scope
;
8500 --------------------------
8501 -- Reset_Analyzed_Flags --
8502 --------------------------
8504 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
8506 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
8507 -- Function used to reset Analyzed flags in tree. Note that we do
8508 -- not reset Analyzed flags in entities, since there is no need to
8509 -- renalalyze entities, and indeed, it is wrong to do so, since it
8510 -- can result in generating auxiliary stuff more than once.
8512 --------------------
8513 -- Clear_Analyzed --
8514 --------------------
8516 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
8518 if not Has_Extension
(N
) then
8519 Set_Analyzed
(N
, False);
8525 function Reset_Analyzed
is
8526 new Traverse_Func
(Clear_Analyzed
);
8528 Discard
: Traverse_Result
;
8529 pragma Warnings
(Off
, Discard
);
8531 -- Start of processing for Reset_Analyzed_Flags
8534 Discard
:= Reset_Analyzed
(N
);
8535 end Reset_Analyzed_Flags
;
8537 ---------------------------
8538 -- Safe_To_Capture_Value --
8539 ---------------------------
8541 function Safe_To_Capture_Value
8544 Cond
: Boolean := False) return Boolean
8547 -- The only entities for which we track constant values are variables
8548 -- which are not renamings, constants, out parameters, and in out
8549 -- parameters, so check if we have this case.
8551 -- Note: it may seem odd to track constant values for constants, but in
8552 -- fact this routine is used for other purposes than simply capturing
8553 -- the value. In particular, the setting of Known[_Non]_Null.
8555 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
8557 Ekind
(Ent
) = E_Constant
8559 Ekind
(Ent
) = E_Out_Parameter
8561 Ekind
(Ent
) = E_In_Out_Parameter
8565 -- For conditionals, we also allow loop parameters and all formals,
8566 -- including in parameters.
8570 (Ekind
(Ent
) = E_Loop_Parameter
8572 Ekind
(Ent
) = E_In_Parameter
)
8576 -- For all other cases, not just unsafe, but impossible to capture
8577 -- Current_Value, since the above are the only entities which have
8578 -- Current_Value fields.
8584 -- Skip if volatile or aliased, since funny things might be going on in
8585 -- these cases which we cannot necessarily track. Also skip any variable
8586 -- for which an address clause is given, or whose address is taken.
8588 if Treat_As_Volatile
(Ent
)
8589 or else Is_Aliased
(Ent
)
8590 or else Present
(Address_Clause
(Ent
))
8591 or else Address_Taken
(Ent
)
8596 -- OK, all above conditions are met. We also require that the scope of
8597 -- the reference be the same as the scope of the entity, not counting
8598 -- packages and blocks and loops.
8601 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
8602 R_Scope
: Entity_Id
;
8605 R_Scope
:= Current_Scope
;
8606 while R_Scope
/= Standard_Standard
loop
8607 exit when R_Scope
= E_Scope
;
8609 if Ekind
(R_Scope
) /= E_Package
8611 Ekind
(R_Scope
) /= E_Block
8613 Ekind
(R_Scope
) /= E_Loop
8617 R_Scope
:= Scope
(R_Scope
);
8622 -- We also require that the reference does not appear in a context
8623 -- where it is not sure to be executed (i.e. a conditional context
8624 -- or an exception handler). We skip this if Cond is True, since the
8625 -- capturing of values from conditional tests handles this ok.
8639 while Present
(P
) loop
8640 if Nkind
(P
) = N_If_Statement
8641 or else Nkind
(P
) = N_Case_Statement
8642 or else (Nkind
(P
) = N_And_Then
and then Desc
= Right_Opnd
(P
))
8643 or else (Nkind
(P
) = N_Or_Else
and then Desc
= Right_Opnd
(P
))
8644 or else Nkind
(P
) = N_Exception_Handler
8645 or else Nkind
(P
) = N_Selective_Accept
8646 or else Nkind
(P
) = N_Conditional_Entry_Call
8647 or else Nkind
(P
) = N_Timed_Entry_Call
8648 or else Nkind
(P
) = N_Asynchronous_Select
8658 -- OK, looks safe to set value
8661 end Safe_To_Capture_Value
;
8667 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
8668 K1
: constant Node_Kind
:= Nkind
(N1
);
8669 K2
: constant Node_Kind
:= Nkind
(N2
);
8672 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
8673 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
8675 return Chars
(N1
) = Chars
(N2
);
8677 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
8678 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
8680 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
8681 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
8692 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
8693 N1
: constant Node_Id
:= Original_Node
(Node1
);
8694 N2
: constant Node_Id
:= Original_Node
(Node2
);
8695 -- We do the tests on original nodes, since we are most interested
8696 -- in the original source, not any expansion that got in the way.
8698 K1
: constant Node_Kind
:= Nkind
(N1
);
8699 K2
: constant Node_Kind
:= Nkind
(N2
);
8702 -- First case, both are entities with same entity
8704 if K1
in N_Has_Entity
8705 and then K2
in N_Has_Entity
8706 and then Present
(Entity
(N1
))
8707 and then Present
(Entity
(N2
))
8708 and then (Ekind
(Entity
(N1
)) = E_Variable
8710 Ekind
(Entity
(N1
)) = E_Constant
)
8711 and then Entity
(N1
) = Entity
(N2
)
8715 -- Second case, selected component with same selector, same record
8717 elsif K1
= N_Selected_Component
8718 and then K2
= N_Selected_Component
8719 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
8721 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
8723 -- Third case, indexed component with same subscripts, same array
8725 elsif K1
= N_Indexed_Component
8726 and then K2
= N_Indexed_Component
8727 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
8732 E1
:= First
(Expressions
(N1
));
8733 E2
:= First
(Expressions
(N2
));
8734 while Present
(E1
) loop
8735 if not Same_Value
(E1
, E2
) then
8746 -- Fourth case, slice of same array with same bounds
8749 and then K2
= N_Slice
8750 and then Nkind
(Discrete_Range
(N1
)) = N_Range
8751 and then Nkind
(Discrete_Range
(N2
)) = N_Range
8752 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
8753 Low_Bound
(Discrete_Range
(N2
)))
8754 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
8755 High_Bound
(Discrete_Range
(N2
)))
8757 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
8759 -- All other cases, not clearly the same object
8770 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
8775 elsif not Is_Constrained
(T1
)
8776 and then not Is_Constrained
(T2
)
8777 and then Base_Type
(T1
) = Base_Type
(T2
)
8781 -- For now don't bother with case of identical constraints, to be
8782 -- fiddled with later on perhaps (this is only used for optimization
8783 -- purposes, so it is not critical to do a best possible job)
8794 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
8796 if Compile_Time_Known_Value
(Node1
)
8797 and then Compile_Time_Known_Value
(Node2
)
8798 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
8801 elsif Same_Object
(Node1
, Node2
) then
8808 ------------------------
8809 -- Scope_Is_Transient --
8810 ------------------------
8812 function Scope_Is_Transient
return Boolean is
8814 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
8815 end Scope_Is_Transient
;
8821 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
8826 while Scop
/= Standard_Standard
loop
8827 Scop
:= Scope
(Scop
);
8829 if Scop
= Scope2
then
8837 --------------------------
8838 -- Scope_Within_Or_Same --
8839 --------------------------
8841 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
8846 while Scop
/= Standard_Standard
loop
8847 if Scop
= Scope2
then
8850 Scop
:= Scope
(Scop
);
8855 end Scope_Within_Or_Same
;
8857 ------------------------
8858 -- Set_Current_Entity --
8859 ------------------------
8861 -- The given entity is to be set as the currently visible definition
8862 -- of its associated name (i.e. the Node_Id associated with its name).
8863 -- All we have to do is to get the name from the identifier, and
8864 -- then set the associated Node_Id to point to the given entity.
8866 procedure Set_Current_Entity
(E
: Entity_Id
) is
8868 Set_Name_Entity_Id
(Chars
(E
), E
);
8869 end Set_Current_Entity
;
8871 ---------------------------------
8872 -- Set_Entity_With_Style_Check --
8873 ---------------------------------
8875 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
8876 Val_Actual
: Entity_Id
;
8880 Set_Entity
(N
, Val
);
8883 and then not Suppress_Style_Checks
(Val
)
8884 and then not In_Instance
8886 if Nkind
(N
) = N_Identifier
then
8888 elsif Nkind
(N
) = N_Expanded_Name
then
8889 Nod
:= Selector_Name
(N
);
8894 -- A special situation arises for derived operations, where we want
8895 -- to do the check against the parent (since the Sloc of the derived
8896 -- operation points to the derived type declaration itself).
8899 while not Comes_From_Source
(Val_Actual
)
8900 and then Nkind
(Val_Actual
) in N_Entity
8901 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
8902 or else Is_Subprogram
(Val_Actual
)
8903 or else Is_Generic_Subprogram
(Val_Actual
))
8904 and then Present
(Alias
(Val_Actual
))
8906 Val_Actual
:= Alias
(Val_Actual
);
8909 -- Renaming declarations for generic actuals do not come from source,
8910 -- and have a different name from that of the entity they rename, so
8911 -- there is no style check to perform here.
8913 if Chars
(Nod
) = Chars
(Val_Actual
) then
8914 Style
.Check_Identifier
(Nod
, Val_Actual
);
8918 Set_Entity
(N
, Val
);
8919 end Set_Entity_With_Style_Check
;
8921 ------------------------
8922 -- Set_Name_Entity_Id --
8923 ------------------------
8925 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
8927 Set_Name_Table_Info
(Id
, Int
(Val
));
8928 end Set_Name_Entity_Id
;
8930 ---------------------
8931 -- Set_Next_Actual --
8932 ---------------------
8934 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
8936 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
8937 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
8939 end Set_Next_Actual
;
8941 -----------------------
8942 -- Set_Public_Status --
8943 -----------------------
8945 procedure Set_Public_Status
(Id
: Entity_Id
) is
8946 S
: constant Entity_Id
:= Current_Scope
;
8949 -- Everything in the scope of Standard is public
8951 if S
= Standard_Standard
then
8954 -- Entity is definitely not public if enclosing scope is not public
8956 elsif not Is_Public
(S
) then
8959 -- An object declaration that occurs in a handled sequence of statements
8960 -- is the declaration for a temporary object generated by the expander.
8961 -- It never needs to be made public and furthermore, making it public
8962 -- can cause back end problems if it is of variable size.
8964 elsif Nkind
(Parent
(Id
)) = N_Object_Declaration
8966 Nkind
(Parent
(Parent
(Id
))) = N_Handled_Sequence_Of_Statements
8970 -- Entities in public packages or records are public
8972 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
8975 -- The bounds of an entry family declaration can generate object
8976 -- declarations that are visible to the back-end, e.g. in the
8977 -- the declaration of a composite type that contains tasks.
8979 elsif Is_Concurrent_Type
(S
)
8980 and then not Has_Completion
(S
)
8981 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
8985 end Set_Public_Status
;
8987 ----------------------------
8988 -- Set_Scope_Is_Transient --
8989 ----------------------------
8991 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
8993 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
8994 end Set_Scope_Is_Transient
;
9000 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
9002 -- We copy Esize, but not RM_Size, since in general RM_Size is
9003 -- subtype specific and does not get inherited by all subtypes.
9005 Set_Esize
(T1
, Esize
(T2
));
9006 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
9008 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
9010 Is_Discrete_Or_Fixed_Point_Type
(T2
)
9012 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
9015 Set_Alignment
(T1
, Alignment
(T2
));
9018 --------------------
9019 -- Static_Integer --
9020 --------------------
9022 function Static_Integer
(N
: Node_Id
) return Uint
is
9024 Analyze_And_Resolve
(N
, Any_Integer
);
9027 or else Error_Posted
(N
)
9028 or else Etype
(N
) = Any_Type
9033 if Is_Static_Expression
(N
) then
9034 if not Raises_Constraint_Error
(N
) then
9035 return Expr_Value
(N
);
9040 elsif Etype
(N
) = Any_Type
then
9044 Flag_Non_Static_Expr
9045 ("static integer expression required here", N
);
9050 --------------------------
9051 -- Statically_Different --
9052 --------------------------
9054 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
9055 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
9056 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
9058 return Is_Entity_Name
(R1
)
9059 and then Is_Entity_Name
(R2
)
9060 and then Entity
(R1
) /= Entity
(R2
)
9061 and then not Is_Formal
(Entity
(R1
))
9062 and then not Is_Formal
(Entity
(R2
));
9063 end Statically_Different
;
9065 -----------------------------
9066 -- Subprogram_Access_Level --
9067 -----------------------------
9069 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
9071 if Present
(Alias
(Subp
)) then
9072 return Subprogram_Access_Level
(Alias
(Subp
));
9074 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
9076 end Subprogram_Access_Level
;
9082 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
9084 if Debug_Flag_W
then
9085 for J
in 0 .. Scope_Stack
.Last
loop
9090 Write_Name
(Chars
(E
));
9091 Write_Str
(" line ");
9092 Write_Int
(Int
(Get_Logical_Line_Number
(Sloc
(N
))));
9097 -----------------------
9098 -- Transfer_Entities --
9099 -----------------------
9101 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
9102 Ent
: Entity_Id
:= First_Entity
(From
);
9109 if (Last_Entity
(To
)) = Empty
then
9110 Set_First_Entity
(To
, Ent
);
9112 Set_Next_Entity
(Last_Entity
(To
), Ent
);
9115 Set_Last_Entity
(To
, Last_Entity
(From
));
9117 while Present
(Ent
) loop
9118 Set_Scope
(Ent
, To
);
9120 if not Is_Public
(Ent
) then
9121 Set_Public_Status
(Ent
);
9124 and then Ekind
(Ent
) = E_Record_Subtype
9127 -- The components of the propagated Itype must be public
9133 Comp
:= First_Entity
(Ent
);
9134 while Present
(Comp
) loop
9135 Set_Is_Public
(Comp
);
9145 Set_First_Entity
(From
, Empty
);
9146 Set_Last_Entity
(From
, Empty
);
9147 end Transfer_Entities
;
9149 -----------------------
9150 -- Type_Access_Level --
9151 -----------------------
9153 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
9157 Btyp
:= Base_Type
(Typ
);
9159 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9160 -- simply use the level where the type is declared. This is true for
9161 -- stand-alone object declarations, and for anonymous access types
9162 -- associated with components the level is the same as that of the
9163 -- enclosing composite type. However, special treatment is needed for
9164 -- the cases of access parameters, return objects of an anonymous access
9165 -- type, and, in Ada 95, access discriminants of limited types.
9167 if Ekind
(Btyp
) in Access_Kind
then
9168 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
9170 -- If the type is a nonlocal anonymous access type (such as for
9171 -- an access parameter) we treat it as being declared at the
9172 -- library level to ensure that names such as X.all'access don't
9173 -- fail static accessibility checks.
9175 if not Is_Local_Anonymous_Access
(Typ
) then
9176 return Scope_Depth
(Standard_Standard
);
9178 -- If this is a return object, the accessibility level is that of
9179 -- the result subtype of the enclosing function. The test here is
9180 -- little complicated, because we have to account for extended
9181 -- return statements that have been rewritten as blocks, in which
9182 -- case we have to find and the Is_Return_Object attribute of the
9183 -- itype's associated object. It would be nice to find a way to
9184 -- simplify this test, but it doesn't seem worthwhile to add a new
9185 -- flag just for purposes of this test. ???
9187 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
9190 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
9191 N_Object_Declaration
9192 and then Is_Return_Object
9193 (Defining_Identifier
9194 (Associated_Node_For_Itype
(Btyp
))))
9200 Scop
:= Scope
(Scope
(Btyp
));
9201 while Present
(Scop
) loop
9202 exit when Ekind
(Scop
) = E_Function
;
9203 Scop
:= Scope
(Scop
);
9206 -- Treat the return object's type as having the level of the
9207 -- function's result subtype (as per RM05-6.5(5.3/2)).
9209 return Type_Access_Level
(Etype
(Scop
));
9214 Btyp
:= Root_Type
(Btyp
);
9216 -- The accessibility level of anonymous acccess types associated with
9217 -- discriminants is that of the current instance of the type, and
9218 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9220 -- AI-402: access discriminants have accessibility based on the
9221 -- object rather than the type in Ada 2005, so the above paragraph
9224 -- ??? Needs completion with rules from AI-416
9226 if Ada_Version
<= Ada_95
9227 and then Ekind
(Typ
) = E_Anonymous_Access_Type
9228 and then Present
(Associated_Node_For_Itype
(Typ
))
9229 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
9230 N_Discriminant_Specification
9232 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
9236 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
9237 end Type_Access_Level
;
9239 --------------------------
9240 -- Unit_Declaration_Node --
9241 --------------------------
9243 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
9244 N
: Node_Id
:= Parent
(Unit_Id
);
9247 -- Predefined operators do not have a full function declaration
9249 if Ekind
(Unit_Id
) = E_Operator
then
9253 -- Isn't there some better way to express the following ???
9255 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
9256 and then Nkind
(N
) /= N_Formal_Package_Declaration
9257 and then Nkind
(N
) /= N_Function_Instantiation
9258 and then Nkind
(N
) /= N_Generic_Package_Declaration
9259 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
9260 and then Nkind
(N
) /= N_Package_Declaration
9261 and then Nkind
(N
) /= N_Package_Body
9262 and then Nkind
(N
) /= N_Package_Instantiation
9263 and then Nkind
(N
) /= N_Package_Renaming_Declaration
9264 and then Nkind
(N
) /= N_Procedure_Instantiation
9265 and then Nkind
(N
) /= N_Protected_Body
9266 and then Nkind
(N
) /= N_Subprogram_Declaration
9267 and then Nkind
(N
) /= N_Subprogram_Body
9268 and then Nkind
(N
) /= N_Subprogram_Body_Stub
9269 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
9270 and then Nkind
(N
) /= N_Task_Body
9271 and then Nkind
(N
) /= N_Task_Type_Declaration
9272 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
9273 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
9276 pragma Assert
(Present
(N
));
9280 end Unit_Declaration_Node
;
9282 ------------------------------
9283 -- Universal_Interpretation --
9284 ------------------------------
9286 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
9287 Index
: Interp_Index
;
9291 -- The argument may be a formal parameter of an operator or subprogram
9292 -- with multiple interpretations, or else an expression for an actual.
9294 if Nkind
(Opnd
) = N_Defining_Identifier
9295 or else not Is_Overloaded
(Opnd
)
9297 if Etype
(Opnd
) = Universal_Integer
9298 or else Etype
(Opnd
) = Universal_Real
9300 return Etype
(Opnd
);
9306 Get_First_Interp
(Opnd
, Index
, It
);
9307 while Present
(It
.Typ
) loop
9308 if It
.Typ
= Universal_Integer
9309 or else It
.Typ
= Universal_Real
9314 Get_Next_Interp
(Index
, It
);
9319 end Universal_Interpretation
;
9325 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
9327 -- Recurse to handle unlikely case of multiple levels of qualification
9329 if Nkind
(Expr
) = N_Qualified_Expression
then
9330 return Unqualify
(Expression
(Expr
));
9332 -- Normal case, not a qualified expression
9339 ----------------------
9340 -- Within_Init_Proc --
9341 ----------------------
9343 function Within_Init_Proc
return Boolean is
9348 while not Is_Overloadable
(S
) loop
9349 if S
= Standard_Standard
then
9356 return Is_Init_Proc
(S
);
9357 end Within_Init_Proc
;
9363 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
9364 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
9365 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
9367 function Has_One_Matching_Field
return Boolean;
9368 -- Determines if Expec_Type is a record type with a single component or
9369 -- discriminant whose type matches the found type or is one dimensional
9370 -- array whose component type matches the found type.
9372 ----------------------------
9373 -- Has_One_Matching_Field --
9374 ----------------------------
9376 function Has_One_Matching_Field
return Boolean is
9380 if Is_Array_Type
(Expec_Type
)
9381 and then Number_Dimensions
(Expec_Type
) = 1
9383 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
9387 elsif not Is_Record_Type
(Expec_Type
) then
9391 E
:= First_Entity
(Expec_Type
);
9396 elsif (Ekind
(E
) /= E_Discriminant
9397 and then Ekind
(E
) /= E_Component
)
9398 or else (Chars
(E
) = Name_uTag
9399 or else Chars
(E
) = Name_uParent
)
9408 if not Covers
(Etype
(E
), Found_Type
) then
9411 elsif Present
(Next_Entity
(E
)) then
9418 end Has_One_Matching_Field
;
9420 -- Start of processing for Wrong_Type
9423 -- Don't output message if either type is Any_Type, or if a message
9424 -- has already been posted for this node. We need to do the latter
9425 -- check explicitly (it is ordinarily done in Errout), because we
9426 -- are using ! to force the output of the error messages.
9428 if Expec_Type
= Any_Type
9429 or else Found_Type
= Any_Type
9430 or else Error_Posted
(Expr
)
9434 -- In an instance, there is an ongoing problem with completion of
9435 -- type derived from private types. Their structure is what Gigi
9436 -- expects, but the Etype is the parent type rather than the
9437 -- derived private type itself. Do not flag error in this case. The
9438 -- private completion is an entity without a parent, like an Itype.
9439 -- Similarly, full and partial views may be incorrect in the instance.
9440 -- There is no simple way to insure that it is consistent ???
9442 elsif In_Instance
then
9443 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
9445 (Has_Private_Declaration
(Expected_Type
)
9446 or else Has_Private_Declaration
(Etype
(Expr
)))
9447 and then No
(Parent
(Expected_Type
))
9453 -- An interesting special check. If the expression is parenthesized
9454 -- and its type corresponds to the type of the sole component of the
9455 -- expected record type, or to the component type of the expected one
9456 -- dimensional array type, then assume we have a bad aggregate attempt.
9458 if Nkind
(Expr
) in N_Subexpr
9459 and then Paren_Count
(Expr
) /= 0
9460 and then Has_One_Matching_Field
9462 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
9464 -- Another special check, if we are looking for a pool-specific access
9465 -- type and we found an E_Access_Attribute_Type, then we have the case
9466 -- of an Access attribute being used in a context which needs a pool-
9467 -- specific type, which is never allowed. The one extra check we make
9468 -- is that the expected designated type covers the Found_Type.
9470 elsif Is_Access_Type
(Expec_Type
)
9471 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
9472 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
9473 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
9475 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
9477 Error_Msg_N
("result must be general access type!", Expr
);
9478 Error_Msg_NE
("add ALL to }!", Expr
, Expec_Type
);
9480 -- Another special check, if the expected type is an integer type,
9481 -- but the expression is of type System.Address, and the parent is
9482 -- an addition or subtraction operation whose left operand is the
9483 -- expression in question and whose right operand is of an integral
9484 -- type, then this is an attempt at address arithmetic, so give
9485 -- appropriate message.
9487 elsif Is_Integer_Type
(Expec_Type
)
9488 and then Is_RTE
(Found_Type
, RE_Address
)
9489 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
9491 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
9492 and then Expr
= Left_Opnd
(Parent
(Expr
))
9493 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
9496 ("address arithmetic not predefined in package System",
9499 ("\possible missing with/use of System.Storage_Elements",
9503 -- If the expected type is an anonymous access type, as for access
9504 -- parameters and discriminants, the error is on the designated types.
9506 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
9507 if Comes_From_Source
(Expec_Type
) then
9508 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
9511 ("expected an access type with designated}",
9512 Expr
, Designated_Type
(Expec_Type
));
9515 if Is_Access_Type
(Found_Type
)
9516 and then not Comes_From_Source
(Found_Type
)
9519 ("\\found an access type with designated}!",
9520 Expr
, Designated_Type
(Found_Type
));
9522 if From_With_Type
(Found_Type
) then
9523 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
9524 Error_Msg_Qual_Level
:= 99;
9525 Error_Msg_NE
("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
9526 Error_Msg_Qual_Level
:= 0;
9528 Error_Msg_NE
("found}!", Expr
, Found_Type
);
9532 -- Normal case of one type found, some other type expected
9535 -- If the names of the two types are the same, see if some number
9536 -- of levels of qualification will help. Don't try more than three
9537 -- levels, and if we get to standard, it's no use (and probably
9538 -- represents an error in the compiler) Also do not bother with
9539 -- internal scope names.
9542 Expec_Scope
: Entity_Id
;
9543 Found_Scope
: Entity_Id
;
9546 Expec_Scope
:= Expec_Type
;
9547 Found_Scope
:= Found_Type
;
9549 for Levels
in Int
range 0 .. 3 loop
9550 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
9551 Error_Msg_Qual_Level
:= Levels
;
9555 Expec_Scope
:= Scope
(Expec_Scope
);
9556 Found_Scope
:= Scope
(Found_Scope
);
9558 exit when Expec_Scope
= Standard_Standard
9559 or else Found_Scope
= Standard_Standard
9560 or else not Comes_From_Source
(Expec_Scope
)
9561 or else not Comes_From_Source
(Found_Scope
);
9565 if Is_Record_Type
(Expec_Type
)
9566 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
9568 Error_Msg_NE
("expected}!", Expr
,
9569 Corresponding_Remote_Type
(Expec_Type
));
9571 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
9574 if Is_Entity_Name
(Expr
)
9575 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
9577 Error_Msg_N
("\\found package name!", Expr
);
9579 elsif Is_Entity_Name
(Expr
)
9581 (Ekind
(Entity
(Expr
)) = E_Procedure
9583 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
9585 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
9587 ("found procedure name, possibly missing Access attribute!",
9591 ("\\found procedure name instead of function!", Expr
);
9594 elsif Nkind
(Expr
) = N_Function_Call
9595 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
9596 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
9597 and then No
(Parameter_Associations
(Expr
))
9600 ("found function name, possibly missing Access attribute!",
9603 -- Catch common error: a prefix or infix operator which is not
9604 -- directly visible because the type isn't.
9606 elsif Nkind
(Expr
) in N_Op
9607 and then Is_Overloaded
(Expr
)
9608 and then not Is_Immediately_Visible
(Expec_Type
)
9609 and then not Is_Potentially_Use_Visible
(Expec_Type
)
9610 and then not In_Use
(Expec_Type
)
9611 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
9614 ("operator of the type is not directly visible!", Expr
);
9616 elsif Ekind
(Found_Type
) = E_Void
9617 and then Present
(Parent
(Found_Type
))
9618 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
9620 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
9623 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
9626 Error_Msg_Qual_Level
:= 0;