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 Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
2196 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
2198 elsif Ekind
(Dynamic_Scope
) = E_Block
2199 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
2201 return Enclosing_Subprogram
(Dynamic_Scope
);
2203 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
2204 return Get_Task_Body_Procedure
(Dynamic_Scope
);
2206 elsif Convention
(Dynamic_Scope
) = Convention_Protected
then
2207 return Protected_Body_Subprogram
(Dynamic_Scope
);
2210 return Dynamic_Scope
;
2212 end Enclosing_Subprogram
;
2214 ------------------------
2215 -- Ensure_Freeze_Node --
2216 ------------------------
2218 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
2222 if No
(Freeze_Node
(E
)) then
2223 FN
:= Make_Freeze_Entity
(Sloc
(E
));
2224 Set_Has_Delayed_Freeze
(E
);
2225 Set_Freeze_Node
(E
, FN
);
2226 Set_Access_Types_To_Process
(FN
, No_Elist
);
2227 Set_TSS_Elist
(FN
, No_Elist
);
2230 end Ensure_Freeze_Node
;
2236 procedure Enter_Name
(Def_Id
: Entity_Id
) is
2237 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
2238 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
2239 S
: constant Entity_Id
:= Current_Scope
;
2241 function Is_Private_Component_Renaming
(N
: Node_Id
) return Boolean;
2242 -- Recognize a renaming declaration that is introduced for private
2243 -- components of a protected type. We treat these as weak declarations
2244 -- so that they are overridden by entities with the same name that
2245 -- come from source, such as formals or local variables of a given
2246 -- protected declaration.
2248 -----------------------------------
2249 -- Is_Private_Component_Renaming --
2250 -----------------------------------
2252 function Is_Private_Component_Renaming
(N
: Node_Id
) return Boolean is
2254 return not Comes_From_Source
(N
)
2255 and then not Comes_From_Source
(Current_Scope
)
2256 and then Nkind
(N
) = N_Object_Renaming_Declaration
;
2257 end Is_Private_Component_Renaming
;
2259 -- Start of processing for Enter_Name
2262 Generate_Definition
(Def_Id
);
2264 -- Add new name to current scope declarations. Check for duplicate
2265 -- declaration, which may or may not be a genuine error.
2269 -- Case of previous entity entered because of a missing declaration
2270 -- or else a bad subtype indication. Best is to use the new entity,
2271 -- and make the previous one invisible.
2273 if Etype
(E
) = Any_Type
then
2274 Set_Is_Immediately_Visible
(E
, False);
2276 -- Case of renaming declaration constructed for package instances.
2277 -- if there is an explicit declaration with the same identifier,
2278 -- the renaming is not immediately visible any longer, but remains
2279 -- visible through selected component notation.
2281 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
2282 and then not Comes_From_Source
(E
)
2284 Set_Is_Immediately_Visible
(E
, False);
2286 -- The new entity may be the package renaming, which has the same
2287 -- same name as a generic formal which has been seen already.
2289 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
2290 and then not Comes_From_Source
(Def_Id
)
2292 Set_Is_Immediately_Visible
(E
, False);
2294 -- For a fat pointer corresponding to a remote access to subprogram,
2295 -- we use the same identifier as the RAS type, so that the proper
2296 -- name appears in the stub. This type is only retrieved through
2297 -- the RAS type and never by visibility, and is not added to the
2298 -- visibility list (see below).
2300 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
2301 and then Present
(Corresponding_Remote_Type
(Def_Id
))
2305 -- A controller component for a type extension overrides the
2306 -- inherited component.
2308 elsif Chars
(E
) = Name_uController
then
2311 -- Case of an implicit operation or derived literal. The new entity
2312 -- hides the implicit one, which is removed from all visibility,
2313 -- i.e. the entity list of its scope, and homonym chain of its name.
2315 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
2316 or else Is_Internal
(E
)
2320 Prev_Vis
: Entity_Id
;
2321 Decl
: constant Node_Id
:= Parent
(E
);
2324 -- If E is an implicit declaration, it cannot be the first
2325 -- entity in the scope.
2327 Prev
:= First_Entity
(Current_Scope
);
2328 while Present
(Prev
)
2329 and then Next_Entity
(Prev
) /= E
2336 -- If E is not on the entity chain of the current scope,
2337 -- it is an implicit declaration in the generic formal
2338 -- part of a generic subprogram. When analyzing the body,
2339 -- the generic formals are visible but not on the entity
2340 -- chain of the subprogram. The new entity will become
2341 -- the visible one in the body.
2344 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
2348 Set_Next_Entity
(Prev
, Next_Entity
(E
));
2350 if No
(Next_Entity
(Prev
)) then
2351 Set_Last_Entity
(Current_Scope
, Prev
);
2354 if E
= Current_Entity
(E
) then
2358 Prev_Vis
:= Current_Entity
(E
);
2359 while Homonym
(Prev_Vis
) /= E
loop
2360 Prev_Vis
:= Homonym
(Prev_Vis
);
2364 if Present
(Prev_Vis
) then
2366 -- Skip E in the visibility chain
2368 Set_Homonym
(Prev_Vis
, Homonym
(E
));
2371 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
2376 -- This section of code could use a comment ???
2378 elsif Present
(Etype
(E
))
2379 and then Is_Concurrent_Type
(Etype
(E
))
2384 elsif Is_Private_Component_Renaming
(Parent
(Def_Id
)) then
2387 -- In the body or private part of an instance, a type extension
2388 -- may introduce a component with the same name as that of an
2389 -- actual. The legality rule is not enforced, but the semantics
2390 -- of the full type with two components of the same name are not
2391 -- clear at this point ???
2393 elsif In_Instance_Not_Visible
then
2396 -- When compiling a package body, some child units may have become
2397 -- visible. They cannot conflict with local entities that hide them.
2399 elsif Is_Child_Unit
(E
)
2400 and then In_Open_Scopes
(Scope
(E
))
2401 and then not Is_Immediately_Visible
(E
)
2405 -- Conversely, with front-end inlining we may compile the parent
2406 -- body first, and a child unit subsequently. The context is now
2407 -- the parent spec, and body entities are not visible.
2409 elsif Is_Child_Unit
(Def_Id
)
2410 and then Is_Package_Body_Entity
(E
)
2411 and then not In_Package_Body
(Current_Scope
)
2415 -- Case of genuine duplicate declaration
2418 Error_Msg_Sloc
:= Sloc
(E
);
2420 -- If the previous declaration is an incomplete type declaration
2421 -- this may be an attempt to complete it with a private type.
2422 -- The following avoids confusing cascaded errors.
2424 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
2425 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
2428 ("incomplete type cannot be completed" &
2429 " with a private declaration",
2431 Set_Is_Immediately_Visible
(E
, False);
2432 Set_Full_View
(E
, Def_Id
);
2434 elsif Ekind
(E
) = E_Discriminant
2435 and then Present
(Scope
(Def_Id
))
2436 and then Scope
(Def_Id
) /= Current_Scope
2438 -- An inherited component of a record conflicts with
2439 -- a new discriminant. The discriminant is inserted first
2440 -- in the scope, but the error should be posted on it, not
2441 -- on the component.
2443 Error_Msg_Sloc
:= Sloc
(Def_Id
);
2444 Error_Msg_N
("& conflicts with declaration#", E
);
2447 -- If the name of the unit appears in its own context clause,
2448 -- a dummy package with the name has already been created, and
2449 -- the error emitted. Try to continue quietly.
2451 elsif Error_Posted
(E
)
2452 and then Sloc
(E
) = No_Location
2453 and then Nkind
(Parent
(E
)) = N_Package_Specification
2454 and then Current_Scope
= Standard_Standard
2456 Set_Scope
(Def_Id
, Current_Scope
);
2460 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
2462 -- Avoid cascaded messages with duplicate components in
2465 if Ekind
(E
) = E_Component
2466 or else Ekind
(E
) = E_Discriminant
2472 if Nkind
(Parent
(Parent
(Def_Id
)))
2473 = N_Generic_Subprogram_Declaration
2475 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
2477 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
2480 -- If entity is in standard, then we are in trouble, because
2481 -- it means that we have a library package with a duplicated
2482 -- name. That's hard to recover from, so abort!
2484 if S
= Standard_Standard
then
2485 raise Unrecoverable_Error
;
2487 -- Otherwise we continue with the declaration. Having two
2488 -- identical declarations should not cause us too much trouble!
2496 -- If we fall through, declaration is OK , or OK enough to continue
2498 -- If Def_Id is a discriminant or a record component we are in the
2499 -- midst of inheriting components in a derived record definition.
2500 -- Preserve their Ekind and Etype.
2502 if Ekind
(Def_Id
) = E_Discriminant
2503 or else Ekind
(Def_Id
) = E_Component
2507 -- If a type is already set, leave it alone (happens whey a type
2508 -- declaration is reanalyzed following a call to the optimizer)
2510 elsif Present
(Etype
(Def_Id
)) then
2513 -- Otherwise, the kind E_Void insures that premature uses of the entity
2514 -- will be detected. Any_Type insures that no cascaded errors will occur
2517 Set_Ekind
(Def_Id
, E_Void
);
2518 Set_Etype
(Def_Id
, Any_Type
);
2521 -- Inherited discriminants and components in derived record types are
2522 -- immediately visible. Itypes are not.
2524 if Ekind
(Def_Id
) = E_Discriminant
2525 or else Ekind
(Def_Id
) = E_Component
2526 or else (No
(Corresponding_Remote_Type
(Def_Id
))
2527 and then not Is_Itype
(Def_Id
))
2529 Set_Is_Immediately_Visible
(Def_Id
);
2530 Set_Current_Entity
(Def_Id
);
2533 Set_Homonym
(Def_Id
, C
);
2534 Append_Entity
(Def_Id
, S
);
2535 Set_Public_Status
(Def_Id
);
2537 -- Warn if new entity hides an old one
2539 if Warn_On_Hiding
and then Present
(C
)
2541 -- Don't warn for record components since they always have a well
2542 -- defined scope which does not confuse other uses. Note that in
2543 -- some cases, Ekind has not been set yet.
2545 and then Ekind
(C
) /= E_Component
2546 and then Ekind
(C
) /= E_Discriminant
2547 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
2548 and then Ekind
(Def_Id
) /= E_Component
2549 and then Ekind
(Def_Id
) /= E_Discriminant
2550 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
2552 -- Don't warn for one character variables. It is too common to use
2553 -- such variables as locals and will just cause too many false hits.
2555 and then Length_Of_Name
(Chars
(C
)) /= 1
2557 -- Don't warn for non-source eneities
2559 and then Comes_From_Source
(C
)
2560 and then Comes_From_Source
(Def_Id
)
2562 -- Don't warn unless entity in question is in extended main source
2564 and then In_Extended_Main_Source_Unit
(Def_Id
)
2566 -- Finally, the hidden entity must be either immediately visible
2567 -- or use visible (from a used package)
2570 (Is_Immediately_Visible
(C
)
2572 Is_Potentially_Use_Visible
(C
))
2574 Error_Msg_Sloc
:= Sloc
(C
);
2575 Error_Msg_N
("declaration hides &#?", Def_Id
);
2579 --------------------------
2580 -- Explain_Limited_Type --
2581 --------------------------
2583 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
2587 -- For array, component type must be limited
2589 if Is_Array_Type
(T
) then
2590 Error_Msg_Node_2
:= T
;
2592 ("\component type& of type& is limited", N
, Component_Type
(T
));
2593 Explain_Limited_Type
(Component_Type
(T
), N
);
2595 elsif Is_Record_Type
(T
) then
2597 -- No need for extra messages if explicit limited record
2599 if Is_Limited_Record
(Base_Type
(T
)) then
2603 -- Otherwise find a limited component. Check only components that
2604 -- come from source, or inherited components that appear in the
2605 -- source of the ancestor.
2607 C
:= First_Component
(T
);
2608 while Present
(C
) loop
2609 if Is_Limited_Type
(Etype
(C
))
2611 (Comes_From_Source
(C
)
2613 (Present
(Original_Record_Component
(C
))
2615 Comes_From_Source
(Original_Record_Component
(C
))))
2617 Error_Msg_Node_2
:= T
;
2618 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
2619 Explain_Limited_Type
(Etype
(C
), N
);
2626 -- The type may be declared explicitly limited, even if no component
2627 -- of it is limited, in which case we fall out of the loop.
2630 end Explain_Limited_Type
;
2632 -------------------------------------
2633 -- Find_Corresponding_Discriminant --
2634 -------------------------------------
2636 function Find_Corresponding_Discriminant
2638 Typ
: Entity_Id
) return Entity_Id
2640 Par_Disc
: Entity_Id
;
2641 Old_Disc
: Entity_Id
;
2642 New_Disc
: Entity_Id
;
2645 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
2647 -- The original type may currently be private, and the discriminant
2648 -- only appear on its full view.
2650 if Is_Private_Type
(Scope
(Par_Disc
))
2651 and then not Has_Discriminants
(Scope
(Par_Disc
))
2652 and then Present
(Full_View
(Scope
(Par_Disc
)))
2654 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
2656 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
2659 if Is_Class_Wide_Type
(Typ
) then
2660 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
2662 New_Disc
:= First_Discriminant
(Typ
);
2665 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
2666 if Old_Disc
= Par_Disc
then
2669 Next_Discriminant
(Old_Disc
);
2670 Next_Discriminant
(New_Disc
);
2674 -- Should always find it
2676 raise Program_Error
;
2677 end Find_Corresponding_Discriminant
;
2679 --------------------------
2680 -- Find_Overlaid_Object --
2681 --------------------------
2683 function Find_Overlaid_Object
(N
: Node_Id
) return Entity_Id
is
2687 -- We are looking for one of the two following forms:
2689 -- for X'Address use Y'Address
2693 -- Const : constant Address := expr;
2695 -- for X'Address use Const;
2697 -- In the second case, the expr is either Y'Address, or recursively a
2698 -- constant that eventually references Y'Address.
2700 if Nkind
(N
) = N_Attribute_Definition_Clause
2701 and then Chars
(N
) = Name_Address
2703 -- This loop checks the form of the expression for Y'Address where Y
2704 -- is an object entity name. The first loop checks the original
2705 -- expression in the attribute definition clause. Subsequent loops
2706 -- check referenced constants.
2708 Expr
:= Expression
(N
);
2710 -- Check for Y'Address where Y is an object entity
2712 if Nkind
(Expr
) = N_Attribute_Reference
2713 and then Attribute_Name
(Expr
) = Name_Address
2714 and then Is_Entity_Name
(Prefix
(Expr
))
2715 and then Is_Object
(Entity
(Prefix
(Expr
)))
2717 return Entity
(Prefix
(Expr
));
2719 -- Check for Const where Const is a constant entity
2721 elsif Is_Entity_Name
(Expr
)
2722 and then Ekind
(Entity
(Expr
)) = E_Constant
2724 Expr
:= Constant_Value
(Entity
(Expr
));
2726 -- Anything else does not need checking
2735 end Find_Overlaid_Object
;
2737 --------------------------------------------
2738 -- Find_Overridden_Synchronized_Primitive --
2739 --------------------------------------------
2741 function Find_Overridden_Synchronized_Primitive
2742 (Def_Id
: Entity_Id
;
2743 First_Hom
: Entity_Id
;
2744 Ifaces_List
: Elist_Id
;
2745 In_Scope
: Boolean) return Entity_Id
2747 Candidate
: Entity_Id
:= Empty
;
2748 Hom
: Entity_Id
:= Empty
;
2749 Iface_Typ
: Entity_Id
;
2750 Subp
: Entity_Id
:= Empty
;
2751 Tag_Typ
: Entity_Id
;
2753 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
;
2754 -- Return the type of a formal parameter as determined by its
2757 function Has_Correct_Formal_Mode
(Subp
: Entity_Id
) return Boolean;
2758 -- For an overridden subprogram Subp, check whether the mode of its
2759 -- first parameter is correct depending on the kind of Tag_Typ.
2761 function Matches_Prefixed_View_Profile
2762 (Prim_Params
: List_Id
;
2763 Iface_Params
: List_Id
) return Boolean;
2764 -- Determine whether a subprogram's parameter profile Prim_Params
2765 -- matches that of a potentially overriden interface subprogram
2766 -- Iface_Params. Also determine if the type of first parameter of
2767 -- Iface_Params is an implemented interface.
2769 -------------------------
2770 -- Find_Parameter_Type --
2771 -------------------------
2773 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
2775 pragma Assert
(Nkind
(Param
) = N_Parameter_Specification
);
2777 if Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
2778 return Etype
(Subtype_Mark
(Parameter_Type
(Param
)));
2781 return Etype
(Parameter_Type
(Param
));
2783 end Find_Parameter_Type
;
2785 -----------------------------
2786 -- Has_Correct_Formal_Mode --
2787 -----------------------------
2789 function Has_Correct_Formal_Mode
(Subp
: Entity_Id
) return Boolean is
2793 Param
:= First_Formal
(Subp
);
2795 -- In order for an entry or a protected procedure to override, the
2796 -- first parameter of the overridden routine must be of mode "out",
2797 -- "in out" or access-to-variable.
2799 if (Ekind
(Subp
) = E_Entry
2800 or else Ekind
(Subp
) = E_Procedure
)
2801 and then Is_Protected_Type
(Tag_Typ
)
2802 and then Ekind
(Param
) /= E_In_Out_Parameter
2803 and then Ekind
(Param
) /= E_Out_Parameter
2804 and then Nkind
(Parameter_Type
(Parent
(Param
))) /=
2810 -- All other cases are OK since a task entry or routine does not
2811 -- have a restriction on the mode of the first parameter of the
2812 -- overridden interface routine.
2815 end Has_Correct_Formal_Mode
;
2817 -----------------------------------
2818 -- Matches_Prefixed_View_Profile --
2819 -----------------------------------
2821 function Matches_Prefixed_View_Profile
2822 (Prim_Params
: List_Id
;
2823 Iface_Params
: List_Id
) return Boolean
2825 Iface_Id
: Entity_Id
;
2826 Iface_Param
: Node_Id
;
2827 Iface_Typ
: Entity_Id
;
2828 Prim_Id
: Entity_Id
;
2829 Prim_Param
: Node_Id
;
2830 Prim_Typ
: Entity_Id
;
2832 function Is_Implemented
(Iface
: Entity_Id
) return Boolean;
2833 -- Determine if Iface is implemented by the current task or
2836 --------------------
2837 -- Is_Implemented --
2838 --------------------
2840 function Is_Implemented
(Iface
: Entity_Id
) return Boolean is
2841 Iface_Elmt
: Elmt_Id
;
2844 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
2845 while Present
(Iface_Elmt
) loop
2846 if Node
(Iface_Elmt
) = Iface
then
2850 Next_Elmt
(Iface_Elmt
);
2856 -- Start of processing for Matches_Prefixed_View_Profile
2859 Iface_Param
:= First
(Iface_Params
);
2860 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
2861 Prim_Param
:= First
(Prim_Params
);
2863 -- The first parameter of the potentially overriden subprogram
2864 -- must be an interface implemented by Prim.
2866 if not Is_Interface
(Iface_Typ
)
2867 or else not Is_Implemented
(Iface_Typ
)
2872 -- The checks on the object parameters are done, move onto the rest
2873 -- of the parameters.
2875 if not In_Scope
then
2876 Prim_Param
:= Next
(Prim_Param
);
2879 Iface_Param
:= Next
(Iface_Param
);
2880 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
2881 Iface_Id
:= Defining_Identifier
(Iface_Param
);
2882 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
2883 Prim_Id
:= Defining_Identifier
(Prim_Param
);
2884 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
2886 -- Case of multiple interface types inside a parameter profile
2888 -- (Obj_Param : in out Iface; ...; Param : Iface)
2890 -- If the interface type is implemented, then the matching type
2891 -- in the primitive should be the implementing record type.
2893 if Ekind
(Iface_Typ
) = E_Record_Type
2894 and then Is_Interface
(Iface_Typ
)
2895 and then Is_Implemented
(Iface_Typ
)
2897 if Prim_Typ
/= Tag_Typ
then
2901 -- The two parameters must be both mode and subtype conformant
2903 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
2905 not Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
2914 -- One of the two lists contains more parameters than the other
2916 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
2921 end Matches_Prefixed_View_Profile
;
2923 -- Start of processing for Find_Overridden_Synchronized_Primitive
2926 -- At this point the caller should have collected the interfaces
2927 -- implemented by the synchronized type.
2929 pragma Assert
(Present
(Ifaces_List
));
2931 -- Find the tagged type to which subprogram Def_Id is primitive. If the
2932 -- subprogram was declared within a protected or a task type, the type
2933 -- is the scope itself, otherwise it is the type of the first parameter.
2936 Tag_Typ
:= Scope
(Def_Id
);
2938 elsif Present
(First_Formal
(Def_Id
)) then
2939 Tag_Typ
:= Find_Parameter_Type
(Parent
(First_Formal
(Def_Id
)));
2941 -- A parameterless subprogram which is declared outside a synchronized
2942 -- type cannot act as a primitive, thus it cannot override anything.
2948 -- Traverse the homonym chain, looking at a potentially overriden
2949 -- subprogram that belongs to an implemented interface.
2952 while Present
(Hom
) loop
2955 -- Entries can override abstract or null interface procedures
2957 if Ekind
(Def_Id
) = E_Entry
2958 and then Ekind
(Subp
) = E_Procedure
2959 and then Nkind
(Parent
(Subp
)) = N_Procedure_Specification
2960 and then (Is_Abstract_Subprogram
(Subp
)
2961 or else Null_Present
(Parent
(Subp
)))
2963 while Present
(Alias
(Subp
)) loop
2964 Subp
:= Alias
(Subp
);
2967 if Matches_Prefixed_View_Profile
2968 (Parameter_Specifications
(Parent
(Def_Id
)),
2969 Parameter_Specifications
(Parent
(Subp
)))
2975 if Has_Correct_Formal_Mode
(Candidate
) then
2980 -- Procedures can override abstract or null interface procedures
2982 elsif Ekind
(Def_Id
) = E_Procedure
2983 and then Ekind
(Subp
) = E_Procedure
2984 and then Nkind
(Parent
(Subp
)) = N_Procedure_Specification
2985 and then (Is_Abstract_Subprogram
(Subp
)
2986 or else Null_Present
(Parent
(Subp
)))
2987 and then Matches_Prefixed_View_Profile
2988 (Parameter_Specifications
(Parent
(Def_Id
)),
2989 Parameter_Specifications
(Parent
(Subp
)))
2995 if Has_Correct_Formal_Mode
(Candidate
) then
2999 -- Functions can override abstract interface functions
3001 elsif Ekind
(Def_Id
) = E_Function
3002 and then Ekind
(Subp
) = E_Function
3003 and then Nkind
(Parent
(Subp
)) = N_Function_Specification
3004 and then Is_Abstract_Subprogram
(Subp
)
3005 and then Matches_Prefixed_View_Profile
3006 (Parameter_Specifications
(Parent
(Def_Id
)),
3007 Parameter_Specifications
(Parent
(Subp
)))
3008 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
3009 Etype
(Result_Definition
(Parent
(Subp
)))
3014 Hom
:= Homonym
(Hom
);
3017 -- After examining all candidates for overriding, we are left with
3018 -- the best match which is a mode incompatible interface routine.
3019 -- Do not emit an error if the Expander is active since this error
3020 -- will be detected later on after all concurrent types are expanded
3021 -- and all wrappers are built. This check is meant for spec-only
3024 if Present
(Candidate
)
3025 and then not Expander_Active
3027 Iface_Typ
:= Find_Parameter_Type
(Parent
(First_Formal
(Candidate
)));
3029 -- Def_Id is primitive of a protected type, declared inside the type,
3030 -- and the candidate is primitive of a limited or synchronized
3034 and then Is_Protected_Type
(Tag_Typ
)
3036 (Is_Limited_Interface
(Iface_Typ
)
3037 or else Is_Protected_Interface
(Iface_Typ
)
3038 or else Is_Synchronized_Interface
(Iface_Typ
)
3039 or else Is_Task_Interface
(Iface_Typ
))
3041 -- Must reword this message, comma before to in -gnatj mode ???
3044 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
3045 "access-to-variable", Tag_Typ
, Candidate
);
3047 ("\to be overridden by protected procedure or entry " &
3048 "(RM 9.4(11.9/2))", Tag_Typ
);
3053 end Find_Overridden_Synchronized_Primitive
;
3055 -----------------------------
3056 -- Find_Static_Alternative --
3057 -----------------------------
3059 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
3060 Expr
: constant Node_Id
:= Expression
(N
);
3061 Val
: constant Uint
:= Expr_Value
(Expr
);
3066 Alt
:= First
(Alternatives
(N
));
3069 if Nkind
(Alt
) /= N_Pragma
then
3070 Choice
:= First
(Discrete_Choices
(Alt
));
3071 while Present
(Choice
) loop
3073 -- Others choice, always matches
3075 if Nkind
(Choice
) = N_Others_Choice
then
3078 -- Range, check if value is in the range
3080 elsif Nkind
(Choice
) = N_Range
then
3082 Val
>= Expr_Value
(Low_Bound
(Choice
))
3084 Val
<= Expr_Value
(High_Bound
(Choice
));
3086 -- Choice is a subtype name. Note that we know it must
3087 -- be a static subtype, since otherwise it would have
3088 -- been diagnosed as illegal.
3090 elsif Is_Entity_Name
(Choice
)
3091 and then Is_Type
(Entity
(Choice
))
3093 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
));
3095 -- Choice is a subtype indication
3097 elsif Nkind
(Choice
) = N_Subtype_Indication
then
3099 C
: constant Node_Id
:= Constraint
(Choice
);
3100 R
: constant Node_Id
:= Range_Expression
(C
);
3104 Val
>= Expr_Value
(Low_Bound
(R
))
3106 Val
<= Expr_Value
(High_Bound
(R
));
3109 -- Choice is a simple expression
3112 exit Search
when Val
= Expr_Value
(Choice
);
3120 pragma Assert
(Present
(Alt
));
3123 -- The above loop *must* terminate by finding a match, since
3124 -- we know the case statement is valid, and the value of the
3125 -- expression is known at compile time. When we fall out of
3126 -- the loop, Alt points to the alternative that we know will
3127 -- be selected at run time.
3130 end Find_Static_Alternative
;
3136 function First_Actual
(Node
: Node_Id
) return Node_Id
is
3140 if No
(Parameter_Associations
(Node
)) then
3144 N
:= First
(Parameter_Associations
(Node
));
3146 if Nkind
(N
) = N_Parameter_Association
then
3147 return First_Named_Actual
(Node
);
3153 -------------------------
3154 -- Full_Qualified_Name --
3155 -------------------------
3157 function Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3159 pragma Warnings
(Off
, Res
);
3161 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
;
3162 -- Compute recursively the qualified name without NUL at the end
3164 ----------------------------------
3165 -- Internal_Full_Qualified_Name --
3166 ----------------------------------
3168 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3169 Ent
: Entity_Id
:= E
;
3170 Parent_Name
: String_Id
:= No_String
;
3173 -- Deals properly with child units
3175 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
3176 Ent
:= Defining_Identifier
(Ent
);
3179 -- Compute qualification recursively (only "Standard" has no scope)
3181 if Present
(Scope
(Scope
(Ent
))) then
3182 Parent_Name
:= Internal_Full_Qualified_Name
(Scope
(Ent
));
3185 -- Every entity should have a name except some expanded blocks
3186 -- don't bother about those.
3188 if Chars
(Ent
) = No_Name
then
3192 -- Add a period between Name and qualification
3194 if Parent_Name
/= No_String
then
3195 Start_String
(Parent_Name
);
3196 Store_String_Char
(Get_Char_Code
('.'));
3202 -- Generates the entity name in upper case
3204 Get_Decoded_Name_String
(Chars
(Ent
));
3206 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3208 end Internal_Full_Qualified_Name
;
3210 -- Start of processing for Full_Qualified_Name
3213 Res
:= Internal_Full_Qualified_Name
(E
);
3214 Store_String_Char
(Get_Char_Code
(ASCII
.nul
));
3216 end Full_Qualified_Name
;
3218 -----------------------
3219 -- Gather_Components --
3220 -----------------------
3222 procedure Gather_Components
3224 Comp_List
: Node_Id
;
3225 Governed_By
: List_Id
;
3227 Report_Errors
: out Boolean)
3231 Discrete_Choice
: Node_Id
;
3232 Comp_Item
: Node_Id
;
3234 Discrim
: Entity_Id
;
3235 Discrim_Name
: Node_Id
;
3236 Discrim_Value
: Node_Id
;
3239 Report_Errors
:= False;
3241 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
3244 elsif Present
(Component_Items
(Comp_List
)) then
3245 Comp_Item
:= First
(Component_Items
(Comp_List
));
3251 while Present
(Comp_Item
) loop
3253 -- Skip the tag of a tagged record, the interface tags, as well
3254 -- as all items that are not user components (anonymous types,
3255 -- rep clauses, Parent field, controller field).
3257 if Nkind
(Comp_Item
) = N_Component_Declaration
then
3259 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
3261 if not Is_Tag
(Comp
)
3262 and then Chars
(Comp
) /= Name_uParent
3263 and then Chars
(Comp
) /= Name_uController
3265 Append_Elmt
(Comp
, Into
);
3273 if No
(Variant_Part
(Comp_List
)) then
3276 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
3277 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3280 -- Look for the discriminant that governs this variant part.
3281 -- The discriminant *must* be in the Governed_By List
3283 Assoc
:= First
(Governed_By
);
3284 Find_Constraint
: loop
3285 Discrim
:= First
(Choices
(Assoc
));
3286 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
3287 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
3289 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
3290 = Chars
(Discrim_Name
))
3291 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
3292 = Chars
(Discrim_Name
);
3294 if No
(Next
(Assoc
)) then
3295 if not Is_Constrained
(Typ
)
3296 and then Is_Derived_Type
(Typ
)
3297 and then Present
(Stored_Constraint
(Typ
))
3299 -- If the type is a tagged type with inherited discriminants,
3300 -- use the stored constraint on the parent in order to find
3301 -- the values of discriminants that are otherwise hidden by an
3302 -- explicit constraint. Renamed discriminants are handled in
3305 -- If several parent discriminants are renamed by a single
3306 -- discriminant of the derived type, the call to obtain the
3307 -- Corresponding_Discriminant field only retrieves the last
3308 -- of them. We recover the constraint on the others from the
3309 -- Stored_Constraint as well.
3316 D
:= First_Discriminant
(Etype
(Typ
));
3317 C
:= First_Elmt
(Stored_Constraint
(Typ
));
3318 while Present
(D
) and then Present
(C
) loop
3319 if Chars
(Discrim_Name
) = Chars
(D
) then
3320 if Is_Entity_Name
(Node
(C
))
3321 and then Entity
(Node
(C
)) = Entity
(Discrim
)
3323 -- D is renamed by Discrim, whose value is given in
3330 Make_Component_Association
(Sloc
(Typ
),
3332 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
3333 Duplicate_Subexpr_No_Checks
(Node
(C
)));
3335 exit Find_Constraint
;
3338 Next_Discriminant
(D
);
3345 if No
(Next
(Assoc
)) then
3346 Error_Msg_NE
(" missing value for discriminant&",
3347 First
(Governed_By
), Discrim_Name
);
3348 Report_Errors
:= True;
3353 end loop Find_Constraint
;
3355 Discrim_Value
:= Expression
(Assoc
);
3357 if not Is_OK_Static_Expression
(Discrim_Value
) then
3359 ("value for discriminant & must be static!",
3360 Discrim_Value
, Discrim
);
3361 Why_Not_Static
(Discrim_Value
);
3362 Report_Errors
:= True;
3366 Search_For_Discriminant_Value
: declare
3372 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
3375 Find_Discrete_Value
: while Present
(Variant
) loop
3376 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
3377 while Present
(Discrete_Choice
) loop
3379 exit Find_Discrete_Value
when
3380 Nkind
(Discrete_Choice
) = N_Others_Choice
;
3382 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
3384 UI_Low
:= Expr_Value
(Low
);
3385 UI_High
:= Expr_Value
(High
);
3387 exit Find_Discrete_Value
when
3388 UI_Low
<= UI_Discrim_Value
3390 UI_High
>= UI_Discrim_Value
;
3392 Next
(Discrete_Choice
);
3395 Next_Non_Pragma
(Variant
);
3396 end loop Find_Discrete_Value
;
3397 end Search_For_Discriminant_Value
;
3399 if No
(Variant
) then
3401 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
3402 Report_Errors
:= True;
3406 -- If we have found the corresponding choice, recursively add its
3407 -- components to the Into list.
3409 Gather_Components
(Empty
,
3410 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
3411 end Gather_Components
;
3413 ------------------------
3414 -- Get_Actual_Subtype --
3415 ------------------------
3417 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
3418 Typ
: constant Entity_Id
:= Etype
(N
);
3419 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
3428 -- If what we have is an identifier that references a subprogram
3429 -- formal, or a variable or constant object, then we get the actual
3430 -- subtype from the referenced entity if one has been built.
3432 if Nkind
(N
) = N_Identifier
3434 (Is_Formal
(Entity
(N
))
3435 or else Ekind
(Entity
(N
)) = E_Constant
3436 or else Ekind
(Entity
(N
)) = E_Variable
)
3437 and then Present
(Actual_Subtype
(Entity
(N
)))
3439 return Actual_Subtype
(Entity
(N
));
3441 -- Actual subtype of unchecked union is always itself. We never need
3442 -- the "real" actual subtype. If we did, we couldn't get it anyway
3443 -- because the discriminant is not available. The restrictions on
3444 -- Unchecked_Union are designed to make sure that this is OK.
3446 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
3449 -- Here for the unconstrained case, we must find actual subtype
3450 -- No actual subtype is available, so we must build it on the fly.
3452 -- Checking the type, not the underlying type, for constrainedness
3453 -- seems to be necessary. Maybe all the tests should be on the type???
3455 elsif (not Is_Constrained
(Typ
))
3456 and then (Is_Array_Type
(Utyp
)
3457 or else (Is_Record_Type
(Utyp
)
3458 and then Has_Discriminants
(Utyp
)))
3459 and then not Has_Unknown_Discriminants
(Utyp
)
3460 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
3462 -- Nothing to do if in default expression
3464 if In_Default_Expression
then
3467 elsif Is_Private_Type
(Typ
)
3468 and then not Has_Discriminants
(Typ
)
3470 -- If the type has no discriminants, there is no subtype to
3471 -- build, even if the underlying type is discriminated.
3475 -- Else build the actual subtype
3478 Decl
:= Build_Actual_Subtype
(Typ
, N
);
3479 Atyp
:= Defining_Identifier
(Decl
);
3481 -- If Build_Actual_Subtype generated a new declaration then use it
3485 -- The actual subtype is an Itype, so analyze the declaration,
3486 -- but do not attach it to the tree, to get the type defined.
3488 Set_Parent
(Decl
, N
);
3489 Set_Is_Itype
(Atyp
);
3490 Analyze
(Decl
, Suppress
=> All_Checks
);
3491 Set_Associated_Node_For_Itype
(Atyp
, N
);
3492 Set_Has_Delayed_Freeze
(Atyp
, False);
3494 -- We need to freeze the actual subtype immediately. This is
3495 -- needed, because otherwise this Itype will not get frozen
3496 -- at all, and it is always safe to freeze on creation because
3497 -- any associated types must be frozen at this point.
3499 Freeze_Itype
(Atyp
, N
);
3502 -- Otherwise we did not build a declaration, so return original
3509 -- For all remaining cases, the actual subtype is the same as
3510 -- the nominal type.
3515 end Get_Actual_Subtype
;
3517 -------------------------------------
3518 -- Get_Actual_Subtype_If_Available --
3519 -------------------------------------
3521 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
3522 Typ
: constant Entity_Id
:= Etype
(N
);
3525 -- If what we have is an identifier that references a subprogram
3526 -- formal, or a variable or constant object, then we get the actual
3527 -- subtype from the referenced entity if one has been built.
3529 if Nkind
(N
) = N_Identifier
3531 (Is_Formal
(Entity
(N
))
3532 or else Ekind
(Entity
(N
)) = E_Constant
3533 or else Ekind
(Entity
(N
)) = E_Variable
)
3534 and then Present
(Actual_Subtype
(Entity
(N
)))
3536 return Actual_Subtype
(Entity
(N
));
3538 -- Otherwise the Etype of N is returned unchanged
3543 end Get_Actual_Subtype_If_Available
;
3545 -------------------------------
3546 -- Get_Default_External_Name --
3547 -------------------------------
3549 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
3551 Get_Decoded_Name_String
(Chars
(E
));
3553 if Opt
.External_Name_Imp_Casing
= Uppercase
then
3554 Set_Casing
(All_Upper_Case
);
3556 Set_Casing
(All_Lower_Case
);
3560 Make_String_Literal
(Sloc
(E
),
3561 Strval
=> String_From_Name_Buffer
);
3562 end Get_Default_External_Name
;
3564 ---------------------------
3565 -- Get_Enum_Lit_From_Pos --
3566 ---------------------------
3568 function Get_Enum_Lit_From_Pos
3571 Loc
: Source_Ptr
) return Node_Id
3576 -- In the case where the literal is of type Character, Wide_Character
3577 -- or Wide_Wide_Character or of a type derived from them, there needs
3578 -- to be some special handling since there is no explicit chain of
3579 -- literals to search. Instead, an N_Character_Literal node is created
3580 -- with the appropriate Char_Code and Chars fields.
3582 if Root_Type
(T
) = Standard_Character
3583 or else Root_Type
(T
) = Standard_Wide_Character
3584 or else Root_Type
(T
) = Standard_Wide_Wide_Character
3586 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
3588 Make_Character_Literal
(Loc
,
3590 Char_Literal_Value
=> Pos
);
3592 -- For all other cases, we have a complete table of literals, and
3593 -- we simply iterate through the chain of literal until the one
3594 -- with the desired position value is found.
3598 Lit
:= First_Literal
(Base_Type
(T
));
3599 for J
in 1 .. UI_To_Int
(Pos
) loop
3603 return New_Occurrence_Of
(Lit
, Loc
);
3605 end Get_Enum_Lit_From_Pos
;
3607 ------------------------
3608 -- Get_Generic_Entity --
3609 ------------------------
3611 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
3612 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
3614 if Present
(Renamed_Object
(Ent
)) then
3615 return Renamed_Object
(Ent
);
3619 end Get_Generic_Entity
;
3621 ----------------------
3622 -- Get_Index_Bounds --
3623 ----------------------
3625 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
3626 Kind
: constant Node_Kind
:= Nkind
(N
);
3630 if Kind
= N_Range
then
3632 H
:= High_Bound
(N
);
3634 elsif Kind
= N_Subtype_Indication
then
3635 R
:= Range_Expression
(Constraint
(N
));
3643 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
3644 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
3647 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
3648 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
3652 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
3653 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
3656 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
3657 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
3661 -- N is an expression, indicating a range with one value
3666 end Get_Index_Bounds
;
3668 ----------------------------------
3669 -- Get_Library_Unit_Name_string --
3670 ----------------------------------
3672 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
3673 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
3676 Get_Unit_Name_String
(Unit_Name_Id
);
3678 -- Remove seven last character (" (spec)" or " (body)")
3680 Name_Len
:= Name_Len
- 7;
3681 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
3682 end Get_Library_Unit_Name_String
;
3684 ------------------------
3685 -- Get_Name_Entity_Id --
3686 ------------------------
3688 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
3690 return Entity_Id
(Get_Name_Table_Info
(Id
));
3691 end Get_Name_Entity_Id
;
3693 ---------------------------
3694 -- Get_Referenced_Object --
3695 ---------------------------
3697 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
3702 while Is_Entity_Name
(R
)
3703 and then Present
(Renamed_Object
(Entity
(R
)))
3705 R
:= Renamed_Object
(Entity
(R
));
3709 end Get_Referenced_Object
;
3711 ------------------------
3712 -- Get_Renamed_Entity --
3713 ------------------------
3715 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
3720 while Present
(Renamed_Entity
(R
)) loop
3721 R
:= Renamed_Entity
(R
);
3725 end Get_Renamed_Entity
;
3727 -------------------------
3728 -- Get_Subprogram_Body --
3729 -------------------------
3731 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
3735 Decl
:= Unit_Declaration_Node
(E
);
3737 if Nkind
(Decl
) = N_Subprogram_Body
then
3740 -- The below comment is bad, because it is possible for
3741 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3743 else -- Nkind (Decl) = N_Subprogram_Declaration
3745 if Present
(Corresponding_Body
(Decl
)) then
3746 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
3748 -- Imported subprogram case
3754 end Get_Subprogram_Body
;
3756 ---------------------------
3757 -- Get_Subprogram_Entity --
3758 ---------------------------
3760 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
3765 if Nkind
(Nod
) = N_Accept_Statement
then
3766 Nam
:= Entry_Direct_Name
(Nod
);
3768 -- For an entry call, the prefix of the call is a selected component.
3769 -- Need additional code for internal calls ???
3771 elsif Nkind
(Nod
) = N_Entry_Call_Statement
then
3772 if Nkind
(Name
(Nod
)) = N_Selected_Component
then
3773 Nam
:= Entity
(Selector_Name
(Name
(Nod
)));
3782 if Nkind
(Nam
) = N_Explicit_Dereference
then
3783 Proc
:= Etype
(Prefix
(Nam
));
3784 elsif Is_Entity_Name
(Nam
) then
3785 Proc
:= Entity
(Nam
);
3790 if Is_Object
(Proc
) then
3791 Proc
:= Etype
(Proc
);
3794 if Ekind
(Proc
) = E_Access_Subprogram_Type
then
3795 Proc
:= Directly_Designated_Type
(Proc
);
3798 if not Is_Subprogram
(Proc
)
3799 and then Ekind
(Proc
) /= E_Subprogram_Type
3805 end Get_Subprogram_Entity
;
3807 -----------------------------
3808 -- Get_Task_Body_Procedure --
3809 -----------------------------
3811 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
3813 -- Note: A task type may be the completion of a private type with
3814 -- discriminants. when performing elaboration checks on a task
3815 -- declaration, the current view of the type may be the private one,
3816 -- and the procedure that holds the body of the task is held in its
3819 -- This is an odd function, why not have Task_Body_Procedure do
3820 -- the following digging???
3822 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
3823 end Get_Task_Body_Procedure
;
3825 -----------------------------
3826 -- Has_Abstract_Interfaces --
3827 -----------------------------
3829 function Has_Abstract_Interfaces
3830 (Tagged_Type
: Entity_Id
;
3831 Use_Full_View
: Boolean := True) return Boolean
3836 pragma Assert
(Is_Record_Type
(Tagged_Type
)
3837 and then Is_Tagged_Type
(Tagged_Type
));
3839 -- Handle concurrent record types
3841 if Is_Concurrent_Record_Type
(Tagged_Type
)
3842 and then Is_Non_Empty_List
(Abstract_Interface_List
(Tagged_Type
))
3849 -- Handle private types
3852 and then Present
(Full_View
(Tagged_Type
))
3854 Typ
:= Full_View
(Tagged_Type
);
3858 if Is_Interface
(Typ
)
3860 (Is_Record_Type
(Typ
)
3861 and then Present
(Abstract_Interfaces
(Typ
))
3862 and then not Is_Empty_Elmt_List
(Abstract_Interfaces
(Typ
)))
3867 exit when Etype
(Typ
) = Typ
3869 -- Handle private types
3871 or else (Present
(Full_View
(Etype
(Typ
)))
3872 and then Full_View
(Etype
(Typ
)) = Typ
)
3874 -- Protect the frontend against wrong source with cyclic
3877 or else Etype
(Typ
) = Tagged_Type
;
3879 -- Climb to the ancestor type handling private types
3881 if Present
(Full_View
(Etype
(Typ
))) then
3882 Typ
:= Full_View
(Etype
(Typ
));
3889 end Has_Abstract_Interfaces
;
3891 -----------------------
3892 -- Has_Access_Values --
3893 -----------------------
3895 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
3896 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
3899 -- Case of a private type which is not completed yet. This can only
3900 -- happen in the case of a generic format type appearing directly, or
3901 -- as a component of the type to which this function is being applied
3902 -- at the top level. Return False in this case, since we certainly do
3903 -- not know that the type contains access types.
3908 elsif Is_Access_Type
(Typ
) then
3911 elsif Is_Array_Type
(Typ
) then
3912 return Has_Access_Values
(Component_Type
(Typ
));
3914 elsif Is_Record_Type
(Typ
) then
3919 Comp
:= First_Component_Or_Discriminant
(Typ
);
3920 while Present
(Comp
) loop
3921 if Has_Access_Values
(Etype
(Comp
)) then
3925 Next_Component_Or_Discriminant
(Comp
);
3934 end Has_Access_Values
;
3936 ------------------------------
3937 -- Has_Compatible_Alignment --
3938 ------------------------------
3940 function Has_Compatible_Alignment
3942 Expr
: Node_Id
) return Alignment_Result
3944 function Has_Compatible_Alignment_Internal
3947 Default
: Alignment_Result
) return Alignment_Result
;
3948 -- This is the internal recursive function that actually does the work.
3949 -- There is one additional parameter, which says what the result should
3950 -- be if no alignment information is found, and there is no definite
3951 -- indication of compatible alignments. At the outer level, this is set
3952 -- to Unknown, but for internal recursive calls in the case where types
3953 -- are known to be correct, it is set to Known_Compatible.
3955 ---------------------------------------
3956 -- Has_Compatible_Alignment_Internal --
3957 ---------------------------------------
3959 function Has_Compatible_Alignment_Internal
3962 Default
: Alignment_Result
) return Alignment_Result
3964 Result
: Alignment_Result
:= Known_Compatible
;
3965 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3966 -- Note that once a value of Known_Incompatible is set, it is sticky
3967 -- and does not get changed to Unknown (the value in Result only gets
3968 -- worse as we go along, never better).
3970 procedure Check_Offset
(Offs
: Uint
);
3971 -- Called when Expr is a selected or indexed component with Offs set
3972 -- to resp Component_First_Bit or Component_Size. Checks that if the
3973 -- offset is specified it is compatible with the object alignment
3974 -- requirements. The value in Result is modified accordingly.
3976 procedure Check_Prefix
;
3977 -- Checks the prefix recursively in the case where the expression
3978 -- is an indexed or selected component.
3980 procedure Set_Result
(R
: Alignment_Result
);
3981 -- If R represents a worse outcome (unknown instead of known
3982 -- compatible, or known incompatible), then set Result to R.
3988 procedure Check_Offset
(Offs
: Uint
) is
3990 -- Unspecified or zero offset is always OK
3992 if Offs
= No_Uint
or else Offs
= Uint_0
then
3995 -- If we do not know required alignment, any non-zero offset is
3996 -- a potential problem (but certainly may be OK, so result is
3999 elsif Unknown_Alignment
(Obj
) then
4000 Set_Result
(Unknown
);
4002 -- If we know the required alignment, see if offset is compatible
4005 if Offs
mod (System_Storage_Unit
* Alignment
(Obj
)) /= 0 then
4006 Set_Result
(Known_Incompatible
);
4015 procedure Check_Prefix
is
4017 -- The subtlety here is that in doing a recursive call to check
4018 -- the prefix, we have to decide what to do in the case where we
4019 -- don't find any specific indication of an alignment problem.
4021 -- At the outer level, we normally set Unknown as the result in
4022 -- this case, since we can only set Known_Compatible if we really
4023 -- know that the alignment value is OK, but for the recursive
4024 -- call, in the case where the types match, and we have not
4025 -- specified a peculiar alignment for the object, we are only
4026 -- concerned about suspicious rep clauses, the default case does
4027 -- not affect us, since the compiler will, in the absence of such
4028 -- rep clauses, ensure that the alignment is correct.
4030 if Default
= Known_Compatible
4032 (Etype
(Obj
) = Etype
(Expr
)
4033 and then (Unknown_Alignment
(Obj
)
4035 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
4038 (Has_Compatible_Alignment_Internal
4039 (Obj
, Prefix
(Expr
), Known_Compatible
));
4041 -- In all other cases, we need a full check on the prefix
4045 (Has_Compatible_Alignment_Internal
4046 (Obj
, Prefix
(Expr
), Unknown
));
4054 procedure Set_Result
(R
: Alignment_Result
) is
4061 -- Start of processing for Has_Compatible_Alignment_Internal
4064 -- If Expr is a selected component, we must make sure there is no
4065 -- potentially troublesome component clause, and that the record is
4068 if Nkind
(Expr
) = N_Selected_Component
then
4070 -- Packed record always generate unknown alignment
4072 if Is_Packed
(Etype
(Prefix
(Expr
))) then
4073 Set_Result
(Unknown
);
4076 -- Check possible bad component offset and check prefix
4079 (Component_Bit_Offset
(Entity
(Selector_Name
(Expr
))));
4082 -- If Expr is an indexed component, we must make sure there is no
4083 -- potentially troublesome Component_Size clause and that the array
4084 -- is not bit-packed.
4086 elsif Nkind
(Expr
) = N_Indexed_Component
then
4088 -- Bit packed array always generates unknown alignment
4090 if Is_Bit_Packed_Array
(Etype
(Prefix
(Expr
))) then
4091 Set_Result
(Unknown
);
4094 -- Check possible bad component size and check prefix
4096 Check_Offset
(Component_Size
(Etype
(Prefix
(Expr
))));
4100 -- Case where we know the alignment of the object
4102 if Known_Alignment
(Obj
) then
4104 ObjA
: constant Uint
:= Alignment
(Obj
);
4105 ExpA
: Uint
:= No_Uint
;
4106 SizA
: Uint
:= No_Uint
;
4109 -- If alignment of Obj is 1, then we are always OK
4112 Set_Result
(Known_Compatible
);
4114 -- Alignment of Obj is greater than 1, so we need to check
4117 -- See if Expr is an object with known alignment
4119 if Is_Entity_Name
(Expr
)
4120 and then Known_Alignment
(Entity
(Expr
))
4122 ExpA
:= Alignment
(Entity
(Expr
));
4124 -- Otherwise, we can use the alignment of the type of
4125 -- Expr given that we already checked for
4126 -- discombobulating rep clauses for the cases of indexed
4127 -- and selected components above.
4129 elsif Known_Alignment
(Etype
(Expr
)) then
4130 ExpA
:= Alignment
(Etype
(Expr
));
4133 -- If we got an alignment, see if it is acceptable
4135 if ExpA
/= No_Uint
then
4137 Set_Result
(Known_Incompatible
);
4140 -- Case of Expr alignment unknown
4143 Set_Result
(Default
);
4146 -- See if size is given. If so, check that it is not too
4147 -- small for the required alignment.
4148 -- See if Expr is an object with known alignment
4150 if Is_Entity_Name
(Expr
)
4151 and then Known_Static_Esize
(Entity
(Expr
))
4153 SizA
:= Esize
(Entity
(Expr
));
4155 -- Otherwise, we check the object size of the Expr type
4157 elsif Known_Static_Esize
(Etype
(Expr
)) then
4158 SizA
:= Esize
(Etype
(Expr
));
4161 -- If we got a size, see if it is a multiple of the Obj
4162 -- alignment, if not, then the alignment cannot be
4163 -- acceptable, since the size is always a multiple of the
4166 if SizA
/= No_Uint
then
4167 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
4168 Set_Result
(Known_Incompatible
);
4174 -- If we can't find the result by direct comparison of alignment
4175 -- values, then there is still one case that we can determine known
4176 -- result, and that is when we can determine that the types are the
4177 -- same, and no alignments are specified. Then we known that the
4178 -- alignments are compatible, even if we don't know the alignment
4179 -- value in the front end.
4181 elsif Etype
(Obj
) = Etype
(Expr
) then
4183 -- Types are the same, but we have to check for possible size
4184 -- and alignments on the Expr object that may make the alignment
4185 -- different, even though the types are the same.
4187 if Is_Entity_Name
(Expr
) then
4189 -- First check alignment of the Expr object. Any alignment less
4190 -- than Maximum_Alignment is worrisome since this is the case
4191 -- where we do not know the alignment of Obj.
4193 if Known_Alignment
(Entity
(Expr
))
4195 UI_To_Int
(Alignment
(Entity
(Expr
)))
4196 < Ttypes
.Maximum_Alignment
4198 Set_Result
(Unknown
);
4200 -- Now check size of Expr object. Any size that is not an
4201 -- even multiple of Maxiumum_Alignment is also worrisome
4202 -- since it may cause the alignment of the object to be less
4203 -- than the alignment of the type.
4205 elsif Known_Static_Esize
(Entity
(Expr
))
4207 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
4208 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
4211 Set_Result
(Unknown
);
4213 -- Otherwise same type is decisive
4216 Set_Result
(Known_Compatible
);
4220 -- Another case to deal with is when there is an explicit size or
4221 -- alignment clause when the types are not the same. If so, then the
4222 -- result is Unknown. We don't need to do this test if the Default is
4223 -- Unknown, since that result will be set in any case.
4225 elsif Default
/= Unknown
4226 and then (Has_Size_Clause
(Etype
(Expr
))
4228 Has_Alignment_Clause
(Etype
(Expr
)))
4230 Set_Result
(Unknown
);
4232 -- If no indication found, set default
4235 Set_Result
(Default
);
4238 -- Return worst result found
4241 end Has_Compatible_Alignment_Internal
;
4243 -- Start of processing for Has_Compatible_Alignment
4246 -- If Obj has no specified alignment, then set alignment from the type
4247 -- alignment. Perhaps we should always do this, but for sure we should
4248 -- do it when there is an address clause since we can do more if the
4249 -- alignment is known.
4251 if Unknown_Alignment
(Obj
) then
4252 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
4255 -- Now do the internal call that does all the work
4257 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
4258 end Has_Compatible_Alignment
;
4260 ----------------------
4261 -- Has_Declarations --
4262 ----------------------
4264 function Has_Declarations
(N
: Node_Id
) return Boolean is
4265 K
: constant Node_Kind
:= Nkind
(N
);
4267 return K
= N_Accept_Statement
4268 or else K
= N_Block_Statement
4269 or else K
= N_Compilation_Unit_Aux
4270 or else K
= N_Entry_Body
4271 or else K
= N_Package_Body
4272 or else K
= N_Protected_Body
4273 or else K
= N_Subprogram_Body
4274 or else K
= N_Task_Body
4275 or else K
= N_Package_Specification
;
4276 end Has_Declarations
;
4278 -------------------------------------------
4279 -- Has_Discriminant_Dependent_Constraint --
4280 -------------------------------------------
4282 function Has_Discriminant_Dependent_Constraint
4283 (Comp
: Entity_Id
) return Boolean
4285 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
4286 Subt_Indic
: constant Node_Id
:=
4287 Subtype_Indication
(Component_Definition
(Comp_Decl
));
4292 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
4293 Constr
:= Constraint
(Subt_Indic
);
4295 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
4296 Assn
:= First
(Constraints
(Constr
));
4297 while Present
(Assn
) loop
4298 case Nkind
(Assn
) is
4299 when N_Subtype_Indication |
4303 if Depends_On_Discriminant
(Assn
) then
4307 when N_Discriminant_Association
=>
4308 if Depends_On_Discriminant
(Expression
(Assn
)) then
4323 end Has_Discriminant_Dependent_Constraint
;
4325 --------------------
4326 -- Has_Infinities --
4327 --------------------
4329 function Has_Infinities
(E
: Entity_Id
) return Boolean is
4332 Is_Floating_Point_Type
(E
)
4333 and then Nkind
(Scalar_Range
(E
)) = N_Range
4334 and then Includes_Infinities
(Scalar_Range
(E
));
4337 ------------------------
4338 -- Has_Null_Exclusion --
4339 ------------------------
4341 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
4344 when N_Access_Definition |
4345 N_Access_Function_Definition |
4346 N_Access_Procedure_Definition |
4347 N_Access_To_Object_Definition |
4349 N_Derived_Type_Definition |
4350 N_Function_Specification |
4351 N_Subtype_Declaration
=>
4352 return Null_Exclusion_Present
(N
);
4354 when N_Component_Definition |
4355 N_Formal_Object_Declaration |
4356 N_Object_Renaming_Declaration
=>
4357 if Present
(Subtype_Mark
(N
)) then
4358 return Null_Exclusion_Present
(N
);
4359 else pragma Assert
(Present
(Access_Definition
(N
)));
4360 return Null_Exclusion_Present
(Access_Definition
(N
));
4363 when N_Discriminant_Specification
=>
4364 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
4365 return Null_Exclusion_Present
(Discriminant_Type
(N
));
4367 return Null_Exclusion_Present
(N
);
4370 when N_Object_Declaration
=>
4371 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
4372 return Null_Exclusion_Present
(Object_Definition
(N
));
4374 return Null_Exclusion_Present
(N
);
4377 when N_Parameter_Specification
=>
4378 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
4379 return Null_Exclusion_Present
(Parameter_Type
(N
));
4381 return Null_Exclusion_Present
(N
);
4388 end Has_Null_Exclusion
;
4390 ------------------------
4391 -- Has_Null_Extension --
4392 ------------------------
4394 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
4395 B
: constant Entity_Id
:= Base_Type
(T
);
4400 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
4401 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
4403 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
4405 if Present
(Ext
) then
4406 if Null_Present
(Ext
) then
4409 Comps
:= Component_List
(Ext
);
4411 -- The null component list is rewritten during analysis to
4412 -- include the parent component. Any other component indicates
4413 -- that the extension was not originally null.
4415 return Null_Present
(Comps
)
4416 or else No
(Next
(First
(Component_Items
(Comps
))));
4425 end Has_Null_Extension
;
4427 --------------------------------------
4428 -- Has_Preelaborable_Initialization --
4429 --------------------------------------
4431 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
4434 procedure Check_Components
(E
: Entity_Id
);
4435 -- Check component/discriminant chain, sets Has_PE False if a component
4436 -- or discriminant does not meet the preelaborable initialization rules.
4438 ----------------------
4439 -- Check_Components --
4440 ----------------------
4442 procedure Check_Components
(E
: Entity_Id
) is
4446 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
4447 -- Returns True if and only if the expression denoted by N does not
4448 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4450 ---------------------------------
4451 -- Is_Preelaborable_Expression --
4452 ---------------------------------
4454 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
4458 Comp_Type
: Entity_Id
;
4459 Is_Array_Aggr
: Boolean;
4462 if Is_Static_Expression
(N
) then
4465 elsif Nkind
(N
) = N_Null
then
4468 elsif Nkind
(N
) = N_Attribute_Reference
4470 (Attribute_Name
(N
) = Name_Access
4472 Attribute_Name
(N
) = Name_Unchecked_Access
4474 Attribute_Name
(N
) = Name_Unrestricted_Access
)
4478 elsif Nkind
(N
) = N_Qualified_Expression
then
4479 return Is_Preelaborable_Expression
(Expression
(N
));
4481 -- For aggregates we have to check that each of the associations
4482 -- is preelaborable.
4484 elsif Nkind
(N
) = N_Aggregate
4485 or else Nkind
(N
) = N_Extension_Aggregate
4487 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
4489 if Is_Array_Aggr
then
4490 Comp_Type
:= Component_Type
(Etype
(N
));
4493 -- Check the ancestor part of extension aggregates, which must
4494 -- be either the name of a type that has preelaborable init or
4495 -- an expression that is preelaborable.
4497 if Nkind
(N
) = N_Extension_Aggregate
then
4499 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
4502 if Is_Entity_Name
(Anc_Part
)
4503 and then Is_Type
(Entity
(Anc_Part
))
4505 if not Has_Preelaborable_Initialization
4511 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
4517 -- Check positional associations
4519 Exp
:= First
(Expressions
(N
));
4520 while Present
(Exp
) loop
4521 if not Is_Preelaborable_Expression
(Exp
) then
4528 -- Check named associations
4530 Assn
:= First
(Component_Associations
(N
));
4531 while Present
(Assn
) loop
4532 Choice
:= First
(Choices
(Assn
));
4533 while Present
(Choice
) loop
4534 if Is_Array_Aggr
then
4535 if Nkind
(Choice
) = N_Others_Choice
then
4538 elsif Nkind
(Choice
) = N_Range
then
4539 if not Is_Static_Range
(Choice
) then
4543 elsif not Is_Static_Expression
(Choice
) then
4548 Comp_Type
:= Etype
(Choice
);
4554 -- If the association has a <> at this point, then we have
4555 -- to check whether the component's type has preelaborable
4556 -- initialization. Note that this only occurs when the
4557 -- association's corresponding component does not have a
4558 -- default expression, the latter case having already been
4559 -- expanded as an expression for the association.
4561 if Box_Present
(Assn
) then
4562 if not Has_Preelaborable_Initialization
(Comp_Type
) then
4566 -- In the expression case we check whether the expression
4567 -- is preelaborable.
4570 not Is_Preelaborable_Expression
(Expression
(Assn
))
4578 -- If we get here then aggregate as a whole is preelaborable
4582 -- All other cases are not preelaborable
4587 end Is_Preelaborable_Expression
;
4589 -- Start of processing for Check_Components
4592 -- Loop through entities of record or protected type
4595 while Present
(Ent
) loop
4597 -- We are interested only in components and discriminants
4599 if Ekind
(Ent
) = E_Component
4601 Ekind
(Ent
) = E_Discriminant
4603 -- Get default expression if any. If there is no declaration
4604 -- node, it means we have an internal entity. The parent and
4605 -- tag fields are examples of such entitires. For these cases,
4606 -- we just test the type of the entity.
4608 if Present
(Declaration_Node
(Ent
)) then
4609 Exp
:= Expression
(Declaration_Node
(Ent
));
4614 -- A component has PI if it has no default expression and the
4615 -- component type has PI.
4618 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
4623 -- Require the default expression to be preelaborable
4625 elsif not Is_Preelaborable_Expression
(Exp
) then
4633 end Check_Components
;
4635 -- Start of processing for Has_Preelaborable_Initialization
4638 -- Immediate return if already marked as known preelaborable init. This
4639 -- covers types for which this function has already been called once
4640 -- and returned True (in which case the result is cached), and also
4641 -- types to which a pragma Preelaborable_Initialization applies.
4643 if Known_To_Have_Preelab_Init
(E
) then
4647 -- If the type is a subtype representing a generic actual type, then
4648 -- test whether its base type has preelaborable initialization since
4649 -- the subtype representing the actual does not inherit this attribute
4650 -- from the actual or formal. (but maybe it should???)
4652 if Is_Generic_Actual_Type
(E
) then
4653 return Has_Preelaborable_Initialization
(Base_Type
(E
));
4656 -- Other private types never have preelaborable initialization
4658 if Is_Private_Type
(E
) then
4662 -- Here for all non-private view
4664 -- All elementary types have preelaborable initialization
4666 if Is_Elementary_Type
(E
) then
4669 -- Array types have PI if the component type has PI
4671 elsif Is_Array_Type
(E
) then
4672 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
4674 -- A derived type has preelaborable initialization if its parent type
4675 -- has preelaborable initialization and (in the case of a derived record
4676 -- extension) if the non-inherited components all have preelaborable
4677 -- initialization. However, a user-defined controlled type with an
4678 -- overriding Initialize procedure does not have preelaborable
4681 elsif Is_Derived_Type
(E
) then
4683 -- First check whether ancestor type has preelaborable initialization
4685 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
4687 -- If OK, check extension components (if any)
4689 if Has_PE
and then Is_Record_Type
(E
) then
4690 Check_Components
(First_Entity
(E
));
4693 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4694 -- with a user defined Initialize procedure does not have PI.
4697 and then Is_Controlled
(E
)
4698 and then Present
(Primitive_Operations
(E
))
4704 P
:= First_Elmt
(Primitive_Operations
(E
));
4705 while Present
(P
) loop
4706 if Chars
(Node
(P
)) = Name_Initialize
4707 and then Comes_From_Source
(Node
(P
))
4718 -- Record type has PI if it is non private and all components have PI
4720 elsif Is_Record_Type
(E
) then
4722 Check_Components
(First_Entity
(E
));
4724 -- Protected types must not have entries, and components must meet
4725 -- same set of rules as for record components.
4727 elsif Is_Protected_Type
(E
) then
4728 if Has_Entries
(E
) then
4732 Check_Components
(First_Entity
(E
));
4733 Check_Components
(First_Private_Entity
(E
));
4736 -- Type System.Address always has preelaborable initialization
4738 elsif Is_RTE
(E
, RE_Address
) then
4741 -- In all other cases, type does not have preelaborable initialization
4747 -- If type has preelaborable initialization, cache result
4750 Set_Known_To_Have_Preelab_Init
(E
);
4754 end Has_Preelaborable_Initialization
;
4756 ---------------------------
4757 -- Has_Private_Component --
4758 ---------------------------
4760 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
4761 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
4762 Component
: Entity_Id
;
4765 if Error_Posted
(Type_Id
)
4766 or else Error_Posted
(Btype
)
4771 if Is_Class_Wide_Type
(Btype
) then
4772 Btype
:= Root_Type
(Btype
);
4775 if Is_Private_Type
(Btype
) then
4777 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
4780 if No
(Full_View
(Btype
)) then
4781 return not Is_Generic_Type
(Btype
)
4782 and then not Is_Generic_Type
(Root_Type
(Btype
));
4784 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
4787 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
4791 elsif Is_Array_Type
(Btype
) then
4792 return Has_Private_Component
(Component_Type
(Btype
));
4794 elsif Is_Record_Type
(Btype
) then
4795 Component
:= First_Component
(Btype
);
4796 while Present
(Component
) loop
4797 if Has_Private_Component
(Etype
(Component
)) then
4801 Next_Component
(Component
);
4806 elsif Is_Protected_Type
(Btype
)
4807 and then Present
(Corresponding_Record_Type
(Btype
))
4809 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
4814 end Has_Private_Component
;
4820 function Has_Stream
(T
: Entity_Id
) return Boolean is
4827 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
4830 elsif Is_Array_Type
(T
) then
4831 return Has_Stream
(Component_Type
(T
));
4833 elsif Is_Record_Type
(T
) then
4834 E
:= First_Component
(T
);
4835 while Present
(E
) loop
4836 if Has_Stream
(Etype
(E
)) then
4845 elsif Is_Private_Type
(T
) then
4846 return Has_Stream
(Underlying_Type
(T
));
4853 --------------------------
4854 -- Has_Tagged_Component --
4855 --------------------------
4857 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
4861 if Is_Private_Type
(Typ
)
4862 and then Present
(Underlying_Type
(Typ
))
4864 return Has_Tagged_Component
(Underlying_Type
(Typ
));
4866 elsif Is_Array_Type
(Typ
) then
4867 return Has_Tagged_Component
(Component_Type
(Typ
));
4869 elsif Is_Tagged_Type
(Typ
) then
4872 elsif Is_Record_Type
(Typ
) then
4873 Comp
:= First_Component
(Typ
);
4874 while Present
(Comp
) loop
4875 if Has_Tagged_Component
(Etype
(Comp
)) then
4879 Comp
:= Next_Component
(Typ
);
4887 end Has_Tagged_Component
;
4893 function In_Instance
return Boolean is
4894 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
4900 and then S
/= Standard_Standard
4902 if (Ekind
(S
) = E_Function
4903 or else Ekind
(S
) = E_Package
4904 or else Ekind
(S
) = E_Procedure
)
4905 and then Is_Generic_Instance
(S
)
4907 -- A child instance is always compiled in the context of a parent
4908 -- instance. Nevertheless, the actuals are not analyzed in an
4909 -- instance context. We detect this case by examining the current
4910 -- compilation unit, which must be a child instance, and checking
4911 -- that it is not currently on the scope stack.
4913 if Is_Child_Unit
(Curr_Unit
)
4915 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
4916 = N_Package_Instantiation
4917 and then not In_Open_Scopes
(Curr_Unit
)
4931 ----------------------
4932 -- In_Instance_Body --
4933 ----------------------
4935 function In_Instance_Body
return Boolean is
4941 and then S
/= Standard_Standard
4943 if (Ekind
(S
) = E_Function
4944 or else Ekind
(S
) = E_Procedure
)
4945 and then Is_Generic_Instance
(S
)
4949 elsif Ekind
(S
) = E_Package
4950 and then In_Package_Body
(S
)
4951 and then Is_Generic_Instance
(S
)
4960 end In_Instance_Body
;
4962 -----------------------------
4963 -- In_Instance_Not_Visible --
4964 -----------------------------
4966 function In_Instance_Not_Visible
return Boolean is
4972 and then S
/= Standard_Standard
4974 if (Ekind
(S
) = E_Function
4975 or else Ekind
(S
) = E_Procedure
)
4976 and then Is_Generic_Instance
(S
)
4980 elsif Ekind
(S
) = E_Package
4981 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
4982 and then Is_Generic_Instance
(S
)
4991 end In_Instance_Not_Visible
;
4993 ------------------------------
4994 -- In_Instance_Visible_Part --
4995 ------------------------------
4997 function In_Instance_Visible_Part
return Boolean is
5003 and then S
/= Standard_Standard
5005 if Ekind
(S
) = E_Package
5006 and then Is_Generic_Instance
(S
)
5007 and then not In_Package_Body
(S
)
5008 and then not In_Private_Part
(S
)
5017 end In_Instance_Visible_Part
;
5019 ----------------------
5020 -- In_Packiage_Body --
5021 ----------------------
5023 function In_Package_Body
return Boolean is
5029 and then S
/= Standard_Standard
5031 if Ekind
(S
) = E_Package
5032 and then In_Package_Body
(S
)
5041 end In_Package_Body
;
5043 --------------------------------------
5044 -- In_Subprogram_Or_Concurrent_Unit --
5045 --------------------------------------
5047 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
5052 -- Use scope chain to check successively outer scopes
5058 if K
in Subprogram_Kind
5059 or else K
in Concurrent_Kind
5060 or else K
in Generic_Subprogram_Kind
5064 elsif E
= Standard_Standard
then
5070 end In_Subprogram_Or_Concurrent_Unit
;
5072 ---------------------
5073 -- In_Visible_Part --
5074 ---------------------
5076 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
5079 Is_Package_Or_Generic_Package
(Scope_Id
)
5080 and then In_Open_Scopes
(Scope_Id
)
5081 and then not In_Package_Body
(Scope_Id
)
5082 and then not In_Private_Part
(Scope_Id
);
5083 end In_Visible_Part
;
5085 ---------------------------------
5086 -- Insert_Explicit_Dereference --
5087 ---------------------------------
5089 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
5090 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
5091 Ent
: Entity_Id
:= Empty
;
5098 Save_Interps
(N
, New_Prefix
);
5100 Make_Explicit_Dereference
(Sloc
(N
),
5101 Prefix
=> New_Prefix
));
5103 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
5105 if Is_Overloaded
(New_Prefix
) then
5107 -- The deference is also overloaded, and its interpretations are the
5108 -- designated types of the interpretations of the original node.
5110 Set_Etype
(N
, Any_Type
);
5112 Get_First_Interp
(New_Prefix
, I
, It
);
5113 while Present
(It
.Nam
) loop
5116 if Is_Access_Type
(T
) then
5117 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
5120 Get_Next_Interp
(I
, It
);
5126 -- Prefix is unambiguous: mark the original prefix (which might
5127 -- Come_From_Source) as a reference, since the new (relocated) one
5128 -- won't be taken into account.
5130 if Is_Entity_Name
(New_Prefix
) then
5131 Ent
:= Entity
(New_Prefix
);
5133 -- For a retrieval of a subcomponent of some composite object,
5134 -- retrieve the ultimate entity if there is one.
5136 elsif Nkind
(New_Prefix
) = N_Selected_Component
5137 or else Nkind
(New_Prefix
) = N_Indexed_Component
5139 Pref
:= Prefix
(New_Prefix
);
5140 while Present
(Pref
)
5142 (Nkind
(Pref
) = N_Selected_Component
5143 or else Nkind
(Pref
) = N_Indexed_Component
)
5145 Pref
:= Prefix
(Pref
);
5148 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
5149 Ent
:= Entity
(Pref
);
5153 if Present
(Ent
) then
5154 Generate_Reference
(Ent
, New_Prefix
);
5157 end Insert_Explicit_Dereference
;
5163 function Is_AAMP_Float
(E
: Entity_Id
) return Boolean is
5164 pragma Assert
(Is_Type
(E
));
5166 return AAMP_On_Target
5167 and then Is_Floating_Point_Type
(E
)
5168 and then E
= Base_Type
(E
);
5171 -------------------------
5172 -- Is_Actual_Parameter --
5173 -------------------------
5175 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
5176 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
5180 when N_Parameter_Association
=>
5181 return N
= Explicit_Actual_Parameter
(Parent
(N
));
5183 when N_Function_Call | N_Procedure_Call_Statement
=>
5184 return Is_List_Member
(N
)
5186 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
5191 end Is_Actual_Parameter
;
5193 ---------------------
5194 -- Is_Aliased_View --
5195 ---------------------
5197 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
5201 if Is_Entity_Name
(Obj
) then
5209 or else (Present
(Renamed_Object
(E
))
5210 and then Is_Aliased_View
(Renamed_Object
(E
)))))
5212 or else ((Is_Formal
(E
)
5213 or else Ekind
(E
) = E_Generic_In_Out_Parameter
5214 or else Ekind
(E
) = E_Generic_In_Parameter
)
5215 and then Is_Tagged_Type
(Etype
(E
)))
5217 or else (Is_Concurrent_Type
(E
)
5218 and then In_Open_Scopes
(E
))
5220 -- Current instance of type, either directly or as rewritten
5221 -- reference to the current object.
5223 or else (Is_Entity_Name
(Original_Node
(Obj
))
5224 and then Present
(Entity
(Original_Node
(Obj
)))
5225 and then Is_Type
(Entity
(Original_Node
(Obj
))))
5227 or else (Is_Type
(E
) and then E
= Current_Scope
)
5229 or else (Is_Incomplete_Or_Private_Type
(E
)
5230 and then Full_View
(E
) = Current_Scope
);
5232 elsif Nkind
(Obj
) = N_Selected_Component
then
5233 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
5235 elsif Nkind
(Obj
) = N_Indexed_Component
then
5236 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
5238 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
5240 Has_Aliased_Components
5241 (Designated_Type
(Etype
(Prefix
(Obj
)))));
5243 elsif Nkind
(Obj
) = N_Unchecked_Type_Conversion
5244 or else Nkind
(Obj
) = N_Type_Conversion
5246 return Is_Tagged_Type
(Etype
(Obj
))
5247 and then Is_Aliased_View
(Expression
(Obj
));
5249 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
5250 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
5255 end Is_Aliased_View
;
5257 -------------------------
5258 -- Is_Ancestor_Package --
5259 -------------------------
5261 function Is_Ancestor_Package
5263 E2
: Entity_Id
) return Boolean
5270 and then Par
/= Standard_Standard
5280 end Is_Ancestor_Package
;
5282 ----------------------
5283 -- Is_Atomic_Object --
5284 ----------------------
5286 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
5288 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
5289 -- Determines if given object has atomic components
5291 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
5292 -- If prefix is an implicit dereference, examine designated type
5294 ----------------------
5295 -- Is_Atomic_Prefix --
5296 ----------------------
5298 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
5300 if Is_Access_Type
(Etype
(N
)) then
5302 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
5304 return Object_Has_Atomic_Components
(N
);
5306 end Is_Atomic_Prefix
;
5308 ----------------------------------
5309 -- Object_Has_Atomic_Components --
5310 ----------------------------------
5312 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
5314 if Has_Atomic_Components
(Etype
(N
))
5315 or else Is_Atomic
(Etype
(N
))
5319 elsif Is_Entity_Name
(N
)
5320 and then (Has_Atomic_Components
(Entity
(N
))
5321 or else Is_Atomic
(Entity
(N
)))
5325 elsif Nkind
(N
) = N_Indexed_Component
5326 or else Nkind
(N
) = N_Selected_Component
5328 return Is_Atomic_Prefix
(Prefix
(N
));
5333 end Object_Has_Atomic_Components
;
5335 -- Start of processing for Is_Atomic_Object
5338 if Is_Atomic
(Etype
(N
))
5339 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
5343 elsif Nkind
(N
) = N_Indexed_Component
5344 or else Nkind
(N
) = N_Selected_Component
5346 return Is_Atomic_Prefix
(Prefix
(N
));
5351 end Is_Atomic_Object
;
5353 -------------------------
5354 -- Is_Coextension_Root --
5355 -------------------------
5357 function Is_Coextension_Root
(N
: Node_Id
) return Boolean is
5360 Nkind
(N
) = N_Allocator
5361 and then Present
(Coextensions
(N
))
5363 -- Anonymous access discriminants carry a list of all nested
5364 -- controlled coextensions.
5366 and then not Is_Dynamic_Coextension
(N
)
5367 and then not Is_Static_Coextension
(N
);
5368 end Is_Coextension_Root
;
5370 --------------------------------------
5371 -- Is_Controlling_Limited_Procedure --
5372 --------------------------------------
5374 function Is_Controlling_Limited_Procedure
5375 (Proc_Nam
: Entity_Id
) return Boolean
5377 Param_Typ
: Entity_Id
:= Empty
;
5380 if Ekind
(Proc_Nam
) = E_Procedure
5381 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
5383 Param_Typ
:= Etype
(Parameter_Type
(First
(
5384 Parameter_Specifications
(Parent
(Proc_Nam
)))));
5386 -- In this case where an Itype was created, the procedure call has been
5389 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
5390 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
5392 Present
(Parameter_Associations
5393 (Associated_Node_For_Itype
(Proc_Nam
)))
5396 Etype
(First
(Parameter_Associations
5397 (Associated_Node_For_Itype
(Proc_Nam
))));
5400 if Present
(Param_Typ
) then
5402 Is_Interface
(Param_Typ
)
5403 and then Is_Limited_Record
(Param_Typ
);
5407 end Is_Controlling_Limited_Procedure
;
5409 ----------------------------------------------
5410 -- Is_Dependent_Component_Of_Mutable_Object --
5411 ----------------------------------------------
5413 function Is_Dependent_Component_Of_Mutable_Object
5414 (Object
: Node_Id
) return Boolean
5417 Prefix_Type
: Entity_Id
;
5418 P_Aliased
: Boolean := False;
5421 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
5422 -- Returns True if and only if Comp is declared within a variant part
5424 --------------------------------
5425 -- Is_Declared_Within_Variant --
5426 --------------------------------
5428 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
5429 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
5430 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
5432 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
5433 end Is_Declared_Within_Variant
;
5435 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5438 if Is_Variable
(Object
) then
5440 if Nkind
(Object
) = N_Selected_Component
then
5441 P
:= Prefix
(Object
);
5442 Prefix_Type
:= Etype
(P
);
5444 if Is_Entity_Name
(P
) then
5446 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
5447 Prefix_Type
:= Base_Type
(Prefix_Type
);
5450 if Is_Aliased
(Entity
(P
)) then
5454 -- A discriminant check on a selected component may be
5455 -- expanded into a dereference when removing side-effects.
5456 -- Recover the original node and its type, which may be
5459 elsif Nkind
(P
) = N_Explicit_Dereference
5460 and then not (Comes_From_Source
(P
))
5462 P
:= Original_Node
(P
);
5463 Prefix_Type
:= Etype
(P
);
5466 -- Check for prefix being an aliased component ???
5471 -- A heap object is constrained by its initial value
5473 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5474 -- the dereferenced case, since the access value might denote an
5475 -- unconstrained aliased object, whereas in Ada 95 the designated
5476 -- object is guaranteed to be constrained. A worst-case assumption
5477 -- has to apply in Ada 2005 because we can't tell at compile time
5478 -- whether the object is "constrained by its initial value"
5479 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5480 -- semantic rules -- these rules are acknowledged to need fixing).
5482 if Ada_Version
< Ada_05
then
5483 if Is_Access_Type
(Prefix_Type
)
5484 or else Nkind
(P
) = N_Explicit_Dereference
5489 elsif Ada_Version
>= Ada_05
then
5490 if Is_Access_Type
(Prefix_Type
) then
5491 Prefix_Type
:= Designated_Type
(Prefix_Type
);
5496 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
5498 -- As per AI-0017, the renaming is illegal in a generic body,
5499 -- even if the subtype is indefinite.
5501 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5503 if not Is_Constrained
(Prefix_Type
)
5504 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
5506 (Is_Generic_Type
(Prefix_Type
)
5507 and then Ekind
(Current_Scope
) = E_Generic_Package
5508 and then In_Package_Body
(Current_Scope
)))
5510 and then (Is_Declared_Within_Variant
(Comp
)
5511 or else Has_Discriminant_Dependent_Constraint
(Comp
))
5512 and then (not P_Aliased
or else Ada_Version
>= Ada_05
)
5518 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5522 elsif Nkind
(Object
) = N_Indexed_Component
5523 or else Nkind
(Object
) = N_Slice
5525 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5527 -- A type conversion that Is_Variable is a view conversion:
5528 -- go back to the denoted object.
5530 elsif Nkind
(Object
) = N_Type_Conversion
then
5532 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
5537 end Is_Dependent_Component_Of_Mutable_Object
;
5539 ---------------------
5540 -- Is_Dereferenced --
5541 ---------------------
5543 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
5544 P
: constant Node_Id
:= Parent
(N
);
5547 (Nkind
(P
) = N_Selected_Component
5549 Nkind
(P
) = N_Explicit_Dereference
5551 Nkind
(P
) = N_Indexed_Component
5553 Nkind
(P
) = N_Slice
)
5554 and then Prefix
(P
) = N
;
5555 end Is_Dereferenced
;
5557 ----------------------
5558 -- Is_Descendent_Of --
5559 ----------------------
5561 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
5566 pragma Assert
(Nkind
(T1
) in N_Entity
);
5567 pragma Assert
(Nkind
(T2
) in N_Entity
);
5569 T
:= Base_Type
(T1
);
5571 -- Immediate return if the types match
5576 -- Comment needed here ???
5578 elsif Ekind
(T
) = E_Class_Wide_Type
then
5579 return Etype
(T
) = T2
;
5587 -- Done if we found the type we are looking for
5592 -- Done if no more derivations to check
5599 -- Following test catches error cases resulting from prev errors
5601 elsif No
(Etyp
) then
5604 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
5607 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
5611 T
:= Base_Type
(Etyp
);
5615 raise Program_Error
;
5616 end Is_Descendent_Of
;
5622 function Is_False
(U
: Uint
) return Boolean is
5627 ---------------------------
5628 -- Is_Fixed_Model_Number --
5629 ---------------------------
5631 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
5632 S
: constant Ureal
:= Small_Value
(T
);
5633 M
: Urealp
.Save_Mark
;
5637 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
5640 end Is_Fixed_Model_Number
;
5642 -------------------------------
5643 -- Is_Fully_Initialized_Type --
5644 -------------------------------
5646 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
5648 if Is_Scalar_Type
(Typ
) then
5651 elsif Is_Access_Type
(Typ
) then
5654 elsif Is_Array_Type
(Typ
) then
5655 if Is_Fully_Initialized_Type
(Component_Type
(Typ
)) then
5659 -- An interesting case, if we have a constrained type one of whose
5660 -- bounds is known to be null, then there are no elements to be
5661 -- initialized, so all the elements are initialized!
5663 if Is_Constrained
(Typ
) then
5666 Indx_Typ
: Entity_Id
;
5670 Indx
:= First_Index
(Typ
);
5671 while Present
(Indx
) loop
5672 if Etype
(Indx
) = Any_Type
then
5675 -- If index is a range, use directly
5677 elsif Nkind
(Indx
) = N_Range
then
5678 Lbd
:= Low_Bound
(Indx
);
5679 Hbd
:= High_Bound
(Indx
);
5682 Indx_Typ
:= Etype
(Indx
);
5684 if Is_Private_Type
(Indx_Typ
) then
5685 Indx_Typ
:= Full_View
(Indx_Typ
);
5688 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
5691 Lbd
:= Type_Low_Bound
(Indx_Typ
);
5692 Hbd
:= Type_High_Bound
(Indx_Typ
);
5696 if Compile_Time_Known_Value
(Lbd
)
5697 and then Compile_Time_Known_Value
(Hbd
)
5699 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
5709 -- If no null indexes, then type is not fully initialized
5715 elsif Is_Record_Type
(Typ
) then
5716 if Has_Discriminants
(Typ
)
5718 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
5719 and then Is_Fully_Initialized_Variant
(Typ
)
5724 -- Controlled records are considered to be fully initialized if
5725 -- there is a user defined Initialize routine. This may not be
5726 -- entirely correct, but as the spec notes, we are guessing here
5727 -- what is best from the point of view of issuing warnings.
5729 if Is_Controlled
(Typ
) then
5731 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5734 if Present
(Utyp
) then
5736 Init
: constant Entity_Id
:=
5738 (Underlying_Type
(Typ
), Name_Initialize
));
5742 and then Comes_From_Source
(Init
)
5744 Is_Predefined_File_Name
5745 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
5749 elsif Has_Null_Extension
(Typ
)
5751 Is_Fully_Initialized_Type
5752 (Etype
(Base_Type
(Typ
)))
5761 -- Otherwise see if all record components are initialized
5767 Ent
:= First_Entity
(Typ
);
5768 while Present
(Ent
) loop
5769 if Chars
(Ent
) = Name_uController
then
5772 elsif Ekind
(Ent
) = E_Component
5773 and then (No
(Parent
(Ent
))
5774 or else No
(Expression
(Parent
(Ent
))))
5775 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
5777 -- Special VM case for uTag component, which needs to be
5778 -- defined in this case, but is never initialized as VMs
5779 -- are using other dispatching mechanisms. Ignore this
5780 -- uninitialized case.
5782 and then (VM_Target
= No_VM
5783 or else Chars
(Ent
) /= Name_uTag
)
5792 -- No uninitialized components, so type is fully initialized.
5793 -- Note that this catches the case of no components as well.
5797 elsif Is_Concurrent_Type
(Typ
) then
5800 elsif Is_Private_Type
(Typ
) then
5802 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5808 return Is_Fully_Initialized_Type
(U
);
5815 end Is_Fully_Initialized_Type
;
5817 ----------------------------------
5818 -- Is_Fully_Initialized_Variant --
5819 ----------------------------------
5821 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
5822 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5823 Constraints
: constant List_Id
:= New_List
;
5824 Components
: constant Elist_Id
:= New_Elmt_List
;
5825 Comp_Elmt
: Elmt_Id
;
5827 Comp_List
: Node_Id
;
5829 Discr_Val
: Node_Id
;
5830 Report_Errors
: Boolean;
5833 if Serious_Errors_Detected
> 0 then
5837 if Is_Record_Type
(Typ
)
5838 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
5839 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
5841 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
5843 Discr
:= First_Discriminant
(Typ
);
5844 while Present
(Discr
) loop
5845 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
5846 Discr_Val
:= Expression
(Parent
(Discr
));
5848 if Present
(Discr_Val
)
5849 and then Is_OK_Static_Expression
(Discr_Val
)
5851 Append_To
(Constraints
,
5852 Make_Component_Association
(Loc
,
5853 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
5854 Expression
=> New_Copy
(Discr_Val
)));
5862 Next_Discriminant
(Discr
);
5867 Comp_List
=> Comp_List
,
5868 Governed_By
=> Constraints
,
5870 Report_Errors
=> Report_Errors
);
5872 -- Check that each component present is fully initialized
5874 Comp_Elmt
:= First_Elmt
(Components
);
5875 while Present
(Comp_Elmt
) loop
5876 Comp_Id
:= Node
(Comp_Elmt
);
5878 if Ekind
(Comp_Id
) = E_Component
5879 and then (No
(Parent
(Comp_Id
))
5880 or else No
(Expression
(Parent
(Comp_Id
))))
5881 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
5886 Next_Elmt
(Comp_Elmt
);
5891 elsif Is_Private_Type
(Typ
) then
5893 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5899 return Is_Fully_Initialized_Variant
(U
);
5905 end Is_Fully_Initialized_Variant
;
5907 ----------------------------
5908 -- Is_Inherited_Operation --
5909 ----------------------------
5911 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
5912 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
5914 pragma Assert
(Is_Overloadable
(E
));
5915 return Kind
= N_Full_Type_Declaration
5916 or else Kind
= N_Private_Extension_Declaration
5917 or else Kind
= N_Subtype_Declaration
5918 or else (Ekind
(E
) = E_Enumeration_Literal
5919 and then Is_Derived_Type
(Etype
(E
)));
5920 end Is_Inherited_Operation
;
5922 -----------------------------
5923 -- Is_Library_Level_Entity --
5924 -----------------------------
5926 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
5928 -- The following is a small optimization, and it also properly handles
5929 -- discriminals, which in task bodies might appear in expressions before
5930 -- the corresponding procedure has been created, and which therefore do
5931 -- not have an assigned scope.
5933 if Ekind
(E
) in Formal_Kind
then
5937 -- Normal test is simply that the enclosing dynamic scope is Standard
5939 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
5940 end Is_Library_Level_Entity
;
5942 ---------------------------------
5943 -- Is_Local_Variable_Reference --
5944 ---------------------------------
5946 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
5948 if not Is_Entity_Name
(Expr
) then
5953 Ent
: constant Entity_Id
:= Entity
(Expr
);
5954 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
5956 if Ekind
(Ent
) /= E_Variable
5958 Ekind
(Ent
) /= E_In_Out_Parameter
5962 return Present
(Sub
) and then Sub
= Current_Subprogram
;
5966 end Is_Local_Variable_Reference
;
5968 -------------------------
5969 -- Is_Object_Reference --
5970 -------------------------
5972 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
5974 if Is_Entity_Name
(N
) then
5975 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
5979 when N_Indexed_Component | N_Slice
=>
5981 Is_Object_Reference
(Prefix
(N
))
5982 or else Is_Access_Type
(Etype
(Prefix
(N
)));
5984 -- In Ada95, a function call is a constant object; a procedure
5987 when N_Function_Call
=>
5988 return Etype
(N
) /= Standard_Void_Type
;
5990 -- A reference to the stream attribute Input is a function call
5992 when N_Attribute_Reference
=>
5993 return Attribute_Name
(N
) = Name_Input
;
5995 when N_Selected_Component
=>
5997 Is_Object_Reference
(Selector_Name
(N
))
5999 (Is_Object_Reference
(Prefix
(N
))
6000 or else Is_Access_Type
(Etype
(Prefix
(N
))));
6002 when N_Explicit_Dereference
=>
6005 -- A view conversion of a tagged object is an object reference
6007 when N_Type_Conversion
=>
6008 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
6009 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
6010 and then Is_Object_Reference
(Expression
(N
));
6012 -- An unchecked type conversion is considered to be an object if
6013 -- the operand is an object (this construction arises only as a
6014 -- result of expansion activities).
6016 when N_Unchecked_Type_Conversion
=>
6023 end Is_Object_Reference
;
6025 -----------------------------------
6026 -- Is_OK_Variable_For_Out_Formal --
6027 -----------------------------------
6029 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
6031 Note_Possible_Modification
(AV
);
6033 -- We must reject parenthesized variable names. The check for
6034 -- Comes_From_Source is present because there are currently
6035 -- cases where the compiler violates this rule (e.g. passing
6036 -- a task object to its controlled Initialize routine).
6038 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
6041 -- A variable is always allowed
6043 elsif Is_Variable
(AV
) then
6046 -- Unchecked conversions are allowed only if they come from the
6047 -- generated code, which sometimes uses unchecked conversions for out
6048 -- parameters in cases where code generation is unaffected. We tell
6049 -- source unchecked conversions by seeing if they are rewrites of an
6050 -- original Unchecked_Conversion function call, or of an explicit
6051 -- conversion of a function call.
6053 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
6054 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
6057 elsif Comes_From_Source
(AV
)
6058 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
6062 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
6063 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
6069 -- Normal type conversions are allowed if argument is a variable
6071 elsif Nkind
(AV
) = N_Type_Conversion
then
6072 if Is_Variable
(Expression
(AV
))
6073 and then Paren_Count
(Expression
(AV
)) = 0
6075 Note_Possible_Modification
(Expression
(AV
));
6078 -- We also allow a non-parenthesized expression that raises
6079 -- constraint error if it rewrites what used to be a variable
6081 elsif Raises_Constraint_Error
(Expression
(AV
))
6082 and then Paren_Count
(Expression
(AV
)) = 0
6083 and then Is_Variable
(Original_Node
(Expression
(AV
)))
6087 -- Type conversion of something other than a variable
6093 -- If this node is rewritten, then test the original form, if that is
6094 -- OK, then we consider the rewritten node OK (for example, if the
6095 -- original node is a conversion, then Is_Variable will not be true
6096 -- but we still want to allow the conversion if it converts a variable).
6098 elsif Original_Node
(AV
) /= AV
then
6099 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
6101 -- All other non-variables are rejected
6106 end Is_OK_Variable_For_Out_Formal
;
6114 E2
: Entity_Id
) return Boolean
6116 Iface_List
: List_Id
;
6117 T
: Entity_Id
:= E2
;
6120 if Is_Concurrent_Type
(T
)
6121 or else Is_Concurrent_Record_Type
(T
)
6123 Iface_List
:= Abstract_Interface_List
(E2
);
6125 if Is_Empty_List
(Iface_List
) then
6129 T
:= Etype
(First
(Iface_List
));
6132 return Is_Ancestor
(E1
, T
);
6135 -----------------------------------
6136 -- Is_Partially_Initialized_Type --
6137 -----------------------------------
6139 function Is_Partially_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
6141 if Is_Scalar_Type
(Typ
) then
6144 elsif Is_Access_Type
(Typ
) then
6147 elsif Is_Array_Type
(Typ
) then
6149 -- If component type is partially initialized, so is array type
6151 if Is_Partially_Initialized_Type
(Component_Type
(Typ
)) then
6154 -- Otherwise we are only partially initialized if we are fully
6155 -- initialized (this is the empty array case, no point in us
6156 -- duplicating that code here).
6159 return Is_Fully_Initialized_Type
(Typ
);
6162 elsif Is_Record_Type
(Typ
) then
6164 -- A discriminated type is always partially initialized
6166 if Has_Discriminants
(Typ
) then
6169 -- A tagged type is always partially initialized
6171 elsif Is_Tagged_Type
(Typ
) then
6174 -- Case of non-discriminated record
6180 Component_Present
: Boolean := False;
6181 -- Set True if at least one component is present. If no
6182 -- components are present, then record type is fully
6183 -- initialized (another odd case, like the null array).
6186 -- Loop through components
6188 Ent
:= First_Entity
(Typ
);
6189 while Present
(Ent
) loop
6190 if Ekind
(Ent
) = E_Component
then
6191 Component_Present
:= True;
6193 -- If a component has an initialization expression then
6194 -- the enclosing record type is partially initialized
6196 if Present
(Parent
(Ent
))
6197 and then Present
(Expression
(Parent
(Ent
)))
6201 -- If a component is of a type which is itself partially
6202 -- initialized, then the enclosing record type is also.
6204 elsif Is_Partially_Initialized_Type
(Etype
(Ent
)) then
6212 -- No initialized components found. If we found any components
6213 -- they were all uninitialized so the result is false.
6215 if Component_Present
then
6218 -- But if we found no components, then all the components are
6219 -- initialized so we consider the type to be initialized.
6227 -- Concurrent types are always fully initialized
6229 elsif Is_Concurrent_Type
(Typ
) then
6232 -- For a private type, go to underlying type. If there is no underlying
6233 -- type then just assume this partially initialized. Not clear if this
6234 -- can happen in a non-error case, but no harm in testing for this.
6236 elsif Is_Private_Type
(Typ
) then
6238 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6243 return Is_Partially_Initialized_Type
(U
);
6247 -- For any other type (are there any?) assume partially initialized
6252 end Is_Partially_Initialized_Type
;
6254 ------------------------------------
6255 -- Is_Potentially_Persistent_Type --
6256 ------------------------------------
6258 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
6263 -- For private type, test corrresponding full type
6265 if Is_Private_Type
(T
) then
6266 return Is_Potentially_Persistent_Type
(Full_View
(T
));
6268 -- Scalar types are potentially persistent
6270 elsif Is_Scalar_Type
(T
) then
6273 -- Record type is potentially persistent if not tagged and the types of
6274 -- all it components are potentially persistent, and no component has
6275 -- an initialization expression.
6277 elsif Is_Record_Type
(T
)
6278 and then not Is_Tagged_Type
(T
)
6279 and then not Is_Partially_Initialized_Type
(T
)
6281 Comp
:= First_Component
(T
);
6282 while Present
(Comp
) loop
6283 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
6292 -- Array type is potentially persistent if its component type is
6293 -- potentially persistent and if all its constraints are static.
6295 elsif Is_Array_Type
(T
) then
6296 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
6300 Indx
:= First_Index
(T
);
6301 while Present
(Indx
) loop
6302 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
6311 -- All other types are not potentially persistent
6316 end Is_Potentially_Persistent_Type
;
6318 -----------------------------
6319 -- Is_RCI_Pkg_Spec_Or_Body --
6320 -----------------------------
6322 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
6324 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
6325 -- Return True if the unit of Cunit is an RCI package declaration
6327 ---------------------------
6328 -- Is_RCI_Pkg_Decl_Cunit --
6329 ---------------------------
6331 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
6332 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
6335 if Nkind
(The_Unit
) /= N_Package_Declaration
then
6339 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
6340 end Is_RCI_Pkg_Decl_Cunit
;
6342 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6345 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
6347 (Nkind
(Unit
(Cunit
)) = N_Package_Body
6348 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
6349 end Is_RCI_Pkg_Spec_Or_Body
;
6351 -----------------------------------------
6352 -- Is_Remote_Access_To_Class_Wide_Type --
6353 -----------------------------------------
6355 function Is_Remote_Access_To_Class_Wide_Type
6356 (E
: Entity_Id
) return Boolean
6360 function Comes_From_Limited_Private_Type_Declaration
6361 (E
: Entity_Id
) return Boolean;
6362 -- Check that the type is declared by a limited type declaration,
6363 -- or else is derived from a Remote_Type ancestor through private
6366 -------------------------------------------------
6367 -- Comes_From_Limited_Private_Type_Declaration --
6368 -------------------------------------------------
6370 function Comes_From_Limited_Private_Type_Declaration
6371 (E
: Entity_Id
) return Boolean
6373 N
: constant Node_Id
:= Declaration_Node
(E
);
6376 if Nkind
(N
) = N_Private_Type_Declaration
6377 and then Limited_Present
(N
)
6382 if Nkind
(N
) = N_Private_Extension_Declaration
then
6384 Comes_From_Limited_Private_Type_Declaration
(Etype
(E
))
6386 (Is_Remote_Types
(Etype
(E
))
6387 and then Is_Limited_Record
(Etype
(E
))
6388 and then Has_Private_Declaration
(Etype
(E
)));
6392 end Comes_From_Limited_Private_Type_Declaration
;
6394 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6397 if not (Is_Remote_Call_Interface
(E
)
6398 or else Is_Remote_Types
(E
))
6399 or else Ekind
(E
) /= E_General_Access_Type
6404 D
:= Designated_Type
(E
);
6406 if Ekind
(D
) /= E_Class_Wide_Type
then
6410 return Comes_From_Limited_Private_Type_Declaration
6411 (Defining_Identifier
(Parent
(D
)));
6412 end Is_Remote_Access_To_Class_Wide_Type
;
6414 -----------------------------------------
6415 -- Is_Remote_Access_To_Subprogram_Type --
6416 -----------------------------------------
6418 function Is_Remote_Access_To_Subprogram_Type
6419 (E
: Entity_Id
) return Boolean
6422 return (Ekind
(E
) = E_Access_Subprogram_Type
6423 or else (Ekind
(E
) = E_Record_Type
6424 and then Present
(Corresponding_Remote_Type
(E
))))
6425 and then (Is_Remote_Call_Interface
(E
)
6426 or else Is_Remote_Types
(E
));
6427 end Is_Remote_Access_To_Subprogram_Type
;
6429 --------------------
6430 -- Is_Remote_Call --
6431 --------------------
6433 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
6435 if Nkind
(N
) /= N_Procedure_Call_Statement
6436 and then Nkind
(N
) /= N_Function_Call
6438 -- An entry call cannot be remote
6442 elsif Nkind
(Name
(N
)) in N_Has_Entity
6443 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
6445 -- A subprogram declared in the spec of a RCI package is remote
6449 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
6450 and then Is_Remote_Access_To_Subprogram_Type
6451 (Etype
(Prefix
(Name
(N
))))
6453 -- The dereference of a RAS is a remote call
6457 elsif Present
(Controlling_Argument
(N
))
6458 and then Is_Remote_Access_To_Class_Wide_Type
6459 (Etype
(Controlling_Argument
(N
)))
6461 -- Any primitive operation call with a controlling argument of
6462 -- a RACW type is a remote call.
6467 -- All other calls are local calls
6472 ----------------------
6473 -- Is_Renamed_Entry --
6474 ----------------------
6476 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
6477 Orig_Node
: Node_Id
:= Empty
;
6478 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
6480 function Is_Entry
(Nam
: Node_Id
) return Boolean;
6481 -- Determine whether Nam is an entry. Traverse selectors
6482 -- if there are nested selected components.
6488 function Is_Entry
(Nam
: Node_Id
) return Boolean is
6490 if Nkind
(Nam
) = N_Selected_Component
then
6491 return Is_Entry
(Selector_Name
(Nam
));
6494 return Ekind
(Entity
(Nam
)) = E_Entry
;
6497 -- Start of processing for Is_Renamed_Entry
6500 if Present
(Alias
(Proc_Nam
)) then
6501 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
6504 -- Look for a rewritten subprogram renaming declaration
6506 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
6507 and then Present
(Original_Node
(Subp_Decl
))
6509 Orig_Node
:= Original_Node
(Subp_Decl
);
6512 -- The rewritten subprogram is actually an entry
6514 if Present
(Orig_Node
)
6515 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
6516 and then Is_Entry
(Name
(Orig_Node
))
6522 end Is_Renamed_Entry
;
6524 ----------------------
6525 -- Is_Selector_Name --
6526 ----------------------
6528 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
6530 if not Is_List_Member
(N
) then
6532 P
: constant Node_Id
:= Parent
(N
);
6533 K
: constant Node_Kind
:= Nkind
(P
);
6536 (K
= N_Expanded_Name
or else
6537 K
= N_Generic_Association
or else
6538 K
= N_Parameter_Association
or else
6539 K
= N_Selected_Component
)
6540 and then Selector_Name
(P
) = N
;
6545 L
: constant List_Id
:= List_Containing
(N
);
6546 P
: constant Node_Id
:= Parent
(L
);
6548 return (Nkind
(P
) = N_Discriminant_Association
6549 and then Selector_Names
(P
) = L
)
6551 (Nkind
(P
) = N_Component_Association
6552 and then Choices
(P
) = L
);
6555 end Is_Selector_Name
;
6561 function Is_Statement
(N
: Node_Id
) return Boolean is
6564 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
6565 or else Nkind
(N
) = N_Procedure_Call_Statement
;
6568 ---------------------------------
6569 -- Is_Synchronized_Tagged_Type --
6570 ---------------------------------
6572 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
6573 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
6576 -- A task or protected type derived from an interface is a tagged type.
6577 -- Such a tagged type is called a synchronized tagged type, as are
6578 -- synchronized interfaces and private extensions whose declaration
6579 -- includes the reserved word synchronized.
6581 return (Is_Tagged_Type
(E
)
6582 and then (Kind
= E_Task_Type
6583 or else Kind
= E_Protected_Type
))
6586 and then Is_Synchronized_Interface
(E
))
6588 (Ekind
(E
) = E_Record_Type_With_Private
6589 and then (Synchronized_Present
(Parent
(E
))
6590 or else Is_Synchronized_Interface
(Etype
(E
))));
6591 end Is_Synchronized_Tagged_Type
;
6597 function Is_Transfer
(N
: Node_Id
) return Boolean is
6598 Kind
: constant Node_Kind
:= Nkind
(N
);
6601 if Kind
= N_Simple_Return_Statement
6603 Kind
= N_Extended_Return_Statement
6605 Kind
= N_Goto_Statement
6607 Kind
= N_Raise_Statement
6609 Kind
= N_Requeue_Statement
6613 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
6614 and then No
(Condition
(N
))
6618 elsif Kind
= N_Procedure_Call_Statement
6619 and then Is_Entity_Name
(Name
(N
))
6620 and then Present
(Entity
(Name
(N
)))
6621 and then No_Return
(Entity
(Name
(N
)))
6625 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
6637 function Is_True
(U
: Uint
) return Boolean is
6646 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
6648 return VM_Target
= CLI_Target
6649 and then Chars
(T
) /= No_Name
6650 and then Get_Name_String
(Chars
(T
)) = "valuetype";
6657 function Is_Variable
(N
: Node_Id
) return Boolean is
6659 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
6660 -- We do the test on the original node, since this is basically a
6661 -- test of syntactic categories, so it must not be disturbed by
6662 -- whatever rewriting might have occurred. For example, an aggregate,
6663 -- which is certainly NOT a variable, could be turned into a variable
6666 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
6667 -- Within a protected function, the private components of the
6668 -- enclosing protected type are constants. A function nested within
6669 -- a (protected) procedure is not itself protected.
6671 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
6672 -- Prefixes can involve implicit dereferences, in which case we
6673 -- must test for the case of a reference of a constant access
6674 -- type, which can never be a variable.
6676 ---------------------------
6677 -- In_Protected_Function --
6678 ---------------------------
6680 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
6681 Prot
: constant Entity_Id
:= Scope
(E
);
6685 if not Is_Protected_Type
(Prot
) then
6689 while Present
(S
) and then S
/= Prot
loop
6690 if Ekind
(S
) = E_Function
6691 and then Scope
(S
) = Prot
6701 end In_Protected_Function
;
6703 ------------------------
6704 -- Is_Variable_Prefix --
6705 ------------------------
6707 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
6709 if Is_Access_Type
(Etype
(P
)) then
6710 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
6712 -- For the case of an indexed component whose prefix has a packed
6713 -- array type, the prefix has been rewritten into a type conversion.
6714 -- Determine variable-ness from the converted expression.
6716 elsif Nkind
(P
) = N_Type_Conversion
6717 and then not Comes_From_Source
(P
)
6718 and then Is_Array_Type
(Etype
(P
))
6719 and then Is_Packed
(Etype
(P
))
6721 return Is_Variable
(Expression
(P
));
6724 return Is_Variable
(P
);
6726 end Is_Variable_Prefix
;
6728 -- Start of processing for Is_Variable
6731 -- Definitely OK if Assignment_OK is set. Since this is something that
6732 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6734 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
6737 -- Normally we go to the original node, but there is one exception
6738 -- where we use the rewritten node, namely when it is an explicit
6739 -- dereference. The generated code may rewrite a prefix which is an
6740 -- access type with an explicit dereference. The dereference is a
6741 -- variable, even though the original node may not be (since it could
6742 -- be a constant of the access type).
6744 -- In Ada 2005 we have a further case to consider: the prefix may be
6745 -- a function call given in prefix notation. The original node appears
6746 -- to be a selected component, but we need to examine the call.
6748 elsif Nkind
(N
) = N_Explicit_Dereference
6749 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
6750 and then Present
(Etype
(Orig_Node
))
6751 and then Is_Access_Type
(Etype
(Orig_Node
))
6753 return Is_Variable_Prefix
(Original_Node
(Prefix
(N
)))
6755 (Nkind
(Orig_Node
) = N_Function_Call
6756 and then not Is_Access_Constant
(Etype
(Prefix
(N
))));
6758 -- A function call is never a variable
6760 elsif Nkind
(N
) = N_Function_Call
then
6763 -- All remaining checks use the original node
6765 elsif Is_Entity_Name
(Orig_Node
)
6766 and then Present
(Entity
(Orig_Node
))
6769 E
: constant Entity_Id
:= Entity
(Orig_Node
);
6770 K
: constant Entity_Kind
:= Ekind
(E
);
6773 return (K
= E_Variable
6774 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
6775 or else (K
= E_Component
6776 and then not In_Protected_Function
(E
))
6777 or else K
= E_Out_Parameter
6778 or else K
= E_In_Out_Parameter
6779 or else K
= E_Generic_In_Out_Parameter
6781 -- Current instance of type:
6783 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
6784 or else (Is_Incomplete_Or_Private_Type
(E
)
6785 and then In_Open_Scopes
(Full_View
(E
)));
6789 case Nkind
(Orig_Node
) is
6790 when N_Indexed_Component | N_Slice
=>
6791 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
6793 when N_Selected_Component
=>
6794 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
6795 and then Is_Variable
(Selector_Name
(Orig_Node
));
6797 -- For an explicit dereference, the type of the prefix cannot
6798 -- be an access to constant or an access to subprogram.
6800 when N_Explicit_Dereference
=>
6802 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
6804 return Is_Access_Type
(Typ
)
6805 and then not Is_Access_Constant
(Root_Type
(Typ
))
6806 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
6809 -- The type conversion is the case where we do not deal with the
6810 -- context dependent special case of an actual parameter. Thus
6811 -- the type conversion is only considered a variable for the
6812 -- purposes of this routine if the target type is tagged. However,
6813 -- a type conversion is considered to be a variable if it does not
6814 -- come from source (this deals for example with the conversions
6815 -- of expressions to their actual subtypes).
6817 when N_Type_Conversion
=>
6818 return Is_Variable
(Expression
(Orig_Node
))
6820 (not Comes_From_Source
(Orig_Node
)
6822 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
6824 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
6826 -- GNAT allows an unchecked type conversion as a variable. This
6827 -- only affects the generation of internal expanded code, since
6828 -- calls to instantiations of Unchecked_Conversion are never
6829 -- considered variables (since they are function calls).
6830 -- This is also true for expression actions.
6832 when N_Unchecked_Type_Conversion
=>
6833 return Is_Variable
(Expression
(Orig_Node
));
6841 ------------------------
6842 -- Is_Volatile_Object --
6843 ------------------------
6845 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
6847 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
6848 -- Determines if given object has volatile components
6850 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
6851 -- If prefix is an implicit dereference, examine designated type
6853 ------------------------
6854 -- Is_Volatile_Prefix --
6855 ------------------------
6857 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
6858 Typ
: constant Entity_Id
:= Etype
(N
);
6861 if Is_Access_Type
(Typ
) then
6863 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
6866 return Is_Volatile
(Dtyp
)
6867 or else Has_Volatile_Components
(Dtyp
);
6871 return Object_Has_Volatile_Components
(N
);
6873 end Is_Volatile_Prefix
;
6875 ------------------------------------
6876 -- Object_Has_Volatile_Components --
6877 ------------------------------------
6879 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
6880 Typ
: constant Entity_Id
:= Etype
(N
);
6883 if Is_Volatile
(Typ
)
6884 or else Has_Volatile_Components
(Typ
)
6888 elsif Is_Entity_Name
(N
)
6889 and then (Has_Volatile_Components
(Entity
(N
))
6890 or else Is_Volatile
(Entity
(N
)))
6894 elsif Nkind
(N
) = N_Indexed_Component
6895 or else Nkind
(N
) = N_Selected_Component
6897 return Is_Volatile_Prefix
(Prefix
(N
));
6902 end Object_Has_Volatile_Components
;
6904 -- Start of processing for Is_Volatile_Object
6907 if Is_Volatile
(Etype
(N
))
6908 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
6912 elsif Nkind
(N
) = N_Indexed_Component
6913 or else Nkind
(N
) = N_Selected_Component
6915 return Is_Volatile_Prefix
(Prefix
(N
));
6920 end Is_Volatile_Object
;
6922 -------------------------
6923 -- Kill_Current_Values --
6924 -------------------------
6926 procedure Kill_Current_Values
(Ent
: Entity_Id
) is
6928 if Is_Object
(Ent
) then
6930 Set_Current_Value
(Ent
, Empty
);
6932 if Ekind
(Ent
) = E_Variable
then
6933 Set_Last_Assignment
(Ent
, Empty
);
6936 if not Can_Never_Be_Null
(Ent
) then
6937 Set_Is_Known_Non_Null
(Ent
, False);
6940 Set_Is_Known_Null
(Ent
, False);
6942 end Kill_Current_Values
;
6944 procedure Kill_Current_Values
is
6947 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
6948 -- Clear current value for entity E and all entities chained to E
6950 ------------------------------------------
6951 -- Kill_Current_Values_For_Entity_Chain --
6952 ------------------------------------------
6954 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
6958 while Present
(Ent
) loop
6959 Kill_Current_Values
(Ent
);
6962 end Kill_Current_Values_For_Entity_Chain
;
6964 -- Start of processing for Kill_Current_Values
6967 -- Kill all saved checks, a special case of killing saved values
6971 -- Loop through relevant scopes, which includes the current scope and
6972 -- any parent scopes if the current scope is a block or a package.
6977 -- Clear current values of all entities in current scope
6979 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
6981 -- If scope is a package, also clear current values of all
6982 -- private entities in the scope.
6984 if Ekind
(S
) = E_Package
6986 Ekind
(S
) = E_Generic_Package
6988 Is_Concurrent_Type
(S
)
6990 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
6993 -- If this is a not a subprogram, deal with parents
6995 if not Is_Subprogram
(S
) then
6997 exit Scope_Loop
when S
= Standard_Standard
;
7001 end loop Scope_Loop
;
7002 end Kill_Current_Values
;
7004 --------------------------
7005 -- Kill_Size_Check_Code --
7006 --------------------------
7008 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
7010 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
7011 and then Present
(Size_Check_Code
(E
))
7013 Remove
(Size_Check_Code
(E
));
7014 Set_Size_Check_Code
(E
, Empty
);
7016 end Kill_Size_Check_Code
;
7018 --------------------------
7019 -- Known_To_Be_Assigned --
7020 --------------------------
7022 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
7023 P
: constant Node_Id
:= Parent
(N
);
7028 -- Test left side of assignment
7030 when N_Assignment_Statement
=>
7031 return N
= Name
(P
);
7033 -- Function call arguments are never lvalues
7035 when N_Function_Call
=>
7038 -- Positional parameter for procedure or accept call
7040 when N_Procedure_Call_Statement |
7049 Proc
:= Get_Subprogram_Entity
(P
);
7055 -- If we are not a list member, something is strange, so
7056 -- be conservative and return False.
7058 if not Is_List_Member
(N
) then
7062 -- We are going to find the right formal by stepping forward
7063 -- through the formals, as we step backwards in the actuals.
7065 Form
:= First_Formal
(Proc
);
7068 -- If no formal, something is weird, so be conservative
7069 -- and return False.
7080 return Ekind
(Form
) /= E_In_Parameter
;
7083 -- Named parameter for procedure or accept call
7085 when N_Parameter_Association
=>
7091 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7097 -- Loop through formals to find the one that matches
7099 Form
:= First_Formal
(Proc
);
7101 -- If no matching formal, that's peculiar, some kind of
7102 -- previous error, so return False to be conservative.
7108 -- Else test for match
7110 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7111 return Ekind
(Form
) /= E_In_Parameter
;
7118 -- Test for appearing in a conversion that itself appears
7119 -- in an lvalue context, since this should be an lvalue.
7121 when N_Type_Conversion
=>
7122 return Known_To_Be_Assigned
(P
);
7124 -- All other references are definitely not knwon to be modifications
7130 end Known_To_Be_Assigned
;
7136 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
7137 P
: constant Node_Id
:= Parent
(N
);
7142 -- Test left side of assignment
7144 when N_Assignment_Statement
=>
7145 return N
= Name
(P
);
7147 -- Test prefix of component or attribute
7149 when N_Attribute_Reference
=>
7150 return N
= Prefix
(P
)
7151 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
7153 when N_Expanded_Name |
7154 N_Explicit_Dereference |
7155 N_Indexed_Component |
7157 N_Selected_Component |
7159 return N
= Prefix
(P
);
7161 -- Function call arguments are never lvalues
7163 when N_Function_Call
=>
7166 -- Positional parameter for procedure, entry, or accept call
7168 when N_Procedure_Call_Statement |
7169 N_Entry_Call_Statement |
7178 Proc
:= Get_Subprogram_Entity
(P
);
7184 -- If we are not a list member, something is strange, so
7185 -- be conservative and return True.
7187 if not Is_List_Member
(N
) then
7191 -- We are going to find the right formal by stepping forward
7192 -- through the formals, as we step backwards in the actuals.
7194 Form
:= First_Formal
(Proc
);
7197 -- If no formal, something is weird, so be conservative
7209 return Ekind
(Form
) /= E_In_Parameter
;
7212 -- Named parameter for procedure or accept call
7214 when N_Parameter_Association
=>
7220 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7226 -- Loop through formals to find the one that matches
7228 Form
:= First_Formal
(Proc
);
7230 -- If no matching formal, that's peculiar, some kind of
7231 -- previous error, so return True to be conservative.
7237 -- Else test for match
7239 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7240 return Ekind
(Form
) /= E_In_Parameter
;
7247 -- Test for appearing in a conversion that itself appears
7248 -- in an lvalue context, since this should be an lvalue.
7250 when N_Type_Conversion
=>
7251 return May_Be_Lvalue
(P
);
7253 -- Test for appearence in object renaming declaration
7255 when N_Object_Renaming_Declaration
=>
7258 -- All other references are definitely not Lvalues
7266 -----------------------
7267 -- Mark_Coextensions --
7268 -----------------------
7270 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
7271 Is_Dynamic
: Boolean := False;
7273 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
7274 -- Recognize an allocator node and label it as a dynamic coextension
7276 --------------------
7277 -- Mark_Allocator --
7278 --------------------
7280 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
7282 if Nkind
(N
) = N_Allocator
then
7284 Set_Is_Dynamic_Coextension
(N
);
7286 Set_Is_Static_Coextension
(N
);
7293 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
7295 -- Start of processing Mark_Coextensions
7298 case Nkind
(Context_Nod
) is
7299 when N_Assignment_Statement |
7300 N_Simple_Return_Statement
=>
7301 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
7303 when N_Object_Declaration
=>
7304 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
;
7306 -- This routine should not be called for constructs which may not
7307 -- contain coextensions.
7310 raise Program_Error
;
7313 Mark_Allocators
(Root_Nod
);
7314 end Mark_Coextensions
;
7316 ----------------------
7317 -- Needs_One_Actual --
7318 ----------------------
7320 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
7324 if Ada_Version
>= Ada_05
7325 and then Present
(First_Formal
(E
))
7327 Formal
:= Next_Formal
(First_Formal
(E
));
7328 while Present
(Formal
) loop
7329 if No
(Default_Value
(Formal
)) then
7333 Next_Formal
(Formal
);
7341 end Needs_One_Actual
;
7343 -------------------------
7344 -- New_External_Entity --
7345 -------------------------
7347 function New_External_Entity
7348 (Kind
: Entity_Kind
;
7349 Scope_Id
: Entity_Id
;
7350 Sloc_Value
: Source_Ptr
;
7351 Related_Id
: Entity_Id
;
7353 Suffix_Index
: Nat
:= 0;
7354 Prefix
: Character := ' ') return Entity_Id
7356 N
: constant Entity_Id
:=
7357 Make_Defining_Identifier
(Sloc_Value
,
7359 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
7362 Set_Ekind
(N
, Kind
);
7363 Set_Is_Internal
(N
, True);
7364 Append_Entity
(N
, Scope_Id
);
7365 Set_Public_Status
(N
);
7367 if Kind
in Type_Kind
then
7368 Init_Size_Align
(N
);
7372 end New_External_Entity
;
7374 -------------------------
7375 -- New_Internal_Entity --
7376 -------------------------
7378 function New_Internal_Entity
7379 (Kind
: Entity_Kind
;
7380 Scope_Id
: Entity_Id
;
7381 Sloc_Value
: Source_Ptr
;
7382 Id_Char
: Character) return Entity_Id
7384 N
: constant Entity_Id
:=
7385 Make_Defining_Identifier
(Sloc_Value
, New_Internal_Name
(Id_Char
));
7388 Set_Ekind
(N
, Kind
);
7389 Set_Is_Internal
(N
, True);
7390 Append_Entity
(N
, Scope_Id
);
7392 if Kind
in Type_Kind
then
7393 Init_Size_Align
(N
);
7397 end New_Internal_Entity
;
7403 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
7407 -- If we are pointing at a positional parameter, it is a member of
7408 -- a node list (the list of parameters), and the next parameter
7409 -- is the next node on the list, unless we hit a parameter
7410 -- association, in which case we shift to using the chain whose
7411 -- head is the First_Named_Actual in the parent, and then is
7412 -- threaded using the Next_Named_Actual of the Parameter_Association.
7413 -- All this fiddling is because the original node list is in the
7414 -- textual call order, and what we need is the declaration order.
7416 if Is_List_Member
(Actual_Id
) then
7417 N
:= Next
(Actual_Id
);
7419 if Nkind
(N
) = N_Parameter_Association
then
7420 return First_Named_Actual
(Parent
(Actual_Id
));
7426 return Next_Named_Actual
(Parent
(Actual_Id
));
7430 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
7432 Actual_Id
:= Next_Actual
(Actual_Id
);
7435 -----------------------
7436 -- Normalize_Actuals --
7437 -----------------------
7439 -- Chain actuals according to formals of subprogram. If there are no named
7440 -- associations, the chain is simply the list of Parameter Associations,
7441 -- since the order is the same as the declaration order. If there are named
7442 -- associations, then the First_Named_Actual field in the N_Function_Call
7443 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7444 -- node for the parameter that comes first in declaration order. The
7445 -- remaining named parameters are then chained in declaration order using
7446 -- Next_Named_Actual.
7448 -- This routine also verifies that the number of actuals is compatible with
7449 -- the number and default values of formals, but performs no type checking
7450 -- (type checking is done by the caller).
7452 -- If the matching succeeds, Success is set to True and the caller proceeds
7453 -- with type-checking. If the match is unsuccessful, then Success is set to
7454 -- False, and the caller attempts a different interpretation, if there is
7457 -- If the flag Report is on, the call is not overloaded, and a failure to
7458 -- match can be reported here, rather than in the caller.
7460 procedure Normalize_Actuals
7464 Success
: out Boolean)
7466 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7467 Actual
: Node_Id
:= Empty
;
7469 Last
: Node_Id
:= Empty
;
7470 First_Named
: Node_Id
:= Empty
;
7473 Formals_To_Match
: Integer := 0;
7474 Actuals_To_Match
: Integer := 0;
7476 procedure Chain
(A
: Node_Id
);
7477 -- Add named actual at the proper place in the list, using the
7478 -- Next_Named_Actual link.
7480 function Reporting
return Boolean;
7481 -- Determines if an error is to be reported. To report an error, we
7482 -- need Report to be True, and also we do not report errors caused
7483 -- by calls to init procs that occur within other init procs. Such
7484 -- errors must always be cascaded errors, since if all the types are
7485 -- declared correctly, the compiler will certainly build decent calls!
7491 procedure Chain
(A
: Node_Id
) is
7495 -- Call node points to first actual in list
7497 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
7500 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
7504 Set_Next_Named_Actual
(Last
, Empty
);
7511 function Reporting
return Boolean is
7516 elsif not Within_Init_Proc
then
7519 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
7527 -- Start of processing for Normalize_Actuals
7530 if Is_Access_Type
(S
) then
7532 -- The name in the call is a function call that returns an access
7533 -- to subprogram. The designated type has the list of formals.
7535 Formal
:= First_Formal
(Designated_Type
(S
));
7537 Formal
:= First_Formal
(S
);
7540 while Present
(Formal
) loop
7541 Formals_To_Match
:= Formals_To_Match
+ 1;
7542 Next_Formal
(Formal
);
7545 -- Find if there is a named association, and verify that no positional
7546 -- associations appear after named ones.
7548 if Present
(Actuals
) then
7549 Actual
:= First
(Actuals
);
7552 while Present
(Actual
)
7553 and then Nkind
(Actual
) /= N_Parameter_Association
7555 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7559 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
7561 -- Most common case: positional notation, no defaults
7566 elsif Actuals_To_Match
> Formals_To_Match
then
7568 -- Too many actuals: will not work
7571 if Is_Entity_Name
(Name
(N
)) then
7572 Error_Msg_N
("too many arguments in call to&", Name
(N
));
7574 Error_Msg_N
("too many arguments in call", N
);
7582 First_Named
:= Actual
;
7584 while Present
(Actual
) loop
7585 if Nkind
(Actual
) /= N_Parameter_Association
then
7587 ("positional parameters not allowed after named ones", Actual
);
7592 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7598 if Present
(Actuals
) then
7599 Actual
:= First
(Actuals
);
7602 Formal
:= First_Formal
(S
);
7603 while Present
(Formal
) loop
7605 -- Match the formals in order. If the corresponding actual
7606 -- is positional, nothing to do. Else scan the list of named
7607 -- actuals to find the one with the right name.
7610 and then Nkind
(Actual
) /= N_Parameter_Association
7613 Actuals_To_Match
:= Actuals_To_Match
- 1;
7614 Formals_To_Match
:= Formals_To_Match
- 1;
7617 -- For named parameters, search the list of actuals to find
7618 -- one that matches the next formal name.
7620 Actual
:= First_Named
;
7622 while Present
(Actual
) loop
7623 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
7626 Actuals_To_Match
:= Actuals_To_Match
- 1;
7627 Formals_To_Match
:= Formals_To_Match
- 1;
7635 if Ekind
(Formal
) /= E_In_Parameter
7636 or else No
(Default_Value
(Formal
))
7639 if (Comes_From_Source
(S
)
7640 or else Sloc
(S
) = Standard_Location
)
7641 and then Is_Overloadable
(S
)
7645 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
7647 (Nkind
(Parent
(N
)) = N_Function_Call
7649 Nkind
(Parent
(N
)) = N_Parameter_Association
))
7650 and then Ekind
(S
) /= E_Function
7652 Set_Etype
(N
, Etype
(S
));
7654 Error_Msg_Name_1
:= Chars
(S
);
7655 Error_Msg_Sloc
:= Sloc
(S
);
7657 ("missing argument for parameter & " &
7658 "in call to % declared #", N
, Formal
);
7661 elsif Is_Overloadable
(S
) then
7662 Error_Msg_Name_1
:= Chars
(S
);
7664 -- Point to type derivation that generated the
7667 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
7670 ("missing argument for parameter & " &
7671 "in call to % (inherited) #", N
, Formal
);
7675 ("missing argument for parameter &", N
, Formal
);
7683 Formals_To_Match
:= Formals_To_Match
- 1;
7688 Next_Formal
(Formal
);
7691 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
7698 -- Find some superfluous named actual that did not get
7699 -- attached to the list of associations.
7701 Actual
:= First
(Actuals
);
7702 while Present
(Actual
) loop
7703 if Nkind
(Actual
) = N_Parameter_Association
7704 and then Actual
/= Last
7705 and then No
(Next_Named_Actual
(Actual
))
7707 Error_Msg_N
("unmatched actual & in call",
7708 Selector_Name
(Actual
));
7719 end Normalize_Actuals
;
7721 --------------------------------
7722 -- Note_Possible_Modification --
7723 --------------------------------
7725 procedure Note_Possible_Modification
(N
: Node_Id
) is
7726 Modification_Comes_From_Source
: constant Boolean :=
7727 Comes_From_Source
(Parent
(N
));
7733 -- Loop to find referenced entity, if there is one
7740 if Is_Entity_Name
(Exp
) then
7741 Ent
:= Entity
(Exp
);
7743 -- If the entity is missing, it is an undeclared identifier,
7744 -- and there is nothing to annotate.
7750 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
7752 P
: constant Node_Id
:= Prefix
(Exp
);
7755 if Nkind
(P
) = N_Selected_Component
7757 Entry_Formal
(Entity
(Selector_Name
(P
))))
7759 -- Case of a reference to an entry formal
7761 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
7763 elsif Nkind
(P
) = N_Identifier
7764 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
7765 and then Present
(Expression
(Parent
(Entity
(P
))))
7766 and then Nkind
(Expression
(Parent
(Entity
(P
))))
7769 -- Case of a reference to a value on which
7770 -- side effects have been removed.
7772 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
7781 elsif Nkind
(Exp
) = N_Type_Conversion
7782 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
7784 Exp
:= Expression
(Exp
);
7787 elsif Nkind
(Exp
) = N_Slice
7788 or else Nkind
(Exp
) = N_Indexed_Component
7789 or else Nkind
(Exp
) = N_Selected_Component
7791 Exp
:= Prefix
(Exp
);
7798 -- Now look for entity being referenced
7800 if Present
(Ent
) then
7801 if Is_Object
(Ent
) then
7802 if Comes_From_Source
(Exp
)
7803 or else Modification_Comes_From_Source
7805 Set_Never_Set_In_Source
(Ent
, False);
7808 Set_Is_True_Constant
(Ent
, False);
7809 Set_Current_Value
(Ent
, Empty
);
7810 Set_Is_Known_Null
(Ent
, False);
7812 if not Can_Never_Be_Null
(Ent
) then
7813 Set_Is_Known_Non_Null
(Ent
, False);
7816 -- Follow renaming chain
7818 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
7819 and then Present
(Renamed_Object
(Ent
))
7821 Exp
:= Renamed_Object
(Ent
);
7825 -- Generate a reference only if the assignment comes from
7826 -- source. This excludes, for example, calls to a dispatching
7827 -- assignment operation when the left-hand side is tagged.
7829 if Modification_Comes_From_Source
then
7830 Generate_Reference
(Ent
, Exp
, 'm');
7833 Check_Nested_Access
(Ent
);
7840 end Note_Possible_Modification
;
7842 -------------------------
7843 -- Object_Access_Level --
7844 -------------------------
7846 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
7849 -- Returns the static accessibility level of the view denoted
7850 -- by Obj. Note that the value returned is the result of a
7851 -- call to Scope_Depth. Only scope depths associated with
7852 -- dynamic scopes can actually be returned. Since only
7853 -- relative levels matter for accessibility checking, the fact
7854 -- that the distance between successive levels of accessibility
7855 -- is not always one is immaterial (invariant: if level(E2) is
7856 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7858 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
7859 -- An explicit dereference is created when removing side-effects
7860 -- from expressions for constraint checking purposes. In this case
7861 -- a local access type is created for it. The correct access level
7862 -- is that of the original source node. We detect this case by
7863 -- noting that the prefix of the dereference is created by an object
7864 -- declaration whose initial expression is a reference.
7870 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
7871 Pref
: constant Node_Id
:= Prefix
(Obj
);
7873 if Is_Entity_Name
(Pref
)
7874 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
7875 and then Present
(Expression
(Parent
(Entity
(Pref
))))
7876 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
7878 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
7884 -- Start of processing for Object_Access_Level
7887 if Is_Entity_Name
(Obj
) then
7890 -- If E is a type then it denotes a current instance.
7891 -- For this case we add one to the normal accessibility
7892 -- level of the type to ensure that current instances
7893 -- are treated as always being deeper than than the level
7894 -- of any visible named access type (see 3.10.2(21)).
7897 return Type_Access_Level
(E
) + 1;
7899 elsif Present
(Renamed_Object
(E
)) then
7900 return Object_Access_Level
(Renamed_Object
(E
));
7902 -- Similarly, if E is a component of the current instance of a
7903 -- protected type, any instance of it is assumed to be at a deeper
7904 -- level than the type. For a protected object (whose type is an
7905 -- anonymous protected type) its components are at the same level
7906 -- as the type itself.
7908 elsif not Is_Overloadable
(E
)
7909 and then Ekind
(Scope
(E
)) = E_Protected_Type
7910 and then Comes_From_Source
(Scope
(E
))
7912 return Type_Access_Level
(Scope
(E
)) + 1;
7915 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
7918 elsif Nkind
(Obj
) = N_Selected_Component
then
7919 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
7920 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
7922 return Object_Access_Level
(Prefix
(Obj
));
7925 elsif Nkind
(Obj
) = N_Indexed_Component
then
7926 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
7927 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
7929 return Object_Access_Level
(Prefix
(Obj
));
7932 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
7934 -- If the prefix is a selected access discriminant then
7935 -- we make a recursive call on the prefix, which will
7936 -- in turn check the level of the prefix object of
7937 -- the selected discriminant.
7939 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
7940 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
7942 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
7944 return Object_Access_Level
(Prefix
(Obj
));
7946 elsif not (Comes_From_Source
(Obj
)) then
7948 Ref
: constant Node_Id
:= Reference_To
(Obj
);
7950 if Present
(Ref
) then
7951 return Object_Access_Level
(Ref
);
7953 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
7958 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
7961 elsif Nkind
(Obj
) = N_Type_Conversion
7962 or else Nkind
(Obj
) = N_Unchecked_Type_Conversion
7964 return Object_Access_Level
(Expression
(Obj
));
7966 -- Function results are objects, so we get either the access level
7967 -- of the function or, in the case of an indirect call, the level of
7968 -- of the access-to-subprogram type.
7970 elsif Nkind
(Obj
) = N_Function_Call
then
7971 if Is_Entity_Name
(Name
(Obj
)) then
7972 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
7974 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
7977 -- For convenience we handle qualified expressions, even though
7978 -- they aren't technically object names.
7980 elsif Nkind
(Obj
) = N_Qualified_Expression
then
7981 return Object_Access_Level
(Expression
(Obj
));
7983 -- Otherwise return the scope level of Standard.
7984 -- (If there are cases that fall through
7985 -- to this point they will be treated as
7986 -- having global accessibility for now. ???)
7989 return Scope_Depth
(Standard_Standard
);
7991 end Object_Access_Level
;
7993 -----------------------
7994 -- Private_Component --
7995 -----------------------
7997 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
7998 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
8000 function Trace_Components
8002 Check
: Boolean) return Entity_Id
;
8003 -- Recursive function that does the work, and checks against circular
8004 -- definition for each subcomponent type.
8006 ----------------------
8007 -- Trace_Components --
8008 ----------------------
8010 function Trace_Components
8012 Check
: Boolean) return Entity_Id
8014 Btype
: constant Entity_Id
:= Base_Type
(T
);
8015 Component
: Entity_Id
;
8017 Candidate
: Entity_Id
:= Empty
;
8020 if Check
and then Btype
= Ancestor
then
8021 Error_Msg_N
("circular type definition", Type_Id
);
8025 if Is_Private_Type
(Btype
)
8026 and then not Is_Generic_Type
(Btype
)
8028 if Present
(Full_View
(Btype
))
8029 and then Is_Record_Type
(Full_View
(Btype
))
8030 and then not Is_Frozen
(Btype
)
8032 -- To indicate that the ancestor depends on a private type,
8033 -- the current Btype is sufficient. However, to check for
8034 -- circular definition we must recurse on the full view.
8036 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
8038 if Candidate
= Any_Type
then
8048 elsif Is_Array_Type
(Btype
) then
8049 return Trace_Components
(Component_Type
(Btype
), True);
8051 elsif Is_Record_Type
(Btype
) then
8052 Component
:= First_Entity
(Btype
);
8053 while Present
(Component
) loop
8055 -- Skip anonymous types generated by constrained components
8057 if not Is_Type
(Component
) then
8058 P
:= Trace_Components
(Etype
(Component
), True);
8061 if P
= Any_Type
then
8069 Next_Entity
(Component
);
8077 end Trace_Components
;
8079 -- Start of processing for Private_Component
8082 return Trace_Components
(Type_Id
, False);
8083 end Private_Component
;
8085 -----------------------
8086 -- Process_End_Label --
8087 -----------------------
8089 procedure Process_End_Label
8097 Label_Ref
: Boolean;
8098 -- Set True if reference to end label itself is required
8101 -- Gets set to the operator symbol or identifier that references
8102 -- the entity Ent. For the child unit case, this is the identifier
8103 -- from the designator. For other cases, this is simply Endl.
8105 procedure Generate_Parent_Ref
(N
: Node_Id
);
8106 -- N is an identifier node that appears as a parent unit reference
8107 -- in the case where Ent is a child unit. This procedure generates
8108 -- an appropriate cross-reference entry.
8110 -------------------------
8111 -- Generate_Parent_Ref --
8112 -------------------------
8114 procedure Generate_Parent_Ref
(N
: Node_Id
) is
8115 Parent_Ent
: Entity_Id
;
8118 -- Search up scope stack. The reason we do this is that normal
8119 -- visibility analysis would not work for two reasons. First in
8120 -- some subunit cases, the entry for the parent unit may not be
8121 -- visible, and in any case there can be a local entity that
8122 -- hides the scope entity.
8124 Parent_Ent
:= Current_Scope
;
8125 while Present
(Parent_Ent
) loop
8126 if Chars
(Parent_Ent
) = Chars
(N
) then
8128 -- Generate the reference. We do NOT consider this as a
8129 -- reference for unreferenced symbol purposes, but we do
8130 -- force a cross-reference even if the end line does not
8131 -- come from source (the caller already generated the
8132 -- appropriate Typ for this situation).
8135 (Parent_Ent
, N
, 'r', Set_Ref
=> False, Force
=> True);
8136 Style
.Check_Identifier
(N
, Parent_Ent
);
8140 Parent_Ent
:= Scope
(Parent_Ent
);
8143 -- Fall through means entity was not found -- that's odd, but
8144 -- the appropriate thing is simply to ignore and not generate
8145 -- any cross-reference for this entry.
8148 end Generate_Parent_Ref
;
8150 -- Start of processing for Process_End_Label
8153 -- If no node, ignore. This happens in some error situations,
8154 -- and also for some internally generated structures where no
8155 -- end label references are required in any case.
8161 -- Nothing to do if no End_Label, happens for internally generated
8162 -- constructs where we don't want an end label reference anyway.
8163 -- Also nothing to do if Endl is a string literal, which means
8164 -- there was some prior error (bad operator symbol)
8166 Endl
:= End_Label
(N
);
8168 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
8172 -- Reference node is not in extended main source unit
8174 if not In_Extended_Main_Source_Unit
(N
) then
8176 -- Generally we do not collect references except for the
8177 -- extended main source unit. The one exception is the 'e'
8178 -- entry for a package spec, where it is useful for a client
8179 -- to have the ending information to define scopes.
8187 -- For this case, we can ignore any parent references,
8188 -- but we need the package name itself for the 'e' entry.
8190 if Nkind
(Endl
) = N_Designator
then
8191 Endl
:= Identifier
(Endl
);
8195 -- Reference is in extended main source unit
8200 -- For designator, generate references for the parent entries
8202 if Nkind
(Endl
) = N_Designator
then
8204 -- Generate references for the prefix if the END line comes
8205 -- from source (otherwise we do not need these references)
8207 if Comes_From_Source
(Endl
) then
8209 while Nkind
(Nam
) = N_Selected_Component
loop
8210 Generate_Parent_Ref
(Selector_Name
(Nam
));
8211 Nam
:= Prefix
(Nam
);
8214 Generate_Parent_Ref
(Nam
);
8217 Endl
:= Identifier
(Endl
);
8221 -- If the end label is not for the given entity, then either we have
8222 -- some previous error, or this is a generic instantiation for which
8223 -- we do not need to make a cross-reference in this case anyway. In
8224 -- either case we simply ignore the call.
8226 if Chars
(Ent
) /= Chars
(Endl
) then
8230 -- If label was really there, then generate a normal reference
8231 -- and then adjust the location in the end label to point past
8232 -- the name (which should almost always be the semicolon).
8236 if Comes_From_Source
(Endl
) then
8238 -- If a label reference is required, then do the style check
8239 -- and generate an l-type cross-reference entry for the label
8243 Style
.Check_Identifier
(Endl
, Ent
);
8245 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
8248 -- Set the location to point past the label (normally this will
8249 -- mean the semicolon immediately following the label). This is
8250 -- done for the sake of the 'e' or 't' entry generated below.
8252 Get_Decoded_Name_String
(Chars
(Endl
));
8253 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
8256 -- Now generate the e/t reference
8258 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
8260 -- Restore Sloc, in case modified above, since we have an identifier
8261 -- and the normal Sloc should be left set in the tree.
8263 Set_Sloc
(Endl
, Loc
);
8264 end Process_End_Label
;
8270 -- We do the conversion to get the value of the real string by using
8271 -- the scanner, see Sinput for details on use of the internal source
8272 -- buffer for scanning internal strings.
8274 function Real_Convert
(S
: String) return Node_Id
is
8275 Save_Src
: constant Source_Buffer_Ptr
:= Source
;
8279 Source
:= Internal_Source_Ptr
;
8282 for J
in S
'Range loop
8283 Source
(Source_Ptr
(J
)) := S
(J
);
8286 Source
(S
'Length + 1) := EOF
;
8288 if Source
(Scan_Ptr
) = '-' then
8290 Scan_Ptr
:= Scan_Ptr
+ 1;
8298 Set_Realval
(Token_Node
, UR_Negate
(Realval
(Token_Node
)));
8305 ---------------------
8306 -- Rep_To_Pos_Flag --
8307 ---------------------
8309 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
8311 return New_Occurrence_Of
8312 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
8313 end Rep_To_Pos_Flag
;
8315 --------------------
8316 -- Require_Entity --
8317 --------------------
8319 procedure Require_Entity
(N
: Node_Id
) is
8321 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
8322 if Total_Errors_Detected
/= 0 then
8323 Set_Entity
(N
, Any_Id
);
8325 raise Program_Error
;
8330 ------------------------------
8331 -- Requires_Transient_Scope --
8332 ------------------------------
8334 -- A transient scope is required when variable-sized temporaries are
8335 -- allocated in the primary or secondary stack, or when finalization
8336 -- actions must be generated before the next instruction.
8338 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
8339 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
8341 -- Start of processing for Requires_Transient_Scope
8344 -- This is a private type which is not completed yet. This can only
8345 -- happen in a default expression (of a formal parameter or of a
8346 -- record component). Do not expand transient scope in this case
8351 -- Do not expand transient scope for non-existent procedure return
8353 elsif Typ
= Standard_Void_Type
then
8356 -- Elementary types do not require a transient scope
8358 elsif Is_Elementary_Type
(Typ
) then
8361 -- Generally, indefinite subtypes require a transient scope, since the
8362 -- back end cannot generate temporaries, since this is not a valid type
8363 -- for declaring an object. It might be possible to relax this in the
8364 -- future, e.g. by declaring the maximum possible space for the type.
8366 elsif Is_Indefinite_Subtype
(Typ
) then
8369 -- Functions returning tagged types may dispatch on result so their
8370 -- returned value is allocated on the secondary stack. Controlled
8371 -- type temporaries need finalization.
8373 elsif Is_Tagged_Type
(Typ
)
8374 or else Has_Controlled_Component
(Typ
)
8376 return not Is_Value_Type
(Typ
);
8380 elsif Is_Record_Type
(Typ
) then
8384 Comp
:= First_Entity
(Typ
);
8385 while Present
(Comp
) loop
8386 if Ekind
(Comp
) = E_Component
8387 and then Requires_Transient_Scope
(Etype
(Comp
))
8398 -- String literal types never require transient scope
8400 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
8403 -- Array type. Note that we already know that this is a constrained
8404 -- array, since unconstrained arrays will fail the indefinite test.
8406 elsif Is_Array_Type
(Typ
) then
8408 -- If component type requires a transient scope, the array does too
8410 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
8413 -- Otherwise, we only need a transient scope if the size is not
8414 -- known at compile time.
8417 return not Size_Known_At_Compile_Time
(Typ
);
8420 -- All other cases do not require a transient scope
8425 end Requires_Transient_Scope
;
8427 --------------------------
8428 -- Reset_Analyzed_Flags --
8429 --------------------------
8431 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
8433 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
8434 -- Function used to reset Analyzed flags in tree. Note that we do
8435 -- not reset Analyzed flags in entities, since there is no need to
8436 -- renalalyze entities, and indeed, it is wrong to do so, since it
8437 -- can result in generating auxiliary stuff more than once.
8439 --------------------
8440 -- Clear_Analyzed --
8441 --------------------
8443 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
8445 if not Has_Extension
(N
) then
8446 Set_Analyzed
(N
, False);
8452 function Reset_Analyzed
is
8453 new Traverse_Func
(Clear_Analyzed
);
8455 Discard
: Traverse_Result
;
8456 pragma Warnings
(Off
, Discard
);
8458 -- Start of processing for Reset_Analyzed_Flags
8461 Discard
:= Reset_Analyzed
(N
);
8462 end Reset_Analyzed_Flags
;
8464 ---------------------------
8465 -- Safe_To_Capture_Value --
8466 ---------------------------
8468 function Safe_To_Capture_Value
8471 Cond
: Boolean := False) return Boolean
8474 -- The only entities for which we track constant values are variables
8475 -- which are not renamings, constants, out parameters, and in out
8476 -- parameters, so check if we have this case.
8478 -- Note: it may seem odd to track constant values for constants, but in
8479 -- fact this routine is used for other purposes than simply capturing
8480 -- the value. In particular, the setting of Known[_Non]_Null.
8482 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
8484 Ekind
(Ent
) = E_Constant
8486 Ekind
(Ent
) = E_Out_Parameter
8488 Ekind
(Ent
) = E_In_Out_Parameter
8492 -- For conditionals, we also allow loop parameters and all formals,
8493 -- including in parameters.
8497 (Ekind
(Ent
) = E_Loop_Parameter
8499 Ekind
(Ent
) = E_In_Parameter
)
8503 -- For all other cases, not just unsafe, but impossible to capture
8504 -- Current_Value, since the above are the only entities which have
8505 -- Current_Value fields.
8511 -- Skip if volatile or aliased, since funny things might be going on in
8512 -- these cases which we cannot necessarily track. Also skip any variable
8513 -- for which an address clause is given, or whose address is taken.
8515 if Treat_As_Volatile
(Ent
)
8516 or else Is_Aliased
(Ent
)
8517 or else Present
(Address_Clause
(Ent
))
8518 or else Address_Taken
(Ent
)
8523 -- OK, all above conditions are met. We also require that the scope of
8524 -- the reference be the same as the scope of the entity, not counting
8525 -- packages and blocks and loops.
8528 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
8529 R_Scope
: Entity_Id
;
8532 R_Scope
:= Current_Scope
;
8533 while R_Scope
/= Standard_Standard
loop
8534 exit when R_Scope
= E_Scope
;
8536 if Ekind
(R_Scope
) /= E_Package
8538 Ekind
(R_Scope
) /= E_Block
8540 Ekind
(R_Scope
) /= E_Loop
8544 R_Scope
:= Scope
(R_Scope
);
8549 -- We also require that the reference does not appear in a context
8550 -- where it is not sure to be executed (i.e. a conditional context
8551 -- or an exception handler). We skip this if Cond is True, since the
8552 -- capturing of values from conditional tests handles this ok.
8566 while Present
(P
) loop
8567 if Nkind
(P
) = N_If_Statement
8568 or else Nkind
(P
) = N_Case_Statement
8569 or else (Nkind
(P
) = N_And_Then
and then Desc
= Right_Opnd
(P
))
8570 or else (Nkind
(P
) = N_Or_Else
and then Desc
= Right_Opnd
(P
))
8571 or else Nkind
(P
) = N_Exception_Handler
8572 or else Nkind
(P
) = N_Selective_Accept
8573 or else Nkind
(P
) = N_Conditional_Entry_Call
8574 or else Nkind
(P
) = N_Timed_Entry_Call
8575 or else Nkind
(P
) = N_Asynchronous_Select
8585 -- OK, looks safe to set value
8588 end Safe_To_Capture_Value
;
8594 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
8595 K1
: constant Node_Kind
:= Nkind
(N1
);
8596 K2
: constant Node_Kind
:= Nkind
(N2
);
8599 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
8600 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
8602 return Chars
(N1
) = Chars
(N2
);
8604 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
8605 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
8607 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
8608 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
8619 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
8620 N1
: constant Node_Id
:= Original_Node
(Node1
);
8621 N2
: constant Node_Id
:= Original_Node
(Node2
);
8622 -- We do the tests on original nodes, since we are most interested
8623 -- in the original source, not any expansion that got in the way.
8625 K1
: constant Node_Kind
:= Nkind
(N1
);
8626 K2
: constant Node_Kind
:= Nkind
(N2
);
8629 -- First case, both are entities with same entity
8631 if K1
in N_Has_Entity
8632 and then K2
in N_Has_Entity
8633 and then Present
(Entity
(N1
))
8634 and then Present
(Entity
(N2
))
8635 and then (Ekind
(Entity
(N1
)) = E_Variable
8637 Ekind
(Entity
(N1
)) = E_Constant
)
8638 and then Entity
(N1
) = Entity
(N2
)
8642 -- Second case, selected component with same selector, same record
8644 elsif K1
= N_Selected_Component
8645 and then K2
= N_Selected_Component
8646 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
8648 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
8650 -- Third case, indexed component with same subscripts, same array
8652 elsif K1
= N_Indexed_Component
8653 and then K2
= N_Indexed_Component
8654 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
8659 E1
:= First
(Expressions
(N1
));
8660 E2
:= First
(Expressions
(N2
));
8661 while Present
(E1
) loop
8662 if not Same_Value
(E1
, E2
) then
8673 -- Fourth case, slice of same array with same bounds
8676 and then K2
= N_Slice
8677 and then Nkind
(Discrete_Range
(N1
)) = N_Range
8678 and then Nkind
(Discrete_Range
(N2
)) = N_Range
8679 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
8680 Low_Bound
(Discrete_Range
(N2
)))
8681 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
8682 High_Bound
(Discrete_Range
(N2
)))
8684 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
8686 -- All other cases, not clearly the same object
8697 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
8702 elsif not Is_Constrained
(T1
)
8703 and then not Is_Constrained
(T2
)
8704 and then Base_Type
(T1
) = Base_Type
(T2
)
8708 -- For now don't bother with case of identical constraints, to be
8709 -- fiddled with later on perhaps (this is only used for optimization
8710 -- purposes, so it is not critical to do a best possible job)
8721 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
8723 if Compile_Time_Known_Value
(Node1
)
8724 and then Compile_Time_Known_Value
(Node2
)
8725 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
8728 elsif Same_Object
(Node1
, Node2
) then
8735 ------------------------
8736 -- Scope_Is_Transient --
8737 ------------------------
8739 function Scope_Is_Transient
return Boolean is
8741 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
8742 end Scope_Is_Transient
;
8748 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
8753 while Scop
/= Standard_Standard
loop
8754 Scop
:= Scope
(Scop
);
8756 if Scop
= Scope2
then
8764 --------------------------
8765 -- Scope_Within_Or_Same --
8766 --------------------------
8768 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
8773 while Scop
/= Standard_Standard
loop
8774 if Scop
= Scope2
then
8777 Scop
:= Scope
(Scop
);
8782 end Scope_Within_Or_Same
;
8784 ------------------------
8785 -- Set_Current_Entity --
8786 ------------------------
8788 -- The given entity is to be set as the currently visible definition
8789 -- of its associated name (i.e. the Node_Id associated with its name).
8790 -- All we have to do is to get the name from the identifier, and
8791 -- then set the associated Node_Id to point to the given entity.
8793 procedure Set_Current_Entity
(E
: Entity_Id
) is
8795 Set_Name_Entity_Id
(Chars
(E
), E
);
8796 end Set_Current_Entity
;
8798 ---------------------------------
8799 -- Set_Entity_With_Style_Check --
8800 ---------------------------------
8802 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
8803 Val_Actual
: Entity_Id
;
8807 Set_Entity
(N
, Val
);
8810 and then not Suppress_Style_Checks
(Val
)
8811 and then not In_Instance
8813 if Nkind
(N
) = N_Identifier
then
8815 elsif Nkind
(N
) = N_Expanded_Name
then
8816 Nod
:= Selector_Name
(N
);
8821 -- A special situation arises for derived operations, where we want
8822 -- to do the check against the parent (since the Sloc of the derived
8823 -- operation points to the derived type declaration itself).
8826 while not Comes_From_Source
(Val_Actual
)
8827 and then Nkind
(Val_Actual
) in N_Entity
8828 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
8829 or else Is_Subprogram
(Val_Actual
)
8830 or else Is_Generic_Subprogram
(Val_Actual
))
8831 and then Present
(Alias
(Val_Actual
))
8833 Val_Actual
:= Alias
(Val_Actual
);
8836 -- Renaming declarations for generic actuals do not come from source,
8837 -- and have a different name from that of the entity they rename, so
8838 -- there is no style check to perform here.
8840 if Chars
(Nod
) = Chars
(Val_Actual
) then
8841 Style
.Check_Identifier
(Nod
, Val_Actual
);
8845 Set_Entity
(N
, Val
);
8846 end Set_Entity_With_Style_Check
;
8848 ------------------------
8849 -- Set_Name_Entity_Id --
8850 ------------------------
8852 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
8854 Set_Name_Table_Info
(Id
, Int
(Val
));
8855 end Set_Name_Entity_Id
;
8857 ---------------------
8858 -- Set_Next_Actual --
8859 ---------------------
8861 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
8863 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
8864 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
8866 end Set_Next_Actual
;
8868 -----------------------
8869 -- Set_Public_Status --
8870 -----------------------
8872 procedure Set_Public_Status
(Id
: Entity_Id
) is
8873 S
: constant Entity_Id
:= Current_Scope
;
8876 -- Everything in the scope of Standard is public
8878 if S
= Standard_Standard
then
8881 -- Entity is definitely not public if enclosing scope is not public
8883 elsif not Is_Public
(S
) then
8886 -- An object declaration that occurs in a handled sequence of statements
8887 -- is the declaration for a temporary object generated by the expander.
8888 -- It never needs to be made public and furthermore, making it public
8889 -- can cause back end problems if it is of variable size.
8891 elsif Nkind
(Parent
(Id
)) = N_Object_Declaration
8893 Nkind
(Parent
(Parent
(Id
))) = N_Handled_Sequence_Of_Statements
8897 -- Entities in public packages or records are public
8899 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
8902 -- The bounds of an entry family declaration can generate object
8903 -- declarations that are visible to the back-end, e.g. in the
8904 -- the declaration of a composite type that contains tasks.
8906 elsif Is_Concurrent_Type
(S
)
8907 and then not Has_Completion
(S
)
8908 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
8912 end Set_Public_Status
;
8914 ----------------------------
8915 -- Set_Scope_Is_Transient --
8916 ----------------------------
8918 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
8920 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
8921 end Set_Scope_Is_Transient
;
8927 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
8929 -- We copy Esize, but not RM_Size, since in general RM_Size is
8930 -- subtype specific and does not get inherited by all subtypes.
8932 Set_Esize
(T1
, Esize
(T2
));
8933 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
8935 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
8937 Is_Discrete_Or_Fixed_Point_Type
(T2
)
8939 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
8942 Set_Alignment
(T1
, Alignment
(T2
));
8945 --------------------
8946 -- Static_Integer --
8947 --------------------
8949 function Static_Integer
(N
: Node_Id
) return Uint
is
8951 Analyze_And_Resolve
(N
, Any_Integer
);
8954 or else Error_Posted
(N
)
8955 or else Etype
(N
) = Any_Type
8960 if Is_Static_Expression
(N
) then
8961 if not Raises_Constraint_Error
(N
) then
8962 return Expr_Value
(N
);
8967 elsif Etype
(N
) = Any_Type
then
8971 Flag_Non_Static_Expr
8972 ("static integer expression required here", N
);
8977 --------------------------
8978 -- Statically_Different --
8979 --------------------------
8981 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
8982 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
8983 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
8985 return Is_Entity_Name
(R1
)
8986 and then Is_Entity_Name
(R2
)
8987 and then Entity
(R1
) /= Entity
(R2
)
8988 and then not Is_Formal
(Entity
(R1
))
8989 and then not Is_Formal
(Entity
(R2
));
8990 end Statically_Different
;
8992 -----------------------------
8993 -- Subprogram_Access_Level --
8994 -----------------------------
8996 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
8998 if Present
(Alias
(Subp
)) then
8999 return Subprogram_Access_Level
(Alias
(Subp
));
9001 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
9003 end Subprogram_Access_Level
;
9009 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
9011 if Debug_Flag_W
then
9012 for J
in 0 .. Scope_Stack
.Last
loop
9017 Write_Name
(Chars
(E
));
9018 Write_Str
(" line ");
9019 Write_Int
(Int
(Get_Logical_Line_Number
(Sloc
(N
))));
9024 -----------------------
9025 -- Transfer_Entities --
9026 -----------------------
9028 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
9029 Ent
: Entity_Id
:= First_Entity
(From
);
9036 if (Last_Entity
(To
)) = Empty
then
9037 Set_First_Entity
(To
, Ent
);
9039 Set_Next_Entity
(Last_Entity
(To
), Ent
);
9042 Set_Last_Entity
(To
, Last_Entity
(From
));
9044 while Present
(Ent
) loop
9045 Set_Scope
(Ent
, To
);
9047 if not Is_Public
(Ent
) then
9048 Set_Public_Status
(Ent
);
9051 and then Ekind
(Ent
) = E_Record_Subtype
9054 -- The components of the propagated Itype must be public
9060 Comp
:= First_Entity
(Ent
);
9061 while Present
(Comp
) loop
9062 Set_Is_Public
(Comp
);
9072 Set_First_Entity
(From
, Empty
);
9073 Set_Last_Entity
(From
, Empty
);
9074 end Transfer_Entities
;
9076 -----------------------
9077 -- Type_Access_Level --
9078 -----------------------
9080 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
9084 Btyp
:= Base_Type
(Typ
);
9086 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9087 -- simply use the level where the type is declared. This is true for
9088 -- stand-alone object declarations, and for anonymous access types
9089 -- associated with components the level is the same as that of the
9090 -- enclosing composite type. However, special treatment is needed for
9091 -- the cases of access parameters, return objects of an anonymous access
9092 -- type, and, in Ada 95, access discriminants of limited types.
9094 if Ekind
(Btyp
) in Access_Kind
then
9095 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
9097 -- If the type is a nonlocal anonymous access type (such as for
9098 -- an access parameter) we treat it as being declared at the
9099 -- library level to ensure that names such as X.all'access don't
9100 -- fail static accessibility checks.
9102 if not Is_Local_Anonymous_Access
(Typ
) then
9103 return Scope_Depth
(Standard_Standard
);
9105 -- If this is a return object, the accessibility level is that of
9106 -- the result subtype of the enclosing function. The test here is
9107 -- little complicated, because we have to account for extended
9108 -- return statements that have been rewritten as blocks, in which
9109 -- case we have to find and the Is_Return_Object attribute of the
9110 -- itype's associated object. It would be nice to find a way to
9111 -- simplify this test, but it doesn't seem worthwhile to add a new
9112 -- flag just for purposes of this test. ???
9114 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
9117 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
9118 N_Object_Declaration
9119 and then Is_Return_Object
9120 (Defining_Identifier
9121 (Associated_Node_For_Itype
(Btyp
))))
9127 Scop
:= Scope
(Scope
(Btyp
));
9128 while Present
(Scop
) loop
9129 exit when Ekind
(Scop
) = E_Function
;
9130 Scop
:= Scope
(Scop
);
9133 -- Treat the return object's type as having the level of the
9134 -- function's result subtype (as per RM05-6.5(5.3/2)).
9136 return Type_Access_Level
(Etype
(Scop
));
9141 Btyp
:= Root_Type
(Btyp
);
9143 -- The accessibility level of anonymous acccess types associated with
9144 -- discriminants is that of the current instance of the type, and
9145 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9147 -- AI-402: access discriminants have accessibility based on the
9148 -- object rather than the type in Ada 2005, so the above paragraph
9151 -- ??? Needs completion with rules from AI-416
9153 if Ada_Version
<= Ada_95
9154 and then Ekind
(Typ
) = E_Anonymous_Access_Type
9155 and then Present
(Associated_Node_For_Itype
(Typ
))
9156 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
9157 N_Discriminant_Specification
9159 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
9163 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
9164 end Type_Access_Level
;
9166 --------------------------
9167 -- Unit_Declaration_Node --
9168 --------------------------
9170 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
9171 N
: Node_Id
:= Parent
(Unit_Id
);
9174 -- Predefined operators do not have a full function declaration
9176 if Ekind
(Unit_Id
) = E_Operator
then
9180 -- Isn't there some better way to express the following ???
9182 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
9183 and then Nkind
(N
) /= N_Formal_Package_Declaration
9184 and then Nkind
(N
) /= N_Function_Instantiation
9185 and then Nkind
(N
) /= N_Generic_Package_Declaration
9186 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
9187 and then Nkind
(N
) /= N_Package_Declaration
9188 and then Nkind
(N
) /= N_Package_Body
9189 and then Nkind
(N
) /= N_Package_Instantiation
9190 and then Nkind
(N
) /= N_Package_Renaming_Declaration
9191 and then Nkind
(N
) /= N_Procedure_Instantiation
9192 and then Nkind
(N
) /= N_Protected_Body
9193 and then Nkind
(N
) /= N_Subprogram_Declaration
9194 and then Nkind
(N
) /= N_Subprogram_Body
9195 and then Nkind
(N
) /= N_Subprogram_Body_Stub
9196 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
9197 and then Nkind
(N
) /= N_Task_Body
9198 and then Nkind
(N
) /= N_Task_Type_Declaration
9199 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
9200 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
9203 pragma Assert
(Present
(N
));
9207 end Unit_Declaration_Node
;
9209 ------------------------------
9210 -- Universal_Interpretation --
9211 ------------------------------
9213 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
9214 Index
: Interp_Index
;
9218 -- The argument may be a formal parameter of an operator or subprogram
9219 -- with multiple interpretations, or else an expression for an actual.
9221 if Nkind
(Opnd
) = N_Defining_Identifier
9222 or else not Is_Overloaded
(Opnd
)
9224 if Etype
(Opnd
) = Universal_Integer
9225 or else Etype
(Opnd
) = Universal_Real
9227 return Etype
(Opnd
);
9233 Get_First_Interp
(Opnd
, Index
, It
);
9234 while Present
(It
.Typ
) loop
9235 if It
.Typ
= Universal_Integer
9236 or else It
.Typ
= Universal_Real
9241 Get_Next_Interp
(Index
, It
);
9246 end Universal_Interpretation
;
9252 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
9254 -- Recurse to handle unlikely case of multiple levels of qualification
9256 if Nkind
(Expr
) = N_Qualified_Expression
then
9257 return Unqualify
(Expression
(Expr
));
9259 -- Normal case, not a qualified expression
9266 ----------------------
9267 -- Within_Init_Proc --
9268 ----------------------
9270 function Within_Init_Proc
return Boolean is
9275 while not Is_Overloadable
(S
) loop
9276 if S
= Standard_Standard
then
9283 return Is_Init_Proc
(S
);
9284 end Within_Init_Proc
;
9290 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
9291 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
9292 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
9294 function Has_One_Matching_Field
return Boolean;
9295 -- Determines if Expec_Type is a record type with a single component or
9296 -- discriminant whose type matches the found type or is one dimensional
9297 -- array whose component type matches the found type.
9299 ----------------------------
9300 -- Has_One_Matching_Field --
9301 ----------------------------
9303 function Has_One_Matching_Field
return Boolean is
9307 if Is_Array_Type
(Expec_Type
)
9308 and then Number_Dimensions
(Expec_Type
) = 1
9310 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
9314 elsif not Is_Record_Type
(Expec_Type
) then
9318 E
:= First_Entity
(Expec_Type
);
9323 elsif (Ekind
(E
) /= E_Discriminant
9324 and then Ekind
(E
) /= E_Component
)
9325 or else (Chars
(E
) = Name_uTag
9326 or else Chars
(E
) = Name_uParent
)
9335 if not Covers
(Etype
(E
), Found_Type
) then
9338 elsif Present
(Next_Entity
(E
)) then
9345 end Has_One_Matching_Field
;
9347 -- Start of processing for Wrong_Type
9350 -- Don't output message if either type is Any_Type, or if a message
9351 -- has already been posted for this node. We need to do the latter
9352 -- check explicitly (it is ordinarily done in Errout), because we
9353 -- are using ! to force the output of the error messages.
9355 if Expec_Type
= Any_Type
9356 or else Found_Type
= Any_Type
9357 or else Error_Posted
(Expr
)
9361 -- In an instance, there is an ongoing problem with completion of
9362 -- type derived from private types. Their structure is what Gigi
9363 -- expects, but the Etype is the parent type rather than the
9364 -- derived private type itself. Do not flag error in this case. The
9365 -- private completion is an entity without a parent, like an Itype.
9366 -- Similarly, full and partial views may be incorrect in the instance.
9367 -- There is no simple way to insure that it is consistent ???
9369 elsif In_Instance
then
9370 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
9372 (Has_Private_Declaration
(Expected_Type
)
9373 or else Has_Private_Declaration
(Etype
(Expr
)))
9374 and then No
(Parent
(Expected_Type
))
9380 -- An interesting special check. If the expression is parenthesized
9381 -- and its type corresponds to the type of the sole component of the
9382 -- expected record type, or to the component type of the expected one
9383 -- dimensional array type, then assume we have a bad aggregate attempt.
9385 if Nkind
(Expr
) in N_Subexpr
9386 and then Paren_Count
(Expr
) /= 0
9387 and then Has_One_Matching_Field
9389 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
9391 -- Another special check, if we are looking for a pool-specific access
9392 -- type and we found an E_Access_Attribute_Type, then we have the case
9393 -- of an Access attribute being used in a context which needs a pool-
9394 -- specific type, which is never allowed. The one extra check we make
9395 -- is that the expected designated type covers the Found_Type.
9397 elsif Is_Access_Type
(Expec_Type
)
9398 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
9399 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
9400 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
9402 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
9404 Error_Msg_N
("result must be general access type!", Expr
);
9405 Error_Msg_NE
("add ALL to }!", Expr
, Expec_Type
);
9407 -- Another special check, if the expected type is an integer type,
9408 -- but the expression is of type System.Address, and the parent is
9409 -- an addition or subtraction operation whose left operand is the
9410 -- expression in question and whose right operand is of an integral
9411 -- type, then this is an attempt at address arithmetic, so give
9412 -- appropriate message.
9414 elsif Is_Integer_Type
(Expec_Type
)
9415 and then Is_RTE
(Found_Type
, RE_Address
)
9416 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
9418 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
9419 and then Expr
= Left_Opnd
(Parent
(Expr
))
9420 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
9423 ("address arithmetic not predefined in package System",
9426 ("\possible missing with/use of System.Storage_Elements",
9430 -- If the expected type is an anonymous access type, as for access
9431 -- parameters and discriminants, the error is on the designated types.
9433 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
9434 if Comes_From_Source
(Expec_Type
) then
9435 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
9438 ("expected an access type with designated}",
9439 Expr
, Designated_Type
(Expec_Type
));
9442 if Is_Access_Type
(Found_Type
)
9443 and then not Comes_From_Source
(Found_Type
)
9446 ("\\found an access type with designated}!",
9447 Expr
, Designated_Type
(Found_Type
));
9449 if From_With_Type
(Found_Type
) then
9450 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
9451 Error_Msg_Qual_Level
:= 99;
9452 Error_Msg_NE
("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
9453 Error_Msg_Qual_Level
:= 0;
9455 Error_Msg_NE
("found}!", Expr
, Found_Type
);
9459 -- Normal case of one type found, some other type expected
9462 -- If the names of the two types are the same, see if some number
9463 -- of levels of qualification will help. Don't try more than three
9464 -- levels, and if we get to standard, it's no use (and probably
9465 -- represents an error in the compiler) Also do not bother with
9466 -- internal scope names.
9469 Expec_Scope
: Entity_Id
;
9470 Found_Scope
: Entity_Id
;
9473 Expec_Scope
:= Expec_Type
;
9474 Found_Scope
:= Found_Type
;
9476 for Levels
in Int
range 0 .. 3 loop
9477 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
9478 Error_Msg_Qual_Level
:= Levels
;
9482 Expec_Scope
:= Scope
(Expec_Scope
);
9483 Found_Scope
:= Scope
(Found_Scope
);
9485 exit when Expec_Scope
= Standard_Standard
9486 or else Found_Scope
= Standard_Standard
9487 or else not Comes_From_Source
(Expec_Scope
)
9488 or else not Comes_From_Source
(Found_Scope
);
9492 if Is_Record_Type
(Expec_Type
)
9493 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
9495 Error_Msg_NE
("expected}!", Expr
,
9496 Corresponding_Remote_Type
(Expec_Type
));
9498 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
9501 if Is_Entity_Name
(Expr
)
9502 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
9504 Error_Msg_N
("\\found package name!", Expr
);
9506 elsif Is_Entity_Name
(Expr
)
9508 (Ekind
(Entity
(Expr
)) = E_Procedure
9510 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
9512 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
9514 ("found procedure name, possibly missing Access attribute!",
9518 ("\\found procedure name instead of function!", Expr
);
9521 elsif Nkind
(Expr
) = N_Function_Call
9522 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
9523 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
9524 and then No
(Parameter_Associations
(Expr
))
9527 ("found function name, possibly missing Access attribute!",
9530 -- Catch common error: a prefix or infix operator which is not
9531 -- directly visible because the type isn't.
9533 elsif Nkind
(Expr
) in N_Op
9534 and then Is_Overloaded
(Expr
)
9535 and then not Is_Immediately_Visible
(Expec_Type
)
9536 and then not Is_Potentially_Use_Visible
(Expec_Type
)
9537 and then not In_Use
(Expec_Type
)
9538 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
9541 ("operator of the type is not directly visible!", Expr
);
9543 elsif Ekind
(Found_Type
) = E_Void
9544 and then Present
(Parent
(Found_Type
))
9545 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
9547 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
9550 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
9553 Error_Msg_Qual_Level
:= 0;