1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Casing
; use Casing
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Errout
; use Errout
;
31 with Elists
; use Elists
;
32 with Exp_Disp
; use Exp_Disp
;
33 with Exp_Tss
; use Exp_Tss
;
34 with Exp_Util
; use Exp_Util
;
35 with Fname
; use Fname
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Nlists
; use Nlists
;
40 with Output
; use Output
;
42 with Rtsfind
; use Rtsfind
;
43 with Scans
; use Scans
;
46 with Sem_Attr
; use Sem_Attr
;
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 Stand
; use Stand
;
55 with Stringt
; use Stringt
;
56 with Targparm
; use Targparm
;
57 with Tbuild
; use Tbuild
;
58 with Ttypes
; use Ttypes
;
59 with Uname
; use Uname
;
61 package body Sem_Util
is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function Build_Component_Subtype
70 T
: Entity_Id
) return Node_Id
;
71 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
72 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
73 -- Loc is the source location, T is the original subtype.
75 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
76 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
77 -- with discriminants whose default values are static, examine only the
78 -- components in the selected variant to determine whether all of them
81 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
82 -- T is a derived tagged type. Check whether the type extension is null.
83 -- If the parent type is fully initialized, T can be treated as such.
85 ------------------------------
86 -- Abstract_Interface_List --
87 ------------------------------
89 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
93 if Is_Concurrent_Type
(Typ
) then
95 -- If we are dealing with a synchronized subtype, go to the base
96 -- type, whose declaration has the interface list.
98 -- Shouldn't this be Declaration_Node???
100 Nod
:= Parent
(Base_Type
(Typ
));
102 if Nkind
(Nod
) = N_Full_Type_Declaration
then
106 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
107 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
108 Nod
:= Type_Definition
(Parent
(Typ
));
110 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
111 if Present
(Full_View
(Typ
)) then
112 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
114 -- If the full-view is not available we cannot do anything else
115 -- here (the source has errors).
121 -- Support for generic formals with interfaces is still missing ???
123 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
128 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
132 elsif Ekind
(Typ
) = E_Record_Subtype
then
133 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
135 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
137 -- Recurse, because parent may still be a private extension. Also
138 -- note that the full view of the subtype or the full view of its
139 -- base type may (both) be unavailable.
141 return Abstract_Interface_List
(Etype
(Typ
));
143 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
144 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
145 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
147 Nod
:= Type_Definition
(Parent
(Typ
));
151 return Interface_List
(Nod
);
152 end Abstract_Interface_List
;
154 --------------------------------
155 -- Add_Access_Type_To_Process --
156 --------------------------------
158 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
162 Ensure_Freeze_Node
(E
);
163 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
167 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
171 end Add_Access_Type_To_Process
;
173 ----------------------------
174 -- Add_Global_Declaration --
175 ----------------------------
177 procedure Add_Global_Declaration
(N
: Node_Id
) is
178 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
181 if No
(Declarations
(Aux_Node
)) then
182 Set_Declarations
(Aux_Node
, New_List
);
185 Append_To
(Declarations
(Aux_Node
), N
);
187 end Add_Global_Declaration
;
189 -----------------------
190 -- Alignment_In_Bits --
191 -----------------------
193 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
195 return Alignment
(E
) * System_Storage_Unit
;
196 end Alignment_In_Bits
;
198 -----------------------------------------
199 -- Apply_Compile_Time_Constraint_Error --
200 -----------------------------------------
202 procedure Apply_Compile_Time_Constraint_Error
205 Reason
: RT_Exception_Code
;
206 Ent
: Entity_Id
:= Empty
;
207 Typ
: Entity_Id
:= Empty
;
208 Loc
: Source_Ptr
:= No_Location
;
209 Rep
: Boolean := True;
210 Warn
: Boolean := False)
212 Stat
: constant Boolean := Is_Static_Expression
(N
);
213 R_Stat
: constant Node_Id
:=
214 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
225 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
231 -- Now we replace the node by an N_Raise_Constraint_Error node
232 -- This does not need reanalyzing, so set it as analyzed now.
235 Set_Analyzed
(N
, True);
238 Set_Raises_Constraint_Error
(N
);
240 -- If the original expression was marked as static, the result is
241 -- still marked as static, but the Raises_Constraint_Error flag is
242 -- always set so that further static evaluation is not attempted.
245 Set_Is_Static_Expression
(N
);
247 end Apply_Compile_Time_Constraint_Error
;
249 --------------------------
250 -- Build_Actual_Subtype --
251 --------------------------
253 function Build_Actual_Subtype
255 N
: Node_Or_Entity_Id
) return Node_Id
258 -- Normally Sloc (N), but may point to corresponding body in some cases
260 Constraints
: List_Id
;
266 Disc_Type
: Entity_Id
;
272 if Nkind
(N
) = N_Defining_Identifier
then
273 Obj
:= New_Reference_To
(N
, Loc
);
275 -- If this is a formal parameter of a subprogram declaration, and
276 -- we are compiling the body, we want the declaration for the
277 -- actual subtype to carry the source position of the body, to
278 -- prevent anomalies in gdb when stepping through the code.
280 if Is_Formal
(N
) then
282 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
284 if Nkind
(Decl
) = N_Subprogram_Declaration
285 and then Present
(Corresponding_Body
(Decl
))
287 Loc
:= Sloc
(Corresponding_Body
(Decl
));
296 if Is_Array_Type
(T
) then
297 Constraints
:= New_List
;
298 for J
in 1 .. Number_Dimensions
(T
) loop
300 -- Build an array subtype declaration with the nominal subtype and
301 -- the bounds of the actual. Add the declaration in front of the
302 -- local declarations for the subprogram, for analysis before any
303 -- reference to the formal in the body.
306 Make_Attribute_Reference
(Loc
,
308 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
309 Attribute_Name
=> Name_First
,
310 Expressions
=> New_List
(
311 Make_Integer_Literal
(Loc
, J
)));
314 Make_Attribute_Reference
(Loc
,
316 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
317 Attribute_Name
=> Name_Last
,
318 Expressions
=> New_List
(
319 Make_Integer_Literal
(Loc
, J
)));
321 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
324 -- If the type has unknown discriminants there is no constrained
325 -- subtype to build. This is never called for a formal or for a
326 -- lhs, so returning the type is ok ???
328 elsif Has_Unknown_Discriminants
(T
) then
332 Constraints
:= New_List
;
334 -- Type T is a generic derived type, inherit the discriminants from
337 if Is_Private_Type
(T
)
338 and then No
(Full_View
(T
))
340 -- T was flagged as an error if it was declared as a formal
341 -- derived type with known discriminants. In this case there
342 -- is no need to look at the parent type since T already carries
343 -- its own discriminants.
345 and then not Error_Posted
(T
)
347 Disc_Type
:= Etype
(Base_Type
(T
));
352 Discr
:= First_Discriminant
(Disc_Type
);
353 while Present
(Discr
) loop
354 Append_To
(Constraints
,
355 Make_Selected_Component
(Loc
,
357 Duplicate_Subexpr_No_Checks
(Obj
),
358 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
359 Next_Discriminant
(Discr
);
364 Make_Defining_Identifier
(Loc
,
365 Chars
=> New_Internal_Name
('S'));
366 Set_Is_Internal
(Subt
);
369 Make_Subtype_Declaration
(Loc
,
370 Defining_Identifier
=> Subt
,
371 Subtype_Indication
=>
372 Make_Subtype_Indication
(Loc
,
373 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
375 Make_Index_Or_Discriminant_Constraint
(Loc
,
376 Constraints
=> Constraints
)));
378 Mark_Rewrite_Insertion
(Decl
);
380 end Build_Actual_Subtype
;
382 ---------------------------------------
383 -- Build_Actual_Subtype_Of_Component --
384 ---------------------------------------
386 function Build_Actual_Subtype_Of_Component
388 N
: Node_Id
) return Node_Id
390 Loc
: constant Source_Ptr
:= Sloc
(N
);
391 P
: constant Node_Id
:= Prefix
(N
);
394 Indx_Type
: Entity_Id
;
396 Deaccessed_T
: Entity_Id
;
397 -- This is either a copy of T, or if T is an access type, then it is
398 -- the directly designated type of this access type.
400 function Build_Actual_Array_Constraint
return List_Id
;
401 -- If one or more of the bounds of the component depends on
402 -- discriminants, build actual constraint using the discriminants
405 function Build_Actual_Record_Constraint
return List_Id
;
406 -- Similar to previous one, for discriminated components constrained
407 -- by the discriminant of the enclosing object.
409 -----------------------------------
410 -- Build_Actual_Array_Constraint --
411 -----------------------------------
413 function Build_Actual_Array_Constraint
return List_Id
is
414 Constraints
: constant List_Id
:= New_List
;
422 Indx
:= First_Index
(Deaccessed_T
);
423 while Present
(Indx
) loop
424 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
425 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
427 if Denotes_Discriminant
(Old_Lo
) then
429 Make_Selected_Component
(Loc
,
430 Prefix
=> New_Copy_Tree
(P
),
431 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
434 Lo
:= New_Copy_Tree
(Old_Lo
);
436 -- The new bound will be reanalyzed in the enclosing
437 -- declaration. For literal bounds that come from a type
438 -- declaration, the type of the context must be imposed, so
439 -- insure that analysis will take place. For non-universal
440 -- types this is not strictly necessary.
442 Set_Analyzed
(Lo
, False);
445 if Denotes_Discriminant
(Old_Hi
) then
447 Make_Selected_Component
(Loc
,
448 Prefix
=> New_Copy_Tree
(P
),
449 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
452 Hi
:= New_Copy_Tree
(Old_Hi
);
453 Set_Analyzed
(Hi
, False);
456 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
461 end Build_Actual_Array_Constraint
;
463 ------------------------------------
464 -- Build_Actual_Record_Constraint --
465 ------------------------------------
467 function Build_Actual_Record_Constraint
return List_Id
is
468 Constraints
: constant List_Id
:= New_List
;
473 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
474 while Present
(D
) loop
475 if Denotes_Discriminant
(Node
(D
)) then
476 D_Val
:= Make_Selected_Component
(Loc
,
477 Prefix
=> New_Copy_Tree
(P
),
478 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
481 D_Val
:= New_Copy_Tree
(Node
(D
));
484 Append
(D_Val
, Constraints
);
489 end Build_Actual_Record_Constraint
;
491 -- Start of processing for Build_Actual_Subtype_Of_Component
494 -- Why the test for Spec_Expression mode here???
496 if In_Spec_Expression
then
499 -- More comments for the rest of this body would be good ???
501 elsif Nkind
(N
) = N_Explicit_Dereference
then
502 if Is_Composite_Type
(T
)
503 and then not Is_Constrained
(T
)
504 and then not (Is_Class_Wide_Type
(T
)
505 and then Is_Constrained
(Root_Type
(T
)))
506 and then not Has_Unknown_Discriminants
(T
)
508 -- If the type of the dereference is already constrained, it
509 -- is an actual subtype.
511 if Is_Array_Type
(Etype
(N
))
512 and then Is_Constrained
(Etype
(N
))
516 Remove_Side_Effects
(P
);
517 return Build_Actual_Subtype
(T
, N
);
524 if Ekind
(T
) = E_Access_Subtype
then
525 Deaccessed_T
:= Designated_Type
(T
);
530 if Ekind
(Deaccessed_T
) = E_Array_Subtype
then
531 Id
:= First_Index
(Deaccessed_T
);
532 while Present
(Id
) loop
533 Indx_Type
:= Underlying_Type
(Etype
(Id
));
535 if Denotes_Discriminant
(Type_Low_Bound
(Indx_Type
))
537 Denotes_Discriminant
(Type_High_Bound
(Indx_Type
))
539 Remove_Side_Effects
(P
);
541 Build_Component_Subtype
542 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
548 elsif Is_Composite_Type
(Deaccessed_T
)
549 and then Has_Discriminants
(Deaccessed_T
)
550 and then not Has_Unknown_Discriminants
(Deaccessed_T
)
552 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
553 while Present
(D
) loop
554 if Denotes_Discriminant
(Node
(D
)) then
555 Remove_Side_Effects
(P
);
557 Build_Component_Subtype
(
558 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
565 -- If none of the above, the actual and nominal subtypes are the same
568 end Build_Actual_Subtype_Of_Component
;
570 -----------------------------
571 -- Build_Component_Subtype --
572 -----------------------------
574 function Build_Component_Subtype
577 T
: Entity_Id
) return Node_Id
583 -- Unchecked_Union components do not require component subtypes
585 if Is_Unchecked_Union
(T
) then
590 Make_Defining_Identifier
(Loc
,
591 Chars
=> New_Internal_Name
('S'));
592 Set_Is_Internal
(Subt
);
595 Make_Subtype_Declaration
(Loc
,
596 Defining_Identifier
=> Subt
,
597 Subtype_Indication
=>
598 Make_Subtype_Indication
(Loc
,
599 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
601 Make_Index_Or_Discriminant_Constraint
(Loc
,
604 Mark_Rewrite_Insertion
(Decl
);
606 end Build_Component_Subtype
;
608 ---------------------------
609 -- Build_Default_Subtype --
610 ---------------------------
612 function Build_Default_Subtype
614 N
: Node_Id
) return Entity_Id
616 Loc
: constant Source_Ptr
:= Sloc
(N
);
620 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
624 Disc
:= First_Discriminant
(T
);
626 if No
(Discriminant_Default_Value
(Disc
)) then
631 Act
: constant Entity_Id
:=
632 Make_Defining_Identifier
(Loc
,
633 Chars
=> New_Internal_Name
('S'));
635 Constraints
: constant List_Id
:= New_List
;
639 while Present
(Disc
) loop
640 Append_To
(Constraints
,
641 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
642 Next_Discriminant
(Disc
);
646 Make_Subtype_Declaration
(Loc
,
647 Defining_Identifier
=> Act
,
648 Subtype_Indication
=>
649 Make_Subtype_Indication
(Loc
,
650 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
652 Make_Index_Or_Discriminant_Constraint
(Loc
,
653 Constraints
=> Constraints
)));
655 Insert_Action
(N
, Decl
);
659 end Build_Default_Subtype
;
661 --------------------------------------------
662 -- Build_Discriminal_Subtype_Of_Component --
663 --------------------------------------------
665 function Build_Discriminal_Subtype_Of_Component
666 (T
: Entity_Id
) return Node_Id
668 Loc
: constant Source_Ptr
:= Sloc
(T
);
672 function Build_Discriminal_Array_Constraint
return List_Id
;
673 -- If one or more of the bounds of the component depends on
674 -- discriminants, build actual constraint using the discriminants
677 function Build_Discriminal_Record_Constraint
return List_Id
;
678 -- Similar to previous one, for discriminated components constrained
679 -- by the discriminant of the enclosing object.
681 ----------------------------------------
682 -- Build_Discriminal_Array_Constraint --
683 ----------------------------------------
685 function Build_Discriminal_Array_Constraint
return List_Id
is
686 Constraints
: constant List_Id
:= New_List
;
694 Indx
:= First_Index
(T
);
695 while Present
(Indx
) loop
696 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
697 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
699 if Denotes_Discriminant
(Old_Lo
) then
700 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
703 Lo
:= New_Copy_Tree
(Old_Lo
);
706 if Denotes_Discriminant
(Old_Hi
) then
707 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
710 Hi
:= New_Copy_Tree
(Old_Hi
);
713 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
718 end Build_Discriminal_Array_Constraint
;
720 -----------------------------------------
721 -- Build_Discriminal_Record_Constraint --
722 -----------------------------------------
724 function Build_Discriminal_Record_Constraint
return List_Id
is
725 Constraints
: constant List_Id
:= New_List
;
730 D
:= First_Elmt
(Discriminant_Constraint
(T
));
731 while Present
(D
) loop
732 if Denotes_Discriminant
(Node
(D
)) then
734 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
737 D_Val
:= New_Copy_Tree
(Node
(D
));
740 Append
(D_Val
, Constraints
);
745 end Build_Discriminal_Record_Constraint
;
747 -- Start of processing for Build_Discriminal_Subtype_Of_Component
750 if Ekind
(T
) = E_Array_Subtype
then
751 Id
:= First_Index
(T
);
752 while Present
(Id
) loop
753 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
754 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
756 return Build_Component_Subtype
757 (Build_Discriminal_Array_Constraint
, Loc
, T
);
763 elsif Ekind
(T
) = E_Record_Subtype
764 and then Has_Discriminants
(T
)
765 and then not Has_Unknown_Discriminants
(T
)
767 D
:= First_Elmt
(Discriminant_Constraint
(T
));
768 while Present
(D
) loop
769 if Denotes_Discriminant
(Node
(D
)) then
770 return Build_Component_Subtype
771 (Build_Discriminal_Record_Constraint
, Loc
, T
);
778 -- If none of the above, the actual and nominal subtypes are the same
781 end Build_Discriminal_Subtype_Of_Component
;
783 ------------------------------
784 -- Build_Elaboration_Entity --
785 ------------------------------
787 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
788 Loc
: constant Source_Ptr
:= Sloc
(N
);
790 Elab_Ent
: Entity_Id
;
792 procedure Set_Package_Name
(Ent
: Entity_Id
);
793 -- Given an entity, sets the fully qualified name of the entity in
794 -- Name_Buffer, with components separated by double underscores. This
795 -- is a recursive routine that climbs the scope chain to Standard.
797 ----------------------
798 -- Set_Package_Name --
799 ----------------------
801 procedure Set_Package_Name
(Ent
: Entity_Id
) is
803 if Scope
(Ent
) /= Standard_Standard
then
804 Set_Package_Name
(Scope
(Ent
));
807 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
809 Name_Buffer
(Name_Len
+ 1) := '_';
810 Name_Buffer
(Name_Len
+ 2) := '_';
811 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
812 Name_Len
:= Name_Len
+ Nam
'Length + 2;
816 Get_Name_String
(Chars
(Ent
));
818 end Set_Package_Name
;
820 -- Start of processing for Build_Elaboration_Entity
823 -- Ignore if already constructed
825 if Present
(Elaboration_Entity
(Spec_Id
)) then
829 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
830 -- name with dots replaced by double underscore. We have to manually
831 -- construct this name, since it will be elaborated in the outer scope,
832 -- and thus will not have the unit name automatically prepended.
834 Set_Package_Name
(Spec_Id
);
838 Name_Buffer
(Name_Len
+ 1) := '_';
839 Name_Buffer
(Name_Len
+ 2) := 'E';
840 Name_Len
:= Name_Len
+ 2;
842 -- Create elaboration flag
845 Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
846 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
849 Make_Object_Declaration
(Loc
,
850 Defining_Identifier
=> Elab_Ent
,
852 New_Occurrence_Of
(Standard_Boolean
, Loc
),
854 New_Occurrence_Of
(Standard_False
, Loc
));
856 Push_Scope
(Standard_Standard
);
857 Add_Global_Declaration
(Decl
);
860 -- Reset True_Constant indication, since we will indeed assign a value
861 -- to the variable in the binder main. We also kill the Current_Value
862 -- and Last_Assignment fields for the same reason.
864 Set_Is_True_Constant
(Elab_Ent
, False);
865 Set_Current_Value
(Elab_Ent
, Empty
);
866 Set_Last_Assignment
(Elab_Ent
, Empty
);
868 -- We do not want any further qualification of the name (if we did
869 -- not do this, we would pick up the name of the generic package
870 -- in the case of a library level generic instantiation).
872 Set_Has_Qualified_Name
(Elab_Ent
);
873 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
874 end Build_Elaboration_Entity
;
876 -----------------------------------
877 -- Cannot_Raise_Constraint_Error --
878 -----------------------------------
880 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
882 if Compile_Time_Known_Value
(Expr
) then
885 elsif Do_Range_Check
(Expr
) then
888 elsif Raises_Constraint_Error
(Expr
) then
896 when N_Expanded_Name
=>
899 when N_Selected_Component
=>
900 return not Do_Discriminant_Check
(Expr
);
902 when N_Attribute_Reference
=>
903 if Do_Overflow_Check
(Expr
) then
906 elsif No
(Expressions
(Expr
)) then
914 N
:= First
(Expressions
(Expr
));
915 while Present
(N
) loop
916 if Cannot_Raise_Constraint_Error
(N
) then
927 when N_Type_Conversion
=>
928 if Do_Overflow_Check
(Expr
)
929 or else Do_Length_Check
(Expr
)
930 or else Do_Tag_Check
(Expr
)
935 Cannot_Raise_Constraint_Error
(Expression
(Expr
));
938 when N_Unchecked_Type_Conversion
=>
939 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
942 if Do_Overflow_Check
(Expr
) then
946 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
953 if Do_Division_Check
(Expr
)
954 or else Do_Overflow_Check
(Expr
)
959 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
961 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
980 N_Op_Shift_Right_Arithmetic |
984 if Do_Overflow_Check
(Expr
) then
988 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
990 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
997 end Cannot_Raise_Constraint_Error
;
999 --------------------------
1000 -- Check_Fully_Declared --
1001 --------------------------
1003 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1005 if Ekind
(T
) = E_Incomplete_Type
then
1007 -- Ada 2005 (AI-50217): If the type is available through a limited
1008 -- with_clause, verify that its full view has been analyzed.
1010 if From_With_Type
(T
)
1011 and then Present
(Non_Limited_View
(T
))
1012 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1014 -- The non-limited view is fully declared
1019 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1022 -- Need comments for these tests ???
1024 elsif Has_Private_Component
(T
)
1025 and then not Is_Generic_Type
(Root_Type
(T
))
1026 and then not In_Spec_Expression
1028 -- Special case: if T is the anonymous type created for a single
1029 -- task or protected object, use the name of the source object.
1031 if Is_Concurrent_Type
(T
)
1032 and then not Comes_From_Source
(T
)
1033 and then Nkind
(N
) = N_Object_Declaration
1035 Error_Msg_NE
("type of& has incomplete component", N
,
1036 Defining_Identifier
(N
));
1040 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1043 end Check_Fully_Declared
;
1045 -------------------------
1046 -- Check_Nested_Access --
1047 -------------------------
1049 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
1050 Scop
: constant Entity_Id
:= Current_Scope
;
1051 Current_Subp
: Entity_Id
;
1052 Enclosing
: Entity_Id
;
1055 -- Currently only enabled for VM back-ends for efficiency, should we
1056 -- enable it more systematically ???
1058 -- Check for Is_Imported needs commenting below ???
1060 if VM_Target
/= No_VM
1061 and then (Ekind
(Ent
) = E_Variable
1063 Ekind
(Ent
) = E_Constant
1065 Ekind
(Ent
) = E_Loop_Parameter
)
1066 and then Scope
(Ent
) /= Empty
1067 and then not Is_Library_Level_Entity
(Ent
)
1068 and then not Is_Imported
(Ent
)
1070 if Is_Subprogram
(Scop
)
1071 or else Is_Generic_Subprogram
(Scop
)
1072 or else Is_Entry
(Scop
)
1074 Current_Subp
:= Scop
;
1076 Current_Subp
:= Current_Subprogram
;
1079 Enclosing
:= Enclosing_Subprogram
(Ent
);
1081 if Enclosing
/= Empty
1082 and then Enclosing
/= Current_Subp
1084 Set_Has_Up_Level_Access
(Ent
, True);
1087 end Check_Nested_Access
;
1089 ------------------------------------------
1090 -- Check_Potentially_Blocking_Operation --
1091 ------------------------------------------
1093 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
1096 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1097 -- When pragma Detect_Blocking is active, the run time will raise
1098 -- Program_Error. Here we only issue a warning, since we generally
1099 -- support the use of potentially blocking operations in the absence
1102 -- Indirect blocking through a subprogram call cannot be diagnosed
1103 -- statically without interprocedural analysis, so we do not attempt
1106 S
:= Scope
(Current_Scope
);
1107 while Present
(S
) and then S
/= Standard_Standard
loop
1108 if Is_Protected_Type
(S
) then
1110 ("potentially blocking operation in protected operation?", N
);
1117 end Check_Potentially_Blocking_Operation
;
1119 ------------------------------
1120 -- Check_Unprotected_Access --
1121 ------------------------------
1123 procedure Check_Unprotected_Access
1127 Cont_Encl_Typ
: Entity_Id
;
1128 Pref_Encl_Typ
: Entity_Id
;
1130 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
1131 -- Check whether Obj is a private component of a protected object.
1132 -- Return the protected type where the component resides, Empty
1135 function Is_Public_Operation
return Boolean;
1136 -- Verify that the enclosing operation is callable from outside the
1137 -- protected object, to minimize false positives.
1139 ------------------------------
1140 -- Enclosing_Protected_Type --
1141 ------------------------------
1143 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
1145 if Is_Entity_Name
(Obj
) then
1147 Ent
: Entity_Id
:= Entity
(Obj
);
1150 -- The object can be a renaming of a private component, use
1151 -- the original record component.
1153 if Is_Prival
(Ent
) then
1154 Ent
:= Prival_Link
(Ent
);
1157 if Is_Protected_Type
(Scope
(Ent
)) then
1163 -- For indexed and selected components, recursively check the prefix
1165 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
1166 return Enclosing_Protected_Type
(Prefix
(Obj
));
1168 -- The object does not denote a protected component
1173 end Enclosing_Protected_Type
;
1175 -------------------------
1176 -- Is_Public_Operation --
1177 -------------------------
1179 function Is_Public_Operation
return Boolean is
1186 and then S
/= Pref_Encl_Typ
1188 if Scope
(S
) = Pref_Encl_Typ
then
1189 E
:= First_Entity
(Pref_Encl_Typ
);
1191 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
1204 end Is_Public_Operation
;
1206 -- Start of processing for Check_Unprotected_Access
1209 if Nkind
(Expr
) = N_Attribute_Reference
1210 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
1212 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
1213 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
1215 -- Check whether we are trying to export a protected component to a
1216 -- context with an equal or lower access level.
1218 if Present
(Pref_Encl_Typ
)
1219 and then No
(Cont_Encl_Typ
)
1220 and then Is_Public_Operation
1221 and then Scope_Depth
(Pref_Encl_Typ
) >=
1222 Object_Access_Level
(Context
)
1225 ("?possible unprotected access to protected data", Expr
);
1228 end Check_Unprotected_Access
;
1234 procedure Check_VMS
(Construct
: Node_Id
) is
1236 if not OpenVMS_On_Target
then
1238 ("this construct is allowed only in Open'V'M'S", Construct
);
1242 ------------------------
1243 -- Collect_Interfaces --
1244 ------------------------
1246 procedure Collect_Interfaces
1248 Ifaces_List
: out Elist_Id
;
1249 Exclude_Parents
: Boolean := False;
1250 Use_Full_View
: Boolean := True)
1252 procedure Collect
(Typ
: Entity_Id
);
1253 -- Subsidiary subprogram used to traverse the whole list
1254 -- of directly and indirectly implemented interfaces
1260 procedure Collect
(Typ
: Entity_Id
) is
1261 Ancestor
: Entity_Id
;
1269 -- Handle private types
1272 and then Is_Private_Type
(Typ
)
1273 and then Present
(Full_View
(Typ
))
1275 Full_T
:= Full_View
(Typ
);
1278 -- Include the ancestor if we are generating the whole list of
1279 -- abstract interfaces.
1281 if Etype
(Full_T
) /= Typ
1283 -- Protect the frontend against wrong sources. For example:
1286 -- type A is tagged null record;
1287 -- type B is new A with private;
1288 -- type C is new A with private;
1290 -- type B is new C with null record;
1291 -- type C is new B with null record;
1294 and then Etype
(Full_T
) /= T
1296 Ancestor
:= Etype
(Full_T
);
1299 if Is_Interface
(Ancestor
)
1300 and then not Exclude_Parents
1302 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
1306 -- Traverse the graph of ancestor interfaces
1308 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
1309 Id
:= First
(Abstract_Interface_List
(Full_T
));
1310 while Present
(Id
) loop
1311 Iface
:= Etype
(Id
);
1313 -- Protect against wrong uses. For example:
1314 -- type I is interface;
1315 -- type O is tagged null record;
1316 -- type Wrong is new I and O with null record; -- ERROR
1318 if Is_Interface
(Iface
) then
1320 and then Etype
(T
) /= T
1321 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
1326 Append_Unique_Elmt
(Iface
, Ifaces_List
);
1335 -- Start of processing for Collect_Interfaces
1338 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
1339 Ifaces_List
:= New_Elmt_List
;
1341 end Collect_Interfaces
;
1343 ----------------------------------
1344 -- Collect_Interface_Components --
1345 ----------------------------------
1347 procedure Collect_Interface_Components
1348 (Tagged_Type
: Entity_Id
;
1349 Components_List
: out Elist_Id
)
1351 procedure Collect
(Typ
: Entity_Id
);
1352 -- Subsidiary subprogram used to climb to the parents
1358 procedure Collect
(Typ
: Entity_Id
) is
1359 Tag_Comp
: Entity_Id
;
1362 if Etype
(Typ
) /= Typ
1364 -- Protect the frontend against wrong sources. For example:
1367 -- type A is tagged null record;
1368 -- type B is new A with private;
1369 -- type C is new A with private;
1371 -- type B is new C with null record;
1372 -- type C is new B with null record;
1375 and then Etype
(Typ
) /= Tagged_Type
1377 Collect
(Etype
(Typ
));
1380 -- Collect the components containing tags of secondary dispatch
1383 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
1384 while Present
(Tag_Comp
) loop
1385 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
1386 Append_Elmt
(Tag_Comp
, Components_List
);
1388 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
1392 -- Start of processing for Collect_Interface_Components
1395 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
1396 and then Is_Tagged_Type
(Tagged_Type
));
1398 Components_List
:= New_Elmt_List
;
1399 Collect
(Tagged_Type
);
1400 end Collect_Interface_Components
;
1402 -----------------------------
1403 -- Collect_Interfaces_Info --
1404 -----------------------------
1406 procedure Collect_Interfaces_Info
1408 Ifaces_List
: out Elist_Id
;
1409 Components_List
: out Elist_Id
;
1410 Tags_List
: out Elist_Id
)
1412 Comps_List
: Elist_Id
;
1413 Comp_Elmt
: Elmt_Id
;
1414 Comp_Iface
: Entity_Id
;
1415 Iface_Elmt
: Elmt_Id
;
1418 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
1419 -- Search for the secondary tag associated with the interface type
1420 -- Iface that is implemented by T.
1426 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
1430 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
1432 and then Ekind
(Node
(ADT
)) = E_Constant
1433 and then Related_Type
(Node
(ADT
)) /= Iface
1435 -- Skip the secondary dispatch tables of Iface
1443 pragma Assert
(Ekind
(Node
(ADT
)) = E_Constant
);
1447 -- Start of processing for Collect_Interfaces_Info
1450 Collect_Interfaces
(T
, Ifaces_List
);
1451 Collect_Interface_Components
(T
, Comps_List
);
1453 -- Search for the record component and tag associated with each
1454 -- interface type of T.
1456 Components_List
:= New_Elmt_List
;
1457 Tags_List
:= New_Elmt_List
;
1459 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1460 while Present
(Iface_Elmt
) loop
1461 Iface
:= Node
(Iface_Elmt
);
1463 -- Associate the primary tag component and the primary dispatch table
1464 -- with all the interfaces that are parents of T
1466 if Is_Ancestor
(Iface
, T
) then
1467 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
1468 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
1470 -- Otherwise search for the tag component and secondary dispatch
1474 Comp_Elmt
:= First_Elmt
(Comps_List
);
1475 while Present
(Comp_Elmt
) loop
1476 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
1478 if Comp_Iface
= Iface
1479 or else Is_Ancestor
(Iface
, Comp_Iface
)
1481 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
1482 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
1486 Next_Elmt
(Comp_Elmt
);
1488 pragma Assert
(Present
(Comp_Elmt
));
1491 Next_Elmt
(Iface_Elmt
);
1493 end Collect_Interfaces_Info
;
1495 ----------------------------------
1496 -- Collect_Primitive_Operations --
1497 ----------------------------------
1499 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
1500 B_Type
: constant Entity_Id
:= Base_Type
(T
);
1501 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
1502 B_Scope
: Entity_Id
:= Scope
(B_Type
);
1506 Formal_Derived
: Boolean := False;
1510 -- For tagged types, the primitive operations are collected as they
1511 -- are declared, and held in an explicit list which is simply returned.
1513 if Is_Tagged_Type
(B_Type
) then
1514 return Primitive_Operations
(B_Type
);
1516 -- An untagged generic type that is a derived type inherits the
1517 -- primitive operations of its parent type. Other formal types only
1518 -- have predefined operators, which are not explicitly represented.
1520 elsif Is_Generic_Type
(B_Type
) then
1521 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
1522 and then Nkind
(Formal_Type_Definition
(B_Decl
))
1523 = N_Formal_Derived_Type_Definition
1525 Formal_Derived
:= True;
1527 return New_Elmt_List
;
1531 Op_List
:= New_Elmt_List
;
1533 if B_Scope
= Standard_Standard
then
1534 if B_Type
= Standard_String
then
1535 Append_Elmt
(Standard_Op_Concat
, Op_List
);
1537 elsif B_Type
= Standard_Wide_String
then
1538 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
1544 elsif (Is_Package_Or_Generic_Package
(B_Scope
)
1546 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
1548 or else Is_Derived_Type
(B_Type
)
1550 -- The primitive operations appear after the base type, except
1551 -- if the derivation happens within the private part of B_Scope
1552 -- and the type is a private type, in which case both the type
1553 -- and some primitive operations may appear before the base
1554 -- type, and the list of candidates starts after the type.
1556 if In_Open_Scopes
(B_Scope
)
1557 and then Scope
(T
) = B_Scope
1558 and then In_Private_Part
(B_Scope
)
1560 Id
:= Next_Entity
(T
);
1562 Id
:= Next_Entity
(B_Type
);
1565 while Present
(Id
) loop
1567 -- Note that generic formal subprograms are not
1568 -- considered to be primitive operations and thus
1569 -- are never inherited.
1571 if Is_Overloadable
(Id
)
1572 and then Nkind
(Parent
(Parent
(Id
)))
1573 not in N_Formal_Subprogram_Declaration
1577 if Base_Type
(Etype
(Id
)) = B_Type
then
1580 Formal
:= First_Formal
(Id
);
1581 while Present
(Formal
) loop
1582 if Base_Type
(Etype
(Formal
)) = B_Type
then
1586 elsif Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
1588 (Designated_Type
(Etype
(Formal
))) = B_Type
1594 Next_Formal
(Formal
);
1598 -- For a formal derived type, the only primitives are the
1599 -- ones inherited from the parent type. Operations appearing
1600 -- in the package declaration are not primitive for it.
1603 and then (not Formal_Derived
1604 or else Present
(Alias
(Id
)))
1606 Append_Elmt
(Id
, Op_List
);
1612 -- For a type declared in System, some of its operations
1613 -- may appear in the target-specific extension to System.
1616 and then Chars
(B_Scope
) = Name_System
1617 and then Scope
(B_Scope
) = Standard_Standard
1618 and then Present_System_Aux
1620 B_Scope
:= System_Aux_Id
;
1621 Id
:= First_Entity
(System_Aux_Id
);
1627 end Collect_Primitive_Operations
;
1629 -----------------------------------
1630 -- Compile_Time_Constraint_Error --
1631 -----------------------------------
1633 function Compile_Time_Constraint_Error
1636 Ent
: Entity_Id
:= Empty
;
1637 Loc
: Source_Ptr
:= No_Location
;
1638 Warn
: Boolean := False) return Node_Id
1640 Msgc
: String (1 .. Msg
'Length + 2);
1641 -- Copy of message, with room for possible ? and ! at end
1651 -- A static constraint error in an instance body is not a fatal error.
1652 -- we choose to inhibit the message altogether, because there is no
1653 -- obvious node (for now) on which to post it. On the other hand the
1654 -- offending node must be replaced with a constraint_error in any case.
1656 -- No messages are generated if we already posted an error on this node
1658 if not Error_Posted
(N
) then
1659 if Loc
/= No_Location
then
1665 Msgc
(1 .. Msg
'Length) := Msg
;
1668 -- Message is a warning, even in Ada 95 case
1670 if Msg
(Msg
'Last) = '?' then
1673 -- In Ada 83, all messages are warnings. In the private part and
1674 -- the body of an instance, constraint_checks are only warnings.
1675 -- We also make this a warning if the Warn parameter is set.
1678 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
1684 elsif In_Instance_Not_Visible
then
1689 -- Otherwise we have a real error message (Ada 95 static case)
1690 -- and we make this an unconditional message. Note that in the
1691 -- warning case we do not make the message unconditional, it seems
1692 -- quite reasonable to delete messages like this (about exceptions
1693 -- that will be raised) in dead code.
1701 -- Should we generate a warning? The answer is not quite yes. The
1702 -- very annoying exception occurs in the case of a short circuit
1703 -- operator where the left operand is static and decisive. Climb
1704 -- parents to see if that is the case we have here. Conditional
1705 -- expressions with decisive conditions are a similar situation.
1713 -- And then with False as left operand
1715 if Nkind
(P
) = N_And_Then
1716 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1717 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
1722 -- OR ELSE with True as left operand
1724 elsif Nkind
(P
) = N_Or_Else
1725 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1726 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
1731 -- Conditional expression
1733 elsif Nkind
(P
) = N_Conditional_Expression
then
1735 Cond
: constant Node_Id
:= First
(Expressions
(P
));
1736 Texp
: constant Node_Id
:= Next
(Cond
);
1737 Fexp
: constant Node_Id
:= Next
(Texp
);
1740 if Compile_Time_Known_Value
(Cond
) then
1742 -- Condition is True and we are in the right operand
1744 if Is_True
(Expr_Value
(Cond
))
1745 and then OldP
= Fexp
1750 -- Condition is False and we are in the left operand
1752 elsif Is_False
(Expr_Value
(Cond
))
1753 and then OldP
= Texp
1761 -- Special case for component association in aggregates, where
1762 -- we want to keep climbing up to the parent aggregate.
1764 elsif Nkind
(P
) = N_Component_Association
1765 and then Nkind
(Parent
(P
)) = N_Aggregate
1769 -- Keep going if within subexpression
1772 exit when Nkind
(P
) not in N_Subexpr
;
1777 if Present
(Ent
) then
1778 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
1780 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
1784 if Inside_Init_Proc
then
1786 ("\?& will be raised for objects of this type",
1787 N
, Standard_Constraint_Error
, Eloc
);
1790 ("\?& will be raised at run time",
1791 N
, Standard_Constraint_Error
, Eloc
);
1796 ("\static expression fails Constraint_Check", Eloc
);
1797 Set_Error_Posted
(N
);
1803 end Compile_Time_Constraint_Error
;
1805 -----------------------
1806 -- Conditional_Delay --
1807 -----------------------
1809 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
1811 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
1812 Set_Has_Delayed_Freeze
(New_Ent
);
1814 end Conditional_Delay
;
1816 -------------------------
1817 -- Copy_Parameter_List --
1818 -------------------------
1820 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
1821 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
1826 if No
(First_Formal
(Subp_Id
)) then
1830 Formal
:= First_Formal
(Subp_Id
);
1831 while Present
(Formal
) loop
1833 (Make_Parameter_Specification
(Loc
,
1834 Defining_Identifier
=>
1835 Make_Defining_Identifier
(Sloc
(Formal
),
1836 Chars
=> Chars
(Formal
)),
1837 In_Present
=> In_Present
(Parent
(Formal
)),
1838 Out_Present
=> Out_Present
(Parent
(Formal
)),
1840 New_Reference_To
(Etype
(Formal
), Loc
),
1842 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
1845 Next_Formal
(Formal
);
1850 end Copy_Parameter_List
;
1852 --------------------
1853 -- Current_Entity --
1854 --------------------
1856 -- The currently visible definition for a given identifier is the
1857 -- one most chained at the start of the visibility chain, i.e. the
1858 -- one that is referenced by the Node_Id value of the name of the
1859 -- given identifier.
1861 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
1863 return Get_Name_Entity_Id
(Chars
(N
));
1866 -----------------------------
1867 -- Current_Entity_In_Scope --
1868 -----------------------------
1870 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
1872 CS
: constant Entity_Id
:= Current_Scope
;
1874 Transient_Case
: constant Boolean := Scope_Is_Transient
;
1877 E
:= Get_Name_Entity_Id
(Chars
(N
));
1879 and then Scope
(E
) /= CS
1880 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
1886 end Current_Entity_In_Scope
;
1892 function Current_Scope
return Entity_Id
is
1894 if Scope_Stack
.Last
= -1 then
1895 return Standard_Standard
;
1898 C
: constant Entity_Id
:=
1899 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
1904 return Standard_Standard
;
1910 ------------------------
1911 -- Current_Subprogram --
1912 ------------------------
1914 function Current_Subprogram
return Entity_Id
is
1915 Scop
: constant Entity_Id
:= Current_Scope
;
1917 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
1920 return Enclosing_Subprogram
(Scop
);
1922 end Current_Subprogram
;
1924 ---------------------
1925 -- Defining_Entity --
1926 ---------------------
1928 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
1929 K
: constant Node_Kind
:= Nkind
(N
);
1930 Err
: Entity_Id
:= Empty
;
1935 N_Subprogram_Declaration |
1936 N_Abstract_Subprogram_Declaration |
1938 N_Package_Declaration |
1939 N_Subprogram_Renaming_Declaration |
1940 N_Subprogram_Body_Stub |
1941 N_Generic_Subprogram_Declaration |
1942 N_Generic_Package_Declaration |
1943 N_Formal_Subprogram_Declaration
1945 return Defining_Entity
(Specification
(N
));
1948 N_Component_Declaration |
1949 N_Defining_Program_Unit_Name |
1950 N_Discriminant_Specification |
1952 N_Entry_Declaration |
1953 N_Entry_Index_Specification |
1954 N_Exception_Declaration |
1955 N_Exception_Renaming_Declaration |
1956 N_Formal_Object_Declaration |
1957 N_Formal_Package_Declaration |
1958 N_Formal_Type_Declaration |
1959 N_Full_Type_Declaration |
1960 N_Implicit_Label_Declaration |
1961 N_Incomplete_Type_Declaration |
1962 N_Loop_Parameter_Specification |
1963 N_Number_Declaration |
1964 N_Object_Declaration |
1965 N_Object_Renaming_Declaration |
1966 N_Package_Body_Stub |
1967 N_Parameter_Specification |
1968 N_Private_Extension_Declaration |
1969 N_Private_Type_Declaration |
1971 N_Protected_Body_Stub |
1972 N_Protected_Type_Declaration |
1973 N_Single_Protected_Declaration |
1974 N_Single_Task_Declaration |
1975 N_Subtype_Declaration |
1978 N_Task_Type_Declaration
1980 return Defining_Identifier
(N
);
1983 return Defining_Entity
(Proper_Body
(N
));
1986 N_Function_Instantiation |
1987 N_Function_Specification |
1988 N_Generic_Function_Renaming_Declaration |
1989 N_Generic_Package_Renaming_Declaration |
1990 N_Generic_Procedure_Renaming_Declaration |
1992 N_Package_Instantiation |
1993 N_Package_Renaming_Declaration |
1994 N_Package_Specification |
1995 N_Procedure_Instantiation |
1996 N_Procedure_Specification
1999 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
2002 if Nkind
(Nam
) in N_Entity
then
2005 -- For Error, make up a name and attach to declaration
2006 -- so we can continue semantic analysis
2008 elsif Nam
= Error
then
2010 Make_Defining_Identifier
(Sloc
(N
),
2011 Chars
=> New_Internal_Name
('T'));
2012 Set_Defining_Unit_Name
(N
, Err
);
2015 -- If not an entity, get defining identifier
2018 return Defining_Identifier
(Nam
);
2022 when N_Block_Statement
=>
2023 return Entity
(Identifier
(N
));
2026 raise Program_Error
;
2029 end Defining_Entity
;
2031 --------------------------
2032 -- Denotes_Discriminant --
2033 --------------------------
2035 function Denotes_Discriminant
2037 Check_Concurrent
: Boolean := False) return Boolean
2041 if not Is_Entity_Name
(N
)
2042 or else No
(Entity
(N
))
2049 -- If we are checking for a protected type, the discriminant may have
2050 -- been rewritten as the corresponding discriminal of the original type
2051 -- or of the corresponding concurrent record, depending on whether we
2052 -- are in the spec or body of the protected type.
2054 return Ekind
(E
) = E_Discriminant
2057 and then Ekind
(E
) = E_In_Parameter
2058 and then Present
(Discriminal_Link
(E
))
2060 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
2062 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
2064 end Denotes_Discriminant
;
2066 ----------------------
2067 -- Denotes_Variable --
2068 ----------------------
2070 function Denotes_Variable
(N
: Node_Id
) return Boolean is
2072 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
2073 end Denotes_Variable
;
2075 -----------------------------
2076 -- Depends_On_Discriminant --
2077 -----------------------------
2079 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
2084 Get_Index_Bounds
(N
, L
, H
);
2085 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
2086 end Depends_On_Discriminant
;
2088 -------------------------
2089 -- Designate_Same_Unit --
2090 -------------------------
2092 function Designate_Same_Unit
2094 Name2
: Node_Id
) return Boolean
2096 K1
: constant Node_Kind
:= Nkind
(Name1
);
2097 K2
: constant Node_Kind
:= Nkind
(Name2
);
2099 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
2100 -- Returns the parent unit name node of a defining program unit name
2101 -- or the prefix if N is a selected component or an expanded name.
2103 function Select_Node
(N
: Node_Id
) return Node_Id
;
2104 -- Returns the defining identifier node of a defining program unit
2105 -- name or the selector node if N is a selected component or an
2112 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
2114 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2126 function Select_Node
(N
: Node_Id
) return Node_Id
is
2128 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2129 return Defining_Identifier
(N
);
2132 return Selector_Name
(N
);
2136 -- Start of processing for Designate_Next_Unit
2139 if (K1
= N_Identifier
or else
2140 K1
= N_Defining_Identifier
)
2142 (K2
= N_Identifier
or else
2143 K2
= N_Defining_Identifier
)
2145 return Chars
(Name1
) = Chars
(Name2
);
2148 (K1
= N_Expanded_Name
or else
2149 K1
= N_Selected_Component
or else
2150 K1
= N_Defining_Program_Unit_Name
)
2152 (K2
= N_Expanded_Name
or else
2153 K2
= N_Selected_Component
or else
2154 K2
= N_Defining_Program_Unit_Name
)
2157 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
2159 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
2164 end Designate_Same_Unit
;
2166 ----------------------------
2167 -- Enclosing_Generic_Body --
2168 ----------------------------
2170 function Enclosing_Generic_Body
2171 (N
: Node_Id
) return Node_Id
2179 while Present
(P
) loop
2180 if Nkind
(P
) = N_Package_Body
2181 or else Nkind
(P
) = N_Subprogram_Body
2183 Spec
:= Corresponding_Spec
(P
);
2185 if Present
(Spec
) then
2186 Decl
:= Unit_Declaration_Node
(Spec
);
2188 if Nkind
(Decl
) = N_Generic_Package_Declaration
2189 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2200 end Enclosing_Generic_Body
;
2202 ----------------------------
2203 -- Enclosing_Generic_Unit --
2204 ----------------------------
2206 function Enclosing_Generic_Unit
2207 (N
: Node_Id
) return Node_Id
2215 while Present
(P
) loop
2216 if Nkind
(P
) = N_Generic_Package_Declaration
2217 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
2221 elsif Nkind
(P
) = N_Package_Body
2222 or else Nkind
(P
) = N_Subprogram_Body
2224 Spec
:= Corresponding_Spec
(P
);
2226 if Present
(Spec
) then
2227 Decl
:= Unit_Declaration_Node
(Spec
);
2229 if Nkind
(Decl
) = N_Generic_Package_Declaration
2230 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2241 end Enclosing_Generic_Unit
;
2243 -------------------------------
2244 -- Enclosing_Lib_Unit_Entity --
2245 -------------------------------
2247 function Enclosing_Lib_Unit_Entity
return Entity_Id
is
2248 Unit_Entity
: Entity_Id
;
2251 -- Look for enclosing library unit entity by following scope links.
2252 -- Equivalent to, but faster than indexing through the scope stack.
2254 Unit_Entity
:= Current_Scope
;
2255 while (Present
(Scope
(Unit_Entity
))
2256 and then Scope
(Unit_Entity
) /= Standard_Standard
)
2257 and not Is_Child_Unit
(Unit_Entity
)
2259 Unit_Entity
:= Scope
(Unit_Entity
);
2263 end Enclosing_Lib_Unit_Entity
;
2265 -----------------------------
2266 -- Enclosing_Lib_Unit_Node --
2267 -----------------------------
2269 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
2270 Current_Node
: Node_Id
;
2274 while Present
(Current_Node
)
2275 and then Nkind
(Current_Node
) /= N_Compilation_Unit
2277 Current_Node
:= Parent
(Current_Node
);
2280 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
2284 return Current_Node
;
2285 end Enclosing_Lib_Unit_Node
;
2287 --------------------------
2288 -- Enclosing_Subprogram --
2289 --------------------------
2291 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
2292 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
2295 if Dynamic_Scope
= Standard_Standard
then
2298 elsif Dynamic_Scope
= Empty
then
2301 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
2302 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
2304 elsif Ekind
(Dynamic_Scope
) = E_Block
2305 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
2307 return Enclosing_Subprogram
(Dynamic_Scope
);
2309 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
2310 return Get_Task_Body_Procedure
(Dynamic_Scope
);
2312 elsif Convention
(Dynamic_Scope
) = Convention_Protected
then
2313 return Protected_Body_Subprogram
(Dynamic_Scope
);
2316 return Dynamic_Scope
;
2318 end Enclosing_Subprogram
;
2320 ------------------------
2321 -- Ensure_Freeze_Node --
2322 ------------------------
2324 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
2328 if No
(Freeze_Node
(E
)) then
2329 FN
:= Make_Freeze_Entity
(Sloc
(E
));
2330 Set_Has_Delayed_Freeze
(E
);
2331 Set_Freeze_Node
(E
, FN
);
2332 Set_Access_Types_To_Process
(FN
, No_Elist
);
2333 Set_TSS_Elist
(FN
, No_Elist
);
2336 end Ensure_Freeze_Node
;
2342 procedure Enter_Name
(Def_Id
: Entity_Id
) is
2343 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
2344 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
2345 S
: constant Entity_Id
:= Current_Scope
;
2348 Generate_Definition
(Def_Id
);
2350 -- Add new name to current scope declarations. Check for duplicate
2351 -- declaration, which may or may not be a genuine error.
2355 -- Case of previous entity entered because of a missing declaration
2356 -- or else a bad subtype indication. Best is to use the new entity,
2357 -- and make the previous one invisible.
2359 if Etype
(E
) = Any_Type
then
2360 Set_Is_Immediately_Visible
(E
, False);
2362 -- Case of renaming declaration constructed for package instances.
2363 -- if there is an explicit declaration with the same identifier,
2364 -- the renaming is not immediately visible any longer, but remains
2365 -- visible through selected component notation.
2367 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
2368 and then not Comes_From_Source
(E
)
2370 Set_Is_Immediately_Visible
(E
, False);
2372 -- The new entity may be the package renaming, which has the same
2373 -- same name as a generic formal which has been seen already.
2375 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
2376 and then not Comes_From_Source
(Def_Id
)
2378 Set_Is_Immediately_Visible
(E
, False);
2380 -- For a fat pointer corresponding to a remote access to subprogram,
2381 -- we use the same identifier as the RAS type, so that the proper
2382 -- name appears in the stub. This type is only retrieved through
2383 -- the RAS type and never by visibility, and is not added to the
2384 -- visibility list (see below).
2386 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
2387 and then Present
(Corresponding_Remote_Type
(Def_Id
))
2391 -- A controller component for a type extension overrides the
2392 -- inherited component.
2394 elsif Chars
(E
) = Name_uController
then
2397 -- Case of an implicit operation or derived literal. The new entity
2398 -- hides the implicit one, which is removed from all visibility,
2399 -- i.e. the entity list of its scope, and homonym chain of its name.
2401 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
2402 or else Is_Internal
(E
)
2406 Prev_Vis
: Entity_Id
;
2407 Decl
: constant Node_Id
:= Parent
(E
);
2410 -- If E is an implicit declaration, it cannot be the first
2411 -- entity in the scope.
2413 Prev
:= First_Entity
(Current_Scope
);
2414 while Present
(Prev
)
2415 and then Next_Entity
(Prev
) /= E
2422 -- If E is not on the entity chain of the current scope,
2423 -- it is an implicit declaration in the generic formal
2424 -- part of a generic subprogram. When analyzing the body,
2425 -- the generic formals are visible but not on the entity
2426 -- chain of the subprogram. The new entity will become
2427 -- the visible one in the body.
2430 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
2434 Set_Next_Entity
(Prev
, Next_Entity
(E
));
2436 if No
(Next_Entity
(Prev
)) then
2437 Set_Last_Entity
(Current_Scope
, Prev
);
2440 if E
= Current_Entity
(E
) then
2444 Prev_Vis
:= Current_Entity
(E
);
2445 while Homonym
(Prev_Vis
) /= E
loop
2446 Prev_Vis
:= Homonym
(Prev_Vis
);
2450 if Present
(Prev_Vis
) then
2452 -- Skip E in the visibility chain
2454 Set_Homonym
(Prev_Vis
, Homonym
(E
));
2457 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
2462 -- This section of code could use a comment ???
2464 elsif Present
(Etype
(E
))
2465 and then Is_Concurrent_Type
(Etype
(E
))
2470 -- If the homograph is a protected component renaming, it should not
2471 -- be hiding the current entity. Such renamings are treated as weak
2474 elsif Is_Prival
(E
) then
2475 Set_Is_Immediately_Visible
(E
, False);
2477 -- In this case the current entity is a protected component renaming.
2478 -- Perform minimal decoration by setting the scope and return since
2479 -- the prival should not be hiding other visible entities.
2481 elsif Is_Prival
(Def_Id
) then
2482 Set_Scope
(Def_Id
, Current_Scope
);
2485 -- Analogous to privals, the discriminal generated for an entry
2486 -- index parameter acts as a weak declaration. Perform minimal
2487 -- decoration to avoid bogus errors.
2489 elsif Is_Discriminal
(Def_Id
)
2490 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
2492 Set_Scope
(Def_Id
, Current_Scope
);
2495 -- In the body or private part of an instance, a type extension
2496 -- may introduce a component with the same name as that of an
2497 -- actual. The legality rule is not enforced, but the semantics
2498 -- of the full type with two components of the same name are not
2499 -- clear at this point ???
2501 elsif In_Instance_Not_Visible
then
2504 -- When compiling a package body, some child units may have become
2505 -- visible. They cannot conflict with local entities that hide them.
2507 elsif Is_Child_Unit
(E
)
2508 and then In_Open_Scopes
(Scope
(E
))
2509 and then not Is_Immediately_Visible
(E
)
2513 -- Conversely, with front-end inlining we may compile the parent
2514 -- body first, and a child unit subsequently. The context is now
2515 -- the parent spec, and body entities are not visible.
2517 elsif Is_Child_Unit
(Def_Id
)
2518 and then Is_Package_Body_Entity
(E
)
2519 and then not In_Package_Body
(Current_Scope
)
2523 -- Case of genuine duplicate declaration
2526 Error_Msg_Sloc
:= Sloc
(E
);
2528 -- If the previous declaration is an incomplete type declaration
2529 -- this may be an attempt to complete it with a private type.
2530 -- The following avoids confusing cascaded errors.
2532 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
2533 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
2536 ("incomplete type cannot be completed with a private " &
2537 "declaration", Parent
(Def_Id
));
2538 Set_Is_Immediately_Visible
(E
, False);
2539 Set_Full_View
(E
, Def_Id
);
2541 -- An inherited component of a record conflicts with a new
2542 -- discriminant. The discriminant is inserted first in the scope,
2543 -- but the error should be posted on it, not on the component.
2545 elsif Ekind
(E
) = E_Discriminant
2546 and then Present
(Scope
(Def_Id
))
2547 and then Scope
(Def_Id
) /= Current_Scope
2549 Error_Msg_Sloc
:= Sloc
(Def_Id
);
2550 Error_Msg_N
("& conflicts with declaration#", E
);
2553 -- If the name of the unit appears in its own context clause,
2554 -- a dummy package with the name has already been created, and
2555 -- the error emitted. Try to continue quietly.
2557 elsif Error_Posted
(E
)
2558 and then Sloc
(E
) = No_Location
2559 and then Nkind
(Parent
(E
)) = N_Package_Specification
2560 and then Current_Scope
= Standard_Standard
2562 Set_Scope
(Def_Id
, Current_Scope
);
2566 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
2568 -- Avoid cascaded messages with duplicate components in
2571 if Ekind
(E
) = E_Component
2572 or else Ekind
(E
) = E_Discriminant
2578 if Nkind
(Parent
(Parent
(Def_Id
))) =
2579 N_Generic_Subprogram_Declaration
2581 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
2583 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
2586 -- If entity is in standard, then we are in trouble, because
2587 -- it means that we have a library package with a duplicated
2588 -- name. That's hard to recover from, so abort!
2590 if S
= Standard_Standard
then
2591 raise Unrecoverable_Error
;
2593 -- Otherwise we continue with the declaration. Having two
2594 -- identical declarations should not cause us too much trouble!
2602 -- If we fall through, declaration is OK , or OK enough to continue
2604 -- If Def_Id is a discriminant or a record component we are in the
2605 -- midst of inheriting components in a derived record definition.
2606 -- Preserve their Ekind and Etype.
2608 if Ekind
(Def_Id
) = E_Discriminant
2609 or else Ekind
(Def_Id
) = E_Component
2613 -- If a type is already set, leave it alone (happens whey a type
2614 -- declaration is reanalyzed following a call to the optimizer)
2616 elsif Present
(Etype
(Def_Id
)) then
2619 -- Otherwise, the kind E_Void insures that premature uses of the entity
2620 -- will be detected. Any_Type insures that no cascaded errors will occur
2623 Set_Ekind
(Def_Id
, E_Void
);
2624 Set_Etype
(Def_Id
, Any_Type
);
2627 -- Inherited discriminants and components in derived record types are
2628 -- immediately visible. Itypes are not.
2630 if Ekind
(Def_Id
) = E_Discriminant
2631 or else Ekind
(Def_Id
) = E_Component
2632 or else (No
(Corresponding_Remote_Type
(Def_Id
))
2633 and then not Is_Itype
(Def_Id
))
2635 Set_Is_Immediately_Visible
(Def_Id
);
2636 Set_Current_Entity
(Def_Id
);
2639 Set_Homonym
(Def_Id
, C
);
2640 Append_Entity
(Def_Id
, S
);
2641 Set_Public_Status
(Def_Id
);
2643 -- Warn if new entity hides an old one
2645 if Warn_On_Hiding
and then Present
(C
)
2647 -- Don't warn for record components since they always have a well
2648 -- defined scope which does not confuse other uses. Note that in
2649 -- some cases, Ekind has not been set yet.
2651 and then Ekind
(C
) /= E_Component
2652 and then Ekind
(C
) /= E_Discriminant
2653 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
2654 and then Ekind
(Def_Id
) /= E_Component
2655 and then Ekind
(Def_Id
) /= E_Discriminant
2656 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
2658 -- Don't warn for one character variables. It is too common to use
2659 -- such variables as locals and will just cause too many false hits.
2661 and then Length_Of_Name
(Chars
(C
)) /= 1
2663 -- Don't warn for non-source entities
2665 and then Comes_From_Source
(C
)
2666 and then Comes_From_Source
(Def_Id
)
2668 -- Don't warn unless entity in question is in extended main source
2670 and then In_Extended_Main_Source_Unit
(Def_Id
)
2672 -- Finally, the hidden entity must be either immediately visible
2673 -- or use visible (from a used package)
2676 (Is_Immediately_Visible
(C
)
2678 Is_Potentially_Use_Visible
(C
))
2680 Error_Msg_Sloc
:= Sloc
(C
);
2681 Error_Msg_N
("declaration hides &#?", Def_Id
);
2685 --------------------------
2686 -- Explain_Limited_Type --
2687 --------------------------
2689 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
2693 -- For array, component type must be limited
2695 if Is_Array_Type
(T
) then
2696 Error_Msg_Node_2
:= T
;
2698 ("\component type& of type& is limited", N
, Component_Type
(T
));
2699 Explain_Limited_Type
(Component_Type
(T
), N
);
2701 elsif Is_Record_Type
(T
) then
2703 -- No need for extra messages if explicit limited record
2705 if Is_Limited_Record
(Base_Type
(T
)) then
2709 -- Otherwise find a limited component. Check only components that
2710 -- come from source, or inherited components that appear in the
2711 -- source of the ancestor.
2713 C
:= First_Component
(T
);
2714 while Present
(C
) loop
2715 if Is_Limited_Type
(Etype
(C
))
2717 (Comes_From_Source
(C
)
2719 (Present
(Original_Record_Component
(C
))
2721 Comes_From_Source
(Original_Record_Component
(C
))))
2723 Error_Msg_Node_2
:= T
;
2724 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
2725 Explain_Limited_Type
(Etype
(C
), N
);
2732 -- The type may be declared explicitly limited, even if no component
2733 -- of it is limited, in which case we fall out of the loop.
2736 end Explain_Limited_Type
;
2742 procedure Find_Actual
2744 Formal
: out Entity_Id
;
2747 Parnt
: constant Node_Id
:= Parent
(N
);
2751 if (Nkind
(Parnt
) = N_Indexed_Component
2753 Nkind
(Parnt
) = N_Selected_Component
)
2754 and then N
= Prefix
(Parnt
)
2756 Find_Actual
(Parnt
, Formal
, Call
);
2759 elsif Nkind
(Parnt
) = N_Parameter_Association
2760 and then N
= Explicit_Actual_Parameter
(Parnt
)
2762 Call
:= Parent
(Parnt
);
2764 elsif Nkind
(Parnt
) = N_Procedure_Call_Statement
then
2773 -- If we have a call to a subprogram look for the parameter. Note that
2774 -- we exclude overloaded calls, since we don't know enough to be sure
2775 -- of giving the right answer in this case.
2777 if Is_Entity_Name
(Name
(Call
))
2778 and then Present
(Entity
(Name
(Call
)))
2779 and then Is_Overloadable
(Entity
(Name
(Call
)))
2780 and then not Is_Overloaded
(Name
(Call
))
2782 -- Fall here if we are definitely a parameter
2784 Actual
:= First_Actual
(Call
);
2785 Formal
:= First_Formal
(Entity
(Name
(Call
)));
2786 while Present
(Formal
) and then Present
(Actual
) loop
2790 Actual
:= Next_Actual
(Actual
);
2791 Formal
:= Next_Formal
(Formal
);
2796 -- Fall through here if we did not find matching actual
2802 -------------------------------------
2803 -- Find_Corresponding_Discriminant --
2804 -------------------------------------
2806 function Find_Corresponding_Discriminant
2808 Typ
: Entity_Id
) return Entity_Id
2810 Par_Disc
: Entity_Id
;
2811 Old_Disc
: Entity_Id
;
2812 New_Disc
: Entity_Id
;
2815 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
2817 -- The original type may currently be private, and the discriminant
2818 -- only appear on its full view.
2820 if Is_Private_Type
(Scope
(Par_Disc
))
2821 and then not Has_Discriminants
(Scope
(Par_Disc
))
2822 and then Present
(Full_View
(Scope
(Par_Disc
)))
2824 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
2826 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
2829 if Is_Class_Wide_Type
(Typ
) then
2830 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
2832 New_Disc
:= First_Discriminant
(Typ
);
2835 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
2836 if Old_Disc
= Par_Disc
then
2839 Next_Discriminant
(Old_Disc
);
2840 Next_Discriminant
(New_Disc
);
2844 -- Should always find it
2846 raise Program_Error
;
2847 end Find_Corresponding_Discriminant
;
2849 --------------------------
2850 -- Find_Overlaid_Object --
2851 --------------------------
2853 function Find_Overlaid_Object
(N
: Node_Id
) return Entity_Id
is
2857 -- We are looking for one of the two following forms:
2859 -- for X'Address use Y'Address
2863 -- Const : constant Address := expr;
2865 -- for X'Address use Const;
2867 -- In the second case, the expr is either Y'Address, or recursively a
2868 -- constant that eventually references Y'Address.
2870 if Nkind
(N
) = N_Attribute_Definition_Clause
2871 and then Chars
(N
) = Name_Address
2873 -- This loop checks the form of the expression for Y'Address where Y
2874 -- is an object entity name. The first loop checks the original
2875 -- expression in the attribute definition clause. Subsequent loops
2876 -- check referenced constants.
2878 Expr
:= Expression
(N
);
2880 -- Check for Y'Address where Y is an object entity
2882 if Nkind
(Expr
) = N_Attribute_Reference
2883 and then Attribute_Name
(Expr
) = Name_Address
2884 and then Is_Entity_Name
(Prefix
(Expr
))
2885 and then Is_Object
(Entity
(Prefix
(Expr
)))
2887 return Entity
(Prefix
(Expr
));
2889 -- Check for Const where Const is a constant entity
2891 elsif Is_Entity_Name
(Expr
)
2892 and then Ekind
(Entity
(Expr
)) = E_Constant
2894 Expr
:= Constant_Value
(Entity
(Expr
));
2896 -- Anything else does not need checking
2905 end Find_Overlaid_Object
;
2907 -------------------------
2908 -- Find_Parameter_Type --
2909 -------------------------
2911 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
2913 if Nkind
(Param
) /= N_Parameter_Specification
then
2916 -- For an access parameter, obtain the type from the formal entity
2917 -- itself, because access to subprogram nodes do not carry a type.
2918 -- Shouldn't we always use the formal entity ???
2920 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
2921 return Etype
(Defining_Identifier
(Param
));
2924 return Etype
(Parameter_Type
(Param
));
2926 end Find_Parameter_Type
;
2928 -----------------------------
2929 -- Find_Static_Alternative --
2930 -----------------------------
2932 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
2933 Expr
: constant Node_Id
:= Expression
(N
);
2934 Val
: constant Uint
:= Expr_Value
(Expr
);
2939 Alt
:= First
(Alternatives
(N
));
2942 if Nkind
(Alt
) /= N_Pragma
then
2943 Choice
:= First
(Discrete_Choices
(Alt
));
2944 while Present
(Choice
) loop
2946 -- Others choice, always matches
2948 if Nkind
(Choice
) = N_Others_Choice
then
2951 -- Range, check if value is in the range
2953 elsif Nkind
(Choice
) = N_Range
then
2955 Val
>= Expr_Value
(Low_Bound
(Choice
))
2957 Val
<= Expr_Value
(High_Bound
(Choice
));
2959 -- Choice is a subtype name. Note that we know it must
2960 -- be a static subtype, since otherwise it would have
2961 -- been diagnosed as illegal.
2963 elsif Is_Entity_Name
(Choice
)
2964 and then Is_Type
(Entity
(Choice
))
2966 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
));
2968 -- Choice is a subtype indication
2970 elsif Nkind
(Choice
) = N_Subtype_Indication
then
2972 C
: constant Node_Id
:= Constraint
(Choice
);
2973 R
: constant Node_Id
:= Range_Expression
(C
);
2977 Val
>= Expr_Value
(Low_Bound
(R
))
2979 Val
<= Expr_Value
(High_Bound
(R
));
2982 -- Choice is a simple expression
2985 exit Search
when Val
= Expr_Value
(Choice
);
2993 pragma Assert
(Present
(Alt
));
2996 -- The above loop *must* terminate by finding a match, since
2997 -- we know the case statement is valid, and the value of the
2998 -- expression is known at compile time. When we fall out of
2999 -- the loop, Alt points to the alternative that we know will
3000 -- be selected at run time.
3003 end Find_Static_Alternative
;
3009 function First_Actual
(Node
: Node_Id
) return Node_Id
is
3013 if No
(Parameter_Associations
(Node
)) then
3017 N
:= First
(Parameter_Associations
(Node
));
3019 if Nkind
(N
) = N_Parameter_Association
then
3020 return First_Named_Actual
(Node
);
3026 -------------------------
3027 -- Full_Qualified_Name --
3028 -------------------------
3030 function Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3032 pragma Warnings
(Off
, Res
);
3034 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
;
3035 -- Compute recursively the qualified name without NUL at the end
3037 ----------------------------------
3038 -- Internal_Full_Qualified_Name --
3039 ----------------------------------
3041 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3042 Ent
: Entity_Id
:= E
;
3043 Parent_Name
: String_Id
:= No_String
;
3046 -- Deals properly with child units
3048 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
3049 Ent
:= Defining_Identifier
(Ent
);
3052 -- Compute qualification recursively (only "Standard" has no scope)
3054 if Present
(Scope
(Scope
(Ent
))) then
3055 Parent_Name
:= Internal_Full_Qualified_Name
(Scope
(Ent
));
3058 -- Every entity should have a name except some expanded blocks
3059 -- don't bother about those.
3061 if Chars
(Ent
) = No_Name
then
3065 -- Add a period between Name and qualification
3067 if Parent_Name
/= No_String
then
3068 Start_String
(Parent_Name
);
3069 Store_String_Char
(Get_Char_Code
('.'));
3075 -- Generates the entity name in upper case
3077 Get_Decoded_Name_String
(Chars
(Ent
));
3079 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3081 end Internal_Full_Qualified_Name
;
3083 -- Start of processing for Full_Qualified_Name
3086 Res
:= Internal_Full_Qualified_Name
(E
);
3087 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
3089 end Full_Qualified_Name
;
3091 -----------------------
3092 -- Gather_Components --
3093 -----------------------
3095 procedure Gather_Components
3097 Comp_List
: Node_Id
;
3098 Governed_By
: List_Id
;
3100 Report_Errors
: out Boolean)
3104 Discrete_Choice
: Node_Id
;
3105 Comp_Item
: Node_Id
;
3107 Discrim
: Entity_Id
;
3108 Discrim_Name
: Node_Id
;
3109 Discrim_Value
: Node_Id
;
3112 Report_Errors
:= False;
3114 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
3117 elsif Present
(Component_Items
(Comp_List
)) then
3118 Comp_Item
:= First
(Component_Items
(Comp_List
));
3124 while Present
(Comp_Item
) loop
3126 -- Skip the tag of a tagged record, the interface tags, as well
3127 -- as all items that are not user components (anonymous types,
3128 -- rep clauses, Parent field, controller field).
3130 if Nkind
(Comp_Item
) = N_Component_Declaration
then
3132 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
3134 if not Is_Tag
(Comp
)
3135 and then Chars
(Comp
) /= Name_uParent
3136 and then Chars
(Comp
) /= Name_uController
3138 Append_Elmt
(Comp
, Into
);
3146 if No
(Variant_Part
(Comp_List
)) then
3149 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
3150 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3153 -- Look for the discriminant that governs this variant part.
3154 -- The discriminant *must* be in the Governed_By List
3156 Assoc
:= First
(Governed_By
);
3157 Find_Constraint
: loop
3158 Discrim
:= First
(Choices
(Assoc
));
3159 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
3160 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
3162 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
3163 = Chars
(Discrim_Name
))
3164 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
3165 = Chars
(Discrim_Name
);
3167 if No
(Next
(Assoc
)) then
3168 if not Is_Constrained
(Typ
)
3169 and then Is_Derived_Type
(Typ
)
3170 and then Present
(Stored_Constraint
(Typ
))
3172 -- If the type is a tagged type with inherited discriminants,
3173 -- use the stored constraint on the parent in order to find
3174 -- the values of discriminants that are otherwise hidden by an
3175 -- explicit constraint. Renamed discriminants are handled in
3178 -- If several parent discriminants are renamed by a single
3179 -- discriminant of the derived type, the call to obtain the
3180 -- Corresponding_Discriminant field only retrieves the last
3181 -- of them. We recover the constraint on the others from the
3182 -- Stored_Constraint as well.
3189 D
:= First_Discriminant
(Etype
(Typ
));
3190 C
:= First_Elmt
(Stored_Constraint
(Typ
));
3191 while Present
(D
) and then Present
(C
) loop
3192 if Chars
(Discrim_Name
) = Chars
(D
) then
3193 if Is_Entity_Name
(Node
(C
))
3194 and then Entity
(Node
(C
)) = Entity
(Discrim
)
3196 -- D is renamed by Discrim, whose value is given in
3203 Make_Component_Association
(Sloc
(Typ
),
3205 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
3206 Duplicate_Subexpr_No_Checks
(Node
(C
)));
3208 exit Find_Constraint
;
3211 Next_Discriminant
(D
);
3218 if No
(Next
(Assoc
)) then
3219 Error_Msg_NE
(" missing value for discriminant&",
3220 First
(Governed_By
), Discrim_Name
);
3221 Report_Errors
:= True;
3226 end loop Find_Constraint
;
3228 Discrim_Value
:= Expression
(Assoc
);
3230 if not Is_OK_Static_Expression
(Discrim_Value
) then
3232 ("value for discriminant & must be static!",
3233 Discrim_Value
, Discrim
);
3234 Why_Not_Static
(Discrim_Value
);
3235 Report_Errors
:= True;
3239 Search_For_Discriminant_Value
: declare
3245 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
3248 Find_Discrete_Value
: while Present
(Variant
) loop
3249 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
3250 while Present
(Discrete_Choice
) loop
3252 exit Find_Discrete_Value
when
3253 Nkind
(Discrete_Choice
) = N_Others_Choice
;
3255 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
3257 UI_Low
:= Expr_Value
(Low
);
3258 UI_High
:= Expr_Value
(High
);
3260 exit Find_Discrete_Value
when
3261 UI_Low
<= UI_Discrim_Value
3263 UI_High
>= UI_Discrim_Value
;
3265 Next
(Discrete_Choice
);
3268 Next_Non_Pragma
(Variant
);
3269 end loop Find_Discrete_Value
;
3270 end Search_For_Discriminant_Value
;
3272 if No
(Variant
) then
3274 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
3275 Report_Errors
:= True;
3279 -- If we have found the corresponding choice, recursively add its
3280 -- components to the Into list.
3282 Gather_Components
(Empty
,
3283 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
3284 end Gather_Components
;
3286 ------------------------
3287 -- Get_Actual_Subtype --
3288 ------------------------
3290 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
3291 Typ
: constant Entity_Id
:= Etype
(N
);
3292 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
3301 -- If what we have is an identifier that references a subprogram
3302 -- formal, or a variable or constant object, then we get the actual
3303 -- subtype from the referenced entity if one has been built.
3305 if Nkind
(N
) = N_Identifier
3307 (Is_Formal
(Entity
(N
))
3308 or else Ekind
(Entity
(N
)) = E_Constant
3309 or else Ekind
(Entity
(N
)) = E_Variable
)
3310 and then Present
(Actual_Subtype
(Entity
(N
)))
3312 return Actual_Subtype
(Entity
(N
));
3314 -- Actual subtype of unchecked union is always itself. We never need
3315 -- the "real" actual subtype. If we did, we couldn't get it anyway
3316 -- because the discriminant is not available. The restrictions on
3317 -- Unchecked_Union are designed to make sure that this is OK.
3319 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
3322 -- Here for the unconstrained case, we must find actual subtype
3323 -- No actual subtype is available, so we must build it on the fly.
3325 -- Checking the type, not the underlying type, for constrainedness
3326 -- seems to be necessary. Maybe all the tests should be on the type???
3328 elsif (not Is_Constrained
(Typ
))
3329 and then (Is_Array_Type
(Utyp
)
3330 or else (Is_Record_Type
(Utyp
)
3331 and then Has_Discriminants
(Utyp
)))
3332 and then not Has_Unknown_Discriminants
(Utyp
)
3333 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
3335 -- Nothing to do if in spec expression (why not???)
3337 if In_Spec_Expression
then
3340 elsif Is_Private_Type
(Typ
)
3341 and then not Has_Discriminants
(Typ
)
3343 -- If the type has no discriminants, there is no subtype to
3344 -- build, even if the underlying type is discriminated.
3348 -- Else build the actual subtype
3351 Decl
:= Build_Actual_Subtype
(Typ
, N
);
3352 Atyp
:= Defining_Identifier
(Decl
);
3354 -- If Build_Actual_Subtype generated a new declaration then use it
3358 -- The actual subtype is an Itype, so analyze the declaration,
3359 -- but do not attach it to the tree, to get the type defined.
3361 Set_Parent
(Decl
, N
);
3362 Set_Is_Itype
(Atyp
);
3363 Analyze
(Decl
, Suppress
=> All_Checks
);
3364 Set_Associated_Node_For_Itype
(Atyp
, N
);
3365 Set_Has_Delayed_Freeze
(Atyp
, False);
3367 -- We need to freeze the actual subtype immediately. This is
3368 -- needed, because otherwise this Itype will not get frozen
3369 -- at all, and it is always safe to freeze on creation because
3370 -- any associated types must be frozen at this point.
3372 Freeze_Itype
(Atyp
, N
);
3375 -- Otherwise we did not build a declaration, so return original
3382 -- For all remaining cases, the actual subtype is the same as
3383 -- the nominal type.
3388 end Get_Actual_Subtype
;
3390 -------------------------------------
3391 -- Get_Actual_Subtype_If_Available --
3392 -------------------------------------
3394 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
3395 Typ
: constant Entity_Id
:= Etype
(N
);
3398 -- If what we have is an identifier that references a subprogram
3399 -- formal, or a variable or constant object, then we get the actual
3400 -- subtype from the referenced entity if one has been built.
3402 if Nkind
(N
) = N_Identifier
3404 (Is_Formal
(Entity
(N
))
3405 or else Ekind
(Entity
(N
)) = E_Constant
3406 or else Ekind
(Entity
(N
)) = E_Variable
)
3407 and then Present
(Actual_Subtype
(Entity
(N
)))
3409 return Actual_Subtype
(Entity
(N
));
3411 -- Otherwise the Etype of N is returned unchanged
3416 end Get_Actual_Subtype_If_Available
;
3418 -------------------------------
3419 -- Get_Default_External_Name --
3420 -------------------------------
3422 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
3424 Get_Decoded_Name_String
(Chars
(E
));
3426 if Opt
.External_Name_Imp_Casing
= Uppercase
then
3427 Set_Casing
(All_Upper_Case
);
3429 Set_Casing
(All_Lower_Case
);
3433 Make_String_Literal
(Sloc
(E
),
3434 Strval
=> String_From_Name_Buffer
);
3435 end Get_Default_External_Name
;
3437 ---------------------------
3438 -- Get_Enum_Lit_From_Pos --
3439 ---------------------------
3441 function Get_Enum_Lit_From_Pos
3444 Loc
: Source_Ptr
) return Node_Id
3449 -- In the case where the literal is of type Character, Wide_Character
3450 -- or Wide_Wide_Character or of a type derived from them, there needs
3451 -- to be some special handling since there is no explicit chain of
3452 -- literals to search. Instead, an N_Character_Literal node is created
3453 -- with the appropriate Char_Code and Chars fields.
3455 if Is_Standard_Character_Type
(T
) then
3456 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
3458 Make_Character_Literal
(Loc
,
3460 Char_Literal_Value
=> Pos
);
3462 -- For all other cases, we have a complete table of literals, and
3463 -- we simply iterate through the chain of literal until the one
3464 -- with the desired position value is found.
3468 Lit
:= First_Literal
(Base_Type
(T
));
3469 for J
in 1 .. UI_To_Int
(Pos
) loop
3473 return New_Occurrence_Of
(Lit
, Loc
);
3475 end Get_Enum_Lit_From_Pos
;
3477 ------------------------
3478 -- Get_Generic_Entity --
3479 ------------------------
3481 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
3482 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
3484 if Present
(Renamed_Object
(Ent
)) then
3485 return Renamed_Object
(Ent
);
3489 end Get_Generic_Entity
;
3491 ----------------------
3492 -- Get_Index_Bounds --
3493 ----------------------
3495 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
3496 Kind
: constant Node_Kind
:= Nkind
(N
);
3500 if Kind
= N_Range
then
3502 H
:= High_Bound
(N
);
3504 elsif Kind
= N_Subtype_Indication
then
3505 R
:= Range_Expression
(Constraint
(N
));
3513 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
3514 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
3517 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
3518 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
3522 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
3523 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
3526 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
3527 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
3531 -- N is an expression, indicating a range with one value
3536 end Get_Index_Bounds
;
3538 ----------------------------------
3539 -- Get_Library_Unit_Name_string --
3540 ----------------------------------
3542 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
3543 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
3546 Get_Unit_Name_String
(Unit_Name_Id
);
3548 -- Remove seven last character (" (spec)" or " (body)")
3550 Name_Len
:= Name_Len
- 7;
3551 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
3552 end Get_Library_Unit_Name_String
;
3554 ------------------------
3555 -- Get_Name_Entity_Id --
3556 ------------------------
3558 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
3560 return Entity_Id
(Get_Name_Table_Info
(Id
));
3561 end Get_Name_Entity_Id
;
3567 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
3569 return Get_Pragma_Id
(Pragma_Name
(N
));
3572 ---------------------------
3573 -- Get_Referenced_Object --
3574 ---------------------------
3576 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
3581 while Is_Entity_Name
(R
)
3582 and then Present
(Renamed_Object
(Entity
(R
)))
3584 R
:= Renamed_Object
(Entity
(R
));
3588 end Get_Referenced_Object
;
3590 ------------------------
3591 -- Get_Renamed_Entity --
3592 ------------------------
3594 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
3599 while Present
(Renamed_Entity
(R
)) loop
3600 R
:= Renamed_Entity
(R
);
3604 end Get_Renamed_Entity
;
3606 -------------------------
3607 -- Get_Subprogram_Body --
3608 -------------------------
3610 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
3614 Decl
:= Unit_Declaration_Node
(E
);
3616 if Nkind
(Decl
) = N_Subprogram_Body
then
3619 -- The below comment is bad, because it is possible for
3620 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3622 else -- Nkind (Decl) = N_Subprogram_Declaration
3624 if Present
(Corresponding_Body
(Decl
)) then
3625 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
3627 -- Imported subprogram case
3633 end Get_Subprogram_Body
;
3635 ---------------------------
3636 -- Get_Subprogram_Entity --
3637 ---------------------------
3639 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
3644 if Nkind
(Nod
) = N_Accept_Statement
then
3645 Nam
:= Entry_Direct_Name
(Nod
);
3647 -- For an entry call, the prefix of the call is a selected component.
3648 -- Need additional code for internal calls ???
3650 elsif Nkind
(Nod
) = N_Entry_Call_Statement
then
3651 if Nkind
(Name
(Nod
)) = N_Selected_Component
then
3652 Nam
:= Entity
(Selector_Name
(Name
(Nod
)));
3661 if Nkind
(Nam
) = N_Explicit_Dereference
then
3662 Proc
:= Etype
(Prefix
(Nam
));
3663 elsif Is_Entity_Name
(Nam
) then
3664 Proc
:= Entity
(Nam
);
3669 if Is_Object
(Proc
) then
3670 Proc
:= Etype
(Proc
);
3673 if Ekind
(Proc
) = E_Access_Subprogram_Type
then
3674 Proc
:= Directly_Designated_Type
(Proc
);
3677 if not Is_Subprogram
(Proc
)
3678 and then Ekind
(Proc
) /= E_Subprogram_Type
3684 end Get_Subprogram_Entity
;
3686 -----------------------------
3687 -- Get_Task_Body_Procedure --
3688 -----------------------------
3690 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
3692 -- Note: A task type may be the completion of a private type with
3693 -- discriminants. When performing elaboration checks on a task
3694 -- declaration, the current view of the type may be the private one,
3695 -- and the procedure that holds the body of the task is held in its
3698 -- This is an odd function, why not have Task_Body_Procedure do
3699 -- the following digging???
3701 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
3702 end Get_Task_Body_Procedure
;
3704 -----------------------
3705 -- Has_Access_Values --
3706 -----------------------
3708 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
3709 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
3712 -- Case of a private type which is not completed yet. This can only
3713 -- happen in the case of a generic format type appearing directly, or
3714 -- as a component of the type to which this function is being applied
3715 -- at the top level. Return False in this case, since we certainly do
3716 -- not know that the type contains access types.
3721 elsif Is_Access_Type
(Typ
) then
3724 elsif Is_Array_Type
(Typ
) then
3725 return Has_Access_Values
(Component_Type
(Typ
));
3727 elsif Is_Record_Type
(Typ
) then
3732 -- Loop to Check components
3734 Comp
:= First_Component_Or_Discriminant
(Typ
);
3735 while Present
(Comp
) loop
3737 -- Check for access component, tag field does not count, even
3738 -- though it is implemented internally using an access type.
3740 if Has_Access_Values
(Etype
(Comp
))
3741 and then Chars
(Comp
) /= Name_uTag
3746 Next_Component_Or_Discriminant
(Comp
);
3755 end Has_Access_Values
;
3757 ------------------------------
3758 -- Has_Compatible_Alignment --
3759 ------------------------------
3761 function Has_Compatible_Alignment
3763 Expr
: Node_Id
) return Alignment_Result
3765 function Has_Compatible_Alignment_Internal
3768 Default
: Alignment_Result
) return Alignment_Result
;
3769 -- This is the internal recursive function that actually does the work.
3770 -- There is one additional parameter, which says what the result should
3771 -- be if no alignment information is found, and there is no definite
3772 -- indication of compatible alignments. At the outer level, this is set
3773 -- to Unknown, but for internal recursive calls in the case where types
3774 -- are known to be correct, it is set to Known_Compatible.
3776 ---------------------------------------
3777 -- Has_Compatible_Alignment_Internal --
3778 ---------------------------------------
3780 function Has_Compatible_Alignment_Internal
3783 Default
: Alignment_Result
) return Alignment_Result
3785 Result
: Alignment_Result
:= Known_Compatible
;
3786 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3787 -- Note that once a value of Known_Incompatible is set, it is sticky
3788 -- and does not get changed to Unknown (the value in Result only gets
3789 -- worse as we go along, never better).
3791 procedure Check_Offset
(Offs
: Uint
);
3792 -- Called when Expr is a selected or indexed component with Offs set
3793 -- to resp Component_First_Bit or Component_Size. Checks that if the
3794 -- offset is specified it is compatible with the object alignment
3795 -- requirements. The value in Result is modified accordingly.
3797 procedure Check_Prefix
;
3798 -- Checks the prefix recursively in the case where the expression
3799 -- is an indexed or selected component.
3801 procedure Set_Result
(R
: Alignment_Result
);
3802 -- If R represents a worse outcome (unknown instead of known
3803 -- compatible, or known incompatible), then set Result to R.
3809 procedure Check_Offset
(Offs
: Uint
) is
3811 -- Unspecified or zero offset is always OK
3813 if Offs
= No_Uint
or else Offs
= Uint_0
then
3816 -- If we do not know required alignment, any non-zero offset is
3817 -- a potential problem (but certainly may be OK, so result is
3820 elsif Unknown_Alignment
(Obj
) then
3821 Set_Result
(Unknown
);
3823 -- If we know the required alignment, see if offset is compatible
3826 if Offs
mod (System_Storage_Unit
* Alignment
(Obj
)) /= 0 then
3827 Set_Result
(Known_Incompatible
);
3836 procedure Check_Prefix
is
3838 -- The subtlety here is that in doing a recursive call to check
3839 -- the prefix, we have to decide what to do in the case where we
3840 -- don't find any specific indication of an alignment problem.
3842 -- At the outer level, we normally set Unknown as the result in
3843 -- this case, since we can only set Known_Compatible if we really
3844 -- know that the alignment value is OK, but for the recursive
3845 -- call, in the case where the types match, and we have not
3846 -- specified a peculiar alignment for the object, we are only
3847 -- concerned about suspicious rep clauses, the default case does
3848 -- not affect us, since the compiler will, in the absence of such
3849 -- rep clauses, ensure that the alignment is correct.
3851 if Default
= Known_Compatible
3853 (Etype
(Obj
) = Etype
(Expr
)
3854 and then (Unknown_Alignment
(Obj
)
3856 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
3859 (Has_Compatible_Alignment_Internal
3860 (Obj
, Prefix
(Expr
), Known_Compatible
));
3862 -- In all other cases, we need a full check on the prefix
3866 (Has_Compatible_Alignment_Internal
3867 (Obj
, Prefix
(Expr
), Unknown
));
3875 procedure Set_Result
(R
: Alignment_Result
) is
3882 -- Start of processing for Has_Compatible_Alignment_Internal
3885 -- If Expr is a selected component, we must make sure there is no
3886 -- potentially troublesome component clause, and that the record is
3889 if Nkind
(Expr
) = N_Selected_Component
then
3891 -- Packed record always generate unknown alignment
3893 if Is_Packed
(Etype
(Prefix
(Expr
))) then
3894 Set_Result
(Unknown
);
3897 -- Check possible bad component offset and check prefix
3900 (Component_Bit_Offset
(Entity
(Selector_Name
(Expr
))));
3903 -- If Expr is an indexed component, we must make sure there is no
3904 -- potentially troublesome Component_Size clause and that the array
3905 -- is not bit-packed.
3907 elsif Nkind
(Expr
) = N_Indexed_Component
then
3909 -- Bit packed array always generates unknown alignment
3911 if Is_Bit_Packed_Array
(Etype
(Prefix
(Expr
))) then
3912 Set_Result
(Unknown
);
3915 -- Check possible bad component size and check prefix
3917 Check_Offset
(Component_Size
(Etype
(Prefix
(Expr
))));
3921 -- Case where we know the alignment of the object
3923 if Known_Alignment
(Obj
) then
3925 ObjA
: constant Uint
:= Alignment
(Obj
);
3926 ExpA
: Uint
:= No_Uint
;
3927 SizA
: Uint
:= No_Uint
;
3930 -- If alignment of Obj is 1, then we are always OK
3933 Set_Result
(Known_Compatible
);
3935 -- Alignment of Obj is greater than 1, so we need to check
3938 -- See if Expr is an object with known alignment
3940 if Is_Entity_Name
(Expr
)
3941 and then Known_Alignment
(Entity
(Expr
))
3943 ExpA
:= Alignment
(Entity
(Expr
));
3945 -- Otherwise, we can use the alignment of the type of
3946 -- Expr given that we already checked for
3947 -- discombobulating rep clauses for the cases of indexed
3948 -- and selected components above.
3950 elsif Known_Alignment
(Etype
(Expr
)) then
3951 ExpA
:= Alignment
(Etype
(Expr
));
3954 -- If we got an alignment, see if it is acceptable
3956 if ExpA
/= No_Uint
then
3958 Set_Result
(Known_Incompatible
);
3961 -- Case of Expr alignment unknown
3964 Set_Result
(Default
);
3967 -- See if size is given. If so, check that it is not too
3968 -- small for the required alignment.
3969 -- See if Expr is an object with known alignment
3971 if Is_Entity_Name
(Expr
)
3972 and then Known_Static_Esize
(Entity
(Expr
))
3974 SizA
:= Esize
(Entity
(Expr
));
3976 -- Otherwise, we check the object size of the Expr type
3978 elsif Known_Static_Esize
(Etype
(Expr
)) then
3979 SizA
:= Esize
(Etype
(Expr
));
3982 -- If we got a size, see if it is a multiple of the Obj
3983 -- alignment, if not, then the alignment cannot be
3984 -- acceptable, since the size is always a multiple of the
3987 if SizA
/= No_Uint
then
3988 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
3989 Set_Result
(Known_Incompatible
);
3995 -- If we can't find the result by direct comparison of alignment
3996 -- values, then there is still one case that we can determine known
3997 -- result, and that is when we can determine that the types are the
3998 -- same, and no alignments are specified. Then we known that the
3999 -- alignments are compatible, even if we don't know the alignment
4000 -- value in the front end.
4002 elsif Etype
(Obj
) = Etype
(Expr
) then
4004 -- Types are the same, but we have to check for possible size
4005 -- and alignments on the Expr object that may make the alignment
4006 -- different, even though the types are the same.
4008 if Is_Entity_Name
(Expr
) then
4010 -- First check alignment of the Expr object. Any alignment less
4011 -- than Maximum_Alignment is worrisome since this is the case
4012 -- where we do not know the alignment of Obj.
4014 if Known_Alignment
(Entity
(Expr
))
4016 UI_To_Int
(Alignment
(Entity
(Expr
)))
4017 < Ttypes
.Maximum_Alignment
4019 Set_Result
(Unknown
);
4021 -- Now check size of Expr object. Any size that is not an
4022 -- even multiple of Maximum_Alignment is also worrisome
4023 -- since it may cause the alignment of the object to be less
4024 -- than the alignment of the type.
4026 elsif Known_Static_Esize
(Entity
(Expr
))
4028 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
4029 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
4032 Set_Result
(Unknown
);
4034 -- Otherwise same type is decisive
4037 Set_Result
(Known_Compatible
);
4041 -- Another case to deal with is when there is an explicit size or
4042 -- alignment clause when the types are not the same. If so, then the
4043 -- result is Unknown. We don't need to do this test if the Default is
4044 -- Unknown, since that result will be set in any case.
4046 elsif Default
/= Unknown
4047 and then (Has_Size_Clause
(Etype
(Expr
))
4049 Has_Alignment_Clause
(Etype
(Expr
)))
4051 Set_Result
(Unknown
);
4053 -- If no indication found, set default
4056 Set_Result
(Default
);
4059 -- Return worst result found
4062 end Has_Compatible_Alignment_Internal
;
4064 -- Start of processing for Has_Compatible_Alignment
4067 -- If Obj has no specified alignment, then set alignment from the type
4068 -- alignment. Perhaps we should always do this, but for sure we should
4069 -- do it when there is an address clause since we can do more if the
4070 -- alignment is known.
4072 if Unknown_Alignment
(Obj
) then
4073 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
4076 -- Now do the internal call that does all the work
4078 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
4079 end Has_Compatible_Alignment
;
4081 ----------------------
4082 -- Has_Declarations --
4083 ----------------------
4085 function Has_Declarations
(N
: Node_Id
) return Boolean is
4086 K
: constant Node_Kind
:= Nkind
(N
);
4088 return K
= N_Accept_Statement
4089 or else K
= N_Block_Statement
4090 or else K
= N_Compilation_Unit_Aux
4091 or else K
= N_Entry_Body
4092 or else K
= N_Package_Body
4093 or else K
= N_Protected_Body
4094 or else K
= N_Subprogram_Body
4095 or else K
= N_Task_Body
4096 or else K
= N_Package_Specification
;
4097 end Has_Declarations
;
4099 -------------------------------------------
4100 -- Has_Discriminant_Dependent_Constraint --
4101 -------------------------------------------
4103 function Has_Discriminant_Dependent_Constraint
4104 (Comp
: Entity_Id
) return Boolean
4106 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
4107 Subt_Indic
: constant Node_Id
:=
4108 Subtype_Indication
(Component_Definition
(Comp_Decl
));
4113 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
4114 Constr
:= Constraint
(Subt_Indic
);
4116 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
4117 Assn
:= First
(Constraints
(Constr
));
4118 while Present
(Assn
) loop
4119 case Nkind
(Assn
) is
4120 when N_Subtype_Indication |
4124 if Depends_On_Discriminant
(Assn
) then
4128 when N_Discriminant_Association
=>
4129 if Depends_On_Discriminant
(Expression
(Assn
)) then
4144 end Has_Discriminant_Dependent_Constraint
;
4146 --------------------
4147 -- Has_Infinities --
4148 --------------------
4150 function Has_Infinities
(E
: Entity_Id
) return Boolean is
4153 Is_Floating_Point_Type
(E
)
4154 and then Nkind
(Scalar_Range
(E
)) = N_Range
4155 and then Includes_Infinities
(Scalar_Range
(E
));
4158 --------------------
4159 -- Has_Interfaces --
4160 --------------------
4162 function Has_Interfaces
4164 Use_Full_View
: Boolean := True) return Boolean
4169 -- Handle concurrent types
4171 if Is_Concurrent_Type
(T
) then
4172 Typ
:= Corresponding_Record_Type
(T
);
4177 if not Present
(Typ
)
4178 or else not Is_Record_Type
(Typ
)
4179 or else not Is_Tagged_Type
(Typ
)
4184 -- Handle private types
4187 and then Present
(Full_View
(Typ
))
4189 Typ
:= Full_View
(Typ
);
4192 -- Handle concurrent record types
4194 if Is_Concurrent_Record_Type
(Typ
)
4195 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
4201 if Is_Interface
(Typ
)
4203 (Is_Record_Type
(Typ
)
4204 and then Present
(Interfaces
(Typ
))
4205 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
4210 exit when Etype
(Typ
) = Typ
4212 -- Handle private types
4214 or else (Present
(Full_View
(Etype
(Typ
)))
4215 and then Full_View
(Etype
(Typ
)) = Typ
)
4217 -- Protect the frontend against wrong source with cyclic
4220 or else Etype
(Typ
) = T
;
4222 -- Climb to the ancestor type handling private types
4224 if Present
(Full_View
(Etype
(Typ
))) then
4225 Typ
:= Full_View
(Etype
(Typ
));
4234 ------------------------
4235 -- Has_Null_Exclusion --
4236 ------------------------
4238 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
4241 when N_Access_Definition |
4242 N_Access_Function_Definition |
4243 N_Access_Procedure_Definition |
4244 N_Access_To_Object_Definition |
4246 N_Derived_Type_Definition |
4247 N_Function_Specification |
4248 N_Subtype_Declaration
=>
4249 return Null_Exclusion_Present
(N
);
4251 when N_Component_Definition |
4252 N_Formal_Object_Declaration |
4253 N_Object_Renaming_Declaration
=>
4254 if Present
(Subtype_Mark
(N
)) then
4255 return Null_Exclusion_Present
(N
);
4256 else pragma Assert
(Present
(Access_Definition
(N
)));
4257 return Null_Exclusion_Present
(Access_Definition
(N
));
4260 when N_Discriminant_Specification
=>
4261 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
4262 return Null_Exclusion_Present
(Discriminant_Type
(N
));
4264 return Null_Exclusion_Present
(N
);
4267 when N_Object_Declaration
=>
4268 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
4269 return Null_Exclusion_Present
(Object_Definition
(N
));
4271 return Null_Exclusion_Present
(N
);
4274 when N_Parameter_Specification
=>
4275 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
4276 return Null_Exclusion_Present
(Parameter_Type
(N
));
4278 return Null_Exclusion_Present
(N
);
4285 end Has_Null_Exclusion
;
4287 ------------------------
4288 -- Has_Null_Extension --
4289 ------------------------
4291 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
4292 B
: constant Entity_Id
:= Base_Type
(T
);
4297 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
4298 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
4300 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
4302 if Present
(Ext
) then
4303 if Null_Present
(Ext
) then
4306 Comps
:= Component_List
(Ext
);
4308 -- The null component list is rewritten during analysis to
4309 -- include the parent component. Any other component indicates
4310 -- that the extension was not originally null.
4312 return Null_Present
(Comps
)
4313 or else No
(Next
(First
(Component_Items
(Comps
))));
4322 end Has_Null_Extension
;
4324 -------------------------------
4325 -- Has_Overriding_Initialize --
4326 -------------------------------
4328 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
4329 BT
: constant Entity_Id
:= Base_Type
(T
);
4334 if Is_Controlled
(BT
) then
4336 -- For derived types, check immediate ancestor, excluding
4337 -- Controlled itself.
4339 if Is_Derived_Type
(BT
)
4340 and then not In_Predefined_Unit
(Etype
(BT
))
4341 and then Has_Overriding_Initialize
(Etype
(BT
))
4345 elsif Present
(Primitive_Operations
(BT
)) then
4346 P
:= First_Elmt
(Primitive_Operations
(BT
));
4347 while Present
(P
) loop
4348 if Chars
(Node
(P
)) = Name_Initialize
4349 and then Comes_From_Source
(Node
(P
))
4360 elsif Has_Controlled_Component
(BT
) then
4361 Comp
:= First_Component
(BT
);
4362 while Present
(Comp
) loop
4363 if Has_Overriding_Initialize
(Etype
(Comp
)) then
4367 Next_Component
(Comp
);
4375 end Has_Overriding_Initialize
;
4377 --------------------------------------
4378 -- Has_Preelaborable_Initialization --
4379 --------------------------------------
4381 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
4384 procedure Check_Components
(E
: Entity_Id
);
4385 -- Check component/discriminant chain, sets Has_PE False if a component
4386 -- or discriminant does not meet the preelaborable initialization rules.
4388 ----------------------
4389 -- Check_Components --
4390 ----------------------
4392 procedure Check_Components
(E
: Entity_Id
) is
4396 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
4397 -- Returns True if and only if the expression denoted by N does not
4398 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4400 ---------------------------------
4401 -- Is_Preelaborable_Expression --
4402 ---------------------------------
4404 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
4408 Comp_Type
: Entity_Id
;
4409 Is_Array_Aggr
: Boolean;
4412 if Is_Static_Expression
(N
) then
4415 elsif Nkind
(N
) = N_Null
then
4418 -- Attributes are allowed in general, even if their prefix is a
4419 -- formal type. (It seems that certain attributes known not to be
4420 -- static might not be allowed, but there are no rules to prevent
4423 elsif Nkind
(N
) = N_Attribute_Reference
then
4426 -- The name of a discriminant evaluated within its parent type is
4427 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4428 -- names that denote discriminals as well as discriminants to
4429 -- catch references occurring within init procs.
4431 elsif Is_Entity_Name
(N
)
4433 (Ekind
(Entity
(N
)) = E_Discriminant
4435 ((Ekind
(Entity
(N
)) = E_Constant
4436 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
4437 and then Present
(Discriminal_Link
(Entity
(N
)))))
4441 elsif Nkind
(N
) = N_Qualified_Expression
then
4442 return Is_Preelaborable_Expression
(Expression
(N
));
4444 -- For aggregates we have to check that each of the associations
4445 -- is preelaborable.
4447 elsif Nkind
(N
) = N_Aggregate
4448 or else Nkind
(N
) = N_Extension_Aggregate
4450 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
4452 if Is_Array_Aggr
then
4453 Comp_Type
:= Component_Type
(Etype
(N
));
4456 -- Check the ancestor part of extension aggregates, which must
4457 -- be either the name of a type that has preelaborable init or
4458 -- an expression that is preelaborable.
4460 if Nkind
(N
) = N_Extension_Aggregate
then
4462 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
4465 if Is_Entity_Name
(Anc_Part
)
4466 and then Is_Type
(Entity
(Anc_Part
))
4468 if not Has_Preelaborable_Initialization
4474 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
4480 -- Check positional associations
4482 Exp
:= First
(Expressions
(N
));
4483 while Present
(Exp
) loop
4484 if not Is_Preelaborable_Expression
(Exp
) then
4491 -- Check named associations
4493 Assn
:= First
(Component_Associations
(N
));
4494 while Present
(Assn
) loop
4495 Choice
:= First
(Choices
(Assn
));
4496 while Present
(Choice
) loop
4497 if Is_Array_Aggr
then
4498 if Nkind
(Choice
) = N_Others_Choice
then
4501 elsif Nkind
(Choice
) = N_Range
then
4502 if not Is_Static_Range
(Choice
) then
4506 elsif not Is_Static_Expression
(Choice
) then
4511 Comp_Type
:= Etype
(Choice
);
4517 -- If the association has a <> at this point, then we have
4518 -- to check whether the component's type has preelaborable
4519 -- initialization. Note that this only occurs when the
4520 -- association's corresponding component does not have a
4521 -- default expression, the latter case having already been
4522 -- expanded as an expression for the association.
4524 if Box_Present
(Assn
) then
4525 if not Has_Preelaborable_Initialization
(Comp_Type
) then
4529 -- In the expression case we check whether the expression
4530 -- is preelaborable.
4533 not Is_Preelaborable_Expression
(Expression
(Assn
))
4541 -- If we get here then aggregate as a whole is preelaborable
4545 -- All other cases are not preelaborable
4550 end Is_Preelaborable_Expression
;
4552 -- Start of processing for Check_Components
4555 -- Loop through entities of record or protected type
4558 while Present
(Ent
) loop
4560 -- We are interested only in components and discriminants
4562 if Ekind
(Ent
) = E_Component
4564 Ekind
(Ent
) = E_Discriminant
4566 -- Get default expression if any. If there is no declaration
4567 -- node, it means we have an internal entity. The parent and
4568 -- tag fields are examples of such entities. For these cases,
4569 -- we just test the type of the entity.
4571 if Present
(Declaration_Node
(Ent
)) then
4572 Exp
:= Expression
(Declaration_Node
(Ent
));
4577 -- A component has PI if it has no default expression and the
4578 -- component type has PI.
4581 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
4586 -- Require the default expression to be preelaborable
4588 elsif not Is_Preelaborable_Expression
(Exp
) then
4596 end Check_Components
;
4598 -- Start of processing for Has_Preelaborable_Initialization
4601 -- Immediate return if already marked as known preelaborable init. This
4602 -- covers types for which this function has already been called once
4603 -- and returned True (in which case the result is cached), and also
4604 -- types to which a pragma Preelaborable_Initialization applies.
4606 if Known_To_Have_Preelab_Init
(E
) then
4610 -- If the type is a subtype representing a generic actual type, then
4611 -- test whether its base type has preelaborable initialization since
4612 -- the subtype representing the actual does not inherit this attribute
4613 -- from the actual or formal. (but maybe it should???)
4615 if Is_Generic_Actual_Type
(E
) then
4616 return Has_Preelaborable_Initialization
(Base_Type
(E
));
4619 -- Other private types never have preelaborable initialization
4621 if Is_Private_Type
(E
) then
4625 -- Here for all non-private view
4627 -- All elementary types have preelaborable initialization
4629 if Is_Elementary_Type
(E
) then
4632 -- Array types have PI if the component type has PI
4634 elsif Is_Array_Type
(E
) then
4635 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
4637 -- A derived type has preelaborable initialization if its parent type
4638 -- has preelaborable initialization and (in the case of a derived record
4639 -- extension) if the non-inherited components all have preelaborable
4640 -- initialization. However, a user-defined controlled type with an
4641 -- overriding Initialize procedure does not have preelaborable
4644 elsif Is_Derived_Type
(E
) then
4646 -- First check whether ancestor type has preelaborable initialization
4648 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
4650 -- If OK, check extension components (if any)
4652 if Has_PE
and then Is_Record_Type
(E
) then
4653 Check_Components
(First_Entity
(E
));
4656 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
4657 -- with a user defined Initialize procedure does not have PI.
4660 and then Is_Controlled
(E
)
4661 and then Has_Overriding_Initialize
(E
)
4666 -- Record type has PI if it is non private and all components have PI
4668 elsif Is_Record_Type
(E
) then
4670 Check_Components
(First_Entity
(E
));
4672 -- Protected types must not have entries, and components must meet
4673 -- same set of rules as for record components.
4675 elsif Is_Protected_Type
(E
) then
4676 if Has_Entries
(E
) then
4680 Check_Components
(First_Entity
(E
));
4681 Check_Components
(First_Private_Entity
(E
));
4684 -- Type System.Address always has preelaborable initialization
4686 elsif Is_RTE
(E
, RE_Address
) then
4689 -- In all other cases, type does not have preelaborable initialization
4695 -- If type has preelaborable initialization, cache result
4698 Set_Known_To_Have_Preelab_Init
(E
);
4702 end Has_Preelaborable_Initialization
;
4704 ---------------------------
4705 -- Has_Private_Component --
4706 ---------------------------
4708 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
4709 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
4710 Component
: Entity_Id
;
4713 if Error_Posted
(Type_Id
)
4714 or else Error_Posted
(Btype
)
4719 if Is_Class_Wide_Type
(Btype
) then
4720 Btype
:= Root_Type
(Btype
);
4723 if Is_Private_Type
(Btype
) then
4725 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
4728 if No
(Full_View
(Btype
)) then
4729 return not Is_Generic_Type
(Btype
)
4730 and then not Is_Generic_Type
(Root_Type
(Btype
));
4732 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
4735 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
4739 elsif Is_Array_Type
(Btype
) then
4740 return Has_Private_Component
(Component_Type
(Btype
));
4742 elsif Is_Record_Type
(Btype
) then
4743 Component
:= First_Component
(Btype
);
4744 while Present
(Component
) loop
4745 if Has_Private_Component
(Etype
(Component
)) then
4749 Next_Component
(Component
);
4754 elsif Is_Protected_Type
(Btype
)
4755 and then Present
(Corresponding_Record_Type
(Btype
))
4757 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
4762 end Has_Private_Component
;
4768 function Has_Stream
(T
: Entity_Id
) return Boolean is
4775 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
4778 elsif Is_Array_Type
(T
) then
4779 return Has_Stream
(Component_Type
(T
));
4781 elsif Is_Record_Type
(T
) then
4782 E
:= First_Component
(T
);
4783 while Present
(E
) loop
4784 if Has_Stream
(Etype
(E
)) then
4793 elsif Is_Private_Type
(T
) then
4794 return Has_Stream
(Underlying_Type
(T
));
4801 --------------------------
4802 -- Has_Tagged_Component --
4803 --------------------------
4805 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
4809 if Is_Private_Type
(Typ
)
4810 and then Present
(Underlying_Type
(Typ
))
4812 return Has_Tagged_Component
(Underlying_Type
(Typ
));
4814 elsif Is_Array_Type
(Typ
) then
4815 return Has_Tagged_Component
(Component_Type
(Typ
));
4817 elsif Is_Tagged_Type
(Typ
) then
4820 elsif Is_Record_Type
(Typ
) then
4821 Comp
:= First_Component
(Typ
);
4822 while Present
(Comp
) loop
4823 if Has_Tagged_Component
(Etype
(Comp
)) then
4827 Comp
:= Next_Component
(Typ
);
4835 end Has_Tagged_Component
;
4837 --------------------------
4838 -- Implements_Interface --
4839 --------------------------
4841 function Implements_Interface
4842 (Typ_Ent
: Entity_Id
;
4843 Iface_Ent
: Entity_Id
;
4844 Exclude_Parents
: Boolean := False) return Boolean
4846 Ifaces_List
: Elist_Id
;
4852 if Is_Class_Wide_Type
(Typ_Ent
) then
4853 Typ
:= Etype
(Typ_Ent
);
4858 if Is_Class_Wide_Type
(Iface_Ent
) then
4859 Iface
:= Etype
(Iface_Ent
);
4864 if not Has_Interfaces
(Typ
) then
4868 Collect_Interfaces
(Typ
, Ifaces_List
);
4870 Elmt
:= First_Elmt
(Ifaces_List
);
4871 while Present
(Elmt
) loop
4872 if Is_Ancestor
(Node
(Elmt
), Typ
)
4873 and then Exclude_Parents
4877 elsif Node
(Elmt
) = Iface
then
4885 end Implements_Interface
;
4891 function In_Instance
return Boolean is
4892 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
4898 and then S
/= Standard_Standard
4900 if (Ekind
(S
) = E_Function
4901 or else Ekind
(S
) = E_Package
4902 or else Ekind
(S
) = E_Procedure
)
4903 and then Is_Generic_Instance
(S
)
4905 -- A child instance is always compiled in the context of a parent
4906 -- instance. Nevertheless, the actuals are not analyzed in an
4907 -- instance context. We detect this case by examining the current
4908 -- compilation unit, which must be a child instance, and checking
4909 -- that it is not currently on the scope stack.
4911 if Is_Child_Unit
(Curr_Unit
)
4913 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
4914 = N_Package_Instantiation
4915 and then not In_Open_Scopes
(Curr_Unit
)
4929 ----------------------
4930 -- In_Instance_Body --
4931 ----------------------
4933 function In_Instance_Body
return Boolean is
4939 and then S
/= Standard_Standard
4941 if (Ekind
(S
) = E_Function
4942 or else Ekind
(S
) = E_Procedure
)
4943 and then Is_Generic_Instance
(S
)
4947 elsif Ekind
(S
) = E_Package
4948 and then In_Package_Body
(S
)
4949 and then Is_Generic_Instance
(S
)
4958 end In_Instance_Body
;
4960 -----------------------------
4961 -- In_Instance_Not_Visible --
4962 -----------------------------
4964 function In_Instance_Not_Visible
return Boolean is
4970 and then S
/= Standard_Standard
4972 if (Ekind
(S
) = E_Function
4973 or else Ekind
(S
) = E_Procedure
)
4974 and then Is_Generic_Instance
(S
)
4978 elsif Ekind
(S
) = E_Package
4979 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
4980 and then Is_Generic_Instance
(S
)
4989 end In_Instance_Not_Visible
;
4991 ------------------------------
4992 -- In_Instance_Visible_Part --
4993 ------------------------------
4995 function In_Instance_Visible_Part
return Boolean is
5001 and then S
/= Standard_Standard
5003 if Ekind
(S
) = E_Package
5004 and then Is_Generic_Instance
(S
)
5005 and then not In_Package_Body
(S
)
5006 and then not In_Private_Part
(S
)
5015 end In_Instance_Visible_Part
;
5017 ---------------------
5018 -- In_Package_Body --
5019 ---------------------
5021 function In_Package_Body
return Boolean is
5027 and then S
/= Standard_Standard
5029 if Ekind
(S
) = E_Package
5030 and then In_Package_Body
(S
)
5039 end In_Package_Body
;
5041 --------------------------------
5042 -- In_Parameter_Specification --
5043 --------------------------------
5045 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
5050 while Present
(PN
) loop
5051 if Nkind
(PN
) = N_Parameter_Specification
then
5059 end In_Parameter_Specification
;
5061 --------------------------------------
5062 -- In_Subprogram_Or_Concurrent_Unit --
5063 --------------------------------------
5065 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
5070 -- Use scope chain to check successively outer scopes
5076 if K
in Subprogram_Kind
5077 or else K
in Concurrent_Kind
5078 or else K
in Generic_Subprogram_Kind
5082 elsif E
= Standard_Standard
then
5088 end In_Subprogram_Or_Concurrent_Unit
;
5090 ---------------------
5091 -- In_Visible_Part --
5092 ---------------------
5094 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
5097 Is_Package_Or_Generic_Package
(Scope_Id
)
5098 and then In_Open_Scopes
(Scope_Id
)
5099 and then not In_Package_Body
(Scope_Id
)
5100 and then not In_Private_Part
(Scope_Id
);
5101 end In_Visible_Part
;
5103 ---------------------------------
5104 -- Insert_Explicit_Dereference --
5105 ---------------------------------
5107 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
5108 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
5109 Ent
: Entity_Id
:= Empty
;
5116 Save_Interps
(N
, New_Prefix
);
5118 Make_Explicit_Dereference
(Sloc
(N
),
5119 Prefix
=> New_Prefix
));
5121 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
5123 if Is_Overloaded
(New_Prefix
) then
5125 -- The deference is also overloaded, and its interpretations are the
5126 -- designated types of the interpretations of the original node.
5128 Set_Etype
(N
, Any_Type
);
5130 Get_First_Interp
(New_Prefix
, I
, It
);
5131 while Present
(It
.Nam
) loop
5134 if Is_Access_Type
(T
) then
5135 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
5138 Get_Next_Interp
(I
, It
);
5144 -- Prefix is unambiguous: mark the original prefix (which might
5145 -- Come_From_Source) as a reference, since the new (relocated) one
5146 -- won't be taken into account.
5148 if Is_Entity_Name
(New_Prefix
) then
5149 Ent
:= Entity
(New_Prefix
);
5151 -- For a retrieval of a subcomponent of some composite object,
5152 -- retrieve the ultimate entity if there is one.
5154 elsif Nkind
(New_Prefix
) = N_Selected_Component
5155 or else Nkind
(New_Prefix
) = N_Indexed_Component
5157 Pref
:= Prefix
(New_Prefix
);
5158 while Present
(Pref
)
5160 (Nkind
(Pref
) = N_Selected_Component
5161 or else Nkind
(Pref
) = N_Indexed_Component
)
5163 Pref
:= Prefix
(Pref
);
5166 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
5167 Ent
:= Entity
(Pref
);
5171 if Present
(Ent
) then
5172 Generate_Reference
(Ent
, New_Prefix
);
5175 end Insert_Explicit_Dereference
;
5177 ------------------------------------------
5178 -- Inspect_Deferred_Constant_Completion --
5179 ------------------------------------------
5181 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
5185 Decl
:= First
(Decls
);
5186 while Present
(Decl
) loop
5188 -- Deferred constant signature
5190 if Nkind
(Decl
) = N_Object_Declaration
5191 and then Constant_Present
(Decl
)
5192 and then No
(Expression
(Decl
))
5194 -- No need to check internally generated constants
5196 and then Comes_From_Source
(Decl
)
5198 -- The constant is not completed. A full object declaration
5199 -- or a pragma Import complete a deferred constant.
5201 and then not Has_Completion
(Defining_Identifier
(Decl
))
5204 ("constant declaration requires initialization expression",
5205 Defining_Identifier
(Decl
));
5208 Decl
:= Next
(Decl
);
5210 end Inspect_Deferred_Constant_Completion
;
5216 function Is_AAMP_Float
(E
: Entity_Id
) return Boolean is
5217 pragma Assert
(Is_Type
(E
));
5219 return AAMP_On_Target
5220 and then Is_Floating_Point_Type
(E
)
5221 and then E
= Base_Type
(E
);
5224 -------------------------
5225 -- Is_Actual_Parameter --
5226 -------------------------
5228 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
5229 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
5233 when N_Parameter_Association
=>
5234 return N
= Explicit_Actual_Parameter
(Parent
(N
));
5236 when N_Function_Call | N_Procedure_Call_Statement
=>
5237 return Is_List_Member
(N
)
5239 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
5244 end Is_Actual_Parameter
;
5246 ---------------------
5247 -- Is_Aliased_View --
5248 ---------------------
5250 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
5254 if Is_Entity_Name
(Obj
) then
5262 or else (Present
(Renamed_Object
(E
))
5263 and then Is_Aliased_View
(Renamed_Object
(E
)))))
5265 or else ((Is_Formal
(E
)
5266 or else Ekind
(E
) = E_Generic_In_Out_Parameter
5267 or else Ekind
(E
) = E_Generic_In_Parameter
)
5268 and then Is_Tagged_Type
(Etype
(E
)))
5270 or else (Is_Concurrent_Type
(E
)
5271 and then In_Open_Scopes
(E
))
5273 -- Current instance of type, either directly or as rewritten
5274 -- reference to the current object.
5276 or else (Is_Entity_Name
(Original_Node
(Obj
))
5277 and then Present
(Entity
(Original_Node
(Obj
)))
5278 and then Is_Type
(Entity
(Original_Node
(Obj
))))
5280 or else (Is_Type
(E
) and then E
= Current_Scope
)
5282 or else (Is_Incomplete_Or_Private_Type
(E
)
5283 and then Full_View
(E
) = Current_Scope
);
5285 elsif Nkind
(Obj
) = N_Selected_Component
then
5286 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
5288 elsif Nkind
(Obj
) = N_Indexed_Component
then
5289 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
5291 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
5293 Has_Aliased_Components
5294 (Designated_Type
(Etype
(Prefix
(Obj
)))));
5296 elsif Nkind
(Obj
) = N_Unchecked_Type_Conversion
5297 or else Nkind
(Obj
) = N_Type_Conversion
5299 return Is_Tagged_Type
(Etype
(Obj
))
5300 and then Is_Aliased_View
(Expression
(Obj
));
5302 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
5303 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
5308 end Is_Aliased_View
;
5310 -------------------------
5311 -- Is_Ancestor_Package --
5312 -------------------------
5314 function Is_Ancestor_Package
5316 E2
: Entity_Id
) return Boolean
5323 and then Par
/= Standard_Standard
5333 end Is_Ancestor_Package
;
5335 ----------------------
5336 -- Is_Atomic_Object --
5337 ----------------------
5339 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
5341 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
5342 -- Determines if given object has atomic components
5344 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
5345 -- If prefix is an implicit dereference, examine designated type
5347 ----------------------
5348 -- Is_Atomic_Prefix --
5349 ----------------------
5351 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
5353 if Is_Access_Type
(Etype
(N
)) then
5355 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
5357 return Object_Has_Atomic_Components
(N
);
5359 end Is_Atomic_Prefix
;
5361 ----------------------------------
5362 -- Object_Has_Atomic_Components --
5363 ----------------------------------
5365 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
5367 if Has_Atomic_Components
(Etype
(N
))
5368 or else Is_Atomic
(Etype
(N
))
5372 elsif Is_Entity_Name
(N
)
5373 and then (Has_Atomic_Components
(Entity
(N
))
5374 or else Is_Atomic
(Entity
(N
)))
5378 elsif Nkind
(N
) = N_Indexed_Component
5379 or else Nkind
(N
) = N_Selected_Component
5381 return Is_Atomic_Prefix
(Prefix
(N
));
5386 end Object_Has_Atomic_Components
;
5388 -- Start of processing for Is_Atomic_Object
5391 if Is_Atomic
(Etype
(N
))
5392 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
5396 elsif Nkind
(N
) = N_Indexed_Component
5397 or else Nkind
(N
) = N_Selected_Component
5399 return Is_Atomic_Prefix
(Prefix
(N
));
5404 end Is_Atomic_Object
;
5406 -------------------------
5407 -- Is_Coextension_Root --
5408 -------------------------
5410 function Is_Coextension_Root
(N
: Node_Id
) return Boolean is
5413 Nkind
(N
) = N_Allocator
5414 and then Present
(Coextensions
(N
))
5416 -- Anonymous access discriminants carry a list of all nested
5417 -- controlled coextensions.
5419 and then not Is_Dynamic_Coextension
(N
)
5420 and then not Is_Static_Coextension
(N
);
5421 end Is_Coextension_Root
;
5423 -----------------------------
5424 -- Is_Concurrent_Interface --
5425 -----------------------------
5427 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
5432 (Is_Protected_Interface
(T
)
5433 or else Is_Synchronized_Interface
(T
)
5434 or else Is_Task_Interface
(T
));
5435 end Is_Concurrent_Interface
;
5437 --------------------------------------
5438 -- Is_Controlling_Limited_Procedure --
5439 --------------------------------------
5441 function Is_Controlling_Limited_Procedure
5442 (Proc_Nam
: Entity_Id
) return Boolean
5444 Param_Typ
: Entity_Id
:= Empty
;
5447 if Ekind
(Proc_Nam
) = E_Procedure
5448 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
5450 Param_Typ
:= Etype
(Parameter_Type
(First
(
5451 Parameter_Specifications
(Parent
(Proc_Nam
)))));
5453 -- In this case where an Itype was created, the procedure call has been
5456 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
5457 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
5459 Present
(Parameter_Associations
5460 (Associated_Node_For_Itype
(Proc_Nam
)))
5463 Etype
(First
(Parameter_Associations
5464 (Associated_Node_For_Itype
(Proc_Nam
))));
5467 if Present
(Param_Typ
) then
5469 Is_Interface
(Param_Typ
)
5470 and then Is_Limited_Record
(Param_Typ
);
5474 end Is_Controlling_Limited_Procedure
;
5476 ----------------------------------------------
5477 -- Is_Dependent_Component_Of_Mutable_Object --
5478 ----------------------------------------------
5480 function Is_Dependent_Component_Of_Mutable_Object
5481 (Object
: Node_Id
) return Boolean
5484 Prefix_Type
: Entity_Id
;
5485 P_Aliased
: Boolean := False;
5488 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
5489 -- Returns True if and only if Comp is declared within a variant part
5491 --------------------------------
5492 -- Is_Declared_Within_Variant --
5493 --------------------------------
5495 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
5496 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
5497 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
5499 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
5500 end Is_Declared_Within_Variant
;
5502 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5505 if Is_Variable
(Object
) then
5507 if Nkind
(Object
) = N_Selected_Component
then
5508 P
:= Prefix
(Object
);
5509 Prefix_Type
:= Etype
(P
);
5511 if Is_Entity_Name
(P
) then
5513 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
5514 Prefix_Type
:= Base_Type
(Prefix_Type
);
5517 if Is_Aliased
(Entity
(P
)) then
5521 -- A discriminant check on a selected component may be
5522 -- expanded into a dereference when removing side-effects.
5523 -- Recover the original node and its type, which may be
5526 elsif Nkind
(P
) = N_Explicit_Dereference
5527 and then not (Comes_From_Source
(P
))
5529 P
:= Original_Node
(P
);
5530 Prefix_Type
:= Etype
(P
);
5533 -- Check for prefix being an aliased component ???
5538 -- A heap object is constrained by its initial value
5540 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5541 -- the dereferenced case, since the access value might denote an
5542 -- unconstrained aliased object, whereas in Ada 95 the designated
5543 -- object is guaranteed to be constrained. A worst-case assumption
5544 -- has to apply in Ada 2005 because we can't tell at compile time
5545 -- whether the object is "constrained by its initial value"
5546 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5547 -- semantic rules -- these rules are acknowledged to need fixing).
5549 if Ada_Version
< Ada_05
then
5550 if Is_Access_Type
(Prefix_Type
)
5551 or else Nkind
(P
) = N_Explicit_Dereference
5556 elsif Ada_Version
>= Ada_05
then
5557 if Is_Access_Type
(Prefix_Type
) then
5559 -- If the access type is pool-specific, and there is no
5560 -- constrained partial view of the designated type, then the
5561 -- designated object is known to be constrained.
5563 if Ekind
(Prefix_Type
) = E_Access_Type
5564 and then not Has_Constrained_Partial_View
5565 (Designated_Type
(Prefix_Type
))
5569 -- Otherwise (general access type, or there is a constrained
5570 -- partial view of the designated type), we need to check
5571 -- based on the designated type.
5574 Prefix_Type
:= Designated_Type
(Prefix_Type
);
5580 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
5582 -- As per AI-0017, the renaming is illegal in a generic body,
5583 -- even if the subtype is indefinite.
5585 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5587 if not Is_Constrained
(Prefix_Type
)
5588 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
5590 (Is_Generic_Type
(Prefix_Type
)
5591 and then Ekind
(Current_Scope
) = E_Generic_Package
5592 and then In_Package_Body
(Current_Scope
)))
5594 and then (Is_Declared_Within_Variant
(Comp
)
5595 or else Has_Discriminant_Dependent_Constraint
(Comp
))
5596 and then (not P_Aliased
or else Ada_Version
>= Ada_05
)
5602 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5606 elsif Nkind
(Object
) = N_Indexed_Component
5607 or else Nkind
(Object
) = N_Slice
5609 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5611 -- A type conversion that Is_Variable is a view conversion:
5612 -- go back to the denoted object.
5614 elsif Nkind
(Object
) = N_Type_Conversion
then
5616 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
5621 end Is_Dependent_Component_Of_Mutable_Object
;
5623 ---------------------
5624 -- Is_Dereferenced --
5625 ---------------------
5627 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
5628 P
: constant Node_Id
:= Parent
(N
);
5631 (Nkind
(P
) = N_Selected_Component
5633 Nkind
(P
) = N_Explicit_Dereference
5635 Nkind
(P
) = N_Indexed_Component
5637 Nkind
(P
) = N_Slice
)
5638 and then Prefix
(P
) = N
;
5639 end Is_Dereferenced
;
5641 ----------------------
5642 -- Is_Descendent_Of --
5643 ----------------------
5645 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
5650 pragma Assert
(Nkind
(T1
) in N_Entity
);
5651 pragma Assert
(Nkind
(T2
) in N_Entity
);
5653 T
:= Base_Type
(T1
);
5655 -- Immediate return if the types match
5660 -- Comment needed here ???
5662 elsif Ekind
(T
) = E_Class_Wide_Type
then
5663 return Etype
(T
) = T2
;
5671 -- Done if we found the type we are looking for
5676 -- Done if no more derivations to check
5683 -- Following test catches error cases resulting from prev errors
5685 elsif No
(Etyp
) then
5688 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
5691 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
5695 T
:= Base_Type
(Etyp
);
5698 end Is_Descendent_Of
;
5704 function Is_False
(U
: Uint
) return Boolean is
5709 ---------------------------
5710 -- Is_Fixed_Model_Number --
5711 ---------------------------
5713 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
5714 S
: constant Ureal
:= Small_Value
(T
);
5715 M
: Urealp
.Save_Mark
;
5719 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
5722 end Is_Fixed_Model_Number
;
5724 -------------------------------
5725 -- Is_Fully_Initialized_Type --
5726 -------------------------------
5728 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
5730 if Is_Scalar_Type
(Typ
) then
5733 elsif Is_Access_Type
(Typ
) then
5736 elsif Is_Array_Type
(Typ
) then
5737 if Is_Fully_Initialized_Type
(Component_Type
(Typ
)) then
5741 -- An interesting case, if we have a constrained type one of whose
5742 -- bounds is known to be null, then there are no elements to be
5743 -- initialized, so all the elements are initialized!
5745 if Is_Constrained
(Typ
) then
5748 Indx_Typ
: Entity_Id
;
5752 Indx
:= First_Index
(Typ
);
5753 while Present
(Indx
) loop
5754 if Etype
(Indx
) = Any_Type
then
5757 -- If index is a range, use directly
5759 elsif Nkind
(Indx
) = N_Range
then
5760 Lbd
:= Low_Bound
(Indx
);
5761 Hbd
:= High_Bound
(Indx
);
5764 Indx_Typ
:= Etype
(Indx
);
5766 if Is_Private_Type
(Indx_Typ
) then
5767 Indx_Typ
:= Full_View
(Indx_Typ
);
5770 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
5773 Lbd
:= Type_Low_Bound
(Indx_Typ
);
5774 Hbd
:= Type_High_Bound
(Indx_Typ
);
5778 if Compile_Time_Known_Value
(Lbd
)
5779 and then Compile_Time_Known_Value
(Hbd
)
5781 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
5791 -- If no null indexes, then type is not fully initialized
5797 elsif Is_Record_Type
(Typ
) then
5798 if Has_Discriminants
(Typ
)
5800 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
5801 and then Is_Fully_Initialized_Variant
(Typ
)
5806 -- Controlled records are considered to be fully initialized if
5807 -- there is a user defined Initialize routine. This may not be
5808 -- entirely correct, but as the spec notes, we are guessing here
5809 -- what is best from the point of view of issuing warnings.
5811 if Is_Controlled
(Typ
) then
5813 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5816 if Present
(Utyp
) then
5818 Init
: constant Entity_Id
:=
5820 (Underlying_Type
(Typ
), Name_Initialize
));
5824 and then Comes_From_Source
(Init
)
5826 Is_Predefined_File_Name
5827 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
5831 elsif Has_Null_Extension
(Typ
)
5833 Is_Fully_Initialized_Type
5834 (Etype
(Base_Type
(Typ
)))
5843 -- Otherwise see if all record components are initialized
5849 Ent
:= First_Entity
(Typ
);
5850 while Present
(Ent
) loop
5851 if Chars
(Ent
) = Name_uController
then
5854 elsif Ekind
(Ent
) = E_Component
5855 and then (No
(Parent
(Ent
))
5856 or else No
(Expression
(Parent
(Ent
))))
5857 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
5859 -- Special VM case for tag components, which need to be
5860 -- defined in this case, but are never initialized as VMs
5861 -- are using other dispatching mechanisms. Ignore this
5862 -- uninitialized case. Note that this applies both to the
5863 -- uTag entry and the main vtable pointer (CPP_Class case).
5865 and then (VM_Target
= No_VM
or else not Is_Tag
(Ent
))
5874 -- No uninitialized components, so type is fully initialized.
5875 -- Note that this catches the case of no components as well.
5879 elsif Is_Concurrent_Type
(Typ
) then
5882 elsif Is_Private_Type
(Typ
) then
5884 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5890 return Is_Fully_Initialized_Type
(U
);
5897 end Is_Fully_Initialized_Type
;
5899 ----------------------------------
5900 -- Is_Fully_Initialized_Variant --
5901 ----------------------------------
5903 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
5904 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5905 Constraints
: constant List_Id
:= New_List
;
5906 Components
: constant Elist_Id
:= New_Elmt_List
;
5907 Comp_Elmt
: Elmt_Id
;
5909 Comp_List
: Node_Id
;
5911 Discr_Val
: Node_Id
;
5913 Report_Errors
: Boolean;
5914 pragma Warnings
(Off
, Report_Errors
);
5917 if Serious_Errors_Detected
> 0 then
5921 if Is_Record_Type
(Typ
)
5922 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
5923 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
5925 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
5927 Discr
:= First_Discriminant
(Typ
);
5928 while Present
(Discr
) loop
5929 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
5930 Discr_Val
:= Expression
(Parent
(Discr
));
5932 if Present
(Discr_Val
)
5933 and then Is_OK_Static_Expression
(Discr_Val
)
5935 Append_To
(Constraints
,
5936 Make_Component_Association
(Loc
,
5937 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
5938 Expression
=> New_Copy
(Discr_Val
)));
5946 Next_Discriminant
(Discr
);
5951 Comp_List
=> Comp_List
,
5952 Governed_By
=> Constraints
,
5954 Report_Errors
=> Report_Errors
);
5956 -- Check that each component present is fully initialized
5958 Comp_Elmt
:= First_Elmt
(Components
);
5959 while Present
(Comp_Elmt
) loop
5960 Comp_Id
:= Node
(Comp_Elmt
);
5962 if Ekind
(Comp_Id
) = E_Component
5963 and then (No
(Parent
(Comp_Id
))
5964 or else No
(Expression
(Parent
(Comp_Id
))))
5965 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
5970 Next_Elmt
(Comp_Elmt
);
5975 elsif Is_Private_Type
(Typ
) then
5977 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5983 return Is_Fully_Initialized_Variant
(U
);
5989 end Is_Fully_Initialized_Variant
;
5991 ----------------------------
5992 -- Is_Inherited_Operation --
5993 ----------------------------
5995 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
5996 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
5998 pragma Assert
(Is_Overloadable
(E
));
5999 return Kind
= N_Full_Type_Declaration
6000 or else Kind
= N_Private_Extension_Declaration
6001 or else Kind
= N_Subtype_Declaration
6002 or else (Ekind
(E
) = E_Enumeration_Literal
6003 and then Is_Derived_Type
(Etype
(E
)));
6004 end Is_Inherited_Operation
;
6006 -----------------------------
6007 -- Is_Library_Level_Entity --
6008 -----------------------------
6010 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
6012 -- The following is a small optimization, and it also properly handles
6013 -- discriminals, which in task bodies might appear in expressions before
6014 -- the corresponding procedure has been created, and which therefore do
6015 -- not have an assigned scope.
6017 if Ekind
(E
) in Formal_Kind
then
6021 -- Normal test is simply that the enclosing dynamic scope is Standard
6023 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
6024 end Is_Library_Level_Entity
;
6026 ---------------------------------
6027 -- Is_Local_Variable_Reference --
6028 ---------------------------------
6030 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
6032 if not Is_Entity_Name
(Expr
) then
6037 Ent
: constant Entity_Id
:= Entity
(Expr
);
6038 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
6040 if Ekind
(Ent
) /= E_Variable
6042 Ekind
(Ent
) /= E_In_Out_Parameter
6046 return Present
(Sub
) and then Sub
= Current_Subprogram
;
6050 end Is_Local_Variable_Reference
;
6052 -------------------------
6053 -- Is_Object_Reference --
6054 -------------------------
6056 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
6058 if Is_Entity_Name
(N
) then
6059 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
6063 when N_Indexed_Component | N_Slice
=>
6065 Is_Object_Reference
(Prefix
(N
))
6066 or else Is_Access_Type
(Etype
(Prefix
(N
)));
6068 -- In Ada95, a function call is a constant object; a procedure
6071 when N_Function_Call
=>
6072 return Etype
(N
) /= Standard_Void_Type
;
6074 -- A reference to the stream attribute Input is a function call
6076 when N_Attribute_Reference
=>
6077 return Attribute_Name
(N
) = Name_Input
;
6079 when N_Selected_Component
=>
6081 Is_Object_Reference
(Selector_Name
(N
))
6083 (Is_Object_Reference
(Prefix
(N
))
6084 or else Is_Access_Type
(Etype
(Prefix
(N
))));
6086 when N_Explicit_Dereference
=>
6089 -- A view conversion of a tagged object is an object reference
6091 when N_Type_Conversion
=>
6092 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
6093 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
6094 and then Is_Object_Reference
(Expression
(N
));
6096 -- An unchecked type conversion is considered to be an object if
6097 -- the operand is an object (this construction arises only as a
6098 -- result of expansion activities).
6100 when N_Unchecked_Type_Conversion
=>
6107 end Is_Object_Reference
;
6109 -----------------------------------
6110 -- Is_OK_Variable_For_Out_Formal --
6111 -----------------------------------
6113 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
6115 Note_Possible_Modification
(AV
, Sure
=> True);
6117 -- We must reject parenthesized variable names. The check for
6118 -- Comes_From_Source is present because there are currently
6119 -- cases where the compiler violates this rule (e.g. passing
6120 -- a task object to its controlled Initialize routine).
6122 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
6125 -- A variable is always allowed
6127 elsif Is_Variable
(AV
) then
6130 -- Unchecked conversions are allowed only if they come from the
6131 -- generated code, which sometimes uses unchecked conversions for out
6132 -- parameters in cases where code generation is unaffected. We tell
6133 -- source unchecked conversions by seeing if they are rewrites of an
6134 -- original Unchecked_Conversion function call, or of an explicit
6135 -- conversion of a function call.
6137 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
6138 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
6141 elsif Comes_From_Source
(AV
)
6142 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
6146 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
6147 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
6153 -- Normal type conversions are allowed if argument is a variable
6155 elsif Nkind
(AV
) = N_Type_Conversion
then
6156 if Is_Variable
(Expression
(AV
))
6157 and then Paren_Count
(Expression
(AV
)) = 0
6159 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
6162 -- We also allow a non-parenthesized expression that raises
6163 -- constraint error if it rewrites what used to be a variable
6165 elsif Raises_Constraint_Error
(Expression
(AV
))
6166 and then Paren_Count
(Expression
(AV
)) = 0
6167 and then Is_Variable
(Original_Node
(Expression
(AV
)))
6171 -- Type conversion of something other than a variable
6177 -- If this node is rewritten, then test the original form, if that is
6178 -- OK, then we consider the rewritten node OK (for example, if the
6179 -- original node is a conversion, then Is_Variable will not be true
6180 -- but we still want to allow the conversion if it converts a variable).
6182 elsif Original_Node
(AV
) /= AV
then
6183 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
6185 -- All other non-variables are rejected
6190 end Is_OK_Variable_For_Out_Formal
;
6192 -----------------------------------
6193 -- Is_Partially_Initialized_Type --
6194 -----------------------------------
6196 function Is_Partially_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
6198 if Is_Scalar_Type
(Typ
) then
6201 elsif Is_Access_Type
(Typ
) then
6204 elsif Is_Array_Type
(Typ
) then
6206 -- If component type is partially initialized, so is array type
6208 if Is_Partially_Initialized_Type
(Component_Type
(Typ
)) then
6211 -- Otherwise we are only partially initialized if we are fully
6212 -- initialized (this is the empty array case, no point in us
6213 -- duplicating that code here).
6216 return Is_Fully_Initialized_Type
(Typ
);
6219 elsif Is_Record_Type
(Typ
) then
6221 -- A discriminated type is always partially initialized
6223 if Has_Discriminants
(Typ
) then
6226 -- A tagged type is always partially initialized
6228 elsif Is_Tagged_Type
(Typ
) then
6231 -- Case of non-discriminated record
6237 Component_Present
: Boolean := False;
6238 -- Set True if at least one component is present. If no
6239 -- components are present, then record type is fully
6240 -- initialized (another odd case, like the null array).
6243 -- Loop through components
6245 Ent
:= First_Entity
(Typ
);
6246 while Present
(Ent
) loop
6247 if Ekind
(Ent
) = E_Component
then
6248 Component_Present
:= True;
6250 -- If a component has an initialization expression then
6251 -- the enclosing record type is partially initialized
6253 if Present
(Parent
(Ent
))
6254 and then Present
(Expression
(Parent
(Ent
)))
6258 -- If a component is of a type which is itself partially
6259 -- initialized, then the enclosing record type is also.
6261 elsif Is_Partially_Initialized_Type
(Etype
(Ent
)) then
6269 -- No initialized components found. If we found any components
6270 -- they were all uninitialized so the result is false.
6272 if Component_Present
then
6275 -- But if we found no components, then all the components are
6276 -- initialized so we consider the type to be initialized.
6284 -- Concurrent types are always fully initialized
6286 elsif Is_Concurrent_Type
(Typ
) then
6289 -- For a private type, go to underlying type. If there is no underlying
6290 -- type then just assume this partially initialized. Not clear if this
6291 -- can happen in a non-error case, but no harm in testing for this.
6293 elsif Is_Private_Type
(Typ
) then
6295 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6300 return Is_Partially_Initialized_Type
(U
);
6304 -- For any other type (are there any?) assume partially initialized
6309 end Is_Partially_Initialized_Type
;
6311 ------------------------------------
6312 -- Is_Potentially_Persistent_Type --
6313 ------------------------------------
6315 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
6320 -- For private type, test corresponding full type
6322 if Is_Private_Type
(T
) then
6323 return Is_Potentially_Persistent_Type
(Full_View
(T
));
6325 -- Scalar types are potentially persistent
6327 elsif Is_Scalar_Type
(T
) then
6330 -- Record type is potentially persistent if not tagged and the types of
6331 -- all it components are potentially persistent, and no component has
6332 -- an initialization expression.
6334 elsif Is_Record_Type
(T
)
6335 and then not Is_Tagged_Type
(T
)
6336 and then not Is_Partially_Initialized_Type
(T
)
6338 Comp
:= First_Component
(T
);
6339 while Present
(Comp
) loop
6340 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
6349 -- Array type is potentially persistent if its component type is
6350 -- potentially persistent and if all its constraints are static.
6352 elsif Is_Array_Type
(T
) then
6353 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
6357 Indx
:= First_Index
(T
);
6358 while Present
(Indx
) loop
6359 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
6368 -- All other types are not potentially persistent
6373 end Is_Potentially_Persistent_Type
;
6375 -----------------------------
6376 -- Is_RCI_Pkg_Spec_Or_Body --
6377 -----------------------------
6379 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
6381 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
6382 -- Return True if the unit of Cunit is an RCI package declaration
6384 ---------------------------
6385 -- Is_RCI_Pkg_Decl_Cunit --
6386 ---------------------------
6388 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
6389 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
6392 if Nkind
(The_Unit
) /= N_Package_Declaration
then
6396 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
6397 end Is_RCI_Pkg_Decl_Cunit
;
6399 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6402 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
6404 (Nkind
(Unit
(Cunit
)) = N_Package_Body
6405 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
6406 end Is_RCI_Pkg_Spec_Or_Body
;
6408 -----------------------------------------
6409 -- Is_Remote_Access_To_Class_Wide_Type --
6410 -----------------------------------------
6412 function Is_Remote_Access_To_Class_Wide_Type
6413 (E
: Entity_Id
) return Boolean
6416 -- A remote access to class-wide type is a general access to object type
6417 -- declared in the visible part of a Remote_Types or Remote_Call_
6420 return Ekind
(E
) = E_General_Access_Type
6421 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
6422 end Is_Remote_Access_To_Class_Wide_Type
;
6424 -----------------------------------------
6425 -- Is_Remote_Access_To_Subprogram_Type --
6426 -----------------------------------------
6428 function Is_Remote_Access_To_Subprogram_Type
6429 (E
: Entity_Id
) return Boolean
6432 return (Ekind
(E
) = E_Access_Subprogram_Type
6433 or else (Ekind
(E
) = E_Record_Type
6434 and then Present
(Corresponding_Remote_Type
(E
))))
6435 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
6436 end Is_Remote_Access_To_Subprogram_Type
;
6438 --------------------
6439 -- Is_Remote_Call --
6440 --------------------
6442 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
6444 if Nkind
(N
) /= N_Procedure_Call_Statement
6445 and then Nkind
(N
) /= N_Function_Call
6447 -- An entry call cannot be remote
6451 elsif Nkind
(Name
(N
)) in N_Has_Entity
6452 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
6454 -- A subprogram declared in the spec of a RCI package is remote
6458 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
6459 and then Is_Remote_Access_To_Subprogram_Type
6460 (Etype
(Prefix
(Name
(N
))))
6462 -- The dereference of a RAS is a remote call
6466 elsif Present
(Controlling_Argument
(N
))
6467 and then Is_Remote_Access_To_Class_Wide_Type
6468 (Etype
(Controlling_Argument
(N
)))
6470 -- Any primitive operation call with a controlling argument of
6471 -- a RACW type is a remote call.
6476 -- All other calls are local calls
6481 ----------------------
6482 -- Is_Renamed_Entry --
6483 ----------------------
6485 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
6486 Orig_Node
: Node_Id
:= Empty
;
6487 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
6489 function Is_Entry
(Nam
: Node_Id
) return Boolean;
6490 -- Determine whether Nam is an entry. Traverse selectors if there are
6491 -- nested selected components.
6497 function Is_Entry
(Nam
: Node_Id
) return Boolean is
6499 if Nkind
(Nam
) = N_Selected_Component
then
6500 return Is_Entry
(Selector_Name
(Nam
));
6503 return Ekind
(Entity
(Nam
)) = E_Entry
;
6506 -- Start of processing for Is_Renamed_Entry
6509 if Present
(Alias
(Proc_Nam
)) then
6510 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
6513 -- Look for a rewritten subprogram renaming declaration
6515 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
6516 and then Present
(Original_Node
(Subp_Decl
))
6518 Orig_Node
:= Original_Node
(Subp_Decl
);
6521 -- The rewritten subprogram is actually an entry
6523 if Present
(Orig_Node
)
6524 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
6525 and then Is_Entry
(Name
(Orig_Node
))
6531 end Is_Renamed_Entry
;
6533 ----------------------
6534 -- Is_Selector_Name --
6535 ----------------------
6537 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
6539 if not Is_List_Member
(N
) then
6541 P
: constant Node_Id
:= Parent
(N
);
6542 K
: constant Node_Kind
:= Nkind
(P
);
6545 (K
= N_Expanded_Name
or else
6546 K
= N_Generic_Association
or else
6547 K
= N_Parameter_Association
or else
6548 K
= N_Selected_Component
)
6549 and then Selector_Name
(P
) = N
;
6554 L
: constant List_Id
:= List_Containing
(N
);
6555 P
: constant Node_Id
:= Parent
(L
);
6557 return (Nkind
(P
) = N_Discriminant_Association
6558 and then Selector_Names
(P
) = L
)
6560 (Nkind
(P
) = N_Component_Association
6561 and then Choices
(P
) = L
);
6564 end Is_Selector_Name
;
6570 function Is_Statement
(N
: Node_Id
) return Boolean is
6573 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
6574 or else Nkind
(N
) = N_Procedure_Call_Statement
;
6577 ---------------------------------
6578 -- Is_Synchronized_Tagged_Type --
6579 ---------------------------------
6581 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
6582 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
6585 -- A task or protected type derived from an interface is a tagged type.
6586 -- Such a tagged type is called a synchronized tagged type, as are
6587 -- synchronized interfaces and private extensions whose declaration
6588 -- includes the reserved word synchronized.
6590 return (Is_Tagged_Type
(E
)
6591 and then (Kind
= E_Task_Type
6592 or else Kind
= E_Protected_Type
))
6595 and then Is_Synchronized_Interface
(E
))
6597 (Ekind
(E
) = E_Record_Type_With_Private
6598 and then (Synchronized_Present
(Parent
(E
))
6599 or else Is_Synchronized_Interface
(Etype
(E
))));
6600 end Is_Synchronized_Tagged_Type
;
6606 function Is_Transfer
(N
: Node_Id
) return Boolean is
6607 Kind
: constant Node_Kind
:= Nkind
(N
);
6610 if Kind
= N_Simple_Return_Statement
6612 Kind
= N_Extended_Return_Statement
6614 Kind
= N_Goto_Statement
6616 Kind
= N_Raise_Statement
6618 Kind
= N_Requeue_Statement
6622 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
6623 and then No
(Condition
(N
))
6627 elsif Kind
= N_Procedure_Call_Statement
6628 and then Is_Entity_Name
(Name
(N
))
6629 and then Present
(Entity
(Name
(N
)))
6630 and then No_Return
(Entity
(Name
(N
)))
6634 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
6646 function Is_True
(U
: Uint
) return Boolean is
6655 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
6657 return VM_Target
= CLI_Target
6658 and then Chars
(T
) /= No_Name
6659 and then Get_Name_String
(Chars
(T
)) = "valuetype";
6666 function Is_Variable
(N
: Node_Id
) return Boolean is
6668 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
6669 -- We do the test on the original node, since this is basically a
6670 -- test of syntactic categories, so it must not be disturbed by
6671 -- whatever rewriting might have occurred. For example, an aggregate,
6672 -- which is certainly NOT a variable, could be turned into a variable
6675 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
6676 -- Within a protected function, the private components of the
6677 -- enclosing protected type are constants. A function nested within
6678 -- a (protected) procedure is not itself protected.
6680 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
6681 -- Prefixes can involve implicit dereferences, in which case we
6682 -- must test for the case of a reference of a constant access
6683 -- type, which can never be a variable.
6685 ---------------------------
6686 -- In_Protected_Function --
6687 ---------------------------
6689 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
6690 Prot
: constant Entity_Id
:= Scope
(E
);
6694 if not Is_Protected_Type
(Prot
) then
6698 while Present
(S
) and then S
/= Prot
loop
6699 if Ekind
(S
) = E_Function
6700 and then Scope
(S
) = Prot
6710 end In_Protected_Function
;
6712 ------------------------
6713 -- Is_Variable_Prefix --
6714 ------------------------
6716 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
6718 if Is_Access_Type
(Etype
(P
)) then
6719 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
6721 -- For the case of an indexed component whose prefix has a packed
6722 -- array type, the prefix has been rewritten into a type conversion.
6723 -- Determine variable-ness from the converted expression.
6725 elsif Nkind
(P
) = N_Type_Conversion
6726 and then not Comes_From_Source
(P
)
6727 and then Is_Array_Type
(Etype
(P
))
6728 and then Is_Packed
(Etype
(P
))
6730 return Is_Variable
(Expression
(P
));
6733 return Is_Variable
(P
);
6735 end Is_Variable_Prefix
;
6737 -- Start of processing for Is_Variable
6740 -- Definitely OK if Assignment_OK is set. Since this is something that
6741 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
6743 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
6746 -- Normally we go to the original node, but there is one exception
6747 -- where we use the rewritten node, namely when it is an explicit
6748 -- dereference. The generated code may rewrite a prefix which is an
6749 -- access type with an explicit dereference. The dereference is a
6750 -- variable, even though the original node may not be (since it could
6751 -- be a constant of the access type).
6753 -- In Ada 2005 we have a further case to consider: the prefix may be
6754 -- a function call given in prefix notation. The original node appears
6755 -- to be a selected component, but we need to examine the call.
6757 elsif Nkind
(N
) = N_Explicit_Dereference
6758 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
6759 and then Present
(Etype
(Orig_Node
))
6760 and then Is_Access_Type
(Etype
(Orig_Node
))
6762 return Is_Variable_Prefix
(Original_Node
(Prefix
(N
)))
6764 (Nkind
(Orig_Node
) = N_Function_Call
6765 and then not Is_Access_Constant
(Etype
(Prefix
(N
))));
6767 -- A function call is never a variable
6769 elsif Nkind
(N
) = N_Function_Call
then
6772 -- All remaining checks use the original node
6774 elsif Is_Entity_Name
(Orig_Node
)
6775 and then Present
(Entity
(Orig_Node
))
6778 E
: constant Entity_Id
:= Entity
(Orig_Node
);
6779 K
: constant Entity_Kind
:= Ekind
(E
);
6782 return (K
= E_Variable
6783 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
6784 or else (K
= E_Component
6785 and then not In_Protected_Function
(E
))
6786 or else K
= E_Out_Parameter
6787 or else K
= E_In_Out_Parameter
6788 or else K
= E_Generic_In_Out_Parameter
6790 -- Current instance of type:
6792 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
6793 or else (Is_Incomplete_Or_Private_Type
(E
)
6794 and then In_Open_Scopes
(Full_View
(E
)));
6798 case Nkind
(Orig_Node
) is
6799 when N_Indexed_Component | N_Slice
=>
6800 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
6802 when N_Selected_Component
=>
6803 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
6804 and then Is_Variable
(Selector_Name
(Orig_Node
));
6806 -- For an explicit dereference, the type of the prefix cannot
6807 -- be an access to constant or an access to subprogram.
6809 when N_Explicit_Dereference
=>
6811 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
6813 return Is_Access_Type
(Typ
)
6814 and then not Is_Access_Constant
(Root_Type
(Typ
))
6815 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
6818 -- The type conversion is the case where we do not deal with the
6819 -- context dependent special case of an actual parameter. Thus
6820 -- the type conversion is only considered a variable for the
6821 -- purposes of this routine if the target type is tagged. However,
6822 -- a type conversion is considered to be a variable if it does not
6823 -- come from source (this deals for example with the conversions
6824 -- of expressions to their actual subtypes).
6826 when N_Type_Conversion
=>
6827 return Is_Variable
(Expression
(Orig_Node
))
6829 (not Comes_From_Source
(Orig_Node
)
6831 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
6833 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
6835 -- GNAT allows an unchecked type conversion as a variable. This
6836 -- only affects the generation of internal expanded code, since
6837 -- calls to instantiations of Unchecked_Conversion are never
6838 -- considered variables (since they are function calls).
6839 -- This is also true for expression actions.
6841 when N_Unchecked_Type_Conversion
=>
6842 return Is_Variable
(Expression
(Orig_Node
));
6850 ------------------------
6851 -- Is_Volatile_Object --
6852 ------------------------
6854 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
6856 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
6857 -- Determines if given object has volatile components
6859 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
6860 -- If prefix is an implicit dereference, examine designated type
6862 ------------------------
6863 -- Is_Volatile_Prefix --
6864 ------------------------
6866 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
6867 Typ
: constant Entity_Id
:= Etype
(N
);
6870 if Is_Access_Type
(Typ
) then
6872 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
6875 return Is_Volatile
(Dtyp
)
6876 or else Has_Volatile_Components
(Dtyp
);
6880 return Object_Has_Volatile_Components
(N
);
6882 end Is_Volatile_Prefix
;
6884 ------------------------------------
6885 -- Object_Has_Volatile_Components --
6886 ------------------------------------
6888 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
6889 Typ
: constant Entity_Id
:= Etype
(N
);
6892 if Is_Volatile
(Typ
)
6893 or else Has_Volatile_Components
(Typ
)
6897 elsif Is_Entity_Name
(N
)
6898 and then (Has_Volatile_Components
(Entity
(N
))
6899 or else Is_Volatile
(Entity
(N
)))
6903 elsif Nkind
(N
) = N_Indexed_Component
6904 or else Nkind
(N
) = N_Selected_Component
6906 return Is_Volatile_Prefix
(Prefix
(N
));
6911 end Object_Has_Volatile_Components
;
6913 -- Start of processing for Is_Volatile_Object
6916 if Is_Volatile
(Etype
(N
))
6917 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
6921 elsif Nkind
(N
) = N_Indexed_Component
6922 or else Nkind
(N
) = N_Selected_Component
6924 return Is_Volatile_Prefix
(Prefix
(N
));
6929 end Is_Volatile_Object
;
6931 -------------------------
6932 -- Kill_Current_Values --
6933 -------------------------
6935 procedure Kill_Current_Values
6937 Last_Assignment_Only
: Boolean := False)
6940 if Is_Assignable
(Ent
) then
6941 Set_Last_Assignment
(Ent
, Empty
);
6944 if not Last_Assignment_Only
and then Is_Object
(Ent
) then
6946 Set_Current_Value
(Ent
, Empty
);
6948 if not Can_Never_Be_Null
(Ent
) then
6949 Set_Is_Known_Non_Null
(Ent
, False);
6952 Set_Is_Known_Null
(Ent
, False);
6954 end Kill_Current_Values
;
6956 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
6959 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
6960 -- Clear current value for entity E and all entities chained to E
6962 ------------------------------------------
6963 -- Kill_Current_Values_For_Entity_Chain --
6964 ------------------------------------------
6966 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
6970 while Present
(Ent
) loop
6971 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
6974 end Kill_Current_Values_For_Entity_Chain
;
6976 -- Start of processing for Kill_Current_Values
6979 -- Kill all saved checks, a special case of killing saved values
6981 if not Last_Assignment_Only
then
6985 -- Loop through relevant scopes, which includes the current scope and
6986 -- any parent scopes if the current scope is a block or a package.
6991 -- Clear current values of all entities in current scope
6993 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
6995 -- If scope is a package, also clear current values of all
6996 -- private entities in the scope.
6998 if Ekind
(S
) = E_Package
7000 Ekind
(S
) = E_Generic_Package
7002 Is_Concurrent_Type
(S
)
7004 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
7007 -- If this is a not a subprogram, deal with parents
7009 if not Is_Subprogram
(S
) then
7011 exit Scope_Loop
when S
= Standard_Standard
;
7015 end loop Scope_Loop
;
7016 end Kill_Current_Values
;
7018 --------------------------
7019 -- Kill_Size_Check_Code --
7020 --------------------------
7022 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
7024 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
7025 and then Present
(Size_Check_Code
(E
))
7027 Remove
(Size_Check_Code
(E
));
7028 Set_Size_Check_Code
(E
, Empty
);
7030 end Kill_Size_Check_Code
;
7032 --------------------------
7033 -- Known_To_Be_Assigned --
7034 --------------------------
7036 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
7037 P
: constant Node_Id
:= Parent
(N
);
7042 -- Test left side of assignment
7044 when N_Assignment_Statement
=>
7045 return N
= Name
(P
);
7047 -- Function call arguments are never lvalues
7049 when N_Function_Call
=>
7052 -- Positional parameter for procedure or accept call
7054 when N_Procedure_Call_Statement |
7063 Proc
:= Get_Subprogram_Entity
(P
);
7069 -- If we are not a list member, something is strange, so
7070 -- be conservative and return False.
7072 if not Is_List_Member
(N
) then
7076 -- We are going to find the right formal by stepping forward
7077 -- through the formals, as we step backwards in the actuals.
7079 Form
:= First_Formal
(Proc
);
7082 -- If no formal, something is weird, so be conservative
7083 -- and return False.
7094 return Ekind
(Form
) /= E_In_Parameter
;
7097 -- Named parameter for procedure or accept call
7099 when N_Parameter_Association
=>
7105 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7111 -- Loop through formals to find the one that matches
7113 Form
:= First_Formal
(Proc
);
7115 -- If no matching formal, that's peculiar, some kind of
7116 -- previous error, so return False to be conservative.
7122 -- Else test for match
7124 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7125 return Ekind
(Form
) /= E_In_Parameter
;
7132 -- Test for appearing in a conversion that itself appears
7133 -- in an lvalue context, since this should be an lvalue.
7135 when N_Type_Conversion
=>
7136 return Known_To_Be_Assigned
(P
);
7138 -- All other references are definitely not known to be modifications
7144 end Known_To_Be_Assigned
;
7150 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
7151 P
: constant Node_Id
:= Parent
(N
);
7156 -- Test left side of assignment
7158 when N_Assignment_Statement
=>
7159 return N
= Name
(P
);
7161 -- Test prefix of component or attribute
7163 when N_Attribute_Reference
=>
7164 return N
= Prefix
(P
)
7165 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
7167 when N_Expanded_Name |
7168 N_Explicit_Dereference |
7169 N_Indexed_Component |
7171 N_Selected_Component |
7173 return N
= Prefix
(P
);
7175 -- Function call arguments are never lvalues
7177 when N_Function_Call
=>
7180 -- Positional parameter for procedure, entry, or accept call
7182 when N_Procedure_Call_Statement |
7183 N_Entry_Call_Statement |
7192 Proc
:= Get_Subprogram_Entity
(P
);
7198 -- If we are not a list member, something is strange, so
7199 -- be conservative and return True.
7201 if not Is_List_Member
(N
) then
7205 -- We are going to find the right formal by stepping forward
7206 -- through the formals, as we step backwards in the actuals.
7208 Form
:= First_Formal
(Proc
);
7211 -- If no formal, something is weird, so be conservative
7223 return Ekind
(Form
) /= E_In_Parameter
;
7226 -- Named parameter for procedure or accept call
7228 when N_Parameter_Association
=>
7234 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7240 -- Loop through formals to find the one that matches
7242 Form
:= First_Formal
(Proc
);
7244 -- If no matching formal, that's peculiar, some kind of
7245 -- previous error, so return True to be conservative.
7251 -- Else test for match
7253 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7254 return Ekind
(Form
) /= E_In_Parameter
;
7261 -- Test for appearing in a conversion that itself appears in an
7262 -- lvalue context, since this should be an lvalue.
7264 when N_Type_Conversion
=>
7265 return May_Be_Lvalue
(P
);
7267 -- Test for appearance in object renaming declaration
7269 when N_Object_Renaming_Declaration
=>
7272 -- All other references are definitely not Lvalues
7280 -----------------------
7281 -- Mark_Coextensions --
7282 -----------------------
7284 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
7285 Is_Dynamic
: Boolean;
7286 -- Indicates whether the context causes nested coextensions to be
7287 -- dynamic or static
7289 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
7290 -- Recognize an allocator node and label it as a dynamic coextension
7292 --------------------
7293 -- Mark_Allocator --
7294 --------------------
7296 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
7298 if Nkind
(N
) = N_Allocator
then
7300 Set_Is_Dynamic_Coextension
(N
);
7302 Set_Is_Static_Coextension
(N
);
7309 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
7311 -- Start of processing Mark_Coextensions
7314 case Nkind
(Context_Nod
) is
7315 when N_Assignment_Statement |
7316 N_Simple_Return_Statement
=>
7317 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
7319 when N_Object_Declaration
=>
7320 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
;
7322 -- This routine should not be called for constructs which may not
7323 -- contain coextensions.
7326 raise Program_Error
;
7329 Mark_Allocators
(Root_Nod
);
7330 end Mark_Coextensions
;
7332 ----------------------
7333 -- Needs_One_Actual --
7334 ----------------------
7336 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
7340 if Ada_Version
>= Ada_05
7341 and then Present
(First_Formal
(E
))
7343 Formal
:= Next_Formal
(First_Formal
(E
));
7344 while Present
(Formal
) loop
7345 if No
(Default_Value
(Formal
)) then
7349 Next_Formal
(Formal
);
7357 end Needs_One_Actual
;
7359 -------------------------
7360 -- New_External_Entity --
7361 -------------------------
7363 function New_External_Entity
7364 (Kind
: Entity_Kind
;
7365 Scope_Id
: Entity_Id
;
7366 Sloc_Value
: Source_Ptr
;
7367 Related_Id
: Entity_Id
;
7369 Suffix_Index
: Nat
:= 0;
7370 Prefix
: Character := ' ') return Entity_Id
7372 N
: constant Entity_Id
:=
7373 Make_Defining_Identifier
(Sloc_Value
,
7375 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
7378 Set_Ekind
(N
, Kind
);
7379 Set_Is_Internal
(N
, True);
7380 Append_Entity
(N
, Scope_Id
);
7381 Set_Public_Status
(N
);
7383 if Kind
in Type_Kind
then
7384 Init_Size_Align
(N
);
7388 end New_External_Entity
;
7390 -------------------------
7391 -- New_Internal_Entity --
7392 -------------------------
7394 function New_Internal_Entity
7395 (Kind
: Entity_Kind
;
7396 Scope_Id
: Entity_Id
;
7397 Sloc_Value
: Source_Ptr
;
7398 Id_Char
: Character) return Entity_Id
7400 N
: constant Entity_Id
:=
7401 Make_Defining_Identifier
(Sloc_Value
, New_Internal_Name
(Id_Char
));
7404 Set_Ekind
(N
, Kind
);
7405 Set_Is_Internal
(N
, True);
7406 Append_Entity
(N
, Scope_Id
);
7408 if Kind
in Type_Kind
then
7409 Init_Size_Align
(N
);
7413 end New_Internal_Entity
;
7419 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
7423 -- If we are pointing at a positional parameter, it is a member of a
7424 -- node list (the list of parameters), and the next parameter is the
7425 -- next node on the list, unless we hit a parameter association, then
7426 -- we shift to using the chain whose head is the First_Named_Actual in
7427 -- the parent, and then is threaded using the Next_Named_Actual of the
7428 -- Parameter_Association. All this fiddling is because the original node
7429 -- list is in the textual call order, and what we need is the
7430 -- declaration order.
7432 if Is_List_Member
(Actual_Id
) then
7433 N
:= Next
(Actual_Id
);
7435 if Nkind
(N
) = N_Parameter_Association
then
7436 return First_Named_Actual
(Parent
(Actual_Id
));
7442 return Next_Named_Actual
(Parent
(Actual_Id
));
7446 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
7448 Actual_Id
:= Next_Actual
(Actual_Id
);
7451 -----------------------
7452 -- Normalize_Actuals --
7453 -----------------------
7455 -- Chain actuals according to formals of subprogram. If there are no named
7456 -- associations, the chain is simply the list of Parameter Associations,
7457 -- since the order is the same as the declaration order. If there are named
7458 -- associations, then the First_Named_Actual field in the N_Function_Call
7459 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7460 -- node for the parameter that comes first in declaration order. The
7461 -- remaining named parameters are then chained in declaration order using
7462 -- Next_Named_Actual.
7464 -- This routine also verifies that the number of actuals is compatible with
7465 -- the number and default values of formals, but performs no type checking
7466 -- (type checking is done by the caller).
7468 -- If the matching succeeds, Success is set to True and the caller proceeds
7469 -- with type-checking. If the match is unsuccessful, then Success is set to
7470 -- False, and the caller attempts a different interpretation, if there is
7473 -- If the flag Report is on, the call is not overloaded, and a failure to
7474 -- match can be reported here, rather than in the caller.
7476 procedure Normalize_Actuals
7480 Success
: out Boolean)
7482 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7483 Actual
: Node_Id
:= Empty
;
7485 Last
: Node_Id
:= Empty
;
7486 First_Named
: Node_Id
:= Empty
;
7489 Formals_To_Match
: Integer := 0;
7490 Actuals_To_Match
: Integer := 0;
7492 procedure Chain
(A
: Node_Id
);
7493 -- Add named actual at the proper place in the list, using the
7494 -- Next_Named_Actual link.
7496 function Reporting
return Boolean;
7497 -- Determines if an error is to be reported. To report an error, we
7498 -- need Report to be True, and also we do not report errors caused
7499 -- by calls to init procs that occur within other init procs. Such
7500 -- errors must always be cascaded errors, since if all the types are
7501 -- declared correctly, the compiler will certainly build decent calls!
7507 procedure Chain
(A
: Node_Id
) is
7511 -- Call node points to first actual in list
7513 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
7516 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
7520 Set_Next_Named_Actual
(Last
, Empty
);
7527 function Reporting
return Boolean is
7532 elsif not Within_Init_Proc
then
7535 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
7543 -- Start of processing for Normalize_Actuals
7546 if Is_Access_Type
(S
) then
7548 -- The name in the call is a function call that returns an access
7549 -- to subprogram. The designated type has the list of formals.
7551 Formal
:= First_Formal
(Designated_Type
(S
));
7553 Formal
:= First_Formal
(S
);
7556 while Present
(Formal
) loop
7557 Formals_To_Match
:= Formals_To_Match
+ 1;
7558 Next_Formal
(Formal
);
7561 -- Find if there is a named association, and verify that no positional
7562 -- associations appear after named ones.
7564 if Present
(Actuals
) then
7565 Actual
:= First
(Actuals
);
7568 while Present
(Actual
)
7569 and then Nkind
(Actual
) /= N_Parameter_Association
7571 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7575 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
7577 -- Most common case: positional notation, no defaults
7582 elsif Actuals_To_Match
> Formals_To_Match
then
7584 -- Too many actuals: will not work
7587 if Is_Entity_Name
(Name
(N
)) then
7588 Error_Msg_N
("too many arguments in call to&", Name
(N
));
7590 Error_Msg_N
("too many arguments in call", N
);
7598 First_Named
:= Actual
;
7600 while Present
(Actual
) loop
7601 if Nkind
(Actual
) /= N_Parameter_Association
then
7603 ("positional parameters not allowed after named ones", Actual
);
7608 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7614 if Present
(Actuals
) then
7615 Actual
:= First
(Actuals
);
7618 Formal
:= First_Formal
(S
);
7619 while Present
(Formal
) loop
7621 -- Match the formals in order. If the corresponding actual is
7622 -- positional, nothing to do. Else scan the list of named actuals
7623 -- to find the one with the right name.
7626 and then Nkind
(Actual
) /= N_Parameter_Association
7629 Actuals_To_Match
:= Actuals_To_Match
- 1;
7630 Formals_To_Match
:= Formals_To_Match
- 1;
7633 -- For named parameters, search the list of actuals to find
7634 -- one that matches the next formal name.
7636 Actual
:= First_Named
;
7638 while Present
(Actual
) loop
7639 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
7642 Actuals_To_Match
:= Actuals_To_Match
- 1;
7643 Formals_To_Match
:= Formals_To_Match
- 1;
7651 if Ekind
(Formal
) /= E_In_Parameter
7652 or else No
(Default_Value
(Formal
))
7655 if (Comes_From_Source
(S
)
7656 or else Sloc
(S
) = Standard_Location
)
7657 and then Is_Overloadable
(S
)
7661 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
7663 (Nkind
(Parent
(N
)) = N_Function_Call
7665 Nkind
(Parent
(N
)) = N_Parameter_Association
))
7666 and then Ekind
(S
) /= E_Function
7668 Set_Etype
(N
, Etype
(S
));
7670 Error_Msg_Name_1
:= Chars
(S
);
7671 Error_Msg_Sloc
:= Sloc
(S
);
7673 ("missing argument for parameter & " &
7674 "in call to % declared #", N
, Formal
);
7677 elsif Is_Overloadable
(S
) then
7678 Error_Msg_Name_1
:= Chars
(S
);
7680 -- Point to type derivation that generated the
7683 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
7686 ("missing argument for parameter & " &
7687 "in call to % (inherited) #", N
, Formal
);
7691 ("missing argument for parameter &", N
, Formal
);
7699 Formals_To_Match
:= Formals_To_Match
- 1;
7704 Next_Formal
(Formal
);
7707 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
7714 -- Find some superfluous named actual that did not get
7715 -- attached to the list of associations.
7717 Actual
:= First
(Actuals
);
7718 while Present
(Actual
) loop
7719 if Nkind
(Actual
) = N_Parameter_Association
7720 and then Actual
/= Last
7721 and then No
(Next_Named_Actual
(Actual
))
7723 Error_Msg_N
("unmatched actual & in call",
7724 Selector_Name
(Actual
));
7735 end Normalize_Actuals
;
7737 --------------------------------
7738 -- Note_Possible_Modification --
7739 --------------------------------
7741 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
7742 Modification_Comes_From_Source
: constant Boolean :=
7743 Comes_From_Source
(Parent
(N
));
7749 -- Loop to find referenced entity, if there is one
7756 if Is_Entity_Name
(Exp
) then
7757 Ent
:= Entity
(Exp
);
7759 -- If the entity is missing, it is an undeclared identifier,
7760 -- and there is nothing to annotate.
7766 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
7768 P
: constant Node_Id
:= Prefix
(Exp
);
7771 if Nkind
(P
) = N_Selected_Component
7773 Entry_Formal
(Entity
(Selector_Name
(P
))))
7775 -- Case of a reference to an entry formal
7777 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
7779 elsif Nkind
(P
) = N_Identifier
7780 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
7781 and then Present
(Expression
(Parent
(Entity
(P
))))
7782 and then Nkind
(Expression
(Parent
(Entity
(P
))))
7785 -- Case of a reference to a value on which side effects have
7788 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
7797 elsif Nkind
(Exp
) = N_Type_Conversion
7798 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
7800 Exp
:= Expression
(Exp
);
7803 elsif Nkind
(Exp
) = N_Slice
7804 or else Nkind
(Exp
) = N_Indexed_Component
7805 or else Nkind
(Exp
) = N_Selected_Component
7807 Exp
:= Prefix
(Exp
);
7814 -- Now look for entity being referenced
7816 if Present
(Ent
) then
7817 if Is_Object
(Ent
) then
7818 if Comes_From_Source
(Exp
)
7819 or else Modification_Comes_From_Source
7821 if Has_Pragma_Unmodified
(Ent
) then
7822 Error_Msg_NE
("?pragma Unmodified given for &!", N
, Ent
);
7825 Set_Never_Set_In_Source
(Ent
, False);
7828 Set_Is_True_Constant
(Ent
, False);
7829 Set_Current_Value
(Ent
, Empty
);
7830 Set_Is_Known_Null
(Ent
, False);
7832 if not Can_Never_Be_Null
(Ent
) then
7833 Set_Is_Known_Non_Null
(Ent
, False);
7836 -- Follow renaming chain
7838 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
7839 and then Present
(Renamed_Object
(Ent
))
7841 Exp
:= Renamed_Object
(Ent
);
7845 -- Generate a reference only if the assignment comes from
7846 -- source. This excludes, for example, calls to a dispatching
7847 -- assignment operation when the left-hand side is tagged.
7849 if Modification_Comes_From_Source
then
7850 Generate_Reference
(Ent
, Exp
, 'm');
7853 Check_Nested_Access
(Ent
);
7858 -- If we are sure this is a modification from source, and we know
7859 -- this modifies a constant, then give an appropriate warning.
7861 if Overlays_Constant
(Ent
)
7862 and then Modification_Comes_From_Source
7866 A
: constant Node_Id
:= Address_Clause
(Ent
);
7870 Exp
: constant Node_Id
:= Expression
(A
);
7872 if Nkind
(Exp
) = N_Attribute_Reference
7873 and then Attribute_Name
(Exp
) = Name_Address
7874 and then Is_Entity_Name
(Prefix
(Exp
))
7876 Error_Msg_Sloc
:= Sloc
(A
);
7878 ("constant& may be modified via address clause#?",
7879 N
, Entity
(Prefix
(Exp
)));
7889 end Note_Possible_Modification
;
7891 -------------------------
7892 -- Object_Access_Level --
7893 -------------------------
7895 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
7898 -- Returns the static accessibility level of the view denoted by Obj. Note
7899 -- that the value returned is the result of a call to Scope_Depth. Only
7900 -- scope depths associated with dynamic scopes can actually be returned.
7901 -- Since only relative levels matter for accessibility checking, the fact
7902 -- that the distance between successive levels of accessibility is not
7903 -- always one is immaterial (invariant: if level(E2) is deeper than
7904 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
7906 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
7907 -- An explicit dereference is created when removing side-effects from
7908 -- expressions for constraint checking purposes. In this case a local
7909 -- access type is created for it. The correct access level is that of
7910 -- the original source node. We detect this case by noting that the
7911 -- prefix of the dereference is created by an object declaration whose
7912 -- initial expression is a reference.
7918 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
7919 Pref
: constant Node_Id
:= Prefix
(Obj
);
7921 if Is_Entity_Name
(Pref
)
7922 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
7923 and then Present
(Expression
(Parent
(Entity
(Pref
))))
7924 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
7926 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
7932 -- Start of processing for Object_Access_Level
7935 if Is_Entity_Name
(Obj
) then
7938 if Is_Prival
(E
) then
7939 E
:= Prival_Link
(E
);
7942 -- If E is a type then it denotes a current instance. For this case
7943 -- we add one to the normal accessibility level of the type to ensure
7944 -- that current instances are treated as always being deeper than
7945 -- than the level of any visible named access type (see 3.10.2(21)).
7948 return Type_Access_Level
(E
) + 1;
7950 elsif Present
(Renamed_Object
(E
)) then
7951 return Object_Access_Level
(Renamed_Object
(E
));
7953 -- Similarly, if E is a component of the current instance of a
7954 -- protected type, any instance of it is assumed to be at a deeper
7955 -- level than the type. For a protected object (whose type is an
7956 -- anonymous protected type) its components are at the same level
7957 -- as the type itself.
7959 elsif not Is_Overloadable
(E
)
7960 and then Ekind
(Scope
(E
)) = E_Protected_Type
7961 and then Comes_From_Source
(Scope
(E
))
7963 return Type_Access_Level
(Scope
(E
)) + 1;
7966 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
7969 elsif Nkind
(Obj
) = N_Selected_Component
then
7970 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
7971 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
7973 return Object_Access_Level
(Prefix
(Obj
));
7976 elsif Nkind
(Obj
) = N_Indexed_Component
then
7977 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
7978 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
7980 return Object_Access_Level
(Prefix
(Obj
));
7983 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
7985 -- If the prefix is a selected access discriminant then we make a
7986 -- recursive call on the prefix, which will in turn check the level
7987 -- of the prefix object of the selected discriminant.
7989 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
7990 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
7992 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
7994 return Object_Access_Level
(Prefix
(Obj
));
7996 elsif not (Comes_From_Source
(Obj
)) then
7998 Ref
: constant Node_Id
:= Reference_To
(Obj
);
8000 if Present
(Ref
) then
8001 return Object_Access_Level
(Ref
);
8003 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8008 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8011 elsif Nkind
(Obj
) = N_Type_Conversion
8012 or else Nkind
(Obj
) = N_Unchecked_Type_Conversion
8014 return Object_Access_Level
(Expression
(Obj
));
8016 -- Function results are objects, so we get either the access level of
8017 -- the function or, in the case of an indirect call, the level of of the
8018 -- access-to-subprogram type.
8020 elsif Nkind
(Obj
) = N_Function_Call
then
8021 if Is_Entity_Name
(Name
(Obj
)) then
8022 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
8024 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
8027 -- For convenience we handle qualified expressions, even though
8028 -- they aren't technically object names.
8030 elsif Nkind
(Obj
) = N_Qualified_Expression
then
8031 return Object_Access_Level
(Expression
(Obj
));
8033 -- Otherwise return the scope level of Standard.
8034 -- (If there are cases that fall through
8035 -- to this point they will be treated as
8036 -- having global accessibility for now. ???)
8039 return Scope_Depth
(Standard_Standard
);
8041 end Object_Access_Level
;
8043 -----------------------
8044 -- Private_Component --
8045 -----------------------
8047 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
8048 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
8050 function Trace_Components
8052 Check
: Boolean) return Entity_Id
;
8053 -- Recursive function that does the work, and checks against circular
8054 -- definition for each subcomponent type.
8056 ----------------------
8057 -- Trace_Components --
8058 ----------------------
8060 function Trace_Components
8062 Check
: Boolean) return Entity_Id
8064 Btype
: constant Entity_Id
:= Base_Type
(T
);
8065 Component
: Entity_Id
;
8067 Candidate
: Entity_Id
:= Empty
;
8070 if Check
and then Btype
= Ancestor
then
8071 Error_Msg_N
("circular type definition", Type_Id
);
8075 if Is_Private_Type
(Btype
)
8076 and then not Is_Generic_Type
(Btype
)
8078 if Present
(Full_View
(Btype
))
8079 and then Is_Record_Type
(Full_View
(Btype
))
8080 and then not Is_Frozen
(Btype
)
8082 -- To indicate that the ancestor depends on a private type, the
8083 -- current Btype is sufficient. However, to check for circular
8084 -- definition we must recurse on the full view.
8086 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
8088 if Candidate
= Any_Type
then
8098 elsif Is_Array_Type
(Btype
) then
8099 return Trace_Components
(Component_Type
(Btype
), True);
8101 elsif Is_Record_Type
(Btype
) then
8102 Component
:= First_Entity
(Btype
);
8103 while Present
(Component
) loop
8105 -- Skip anonymous types generated by constrained components
8107 if not Is_Type
(Component
) then
8108 P
:= Trace_Components
(Etype
(Component
), True);
8111 if P
= Any_Type
then
8119 Next_Entity
(Component
);
8127 end Trace_Components
;
8129 -- Start of processing for Private_Component
8132 return Trace_Components
(Type_Id
, False);
8133 end Private_Component
;
8135 ---------------------------
8136 -- Primitive_Names_Match --
8137 ---------------------------
8139 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
8141 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
8142 -- Given an internal name, returns the corresponding non-internal name
8144 ------------------------
8145 -- Non_Internal_Name --
8146 ------------------------
8148 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
8150 Get_Name_String
(Chars
(E
));
8151 Name_Len
:= Name_Len
- 1;
8153 end Non_Internal_Name
;
8155 -- Start of processing for Primitive_Names_Match
8158 pragma Assert
(Present
(E1
) and then Present
(E2
));
8160 return Chars
(E1
) = Chars
(E2
)
8162 (not Is_Internal_Name
(Chars
(E1
))
8163 and then Is_Internal_Name
(Chars
(E2
))
8164 and then Non_Internal_Name
(E2
) = Chars
(E1
))
8166 (not Is_Internal_Name
(Chars
(E2
))
8167 and then Is_Internal_Name
(Chars
(E1
))
8168 and then Non_Internal_Name
(E1
) = Chars
(E2
))
8170 (Is_Predefined_Dispatching_Operation
(E1
)
8171 and then Is_Predefined_Dispatching_Operation
(E2
)
8172 and then Same_TSS
(E1
, E2
))
8174 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
8175 end Primitive_Names_Match
;
8177 -----------------------
8178 -- Process_End_Label --
8179 -----------------------
8181 procedure Process_End_Label
8190 Label_Ref
: Boolean;
8191 -- Set True if reference to end label itself is required
8194 -- Gets set to the operator symbol or identifier that references the
8195 -- entity Ent. For the child unit case, this is the identifier from the
8196 -- designator. For other cases, this is simply Endl.
8198 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
8199 -- N is an identifier node that appears as a parent unit reference in
8200 -- the case where Ent is a child unit. This procedure generates an
8201 -- appropriate cross-reference entry. E is the corresponding entity.
8203 -------------------------
8204 -- Generate_Parent_Ref --
8205 -------------------------
8207 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
8209 -- If names do not match, something weird, skip reference
8211 if Chars
(E
) = Chars
(N
) then
8213 -- Generate the reference. We do NOT consider this as a reference
8214 -- for unreferenced symbol purposes.
8216 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
8219 Style
.Check_Identifier
(N
, E
);
8222 end Generate_Parent_Ref
;
8224 -- Start of processing for Process_End_Label
8227 -- If no node, ignore. This happens in some error situations, and
8228 -- also for some internally generated structures where no end label
8229 -- references are required in any case.
8235 -- Nothing to do if no End_Label, happens for internally generated
8236 -- constructs where we don't want an end label reference anyway. Also
8237 -- nothing to do if Endl is a string literal, which means there was
8238 -- some prior error (bad operator symbol)
8240 Endl
:= End_Label
(N
);
8242 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
8246 -- Reference node is not in extended main source unit
8248 if not In_Extended_Main_Source_Unit
(N
) then
8250 -- Generally we do not collect references except for the extended
8251 -- main source unit. The one exception is the 'e' entry for a
8252 -- package spec, where it is useful for a client to have the
8253 -- ending information to define scopes.
8261 -- For this case, we can ignore any parent references, but we
8262 -- need the package name itself for the 'e' entry.
8264 if Nkind
(Endl
) = N_Designator
then
8265 Endl
:= Identifier
(Endl
);
8269 -- Reference is in extended main source unit
8274 -- For designator, generate references for the parent entries
8276 if Nkind
(Endl
) = N_Designator
then
8278 -- Generate references for the prefix if the END line comes from
8279 -- source (otherwise we do not need these references) We climb the
8280 -- scope stack to find the expected entities.
8282 if Comes_From_Source
(Endl
) then
8284 Scop
:= Current_Scope
;
8285 while Nkind
(Nam
) = N_Selected_Component
loop
8286 Scop
:= Scope
(Scop
);
8287 exit when No
(Scop
);
8288 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
8289 Nam
:= Prefix
(Nam
);
8292 if Present
(Scop
) then
8293 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
8297 Endl
:= Identifier
(Endl
);
8301 -- If the end label is not for the given entity, then either we have
8302 -- some previous error, or this is a generic instantiation for which
8303 -- we do not need to make a cross-reference in this case anyway. In
8304 -- either case we simply ignore the call.
8306 if Chars
(Ent
) /= Chars
(Endl
) then
8310 -- If label was really there, then generate a normal reference and then
8311 -- adjust the location in the end label to point past the name (which
8312 -- should almost always be the semicolon).
8316 if Comes_From_Source
(Endl
) then
8318 -- If a label reference is required, then do the style check and
8319 -- generate an l-type cross-reference entry for the label
8323 Style
.Check_Identifier
(Endl
, Ent
);
8326 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
8329 -- Set the location to point past the label (normally this will
8330 -- mean the semicolon immediately following the label). This is
8331 -- done for the sake of the 'e' or 't' entry generated below.
8333 Get_Decoded_Name_String
(Chars
(Endl
));
8334 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
8337 -- Now generate the e/t reference
8339 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
8341 -- Restore Sloc, in case modified above, since we have an identifier
8342 -- and the normal Sloc should be left set in the tree.
8344 Set_Sloc
(Endl
, Loc
);
8345 end Process_End_Label
;
8351 -- We do the conversion to get the value of the real string by using
8352 -- the scanner, see Sinput for details on use of the internal source
8353 -- buffer for scanning internal strings.
8355 function Real_Convert
(S
: String) return Node_Id
is
8356 Save_Src
: constant Source_Buffer_Ptr
:= Source
;
8360 Source
:= Internal_Source_Ptr
;
8363 for J
in S
'Range loop
8364 Source
(Source_Ptr
(J
)) := S
(J
);
8367 Source
(S
'Length + 1) := EOF
;
8369 if Source
(Scan_Ptr
) = '-' then
8371 Scan_Ptr
:= Scan_Ptr
+ 1;
8379 Set_Realval
(Token_Node
, UR_Negate
(Realval
(Token_Node
)));
8386 --------------------
8387 -- Remove_Homonym --
8388 --------------------
8390 procedure Remove_Homonym
(E
: Entity_Id
) is
8391 Prev
: Entity_Id
:= Empty
;
8395 if E
= Current_Entity
(E
) then
8396 if Present
(Homonym
(E
)) then
8397 Set_Current_Entity
(Homonym
(E
));
8399 Set_Name_Entity_Id
(Chars
(E
), Empty
);
8402 H
:= Current_Entity
(E
);
8403 while Present
(H
) and then H
/= E
loop
8408 Set_Homonym
(Prev
, Homonym
(E
));
8412 ---------------------
8413 -- Rep_To_Pos_Flag --
8414 ---------------------
8416 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
8418 return New_Occurrence_Of
8419 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
8420 end Rep_To_Pos_Flag
;
8422 --------------------
8423 -- Require_Entity --
8424 --------------------
8426 procedure Require_Entity
(N
: Node_Id
) is
8428 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
8429 if Total_Errors_Detected
/= 0 then
8430 Set_Entity
(N
, Any_Id
);
8432 raise Program_Error
;
8437 ------------------------------
8438 -- Requires_Transient_Scope --
8439 ------------------------------
8441 -- A transient scope is required when variable-sized temporaries are
8442 -- allocated in the primary or secondary stack, or when finalization
8443 -- actions must be generated before the next instruction.
8445 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
8446 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
8448 -- Start of processing for Requires_Transient_Scope
8451 -- This is a private type which is not completed yet. This can only
8452 -- happen in a default expression (of a formal parameter or of a
8453 -- record component). Do not expand transient scope in this case
8458 -- Do not expand transient scope for non-existent procedure return
8460 elsif Typ
= Standard_Void_Type
then
8463 -- Elementary types do not require a transient scope
8465 elsif Is_Elementary_Type
(Typ
) then
8468 -- Generally, indefinite subtypes require a transient scope, since the
8469 -- back end cannot generate temporaries, since this is not a valid type
8470 -- for declaring an object. It might be possible to relax this in the
8471 -- future, e.g. by declaring the maximum possible space for the type.
8473 elsif Is_Indefinite_Subtype
(Typ
) then
8476 -- Functions returning tagged types may dispatch on result so their
8477 -- returned value is allocated on the secondary stack. Controlled
8478 -- type temporaries need finalization.
8480 elsif Is_Tagged_Type
(Typ
)
8481 or else Has_Controlled_Component
(Typ
)
8483 return not Is_Value_Type
(Typ
);
8487 elsif Is_Record_Type
(Typ
) then
8491 Comp
:= First_Entity
(Typ
);
8492 while Present
(Comp
) loop
8493 if Ekind
(Comp
) = E_Component
8494 and then Requires_Transient_Scope
(Etype
(Comp
))
8505 -- String literal types never require transient scope
8507 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
8510 -- Array type. Note that we already know that this is a constrained
8511 -- array, since unconstrained arrays will fail the indefinite test.
8513 elsif Is_Array_Type
(Typ
) then
8515 -- If component type requires a transient scope, the array does too
8517 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
8520 -- Otherwise, we only need a transient scope if the size is not
8521 -- known at compile time.
8524 return not Size_Known_At_Compile_Time
(Typ
);
8527 -- All other cases do not require a transient scope
8532 end Requires_Transient_Scope
;
8534 --------------------------
8535 -- Reset_Analyzed_Flags --
8536 --------------------------
8538 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
8540 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
8541 -- Function used to reset Analyzed flags in tree. Note that we do
8542 -- not reset Analyzed flags in entities, since there is no need to
8543 -- reanalyze entities, and indeed, it is wrong to do so, since it
8544 -- can result in generating auxiliary stuff more than once.
8546 --------------------
8547 -- Clear_Analyzed --
8548 --------------------
8550 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
8552 if not Has_Extension
(N
) then
8553 Set_Analyzed
(N
, False);
8559 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
8561 -- Start of processing for Reset_Analyzed_Flags
8565 end Reset_Analyzed_Flags
;
8567 ---------------------------
8568 -- Safe_To_Capture_Value --
8569 ---------------------------
8571 function Safe_To_Capture_Value
8574 Cond
: Boolean := False) return Boolean
8577 -- The only entities for which we track constant values are variables
8578 -- which are not renamings, constants, out parameters, and in out
8579 -- parameters, so check if we have this case.
8581 -- Note: it may seem odd to track constant values for constants, but in
8582 -- fact this routine is used for other purposes than simply capturing
8583 -- the value. In particular, the setting of Known[_Non]_Null.
8585 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
8587 Ekind
(Ent
) = E_Constant
8589 Ekind
(Ent
) = E_Out_Parameter
8591 Ekind
(Ent
) = E_In_Out_Parameter
8595 -- For conditionals, we also allow loop parameters and all formals,
8596 -- including in parameters.
8600 (Ekind
(Ent
) = E_Loop_Parameter
8602 Ekind
(Ent
) = E_In_Parameter
)
8606 -- For all other cases, not just unsafe, but impossible to capture
8607 -- Current_Value, since the above are the only entities which have
8608 -- Current_Value fields.
8614 -- Skip if volatile or aliased, since funny things might be going on in
8615 -- these cases which we cannot necessarily track. Also skip any variable
8616 -- for which an address clause is given, or whose address is taken. Also
8617 -- never capture value of library level variables (an attempt to do so
8618 -- can occur in the case of package elaboration code).
8620 if Treat_As_Volatile
(Ent
)
8621 or else Is_Aliased
(Ent
)
8622 or else Present
(Address_Clause
(Ent
))
8623 or else Address_Taken
(Ent
)
8624 or else (Is_Library_Level_Entity
(Ent
)
8625 and then Ekind
(Ent
) = E_Variable
)
8630 -- OK, all above conditions are met. We also require that the scope of
8631 -- the reference be the same as the scope of the entity, not counting
8632 -- packages and blocks and loops.
8635 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
8636 R_Scope
: Entity_Id
;
8639 R_Scope
:= Current_Scope
;
8640 while R_Scope
/= Standard_Standard
loop
8641 exit when R_Scope
= E_Scope
;
8643 if Ekind
(R_Scope
) /= E_Package
8645 Ekind
(R_Scope
) /= E_Block
8647 Ekind
(R_Scope
) /= E_Loop
8651 R_Scope
:= Scope
(R_Scope
);
8656 -- We also require that the reference does not appear in a context
8657 -- where it is not sure to be executed (i.e. a conditional context
8658 -- or an exception handler). We skip this if Cond is True, since the
8659 -- capturing of values from conditional tests handles this ok.
8673 while Present
(P
) loop
8674 if Nkind
(P
) = N_If_Statement
8675 or else Nkind
(P
) = N_Case_Statement
8676 or else (Nkind
(P
) = N_And_Then
and then Desc
= Right_Opnd
(P
))
8677 or else (Nkind
(P
) = N_Or_Else
and then Desc
= Right_Opnd
(P
))
8678 or else Nkind
(P
) = N_Exception_Handler
8679 or else Nkind
(P
) = N_Selective_Accept
8680 or else Nkind
(P
) = N_Conditional_Entry_Call
8681 or else Nkind
(P
) = N_Timed_Entry_Call
8682 or else Nkind
(P
) = N_Asynchronous_Select
8692 -- OK, looks safe to set value
8695 end Safe_To_Capture_Value
;
8701 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
8702 K1
: constant Node_Kind
:= Nkind
(N1
);
8703 K2
: constant Node_Kind
:= Nkind
(N2
);
8706 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
8707 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
8709 return Chars
(N1
) = Chars
(N2
);
8711 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
8712 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
8714 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
8715 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
8726 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
8727 N1
: constant Node_Id
:= Original_Node
(Node1
);
8728 N2
: constant Node_Id
:= Original_Node
(Node2
);
8729 -- We do the tests on original nodes, since we are most interested
8730 -- in the original source, not any expansion that got in the way.
8732 K1
: constant Node_Kind
:= Nkind
(N1
);
8733 K2
: constant Node_Kind
:= Nkind
(N2
);
8736 -- First case, both are entities with same entity
8738 if K1
in N_Has_Entity
8739 and then K2
in N_Has_Entity
8740 and then Present
(Entity
(N1
))
8741 and then Present
(Entity
(N2
))
8742 and then (Ekind
(Entity
(N1
)) = E_Variable
8744 Ekind
(Entity
(N1
)) = E_Constant
)
8745 and then Entity
(N1
) = Entity
(N2
)
8749 -- Second case, selected component with same selector, same record
8751 elsif K1
= N_Selected_Component
8752 and then K2
= N_Selected_Component
8753 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
8755 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
8757 -- Third case, indexed component with same subscripts, same array
8759 elsif K1
= N_Indexed_Component
8760 and then K2
= N_Indexed_Component
8761 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
8766 E1
:= First
(Expressions
(N1
));
8767 E2
:= First
(Expressions
(N2
));
8768 while Present
(E1
) loop
8769 if not Same_Value
(E1
, E2
) then
8780 -- Fourth case, slice of same array with same bounds
8783 and then K2
= N_Slice
8784 and then Nkind
(Discrete_Range
(N1
)) = N_Range
8785 and then Nkind
(Discrete_Range
(N2
)) = N_Range
8786 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
8787 Low_Bound
(Discrete_Range
(N2
)))
8788 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
8789 High_Bound
(Discrete_Range
(N2
)))
8791 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
8793 -- All other cases, not clearly the same object
8804 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
8809 elsif not Is_Constrained
(T1
)
8810 and then not Is_Constrained
(T2
)
8811 and then Base_Type
(T1
) = Base_Type
(T2
)
8815 -- For now don't bother with case of identical constraints, to be
8816 -- fiddled with later on perhaps (this is only used for optimization
8817 -- purposes, so it is not critical to do a best possible job)
8828 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
8830 if Compile_Time_Known_Value
(Node1
)
8831 and then Compile_Time_Known_Value
(Node2
)
8832 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
8835 elsif Same_Object
(Node1
, Node2
) then
8842 ------------------------
8843 -- Scope_Is_Transient --
8844 ------------------------
8846 function Scope_Is_Transient
return Boolean is
8848 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
8849 end Scope_Is_Transient
;
8855 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
8860 while Scop
/= Standard_Standard
loop
8861 Scop
:= Scope
(Scop
);
8863 if Scop
= Scope2
then
8871 --------------------------
8872 -- Scope_Within_Or_Same --
8873 --------------------------
8875 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
8880 while Scop
/= Standard_Standard
loop
8881 if Scop
= Scope2
then
8884 Scop
:= Scope
(Scop
);
8889 end Scope_Within_Or_Same
;
8891 --------------------
8892 -- Set_Convention --
8893 --------------------
8895 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
8897 Basic_Set_Convention
(E
, Val
);
8900 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
8901 and then Has_Foreign_Convention
(E
)
8903 Set_Can_Use_Internal_Rep
(E
, False);
8907 ------------------------
8908 -- Set_Current_Entity --
8909 ------------------------
8911 -- The given entity is to be set as the currently visible definition
8912 -- of its associated name (i.e. the Node_Id associated with its name).
8913 -- All we have to do is to get the name from the identifier, and
8914 -- then set the associated Node_Id to point to the given entity.
8916 procedure Set_Current_Entity
(E
: Entity_Id
) is
8918 Set_Name_Entity_Id
(Chars
(E
), E
);
8919 end Set_Current_Entity
;
8921 ---------------------------
8922 -- Set_Debug_Info_Needed --
8923 ---------------------------
8925 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
8927 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
8928 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
8929 -- Used to set debug info in a related node if not set already
8931 --------------------------------------
8932 -- Set_Debug_Info_Needed_If_Not_Set --
8933 --------------------------------------
8935 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
8938 and then not Needs_Debug_Info
(E
)
8940 Set_Debug_Info_Needed
(E
);
8942 end Set_Debug_Info_Needed_If_Not_Set
;
8944 -- Start of processing for Set_Debug_Info_Needed
8947 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
8948 -- indicates that Debug_Info_Needed is never required for the entity.
8951 or else Debug_Info_Off
(T
)
8956 -- Set flag in entity itself. Note that we will go through the following
8957 -- circuitry even if the flag is already set on T. That's intentional,
8958 -- it makes sure that the flag will be set in subsidiary entities.
8960 Set_Needs_Debug_Info
(T
);
8962 -- Set flag on subsidiary entities if not set already
8964 if Is_Object
(T
) then
8965 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
8967 elsif Is_Type
(T
) then
8968 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
8970 if Is_Record_Type
(T
) then
8972 Ent
: Entity_Id
:= First_Entity
(T
);
8974 while Present
(Ent
) loop
8975 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
8980 elsif Is_Array_Type
(T
) then
8981 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
8984 Indx
: Node_Id
:= First_Index
(T
);
8986 while Present
(Indx
) loop
8987 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
8988 Indx
:= Next_Index
(Indx
);
8992 if Is_Packed
(T
) then
8993 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
8996 elsif Is_Access_Type
(T
) then
8997 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
8999 elsif Is_Private_Type
(T
) then
9000 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
9002 elsif Is_Protected_Type
(T
) then
9003 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
9006 end Set_Debug_Info_Needed
;
9008 ---------------------------------
9009 -- Set_Entity_With_Style_Check --
9010 ---------------------------------
9012 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
9013 Val_Actual
: Entity_Id
;
9017 Set_Entity
(N
, Val
);
9020 and then not Suppress_Style_Checks
(Val
)
9021 and then not In_Instance
9023 if Nkind
(N
) = N_Identifier
then
9025 elsif Nkind
(N
) = N_Expanded_Name
then
9026 Nod
:= Selector_Name
(N
);
9031 -- A special situation arises for derived operations, where we want
9032 -- to do the check against the parent (since the Sloc of the derived
9033 -- operation points to the derived type declaration itself).
9036 while not Comes_From_Source
(Val_Actual
)
9037 and then Nkind
(Val_Actual
) in N_Entity
9038 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
9039 or else Is_Subprogram
(Val_Actual
)
9040 or else Is_Generic_Subprogram
(Val_Actual
))
9041 and then Present
(Alias
(Val_Actual
))
9043 Val_Actual
:= Alias
(Val_Actual
);
9046 -- Renaming declarations for generic actuals do not come from source,
9047 -- and have a different name from that of the entity they rename, so
9048 -- there is no style check to perform here.
9050 if Chars
(Nod
) = Chars
(Val_Actual
) then
9051 Style
.Check_Identifier
(Nod
, Val_Actual
);
9055 Set_Entity
(N
, Val
);
9056 end Set_Entity_With_Style_Check
;
9058 ------------------------
9059 -- Set_Name_Entity_Id --
9060 ------------------------
9062 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
9064 Set_Name_Table_Info
(Id
, Int
(Val
));
9065 end Set_Name_Entity_Id
;
9067 ---------------------
9068 -- Set_Next_Actual --
9069 ---------------------
9071 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
9073 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
9074 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
9076 end Set_Next_Actual
;
9078 ----------------------------------
9079 -- Set_Optimize_Alignment_Flags --
9080 ----------------------------------
9082 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
9084 if Optimize_Alignment
= 'S' then
9085 Set_Optimize_Alignment_Space
(E
);
9086 elsif Optimize_Alignment
= 'T' then
9087 Set_Optimize_Alignment_Time
(E
);
9089 end Set_Optimize_Alignment_Flags
;
9091 -----------------------
9092 -- Set_Public_Status --
9093 -----------------------
9095 procedure Set_Public_Status
(Id
: Entity_Id
) is
9096 S
: constant Entity_Id
:= Current_Scope
;
9098 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
9099 -- Determines if E is defined within handled statement sequence or
9100 -- an if statement, returns True if so, False otherwise.
9102 ----------------------
9103 -- Within_HSS_Or_If --
9104 ----------------------
9106 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
9109 N
:= Declaration_Node
(E
);
9116 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
9122 end Within_HSS_Or_If
;
9124 -- Start of processing for Set_Public_Status
9127 -- Everything in the scope of Standard is public
9129 if S
= Standard_Standard
then
9132 -- Entity is definitely not public if enclosing scope is not public
9134 elsif not Is_Public
(S
) then
9137 -- An object or function declaration that occurs in a handled sequence
9138 -- of statements or within an if statement is the declaration for a
9139 -- temporary object or local subprogram generated by the expander. It
9140 -- never needs to be made public and furthermore, making it public can
9141 -- cause back end problems.
9143 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
9144 N_Function_Specification
)
9145 and then Within_HSS_Or_If
(Id
)
9149 -- Entities in public packages or records are public
9151 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
9154 -- The bounds of an entry family declaration can generate object
9155 -- declarations that are visible to the back-end, e.g. in the
9156 -- the declaration of a composite type that contains tasks.
9158 elsif Is_Concurrent_Type
(S
)
9159 and then not Has_Completion
(S
)
9160 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
9164 end Set_Public_Status
;
9166 -----------------------------
9167 -- Set_Referenced_Modified --
9168 -----------------------------
9170 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
9174 -- Deal with indexed or selected component where prefix is modified
9176 if Nkind
(N
) = N_Indexed_Component
9178 Nkind
(N
) = N_Selected_Component
9182 -- If prefix is access type, then it is the designated object that is
9183 -- being modified, which means we have no entity to set the flag on.
9185 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
9188 -- Otherwise chase the prefix
9191 Set_Referenced_Modified
(Pref
, Out_Param
);
9194 -- Otherwise see if we have an entity name (only other case to process)
9196 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
9197 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
9198 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
9200 end Set_Referenced_Modified
;
9202 ----------------------------
9203 -- Set_Scope_Is_Transient --
9204 ----------------------------
9206 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
9208 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
9209 end Set_Scope_Is_Transient
;
9215 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
9217 -- We copy Esize, but not RM_Size, since in general RM_Size is
9218 -- subtype specific and does not get inherited by all subtypes.
9220 Set_Esize
(T1
, Esize
(T2
));
9221 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
9223 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
9225 Is_Discrete_Or_Fixed_Point_Type
(T2
)
9227 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
9230 Set_Alignment
(T1
, Alignment
(T2
));
9233 --------------------
9234 -- Static_Integer --
9235 --------------------
9237 function Static_Integer
(N
: Node_Id
) return Uint
is
9239 Analyze_And_Resolve
(N
, Any_Integer
);
9242 or else Error_Posted
(N
)
9243 or else Etype
(N
) = Any_Type
9248 if Is_Static_Expression
(N
) then
9249 if not Raises_Constraint_Error
(N
) then
9250 return Expr_Value
(N
);
9255 elsif Etype
(N
) = Any_Type
then
9259 Flag_Non_Static_Expr
9260 ("static integer expression required here", N
);
9265 --------------------------
9266 -- Statically_Different --
9267 --------------------------
9269 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
9270 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
9271 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
9273 return Is_Entity_Name
(R1
)
9274 and then Is_Entity_Name
(R2
)
9275 and then Entity
(R1
) /= Entity
(R2
)
9276 and then not Is_Formal
(Entity
(R1
))
9277 and then not Is_Formal
(Entity
(R2
));
9278 end Statically_Different
;
9280 -----------------------------
9281 -- Subprogram_Access_Level --
9282 -----------------------------
9284 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
9286 if Present
(Alias
(Subp
)) then
9287 return Subprogram_Access_Level
(Alias
(Subp
));
9289 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
9291 end Subprogram_Access_Level
;
9297 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
9299 if Debug_Flag_W
then
9300 for J
in 0 .. Scope_Stack
.Last
loop
9305 Write_Name
(Chars
(E
));
9306 Write_Str
(" from ");
9307 Write_Location
(Sloc
(N
));
9312 -----------------------
9313 -- Transfer_Entities --
9314 -----------------------
9316 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
9317 Ent
: Entity_Id
:= First_Entity
(From
);
9324 if (Last_Entity
(To
)) = Empty
then
9325 Set_First_Entity
(To
, Ent
);
9327 Set_Next_Entity
(Last_Entity
(To
), Ent
);
9330 Set_Last_Entity
(To
, Last_Entity
(From
));
9332 while Present
(Ent
) loop
9333 Set_Scope
(Ent
, To
);
9335 if not Is_Public
(Ent
) then
9336 Set_Public_Status
(Ent
);
9339 and then Ekind
(Ent
) = E_Record_Subtype
9342 -- The components of the propagated Itype must be public
9348 Comp
:= First_Entity
(Ent
);
9349 while Present
(Comp
) loop
9350 Set_Is_Public
(Comp
);
9360 Set_First_Entity
(From
, Empty
);
9361 Set_Last_Entity
(From
, Empty
);
9362 end Transfer_Entities
;
9364 -----------------------
9365 -- Type_Access_Level --
9366 -----------------------
9368 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
9372 Btyp
:= Base_Type
(Typ
);
9374 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9375 -- simply use the level where the type is declared. This is true for
9376 -- stand-alone object declarations, and for anonymous access types
9377 -- associated with components the level is the same as that of the
9378 -- enclosing composite type. However, special treatment is needed for
9379 -- the cases of access parameters, return objects of an anonymous access
9380 -- type, and, in Ada 95, access discriminants of limited types.
9382 if Ekind
(Btyp
) in Access_Kind
then
9383 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
9385 -- If the type is a nonlocal anonymous access type (such as for
9386 -- an access parameter) we treat it as being declared at the
9387 -- library level to ensure that names such as X.all'access don't
9388 -- fail static accessibility checks.
9390 if not Is_Local_Anonymous_Access
(Typ
) then
9391 return Scope_Depth
(Standard_Standard
);
9393 -- If this is a return object, the accessibility level is that of
9394 -- the result subtype of the enclosing function. The test here is
9395 -- little complicated, because we have to account for extended
9396 -- return statements that have been rewritten as blocks, in which
9397 -- case we have to find and the Is_Return_Object attribute of the
9398 -- itype's associated object. It would be nice to find a way to
9399 -- simplify this test, but it doesn't seem worthwhile to add a new
9400 -- flag just for purposes of this test. ???
9402 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
9405 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
9406 N_Object_Declaration
9407 and then Is_Return_Object
9408 (Defining_Identifier
9409 (Associated_Node_For_Itype
(Btyp
))))
9415 Scop
:= Scope
(Scope
(Btyp
));
9416 while Present
(Scop
) loop
9417 exit when Ekind
(Scop
) = E_Function
;
9418 Scop
:= Scope
(Scop
);
9421 -- Treat the return object's type as having the level of the
9422 -- function's result subtype (as per RM05-6.5(5.3/2)).
9424 return Type_Access_Level
(Etype
(Scop
));
9429 Btyp
:= Root_Type
(Btyp
);
9431 -- The accessibility level of anonymous access types associated with
9432 -- discriminants is that of the current instance of the type, and
9433 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9435 -- AI-402: access discriminants have accessibility based on the
9436 -- object rather than the type in Ada 2005, so the above paragraph
9439 -- ??? Needs completion with rules from AI-416
9441 if Ada_Version
<= Ada_95
9442 and then Ekind
(Typ
) = E_Anonymous_Access_Type
9443 and then Present
(Associated_Node_For_Itype
(Typ
))
9444 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
9445 N_Discriminant_Specification
9447 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
9451 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
9452 end Type_Access_Level
;
9454 --------------------
9455 -- Ultimate_Alias --
9456 --------------------
9457 -- To do: add occurrences calling this new subprogram
9459 function Ultimate_Alias
(Prim
: Entity_Id
) return Entity_Id
is
9460 E
: Entity_Id
:= Prim
;
9463 while Present
(Alias
(E
)) loop
9470 --------------------------
9471 -- Unit_Declaration_Node --
9472 --------------------------
9474 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
9475 N
: Node_Id
:= Parent
(Unit_Id
);
9478 -- Predefined operators do not have a full function declaration
9480 if Ekind
(Unit_Id
) = E_Operator
then
9484 -- Isn't there some better way to express the following ???
9486 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
9487 and then Nkind
(N
) /= N_Formal_Package_Declaration
9488 and then Nkind
(N
) /= N_Function_Instantiation
9489 and then Nkind
(N
) /= N_Generic_Package_Declaration
9490 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
9491 and then Nkind
(N
) /= N_Package_Declaration
9492 and then Nkind
(N
) /= N_Package_Body
9493 and then Nkind
(N
) /= N_Package_Instantiation
9494 and then Nkind
(N
) /= N_Package_Renaming_Declaration
9495 and then Nkind
(N
) /= N_Procedure_Instantiation
9496 and then Nkind
(N
) /= N_Protected_Body
9497 and then Nkind
(N
) /= N_Subprogram_Declaration
9498 and then Nkind
(N
) /= N_Subprogram_Body
9499 and then Nkind
(N
) /= N_Subprogram_Body_Stub
9500 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
9501 and then Nkind
(N
) /= N_Task_Body
9502 and then Nkind
(N
) /= N_Task_Type_Declaration
9503 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
9504 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
9507 pragma Assert
(Present
(N
));
9511 end Unit_Declaration_Node
;
9513 ------------------------------
9514 -- Universal_Interpretation --
9515 ------------------------------
9517 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
9518 Index
: Interp_Index
;
9522 -- The argument may be a formal parameter of an operator or subprogram
9523 -- with multiple interpretations, or else an expression for an actual.
9525 if Nkind
(Opnd
) = N_Defining_Identifier
9526 or else not Is_Overloaded
(Opnd
)
9528 if Etype
(Opnd
) = Universal_Integer
9529 or else Etype
(Opnd
) = Universal_Real
9531 return Etype
(Opnd
);
9537 Get_First_Interp
(Opnd
, Index
, It
);
9538 while Present
(It
.Typ
) loop
9539 if It
.Typ
= Universal_Integer
9540 or else It
.Typ
= Universal_Real
9545 Get_Next_Interp
(Index
, It
);
9550 end Universal_Interpretation
;
9556 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
9558 -- Recurse to handle unlikely case of multiple levels of qualification
9560 if Nkind
(Expr
) = N_Qualified_Expression
then
9561 return Unqualify
(Expression
(Expr
));
9563 -- Normal case, not a qualified expression
9570 ----------------------
9571 -- Within_Init_Proc --
9572 ----------------------
9574 function Within_Init_Proc
return Boolean is
9579 while not Is_Overloadable
(S
) loop
9580 if S
= Standard_Standard
then
9587 return Is_Init_Proc
(S
);
9588 end Within_Init_Proc
;
9594 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
9595 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
9596 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
9598 function Has_One_Matching_Field
return Boolean;
9599 -- Determines if Expec_Type is a record type with a single component or
9600 -- discriminant whose type matches the found type or is one dimensional
9601 -- array whose component type matches the found type.
9603 ----------------------------
9604 -- Has_One_Matching_Field --
9605 ----------------------------
9607 function Has_One_Matching_Field
return Boolean is
9611 if Is_Array_Type
(Expec_Type
)
9612 and then Number_Dimensions
(Expec_Type
) = 1
9614 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
9618 elsif not Is_Record_Type
(Expec_Type
) then
9622 E
:= First_Entity
(Expec_Type
);
9627 elsif (Ekind
(E
) /= E_Discriminant
9628 and then Ekind
(E
) /= E_Component
)
9629 or else (Chars
(E
) = Name_uTag
9630 or else Chars
(E
) = Name_uParent
)
9639 if not Covers
(Etype
(E
), Found_Type
) then
9642 elsif Present
(Next_Entity
(E
)) then
9649 end Has_One_Matching_Field
;
9651 -- Start of processing for Wrong_Type
9654 -- Don't output message if either type is Any_Type, or if a message
9655 -- has already been posted for this node. We need to do the latter
9656 -- check explicitly (it is ordinarily done in Errout), because we
9657 -- are using ! to force the output of the error messages.
9659 if Expec_Type
= Any_Type
9660 or else Found_Type
= Any_Type
9661 or else Error_Posted
(Expr
)
9665 -- In an instance, there is an ongoing problem with completion of
9666 -- type derived from private types. Their structure is what Gigi
9667 -- expects, but the Etype is the parent type rather than the
9668 -- derived private type itself. Do not flag error in this case. The
9669 -- private completion is an entity without a parent, like an Itype.
9670 -- Similarly, full and partial views may be incorrect in the instance.
9671 -- There is no simple way to insure that it is consistent ???
9673 elsif In_Instance
then
9674 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
9676 (Has_Private_Declaration
(Expected_Type
)
9677 or else Has_Private_Declaration
(Etype
(Expr
)))
9678 and then No
(Parent
(Expected_Type
))
9684 -- An interesting special check. If the expression is parenthesized
9685 -- and its type corresponds to the type of the sole component of the
9686 -- expected record type, or to the component type of the expected one
9687 -- dimensional array type, then assume we have a bad aggregate attempt.
9689 if Nkind
(Expr
) in N_Subexpr
9690 and then Paren_Count
(Expr
) /= 0
9691 and then Has_One_Matching_Field
9693 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
9695 -- Another special check, if we are looking for a pool-specific access
9696 -- type and we found an E_Access_Attribute_Type, then we have the case
9697 -- of an Access attribute being used in a context which needs a pool-
9698 -- specific type, which is never allowed. The one extra check we make
9699 -- is that the expected designated type covers the Found_Type.
9701 elsif Is_Access_Type
(Expec_Type
)
9702 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
9703 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
9704 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
9706 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
9708 Error_Msg_N
("result must be general access type!", Expr
);
9709 Error_Msg_NE
("add ALL to }!", Expr
, Expec_Type
);
9711 -- Another special check, if the expected type is an integer type,
9712 -- but the expression is of type System.Address, and the parent is
9713 -- an addition or subtraction operation whose left operand is the
9714 -- expression in question and whose right operand is of an integral
9715 -- type, then this is an attempt at address arithmetic, so give
9716 -- appropriate message.
9718 elsif Is_Integer_Type
(Expec_Type
)
9719 and then Is_RTE
(Found_Type
, RE_Address
)
9720 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
9722 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
9723 and then Expr
= Left_Opnd
(Parent
(Expr
))
9724 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
9727 ("address arithmetic not predefined in package System",
9730 ("\possible missing with/use of System.Storage_Elements",
9734 -- If the expected type is an anonymous access type, as for access
9735 -- parameters and discriminants, the error is on the designated types.
9737 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
9738 if Comes_From_Source
(Expec_Type
) then
9739 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
9742 ("expected an access type with designated}",
9743 Expr
, Designated_Type
(Expec_Type
));
9746 if Is_Access_Type
(Found_Type
)
9747 and then not Comes_From_Source
(Found_Type
)
9750 ("\\found an access type with designated}!",
9751 Expr
, Designated_Type
(Found_Type
));
9753 if From_With_Type
(Found_Type
) then
9754 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
9755 Error_Msg_Qual_Level
:= 99;
9756 Error_Msg_NE
("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
9757 Error_Msg_Qual_Level
:= 0;
9759 Error_Msg_NE
("found}!", Expr
, Found_Type
);
9763 -- Normal case of one type found, some other type expected
9766 -- If the names of the two types are the same, see if some number
9767 -- of levels of qualification will help. Don't try more than three
9768 -- levels, and if we get to standard, it's no use (and probably
9769 -- represents an error in the compiler) Also do not bother with
9770 -- internal scope names.
9773 Expec_Scope
: Entity_Id
;
9774 Found_Scope
: Entity_Id
;
9777 Expec_Scope
:= Expec_Type
;
9778 Found_Scope
:= Found_Type
;
9780 for Levels
in Int
range 0 .. 3 loop
9781 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
9782 Error_Msg_Qual_Level
:= Levels
;
9786 Expec_Scope
:= Scope
(Expec_Scope
);
9787 Found_Scope
:= Scope
(Found_Scope
);
9789 exit when Expec_Scope
= Standard_Standard
9790 or else Found_Scope
= Standard_Standard
9791 or else not Comes_From_Source
(Expec_Scope
)
9792 or else not Comes_From_Source
(Found_Scope
);
9796 if Is_Record_Type
(Expec_Type
)
9797 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
9799 Error_Msg_NE
("expected}!", Expr
,
9800 Corresponding_Remote_Type
(Expec_Type
));
9802 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
9805 if Is_Entity_Name
(Expr
)
9806 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
9808 Error_Msg_N
("\\found package name!", Expr
);
9810 elsif Is_Entity_Name
(Expr
)
9812 (Ekind
(Entity
(Expr
)) = E_Procedure
9814 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
9816 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
9818 ("found procedure name, possibly missing Access attribute!",
9822 ("\\found procedure name instead of function!", Expr
);
9825 elsif Nkind
(Expr
) = N_Function_Call
9826 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
9827 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
9828 and then No
(Parameter_Associations
(Expr
))
9831 ("found function name, possibly missing Access attribute!",
9834 -- Catch common error: a prefix or infix operator which is not
9835 -- directly visible because the type isn't.
9837 elsif Nkind
(Expr
) in N_Op
9838 and then Is_Overloaded
(Expr
)
9839 and then not Is_Immediately_Visible
(Expec_Type
)
9840 and then not Is_Potentially_Use_Visible
(Expec_Type
)
9841 and then not In_Use
(Expec_Type
)
9842 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
9845 ("operator of the type is not directly visible!", Expr
);
9847 elsif Ekind
(Found_Type
) = E_Void
9848 and then Present
(Parent
(Found_Type
))
9849 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
9851 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
9854 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
9857 Error_Msg_Qual_Level
:= 0;