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_Tss
; use Exp_Tss
;
33 with Exp_Util
; use Exp_Util
;
34 with Fname
; use Fname
;
35 with Freeze
; use Freeze
;
37 with Lib
.Xref
; use Lib
.Xref
;
38 with Nlists
; use Nlists
;
39 with Output
; use Output
;
41 with Rtsfind
; use Rtsfind
;
42 with Scans
; use Scans
;
45 with Sem_Attr
; use Sem_Attr
;
46 with Sem_Ch6
; use Sem_Ch6
;
47 with Sem_Ch8
; use Sem_Ch8
;
48 with Sem_Eval
; use Sem_Eval
;
49 with Sem_Res
; use Sem_Res
;
50 with Sem_Type
; use Sem_Type
;
51 with Sinfo
; use Sinfo
;
52 with Sinput
; use Sinput
;
53 with 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 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
103 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
104 Nod
:= Type_Definition
(Parent
(Typ
));
106 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
107 if Present
(Full_View
(Typ
)) then
108 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
110 -- If the full-view is not available we cannot do anything else
111 -- here (the source has errors).
117 -- Support for generic formals with interfaces is still missing ???
119 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
124 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
128 elsif Ekind
(Typ
) = E_Record_Subtype
then
129 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
131 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
133 -- Recurse, because parent may still be a private extension. Also
134 -- note that the full view of the subtype or the full view of its
135 -- base type may (both) be unavailable.
137 return Abstract_Interface_List
(Etype
(Typ
));
139 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
140 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
141 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
143 Nod
:= Type_Definition
(Parent
(Typ
));
147 return Interface_List
(Nod
);
148 end Abstract_Interface_List
;
150 --------------------------------
151 -- Add_Access_Type_To_Process --
152 --------------------------------
154 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
158 Ensure_Freeze_Node
(E
);
159 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
163 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
167 end Add_Access_Type_To_Process
;
169 ----------------------------
170 -- Add_Global_Declaration --
171 ----------------------------
173 procedure Add_Global_Declaration
(N
: Node_Id
) is
174 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
177 if No
(Declarations
(Aux_Node
)) then
178 Set_Declarations
(Aux_Node
, New_List
);
181 Append_To
(Declarations
(Aux_Node
), N
);
183 end Add_Global_Declaration
;
185 -----------------------
186 -- Alignment_In_Bits --
187 -----------------------
189 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
191 return Alignment
(E
) * System_Storage_Unit
;
192 end Alignment_In_Bits
;
194 -----------------------------------------
195 -- Apply_Compile_Time_Constraint_Error --
196 -----------------------------------------
198 procedure Apply_Compile_Time_Constraint_Error
201 Reason
: RT_Exception_Code
;
202 Ent
: Entity_Id
:= Empty
;
203 Typ
: Entity_Id
:= Empty
;
204 Loc
: Source_Ptr
:= No_Location
;
205 Rep
: Boolean := True;
206 Warn
: Boolean := False)
208 Stat
: constant Boolean := Is_Static_Expression
(N
);
209 R_Stat
: constant Node_Id
:=
210 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
221 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
227 -- Now we replace the node by an N_Raise_Constraint_Error node
228 -- This does not need reanalyzing, so set it as analyzed now.
231 Set_Analyzed
(N
, True);
234 Set_Raises_Constraint_Error
(N
);
236 -- If the original expression was marked as static, the result is
237 -- still marked as static, but the Raises_Constraint_Error flag is
238 -- always set so that further static evaluation is not attempted.
241 Set_Is_Static_Expression
(N
);
243 end Apply_Compile_Time_Constraint_Error
;
245 --------------------------
246 -- Build_Actual_Subtype --
247 --------------------------
249 function Build_Actual_Subtype
251 N
: Node_Or_Entity_Id
) return Node_Id
254 -- Normally Sloc (N), but may point to corresponding body in some cases
256 Constraints
: List_Id
;
262 Disc_Type
: Entity_Id
;
268 if Nkind
(N
) = N_Defining_Identifier
then
269 Obj
:= New_Reference_To
(N
, Loc
);
271 -- If this is a formal parameter of a subprogram declaration, and
272 -- we are compiling the body, we want the declaration for the
273 -- actual subtype to carry the source position of the body, to
274 -- prevent anomalies in gdb when stepping through the code.
276 if Is_Formal
(N
) then
278 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
280 if Nkind
(Decl
) = N_Subprogram_Declaration
281 and then Present
(Corresponding_Body
(Decl
))
283 Loc
:= Sloc
(Corresponding_Body
(Decl
));
292 if Is_Array_Type
(T
) then
293 Constraints
:= New_List
;
294 for J
in 1 .. Number_Dimensions
(T
) loop
296 -- Build an array subtype declaration with the nominal subtype and
297 -- the bounds of the actual. Add the declaration in front of the
298 -- local declarations for the subprogram, for analysis before any
299 -- reference to the formal in the body.
302 Make_Attribute_Reference
(Loc
,
304 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
305 Attribute_Name
=> Name_First
,
306 Expressions
=> New_List
(
307 Make_Integer_Literal
(Loc
, J
)));
310 Make_Attribute_Reference
(Loc
,
312 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
313 Attribute_Name
=> Name_Last
,
314 Expressions
=> New_List
(
315 Make_Integer_Literal
(Loc
, J
)));
317 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
320 -- If the type has unknown discriminants there is no constrained
321 -- subtype to build. This is never called for a formal or for a
322 -- lhs, so returning the type is ok ???
324 elsif Has_Unknown_Discriminants
(T
) then
328 Constraints
:= New_List
;
330 -- Type T is a generic derived type, inherit the discriminants from
333 if Is_Private_Type
(T
)
334 and then No
(Full_View
(T
))
336 -- T was flagged as an error if it was declared as a formal
337 -- derived type with known discriminants. In this case there
338 -- is no need to look at the parent type since T already carries
339 -- its own discriminants.
341 and then not Error_Posted
(T
)
343 Disc_Type
:= Etype
(Base_Type
(T
));
348 Discr
:= First_Discriminant
(Disc_Type
);
349 while Present
(Discr
) loop
350 Append_To
(Constraints
,
351 Make_Selected_Component
(Loc
,
353 Duplicate_Subexpr_No_Checks
(Obj
),
354 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
355 Next_Discriminant
(Discr
);
360 Make_Defining_Identifier
(Loc
,
361 Chars
=> New_Internal_Name
('S'));
362 Set_Is_Internal
(Subt
);
365 Make_Subtype_Declaration
(Loc
,
366 Defining_Identifier
=> Subt
,
367 Subtype_Indication
=>
368 Make_Subtype_Indication
(Loc
,
369 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
371 Make_Index_Or_Discriminant_Constraint
(Loc
,
372 Constraints
=> Constraints
)));
374 Mark_Rewrite_Insertion
(Decl
);
376 end Build_Actual_Subtype
;
378 ---------------------------------------
379 -- Build_Actual_Subtype_Of_Component --
380 ---------------------------------------
382 function Build_Actual_Subtype_Of_Component
384 N
: Node_Id
) return Node_Id
386 Loc
: constant Source_Ptr
:= Sloc
(N
);
387 P
: constant Node_Id
:= Prefix
(N
);
390 Indx_Type
: Entity_Id
;
392 Deaccessed_T
: Entity_Id
;
393 -- This is either a copy of T, or if T is an access type, then it is
394 -- the directly designated type of this access type.
396 function Build_Actual_Array_Constraint
return List_Id
;
397 -- If one or more of the bounds of the component depends on
398 -- discriminants, build actual constraint using the discriminants
401 function Build_Actual_Record_Constraint
return List_Id
;
402 -- Similar to previous one, for discriminated components constrained
403 -- by the discriminant of the enclosing object.
405 -----------------------------------
406 -- Build_Actual_Array_Constraint --
407 -----------------------------------
409 function Build_Actual_Array_Constraint
return List_Id
is
410 Constraints
: constant List_Id
:= New_List
;
418 Indx
:= First_Index
(Deaccessed_T
);
419 while Present
(Indx
) loop
420 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
421 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
423 if Denotes_Discriminant
(Old_Lo
) then
425 Make_Selected_Component
(Loc
,
426 Prefix
=> New_Copy_Tree
(P
),
427 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
430 Lo
:= New_Copy_Tree
(Old_Lo
);
432 -- The new bound will be reanalyzed in the enclosing
433 -- declaration. For literal bounds that come from a type
434 -- declaration, the type of the context must be imposed, so
435 -- insure that analysis will take place. For non-universal
436 -- types this is not strictly necessary.
438 Set_Analyzed
(Lo
, False);
441 if Denotes_Discriminant
(Old_Hi
) then
443 Make_Selected_Component
(Loc
,
444 Prefix
=> New_Copy_Tree
(P
),
445 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
448 Hi
:= New_Copy_Tree
(Old_Hi
);
449 Set_Analyzed
(Hi
, False);
452 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
457 end Build_Actual_Array_Constraint
;
459 ------------------------------------
460 -- Build_Actual_Record_Constraint --
461 ------------------------------------
463 function Build_Actual_Record_Constraint
return List_Id
is
464 Constraints
: constant List_Id
:= New_List
;
469 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
470 while Present
(D
) loop
471 if Denotes_Discriminant
(Node
(D
)) then
472 D_Val
:= Make_Selected_Component
(Loc
,
473 Prefix
=> New_Copy_Tree
(P
),
474 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
477 D_Val
:= New_Copy_Tree
(Node
(D
));
480 Append
(D_Val
, Constraints
);
485 end Build_Actual_Record_Constraint
;
487 -- Start of processing for Build_Actual_Subtype_Of_Component
490 -- Why the test for Spec_Expression mode here???
492 if In_Spec_Expression
then
495 -- More comments for the rest of this body would be good ???
497 elsif Nkind
(N
) = N_Explicit_Dereference
then
498 if Is_Composite_Type
(T
)
499 and then not Is_Constrained
(T
)
500 and then not (Is_Class_Wide_Type
(T
)
501 and then Is_Constrained
(Root_Type
(T
)))
502 and then not Has_Unknown_Discriminants
(T
)
504 -- If the type of the dereference is already constrained, it
505 -- is an actual subtype.
507 if Is_Array_Type
(Etype
(N
))
508 and then Is_Constrained
(Etype
(N
))
512 Remove_Side_Effects
(P
);
513 return Build_Actual_Subtype
(T
, N
);
520 if Ekind
(T
) = E_Access_Subtype
then
521 Deaccessed_T
:= Designated_Type
(T
);
526 if Ekind
(Deaccessed_T
) = E_Array_Subtype
then
527 Id
:= First_Index
(Deaccessed_T
);
528 while Present
(Id
) loop
529 Indx_Type
:= Underlying_Type
(Etype
(Id
));
531 if Denotes_Discriminant
(Type_Low_Bound
(Indx_Type
))
533 Denotes_Discriminant
(Type_High_Bound
(Indx_Type
))
535 Remove_Side_Effects
(P
);
537 Build_Component_Subtype
538 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
544 elsif Is_Composite_Type
(Deaccessed_T
)
545 and then Has_Discriminants
(Deaccessed_T
)
546 and then not Has_Unknown_Discriminants
(Deaccessed_T
)
548 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
549 while Present
(D
) loop
550 if Denotes_Discriminant
(Node
(D
)) then
551 Remove_Side_Effects
(P
);
553 Build_Component_Subtype
(
554 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
561 -- If none of the above, the actual and nominal subtypes are the same
564 end Build_Actual_Subtype_Of_Component
;
566 -----------------------------
567 -- Build_Component_Subtype --
568 -----------------------------
570 function Build_Component_Subtype
573 T
: Entity_Id
) return Node_Id
579 -- Unchecked_Union components do not require component subtypes
581 if Is_Unchecked_Union
(T
) then
586 Make_Defining_Identifier
(Loc
,
587 Chars
=> New_Internal_Name
('S'));
588 Set_Is_Internal
(Subt
);
591 Make_Subtype_Declaration
(Loc
,
592 Defining_Identifier
=> Subt
,
593 Subtype_Indication
=>
594 Make_Subtype_Indication
(Loc
,
595 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
597 Make_Index_Or_Discriminant_Constraint
(Loc
,
600 Mark_Rewrite_Insertion
(Decl
);
602 end Build_Component_Subtype
;
604 ---------------------------
605 -- Build_Default_Subtype --
606 ---------------------------
608 function Build_Default_Subtype
610 N
: Node_Id
) return Entity_Id
612 Loc
: constant Source_Ptr
:= Sloc
(N
);
616 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
620 Disc
:= First_Discriminant
(T
);
622 if No
(Discriminant_Default_Value
(Disc
)) then
627 Act
: constant Entity_Id
:=
628 Make_Defining_Identifier
(Loc
,
629 Chars
=> New_Internal_Name
('S'));
631 Constraints
: constant List_Id
:= New_List
;
635 while Present
(Disc
) loop
636 Append_To
(Constraints
,
637 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
638 Next_Discriminant
(Disc
);
642 Make_Subtype_Declaration
(Loc
,
643 Defining_Identifier
=> Act
,
644 Subtype_Indication
=>
645 Make_Subtype_Indication
(Loc
,
646 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
648 Make_Index_Or_Discriminant_Constraint
(Loc
,
649 Constraints
=> Constraints
)));
651 Insert_Action
(N
, Decl
);
655 end Build_Default_Subtype
;
657 --------------------------------------------
658 -- Build_Discriminal_Subtype_Of_Component --
659 --------------------------------------------
661 function Build_Discriminal_Subtype_Of_Component
662 (T
: Entity_Id
) return Node_Id
664 Loc
: constant Source_Ptr
:= Sloc
(T
);
668 function Build_Discriminal_Array_Constraint
return List_Id
;
669 -- If one or more of the bounds of the component depends on
670 -- discriminants, build actual constraint using the discriminants
673 function Build_Discriminal_Record_Constraint
return List_Id
;
674 -- Similar to previous one, for discriminated components constrained
675 -- by the discriminant of the enclosing object.
677 ----------------------------------------
678 -- Build_Discriminal_Array_Constraint --
679 ----------------------------------------
681 function Build_Discriminal_Array_Constraint
return List_Id
is
682 Constraints
: constant List_Id
:= New_List
;
690 Indx
:= First_Index
(T
);
691 while Present
(Indx
) loop
692 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
693 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
695 if Denotes_Discriminant
(Old_Lo
) then
696 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
699 Lo
:= New_Copy_Tree
(Old_Lo
);
702 if Denotes_Discriminant
(Old_Hi
) then
703 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
706 Hi
:= New_Copy_Tree
(Old_Hi
);
709 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
714 end Build_Discriminal_Array_Constraint
;
716 -----------------------------------------
717 -- Build_Discriminal_Record_Constraint --
718 -----------------------------------------
720 function Build_Discriminal_Record_Constraint
return List_Id
is
721 Constraints
: constant List_Id
:= New_List
;
726 D
:= First_Elmt
(Discriminant_Constraint
(T
));
727 while Present
(D
) loop
728 if Denotes_Discriminant
(Node
(D
)) then
730 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
733 D_Val
:= New_Copy_Tree
(Node
(D
));
736 Append
(D_Val
, Constraints
);
741 end Build_Discriminal_Record_Constraint
;
743 -- Start of processing for Build_Discriminal_Subtype_Of_Component
746 if Ekind
(T
) = E_Array_Subtype
then
747 Id
:= First_Index
(T
);
748 while Present
(Id
) loop
749 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
750 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
752 return Build_Component_Subtype
753 (Build_Discriminal_Array_Constraint
, Loc
, T
);
759 elsif Ekind
(T
) = E_Record_Subtype
760 and then Has_Discriminants
(T
)
761 and then not Has_Unknown_Discriminants
(T
)
763 D
:= First_Elmt
(Discriminant_Constraint
(T
));
764 while Present
(D
) loop
765 if Denotes_Discriminant
(Node
(D
)) then
766 return Build_Component_Subtype
767 (Build_Discriminal_Record_Constraint
, Loc
, T
);
774 -- If none of the above, the actual and nominal subtypes are the same
777 end Build_Discriminal_Subtype_Of_Component
;
779 ------------------------------
780 -- Build_Elaboration_Entity --
781 ------------------------------
783 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
784 Loc
: constant Source_Ptr
:= Sloc
(N
);
786 Elab_Ent
: Entity_Id
;
788 procedure Set_Package_Name
(Ent
: Entity_Id
);
789 -- Given an entity, sets the fully qualified name of the entity in
790 -- Name_Buffer, with components separated by double underscores. This
791 -- is a recursive routine that climbs the scope chain to Standard.
793 ----------------------
794 -- Set_Package_Name --
795 ----------------------
797 procedure Set_Package_Name
(Ent
: Entity_Id
) is
799 if Scope
(Ent
) /= Standard_Standard
then
800 Set_Package_Name
(Scope
(Ent
));
803 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
805 Name_Buffer
(Name_Len
+ 1) := '_';
806 Name_Buffer
(Name_Len
+ 2) := '_';
807 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
808 Name_Len
:= Name_Len
+ Nam
'Length + 2;
812 Get_Name_String
(Chars
(Ent
));
814 end Set_Package_Name
;
816 -- Start of processing for Build_Elaboration_Entity
819 -- Ignore if already constructed
821 if Present
(Elaboration_Entity
(Spec_Id
)) then
825 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
826 -- name with dots replaced by double underscore. We have to manually
827 -- construct this name, since it will be elaborated in the outer scope,
828 -- and thus will not have the unit name automatically prepended.
830 Set_Package_Name
(Spec_Id
);
834 Name_Buffer
(Name_Len
+ 1) := '_';
835 Name_Buffer
(Name_Len
+ 2) := 'E';
836 Name_Len
:= Name_Len
+ 2;
838 -- Create elaboration flag
841 Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
842 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
845 Make_Object_Declaration
(Loc
,
846 Defining_Identifier
=> Elab_Ent
,
848 New_Occurrence_Of
(Standard_Boolean
, Loc
),
850 New_Occurrence_Of
(Standard_False
, Loc
));
852 Push_Scope
(Standard_Standard
);
853 Add_Global_Declaration
(Decl
);
856 -- Reset True_Constant indication, since we will indeed assign a value
857 -- to the variable in the binder main. We also kill the Current_Value
858 -- and Last_Assignment fields for the same reason.
860 Set_Is_True_Constant
(Elab_Ent
, False);
861 Set_Current_Value
(Elab_Ent
, Empty
);
862 Set_Last_Assignment
(Elab_Ent
, Empty
);
864 -- We do not want any further qualification of the name (if we did
865 -- not do this, we would pick up the name of the generic package
866 -- in the case of a library level generic instantiation).
868 Set_Has_Qualified_Name
(Elab_Ent
);
869 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
870 end Build_Elaboration_Entity
;
872 -----------------------------------
873 -- Cannot_Raise_Constraint_Error --
874 -----------------------------------
876 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
878 if Compile_Time_Known_Value
(Expr
) then
881 elsif Do_Range_Check
(Expr
) then
884 elsif Raises_Constraint_Error
(Expr
) then
892 when N_Expanded_Name
=>
895 when N_Selected_Component
=>
896 return not Do_Discriminant_Check
(Expr
);
898 when N_Attribute_Reference
=>
899 if Do_Overflow_Check
(Expr
) then
902 elsif No
(Expressions
(Expr
)) then
910 N
:= First
(Expressions
(Expr
));
911 while Present
(N
) loop
912 if Cannot_Raise_Constraint_Error
(N
) then
923 when N_Type_Conversion
=>
924 if Do_Overflow_Check
(Expr
)
925 or else Do_Length_Check
(Expr
)
926 or else Do_Tag_Check
(Expr
)
931 Cannot_Raise_Constraint_Error
(Expression
(Expr
));
934 when N_Unchecked_Type_Conversion
=>
935 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
938 if Do_Overflow_Check
(Expr
) then
942 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
949 if Do_Division_Check
(Expr
)
950 or else Do_Overflow_Check
(Expr
)
955 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
957 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
976 N_Op_Shift_Right_Arithmetic |
980 if Do_Overflow_Check
(Expr
) then
984 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
986 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
993 end Cannot_Raise_Constraint_Error
;
995 --------------------------
996 -- Check_Fully_Declared --
997 --------------------------
999 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1001 if Ekind
(T
) = E_Incomplete_Type
then
1003 -- Ada 2005 (AI-50217): If the type is available through a limited
1004 -- with_clause, verify that its full view has been analyzed.
1006 if From_With_Type
(T
)
1007 and then Present
(Non_Limited_View
(T
))
1008 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1010 -- The non-limited view is fully declared
1015 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1018 -- Need comments for these tests ???
1020 elsif Has_Private_Component
(T
)
1021 and then not Is_Generic_Type
(Root_Type
(T
))
1022 and then not In_Spec_Expression
1024 -- Special case: if T is the anonymous type created for a single
1025 -- task or protected object, use the name of the source object.
1027 if Is_Concurrent_Type
(T
)
1028 and then not Comes_From_Source
(T
)
1029 and then Nkind
(N
) = N_Object_Declaration
1031 Error_Msg_NE
("type of& has incomplete component", N
,
1032 Defining_Identifier
(N
));
1036 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1039 end Check_Fully_Declared
;
1041 -------------------------
1042 -- Check_Nested_Access --
1043 -------------------------
1045 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
1046 Scop
: constant Entity_Id
:= Current_Scope
;
1047 Current_Subp
: Entity_Id
;
1048 Enclosing
: Entity_Id
;
1051 -- Currently only enabled for VM back-ends for efficiency, should we
1052 -- enable it more systematically ???
1054 -- Check for Is_Imported needs commenting below ???
1056 if VM_Target
/= No_VM
1057 and then (Ekind
(Ent
) = E_Variable
1059 Ekind
(Ent
) = E_Constant
1061 Ekind
(Ent
) = E_Loop_Parameter
)
1062 and then Scope
(Ent
) /= Empty
1063 and then not Is_Library_Level_Entity
(Ent
)
1064 and then not Is_Imported
(Ent
)
1066 if Is_Subprogram
(Scop
)
1067 or else Is_Generic_Subprogram
(Scop
)
1068 or else Is_Entry
(Scop
)
1070 Current_Subp
:= Scop
;
1072 Current_Subp
:= Current_Subprogram
;
1075 Enclosing
:= Enclosing_Subprogram
(Ent
);
1077 if Enclosing
/= Empty
1078 and then Enclosing
/= Current_Subp
1080 Set_Has_Up_Level_Access
(Ent
, True);
1083 end Check_Nested_Access
;
1085 ------------------------------------------
1086 -- Check_Potentially_Blocking_Operation --
1087 ------------------------------------------
1089 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
1092 -- N is one of the potentially blocking operations listed in 9.5.1(8).
1093 -- When pragma Detect_Blocking is active, the run time will raise
1094 -- Program_Error. Here we only issue a warning, since we generally
1095 -- support the use of potentially blocking operations in the absence
1098 -- Indirect blocking through a subprogram call cannot be diagnosed
1099 -- statically without interprocedural analysis, so we do not attempt
1102 S
:= Scope
(Current_Scope
);
1103 while Present
(S
) and then S
/= Standard_Standard
loop
1104 if Is_Protected_Type
(S
) then
1106 ("potentially blocking operation in protected operation?", N
);
1113 end Check_Potentially_Blocking_Operation
;
1115 ------------------------------
1116 -- Check_Unprotected_Access --
1117 ------------------------------
1119 procedure Check_Unprotected_Access
1123 Cont_Encl_Typ
: Entity_Id
;
1124 Pref_Encl_Typ
: Entity_Id
;
1126 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
1127 -- Check whether Obj is a private component of a protected object.
1128 -- Return the protected type where the component resides, Empty
1131 function Is_Public_Operation
return Boolean;
1132 -- Verify that the enclosing operation is callable from outside the
1133 -- protected object, to minimize false positives.
1135 ------------------------------
1136 -- Enclosing_Protected_Type --
1137 ------------------------------
1139 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
1141 if Is_Entity_Name
(Obj
) then
1143 Ent
: Entity_Id
:= Entity
(Obj
);
1146 -- The object can be a renaming of a private component, use
1147 -- the original record component.
1149 if Is_Prival
(Ent
) then
1150 Ent
:= Prival_Link
(Ent
);
1153 if Is_Protected_Type
(Scope
(Ent
)) then
1159 -- For indexed and selected components, recursively check the prefix
1161 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
1162 return Enclosing_Protected_Type
(Prefix
(Obj
));
1164 -- The object does not denote a protected component
1169 end Enclosing_Protected_Type
;
1171 -------------------------
1172 -- Is_Public_Operation --
1173 -------------------------
1175 function Is_Public_Operation
return Boolean is
1182 and then S
/= Pref_Encl_Typ
1184 if Scope
(S
) = Pref_Encl_Typ
then
1185 E
:= First_Entity
(Pref_Encl_Typ
);
1187 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
1200 end Is_Public_Operation
;
1202 -- Start of processing for Check_Unprotected_Access
1205 if Nkind
(Expr
) = N_Attribute_Reference
1206 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
1208 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
1209 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
1211 -- Check whether we are trying to export a protected component to a
1212 -- context with an equal or lower access level.
1214 if Present
(Pref_Encl_Typ
)
1215 and then No
(Cont_Encl_Typ
)
1216 and then Is_Public_Operation
1217 and then Scope_Depth
(Pref_Encl_Typ
) >=
1218 Object_Access_Level
(Context
)
1221 ("?possible unprotected access to protected data", Expr
);
1224 end Check_Unprotected_Access
;
1230 procedure Check_VMS
(Construct
: Node_Id
) is
1232 if not OpenVMS_On_Target
then
1234 ("this construct is allowed only in Open'V'M'S", Construct
);
1238 ---------------------------------
1239 -- Collect_Abstract_Interfaces --
1240 ---------------------------------
1242 procedure Collect_Abstract_Interfaces
1244 Ifaces_List
: out Elist_Id
;
1245 Exclude_Parent_Interfaces
: Boolean := False;
1246 Use_Full_View
: Boolean := True)
1248 procedure Add_Interface
(Iface
: Entity_Id
);
1249 -- Add the interface it if is not already in the list
1251 procedure Collect
(Typ
: Entity_Id
);
1252 -- Subsidiary subprogram used to traverse the whole list
1253 -- of directly and indirectly implemented interfaces
1255 function Interface_Present_In_Parent
1257 Iface
: Entity_Id
) return Boolean;
1258 -- Typ must be a tagged record type/subtype and Iface must be an
1259 -- abstract interface type. This function is used to check if Typ
1260 -- or some parent of Typ implements Iface.
1266 procedure Add_Interface
(Iface
: Entity_Id
) is
1270 Elmt
:= First_Elmt
(Ifaces_List
);
1271 while Present
(Elmt
) and then Node
(Elmt
) /= Iface
loop
1276 Append_Elmt
(Iface
, Ifaces_List
);
1284 procedure Collect
(Typ
: Entity_Id
) is
1285 Ancestor
: Entity_Id
;
1287 Iface_List
: List_Id
;
1294 -- Handle private types
1297 and then Is_Private_Type
(Typ
)
1298 and then Present
(Full_View
(Typ
))
1300 Full_T
:= Full_View
(Typ
);
1303 Iface_List
:= Abstract_Interface_List
(Full_T
);
1305 -- Include the ancestor if we are generating the whole list of
1306 -- abstract interfaces.
1308 -- In concurrent types the ancestor interface (if any) is the
1309 -- first element of the list of interface types.
1311 if Is_Concurrent_Type
(Full_T
)
1312 or else Is_Concurrent_Record_Type
(Full_T
)
1314 if Is_Non_Empty_List
(Iface_List
) then
1315 Ancestor
:= Etype
(First
(Iface_List
));
1318 if not Exclude_Parent_Interfaces
then
1319 Add_Interface
(Ancestor
);
1323 elsif Etype
(Full_T
) /= Typ
1325 -- Protect the frontend against wrong sources. For example:
1328 -- type A is tagged null record;
1329 -- type B is new A with private;
1330 -- type C is new A with private;
1332 -- type B is new C with null record;
1333 -- type C is new B with null record;
1336 and then Etype
(Full_T
) /= T
1338 Ancestor
:= Etype
(Full_T
);
1341 if Is_Interface
(Ancestor
)
1342 and then not Exclude_Parent_Interfaces
1344 Add_Interface
(Ancestor
);
1348 -- Traverse the graph of ancestor interfaces
1350 if Is_Non_Empty_List
(Iface_List
) then
1351 Id
:= First
(Iface_List
);
1353 -- In concurrent types the ancestor interface (if any) is the
1354 -- first element of the list of interface types and we have
1355 -- already processed them while climbing to the root type.
1357 if Is_Concurrent_Type
(Full_T
)
1358 or else Is_Concurrent_Record_Type
(Full_T
)
1363 while Present
(Id
) loop
1364 Iface
:= Etype
(Id
);
1366 -- Protect against wrong uses. For example:
1367 -- type I is interface;
1368 -- type O is tagged null record;
1369 -- type Wrong is new I and O with null record; -- ERROR
1371 if Is_Interface
(Iface
) then
1372 if Exclude_Parent_Interfaces
1373 and then Interface_Present_In_Parent
(T
, Iface
)
1378 Add_Interface
(Iface
);
1387 ---------------------------------
1388 -- Interface_Present_In_Parent --
1389 ---------------------------------
1391 function Interface_Present_In_Parent
1393 Iface
: Entity_Id
) return Boolean
1395 Aux
: Entity_Id
:= Typ
;
1396 Iface_List
: List_Id
;
1399 if Is_Concurrent_Type
(Typ
)
1400 or else Is_Concurrent_Record_Type
(Typ
)
1402 Iface_List
:= Abstract_Interface_List
(Typ
);
1404 if Is_Non_Empty_List
(Iface_List
) then
1405 Aux
:= Etype
(First
(Iface_List
));
1411 return Interface_Present_In_Ancestor
(Aux
, Iface
);
1412 end Interface_Present_In_Parent
;
1414 -- Start of processing for Collect_Abstract_Interfaces
1417 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
1418 Ifaces_List
:= New_Elmt_List
;
1420 end Collect_Abstract_Interfaces
;
1422 ----------------------------------
1423 -- Collect_Interface_Components --
1424 ----------------------------------
1426 procedure Collect_Interface_Components
1427 (Tagged_Type
: Entity_Id
;
1428 Components_List
: out Elist_Id
)
1430 procedure Collect
(Typ
: Entity_Id
);
1431 -- Subsidiary subprogram used to climb to the parents
1437 procedure Collect
(Typ
: Entity_Id
) is
1438 Tag_Comp
: Entity_Id
;
1441 if Etype
(Typ
) /= Typ
1443 -- Protect the frontend against wrong sources. For example:
1446 -- type A is tagged null record;
1447 -- type B is new A with private;
1448 -- type C is new A with private;
1450 -- type B is new C with null record;
1451 -- type C is new B with null record;
1454 and then Etype
(Typ
) /= Tagged_Type
1456 Collect
(Etype
(Typ
));
1459 -- Collect the components containing tags of secondary dispatch
1462 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
1463 while Present
(Tag_Comp
) loop
1464 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
1465 Append_Elmt
(Tag_Comp
, Components_List
);
1467 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
1471 -- Start of processing for Collect_Interface_Components
1474 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
1475 and then Is_Tagged_Type
(Tagged_Type
));
1477 Components_List
:= New_Elmt_List
;
1478 Collect
(Tagged_Type
);
1479 end Collect_Interface_Components
;
1481 -----------------------------
1482 -- Collect_Interfaces_Info --
1483 -----------------------------
1485 procedure Collect_Interfaces_Info
1487 Ifaces_List
: out Elist_Id
;
1488 Components_List
: out Elist_Id
;
1489 Tags_List
: out Elist_Id
)
1491 Comps_List
: Elist_Id
;
1492 Comp_Elmt
: Elmt_Id
;
1493 Comp_Iface
: Entity_Id
;
1494 Iface_Elmt
: Elmt_Id
;
1497 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
1498 -- Search for the secondary tag associated with the interface type
1499 -- Iface that is implemented by T.
1505 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
1509 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
1511 and then Ekind
(Node
(ADT
)) = E_Constant
1512 and then Related_Type
(Node
(ADT
)) /= Iface
1514 -- Skip the secondary dispatch tables of Iface
1522 pragma Assert
(Ekind
(Node
(ADT
)) = E_Constant
);
1526 -- Start of processing for Collect_Interfaces_Info
1529 Collect_Abstract_Interfaces
(T
, Ifaces_List
);
1530 Collect_Interface_Components
(T
, Comps_List
);
1532 -- Search for the record component and tag associated with each
1533 -- interface type of T.
1535 Components_List
:= New_Elmt_List
;
1536 Tags_List
:= New_Elmt_List
;
1538 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1539 while Present
(Iface_Elmt
) loop
1540 Iface
:= Node
(Iface_Elmt
);
1542 -- Associate the primary tag component and the primary dispatch table
1543 -- with all the interfaces that are parents of T
1545 if Is_Parent
(Iface
, T
) then
1546 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
1547 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
1549 -- Otherwise search for the tag component and secondary dispatch
1553 Comp_Elmt
:= First_Elmt
(Comps_List
);
1554 while Present
(Comp_Elmt
) loop
1555 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
1557 if Comp_Iface
= Iface
1558 or else Is_Parent
(Iface
, Comp_Iface
)
1560 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
1561 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
1565 Next_Elmt
(Comp_Elmt
);
1567 pragma Assert
(Present
(Comp_Elmt
));
1570 Next_Elmt
(Iface_Elmt
);
1572 end Collect_Interfaces_Info
;
1574 ----------------------------------
1575 -- Collect_Primitive_Operations --
1576 ----------------------------------
1578 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
1579 B_Type
: constant Entity_Id
:= Base_Type
(T
);
1580 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
1581 B_Scope
: Entity_Id
:= Scope
(B_Type
);
1585 Formal_Derived
: Boolean := False;
1589 -- For tagged types, the primitive operations are collected as they
1590 -- are declared, and held in an explicit list which is simply returned.
1592 if Is_Tagged_Type
(B_Type
) then
1593 return Primitive_Operations
(B_Type
);
1595 -- An untagged generic type that is a derived type inherits the
1596 -- primitive operations of its parent type. Other formal types only
1597 -- have predefined operators, which are not explicitly represented.
1599 elsif Is_Generic_Type
(B_Type
) then
1600 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
1601 and then Nkind
(Formal_Type_Definition
(B_Decl
))
1602 = N_Formal_Derived_Type_Definition
1604 Formal_Derived
:= True;
1606 return New_Elmt_List
;
1610 Op_List
:= New_Elmt_List
;
1612 if B_Scope
= Standard_Standard
then
1613 if B_Type
= Standard_String
then
1614 Append_Elmt
(Standard_Op_Concat
, Op_List
);
1616 elsif B_Type
= Standard_Wide_String
then
1617 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
1623 elsif (Is_Package_Or_Generic_Package
(B_Scope
)
1625 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
1627 or else Is_Derived_Type
(B_Type
)
1629 -- The primitive operations appear after the base type, except
1630 -- if the derivation happens within the private part of B_Scope
1631 -- and the type is a private type, in which case both the type
1632 -- and some primitive operations may appear before the base
1633 -- type, and the list of candidates starts after the type.
1635 if In_Open_Scopes
(B_Scope
)
1636 and then Scope
(T
) = B_Scope
1637 and then In_Private_Part
(B_Scope
)
1639 Id
:= Next_Entity
(T
);
1641 Id
:= Next_Entity
(B_Type
);
1644 while Present
(Id
) loop
1646 -- Note that generic formal subprograms are not
1647 -- considered to be primitive operations and thus
1648 -- are never inherited.
1650 if Is_Overloadable
(Id
)
1651 and then Nkind
(Parent
(Parent
(Id
)))
1652 not in N_Formal_Subprogram_Declaration
1656 if Base_Type
(Etype
(Id
)) = B_Type
then
1659 Formal
:= First_Formal
(Id
);
1660 while Present
(Formal
) loop
1661 if Base_Type
(Etype
(Formal
)) = B_Type
then
1665 elsif Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
1667 (Designated_Type
(Etype
(Formal
))) = B_Type
1673 Next_Formal
(Formal
);
1677 -- For a formal derived type, the only primitives are the
1678 -- ones inherited from the parent type. Operations appearing
1679 -- in the package declaration are not primitive for it.
1682 and then (not Formal_Derived
1683 or else Present
(Alias
(Id
)))
1685 Append_Elmt
(Id
, Op_List
);
1691 -- For a type declared in System, some of its operations
1692 -- may appear in the target-specific extension to System.
1695 and then Chars
(B_Scope
) = Name_System
1696 and then Scope
(B_Scope
) = Standard_Standard
1697 and then Present_System_Aux
1699 B_Scope
:= System_Aux_Id
;
1700 Id
:= First_Entity
(System_Aux_Id
);
1706 end Collect_Primitive_Operations
;
1708 -----------------------------------
1709 -- Compile_Time_Constraint_Error --
1710 -----------------------------------
1712 function Compile_Time_Constraint_Error
1715 Ent
: Entity_Id
:= Empty
;
1716 Loc
: Source_Ptr
:= No_Location
;
1717 Warn
: Boolean := False) return Node_Id
1719 Msgc
: String (1 .. Msg
'Length + 2);
1720 -- Copy of message, with room for possible ? and ! at end
1730 -- A static constraint error in an instance body is not a fatal error.
1731 -- we choose to inhibit the message altogether, because there is no
1732 -- obvious node (for now) on which to post it. On the other hand the
1733 -- offending node must be replaced with a constraint_error in any case.
1735 -- No messages are generated if we already posted an error on this node
1737 if not Error_Posted
(N
) then
1738 if Loc
/= No_Location
then
1744 Msgc
(1 .. Msg
'Length) := Msg
;
1747 -- Message is a warning, even in Ada 95 case
1749 if Msg
(Msg
'Last) = '?' then
1752 -- In Ada 83, all messages are warnings. In the private part and
1753 -- the body of an instance, constraint_checks are only warnings.
1754 -- We also make this a warning if the Warn parameter is set.
1757 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
1763 elsif In_Instance_Not_Visible
then
1768 -- Otherwise we have a real error message (Ada 95 static case)
1769 -- and we make this an unconditional message. Note that in the
1770 -- warning case we do not make the message unconditional, it seems
1771 -- quite reasonable to delete messages like this (about exceptions
1772 -- that will be raised) in dead code.
1780 -- Should we generate a warning? The answer is not quite yes. The
1781 -- very annoying exception occurs in the case of a short circuit
1782 -- operator where the left operand is static and decisive. Climb
1783 -- parents to see if that is the case we have here. Conditional
1784 -- expressions with decisive conditions are a similar situation.
1792 -- And then with False as left operand
1794 if Nkind
(P
) = N_And_Then
1795 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1796 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
1801 -- OR ELSE with True as left operand
1803 elsif Nkind
(P
) = N_Or_Else
1804 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1805 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
1810 -- Conditional expression
1812 elsif Nkind
(P
) = N_Conditional_Expression
then
1814 Cond
: constant Node_Id
:= First
(Expressions
(P
));
1815 Texp
: constant Node_Id
:= Next
(Cond
);
1816 Fexp
: constant Node_Id
:= Next
(Texp
);
1819 if Compile_Time_Known_Value
(Cond
) then
1821 -- Condition is True and we are in the right operand
1823 if Is_True
(Expr_Value
(Cond
))
1824 and then OldP
= Fexp
1829 -- Condition is False and we are in the left operand
1831 elsif Is_False
(Expr_Value
(Cond
))
1832 and then OldP
= Texp
1840 -- Special case for component association in aggregates, where
1841 -- we want to keep climbing up to the parent aggregate.
1843 elsif Nkind
(P
) = N_Component_Association
1844 and then Nkind
(Parent
(P
)) = N_Aggregate
1848 -- Keep going if within subexpression
1851 exit when Nkind
(P
) not in N_Subexpr
;
1856 if Present
(Ent
) then
1857 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
1859 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
1863 if Inside_Init_Proc
then
1865 ("\?& will be raised for objects of this type",
1866 N
, Standard_Constraint_Error
, Eloc
);
1869 ("\?& will be raised at run time",
1870 N
, Standard_Constraint_Error
, Eloc
);
1875 ("\static expression fails Constraint_Check", Eloc
);
1876 Set_Error_Posted
(N
);
1882 end Compile_Time_Constraint_Error
;
1884 -----------------------
1885 -- Conditional_Delay --
1886 -----------------------
1888 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
1890 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
1891 Set_Has_Delayed_Freeze
(New_Ent
);
1893 end Conditional_Delay
;
1895 -------------------------
1896 -- Copy_Parameter_List --
1897 -------------------------
1899 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
1900 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
1905 if No
(First_Formal
(Subp_Id
)) then
1909 Formal
:= First_Formal
(Subp_Id
);
1910 while Present
(Formal
) loop
1912 (Make_Parameter_Specification
(Loc
,
1913 Defining_Identifier
=>
1914 Make_Defining_Identifier
(Sloc
(Formal
),
1915 Chars
=> Chars
(Formal
)),
1916 In_Present
=> In_Present
(Parent
(Formal
)),
1917 Out_Present
=> Out_Present
(Parent
(Formal
)),
1919 New_Reference_To
(Etype
(Formal
), Loc
),
1921 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
1924 Next_Formal
(Formal
);
1929 end Copy_Parameter_List
;
1931 --------------------
1932 -- Current_Entity --
1933 --------------------
1935 -- The currently visible definition for a given identifier is the
1936 -- one most chained at the start of the visibility chain, i.e. the
1937 -- one that is referenced by the Node_Id value of the name of the
1938 -- given identifier.
1940 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
1942 return Get_Name_Entity_Id
(Chars
(N
));
1945 -----------------------------
1946 -- Current_Entity_In_Scope --
1947 -----------------------------
1949 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
1951 CS
: constant Entity_Id
:= Current_Scope
;
1953 Transient_Case
: constant Boolean := Scope_Is_Transient
;
1956 E
:= Get_Name_Entity_Id
(Chars
(N
));
1958 and then Scope
(E
) /= CS
1959 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
1965 end Current_Entity_In_Scope
;
1971 function Current_Scope
return Entity_Id
is
1973 if Scope_Stack
.Last
= -1 then
1974 return Standard_Standard
;
1977 C
: constant Entity_Id
:=
1978 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
1983 return Standard_Standard
;
1989 ------------------------
1990 -- Current_Subprogram --
1991 ------------------------
1993 function Current_Subprogram
return Entity_Id
is
1994 Scop
: constant Entity_Id
:= Current_Scope
;
1997 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
2000 return Enclosing_Subprogram
(Scop
);
2002 end Current_Subprogram
;
2004 ---------------------
2005 -- Defining_Entity --
2006 ---------------------
2008 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
2009 K
: constant Node_Kind
:= Nkind
(N
);
2010 Err
: Entity_Id
:= Empty
;
2015 N_Subprogram_Declaration |
2016 N_Abstract_Subprogram_Declaration |
2018 N_Package_Declaration |
2019 N_Subprogram_Renaming_Declaration |
2020 N_Subprogram_Body_Stub |
2021 N_Generic_Subprogram_Declaration |
2022 N_Generic_Package_Declaration |
2023 N_Formal_Subprogram_Declaration
2025 return Defining_Entity
(Specification
(N
));
2028 N_Component_Declaration |
2029 N_Defining_Program_Unit_Name |
2030 N_Discriminant_Specification |
2032 N_Entry_Declaration |
2033 N_Entry_Index_Specification |
2034 N_Exception_Declaration |
2035 N_Exception_Renaming_Declaration |
2036 N_Formal_Object_Declaration |
2037 N_Formal_Package_Declaration |
2038 N_Formal_Type_Declaration |
2039 N_Full_Type_Declaration |
2040 N_Implicit_Label_Declaration |
2041 N_Incomplete_Type_Declaration |
2042 N_Loop_Parameter_Specification |
2043 N_Number_Declaration |
2044 N_Object_Declaration |
2045 N_Object_Renaming_Declaration |
2046 N_Package_Body_Stub |
2047 N_Parameter_Specification |
2048 N_Private_Extension_Declaration |
2049 N_Private_Type_Declaration |
2051 N_Protected_Body_Stub |
2052 N_Protected_Type_Declaration |
2053 N_Single_Protected_Declaration |
2054 N_Single_Task_Declaration |
2055 N_Subtype_Declaration |
2058 N_Task_Type_Declaration
2060 return Defining_Identifier
(N
);
2063 return Defining_Entity
(Proper_Body
(N
));
2066 N_Function_Instantiation |
2067 N_Function_Specification |
2068 N_Generic_Function_Renaming_Declaration |
2069 N_Generic_Package_Renaming_Declaration |
2070 N_Generic_Procedure_Renaming_Declaration |
2072 N_Package_Instantiation |
2073 N_Package_Renaming_Declaration |
2074 N_Package_Specification |
2075 N_Procedure_Instantiation |
2076 N_Procedure_Specification
2079 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
2082 if Nkind
(Nam
) in N_Entity
then
2085 -- For Error, make up a name and attach to declaration
2086 -- so we can continue semantic analysis
2088 elsif Nam
= Error
then
2090 Make_Defining_Identifier
(Sloc
(N
),
2091 Chars
=> New_Internal_Name
('T'));
2092 Set_Defining_Unit_Name
(N
, Err
);
2095 -- If not an entity, get defining identifier
2098 return Defining_Identifier
(Nam
);
2102 when N_Block_Statement
=>
2103 return Entity
(Identifier
(N
));
2106 raise Program_Error
;
2109 end Defining_Entity
;
2111 --------------------------
2112 -- Denotes_Discriminant --
2113 --------------------------
2115 function Denotes_Discriminant
2117 Check_Concurrent
: Boolean := False) return Boolean
2121 if not Is_Entity_Name
(N
)
2122 or else No
(Entity
(N
))
2129 -- If we are checking for a protected type, the discriminant may have
2130 -- been rewritten as the corresponding discriminal of the original type
2131 -- or of the corresponding concurrent record, depending on whether we
2132 -- are in the spec or body of the protected type.
2134 return Ekind
(E
) = E_Discriminant
2137 and then Ekind
(E
) = E_In_Parameter
2138 and then Present
(Discriminal_Link
(E
))
2140 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
2142 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
2144 end Denotes_Discriminant
;
2146 ----------------------
2147 -- Denotes_Variable --
2148 ----------------------
2150 function Denotes_Variable
(N
: Node_Id
) return Boolean is
2152 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
2153 end Denotes_Variable
;
2155 -----------------------------
2156 -- Depends_On_Discriminant --
2157 -----------------------------
2159 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
2164 Get_Index_Bounds
(N
, L
, H
);
2165 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
2166 end Depends_On_Discriminant
;
2168 -------------------------
2169 -- Designate_Same_Unit --
2170 -------------------------
2172 function Designate_Same_Unit
2174 Name2
: Node_Id
) return Boolean
2176 K1
: constant Node_Kind
:= Nkind
(Name1
);
2177 K2
: constant Node_Kind
:= Nkind
(Name2
);
2179 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
2180 -- Returns the parent unit name node of a defining program unit name
2181 -- or the prefix if N is a selected component or an expanded name.
2183 function Select_Node
(N
: Node_Id
) return Node_Id
;
2184 -- Returns the defining identifier node of a defining program unit
2185 -- name or the selector node if N is a selected component or an
2192 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
2194 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2206 function Select_Node
(N
: Node_Id
) return Node_Id
is
2208 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
2209 return Defining_Identifier
(N
);
2212 return Selector_Name
(N
);
2216 -- Start of processing for Designate_Next_Unit
2219 if (K1
= N_Identifier
or else
2220 K1
= N_Defining_Identifier
)
2222 (K2
= N_Identifier
or else
2223 K2
= N_Defining_Identifier
)
2225 return Chars
(Name1
) = Chars
(Name2
);
2228 (K1
= N_Expanded_Name
or else
2229 K1
= N_Selected_Component
or else
2230 K1
= N_Defining_Program_Unit_Name
)
2232 (K2
= N_Expanded_Name
or else
2233 K2
= N_Selected_Component
or else
2234 K2
= N_Defining_Program_Unit_Name
)
2237 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
2239 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
2244 end Designate_Same_Unit
;
2246 ----------------------------
2247 -- Enclosing_Generic_Body --
2248 ----------------------------
2250 function Enclosing_Generic_Body
2251 (N
: Node_Id
) return Node_Id
2259 while Present
(P
) loop
2260 if Nkind
(P
) = N_Package_Body
2261 or else Nkind
(P
) = N_Subprogram_Body
2263 Spec
:= Corresponding_Spec
(P
);
2265 if Present
(Spec
) then
2266 Decl
:= Unit_Declaration_Node
(Spec
);
2268 if Nkind
(Decl
) = N_Generic_Package_Declaration
2269 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2280 end Enclosing_Generic_Body
;
2282 ----------------------------
2283 -- Enclosing_Generic_Unit --
2284 ----------------------------
2286 function Enclosing_Generic_Unit
2287 (N
: Node_Id
) return Node_Id
2295 while Present
(P
) loop
2296 if Nkind
(P
) = N_Generic_Package_Declaration
2297 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
2301 elsif Nkind
(P
) = N_Package_Body
2302 or else Nkind
(P
) = N_Subprogram_Body
2304 Spec
:= Corresponding_Spec
(P
);
2306 if Present
(Spec
) then
2307 Decl
:= Unit_Declaration_Node
(Spec
);
2309 if Nkind
(Decl
) = N_Generic_Package_Declaration
2310 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
2321 end Enclosing_Generic_Unit
;
2323 -------------------------------
2324 -- Enclosing_Lib_Unit_Entity --
2325 -------------------------------
2327 function Enclosing_Lib_Unit_Entity
return Entity_Id
is
2328 Unit_Entity
: Entity_Id
;
2331 -- Look for enclosing library unit entity by following scope links.
2332 -- Equivalent to, but faster than indexing through the scope stack.
2334 Unit_Entity
:= Current_Scope
;
2335 while (Present
(Scope
(Unit_Entity
))
2336 and then Scope
(Unit_Entity
) /= Standard_Standard
)
2337 and not Is_Child_Unit
(Unit_Entity
)
2339 Unit_Entity
:= Scope
(Unit_Entity
);
2343 end Enclosing_Lib_Unit_Entity
;
2345 -----------------------------
2346 -- Enclosing_Lib_Unit_Node --
2347 -----------------------------
2349 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
2350 Current_Node
: Node_Id
;
2354 while Present
(Current_Node
)
2355 and then Nkind
(Current_Node
) /= N_Compilation_Unit
2357 Current_Node
:= Parent
(Current_Node
);
2360 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
2364 return Current_Node
;
2365 end Enclosing_Lib_Unit_Node
;
2367 --------------------------
2368 -- Enclosing_Subprogram --
2369 --------------------------
2371 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
2372 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
2375 if Dynamic_Scope
= Standard_Standard
then
2378 elsif Dynamic_Scope
= Empty
then
2381 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
2382 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
2384 elsif Ekind
(Dynamic_Scope
) = E_Block
2385 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
2387 return Enclosing_Subprogram
(Dynamic_Scope
);
2389 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
2390 return Get_Task_Body_Procedure
(Dynamic_Scope
);
2392 elsif Convention
(Dynamic_Scope
) = Convention_Protected
then
2393 return Protected_Body_Subprogram
(Dynamic_Scope
);
2396 return Dynamic_Scope
;
2398 end Enclosing_Subprogram
;
2400 ------------------------
2401 -- Ensure_Freeze_Node --
2402 ------------------------
2404 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
2408 if No
(Freeze_Node
(E
)) then
2409 FN
:= Make_Freeze_Entity
(Sloc
(E
));
2410 Set_Has_Delayed_Freeze
(E
);
2411 Set_Freeze_Node
(E
, FN
);
2412 Set_Access_Types_To_Process
(FN
, No_Elist
);
2413 Set_TSS_Elist
(FN
, No_Elist
);
2416 end Ensure_Freeze_Node
;
2422 procedure Enter_Name
(Def_Id
: Entity_Id
) is
2423 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
2424 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
2425 S
: constant Entity_Id
:= Current_Scope
;
2428 Generate_Definition
(Def_Id
);
2430 -- Add new name to current scope declarations. Check for duplicate
2431 -- declaration, which may or may not be a genuine error.
2435 -- Case of previous entity entered because of a missing declaration
2436 -- or else a bad subtype indication. Best is to use the new entity,
2437 -- and make the previous one invisible.
2439 if Etype
(E
) = Any_Type
then
2440 Set_Is_Immediately_Visible
(E
, False);
2442 -- Case of renaming declaration constructed for package instances.
2443 -- if there is an explicit declaration with the same identifier,
2444 -- the renaming is not immediately visible any longer, but remains
2445 -- visible through selected component notation.
2447 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
2448 and then not Comes_From_Source
(E
)
2450 Set_Is_Immediately_Visible
(E
, False);
2452 -- The new entity may be the package renaming, which has the same
2453 -- same name as a generic formal which has been seen already.
2455 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
2456 and then not Comes_From_Source
(Def_Id
)
2458 Set_Is_Immediately_Visible
(E
, False);
2460 -- For a fat pointer corresponding to a remote access to subprogram,
2461 -- we use the same identifier as the RAS type, so that the proper
2462 -- name appears in the stub. This type is only retrieved through
2463 -- the RAS type and never by visibility, and is not added to the
2464 -- visibility list (see below).
2466 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
2467 and then Present
(Corresponding_Remote_Type
(Def_Id
))
2471 -- A controller component for a type extension overrides the
2472 -- inherited component.
2474 elsif Chars
(E
) = Name_uController
then
2477 -- Case of an implicit operation or derived literal. The new entity
2478 -- hides the implicit one, which is removed from all visibility,
2479 -- i.e. the entity list of its scope, and homonym chain of its name.
2481 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
2482 or else Is_Internal
(E
)
2486 Prev_Vis
: Entity_Id
;
2487 Decl
: constant Node_Id
:= Parent
(E
);
2490 -- If E is an implicit declaration, it cannot be the first
2491 -- entity in the scope.
2493 Prev
:= First_Entity
(Current_Scope
);
2494 while Present
(Prev
)
2495 and then Next_Entity
(Prev
) /= E
2502 -- If E is not on the entity chain of the current scope,
2503 -- it is an implicit declaration in the generic formal
2504 -- part of a generic subprogram. When analyzing the body,
2505 -- the generic formals are visible but not on the entity
2506 -- chain of the subprogram. The new entity will become
2507 -- the visible one in the body.
2510 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
2514 Set_Next_Entity
(Prev
, Next_Entity
(E
));
2516 if No
(Next_Entity
(Prev
)) then
2517 Set_Last_Entity
(Current_Scope
, Prev
);
2520 if E
= Current_Entity
(E
) then
2524 Prev_Vis
:= Current_Entity
(E
);
2525 while Homonym
(Prev_Vis
) /= E
loop
2526 Prev_Vis
:= Homonym
(Prev_Vis
);
2530 if Present
(Prev_Vis
) then
2532 -- Skip E in the visibility chain
2534 Set_Homonym
(Prev_Vis
, Homonym
(E
));
2537 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
2542 -- This section of code could use a comment ???
2544 elsif Present
(Etype
(E
))
2545 and then Is_Concurrent_Type
(Etype
(E
))
2550 -- If the homograph is a protected component renaming, it should not
2551 -- be hiding the current entity. Such renamings are treated as weak
2554 elsif Is_Prival
(E
) then
2555 Set_Is_Immediately_Visible
(E
, False);
2557 -- In this case the current entity is a protected component renaming.
2558 -- Perform minimal decoration by setting the scope and return since
2559 -- the prival should not be hiding other visible entities.
2561 elsif Is_Prival
(Def_Id
) then
2562 Set_Scope
(Def_Id
, Current_Scope
);
2565 -- Analogous to privals, the discriminal generated for an entry
2566 -- index parameter acts as a weak declaration. Perform minimal
2567 -- decoration to avoid bogus errors.
2569 elsif Is_Discriminal
(Def_Id
)
2570 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
2572 Set_Scope
(Def_Id
, Current_Scope
);
2575 -- In the body or private part of an instance, a type extension
2576 -- may introduce a component with the same name as that of an
2577 -- actual. The legality rule is not enforced, but the semantics
2578 -- of the full type with two components of the same name are not
2579 -- clear at this point ???
2581 elsif In_Instance_Not_Visible
then
2584 -- When compiling a package body, some child units may have become
2585 -- visible. They cannot conflict with local entities that hide them.
2587 elsif Is_Child_Unit
(E
)
2588 and then In_Open_Scopes
(Scope
(E
))
2589 and then not Is_Immediately_Visible
(E
)
2593 -- Conversely, with front-end inlining we may compile the parent
2594 -- body first, and a child unit subsequently. The context is now
2595 -- the parent spec, and body entities are not visible.
2597 elsif Is_Child_Unit
(Def_Id
)
2598 and then Is_Package_Body_Entity
(E
)
2599 and then not In_Package_Body
(Current_Scope
)
2603 -- Case of genuine duplicate declaration
2606 Error_Msg_Sloc
:= Sloc
(E
);
2608 -- If the previous declaration is an incomplete type declaration
2609 -- this may be an attempt to complete it with a private type.
2610 -- The following avoids confusing cascaded errors.
2612 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
2613 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
2616 ("incomplete type cannot be completed with a private " &
2617 "declaration", Parent
(Def_Id
));
2618 Set_Is_Immediately_Visible
(E
, False);
2619 Set_Full_View
(E
, Def_Id
);
2621 -- An inherited component of a record conflicts with a new
2622 -- discriminant. The discriminant is inserted first in the scope,
2623 -- but the error should be posted on it, not on the component.
2625 elsif Ekind
(E
) = E_Discriminant
2626 and then Present
(Scope
(Def_Id
))
2627 and then Scope
(Def_Id
) /= Current_Scope
2629 Error_Msg_Sloc
:= Sloc
(Def_Id
);
2630 Error_Msg_N
("& conflicts with declaration#", E
);
2633 -- If the name of the unit appears in its own context clause,
2634 -- a dummy package with the name has already been created, and
2635 -- the error emitted. Try to continue quietly.
2637 elsif Error_Posted
(E
)
2638 and then Sloc
(E
) = No_Location
2639 and then Nkind
(Parent
(E
)) = N_Package_Specification
2640 and then Current_Scope
= Standard_Standard
2642 Set_Scope
(Def_Id
, Current_Scope
);
2646 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
2648 -- Avoid cascaded messages with duplicate components in
2651 if Ekind
(E
) = E_Component
2652 or else Ekind
(E
) = E_Discriminant
2658 if Nkind
(Parent
(Parent
(Def_Id
))) =
2659 N_Generic_Subprogram_Declaration
2661 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
2663 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
2666 -- If entity is in standard, then we are in trouble, because
2667 -- it means that we have a library package with a duplicated
2668 -- name. That's hard to recover from, so abort!
2670 if S
= Standard_Standard
then
2671 raise Unrecoverable_Error
;
2673 -- Otherwise we continue with the declaration. Having two
2674 -- identical declarations should not cause us too much trouble!
2682 -- If we fall through, declaration is OK , or OK enough to continue
2684 -- If Def_Id is a discriminant or a record component we are in the
2685 -- midst of inheriting components in a derived record definition.
2686 -- Preserve their Ekind and Etype.
2688 if Ekind
(Def_Id
) = E_Discriminant
2689 or else Ekind
(Def_Id
) = E_Component
2693 -- If a type is already set, leave it alone (happens whey a type
2694 -- declaration is reanalyzed following a call to the optimizer)
2696 elsif Present
(Etype
(Def_Id
)) then
2699 -- Otherwise, the kind E_Void insures that premature uses of the entity
2700 -- will be detected. Any_Type insures that no cascaded errors will occur
2703 Set_Ekind
(Def_Id
, E_Void
);
2704 Set_Etype
(Def_Id
, Any_Type
);
2707 -- Inherited discriminants and components in derived record types are
2708 -- immediately visible. Itypes are not.
2710 if Ekind
(Def_Id
) = E_Discriminant
2711 or else Ekind
(Def_Id
) = E_Component
2712 or else (No
(Corresponding_Remote_Type
(Def_Id
))
2713 and then not Is_Itype
(Def_Id
))
2715 Set_Is_Immediately_Visible
(Def_Id
);
2716 Set_Current_Entity
(Def_Id
);
2719 Set_Homonym
(Def_Id
, C
);
2720 Append_Entity
(Def_Id
, S
);
2721 Set_Public_Status
(Def_Id
);
2723 -- Warn if new entity hides an old one
2725 if Warn_On_Hiding
and then Present
(C
)
2727 -- Don't warn for record components since they always have a well
2728 -- defined scope which does not confuse other uses. Note that in
2729 -- some cases, Ekind has not been set yet.
2731 and then Ekind
(C
) /= E_Component
2732 and then Ekind
(C
) /= E_Discriminant
2733 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
2734 and then Ekind
(Def_Id
) /= E_Component
2735 and then Ekind
(Def_Id
) /= E_Discriminant
2736 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
2738 -- Don't warn for one character variables. It is too common to use
2739 -- such variables as locals and will just cause too many false hits.
2741 and then Length_Of_Name
(Chars
(C
)) /= 1
2743 -- Don't warn for non-source entities
2745 and then Comes_From_Source
(C
)
2746 and then Comes_From_Source
(Def_Id
)
2748 -- Don't warn unless entity in question is in extended main source
2750 and then In_Extended_Main_Source_Unit
(Def_Id
)
2752 -- Finally, the hidden entity must be either immediately visible
2753 -- or use visible (from a used package)
2756 (Is_Immediately_Visible
(C
)
2758 Is_Potentially_Use_Visible
(C
))
2760 Error_Msg_Sloc
:= Sloc
(C
);
2761 Error_Msg_N
("declaration hides &#?", Def_Id
);
2765 --------------------------
2766 -- Explain_Limited_Type --
2767 --------------------------
2769 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
2773 -- For array, component type must be limited
2775 if Is_Array_Type
(T
) then
2776 Error_Msg_Node_2
:= T
;
2778 ("\component type& of type& is limited", N
, Component_Type
(T
));
2779 Explain_Limited_Type
(Component_Type
(T
), N
);
2781 elsif Is_Record_Type
(T
) then
2783 -- No need for extra messages if explicit limited record
2785 if Is_Limited_Record
(Base_Type
(T
)) then
2789 -- Otherwise find a limited component. Check only components that
2790 -- come from source, or inherited components that appear in the
2791 -- source of the ancestor.
2793 C
:= First_Component
(T
);
2794 while Present
(C
) loop
2795 if Is_Limited_Type
(Etype
(C
))
2797 (Comes_From_Source
(C
)
2799 (Present
(Original_Record_Component
(C
))
2801 Comes_From_Source
(Original_Record_Component
(C
))))
2803 Error_Msg_Node_2
:= T
;
2804 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
2805 Explain_Limited_Type
(Etype
(C
), N
);
2812 -- The type may be declared explicitly limited, even if no component
2813 -- of it is limited, in which case we fall out of the loop.
2816 end Explain_Limited_Type
;
2822 procedure Find_Actual
2824 Formal
: out Entity_Id
;
2827 Parnt
: constant Node_Id
:= Parent
(N
);
2831 if (Nkind
(Parnt
) = N_Indexed_Component
2833 Nkind
(Parnt
) = N_Selected_Component
)
2834 and then N
= Prefix
(Parnt
)
2836 Find_Actual
(Parnt
, Formal
, Call
);
2839 elsif Nkind
(Parnt
) = N_Parameter_Association
2840 and then N
= Explicit_Actual_Parameter
(Parnt
)
2842 Call
:= Parent
(Parnt
);
2844 elsif Nkind
(Parnt
) = N_Procedure_Call_Statement
then
2853 -- If we have a call to a subprogram look for the parameter. Note that
2854 -- we exclude overloaded calls, since we don't know enough to be sure
2855 -- of giving the right answer in this case.
2857 if Is_Entity_Name
(Name
(Call
))
2858 and then Present
(Entity
(Name
(Call
)))
2859 and then Is_Overloadable
(Entity
(Name
(Call
)))
2860 and then not Is_Overloaded
(Name
(Call
))
2862 -- Fall here if we are definitely a parameter
2864 Actual
:= First_Actual
(Call
);
2865 Formal
:= First_Formal
(Entity
(Name
(Call
)));
2866 while Present
(Formal
) and then Present
(Actual
) loop
2870 Actual
:= Next_Actual
(Actual
);
2871 Formal
:= Next_Formal
(Formal
);
2876 -- Fall through here if we did not find matching actual
2882 -------------------------------------
2883 -- Find_Corresponding_Discriminant --
2884 -------------------------------------
2886 function Find_Corresponding_Discriminant
2888 Typ
: Entity_Id
) return Entity_Id
2890 Par_Disc
: Entity_Id
;
2891 Old_Disc
: Entity_Id
;
2892 New_Disc
: Entity_Id
;
2895 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
2897 -- The original type may currently be private, and the discriminant
2898 -- only appear on its full view.
2900 if Is_Private_Type
(Scope
(Par_Disc
))
2901 and then not Has_Discriminants
(Scope
(Par_Disc
))
2902 and then Present
(Full_View
(Scope
(Par_Disc
)))
2904 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
2906 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
2909 if Is_Class_Wide_Type
(Typ
) then
2910 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
2912 New_Disc
:= First_Discriminant
(Typ
);
2915 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
2916 if Old_Disc
= Par_Disc
then
2919 Next_Discriminant
(Old_Disc
);
2920 Next_Discriminant
(New_Disc
);
2924 -- Should always find it
2926 raise Program_Error
;
2927 end Find_Corresponding_Discriminant
;
2929 --------------------------
2930 -- Find_Overlaid_Object --
2931 --------------------------
2933 function Find_Overlaid_Object
(N
: Node_Id
) return Entity_Id
is
2937 -- We are looking for one of the two following forms:
2939 -- for X'Address use Y'Address
2943 -- Const : constant Address := expr;
2945 -- for X'Address use Const;
2947 -- In the second case, the expr is either Y'Address, or recursively a
2948 -- constant that eventually references Y'Address.
2950 if Nkind
(N
) = N_Attribute_Definition_Clause
2951 and then Chars
(N
) = Name_Address
2953 -- This loop checks the form of the expression for Y'Address where Y
2954 -- is an object entity name. The first loop checks the original
2955 -- expression in the attribute definition clause. Subsequent loops
2956 -- check referenced constants.
2958 Expr
:= Expression
(N
);
2960 -- Check for Y'Address where Y is an object entity
2962 if Nkind
(Expr
) = N_Attribute_Reference
2963 and then Attribute_Name
(Expr
) = Name_Address
2964 and then Is_Entity_Name
(Prefix
(Expr
))
2965 and then Is_Object
(Entity
(Prefix
(Expr
)))
2967 return Entity
(Prefix
(Expr
));
2969 -- Check for Const where Const is a constant entity
2971 elsif Is_Entity_Name
(Expr
)
2972 and then Ekind
(Entity
(Expr
)) = E_Constant
2974 Expr
:= Constant_Value
(Entity
(Expr
));
2976 -- Anything else does not need checking
2985 end Find_Overlaid_Object
;
2987 --------------------------------------------
2988 -- Find_Overridden_Synchronized_Primitive --
2989 --------------------------------------------
2991 function Find_Overridden_Synchronized_Primitive
2992 (Def_Id
: Entity_Id
;
2993 First_Hom
: Entity_Id
;
2994 Ifaces_List
: Elist_Id
;
2995 In_Scope
: Boolean) return Entity_Id
2997 Candidate
: Entity_Id
:= Empty
;
2998 Hom
: Entity_Id
:= Empty
;
2999 Iface_Typ
: Entity_Id
;
3000 Subp
: Entity_Id
:= Empty
;
3001 Tag_Typ
: Entity_Id
;
3003 function Has_Correct_Formal_Mode
(Subp
: Entity_Id
) return Boolean;
3004 -- For an overridden subprogram Subp, check whether the mode of its
3005 -- first parameter is correct depending on the kind of Tag_Typ.
3007 function Matches_Prefixed_View_Profile
3008 (Prim_Params
: List_Id
;
3009 Iface_Params
: List_Id
) return Boolean;
3010 -- Determine whether a subprogram's parameter profile Prim_Params
3011 -- matches that of a potentially overridden interface subprogram
3012 -- Iface_Params. Also determine if the type of first parameter of
3013 -- Iface_Params is an implemented interface.
3015 -----------------------------
3016 -- Has_Correct_Formal_Mode --
3017 -----------------------------
3019 function Has_Correct_Formal_Mode
(Subp
: Entity_Id
) return Boolean is
3023 Param
:= First_Formal
(Subp
);
3025 -- In order for an entry or a protected procedure to override, the
3026 -- first parameter of the overridden routine must be of mode "out",
3027 -- "in out" or access-to-variable.
3029 if (Ekind
(Subp
) = E_Entry
3030 or else Ekind
(Subp
) = E_Procedure
)
3031 and then Is_Protected_Type
(Tag_Typ
)
3032 and then Ekind
(Param
) /= E_In_Out_Parameter
3033 and then Ekind
(Param
) /= E_Out_Parameter
3034 and then Nkind
(Parameter_Type
(Parent
(Param
))) /=
3040 -- All other cases are OK since a task entry or routine does not
3041 -- have a restriction on the mode of the first parameter of the
3042 -- overridden interface routine.
3045 end Has_Correct_Formal_Mode
;
3047 -----------------------------------
3048 -- Matches_Prefixed_View_Profile --
3049 -----------------------------------
3051 function Matches_Prefixed_View_Profile
3052 (Prim_Params
: List_Id
;
3053 Iface_Params
: List_Id
) return Boolean
3055 Iface_Id
: Entity_Id
;
3056 Iface_Param
: Node_Id
;
3057 Iface_Typ
: Entity_Id
;
3058 Prim_Id
: Entity_Id
;
3059 Prim_Param
: Node_Id
;
3060 Prim_Typ
: Entity_Id
;
3062 function Is_Implemented
(Iface
: Entity_Id
) return Boolean;
3063 -- Determine if Iface is implemented by the current task or
3066 --------------------
3067 -- Is_Implemented --
3068 --------------------
3070 function Is_Implemented
(Iface
: Entity_Id
) return Boolean is
3071 Iface_Elmt
: Elmt_Id
;
3074 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3075 while Present
(Iface_Elmt
) loop
3076 if Node
(Iface_Elmt
) = Iface
then
3080 Next_Elmt
(Iface_Elmt
);
3086 -- Start of processing for Matches_Prefixed_View_Profile
3089 Iface_Param
:= First
(Iface_Params
);
3091 if Nkind
(Parameter_Type
(Iface_Param
)) = N_Access_Definition
then
3093 Designated_Type
(Etype
(Defining_Identifier
(Iface_Param
)));
3095 Iface_Typ
:= Etype
(Defining_Identifier
(Iface_Param
));
3098 Prim_Param
:= First
(Prim_Params
);
3100 -- The first parameter of the potentially overridden subprogram
3101 -- must be an interface implemented by Prim.
3103 if not Is_Interface
(Iface_Typ
)
3104 or else not Is_Implemented
(Iface_Typ
)
3109 -- The checks on the object parameters are done, move onto the rest
3110 -- of the parameters.
3112 if not In_Scope
then
3113 Prim_Param
:= Next
(Prim_Param
);
3116 Iface_Param
:= Next
(Iface_Param
);
3117 while Present
(Iface_Param
) and then Present
(Prim_Param
) loop
3118 Iface_Id
:= Defining_Identifier
(Iface_Param
);
3119 Iface_Typ
:= Find_Parameter_Type
(Iface_Param
);
3120 Prim_Id
:= Defining_Identifier
(Prim_Param
);
3121 Prim_Typ
:= Find_Parameter_Type
(Prim_Param
);
3123 -- Case of multiple interface types inside a parameter profile
3125 -- (Obj_Param : in out Iface; ...; Param : Iface)
3127 -- If the interface type is implemented, then the matching type
3128 -- in the primitive should be the implementing record type.
3130 if Ekind
(Iface_Typ
) = E_Record_Type
3131 and then Is_Interface
(Iface_Typ
)
3132 and then Is_Implemented
(Iface_Typ
)
3134 if Prim_Typ
/= Tag_Typ
then
3138 -- The two parameters must be both mode and subtype conformant
3140 elsif Ekind
(Iface_Id
) /= Ekind
(Prim_Id
)
3142 not Conforming_Types
(Iface_Typ
, Prim_Typ
, Subtype_Conformant
)
3151 -- One of the two lists contains more parameters than the other
3153 if Present
(Iface_Param
) or else Present
(Prim_Param
) then
3158 end Matches_Prefixed_View_Profile
;
3160 -- Start of processing for Find_Overridden_Synchronized_Primitive
3163 -- At this point the caller should have collected the interfaces
3164 -- implemented by the synchronized type.
3166 pragma Assert
(Present
(Ifaces_List
));
3168 -- Find the tagged type to which subprogram Def_Id is primitive. If the
3169 -- subprogram was declared within a protected or a task type, the type
3170 -- is the scope itself, otherwise it is the type of the first parameter.
3173 Tag_Typ
:= Scope
(Def_Id
);
3175 elsif Present
(First_Formal
(Def_Id
)) then
3176 Tag_Typ
:= Find_Parameter_Type
(Parent
(First_Formal
(Def_Id
)));
3178 -- A parameterless subprogram which is declared outside a synchronized
3179 -- type cannot act as a primitive, thus it cannot override anything.
3185 -- Traverse the homonym chain, looking at a potentially overridden
3186 -- subprogram that belongs to an implemented interface.
3189 while Present
(Hom
) loop
3192 -- Entries can override abstract or null interface procedures
3194 if Ekind
(Def_Id
) = E_Entry
3195 and then Ekind
(Subp
) = E_Procedure
3196 and then Nkind
(Parent
(Subp
)) = N_Procedure_Specification
3197 and then (Is_Abstract_Subprogram
(Subp
)
3198 or else Null_Present
(Parent
(Subp
)))
3200 while Present
(Alias
(Subp
)) loop
3201 Subp
:= Alias
(Subp
);
3204 if Matches_Prefixed_View_Profile
3205 (Parameter_Specifications
(Parent
(Def_Id
)),
3206 Parameter_Specifications
(Parent
(Subp
)))
3212 if Has_Correct_Formal_Mode
(Candidate
) then
3217 -- Procedures can override abstract or null interface procedures
3219 elsif Ekind
(Def_Id
) = E_Procedure
3220 and then Ekind
(Subp
) = E_Procedure
3221 and then Nkind
(Parent
(Subp
)) = N_Procedure_Specification
3222 and then (Is_Abstract_Subprogram
(Subp
)
3223 or else Null_Present
(Parent
(Subp
)))
3224 and then Matches_Prefixed_View_Profile
3225 (Parameter_Specifications
(Parent
(Def_Id
)),
3226 Parameter_Specifications
(Parent
(Subp
)))
3232 if Has_Correct_Formal_Mode
(Candidate
) then
3236 -- Functions can override abstract interface functions
3238 elsif Ekind
(Def_Id
) = E_Function
3239 and then Ekind
(Subp
) = E_Function
3240 and then Nkind
(Parent
(Subp
)) = N_Function_Specification
3241 and then Is_Abstract_Subprogram
(Subp
)
3242 and then Matches_Prefixed_View_Profile
3243 (Parameter_Specifications
(Parent
(Def_Id
)),
3244 Parameter_Specifications
(Parent
(Subp
)))
3245 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
3246 Etype
(Result_Definition
(Parent
(Subp
)))
3251 Hom
:= Homonym
(Hom
);
3254 -- After examining all candidates for overriding, we are left with
3255 -- the best match which is a mode incompatible interface routine.
3256 -- Do not emit an error if the Expander is active since this error
3257 -- will be detected later on after all concurrent types are expanded
3258 -- and all wrappers are built. This check is meant for spec-only
3261 if Present
(Candidate
)
3262 and then not Expander_Active
3264 Iface_Typ
:= Find_Parameter_Type
(Parent
(First_Formal
(Candidate
)));
3266 -- Def_Id is primitive of a protected type, declared inside the type,
3267 -- and the candidate is primitive of a limited or synchronized
3271 and then Is_Protected_Type
(Tag_Typ
)
3273 (Is_Limited_Interface
(Iface_Typ
)
3274 or else Is_Protected_Interface
(Iface_Typ
)
3275 or else Is_Synchronized_Interface
(Iface_Typ
)
3276 or else Is_Task_Interface
(Iface_Typ
))
3278 -- Must reword this message, comma before to in -gnatj mode ???
3281 ("first formal of & must be of mode `OUT`, `IN OUT` or " &
3282 "access-to-variable", Tag_Typ
, Candidate
);
3284 ("\to be overridden by protected procedure or entry " &
3285 "(RM 9.4(11.9/2))", Tag_Typ
);
3290 end Find_Overridden_Synchronized_Primitive
;
3292 -------------------------
3293 -- Find_Parameter_Type --
3294 -------------------------
3296 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
3298 if Nkind
(Param
) /= N_Parameter_Specification
then
3301 -- For an access parameter, obtain the type from the formal entity
3302 -- itself, because access to subprogram nodes do not carry a type.
3303 -- Shouldn't we always use the formal entity ???
3305 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
3306 return Etype
(Defining_Identifier
(Param
));
3309 return Etype
(Parameter_Type
(Param
));
3311 end Find_Parameter_Type
;
3313 -----------------------------
3314 -- Find_Static_Alternative --
3315 -----------------------------
3317 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
3318 Expr
: constant Node_Id
:= Expression
(N
);
3319 Val
: constant Uint
:= Expr_Value
(Expr
);
3324 Alt
:= First
(Alternatives
(N
));
3327 if Nkind
(Alt
) /= N_Pragma
then
3328 Choice
:= First
(Discrete_Choices
(Alt
));
3329 while Present
(Choice
) loop
3331 -- Others choice, always matches
3333 if Nkind
(Choice
) = N_Others_Choice
then
3336 -- Range, check if value is in the range
3338 elsif Nkind
(Choice
) = N_Range
then
3340 Val
>= Expr_Value
(Low_Bound
(Choice
))
3342 Val
<= Expr_Value
(High_Bound
(Choice
));
3344 -- Choice is a subtype name. Note that we know it must
3345 -- be a static subtype, since otherwise it would have
3346 -- been diagnosed as illegal.
3348 elsif Is_Entity_Name
(Choice
)
3349 and then Is_Type
(Entity
(Choice
))
3351 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
));
3353 -- Choice is a subtype indication
3355 elsif Nkind
(Choice
) = N_Subtype_Indication
then
3357 C
: constant Node_Id
:= Constraint
(Choice
);
3358 R
: constant Node_Id
:= Range_Expression
(C
);
3362 Val
>= Expr_Value
(Low_Bound
(R
))
3364 Val
<= Expr_Value
(High_Bound
(R
));
3367 -- Choice is a simple expression
3370 exit Search
when Val
= Expr_Value
(Choice
);
3378 pragma Assert
(Present
(Alt
));
3381 -- The above loop *must* terminate by finding a match, since
3382 -- we know the case statement is valid, and the value of the
3383 -- expression is known at compile time. When we fall out of
3384 -- the loop, Alt points to the alternative that we know will
3385 -- be selected at run time.
3388 end Find_Static_Alternative
;
3394 function First_Actual
(Node
: Node_Id
) return Node_Id
is
3398 if No
(Parameter_Associations
(Node
)) then
3402 N
:= First
(Parameter_Associations
(Node
));
3404 if Nkind
(N
) = N_Parameter_Association
then
3405 return First_Named_Actual
(Node
);
3411 -------------------------
3412 -- Full_Qualified_Name --
3413 -------------------------
3415 function Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3417 pragma Warnings
(Off
, Res
);
3419 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
;
3420 -- Compute recursively the qualified name without NUL at the end
3422 ----------------------------------
3423 -- Internal_Full_Qualified_Name --
3424 ----------------------------------
3426 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
3427 Ent
: Entity_Id
:= E
;
3428 Parent_Name
: String_Id
:= No_String
;
3431 -- Deals properly with child units
3433 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
3434 Ent
:= Defining_Identifier
(Ent
);
3437 -- Compute qualification recursively (only "Standard" has no scope)
3439 if Present
(Scope
(Scope
(Ent
))) then
3440 Parent_Name
:= Internal_Full_Qualified_Name
(Scope
(Ent
));
3443 -- Every entity should have a name except some expanded blocks
3444 -- don't bother about those.
3446 if Chars
(Ent
) = No_Name
then
3450 -- Add a period between Name and qualification
3452 if Parent_Name
/= No_String
then
3453 Start_String
(Parent_Name
);
3454 Store_String_Char
(Get_Char_Code
('.'));
3460 -- Generates the entity name in upper case
3462 Get_Decoded_Name_String
(Chars
(Ent
));
3464 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3466 end Internal_Full_Qualified_Name
;
3468 -- Start of processing for Full_Qualified_Name
3471 Res
:= Internal_Full_Qualified_Name
(E
);
3472 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
3474 end Full_Qualified_Name
;
3476 -----------------------
3477 -- Gather_Components --
3478 -----------------------
3480 procedure Gather_Components
3482 Comp_List
: Node_Id
;
3483 Governed_By
: List_Id
;
3485 Report_Errors
: out Boolean)
3489 Discrete_Choice
: Node_Id
;
3490 Comp_Item
: Node_Id
;
3492 Discrim
: Entity_Id
;
3493 Discrim_Name
: Node_Id
;
3494 Discrim_Value
: Node_Id
;
3497 Report_Errors
:= False;
3499 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
3502 elsif Present
(Component_Items
(Comp_List
)) then
3503 Comp_Item
:= First
(Component_Items
(Comp_List
));
3509 while Present
(Comp_Item
) loop
3511 -- Skip the tag of a tagged record, the interface tags, as well
3512 -- as all items that are not user components (anonymous types,
3513 -- rep clauses, Parent field, controller field).
3515 if Nkind
(Comp_Item
) = N_Component_Declaration
then
3517 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
3519 if not Is_Tag
(Comp
)
3520 and then Chars
(Comp
) /= Name_uParent
3521 and then Chars
(Comp
) /= Name_uController
3523 Append_Elmt
(Comp
, Into
);
3531 if No
(Variant_Part
(Comp_List
)) then
3534 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
3535 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
3538 -- Look for the discriminant that governs this variant part.
3539 -- The discriminant *must* be in the Governed_By List
3541 Assoc
:= First
(Governed_By
);
3542 Find_Constraint
: loop
3543 Discrim
:= First
(Choices
(Assoc
));
3544 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
3545 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
3547 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
3548 = Chars
(Discrim_Name
))
3549 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
3550 = Chars
(Discrim_Name
);
3552 if No
(Next
(Assoc
)) then
3553 if not Is_Constrained
(Typ
)
3554 and then Is_Derived_Type
(Typ
)
3555 and then Present
(Stored_Constraint
(Typ
))
3557 -- If the type is a tagged type with inherited discriminants,
3558 -- use the stored constraint on the parent in order to find
3559 -- the values of discriminants that are otherwise hidden by an
3560 -- explicit constraint. Renamed discriminants are handled in
3563 -- If several parent discriminants are renamed by a single
3564 -- discriminant of the derived type, the call to obtain the
3565 -- Corresponding_Discriminant field only retrieves the last
3566 -- of them. We recover the constraint on the others from the
3567 -- Stored_Constraint as well.
3574 D
:= First_Discriminant
(Etype
(Typ
));
3575 C
:= First_Elmt
(Stored_Constraint
(Typ
));
3576 while Present
(D
) and then Present
(C
) loop
3577 if Chars
(Discrim_Name
) = Chars
(D
) then
3578 if Is_Entity_Name
(Node
(C
))
3579 and then Entity
(Node
(C
)) = Entity
(Discrim
)
3581 -- D is renamed by Discrim, whose value is given in
3588 Make_Component_Association
(Sloc
(Typ
),
3590 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
3591 Duplicate_Subexpr_No_Checks
(Node
(C
)));
3593 exit Find_Constraint
;
3596 Next_Discriminant
(D
);
3603 if No
(Next
(Assoc
)) then
3604 Error_Msg_NE
(" missing value for discriminant&",
3605 First
(Governed_By
), Discrim_Name
);
3606 Report_Errors
:= True;
3611 end loop Find_Constraint
;
3613 Discrim_Value
:= Expression
(Assoc
);
3615 if not Is_OK_Static_Expression
(Discrim_Value
) then
3617 ("value for discriminant & must be static!",
3618 Discrim_Value
, Discrim
);
3619 Why_Not_Static
(Discrim_Value
);
3620 Report_Errors
:= True;
3624 Search_For_Discriminant_Value
: declare
3630 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
3633 Find_Discrete_Value
: while Present
(Variant
) loop
3634 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
3635 while Present
(Discrete_Choice
) loop
3637 exit Find_Discrete_Value
when
3638 Nkind
(Discrete_Choice
) = N_Others_Choice
;
3640 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
3642 UI_Low
:= Expr_Value
(Low
);
3643 UI_High
:= Expr_Value
(High
);
3645 exit Find_Discrete_Value
when
3646 UI_Low
<= UI_Discrim_Value
3648 UI_High
>= UI_Discrim_Value
;
3650 Next
(Discrete_Choice
);
3653 Next_Non_Pragma
(Variant
);
3654 end loop Find_Discrete_Value
;
3655 end Search_For_Discriminant_Value
;
3657 if No
(Variant
) then
3659 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
3660 Report_Errors
:= True;
3664 -- If we have found the corresponding choice, recursively add its
3665 -- components to the Into list.
3667 Gather_Components
(Empty
,
3668 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
3669 end Gather_Components
;
3671 ------------------------
3672 -- Get_Actual_Subtype --
3673 ------------------------
3675 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
3676 Typ
: constant Entity_Id
:= Etype
(N
);
3677 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
3686 -- If what we have is an identifier that references a subprogram
3687 -- formal, or a variable or constant object, then we get the actual
3688 -- subtype from the referenced entity if one has been built.
3690 if Nkind
(N
) = N_Identifier
3692 (Is_Formal
(Entity
(N
))
3693 or else Ekind
(Entity
(N
)) = E_Constant
3694 or else Ekind
(Entity
(N
)) = E_Variable
)
3695 and then Present
(Actual_Subtype
(Entity
(N
)))
3697 return Actual_Subtype
(Entity
(N
));
3699 -- Actual subtype of unchecked union is always itself. We never need
3700 -- the "real" actual subtype. If we did, we couldn't get it anyway
3701 -- because the discriminant is not available. The restrictions on
3702 -- Unchecked_Union are designed to make sure that this is OK.
3704 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
3707 -- Here for the unconstrained case, we must find actual subtype
3708 -- No actual subtype is available, so we must build it on the fly.
3710 -- Checking the type, not the underlying type, for constrainedness
3711 -- seems to be necessary. Maybe all the tests should be on the type???
3713 elsif (not Is_Constrained
(Typ
))
3714 and then (Is_Array_Type
(Utyp
)
3715 or else (Is_Record_Type
(Utyp
)
3716 and then Has_Discriminants
(Utyp
)))
3717 and then not Has_Unknown_Discriminants
(Utyp
)
3718 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
3720 -- Nothing to do if in spec expression (why not???)
3722 if In_Spec_Expression
then
3725 elsif Is_Private_Type
(Typ
)
3726 and then not Has_Discriminants
(Typ
)
3728 -- If the type has no discriminants, there is no subtype to
3729 -- build, even if the underlying type is discriminated.
3733 -- Else build the actual subtype
3736 Decl
:= Build_Actual_Subtype
(Typ
, N
);
3737 Atyp
:= Defining_Identifier
(Decl
);
3739 -- If Build_Actual_Subtype generated a new declaration then use it
3743 -- The actual subtype is an Itype, so analyze the declaration,
3744 -- but do not attach it to the tree, to get the type defined.
3746 Set_Parent
(Decl
, N
);
3747 Set_Is_Itype
(Atyp
);
3748 Analyze
(Decl
, Suppress
=> All_Checks
);
3749 Set_Associated_Node_For_Itype
(Atyp
, N
);
3750 Set_Has_Delayed_Freeze
(Atyp
, False);
3752 -- We need to freeze the actual subtype immediately. This is
3753 -- needed, because otherwise this Itype will not get frozen
3754 -- at all, and it is always safe to freeze on creation because
3755 -- any associated types must be frozen at this point.
3757 Freeze_Itype
(Atyp
, N
);
3760 -- Otherwise we did not build a declaration, so return original
3767 -- For all remaining cases, the actual subtype is the same as
3768 -- the nominal type.
3773 end Get_Actual_Subtype
;
3775 -------------------------------------
3776 -- Get_Actual_Subtype_If_Available --
3777 -------------------------------------
3779 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
3780 Typ
: constant Entity_Id
:= Etype
(N
);
3783 -- If what we have is an identifier that references a subprogram
3784 -- formal, or a variable or constant object, then we get the actual
3785 -- subtype from the referenced entity if one has been built.
3787 if Nkind
(N
) = N_Identifier
3789 (Is_Formal
(Entity
(N
))
3790 or else Ekind
(Entity
(N
)) = E_Constant
3791 or else Ekind
(Entity
(N
)) = E_Variable
)
3792 and then Present
(Actual_Subtype
(Entity
(N
)))
3794 return Actual_Subtype
(Entity
(N
));
3796 -- Otherwise the Etype of N is returned unchanged
3801 end Get_Actual_Subtype_If_Available
;
3803 -------------------------------
3804 -- Get_Default_External_Name --
3805 -------------------------------
3807 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
3809 Get_Decoded_Name_String
(Chars
(E
));
3811 if Opt
.External_Name_Imp_Casing
= Uppercase
then
3812 Set_Casing
(All_Upper_Case
);
3814 Set_Casing
(All_Lower_Case
);
3818 Make_String_Literal
(Sloc
(E
),
3819 Strval
=> String_From_Name_Buffer
);
3820 end Get_Default_External_Name
;
3822 ---------------------------
3823 -- Get_Enum_Lit_From_Pos --
3824 ---------------------------
3826 function Get_Enum_Lit_From_Pos
3829 Loc
: Source_Ptr
) return Node_Id
3834 -- In the case where the literal is of type Character, Wide_Character
3835 -- or Wide_Wide_Character or of a type derived from them, there needs
3836 -- to be some special handling since there is no explicit chain of
3837 -- literals to search. Instead, an N_Character_Literal node is created
3838 -- with the appropriate Char_Code and Chars fields.
3840 if Is_Standard_Character_Type
(T
) then
3841 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
3843 Make_Character_Literal
(Loc
,
3845 Char_Literal_Value
=> Pos
);
3847 -- For all other cases, we have a complete table of literals, and
3848 -- we simply iterate through the chain of literal until the one
3849 -- with the desired position value is found.
3853 Lit
:= First_Literal
(Base_Type
(T
));
3854 for J
in 1 .. UI_To_Int
(Pos
) loop
3858 return New_Occurrence_Of
(Lit
, Loc
);
3860 end Get_Enum_Lit_From_Pos
;
3862 ------------------------
3863 -- Get_Generic_Entity --
3864 ------------------------
3866 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
3867 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
3869 if Present
(Renamed_Object
(Ent
)) then
3870 return Renamed_Object
(Ent
);
3874 end Get_Generic_Entity
;
3876 ----------------------
3877 -- Get_Index_Bounds --
3878 ----------------------
3880 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
3881 Kind
: constant Node_Kind
:= Nkind
(N
);
3885 if Kind
= N_Range
then
3887 H
:= High_Bound
(N
);
3889 elsif Kind
= N_Subtype_Indication
then
3890 R
:= Range_Expression
(Constraint
(N
));
3898 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
3899 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
3902 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
3903 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
3907 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
3908 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
3911 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
3912 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
3916 -- N is an expression, indicating a range with one value
3921 end Get_Index_Bounds
;
3923 ----------------------------------
3924 -- Get_Library_Unit_Name_string --
3925 ----------------------------------
3927 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
3928 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
3931 Get_Unit_Name_String
(Unit_Name_Id
);
3933 -- Remove seven last character (" (spec)" or " (body)")
3935 Name_Len
:= Name_Len
- 7;
3936 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
3937 end Get_Library_Unit_Name_String
;
3939 ------------------------
3940 -- Get_Name_Entity_Id --
3941 ------------------------
3943 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
3945 return Entity_Id
(Get_Name_Table_Info
(Id
));
3946 end Get_Name_Entity_Id
;
3952 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
3954 return Get_Pragma_Id
(Pragma_Name
(N
));
3957 ---------------------------
3958 -- Get_Referenced_Object --
3959 ---------------------------
3961 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
3966 while Is_Entity_Name
(R
)
3967 and then Present
(Renamed_Object
(Entity
(R
)))
3969 R
:= Renamed_Object
(Entity
(R
));
3973 end Get_Referenced_Object
;
3975 ------------------------
3976 -- Get_Renamed_Entity --
3977 ------------------------
3979 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
3984 while Present
(Renamed_Entity
(R
)) loop
3985 R
:= Renamed_Entity
(R
);
3989 end Get_Renamed_Entity
;
3991 -------------------------
3992 -- Get_Subprogram_Body --
3993 -------------------------
3995 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
3999 Decl
:= Unit_Declaration_Node
(E
);
4001 if Nkind
(Decl
) = N_Subprogram_Body
then
4004 -- The below comment is bad, because it is possible for
4005 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
4007 else -- Nkind (Decl) = N_Subprogram_Declaration
4009 if Present
(Corresponding_Body
(Decl
)) then
4010 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
4012 -- Imported subprogram case
4018 end Get_Subprogram_Body
;
4020 ---------------------------
4021 -- Get_Subprogram_Entity --
4022 ---------------------------
4024 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
4029 if Nkind
(Nod
) = N_Accept_Statement
then
4030 Nam
:= Entry_Direct_Name
(Nod
);
4032 -- For an entry call, the prefix of the call is a selected component.
4033 -- Need additional code for internal calls ???
4035 elsif Nkind
(Nod
) = N_Entry_Call_Statement
then
4036 if Nkind
(Name
(Nod
)) = N_Selected_Component
then
4037 Nam
:= Entity
(Selector_Name
(Name
(Nod
)));
4046 if Nkind
(Nam
) = N_Explicit_Dereference
then
4047 Proc
:= Etype
(Prefix
(Nam
));
4048 elsif Is_Entity_Name
(Nam
) then
4049 Proc
:= Entity
(Nam
);
4054 if Is_Object
(Proc
) then
4055 Proc
:= Etype
(Proc
);
4058 if Ekind
(Proc
) = E_Access_Subprogram_Type
then
4059 Proc
:= Directly_Designated_Type
(Proc
);
4062 if not Is_Subprogram
(Proc
)
4063 and then Ekind
(Proc
) /= E_Subprogram_Type
4069 end Get_Subprogram_Entity
;
4071 -----------------------------
4072 -- Get_Task_Body_Procedure --
4073 -----------------------------
4075 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
4077 -- Note: A task type may be the completion of a private type with
4078 -- discriminants. When performing elaboration checks on a task
4079 -- declaration, the current view of the type may be the private one,
4080 -- and the procedure that holds the body of the task is held in its
4083 -- This is an odd function, why not have Task_Body_Procedure do
4084 -- the following digging???
4086 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
4087 end Get_Task_Body_Procedure
;
4089 -----------------------------
4090 -- Has_Abstract_Interfaces --
4091 -----------------------------
4093 function Has_Abstract_Interfaces
4095 Use_Full_View
: Boolean := True) return Boolean
4100 -- Handle concurrent types
4102 if Is_Concurrent_Type
(T
) then
4103 Typ
:= Corresponding_Record_Type
(T
);
4108 if not Present
(Typ
)
4109 or else not Is_Tagged_Type
(Typ
)
4114 pragma Assert
(Is_Record_Type
(Typ
));
4116 -- Handle private types
4119 and then Present
(Full_View
(Typ
))
4121 Typ
:= Full_View
(Typ
);
4124 -- Handle concurrent record types
4126 if Is_Concurrent_Record_Type
(Typ
)
4127 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
4133 if Is_Interface
(Typ
)
4135 (Is_Record_Type
(Typ
)
4136 and then Present
(Abstract_Interfaces
(Typ
))
4137 and then not Is_Empty_Elmt_List
(Abstract_Interfaces
(Typ
)))
4142 exit when Etype
(Typ
) = Typ
4144 -- Handle private types
4146 or else (Present
(Full_View
(Etype
(Typ
)))
4147 and then Full_View
(Etype
(Typ
)) = Typ
)
4149 -- Protect the frontend against wrong source with cyclic
4152 or else Etype
(Typ
) = T
;
4154 -- Climb to the ancestor type handling private types
4156 if Present
(Full_View
(Etype
(Typ
))) then
4157 Typ
:= Full_View
(Etype
(Typ
));
4164 end Has_Abstract_Interfaces
;
4166 -----------------------
4167 -- Has_Access_Values --
4168 -----------------------
4170 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
4171 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
4174 -- Case of a private type which is not completed yet. This can only
4175 -- happen in the case of a generic format type appearing directly, or
4176 -- as a component of the type to which this function is being applied
4177 -- at the top level. Return False in this case, since we certainly do
4178 -- not know that the type contains access types.
4183 elsif Is_Access_Type
(Typ
) then
4186 elsif Is_Array_Type
(Typ
) then
4187 return Has_Access_Values
(Component_Type
(Typ
));
4189 elsif Is_Record_Type
(Typ
) then
4194 -- Loop to Check components
4196 Comp
:= First_Component_Or_Discriminant
(Typ
);
4197 while Present
(Comp
) loop
4199 -- Check for access component, tag field does not count, even
4200 -- though it is implemented internally using an access type.
4202 if Has_Access_Values
(Etype
(Comp
))
4203 and then Chars
(Comp
) /= Name_uTag
4208 Next_Component_Or_Discriminant
(Comp
);
4217 end Has_Access_Values
;
4219 ------------------------------
4220 -- Has_Compatible_Alignment --
4221 ------------------------------
4223 function Has_Compatible_Alignment
4225 Expr
: Node_Id
) return Alignment_Result
4227 function Has_Compatible_Alignment_Internal
4230 Default
: Alignment_Result
) return Alignment_Result
;
4231 -- This is the internal recursive function that actually does the work.
4232 -- There is one additional parameter, which says what the result should
4233 -- be if no alignment information is found, and there is no definite
4234 -- indication of compatible alignments. At the outer level, this is set
4235 -- to Unknown, but for internal recursive calls in the case where types
4236 -- are known to be correct, it is set to Known_Compatible.
4238 ---------------------------------------
4239 -- Has_Compatible_Alignment_Internal --
4240 ---------------------------------------
4242 function Has_Compatible_Alignment_Internal
4245 Default
: Alignment_Result
) return Alignment_Result
4247 Result
: Alignment_Result
:= Known_Compatible
;
4248 -- Set to result if Problem_Prefix or Problem_Offset returns True.
4249 -- Note that once a value of Known_Incompatible is set, it is sticky
4250 -- and does not get changed to Unknown (the value in Result only gets
4251 -- worse as we go along, never better).
4253 procedure Check_Offset
(Offs
: Uint
);
4254 -- Called when Expr is a selected or indexed component with Offs set
4255 -- to resp Component_First_Bit or Component_Size. Checks that if the
4256 -- offset is specified it is compatible with the object alignment
4257 -- requirements. The value in Result is modified accordingly.
4259 procedure Check_Prefix
;
4260 -- Checks the prefix recursively in the case where the expression
4261 -- is an indexed or selected component.
4263 procedure Set_Result
(R
: Alignment_Result
);
4264 -- If R represents a worse outcome (unknown instead of known
4265 -- compatible, or known incompatible), then set Result to R.
4271 procedure Check_Offset
(Offs
: Uint
) is
4273 -- Unspecified or zero offset is always OK
4275 if Offs
= No_Uint
or else Offs
= Uint_0
then
4278 -- If we do not know required alignment, any non-zero offset is
4279 -- a potential problem (but certainly may be OK, so result is
4282 elsif Unknown_Alignment
(Obj
) then
4283 Set_Result
(Unknown
);
4285 -- If we know the required alignment, see if offset is compatible
4288 if Offs
mod (System_Storage_Unit
* Alignment
(Obj
)) /= 0 then
4289 Set_Result
(Known_Incompatible
);
4298 procedure Check_Prefix
is
4300 -- The subtlety here is that in doing a recursive call to check
4301 -- the prefix, we have to decide what to do in the case where we
4302 -- don't find any specific indication of an alignment problem.
4304 -- At the outer level, we normally set Unknown as the result in
4305 -- this case, since we can only set Known_Compatible if we really
4306 -- know that the alignment value is OK, but for the recursive
4307 -- call, in the case where the types match, and we have not
4308 -- specified a peculiar alignment for the object, we are only
4309 -- concerned about suspicious rep clauses, the default case does
4310 -- not affect us, since the compiler will, in the absence of such
4311 -- rep clauses, ensure that the alignment is correct.
4313 if Default
= Known_Compatible
4315 (Etype
(Obj
) = Etype
(Expr
)
4316 and then (Unknown_Alignment
(Obj
)
4318 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
4321 (Has_Compatible_Alignment_Internal
4322 (Obj
, Prefix
(Expr
), Known_Compatible
));
4324 -- In all other cases, we need a full check on the prefix
4328 (Has_Compatible_Alignment_Internal
4329 (Obj
, Prefix
(Expr
), Unknown
));
4337 procedure Set_Result
(R
: Alignment_Result
) is
4344 -- Start of processing for Has_Compatible_Alignment_Internal
4347 -- If Expr is a selected component, we must make sure there is no
4348 -- potentially troublesome component clause, and that the record is
4351 if Nkind
(Expr
) = N_Selected_Component
then
4353 -- Packed record always generate unknown alignment
4355 if Is_Packed
(Etype
(Prefix
(Expr
))) then
4356 Set_Result
(Unknown
);
4359 -- Check possible bad component offset and check prefix
4362 (Component_Bit_Offset
(Entity
(Selector_Name
(Expr
))));
4365 -- If Expr is an indexed component, we must make sure there is no
4366 -- potentially troublesome Component_Size clause and that the array
4367 -- is not bit-packed.
4369 elsif Nkind
(Expr
) = N_Indexed_Component
then
4371 -- Bit packed array always generates unknown alignment
4373 if Is_Bit_Packed_Array
(Etype
(Prefix
(Expr
))) then
4374 Set_Result
(Unknown
);
4377 -- Check possible bad component size and check prefix
4379 Check_Offset
(Component_Size
(Etype
(Prefix
(Expr
))));
4383 -- Case where we know the alignment of the object
4385 if Known_Alignment
(Obj
) then
4387 ObjA
: constant Uint
:= Alignment
(Obj
);
4388 ExpA
: Uint
:= No_Uint
;
4389 SizA
: Uint
:= No_Uint
;
4392 -- If alignment of Obj is 1, then we are always OK
4395 Set_Result
(Known_Compatible
);
4397 -- Alignment of Obj is greater than 1, so we need to check
4400 -- See if Expr is an object with known alignment
4402 if Is_Entity_Name
(Expr
)
4403 and then Known_Alignment
(Entity
(Expr
))
4405 ExpA
:= Alignment
(Entity
(Expr
));
4407 -- Otherwise, we can use the alignment of the type of
4408 -- Expr given that we already checked for
4409 -- discombobulating rep clauses for the cases of indexed
4410 -- and selected components above.
4412 elsif Known_Alignment
(Etype
(Expr
)) then
4413 ExpA
:= Alignment
(Etype
(Expr
));
4416 -- If we got an alignment, see if it is acceptable
4418 if ExpA
/= No_Uint
then
4420 Set_Result
(Known_Incompatible
);
4423 -- Case of Expr alignment unknown
4426 Set_Result
(Default
);
4429 -- See if size is given. If so, check that it is not too
4430 -- small for the required alignment.
4431 -- See if Expr is an object with known alignment
4433 if Is_Entity_Name
(Expr
)
4434 and then Known_Static_Esize
(Entity
(Expr
))
4436 SizA
:= Esize
(Entity
(Expr
));
4438 -- Otherwise, we check the object size of the Expr type
4440 elsif Known_Static_Esize
(Etype
(Expr
)) then
4441 SizA
:= Esize
(Etype
(Expr
));
4444 -- If we got a size, see if it is a multiple of the Obj
4445 -- alignment, if not, then the alignment cannot be
4446 -- acceptable, since the size is always a multiple of the
4449 if SizA
/= No_Uint
then
4450 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
4451 Set_Result
(Known_Incompatible
);
4457 -- If we can't find the result by direct comparison of alignment
4458 -- values, then there is still one case that we can determine known
4459 -- result, and that is when we can determine that the types are the
4460 -- same, and no alignments are specified. Then we known that the
4461 -- alignments are compatible, even if we don't know the alignment
4462 -- value in the front end.
4464 elsif Etype
(Obj
) = Etype
(Expr
) then
4466 -- Types are the same, but we have to check for possible size
4467 -- and alignments on the Expr object that may make the alignment
4468 -- different, even though the types are the same.
4470 if Is_Entity_Name
(Expr
) then
4472 -- First check alignment of the Expr object. Any alignment less
4473 -- than Maximum_Alignment is worrisome since this is the case
4474 -- where we do not know the alignment of Obj.
4476 if Known_Alignment
(Entity
(Expr
))
4478 UI_To_Int
(Alignment
(Entity
(Expr
)))
4479 < Ttypes
.Maximum_Alignment
4481 Set_Result
(Unknown
);
4483 -- Now check size of Expr object. Any size that is not an
4484 -- even multiple of Maximum_Alignment is also worrisome
4485 -- since it may cause the alignment of the object to be less
4486 -- than the alignment of the type.
4488 elsif Known_Static_Esize
(Entity
(Expr
))
4490 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
4491 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
4494 Set_Result
(Unknown
);
4496 -- Otherwise same type is decisive
4499 Set_Result
(Known_Compatible
);
4503 -- Another case to deal with is when there is an explicit size or
4504 -- alignment clause when the types are not the same. If so, then the
4505 -- result is Unknown. We don't need to do this test if the Default is
4506 -- Unknown, since that result will be set in any case.
4508 elsif Default
/= Unknown
4509 and then (Has_Size_Clause
(Etype
(Expr
))
4511 Has_Alignment_Clause
(Etype
(Expr
)))
4513 Set_Result
(Unknown
);
4515 -- If no indication found, set default
4518 Set_Result
(Default
);
4521 -- Return worst result found
4524 end Has_Compatible_Alignment_Internal
;
4526 -- Start of processing for Has_Compatible_Alignment
4529 -- If Obj has no specified alignment, then set alignment from the type
4530 -- alignment. Perhaps we should always do this, but for sure we should
4531 -- do it when there is an address clause since we can do more if the
4532 -- alignment is known.
4534 if Unknown_Alignment
(Obj
) then
4535 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
4538 -- Now do the internal call that does all the work
4540 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
4541 end Has_Compatible_Alignment
;
4543 ----------------------
4544 -- Has_Declarations --
4545 ----------------------
4547 function Has_Declarations
(N
: Node_Id
) return Boolean is
4548 K
: constant Node_Kind
:= Nkind
(N
);
4550 return K
= N_Accept_Statement
4551 or else K
= N_Block_Statement
4552 or else K
= N_Compilation_Unit_Aux
4553 or else K
= N_Entry_Body
4554 or else K
= N_Package_Body
4555 or else K
= N_Protected_Body
4556 or else K
= N_Subprogram_Body
4557 or else K
= N_Task_Body
4558 or else K
= N_Package_Specification
;
4559 end Has_Declarations
;
4561 -------------------------------------------
4562 -- Has_Discriminant_Dependent_Constraint --
4563 -------------------------------------------
4565 function Has_Discriminant_Dependent_Constraint
4566 (Comp
: Entity_Id
) return Boolean
4568 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
4569 Subt_Indic
: constant Node_Id
:=
4570 Subtype_Indication
(Component_Definition
(Comp_Decl
));
4575 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
4576 Constr
:= Constraint
(Subt_Indic
);
4578 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
4579 Assn
:= First
(Constraints
(Constr
));
4580 while Present
(Assn
) loop
4581 case Nkind
(Assn
) is
4582 when N_Subtype_Indication |
4586 if Depends_On_Discriminant
(Assn
) then
4590 when N_Discriminant_Association
=>
4591 if Depends_On_Discriminant
(Expression
(Assn
)) then
4606 end Has_Discriminant_Dependent_Constraint
;
4608 --------------------
4609 -- Has_Infinities --
4610 --------------------
4612 function Has_Infinities
(E
: Entity_Id
) return Boolean is
4615 Is_Floating_Point_Type
(E
)
4616 and then Nkind
(Scalar_Range
(E
)) = N_Range
4617 and then Includes_Infinities
(Scalar_Range
(E
));
4620 ------------------------
4621 -- Has_Null_Exclusion --
4622 ------------------------
4624 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
4627 when N_Access_Definition |
4628 N_Access_Function_Definition |
4629 N_Access_Procedure_Definition |
4630 N_Access_To_Object_Definition |
4632 N_Derived_Type_Definition |
4633 N_Function_Specification |
4634 N_Subtype_Declaration
=>
4635 return Null_Exclusion_Present
(N
);
4637 when N_Component_Definition |
4638 N_Formal_Object_Declaration |
4639 N_Object_Renaming_Declaration
=>
4640 if Present
(Subtype_Mark
(N
)) then
4641 return Null_Exclusion_Present
(N
);
4642 else pragma Assert
(Present
(Access_Definition
(N
)));
4643 return Null_Exclusion_Present
(Access_Definition
(N
));
4646 when N_Discriminant_Specification
=>
4647 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
4648 return Null_Exclusion_Present
(Discriminant_Type
(N
));
4650 return Null_Exclusion_Present
(N
);
4653 when N_Object_Declaration
=>
4654 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
4655 return Null_Exclusion_Present
(Object_Definition
(N
));
4657 return Null_Exclusion_Present
(N
);
4660 when N_Parameter_Specification
=>
4661 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
4662 return Null_Exclusion_Present
(Parameter_Type
(N
));
4664 return Null_Exclusion_Present
(N
);
4671 end Has_Null_Exclusion
;
4673 ------------------------
4674 -- Has_Null_Extension --
4675 ------------------------
4677 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
4678 B
: constant Entity_Id
:= Base_Type
(T
);
4683 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
4684 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
4686 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
4688 if Present
(Ext
) then
4689 if Null_Present
(Ext
) then
4692 Comps
:= Component_List
(Ext
);
4694 -- The null component list is rewritten during analysis to
4695 -- include the parent component. Any other component indicates
4696 -- that the extension was not originally null.
4698 return Null_Present
(Comps
)
4699 or else No
(Next
(First
(Component_Items
(Comps
))));
4708 end Has_Null_Extension
;
4710 -------------------------------
4711 -- Has_Overriding_Initialize --
4712 -------------------------------
4714 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
4715 BT
: constant Entity_Id
:= Base_Type
(T
);
4720 if Is_Controlled
(BT
) then
4722 -- For derived types, check immediate ancestor, excluding
4723 -- Controlled itself.
4725 if Is_Derived_Type
(BT
)
4726 and then not In_Predefined_Unit
(Etype
(BT
))
4727 and then Has_Overriding_Initialize
(Etype
(BT
))
4731 elsif Present
(Primitive_Operations
(BT
)) then
4732 P
:= First_Elmt
(Primitive_Operations
(BT
));
4733 while Present
(P
) loop
4734 if Chars
(Node
(P
)) = Name_Initialize
4735 and then Comes_From_Source
(Node
(P
))
4746 elsif Has_Controlled_Component
(BT
) then
4747 Comp
:= First_Component
(BT
);
4748 while Present
(Comp
) loop
4749 if Has_Overriding_Initialize
(Etype
(Comp
)) then
4753 Next_Component
(Comp
);
4761 end Has_Overriding_Initialize
;
4763 --------------------------------------
4764 -- Has_Preelaborable_Initialization --
4765 --------------------------------------
4767 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
4770 procedure Check_Components
(E
: Entity_Id
);
4771 -- Check component/discriminant chain, sets Has_PE False if a component
4772 -- or discriminant does not meet the preelaborable initialization rules.
4774 ----------------------
4775 -- Check_Components --
4776 ----------------------
4778 procedure Check_Components
(E
: Entity_Id
) is
4782 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
4783 -- Returns True if and only if the expression denoted by N does not
4784 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
4786 ---------------------------------
4787 -- Is_Preelaborable_Expression --
4788 ---------------------------------
4790 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
4794 Comp_Type
: Entity_Id
;
4795 Is_Array_Aggr
: Boolean;
4798 if Is_Static_Expression
(N
) then
4801 elsif Nkind
(N
) = N_Null
then
4804 -- Attributes are allowed in general, even if their prefix is a
4805 -- formal type. (It seems that certain attributes known not to be
4806 -- static might not be allowed, but there are no rules to prevent
4809 elsif Nkind
(N
) = N_Attribute_Reference
then
4812 -- The name of a discriminant evaluated within its parent type is
4813 -- defined to be preelaborable (10.2.1(8)). Note that we test for
4814 -- names that denote discriminals as well as discriminants to
4815 -- catch references occurring within init procs.
4817 elsif Is_Entity_Name
(N
)
4819 (Ekind
(Entity
(N
)) = E_Discriminant
4821 ((Ekind
(Entity
(N
)) = E_Constant
4822 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
4823 and then Present
(Discriminal_Link
(Entity
(N
)))))
4827 elsif Nkind
(N
) = N_Qualified_Expression
then
4828 return Is_Preelaborable_Expression
(Expression
(N
));
4830 -- For aggregates we have to check that each of the associations
4831 -- is preelaborable.
4833 elsif Nkind
(N
) = N_Aggregate
4834 or else Nkind
(N
) = N_Extension_Aggregate
4836 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
4838 if Is_Array_Aggr
then
4839 Comp_Type
:= Component_Type
(Etype
(N
));
4842 -- Check the ancestor part of extension aggregates, which must
4843 -- be either the name of a type that has preelaborable init or
4844 -- an expression that is preelaborable.
4846 if Nkind
(N
) = N_Extension_Aggregate
then
4848 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
4851 if Is_Entity_Name
(Anc_Part
)
4852 and then Is_Type
(Entity
(Anc_Part
))
4854 if not Has_Preelaborable_Initialization
4860 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
4866 -- Check positional associations
4868 Exp
:= First
(Expressions
(N
));
4869 while Present
(Exp
) loop
4870 if not Is_Preelaborable_Expression
(Exp
) then
4877 -- Check named associations
4879 Assn
:= First
(Component_Associations
(N
));
4880 while Present
(Assn
) loop
4881 Choice
:= First
(Choices
(Assn
));
4882 while Present
(Choice
) loop
4883 if Is_Array_Aggr
then
4884 if Nkind
(Choice
) = N_Others_Choice
then
4887 elsif Nkind
(Choice
) = N_Range
then
4888 if not Is_Static_Range
(Choice
) then
4892 elsif not Is_Static_Expression
(Choice
) then
4897 Comp_Type
:= Etype
(Choice
);
4903 -- If the association has a <> at this point, then we have
4904 -- to check whether the component's type has preelaborable
4905 -- initialization. Note that this only occurs when the
4906 -- association's corresponding component does not have a
4907 -- default expression, the latter case having already been
4908 -- expanded as an expression for the association.
4910 if Box_Present
(Assn
) then
4911 if not Has_Preelaborable_Initialization
(Comp_Type
) then
4915 -- In the expression case we check whether the expression
4916 -- is preelaborable.
4919 not Is_Preelaborable_Expression
(Expression
(Assn
))
4927 -- If we get here then aggregate as a whole is preelaborable
4931 -- All other cases are not preelaborable
4936 end Is_Preelaborable_Expression
;
4938 -- Start of processing for Check_Components
4941 -- Loop through entities of record or protected type
4944 while Present
(Ent
) loop
4946 -- We are interested only in components and discriminants
4948 if Ekind
(Ent
) = E_Component
4950 Ekind
(Ent
) = E_Discriminant
4952 -- Get default expression if any. If there is no declaration
4953 -- node, it means we have an internal entity. The parent and
4954 -- tag fields are examples of such entities. For these cases,
4955 -- we just test the type of the entity.
4957 if Present
(Declaration_Node
(Ent
)) then
4958 Exp
:= Expression
(Declaration_Node
(Ent
));
4963 -- A component has PI if it has no default expression and the
4964 -- component type has PI.
4967 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
4972 -- Require the default expression to be preelaborable
4974 elsif not Is_Preelaborable_Expression
(Exp
) then
4982 end Check_Components
;
4984 -- Start of processing for Has_Preelaborable_Initialization
4987 -- Immediate return if already marked as known preelaborable init. This
4988 -- covers types for which this function has already been called once
4989 -- and returned True (in which case the result is cached), and also
4990 -- types to which a pragma Preelaborable_Initialization applies.
4992 if Known_To_Have_Preelab_Init
(E
) then
4996 -- If the type is a subtype representing a generic actual type, then
4997 -- test whether its base type has preelaborable initialization since
4998 -- the subtype representing the actual does not inherit this attribute
4999 -- from the actual or formal. (but maybe it should???)
5001 if Is_Generic_Actual_Type
(E
) then
5002 return Has_Preelaborable_Initialization
(Base_Type
(E
));
5005 -- Other private types never have preelaborable initialization
5007 if Is_Private_Type
(E
) then
5011 -- Here for all non-private view
5013 -- All elementary types have preelaborable initialization
5015 if Is_Elementary_Type
(E
) then
5018 -- Array types have PI if the component type has PI
5020 elsif Is_Array_Type
(E
) then
5021 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
5023 -- A derived type has preelaborable initialization if its parent type
5024 -- has preelaborable initialization and (in the case of a derived record
5025 -- extension) if the non-inherited components all have preelaborable
5026 -- initialization. However, a user-defined controlled type with an
5027 -- overriding Initialize procedure does not have preelaborable
5030 elsif Is_Derived_Type
(E
) then
5032 -- First check whether ancestor type has preelaborable initialization
5034 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
5036 -- If OK, check extension components (if any)
5038 if Has_PE
and then Is_Record_Type
(E
) then
5039 Check_Components
(First_Entity
(E
));
5042 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
5043 -- with a user defined Initialize procedure does not have PI.
5046 and then Is_Controlled
(E
)
5047 and then Has_Overriding_Initialize
(E
)
5052 -- Record type has PI if it is non private and all components have PI
5054 elsif Is_Record_Type
(E
) then
5056 Check_Components
(First_Entity
(E
));
5058 -- Protected types must not have entries, and components must meet
5059 -- same set of rules as for record components.
5061 elsif Is_Protected_Type
(E
) then
5062 if Has_Entries
(E
) then
5066 Check_Components
(First_Entity
(E
));
5067 Check_Components
(First_Private_Entity
(E
));
5070 -- Type System.Address always has preelaborable initialization
5072 elsif Is_RTE
(E
, RE_Address
) then
5075 -- In all other cases, type does not have preelaborable initialization
5081 -- If type has preelaborable initialization, cache result
5084 Set_Known_To_Have_Preelab_Init
(E
);
5088 end Has_Preelaborable_Initialization
;
5090 ---------------------------
5091 -- Has_Private_Component --
5092 ---------------------------
5094 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
5095 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
5096 Component
: Entity_Id
;
5099 if Error_Posted
(Type_Id
)
5100 or else Error_Posted
(Btype
)
5105 if Is_Class_Wide_Type
(Btype
) then
5106 Btype
:= Root_Type
(Btype
);
5109 if Is_Private_Type
(Btype
) then
5111 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
5114 if No
(Full_View
(Btype
)) then
5115 return not Is_Generic_Type
(Btype
)
5116 and then not Is_Generic_Type
(Root_Type
(Btype
));
5118 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
5121 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
5125 elsif Is_Array_Type
(Btype
) then
5126 return Has_Private_Component
(Component_Type
(Btype
));
5128 elsif Is_Record_Type
(Btype
) then
5129 Component
:= First_Component
(Btype
);
5130 while Present
(Component
) loop
5131 if Has_Private_Component
(Etype
(Component
)) then
5135 Next_Component
(Component
);
5140 elsif Is_Protected_Type
(Btype
)
5141 and then Present
(Corresponding_Record_Type
(Btype
))
5143 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
5148 end Has_Private_Component
;
5154 function Has_Stream
(T
: Entity_Id
) return Boolean is
5161 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
5164 elsif Is_Array_Type
(T
) then
5165 return Has_Stream
(Component_Type
(T
));
5167 elsif Is_Record_Type
(T
) then
5168 E
:= First_Component
(T
);
5169 while Present
(E
) loop
5170 if Has_Stream
(Etype
(E
)) then
5179 elsif Is_Private_Type
(T
) then
5180 return Has_Stream
(Underlying_Type
(T
));
5187 --------------------------
5188 -- Has_Tagged_Component --
5189 --------------------------
5191 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
5195 if Is_Private_Type
(Typ
)
5196 and then Present
(Underlying_Type
(Typ
))
5198 return Has_Tagged_Component
(Underlying_Type
(Typ
));
5200 elsif Is_Array_Type
(Typ
) then
5201 return Has_Tagged_Component
(Component_Type
(Typ
));
5203 elsif Is_Tagged_Type
(Typ
) then
5206 elsif Is_Record_Type
(Typ
) then
5207 Comp
:= First_Component
(Typ
);
5208 while Present
(Comp
) loop
5209 if Has_Tagged_Component
(Etype
(Comp
)) then
5213 Comp
:= Next_Component
(Typ
);
5221 end Has_Tagged_Component
;
5227 function In_Instance
return Boolean is
5228 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
5234 and then S
/= Standard_Standard
5236 if (Ekind
(S
) = E_Function
5237 or else Ekind
(S
) = E_Package
5238 or else Ekind
(S
) = E_Procedure
)
5239 and then Is_Generic_Instance
(S
)
5241 -- A child instance is always compiled in the context of a parent
5242 -- instance. Nevertheless, the actuals are not analyzed in an
5243 -- instance context. We detect this case by examining the current
5244 -- compilation unit, which must be a child instance, and checking
5245 -- that it is not currently on the scope stack.
5247 if Is_Child_Unit
(Curr_Unit
)
5249 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
5250 = N_Package_Instantiation
5251 and then not In_Open_Scopes
(Curr_Unit
)
5265 ----------------------
5266 -- In_Instance_Body --
5267 ----------------------
5269 function In_Instance_Body
return Boolean is
5275 and then S
/= Standard_Standard
5277 if (Ekind
(S
) = E_Function
5278 or else Ekind
(S
) = E_Procedure
)
5279 and then Is_Generic_Instance
(S
)
5283 elsif Ekind
(S
) = E_Package
5284 and then In_Package_Body
(S
)
5285 and then Is_Generic_Instance
(S
)
5294 end In_Instance_Body
;
5296 -----------------------------
5297 -- In_Instance_Not_Visible --
5298 -----------------------------
5300 function In_Instance_Not_Visible
return Boolean is
5306 and then S
/= Standard_Standard
5308 if (Ekind
(S
) = E_Function
5309 or else Ekind
(S
) = E_Procedure
)
5310 and then Is_Generic_Instance
(S
)
5314 elsif Ekind
(S
) = E_Package
5315 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
5316 and then Is_Generic_Instance
(S
)
5325 end In_Instance_Not_Visible
;
5327 ------------------------------
5328 -- In_Instance_Visible_Part --
5329 ------------------------------
5331 function In_Instance_Visible_Part
return Boolean is
5337 and then S
/= Standard_Standard
5339 if Ekind
(S
) = E_Package
5340 and then Is_Generic_Instance
(S
)
5341 and then not In_Package_Body
(S
)
5342 and then not In_Private_Part
(S
)
5351 end In_Instance_Visible_Part
;
5353 ---------------------
5354 -- In_Package_Body --
5355 ---------------------
5357 function In_Package_Body
return Boolean is
5363 and then S
/= Standard_Standard
5365 if Ekind
(S
) = E_Package
5366 and then In_Package_Body
(S
)
5375 end In_Package_Body
;
5377 --------------------------------------
5378 -- In_Subprogram_Or_Concurrent_Unit --
5379 --------------------------------------
5381 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
5386 -- Use scope chain to check successively outer scopes
5392 if K
in Subprogram_Kind
5393 or else K
in Concurrent_Kind
5394 or else K
in Generic_Subprogram_Kind
5398 elsif E
= Standard_Standard
then
5404 end In_Subprogram_Or_Concurrent_Unit
;
5406 ---------------------
5407 -- In_Visible_Part --
5408 ---------------------
5410 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
5413 Is_Package_Or_Generic_Package
(Scope_Id
)
5414 and then In_Open_Scopes
(Scope_Id
)
5415 and then not In_Package_Body
(Scope_Id
)
5416 and then not In_Private_Part
(Scope_Id
);
5417 end In_Visible_Part
;
5419 ---------------------------------
5420 -- Insert_Explicit_Dereference --
5421 ---------------------------------
5423 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
5424 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
5425 Ent
: Entity_Id
:= Empty
;
5432 Save_Interps
(N
, New_Prefix
);
5434 Make_Explicit_Dereference
(Sloc
(N
),
5435 Prefix
=> New_Prefix
));
5437 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
5439 if Is_Overloaded
(New_Prefix
) then
5441 -- The deference is also overloaded, and its interpretations are the
5442 -- designated types of the interpretations of the original node.
5444 Set_Etype
(N
, Any_Type
);
5446 Get_First_Interp
(New_Prefix
, I
, It
);
5447 while Present
(It
.Nam
) loop
5450 if Is_Access_Type
(T
) then
5451 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
5454 Get_Next_Interp
(I
, It
);
5460 -- Prefix is unambiguous: mark the original prefix (which might
5461 -- Come_From_Source) as a reference, since the new (relocated) one
5462 -- won't be taken into account.
5464 if Is_Entity_Name
(New_Prefix
) then
5465 Ent
:= Entity
(New_Prefix
);
5467 -- For a retrieval of a subcomponent of some composite object,
5468 -- retrieve the ultimate entity if there is one.
5470 elsif Nkind
(New_Prefix
) = N_Selected_Component
5471 or else Nkind
(New_Prefix
) = N_Indexed_Component
5473 Pref
:= Prefix
(New_Prefix
);
5474 while Present
(Pref
)
5476 (Nkind
(Pref
) = N_Selected_Component
5477 or else Nkind
(Pref
) = N_Indexed_Component
)
5479 Pref
:= Prefix
(Pref
);
5482 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
5483 Ent
:= Entity
(Pref
);
5487 if Present
(Ent
) then
5488 Generate_Reference
(Ent
, New_Prefix
);
5491 end Insert_Explicit_Dereference
;
5497 function Is_AAMP_Float
(E
: Entity_Id
) return Boolean is
5498 pragma Assert
(Is_Type
(E
));
5500 return AAMP_On_Target
5501 and then Is_Floating_Point_Type
(E
)
5502 and then E
= Base_Type
(E
);
5505 -------------------------
5506 -- Is_Actual_Parameter --
5507 -------------------------
5509 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
5510 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
5514 when N_Parameter_Association
=>
5515 return N
= Explicit_Actual_Parameter
(Parent
(N
));
5517 when N_Function_Call | N_Procedure_Call_Statement
=>
5518 return Is_List_Member
(N
)
5520 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
5525 end Is_Actual_Parameter
;
5527 ---------------------
5528 -- Is_Aliased_View --
5529 ---------------------
5531 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
5535 if Is_Entity_Name
(Obj
) then
5543 or else (Present
(Renamed_Object
(E
))
5544 and then Is_Aliased_View
(Renamed_Object
(E
)))))
5546 or else ((Is_Formal
(E
)
5547 or else Ekind
(E
) = E_Generic_In_Out_Parameter
5548 or else Ekind
(E
) = E_Generic_In_Parameter
)
5549 and then Is_Tagged_Type
(Etype
(E
)))
5551 or else (Is_Concurrent_Type
(E
)
5552 and then In_Open_Scopes
(E
))
5554 -- Current instance of type, either directly or as rewritten
5555 -- reference to the current object.
5557 or else (Is_Entity_Name
(Original_Node
(Obj
))
5558 and then Present
(Entity
(Original_Node
(Obj
)))
5559 and then Is_Type
(Entity
(Original_Node
(Obj
))))
5561 or else (Is_Type
(E
) and then E
= Current_Scope
)
5563 or else (Is_Incomplete_Or_Private_Type
(E
)
5564 and then Full_View
(E
) = Current_Scope
);
5566 elsif Nkind
(Obj
) = N_Selected_Component
then
5567 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
5569 elsif Nkind
(Obj
) = N_Indexed_Component
then
5570 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
5572 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
5574 Has_Aliased_Components
5575 (Designated_Type
(Etype
(Prefix
(Obj
)))));
5577 elsif Nkind
(Obj
) = N_Unchecked_Type_Conversion
5578 or else Nkind
(Obj
) = N_Type_Conversion
5580 return Is_Tagged_Type
(Etype
(Obj
))
5581 and then Is_Aliased_View
(Expression
(Obj
));
5583 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
5584 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
5589 end Is_Aliased_View
;
5591 -------------------------
5592 -- Is_Ancestor_Package --
5593 -------------------------
5595 function Is_Ancestor_Package
5597 E2
: Entity_Id
) return Boolean
5604 and then Par
/= Standard_Standard
5614 end Is_Ancestor_Package
;
5616 ----------------------
5617 -- Is_Atomic_Object --
5618 ----------------------
5620 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
5622 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
5623 -- Determines if given object has atomic components
5625 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
5626 -- If prefix is an implicit dereference, examine designated type
5628 ----------------------
5629 -- Is_Atomic_Prefix --
5630 ----------------------
5632 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
5634 if Is_Access_Type
(Etype
(N
)) then
5636 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
5638 return Object_Has_Atomic_Components
(N
);
5640 end Is_Atomic_Prefix
;
5642 ----------------------------------
5643 -- Object_Has_Atomic_Components --
5644 ----------------------------------
5646 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
5648 if Has_Atomic_Components
(Etype
(N
))
5649 or else Is_Atomic
(Etype
(N
))
5653 elsif Is_Entity_Name
(N
)
5654 and then (Has_Atomic_Components
(Entity
(N
))
5655 or else Is_Atomic
(Entity
(N
)))
5659 elsif Nkind
(N
) = N_Indexed_Component
5660 or else Nkind
(N
) = N_Selected_Component
5662 return Is_Atomic_Prefix
(Prefix
(N
));
5667 end Object_Has_Atomic_Components
;
5669 -- Start of processing for Is_Atomic_Object
5672 if Is_Atomic
(Etype
(N
))
5673 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
5677 elsif Nkind
(N
) = N_Indexed_Component
5678 or else Nkind
(N
) = N_Selected_Component
5680 return Is_Atomic_Prefix
(Prefix
(N
));
5685 end Is_Atomic_Object
;
5687 -------------------------
5688 -- Is_Coextension_Root --
5689 -------------------------
5691 function Is_Coextension_Root
(N
: Node_Id
) return Boolean is
5694 Nkind
(N
) = N_Allocator
5695 and then Present
(Coextensions
(N
))
5697 -- Anonymous access discriminants carry a list of all nested
5698 -- controlled coextensions.
5700 and then not Is_Dynamic_Coextension
(N
)
5701 and then not Is_Static_Coextension
(N
);
5702 end Is_Coextension_Root
;
5704 -----------------------------
5705 -- Is_Concurrent_Interface --
5706 -----------------------------
5708 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
5713 (Is_Protected_Interface
(T
)
5714 or else Is_Synchronized_Interface
(T
)
5715 or else Is_Task_Interface
(T
));
5716 end Is_Concurrent_Interface
;
5718 --------------------------------------
5719 -- Is_Controlling_Limited_Procedure --
5720 --------------------------------------
5722 function Is_Controlling_Limited_Procedure
5723 (Proc_Nam
: Entity_Id
) return Boolean
5725 Param_Typ
: Entity_Id
:= Empty
;
5728 if Ekind
(Proc_Nam
) = E_Procedure
5729 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
5731 Param_Typ
:= Etype
(Parameter_Type
(First
(
5732 Parameter_Specifications
(Parent
(Proc_Nam
)))));
5734 -- In this case where an Itype was created, the procedure call has been
5737 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
5738 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
5740 Present
(Parameter_Associations
5741 (Associated_Node_For_Itype
(Proc_Nam
)))
5744 Etype
(First
(Parameter_Associations
5745 (Associated_Node_For_Itype
(Proc_Nam
))));
5748 if Present
(Param_Typ
) then
5750 Is_Interface
(Param_Typ
)
5751 and then Is_Limited_Record
(Param_Typ
);
5755 end Is_Controlling_Limited_Procedure
;
5757 ----------------------------------------------
5758 -- Is_Dependent_Component_Of_Mutable_Object --
5759 ----------------------------------------------
5761 function Is_Dependent_Component_Of_Mutable_Object
5762 (Object
: Node_Id
) return Boolean
5765 Prefix_Type
: Entity_Id
;
5766 P_Aliased
: Boolean := False;
5769 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
5770 -- Returns True if and only if Comp is declared within a variant part
5772 --------------------------------
5773 -- Is_Declared_Within_Variant --
5774 --------------------------------
5776 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
5777 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
5778 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
5780 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
5781 end Is_Declared_Within_Variant
;
5783 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
5786 if Is_Variable
(Object
) then
5788 if Nkind
(Object
) = N_Selected_Component
then
5789 P
:= Prefix
(Object
);
5790 Prefix_Type
:= Etype
(P
);
5792 if Is_Entity_Name
(P
) then
5794 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
5795 Prefix_Type
:= Base_Type
(Prefix_Type
);
5798 if Is_Aliased
(Entity
(P
)) then
5802 -- A discriminant check on a selected component may be
5803 -- expanded into a dereference when removing side-effects.
5804 -- Recover the original node and its type, which may be
5807 elsif Nkind
(P
) = N_Explicit_Dereference
5808 and then not (Comes_From_Source
(P
))
5810 P
:= Original_Node
(P
);
5811 Prefix_Type
:= Etype
(P
);
5814 -- Check for prefix being an aliased component ???
5819 -- A heap object is constrained by its initial value
5821 -- Ada 2005 (AI-363): Always assume the object could be mutable in
5822 -- the dereferenced case, since the access value might denote an
5823 -- unconstrained aliased object, whereas in Ada 95 the designated
5824 -- object is guaranteed to be constrained. A worst-case assumption
5825 -- has to apply in Ada 2005 because we can't tell at compile time
5826 -- whether the object is "constrained by its initial value"
5827 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
5828 -- semantic rules -- these rules are acknowledged to need fixing).
5830 if Ada_Version
< Ada_05
then
5831 if Is_Access_Type
(Prefix_Type
)
5832 or else Nkind
(P
) = N_Explicit_Dereference
5837 elsif Ada_Version
>= Ada_05
then
5838 if Is_Access_Type
(Prefix_Type
) then
5840 -- If the access type is pool-specific, and there is no
5841 -- constrained partial view of the designated type, then the
5842 -- designated object is known to be constrained.
5844 if Ekind
(Prefix_Type
) = E_Access_Type
5845 and then not Has_Constrained_Partial_View
5846 (Designated_Type
(Prefix_Type
))
5850 -- Otherwise (general access type, or there is a constrained
5851 -- partial view of the designated type), we need to check
5852 -- based on the designated type.
5855 Prefix_Type
:= Designated_Type
(Prefix_Type
);
5861 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
5863 -- As per AI-0017, the renaming is illegal in a generic body,
5864 -- even if the subtype is indefinite.
5866 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
5868 if not Is_Constrained
(Prefix_Type
)
5869 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
5871 (Is_Generic_Type
(Prefix_Type
)
5872 and then Ekind
(Current_Scope
) = E_Generic_Package
5873 and then In_Package_Body
(Current_Scope
)))
5875 and then (Is_Declared_Within_Variant
(Comp
)
5876 or else Has_Discriminant_Dependent_Constraint
(Comp
))
5877 and then (not P_Aliased
or else Ada_Version
>= Ada_05
)
5883 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5887 elsif Nkind
(Object
) = N_Indexed_Component
5888 or else Nkind
(Object
) = N_Slice
5890 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
5892 -- A type conversion that Is_Variable is a view conversion:
5893 -- go back to the denoted object.
5895 elsif Nkind
(Object
) = N_Type_Conversion
then
5897 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
5902 end Is_Dependent_Component_Of_Mutable_Object
;
5904 ---------------------
5905 -- Is_Dereferenced --
5906 ---------------------
5908 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
5909 P
: constant Node_Id
:= Parent
(N
);
5912 (Nkind
(P
) = N_Selected_Component
5914 Nkind
(P
) = N_Explicit_Dereference
5916 Nkind
(P
) = N_Indexed_Component
5918 Nkind
(P
) = N_Slice
)
5919 and then Prefix
(P
) = N
;
5920 end Is_Dereferenced
;
5922 ----------------------
5923 -- Is_Descendent_Of --
5924 ----------------------
5926 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
5931 pragma Assert
(Nkind
(T1
) in N_Entity
);
5932 pragma Assert
(Nkind
(T2
) in N_Entity
);
5934 T
:= Base_Type
(T1
);
5936 -- Immediate return if the types match
5941 -- Comment needed here ???
5943 elsif Ekind
(T
) = E_Class_Wide_Type
then
5944 return Etype
(T
) = T2
;
5952 -- Done if we found the type we are looking for
5957 -- Done if no more derivations to check
5964 -- Following test catches error cases resulting from prev errors
5966 elsif No
(Etyp
) then
5969 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
5972 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
5976 T
:= Base_Type
(Etyp
);
5979 end Is_Descendent_Of
;
5985 function Is_False
(U
: Uint
) return Boolean is
5990 ---------------------------
5991 -- Is_Fixed_Model_Number --
5992 ---------------------------
5994 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
5995 S
: constant Ureal
:= Small_Value
(T
);
5996 M
: Urealp
.Save_Mark
;
6000 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
6003 end Is_Fixed_Model_Number
;
6005 -------------------------------
6006 -- Is_Fully_Initialized_Type --
6007 -------------------------------
6009 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
6011 if Is_Scalar_Type
(Typ
) then
6014 elsif Is_Access_Type
(Typ
) then
6017 elsif Is_Array_Type
(Typ
) then
6018 if Is_Fully_Initialized_Type
(Component_Type
(Typ
)) then
6022 -- An interesting case, if we have a constrained type one of whose
6023 -- bounds is known to be null, then there are no elements to be
6024 -- initialized, so all the elements are initialized!
6026 if Is_Constrained
(Typ
) then
6029 Indx_Typ
: Entity_Id
;
6033 Indx
:= First_Index
(Typ
);
6034 while Present
(Indx
) loop
6035 if Etype
(Indx
) = Any_Type
then
6038 -- If index is a range, use directly
6040 elsif Nkind
(Indx
) = N_Range
then
6041 Lbd
:= Low_Bound
(Indx
);
6042 Hbd
:= High_Bound
(Indx
);
6045 Indx_Typ
:= Etype
(Indx
);
6047 if Is_Private_Type
(Indx_Typ
) then
6048 Indx_Typ
:= Full_View
(Indx_Typ
);
6051 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
6054 Lbd
:= Type_Low_Bound
(Indx_Typ
);
6055 Hbd
:= Type_High_Bound
(Indx_Typ
);
6059 if Compile_Time_Known_Value
(Lbd
)
6060 and then Compile_Time_Known_Value
(Hbd
)
6062 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
6072 -- If no null indexes, then type is not fully initialized
6078 elsif Is_Record_Type
(Typ
) then
6079 if Has_Discriminants
(Typ
)
6081 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
6082 and then Is_Fully_Initialized_Variant
(Typ
)
6087 -- Controlled records are considered to be fully initialized if
6088 -- there is a user defined Initialize routine. This may not be
6089 -- entirely correct, but as the spec notes, we are guessing here
6090 -- what is best from the point of view of issuing warnings.
6092 if Is_Controlled
(Typ
) then
6094 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
6097 if Present
(Utyp
) then
6099 Init
: constant Entity_Id
:=
6101 (Underlying_Type
(Typ
), Name_Initialize
));
6105 and then Comes_From_Source
(Init
)
6107 Is_Predefined_File_Name
6108 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
6112 elsif Has_Null_Extension
(Typ
)
6114 Is_Fully_Initialized_Type
6115 (Etype
(Base_Type
(Typ
)))
6124 -- Otherwise see if all record components are initialized
6130 Ent
:= First_Entity
(Typ
);
6131 while Present
(Ent
) loop
6132 if Chars
(Ent
) = Name_uController
then
6135 elsif Ekind
(Ent
) = E_Component
6136 and then (No
(Parent
(Ent
))
6137 or else No
(Expression
(Parent
(Ent
))))
6138 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
6140 -- Special VM case for tag components, which need to be
6141 -- defined in this case, but are never initialized as VMs
6142 -- are using other dispatching mechanisms. Ignore this
6143 -- uninitialized case. Note that this applies both to the
6144 -- uTag entry and the main vtable pointer (CPP_Class case).
6146 and then (VM_Target
= No_VM
or else not Is_Tag
(Ent
))
6155 -- No uninitialized components, so type is fully initialized.
6156 -- Note that this catches the case of no components as well.
6160 elsif Is_Concurrent_Type
(Typ
) then
6163 elsif Is_Private_Type
(Typ
) then
6165 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6171 return Is_Fully_Initialized_Type
(U
);
6178 end Is_Fully_Initialized_Type
;
6180 ----------------------------------
6181 -- Is_Fully_Initialized_Variant --
6182 ----------------------------------
6184 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
6185 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6186 Constraints
: constant List_Id
:= New_List
;
6187 Components
: constant Elist_Id
:= New_Elmt_List
;
6188 Comp_Elmt
: Elmt_Id
;
6190 Comp_List
: Node_Id
;
6192 Discr_Val
: Node_Id
;
6194 Report_Errors
: Boolean;
6195 pragma Warnings
(Off
, Report_Errors
);
6198 if Serious_Errors_Detected
> 0 then
6202 if Is_Record_Type
(Typ
)
6203 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
6204 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
6206 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
6208 Discr
:= First_Discriminant
(Typ
);
6209 while Present
(Discr
) loop
6210 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
6211 Discr_Val
:= Expression
(Parent
(Discr
));
6213 if Present
(Discr_Val
)
6214 and then Is_OK_Static_Expression
(Discr_Val
)
6216 Append_To
(Constraints
,
6217 Make_Component_Association
(Loc
,
6218 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
6219 Expression
=> New_Copy
(Discr_Val
)));
6227 Next_Discriminant
(Discr
);
6232 Comp_List
=> Comp_List
,
6233 Governed_By
=> Constraints
,
6235 Report_Errors
=> Report_Errors
);
6237 -- Check that each component present is fully initialized
6239 Comp_Elmt
:= First_Elmt
(Components
);
6240 while Present
(Comp_Elmt
) loop
6241 Comp_Id
:= Node
(Comp_Elmt
);
6243 if Ekind
(Comp_Id
) = E_Component
6244 and then (No
(Parent
(Comp_Id
))
6245 or else No
(Expression
(Parent
(Comp_Id
))))
6246 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
6251 Next_Elmt
(Comp_Elmt
);
6256 elsif Is_Private_Type
(Typ
) then
6258 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6264 return Is_Fully_Initialized_Variant
(U
);
6270 end Is_Fully_Initialized_Variant
;
6272 ----------------------------
6273 -- Is_Inherited_Operation --
6274 ----------------------------
6276 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
6277 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
6279 pragma Assert
(Is_Overloadable
(E
));
6280 return Kind
= N_Full_Type_Declaration
6281 or else Kind
= N_Private_Extension_Declaration
6282 or else Kind
= N_Subtype_Declaration
6283 or else (Ekind
(E
) = E_Enumeration_Literal
6284 and then Is_Derived_Type
(Etype
(E
)));
6285 end Is_Inherited_Operation
;
6287 -----------------------------
6288 -- Is_Library_Level_Entity --
6289 -----------------------------
6291 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
6293 -- The following is a small optimization, and it also properly handles
6294 -- discriminals, which in task bodies might appear in expressions before
6295 -- the corresponding procedure has been created, and which therefore do
6296 -- not have an assigned scope.
6298 if Ekind
(E
) in Formal_Kind
then
6302 -- Normal test is simply that the enclosing dynamic scope is Standard
6304 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
6305 end Is_Library_Level_Entity
;
6307 ---------------------------------
6308 -- Is_Local_Variable_Reference --
6309 ---------------------------------
6311 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
6313 if not Is_Entity_Name
(Expr
) then
6318 Ent
: constant Entity_Id
:= Entity
(Expr
);
6319 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
6321 if Ekind
(Ent
) /= E_Variable
6323 Ekind
(Ent
) /= E_In_Out_Parameter
6327 return Present
(Sub
) and then Sub
= Current_Subprogram
;
6331 end Is_Local_Variable_Reference
;
6333 -------------------------
6334 -- Is_Object_Reference --
6335 -------------------------
6337 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
6339 if Is_Entity_Name
(N
) then
6340 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
6344 when N_Indexed_Component | N_Slice
=>
6346 Is_Object_Reference
(Prefix
(N
))
6347 or else Is_Access_Type
(Etype
(Prefix
(N
)));
6349 -- In Ada95, a function call is a constant object; a procedure
6352 when N_Function_Call
=>
6353 return Etype
(N
) /= Standard_Void_Type
;
6355 -- A reference to the stream attribute Input is a function call
6357 when N_Attribute_Reference
=>
6358 return Attribute_Name
(N
) = Name_Input
;
6360 when N_Selected_Component
=>
6362 Is_Object_Reference
(Selector_Name
(N
))
6364 (Is_Object_Reference
(Prefix
(N
))
6365 or else Is_Access_Type
(Etype
(Prefix
(N
))));
6367 when N_Explicit_Dereference
=>
6370 -- A view conversion of a tagged object is an object reference
6372 when N_Type_Conversion
=>
6373 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
6374 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
6375 and then Is_Object_Reference
(Expression
(N
));
6377 -- An unchecked type conversion is considered to be an object if
6378 -- the operand is an object (this construction arises only as a
6379 -- result of expansion activities).
6381 when N_Unchecked_Type_Conversion
=>
6388 end Is_Object_Reference
;
6390 -----------------------------------
6391 -- Is_OK_Variable_For_Out_Formal --
6392 -----------------------------------
6394 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
6396 Note_Possible_Modification
(AV
, Sure
=> True);
6398 -- We must reject parenthesized variable names. The check for
6399 -- Comes_From_Source is present because there are currently
6400 -- cases where the compiler violates this rule (e.g. passing
6401 -- a task object to its controlled Initialize routine).
6403 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
6406 -- A variable is always allowed
6408 elsif Is_Variable
(AV
) then
6411 -- Unchecked conversions are allowed only if they come from the
6412 -- generated code, which sometimes uses unchecked conversions for out
6413 -- parameters in cases where code generation is unaffected. We tell
6414 -- source unchecked conversions by seeing if they are rewrites of an
6415 -- original Unchecked_Conversion function call, or of an explicit
6416 -- conversion of a function call.
6418 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
6419 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
6422 elsif Comes_From_Source
(AV
)
6423 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
6427 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
6428 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
6434 -- Normal type conversions are allowed if argument is a variable
6436 elsif Nkind
(AV
) = N_Type_Conversion
then
6437 if Is_Variable
(Expression
(AV
))
6438 and then Paren_Count
(Expression
(AV
)) = 0
6440 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
6443 -- We also allow a non-parenthesized expression that raises
6444 -- constraint error if it rewrites what used to be a variable
6446 elsif Raises_Constraint_Error
(Expression
(AV
))
6447 and then Paren_Count
(Expression
(AV
)) = 0
6448 and then Is_Variable
(Original_Node
(Expression
(AV
)))
6452 -- Type conversion of something other than a variable
6458 -- If this node is rewritten, then test the original form, if that is
6459 -- OK, then we consider the rewritten node OK (for example, if the
6460 -- original node is a conversion, then Is_Variable will not be true
6461 -- but we still want to allow the conversion if it converts a variable).
6463 elsif Original_Node
(AV
) /= AV
then
6464 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
6466 -- All other non-variables are rejected
6471 end Is_OK_Variable_For_Out_Formal
;
6479 E2
: Entity_Id
) return Boolean
6481 Iface_List
: List_Id
;
6482 T
: Entity_Id
:= E2
;
6485 if Is_Concurrent_Type
(T
)
6486 or else Is_Concurrent_Record_Type
(T
)
6488 Iface_List
:= Abstract_Interface_List
(E2
);
6490 if Is_Empty_List
(Iface_List
) then
6494 T
:= Etype
(First
(Iface_List
));
6497 return Is_Ancestor
(E1
, T
);
6500 -----------------------------------
6501 -- Is_Partially_Initialized_Type --
6502 -----------------------------------
6504 function Is_Partially_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
6506 if Is_Scalar_Type
(Typ
) then
6509 elsif Is_Access_Type
(Typ
) then
6512 elsif Is_Array_Type
(Typ
) then
6514 -- If component type is partially initialized, so is array type
6516 if Is_Partially_Initialized_Type
(Component_Type
(Typ
)) then
6519 -- Otherwise we are only partially initialized if we are fully
6520 -- initialized (this is the empty array case, no point in us
6521 -- duplicating that code here).
6524 return Is_Fully_Initialized_Type
(Typ
);
6527 elsif Is_Record_Type
(Typ
) then
6529 -- A discriminated type is always partially initialized
6531 if Has_Discriminants
(Typ
) then
6534 -- A tagged type is always partially initialized
6536 elsif Is_Tagged_Type
(Typ
) then
6539 -- Case of non-discriminated record
6545 Component_Present
: Boolean := False;
6546 -- Set True if at least one component is present. If no
6547 -- components are present, then record type is fully
6548 -- initialized (another odd case, like the null array).
6551 -- Loop through components
6553 Ent
:= First_Entity
(Typ
);
6554 while Present
(Ent
) loop
6555 if Ekind
(Ent
) = E_Component
then
6556 Component_Present
:= True;
6558 -- If a component has an initialization expression then
6559 -- the enclosing record type is partially initialized
6561 if Present
(Parent
(Ent
))
6562 and then Present
(Expression
(Parent
(Ent
)))
6566 -- If a component is of a type which is itself partially
6567 -- initialized, then the enclosing record type is also.
6569 elsif Is_Partially_Initialized_Type
(Etype
(Ent
)) then
6577 -- No initialized components found. If we found any components
6578 -- they were all uninitialized so the result is false.
6580 if Component_Present
then
6583 -- But if we found no components, then all the components are
6584 -- initialized so we consider the type to be initialized.
6592 -- Concurrent types are always fully initialized
6594 elsif Is_Concurrent_Type
(Typ
) then
6597 -- For a private type, go to underlying type. If there is no underlying
6598 -- type then just assume this partially initialized. Not clear if this
6599 -- can happen in a non-error case, but no harm in testing for this.
6601 elsif Is_Private_Type
(Typ
) then
6603 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
6608 return Is_Partially_Initialized_Type
(U
);
6612 -- For any other type (are there any?) assume partially initialized
6617 end Is_Partially_Initialized_Type
;
6619 ------------------------------------
6620 -- Is_Potentially_Persistent_Type --
6621 ------------------------------------
6623 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
6628 -- For private type, test corresponding full type
6630 if Is_Private_Type
(T
) then
6631 return Is_Potentially_Persistent_Type
(Full_View
(T
));
6633 -- Scalar types are potentially persistent
6635 elsif Is_Scalar_Type
(T
) then
6638 -- Record type is potentially persistent if not tagged and the types of
6639 -- all it components are potentially persistent, and no component has
6640 -- an initialization expression.
6642 elsif Is_Record_Type
(T
)
6643 and then not Is_Tagged_Type
(T
)
6644 and then not Is_Partially_Initialized_Type
(T
)
6646 Comp
:= First_Component
(T
);
6647 while Present
(Comp
) loop
6648 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
6657 -- Array type is potentially persistent if its component type is
6658 -- potentially persistent and if all its constraints are static.
6660 elsif Is_Array_Type
(T
) then
6661 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
6665 Indx
:= First_Index
(T
);
6666 while Present
(Indx
) loop
6667 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
6676 -- All other types are not potentially persistent
6681 end Is_Potentially_Persistent_Type
;
6683 -----------------------------
6684 -- Is_RCI_Pkg_Spec_Or_Body --
6685 -----------------------------
6687 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
6689 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
6690 -- Return True if the unit of Cunit is an RCI package declaration
6692 ---------------------------
6693 -- Is_RCI_Pkg_Decl_Cunit --
6694 ---------------------------
6696 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
6697 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
6700 if Nkind
(The_Unit
) /= N_Package_Declaration
then
6704 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
6705 end Is_RCI_Pkg_Decl_Cunit
;
6707 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
6710 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
6712 (Nkind
(Unit
(Cunit
)) = N_Package_Body
6713 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
6714 end Is_RCI_Pkg_Spec_Or_Body
;
6716 -----------------------------------------
6717 -- Is_Remote_Access_To_Class_Wide_Type --
6718 -----------------------------------------
6720 function Is_Remote_Access_To_Class_Wide_Type
6721 (E
: Entity_Id
) return Boolean
6725 function Comes_From_Limited_Private_Type_Declaration
6726 (E
: Entity_Id
) return Boolean;
6727 -- Check that the type is declared by a limited type declaration,
6728 -- or else is derived from a Remote_Type ancestor through private
6731 -------------------------------------------------
6732 -- Comes_From_Limited_Private_Type_Declaration --
6733 -------------------------------------------------
6735 function Comes_From_Limited_Private_Type_Declaration
6736 (E
: Entity_Id
) return Boolean
6738 N
: constant Node_Id
:= Declaration_Node
(E
);
6741 if Nkind
(N
) = N_Private_Type_Declaration
6742 and then Limited_Present
(N
)
6747 if Nkind
(N
) = N_Private_Extension_Declaration
then
6749 Comes_From_Limited_Private_Type_Declaration
(Etype
(E
))
6751 (Is_Remote_Types
(Etype
(E
))
6752 and then Is_Limited_Record
(Etype
(E
))
6753 and then Has_Private_Declaration
(Etype
(E
)));
6757 end Comes_From_Limited_Private_Type_Declaration
;
6759 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
6762 if not (Is_Remote_Call_Interface
(E
)
6763 or else Is_Remote_Types
(E
))
6764 or else Ekind
(E
) /= E_General_Access_Type
6769 D
:= Designated_Type
(E
);
6771 if Ekind
(D
) /= E_Class_Wide_Type
then
6775 return Comes_From_Limited_Private_Type_Declaration
6776 (Defining_Identifier
(Parent
(D
)));
6777 end Is_Remote_Access_To_Class_Wide_Type
;
6779 -----------------------------------------
6780 -- Is_Remote_Access_To_Subprogram_Type --
6781 -----------------------------------------
6783 function Is_Remote_Access_To_Subprogram_Type
6784 (E
: Entity_Id
) return Boolean
6787 return (Ekind
(E
) = E_Access_Subprogram_Type
6788 or else (Ekind
(E
) = E_Record_Type
6789 and then Present
(Corresponding_Remote_Type
(E
))))
6790 and then (Is_Remote_Call_Interface
(E
)
6791 or else Is_Remote_Types
(E
));
6792 end Is_Remote_Access_To_Subprogram_Type
;
6794 --------------------
6795 -- Is_Remote_Call --
6796 --------------------
6798 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
6800 if Nkind
(N
) /= N_Procedure_Call_Statement
6801 and then Nkind
(N
) /= N_Function_Call
6803 -- An entry call cannot be remote
6807 elsif Nkind
(Name
(N
)) in N_Has_Entity
6808 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
6810 -- A subprogram declared in the spec of a RCI package is remote
6814 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
6815 and then Is_Remote_Access_To_Subprogram_Type
6816 (Etype
(Prefix
(Name
(N
))))
6818 -- The dereference of a RAS is a remote call
6822 elsif Present
(Controlling_Argument
(N
))
6823 and then Is_Remote_Access_To_Class_Wide_Type
6824 (Etype
(Controlling_Argument
(N
)))
6826 -- Any primitive operation call with a controlling argument of
6827 -- a RACW type is a remote call.
6832 -- All other calls are local calls
6837 ----------------------
6838 -- Is_Renamed_Entry --
6839 ----------------------
6841 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
6842 Orig_Node
: Node_Id
:= Empty
;
6843 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
6845 function Is_Entry
(Nam
: Node_Id
) return Boolean;
6846 -- Determine whether Nam is an entry. Traverse selectors
6847 -- if there are nested selected components.
6853 function Is_Entry
(Nam
: Node_Id
) return Boolean is
6855 if Nkind
(Nam
) = N_Selected_Component
then
6856 return Is_Entry
(Selector_Name
(Nam
));
6859 return Ekind
(Entity
(Nam
)) = E_Entry
;
6862 -- Start of processing for Is_Renamed_Entry
6865 if Present
(Alias
(Proc_Nam
)) then
6866 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
6869 -- Look for a rewritten subprogram renaming declaration
6871 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
6872 and then Present
(Original_Node
(Subp_Decl
))
6874 Orig_Node
:= Original_Node
(Subp_Decl
);
6877 -- The rewritten subprogram is actually an entry
6879 if Present
(Orig_Node
)
6880 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
6881 and then Is_Entry
(Name
(Orig_Node
))
6887 end Is_Renamed_Entry
;
6889 ----------------------
6890 -- Is_Selector_Name --
6891 ----------------------
6893 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
6895 if not Is_List_Member
(N
) then
6897 P
: constant Node_Id
:= Parent
(N
);
6898 K
: constant Node_Kind
:= Nkind
(P
);
6901 (K
= N_Expanded_Name
or else
6902 K
= N_Generic_Association
or else
6903 K
= N_Parameter_Association
or else
6904 K
= N_Selected_Component
)
6905 and then Selector_Name
(P
) = N
;
6910 L
: constant List_Id
:= List_Containing
(N
);
6911 P
: constant Node_Id
:= Parent
(L
);
6913 return (Nkind
(P
) = N_Discriminant_Association
6914 and then Selector_Names
(P
) = L
)
6916 (Nkind
(P
) = N_Component_Association
6917 and then Choices
(P
) = L
);
6920 end Is_Selector_Name
;
6926 function Is_Statement
(N
: Node_Id
) return Boolean is
6929 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
6930 or else Nkind
(N
) = N_Procedure_Call_Statement
;
6933 ---------------------------------
6934 -- Is_Synchronized_Tagged_Type --
6935 ---------------------------------
6937 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
6938 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
6941 -- A task or protected type derived from an interface is a tagged type.
6942 -- Such a tagged type is called a synchronized tagged type, as are
6943 -- synchronized interfaces and private extensions whose declaration
6944 -- includes the reserved word synchronized.
6946 return (Is_Tagged_Type
(E
)
6947 and then (Kind
= E_Task_Type
6948 or else Kind
= E_Protected_Type
))
6951 and then Is_Synchronized_Interface
(E
))
6953 (Ekind
(E
) = E_Record_Type_With_Private
6954 and then (Synchronized_Present
(Parent
(E
))
6955 or else Is_Synchronized_Interface
(Etype
(E
))));
6956 end Is_Synchronized_Tagged_Type
;
6962 function Is_Transfer
(N
: Node_Id
) return Boolean is
6963 Kind
: constant Node_Kind
:= Nkind
(N
);
6966 if Kind
= N_Simple_Return_Statement
6968 Kind
= N_Extended_Return_Statement
6970 Kind
= N_Goto_Statement
6972 Kind
= N_Raise_Statement
6974 Kind
= N_Requeue_Statement
6978 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
6979 and then No
(Condition
(N
))
6983 elsif Kind
= N_Procedure_Call_Statement
6984 and then Is_Entity_Name
(Name
(N
))
6985 and then Present
(Entity
(Name
(N
)))
6986 and then No_Return
(Entity
(Name
(N
)))
6990 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
7002 function Is_True
(U
: Uint
) return Boolean is
7011 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
7013 return VM_Target
= CLI_Target
7014 and then Chars
(T
) /= No_Name
7015 and then Get_Name_String
(Chars
(T
)) = "valuetype";
7022 function Is_Variable
(N
: Node_Id
) return Boolean is
7024 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
7025 -- We do the test on the original node, since this is basically a
7026 -- test of syntactic categories, so it must not be disturbed by
7027 -- whatever rewriting might have occurred. For example, an aggregate,
7028 -- which is certainly NOT a variable, could be turned into a variable
7031 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
7032 -- Within a protected function, the private components of the
7033 -- enclosing protected type are constants. A function nested within
7034 -- a (protected) procedure is not itself protected.
7036 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
7037 -- Prefixes can involve implicit dereferences, in which case we
7038 -- must test for the case of a reference of a constant access
7039 -- type, which can never be a variable.
7041 ---------------------------
7042 -- In_Protected_Function --
7043 ---------------------------
7045 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
7046 Prot
: constant Entity_Id
:= Scope
(E
);
7050 if not Is_Protected_Type
(Prot
) then
7054 while Present
(S
) and then S
/= Prot
loop
7055 if Ekind
(S
) = E_Function
7056 and then Scope
(S
) = Prot
7066 end In_Protected_Function
;
7068 ------------------------
7069 -- Is_Variable_Prefix --
7070 ------------------------
7072 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
7074 if Is_Access_Type
(Etype
(P
)) then
7075 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
7077 -- For the case of an indexed component whose prefix has a packed
7078 -- array type, the prefix has been rewritten into a type conversion.
7079 -- Determine variable-ness from the converted expression.
7081 elsif Nkind
(P
) = N_Type_Conversion
7082 and then not Comes_From_Source
(P
)
7083 and then Is_Array_Type
(Etype
(P
))
7084 and then Is_Packed
(Etype
(P
))
7086 return Is_Variable
(Expression
(P
));
7089 return Is_Variable
(P
);
7091 end Is_Variable_Prefix
;
7093 -- Start of processing for Is_Variable
7096 -- Definitely OK if Assignment_OK is set. Since this is something that
7097 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
7099 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
7102 -- Normally we go to the original node, but there is one exception
7103 -- where we use the rewritten node, namely when it is an explicit
7104 -- dereference. The generated code may rewrite a prefix which is an
7105 -- access type with an explicit dereference. The dereference is a
7106 -- variable, even though the original node may not be (since it could
7107 -- be a constant of the access type).
7109 -- In Ada 2005 we have a further case to consider: the prefix may be
7110 -- a function call given in prefix notation. The original node appears
7111 -- to be a selected component, but we need to examine the call.
7113 elsif Nkind
(N
) = N_Explicit_Dereference
7114 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
7115 and then Present
(Etype
(Orig_Node
))
7116 and then Is_Access_Type
(Etype
(Orig_Node
))
7118 return Is_Variable_Prefix
(Original_Node
(Prefix
(N
)))
7120 (Nkind
(Orig_Node
) = N_Function_Call
7121 and then not Is_Access_Constant
(Etype
(Prefix
(N
))));
7123 -- A function call is never a variable
7125 elsif Nkind
(N
) = N_Function_Call
then
7128 -- All remaining checks use the original node
7130 elsif Is_Entity_Name
(Orig_Node
)
7131 and then Present
(Entity
(Orig_Node
))
7134 E
: constant Entity_Id
:= Entity
(Orig_Node
);
7135 K
: constant Entity_Kind
:= Ekind
(E
);
7138 return (K
= E_Variable
7139 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
7140 or else (K
= E_Component
7141 and then not In_Protected_Function
(E
))
7142 or else K
= E_Out_Parameter
7143 or else K
= E_In_Out_Parameter
7144 or else K
= E_Generic_In_Out_Parameter
7146 -- Current instance of type:
7148 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
7149 or else (Is_Incomplete_Or_Private_Type
(E
)
7150 and then In_Open_Scopes
(Full_View
(E
)));
7154 case Nkind
(Orig_Node
) is
7155 when N_Indexed_Component | N_Slice
=>
7156 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
7158 when N_Selected_Component
=>
7159 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
7160 and then Is_Variable
(Selector_Name
(Orig_Node
));
7162 -- For an explicit dereference, the type of the prefix cannot
7163 -- be an access to constant or an access to subprogram.
7165 when N_Explicit_Dereference
=>
7167 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
7169 return Is_Access_Type
(Typ
)
7170 and then not Is_Access_Constant
(Root_Type
(Typ
))
7171 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
7174 -- The type conversion is the case where we do not deal with the
7175 -- context dependent special case of an actual parameter. Thus
7176 -- the type conversion is only considered a variable for the
7177 -- purposes of this routine if the target type is tagged. However,
7178 -- a type conversion is considered to be a variable if it does not
7179 -- come from source (this deals for example with the conversions
7180 -- of expressions to their actual subtypes).
7182 when N_Type_Conversion
=>
7183 return Is_Variable
(Expression
(Orig_Node
))
7185 (not Comes_From_Source
(Orig_Node
)
7187 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
7189 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
7191 -- GNAT allows an unchecked type conversion as a variable. This
7192 -- only affects the generation of internal expanded code, since
7193 -- calls to instantiations of Unchecked_Conversion are never
7194 -- considered variables (since they are function calls).
7195 -- This is also true for expression actions.
7197 when N_Unchecked_Type_Conversion
=>
7198 return Is_Variable
(Expression
(Orig_Node
));
7206 ------------------------
7207 -- Is_Volatile_Object --
7208 ------------------------
7210 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
7212 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
7213 -- Determines if given object has volatile components
7215 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
7216 -- If prefix is an implicit dereference, examine designated type
7218 ------------------------
7219 -- Is_Volatile_Prefix --
7220 ------------------------
7222 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
7223 Typ
: constant Entity_Id
:= Etype
(N
);
7226 if Is_Access_Type
(Typ
) then
7228 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
7231 return Is_Volatile
(Dtyp
)
7232 or else Has_Volatile_Components
(Dtyp
);
7236 return Object_Has_Volatile_Components
(N
);
7238 end Is_Volatile_Prefix
;
7240 ------------------------------------
7241 -- Object_Has_Volatile_Components --
7242 ------------------------------------
7244 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
7245 Typ
: constant Entity_Id
:= Etype
(N
);
7248 if Is_Volatile
(Typ
)
7249 or else Has_Volatile_Components
(Typ
)
7253 elsif Is_Entity_Name
(N
)
7254 and then (Has_Volatile_Components
(Entity
(N
))
7255 or else Is_Volatile
(Entity
(N
)))
7259 elsif Nkind
(N
) = N_Indexed_Component
7260 or else Nkind
(N
) = N_Selected_Component
7262 return Is_Volatile_Prefix
(Prefix
(N
));
7267 end Object_Has_Volatile_Components
;
7269 -- Start of processing for Is_Volatile_Object
7272 if Is_Volatile
(Etype
(N
))
7273 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
7277 elsif Nkind
(N
) = N_Indexed_Component
7278 or else Nkind
(N
) = N_Selected_Component
7280 return Is_Volatile_Prefix
(Prefix
(N
));
7285 end Is_Volatile_Object
;
7287 -------------------------
7288 -- Kill_Current_Values --
7289 -------------------------
7291 procedure Kill_Current_Values
7293 Last_Assignment_Only
: Boolean := False)
7296 if Is_Assignable
(Ent
) then
7297 Set_Last_Assignment
(Ent
, Empty
);
7300 if not Last_Assignment_Only
and then Is_Object
(Ent
) then
7302 Set_Current_Value
(Ent
, Empty
);
7304 if not Can_Never_Be_Null
(Ent
) then
7305 Set_Is_Known_Non_Null
(Ent
, False);
7308 Set_Is_Known_Null
(Ent
, False);
7310 end Kill_Current_Values
;
7312 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
7315 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
7316 -- Clear current value for entity E and all entities chained to E
7318 ------------------------------------------
7319 -- Kill_Current_Values_For_Entity_Chain --
7320 ------------------------------------------
7322 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
7326 while Present
(Ent
) loop
7327 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
7330 end Kill_Current_Values_For_Entity_Chain
;
7332 -- Start of processing for Kill_Current_Values
7335 -- Kill all saved checks, a special case of killing saved values
7337 if not Last_Assignment_Only
then
7341 -- Loop through relevant scopes, which includes the current scope and
7342 -- any parent scopes if the current scope is a block or a package.
7347 -- Clear current values of all entities in current scope
7349 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
7351 -- If scope is a package, also clear current values of all
7352 -- private entities in the scope.
7354 if Ekind
(S
) = E_Package
7356 Ekind
(S
) = E_Generic_Package
7358 Is_Concurrent_Type
(S
)
7360 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
7363 -- If this is a not a subprogram, deal with parents
7365 if not Is_Subprogram
(S
) then
7367 exit Scope_Loop
when S
= Standard_Standard
;
7371 end loop Scope_Loop
;
7372 end Kill_Current_Values
;
7374 --------------------------
7375 -- Kill_Size_Check_Code --
7376 --------------------------
7378 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
7380 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
7381 and then Present
(Size_Check_Code
(E
))
7383 Remove
(Size_Check_Code
(E
));
7384 Set_Size_Check_Code
(E
, Empty
);
7386 end Kill_Size_Check_Code
;
7388 --------------------------
7389 -- Known_To_Be_Assigned --
7390 --------------------------
7392 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
7393 P
: constant Node_Id
:= Parent
(N
);
7398 -- Test left side of assignment
7400 when N_Assignment_Statement
=>
7401 return N
= Name
(P
);
7403 -- Function call arguments are never lvalues
7405 when N_Function_Call
=>
7408 -- Positional parameter for procedure or accept call
7410 when N_Procedure_Call_Statement |
7419 Proc
:= Get_Subprogram_Entity
(P
);
7425 -- If we are not a list member, something is strange, so
7426 -- be conservative and return False.
7428 if not Is_List_Member
(N
) then
7432 -- We are going to find the right formal by stepping forward
7433 -- through the formals, as we step backwards in the actuals.
7435 Form
:= First_Formal
(Proc
);
7438 -- If no formal, something is weird, so be conservative
7439 -- and return False.
7450 return Ekind
(Form
) /= E_In_Parameter
;
7453 -- Named parameter for procedure or accept call
7455 when N_Parameter_Association
=>
7461 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7467 -- Loop through formals to find the one that matches
7469 Form
:= First_Formal
(Proc
);
7471 -- If no matching formal, that's peculiar, some kind of
7472 -- previous error, so return False to be conservative.
7478 -- Else test for match
7480 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7481 return Ekind
(Form
) /= E_In_Parameter
;
7488 -- Test for appearing in a conversion that itself appears
7489 -- in an lvalue context, since this should be an lvalue.
7491 when N_Type_Conversion
=>
7492 return Known_To_Be_Assigned
(P
);
7494 -- All other references are definitely not known to be modifications
7500 end Known_To_Be_Assigned
;
7506 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
7507 P
: constant Node_Id
:= Parent
(N
);
7512 -- Test left side of assignment
7514 when N_Assignment_Statement
=>
7515 return N
= Name
(P
);
7517 -- Test prefix of component or attribute
7519 when N_Attribute_Reference
=>
7520 return N
= Prefix
(P
)
7521 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
7523 when N_Expanded_Name |
7524 N_Explicit_Dereference |
7525 N_Indexed_Component |
7527 N_Selected_Component |
7529 return N
= Prefix
(P
);
7531 -- Function call arguments are never lvalues
7533 when N_Function_Call
=>
7536 -- Positional parameter for procedure, entry, or accept call
7538 when N_Procedure_Call_Statement |
7539 N_Entry_Call_Statement |
7548 Proc
:= Get_Subprogram_Entity
(P
);
7554 -- If we are not a list member, something is strange, so
7555 -- be conservative and return True.
7557 if not Is_List_Member
(N
) then
7561 -- We are going to find the right formal by stepping forward
7562 -- through the formals, as we step backwards in the actuals.
7564 Form
:= First_Formal
(Proc
);
7567 -- If no formal, something is weird, so be conservative
7579 return Ekind
(Form
) /= E_In_Parameter
;
7582 -- Named parameter for procedure or accept call
7584 when N_Parameter_Association
=>
7590 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
7596 -- Loop through formals to find the one that matches
7598 Form
:= First_Formal
(Proc
);
7600 -- If no matching formal, that's peculiar, some kind of
7601 -- previous error, so return True to be conservative.
7607 -- Else test for match
7609 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
7610 return Ekind
(Form
) /= E_In_Parameter
;
7617 -- Test for appearing in a conversion that itself appears in an
7618 -- lvalue context, since this should be an lvalue.
7620 when N_Type_Conversion
=>
7621 return May_Be_Lvalue
(P
);
7623 -- Test for appearance in object renaming declaration
7625 when N_Object_Renaming_Declaration
=>
7628 -- All other references are definitely not Lvalues
7636 -----------------------
7637 -- Mark_Coextensions --
7638 -----------------------
7640 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
7641 Is_Dynamic
: Boolean;
7642 -- Indicates whether the context causes nested coextensions to be
7643 -- dynamic or static
7645 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
7646 -- Recognize an allocator node and label it as a dynamic coextension
7648 --------------------
7649 -- Mark_Allocator --
7650 --------------------
7652 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
7654 if Nkind
(N
) = N_Allocator
then
7656 Set_Is_Dynamic_Coextension
(N
);
7658 Set_Is_Static_Coextension
(N
);
7665 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
7667 -- Start of processing Mark_Coextensions
7670 case Nkind
(Context_Nod
) is
7671 when N_Assignment_Statement |
7672 N_Simple_Return_Statement
=>
7673 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
7675 when N_Object_Declaration
=>
7676 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
;
7678 -- This routine should not be called for constructs which may not
7679 -- contain coextensions.
7682 raise Program_Error
;
7685 Mark_Allocators
(Root_Nod
);
7686 end Mark_Coextensions
;
7688 ----------------------
7689 -- Needs_One_Actual --
7690 ----------------------
7692 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
7696 if Ada_Version
>= Ada_05
7697 and then Present
(First_Formal
(E
))
7699 Formal
:= Next_Formal
(First_Formal
(E
));
7700 while Present
(Formal
) loop
7701 if No
(Default_Value
(Formal
)) then
7705 Next_Formal
(Formal
);
7713 end Needs_One_Actual
;
7715 -------------------------
7716 -- New_External_Entity --
7717 -------------------------
7719 function New_External_Entity
7720 (Kind
: Entity_Kind
;
7721 Scope_Id
: Entity_Id
;
7722 Sloc_Value
: Source_Ptr
;
7723 Related_Id
: Entity_Id
;
7725 Suffix_Index
: Nat
:= 0;
7726 Prefix
: Character := ' ') return Entity_Id
7728 N
: constant Entity_Id
:=
7729 Make_Defining_Identifier
(Sloc_Value
,
7731 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
7734 Set_Ekind
(N
, Kind
);
7735 Set_Is_Internal
(N
, True);
7736 Append_Entity
(N
, Scope_Id
);
7737 Set_Public_Status
(N
);
7739 if Kind
in Type_Kind
then
7740 Init_Size_Align
(N
);
7744 end New_External_Entity
;
7746 -------------------------
7747 -- New_Internal_Entity --
7748 -------------------------
7750 function New_Internal_Entity
7751 (Kind
: Entity_Kind
;
7752 Scope_Id
: Entity_Id
;
7753 Sloc_Value
: Source_Ptr
;
7754 Id_Char
: Character) return Entity_Id
7756 N
: constant Entity_Id
:=
7757 Make_Defining_Identifier
(Sloc_Value
, New_Internal_Name
(Id_Char
));
7760 Set_Ekind
(N
, Kind
);
7761 Set_Is_Internal
(N
, True);
7762 Append_Entity
(N
, Scope_Id
);
7764 if Kind
in Type_Kind
then
7765 Init_Size_Align
(N
);
7769 end New_Internal_Entity
;
7775 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
7779 -- If we are pointing at a positional parameter, it is a member of a
7780 -- node list (the list of parameters), and the next parameter is the
7781 -- next node on the list, unless we hit a parameter association, then
7782 -- we shift to using the chain whose head is the First_Named_Actual in
7783 -- the parent, and then is threaded using the Next_Named_Actual of the
7784 -- Parameter_Association. All this fiddling is because the original node
7785 -- list is in the textual call order, and what we need is the
7786 -- declaration order.
7788 if Is_List_Member
(Actual_Id
) then
7789 N
:= Next
(Actual_Id
);
7791 if Nkind
(N
) = N_Parameter_Association
then
7792 return First_Named_Actual
(Parent
(Actual_Id
));
7798 return Next_Named_Actual
(Parent
(Actual_Id
));
7802 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
7804 Actual_Id
:= Next_Actual
(Actual_Id
);
7807 -----------------------
7808 -- Normalize_Actuals --
7809 -----------------------
7811 -- Chain actuals according to formals of subprogram. If there are no named
7812 -- associations, the chain is simply the list of Parameter Associations,
7813 -- since the order is the same as the declaration order. If there are named
7814 -- associations, then the First_Named_Actual field in the N_Function_Call
7815 -- or N_Procedure_Call_Statement node points to the Parameter_Association
7816 -- node for the parameter that comes first in declaration order. The
7817 -- remaining named parameters are then chained in declaration order using
7818 -- Next_Named_Actual.
7820 -- This routine also verifies that the number of actuals is compatible with
7821 -- the number and default values of formals, but performs no type checking
7822 -- (type checking is done by the caller).
7824 -- If the matching succeeds, Success is set to True and the caller proceeds
7825 -- with type-checking. If the match is unsuccessful, then Success is set to
7826 -- False, and the caller attempts a different interpretation, if there is
7829 -- If the flag Report is on, the call is not overloaded, and a failure to
7830 -- match can be reported here, rather than in the caller.
7832 procedure Normalize_Actuals
7836 Success
: out Boolean)
7838 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
7839 Actual
: Node_Id
:= Empty
;
7841 Last
: Node_Id
:= Empty
;
7842 First_Named
: Node_Id
:= Empty
;
7845 Formals_To_Match
: Integer := 0;
7846 Actuals_To_Match
: Integer := 0;
7848 procedure Chain
(A
: Node_Id
);
7849 -- Add named actual at the proper place in the list, using the
7850 -- Next_Named_Actual link.
7852 function Reporting
return Boolean;
7853 -- Determines if an error is to be reported. To report an error, we
7854 -- need Report to be True, and also we do not report errors caused
7855 -- by calls to init procs that occur within other init procs. Such
7856 -- errors must always be cascaded errors, since if all the types are
7857 -- declared correctly, the compiler will certainly build decent calls!
7863 procedure Chain
(A
: Node_Id
) is
7867 -- Call node points to first actual in list
7869 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
7872 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
7876 Set_Next_Named_Actual
(Last
, Empty
);
7883 function Reporting
return Boolean is
7888 elsif not Within_Init_Proc
then
7891 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
7899 -- Start of processing for Normalize_Actuals
7902 if Is_Access_Type
(S
) then
7904 -- The name in the call is a function call that returns an access
7905 -- to subprogram. The designated type has the list of formals.
7907 Formal
:= First_Formal
(Designated_Type
(S
));
7909 Formal
:= First_Formal
(S
);
7912 while Present
(Formal
) loop
7913 Formals_To_Match
:= Formals_To_Match
+ 1;
7914 Next_Formal
(Formal
);
7917 -- Find if there is a named association, and verify that no positional
7918 -- associations appear after named ones.
7920 if Present
(Actuals
) then
7921 Actual
:= First
(Actuals
);
7924 while Present
(Actual
)
7925 and then Nkind
(Actual
) /= N_Parameter_Association
7927 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7931 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
7933 -- Most common case: positional notation, no defaults
7938 elsif Actuals_To_Match
> Formals_To_Match
then
7940 -- Too many actuals: will not work
7943 if Is_Entity_Name
(Name
(N
)) then
7944 Error_Msg_N
("too many arguments in call to&", Name
(N
));
7946 Error_Msg_N
("too many arguments in call", N
);
7954 First_Named
:= Actual
;
7956 while Present
(Actual
) loop
7957 if Nkind
(Actual
) /= N_Parameter_Association
then
7959 ("positional parameters not allowed after named ones", Actual
);
7964 Actuals_To_Match
:= Actuals_To_Match
+ 1;
7970 if Present
(Actuals
) then
7971 Actual
:= First
(Actuals
);
7974 Formal
:= First_Formal
(S
);
7975 while Present
(Formal
) loop
7977 -- Match the formals in order. If the corresponding actual is
7978 -- positional, nothing to do. Else scan the list of named actuals
7979 -- to find the one with the right name.
7982 and then Nkind
(Actual
) /= N_Parameter_Association
7985 Actuals_To_Match
:= Actuals_To_Match
- 1;
7986 Formals_To_Match
:= Formals_To_Match
- 1;
7989 -- For named parameters, search the list of actuals to find
7990 -- one that matches the next formal name.
7992 Actual
:= First_Named
;
7994 while Present
(Actual
) loop
7995 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
7998 Actuals_To_Match
:= Actuals_To_Match
- 1;
7999 Formals_To_Match
:= Formals_To_Match
- 1;
8007 if Ekind
(Formal
) /= E_In_Parameter
8008 or else No
(Default_Value
(Formal
))
8011 if (Comes_From_Source
(S
)
8012 or else Sloc
(S
) = Standard_Location
)
8013 and then Is_Overloadable
(S
)
8017 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
8019 (Nkind
(Parent
(N
)) = N_Function_Call
8021 Nkind
(Parent
(N
)) = N_Parameter_Association
))
8022 and then Ekind
(S
) /= E_Function
8024 Set_Etype
(N
, Etype
(S
));
8026 Error_Msg_Name_1
:= Chars
(S
);
8027 Error_Msg_Sloc
:= Sloc
(S
);
8029 ("missing argument for parameter & " &
8030 "in call to % declared #", N
, Formal
);
8033 elsif Is_Overloadable
(S
) then
8034 Error_Msg_Name_1
:= Chars
(S
);
8036 -- Point to type derivation that generated the
8039 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
8042 ("missing argument for parameter & " &
8043 "in call to % (inherited) #", N
, Formal
);
8047 ("missing argument for parameter &", N
, Formal
);
8055 Formals_To_Match
:= Formals_To_Match
- 1;
8060 Next_Formal
(Formal
);
8063 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
8070 -- Find some superfluous named actual that did not get
8071 -- attached to the list of associations.
8073 Actual
:= First
(Actuals
);
8074 while Present
(Actual
) loop
8075 if Nkind
(Actual
) = N_Parameter_Association
8076 and then Actual
/= Last
8077 and then No
(Next_Named_Actual
(Actual
))
8079 Error_Msg_N
("unmatched actual & in call",
8080 Selector_Name
(Actual
));
8091 end Normalize_Actuals
;
8093 --------------------------------
8094 -- Note_Possible_Modification --
8095 --------------------------------
8097 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
8098 Modification_Comes_From_Source
: constant Boolean :=
8099 Comes_From_Source
(Parent
(N
));
8105 -- Loop to find referenced entity, if there is one
8112 if Is_Entity_Name
(Exp
) then
8113 Ent
:= Entity
(Exp
);
8115 -- If the entity is missing, it is an undeclared identifier,
8116 -- and there is nothing to annotate.
8122 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
8124 P
: constant Node_Id
:= Prefix
(Exp
);
8127 if Nkind
(P
) = N_Selected_Component
8129 Entry_Formal
(Entity
(Selector_Name
(P
))))
8131 -- Case of a reference to an entry formal
8133 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
8135 elsif Nkind
(P
) = N_Identifier
8136 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
8137 and then Present
(Expression
(Parent
(Entity
(P
))))
8138 and then Nkind
(Expression
(Parent
(Entity
(P
))))
8141 -- Case of a reference to a value on which side effects have
8144 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
8153 elsif Nkind
(Exp
) = N_Type_Conversion
8154 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
8156 Exp
:= Expression
(Exp
);
8159 elsif Nkind
(Exp
) = N_Slice
8160 or else Nkind
(Exp
) = N_Indexed_Component
8161 or else Nkind
(Exp
) = N_Selected_Component
8163 Exp
:= Prefix
(Exp
);
8170 -- Now look for entity being referenced
8172 if Present
(Ent
) then
8173 if Is_Object
(Ent
) then
8174 if Comes_From_Source
(Exp
)
8175 or else Modification_Comes_From_Source
8177 if Has_Pragma_Unmodified
(Ent
) then
8178 Error_Msg_NE
("?pragma Unmodified given for &!", N
, Ent
);
8181 Set_Never_Set_In_Source
(Ent
, False);
8184 Set_Is_True_Constant
(Ent
, False);
8185 Set_Current_Value
(Ent
, Empty
);
8186 Set_Is_Known_Null
(Ent
, False);
8188 if not Can_Never_Be_Null
(Ent
) then
8189 Set_Is_Known_Non_Null
(Ent
, False);
8192 -- Follow renaming chain
8194 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
8195 and then Present
(Renamed_Object
(Ent
))
8197 Exp
:= Renamed_Object
(Ent
);
8201 -- Generate a reference only if the assignment comes from
8202 -- source. This excludes, for example, calls to a dispatching
8203 -- assignment operation when the left-hand side is tagged.
8205 if Modification_Comes_From_Source
then
8206 Generate_Reference
(Ent
, Exp
, 'm');
8209 Check_Nested_Access
(Ent
);
8214 -- If we are sure this is a modification from source, and we know
8215 -- this modifies a constant, then give an appropriate warning.
8217 if Overlays_Constant
(Ent
)
8218 and then Modification_Comes_From_Source
8222 A
: constant Node_Id
:= Address_Clause
(Ent
);
8226 Exp
: constant Node_Id
:= Expression
(A
);
8228 if Nkind
(Exp
) = N_Attribute_Reference
8229 and then Attribute_Name
(Exp
) = Name_Address
8230 and then Is_Entity_Name
(Prefix
(Exp
))
8232 Error_Msg_Sloc
:= Sloc
(A
);
8234 ("constant& may be modified via address clause#?",
8235 N
, Entity
(Prefix
(Exp
)));
8245 end Note_Possible_Modification
;
8247 -------------------------
8248 -- Object_Access_Level --
8249 -------------------------
8251 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
8254 -- Returns the static accessibility level of the view denoted by Obj. Note
8255 -- that the value returned is the result of a call to Scope_Depth. Only
8256 -- scope depths associated with dynamic scopes can actually be returned.
8257 -- Since only relative levels matter for accessibility checking, the fact
8258 -- that the distance between successive levels of accessibility is not
8259 -- always one is immaterial (invariant: if level(E2) is deeper than
8260 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
8262 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
8263 -- An explicit dereference is created when removing side-effects from
8264 -- expressions for constraint checking purposes. In this case a local
8265 -- access type is created for it. The correct access level is that of
8266 -- the original source node. We detect this case by noting that the
8267 -- prefix of the dereference is created by an object declaration whose
8268 -- initial expression is a reference.
8274 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
8275 Pref
: constant Node_Id
:= Prefix
(Obj
);
8277 if Is_Entity_Name
(Pref
)
8278 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
8279 and then Present
(Expression
(Parent
(Entity
(Pref
))))
8280 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
8282 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
8288 -- Start of processing for Object_Access_Level
8291 if Is_Entity_Name
(Obj
) then
8294 if Is_Prival
(E
) then
8295 E
:= Prival_Link
(E
);
8298 -- If E is a type then it denotes a current instance. For this case
8299 -- we add one to the normal accessibility level of the type to ensure
8300 -- that current instances are treated as always being deeper than
8301 -- than the level of any visible named access type (see 3.10.2(21)).
8304 return Type_Access_Level
(E
) + 1;
8306 elsif Present
(Renamed_Object
(E
)) then
8307 return Object_Access_Level
(Renamed_Object
(E
));
8309 -- Similarly, if E is a component of the current instance of a
8310 -- protected type, any instance of it is assumed to be at a deeper
8311 -- level than the type. For a protected object (whose type is an
8312 -- anonymous protected type) its components are at the same level
8313 -- as the type itself.
8315 elsif not Is_Overloadable
(E
)
8316 and then Ekind
(Scope
(E
)) = E_Protected_Type
8317 and then Comes_From_Source
(Scope
(E
))
8319 return Type_Access_Level
(Scope
(E
)) + 1;
8322 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
8325 elsif Nkind
(Obj
) = N_Selected_Component
then
8326 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
8327 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8329 return Object_Access_Level
(Prefix
(Obj
));
8332 elsif Nkind
(Obj
) = N_Indexed_Component
then
8333 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
8334 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8336 return Object_Access_Level
(Prefix
(Obj
));
8339 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
8341 -- If the prefix is a selected access discriminant then we make a
8342 -- recursive call on the prefix, which will in turn check the level
8343 -- of the prefix object of the selected discriminant.
8345 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
8346 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
8348 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
8350 return Object_Access_Level
(Prefix
(Obj
));
8352 elsif not (Comes_From_Source
(Obj
)) then
8354 Ref
: constant Node_Id
:= Reference_To
(Obj
);
8356 if Present
(Ref
) then
8357 return Object_Access_Level
(Ref
);
8359 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8364 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
8367 elsif Nkind
(Obj
) = N_Type_Conversion
8368 or else Nkind
(Obj
) = N_Unchecked_Type_Conversion
8370 return Object_Access_Level
(Expression
(Obj
));
8372 -- Function results are objects, so we get either the access level of
8373 -- the function or, in the case of an indirect call, the level of of the
8374 -- access-to-subprogram type.
8376 elsif Nkind
(Obj
) = N_Function_Call
then
8377 if Is_Entity_Name
(Name
(Obj
)) then
8378 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
8380 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
8383 -- For convenience we handle qualified expressions, even though
8384 -- they aren't technically object names.
8386 elsif Nkind
(Obj
) = N_Qualified_Expression
then
8387 return Object_Access_Level
(Expression
(Obj
));
8389 -- Otherwise return the scope level of Standard.
8390 -- (If there are cases that fall through
8391 -- to this point they will be treated as
8392 -- having global accessibility for now. ???)
8395 return Scope_Depth
(Standard_Standard
);
8397 end Object_Access_Level
;
8399 -----------------------
8400 -- Private_Component --
8401 -----------------------
8403 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
8404 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
8406 function Trace_Components
8408 Check
: Boolean) return Entity_Id
;
8409 -- Recursive function that does the work, and checks against circular
8410 -- definition for each subcomponent type.
8412 ----------------------
8413 -- Trace_Components --
8414 ----------------------
8416 function Trace_Components
8418 Check
: Boolean) return Entity_Id
8420 Btype
: constant Entity_Id
:= Base_Type
(T
);
8421 Component
: Entity_Id
;
8423 Candidate
: Entity_Id
:= Empty
;
8426 if Check
and then Btype
= Ancestor
then
8427 Error_Msg_N
("circular type definition", Type_Id
);
8431 if Is_Private_Type
(Btype
)
8432 and then not Is_Generic_Type
(Btype
)
8434 if Present
(Full_View
(Btype
))
8435 and then Is_Record_Type
(Full_View
(Btype
))
8436 and then not Is_Frozen
(Btype
)
8438 -- To indicate that the ancestor depends on a private type, the
8439 -- current Btype is sufficient. However, to check for circular
8440 -- definition we must recurse on the full view.
8442 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
8444 if Candidate
= Any_Type
then
8454 elsif Is_Array_Type
(Btype
) then
8455 return Trace_Components
(Component_Type
(Btype
), True);
8457 elsif Is_Record_Type
(Btype
) then
8458 Component
:= First_Entity
(Btype
);
8459 while Present
(Component
) loop
8461 -- Skip anonymous types generated by constrained components
8463 if not Is_Type
(Component
) then
8464 P
:= Trace_Components
(Etype
(Component
), True);
8467 if P
= Any_Type
then
8475 Next_Entity
(Component
);
8483 end Trace_Components
;
8485 -- Start of processing for Private_Component
8488 return Trace_Components
(Type_Id
, False);
8489 end Private_Component
;
8491 -----------------------
8492 -- Process_End_Label --
8493 -----------------------
8495 procedure Process_End_Label
8504 Label_Ref
: Boolean;
8505 -- Set True if reference to end label itself is required
8508 -- Gets set to the operator symbol or identifier that references the
8509 -- entity Ent. For the child unit case, this is the identifier from the
8510 -- designator. For other cases, this is simply Endl.
8512 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
8513 -- N is an identifier node that appears as a parent unit reference in
8514 -- the case where Ent is a child unit. This procedure generates an
8515 -- appropriate cross-reference entry. E is the corresponding entity.
8517 -------------------------
8518 -- Generate_Parent_Ref --
8519 -------------------------
8521 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
8523 -- If names do not match, something weird, skip reference
8525 if Chars
(E
) = Chars
(N
) then
8527 -- Generate the reference. We do NOT consider this as a reference
8528 -- for unreferenced symbol purposes.
8530 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
8533 Style
.Check_Identifier
(N
, E
);
8536 end Generate_Parent_Ref
;
8538 -- Start of processing for Process_End_Label
8541 -- If no node, ignore. This happens in some error situations, and
8542 -- also for some internally generated structures where no end label
8543 -- references are required in any case.
8549 -- Nothing to do if no End_Label, happens for internally generated
8550 -- constructs where we don't want an end label reference anyway. Also
8551 -- nothing to do if Endl is a string literal, which means there was
8552 -- some prior error (bad operator symbol)
8554 Endl
:= End_Label
(N
);
8556 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
8560 -- Reference node is not in extended main source unit
8562 if not In_Extended_Main_Source_Unit
(N
) then
8564 -- Generally we do not collect references except for the extended
8565 -- main source unit. The one exception is the 'e' entry for a
8566 -- package spec, where it is useful for a client to have the
8567 -- ending information to define scopes.
8575 -- For this case, we can ignore any parent references, but we
8576 -- need the package name itself for the 'e' entry.
8578 if Nkind
(Endl
) = N_Designator
then
8579 Endl
:= Identifier
(Endl
);
8583 -- Reference is in extended main source unit
8588 -- For designator, generate references for the parent entries
8590 if Nkind
(Endl
) = N_Designator
then
8592 -- Generate references for the prefix if the END line comes from
8593 -- source (otherwise we do not need these references) We climb the
8594 -- scope stack to find the expected entities.
8596 if Comes_From_Source
(Endl
) then
8598 Scop
:= Current_Scope
;
8599 while Nkind
(Nam
) = N_Selected_Component
loop
8600 Scop
:= Scope
(Scop
);
8601 exit when No
(Scop
);
8602 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
8603 Nam
:= Prefix
(Nam
);
8606 if Present
(Scop
) then
8607 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
8611 Endl
:= Identifier
(Endl
);
8615 -- If the end label is not for the given entity, then either we have
8616 -- some previous error, or this is a generic instantiation for which
8617 -- we do not need to make a cross-reference in this case anyway. In
8618 -- either case we simply ignore the call.
8620 if Chars
(Ent
) /= Chars
(Endl
) then
8624 -- If label was really there, then generate a normal reference and then
8625 -- adjust the location in the end label to point past the name (which
8626 -- should almost always be the semicolon).
8630 if Comes_From_Source
(Endl
) then
8632 -- If a label reference is required, then do the style check and
8633 -- generate an l-type cross-reference entry for the label
8637 Style
.Check_Identifier
(Endl
, Ent
);
8640 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
8643 -- Set the location to point past the label (normally this will
8644 -- mean the semicolon immediately following the label). This is
8645 -- done for the sake of the 'e' or 't' entry generated below.
8647 Get_Decoded_Name_String
(Chars
(Endl
));
8648 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
8651 -- Now generate the e/t reference
8653 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
8655 -- Restore Sloc, in case modified above, since we have an identifier
8656 -- and the normal Sloc should be left set in the tree.
8658 Set_Sloc
(Endl
, Loc
);
8659 end Process_End_Label
;
8665 -- We do the conversion to get the value of the real string by using
8666 -- the scanner, see Sinput for details on use of the internal source
8667 -- buffer for scanning internal strings.
8669 function Real_Convert
(S
: String) return Node_Id
is
8670 Save_Src
: constant Source_Buffer_Ptr
:= Source
;
8674 Source
:= Internal_Source_Ptr
;
8677 for J
in S
'Range loop
8678 Source
(Source_Ptr
(J
)) := S
(J
);
8681 Source
(S
'Length + 1) := EOF
;
8683 if Source
(Scan_Ptr
) = '-' then
8685 Scan_Ptr
:= Scan_Ptr
+ 1;
8693 Set_Realval
(Token_Node
, UR_Negate
(Realval
(Token_Node
)));
8700 ---------------------
8701 -- Rep_To_Pos_Flag --
8702 ---------------------
8704 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
8706 return New_Occurrence_Of
8707 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
8708 end Rep_To_Pos_Flag
;
8710 --------------------
8711 -- Require_Entity --
8712 --------------------
8714 procedure Require_Entity
(N
: Node_Id
) is
8716 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
8717 if Total_Errors_Detected
/= 0 then
8718 Set_Entity
(N
, Any_Id
);
8720 raise Program_Error
;
8725 ------------------------------
8726 -- Requires_Transient_Scope --
8727 ------------------------------
8729 -- A transient scope is required when variable-sized temporaries are
8730 -- allocated in the primary or secondary stack, or when finalization
8731 -- actions must be generated before the next instruction.
8733 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
8734 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
8736 -- Start of processing for Requires_Transient_Scope
8739 -- This is a private type which is not completed yet. This can only
8740 -- happen in a default expression (of a formal parameter or of a
8741 -- record component). Do not expand transient scope in this case
8746 -- Do not expand transient scope for non-existent procedure return
8748 elsif Typ
= Standard_Void_Type
then
8751 -- Elementary types do not require a transient scope
8753 elsif Is_Elementary_Type
(Typ
) then
8756 -- Generally, indefinite subtypes require a transient scope, since the
8757 -- back end cannot generate temporaries, since this is not a valid type
8758 -- for declaring an object. It might be possible to relax this in the
8759 -- future, e.g. by declaring the maximum possible space for the type.
8761 elsif Is_Indefinite_Subtype
(Typ
) then
8764 -- Functions returning tagged types may dispatch on result so their
8765 -- returned value is allocated on the secondary stack. Controlled
8766 -- type temporaries need finalization.
8768 elsif Is_Tagged_Type
(Typ
)
8769 or else Has_Controlled_Component
(Typ
)
8771 return not Is_Value_Type
(Typ
);
8775 elsif Is_Record_Type
(Typ
) then
8779 Comp
:= First_Entity
(Typ
);
8780 while Present
(Comp
) loop
8781 if Ekind
(Comp
) = E_Component
8782 and then Requires_Transient_Scope
(Etype
(Comp
))
8793 -- String literal types never require transient scope
8795 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
8798 -- Array type. Note that we already know that this is a constrained
8799 -- array, since unconstrained arrays will fail the indefinite test.
8801 elsif Is_Array_Type
(Typ
) then
8803 -- If component type requires a transient scope, the array does too
8805 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
8808 -- Otherwise, we only need a transient scope if the size is not
8809 -- known at compile time.
8812 return not Size_Known_At_Compile_Time
(Typ
);
8815 -- All other cases do not require a transient scope
8820 end Requires_Transient_Scope
;
8822 --------------------------
8823 -- Reset_Analyzed_Flags --
8824 --------------------------
8826 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
8828 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
8829 -- Function used to reset Analyzed flags in tree. Note that we do
8830 -- not reset Analyzed flags in entities, since there is no need to
8831 -- reanalyze entities, and indeed, it is wrong to do so, since it
8832 -- can result in generating auxiliary stuff more than once.
8834 --------------------
8835 -- Clear_Analyzed --
8836 --------------------
8838 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
8840 if not Has_Extension
(N
) then
8841 Set_Analyzed
(N
, False);
8847 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
8849 -- Start of processing for Reset_Analyzed_Flags
8853 end Reset_Analyzed_Flags
;
8855 ---------------------------
8856 -- Safe_To_Capture_Value --
8857 ---------------------------
8859 function Safe_To_Capture_Value
8862 Cond
: Boolean := False) return Boolean
8865 -- The only entities for which we track constant values are variables
8866 -- which are not renamings, constants, out parameters, and in out
8867 -- parameters, so check if we have this case.
8869 -- Note: it may seem odd to track constant values for constants, but in
8870 -- fact this routine is used for other purposes than simply capturing
8871 -- the value. In particular, the setting of Known[_Non]_Null.
8873 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
8875 Ekind
(Ent
) = E_Constant
8877 Ekind
(Ent
) = E_Out_Parameter
8879 Ekind
(Ent
) = E_In_Out_Parameter
8883 -- For conditionals, we also allow loop parameters and all formals,
8884 -- including in parameters.
8888 (Ekind
(Ent
) = E_Loop_Parameter
8890 Ekind
(Ent
) = E_In_Parameter
)
8894 -- For all other cases, not just unsafe, but impossible to capture
8895 -- Current_Value, since the above are the only entities which have
8896 -- Current_Value fields.
8902 -- Skip if volatile or aliased, since funny things might be going on in
8903 -- these cases which we cannot necessarily track. Also skip any variable
8904 -- for which an address clause is given, or whose address is taken. Also
8905 -- never capture value of library level variables (an attempt to do so
8906 -- can occur in the case of package elaboration code).
8908 if Treat_As_Volatile
(Ent
)
8909 or else Is_Aliased
(Ent
)
8910 or else Present
(Address_Clause
(Ent
))
8911 or else Address_Taken
(Ent
)
8912 or else (Is_Library_Level_Entity
(Ent
)
8913 and then Ekind
(Ent
) = E_Variable
)
8918 -- OK, all above conditions are met. We also require that the scope of
8919 -- the reference be the same as the scope of the entity, not counting
8920 -- packages and blocks and loops.
8923 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
8924 R_Scope
: Entity_Id
;
8927 R_Scope
:= Current_Scope
;
8928 while R_Scope
/= Standard_Standard
loop
8929 exit when R_Scope
= E_Scope
;
8931 if Ekind
(R_Scope
) /= E_Package
8933 Ekind
(R_Scope
) /= E_Block
8935 Ekind
(R_Scope
) /= E_Loop
8939 R_Scope
:= Scope
(R_Scope
);
8944 -- We also require that the reference does not appear in a context
8945 -- where it is not sure to be executed (i.e. a conditional context
8946 -- or an exception handler). We skip this if Cond is True, since the
8947 -- capturing of values from conditional tests handles this ok.
8961 while Present
(P
) loop
8962 if Nkind
(P
) = N_If_Statement
8963 or else Nkind
(P
) = N_Case_Statement
8964 or else (Nkind
(P
) = N_And_Then
and then Desc
= Right_Opnd
(P
))
8965 or else (Nkind
(P
) = N_Or_Else
and then Desc
= Right_Opnd
(P
))
8966 or else Nkind
(P
) = N_Exception_Handler
8967 or else Nkind
(P
) = N_Selective_Accept
8968 or else Nkind
(P
) = N_Conditional_Entry_Call
8969 or else Nkind
(P
) = N_Timed_Entry_Call
8970 or else Nkind
(P
) = N_Asynchronous_Select
8980 -- OK, looks safe to set value
8983 end Safe_To_Capture_Value
;
8989 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
8990 K1
: constant Node_Kind
:= Nkind
(N1
);
8991 K2
: constant Node_Kind
:= Nkind
(N2
);
8994 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
8995 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
8997 return Chars
(N1
) = Chars
(N2
);
8999 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
9000 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
9002 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
9003 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
9014 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
9015 N1
: constant Node_Id
:= Original_Node
(Node1
);
9016 N2
: constant Node_Id
:= Original_Node
(Node2
);
9017 -- We do the tests on original nodes, since we are most interested
9018 -- in the original source, not any expansion that got in the way.
9020 K1
: constant Node_Kind
:= Nkind
(N1
);
9021 K2
: constant Node_Kind
:= Nkind
(N2
);
9024 -- First case, both are entities with same entity
9026 if K1
in N_Has_Entity
9027 and then K2
in N_Has_Entity
9028 and then Present
(Entity
(N1
))
9029 and then Present
(Entity
(N2
))
9030 and then (Ekind
(Entity
(N1
)) = E_Variable
9032 Ekind
(Entity
(N1
)) = E_Constant
)
9033 and then Entity
(N1
) = Entity
(N2
)
9037 -- Second case, selected component with same selector, same record
9039 elsif K1
= N_Selected_Component
9040 and then K2
= N_Selected_Component
9041 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
9043 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
9045 -- Third case, indexed component with same subscripts, same array
9047 elsif K1
= N_Indexed_Component
9048 and then K2
= N_Indexed_Component
9049 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
9054 E1
:= First
(Expressions
(N1
));
9055 E2
:= First
(Expressions
(N2
));
9056 while Present
(E1
) loop
9057 if not Same_Value
(E1
, E2
) then
9068 -- Fourth case, slice of same array with same bounds
9071 and then K2
= N_Slice
9072 and then Nkind
(Discrete_Range
(N1
)) = N_Range
9073 and then Nkind
(Discrete_Range
(N2
)) = N_Range
9074 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
9075 Low_Bound
(Discrete_Range
(N2
)))
9076 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
9077 High_Bound
(Discrete_Range
(N2
)))
9079 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
9081 -- All other cases, not clearly the same object
9092 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
9097 elsif not Is_Constrained
(T1
)
9098 and then not Is_Constrained
(T2
)
9099 and then Base_Type
(T1
) = Base_Type
(T2
)
9103 -- For now don't bother with case of identical constraints, to be
9104 -- fiddled with later on perhaps (this is only used for optimization
9105 -- purposes, so it is not critical to do a best possible job)
9116 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
9118 if Compile_Time_Known_Value
(Node1
)
9119 and then Compile_Time_Known_Value
(Node2
)
9120 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
9123 elsif Same_Object
(Node1
, Node2
) then
9130 ------------------------
9131 -- Scope_Is_Transient --
9132 ------------------------
9134 function Scope_Is_Transient
return Boolean is
9136 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
9137 end Scope_Is_Transient
;
9143 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
9148 while Scop
/= Standard_Standard
loop
9149 Scop
:= Scope
(Scop
);
9151 if Scop
= Scope2
then
9159 --------------------------
9160 -- Scope_Within_Or_Same --
9161 --------------------------
9163 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
9168 while Scop
/= Standard_Standard
loop
9169 if Scop
= Scope2
then
9172 Scop
:= Scope
(Scop
);
9177 end Scope_Within_Or_Same
;
9179 --------------------
9180 -- Set_Convention --
9181 --------------------
9183 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
9185 Basic_Set_Convention
(E
, Val
);
9188 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
9189 and then Has_Foreign_Convention
(E
)
9191 Set_Can_Use_Internal_Rep
(E
, False);
9195 ------------------------
9196 -- Set_Current_Entity --
9197 ------------------------
9199 -- The given entity is to be set as the currently visible definition
9200 -- of its associated name (i.e. the Node_Id associated with its name).
9201 -- All we have to do is to get the name from the identifier, and
9202 -- then set the associated Node_Id to point to the given entity.
9204 procedure Set_Current_Entity
(E
: Entity_Id
) is
9206 Set_Name_Entity_Id
(Chars
(E
), E
);
9207 end Set_Current_Entity
;
9209 ---------------------------
9210 -- Set_Debug_Info_Needed --
9211 ---------------------------
9213 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
9215 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
9216 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
9217 -- Used to set debug info in a related node if not set already
9219 --------------------------------------
9220 -- Set_Debug_Info_Needed_If_Not_Set --
9221 --------------------------------------
9223 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
9226 and then not Needs_Debug_Info
(E
)
9228 Set_Debug_Info_Needed
(E
);
9230 end Set_Debug_Info_Needed_If_Not_Set
;
9232 -- Start of processing for Set_Debug_Info_Needed
9235 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
9236 -- indicates that Debug_Info_Needed is never required for the entity.
9239 or else Debug_Info_Off
(T
)
9244 -- Set flag in entity itself. Note that we will go through the following
9245 -- circuitry even if the flag is already set on T. That's intentional,
9246 -- it makes sure that the flag will be set in subsidiary entities.
9248 Set_Needs_Debug_Info
(T
);
9250 -- Set flag on subsidiary entities if not set already
9252 if Is_Object
(T
) then
9253 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
9255 elsif Is_Type
(T
) then
9256 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
9258 if Is_Record_Type
(T
) then
9260 Ent
: Entity_Id
:= First_Entity
(T
);
9262 while Present
(Ent
) loop
9263 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
9268 elsif Is_Array_Type
(T
) then
9269 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
9272 Indx
: Node_Id
:= First_Index
(T
);
9274 while Present
(Indx
) loop
9275 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
9276 Indx
:= Next_Index
(Indx
);
9280 if Is_Packed
(T
) then
9281 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
9284 elsif Is_Access_Type
(T
) then
9285 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
9287 elsif Is_Private_Type
(T
) then
9288 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
9290 elsif Is_Protected_Type
(T
) then
9291 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
9294 end Set_Debug_Info_Needed
;
9296 ---------------------------------
9297 -- Set_Entity_With_Style_Check --
9298 ---------------------------------
9300 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
9301 Val_Actual
: Entity_Id
;
9305 Set_Entity
(N
, Val
);
9308 and then not Suppress_Style_Checks
(Val
)
9309 and then not In_Instance
9311 if Nkind
(N
) = N_Identifier
then
9313 elsif Nkind
(N
) = N_Expanded_Name
then
9314 Nod
:= Selector_Name
(N
);
9319 -- A special situation arises for derived operations, where we want
9320 -- to do the check against the parent (since the Sloc of the derived
9321 -- operation points to the derived type declaration itself).
9324 while not Comes_From_Source
(Val_Actual
)
9325 and then Nkind
(Val_Actual
) in N_Entity
9326 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
9327 or else Is_Subprogram
(Val_Actual
)
9328 or else Is_Generic_Subprogram
(Val_Actual
))
9329 and then Present
(Alias
(Val_Actual
))
9331 Val_Actual
:= Alias
(Val_Actual
);
9334 -- Renaming declarations for generic actuals do not come from source,
9335 -- and have a different name from that of the entity they rename, so
9336 -- there is no style check to perform here.
9338 if Chars
(Nod
) = Chars
(Val_Actual
) then
9339 Style
.Check_Identifier
(Nod
, Val_Actual
);
9343 Set_Entity
(N
, Val
);
9344 end Set_Entity_With_Style_Check
;
9346 ------------------------
9347 -- Set_Name_Entity_Id --
9348 ------------------------
9350 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
9352 Set_Name_Table_Info
(Id
, Int
(Val
));
9353 end Set_Name_Entity_Id
;
9355 ---------------------
9356 -- Set_Next_Actual --
9357 ---------------------
9359 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
9361 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
9362 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
9364 end Set_Next_Actual
;
9366 ----------------------------------
9367 -- Set_Optimize_Alignment_Flags --
9368 ----------------------------------
9370 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
9372 if Optimize_Alignment
= 'S' then
9373 Set_Optimize_Alignment_Space
(E
);
9374 elsif Optimize_Alignment
= 'T' then
9375 Set_Optimize_Alignment_Time
(E
);
9377 end Set_Optimize_Alignment_Flags
;
9379 -----------------------
9380 -- Set_Public_Status --
9381 -----------------------
9383 procedure Set_Public_Status
(Id
: Entity_Id
) is
9384 S
: constant Entity_Id
:= Current_Scope
;
9386 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
9387 -- Determines if E is defined within handled statement sequence or
9388 -- an if statement, returns True if so, False otherwise.
9390 ----------------------
9391 -- Within_HSS_Or_If --
9392 ----------------------
9394 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
9397 N
:= Declaration_Node
(E
);
9404 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
9410 end Within_HSS_Or_If
;
9412 -- Start of processing for Set_Public_Status
9415 -- Everything in the scope of Standard is public
9417 if S
= Standard_Standard
then
9420 -- Entity is definitely not public if enclosing scope is not public
9422 elsif not Is_Public
(S
) then
9425 -- An object or function declaration that occurs in a handled sequence
9426 -- of statements or within an if statement is the declaration for a
9427 -- temporary object or local subprogram generated by the expander. It
9428 -- never needs to be made public and furthermore, making it public can
9429 -- cause back end problems.
9431 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
9432 N_Function_Specification
)
9433 and then Within_HSS_Or_If
(Id
)
9437 -- Entities in public packages or records are public
9439 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
9442 -- The bounds of an entry family declaration can generate object
9443 -- declarations that are visible to the back-end, e.g. in the
9444 -- the declaration of a composite type that contains tasks.
9446 elsif Is_Concurrent_Type
(S
)
9447 and then not Has_Completion
(S
)
9448 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
9452 end Set_Public_Status
;
9454 -----------------------------
9455 -- Set_Referenced_Modified --
9456 -----------------------------
9458 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
9462 -- Deal with indexed or selected component where prefix is modified
9464 if Nkind
(N
) = N_Indexed_Component
9466 Nkind
(N
) = N_Selected_Component
9470 -- If prefix is access type, then it is the designated object that is
9471 -- being modified, which means we have no entity to set the flag on.
9473 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
9476 -- Otherwise chase the prefix
9479 Set_Referenced_Modified
(Pref
, Out_Param
);
9482 -- Otherwise see if we have an entity name (only other case to process)
9484 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
9485 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
9486 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
9488 end Set_Referenced_Modified
;
9490 ----------------------------
9491 -- Set_Scope_Is_Transient --
9492 ----------------------------
9494 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
9496 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
9497 end Set_Scope_Is_Transient
;
9503 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
9505 -- We copy Esize, but not RM_Size, since in general RM_Size is
9506 -- subtype specific and does not get inherited by all subtypes.
9508 Set_Esize
(T1
, Esize
(T2
));
9509 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
9511 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
9513 Is_Discrete_Or_Fixed_Point_Type
(T2
)
9515 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
9518 Set_Alignment
(T1
, Alignment
(T2
));
9521 --------------------
9522 -- Static_Integer --
9523 --------------------
9525 function Static_Integer
(N
: Node_Id
) return Uint
is
9527 Analyze_And_Resolve
(N
, Any_Integer
);
9530 or else Error_Posted
(N
)
9531 or else Etype
(N
) = Any_Type
9536 if Is_Static_Expression
(N
) then
9537 if not Raises_Constraint_Error
(N
) then
9538 return Expr_Value
(N
);
9543 elsif Etype
(N
) = Any_Type
then
9547 Flag_Non_Static_Expr
9548 ("static integer expression required here", N
);
9553 --------------------------
9554 -- Statically_Different --
9555 --------------------------
9557 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
9558 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
9559 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
9561 return Is_Entity_Name
(R1
)
9562 and then Is_Entity_Name
(R2
)
9563 and then Entity
(R1
) /= Entity
(R2
)
9564 and then not Is_Formal
(Entity
(R1
))
9565 and then not Is_Formal
(Entity
(R2
));
9566 end Statically_Different
;
9568 -----------------------------
9569 -- Subprogram_Access_Level --
9570 -----------------------------
9572 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
9574 if Present
(Alias
(Subp
)) then
9575 return Subprogram_Access_Level
(Alias
(Subp
));
9577 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
9579 end Subprogram_Access_Level
;
9585 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
9587 if Debug_Flag_W
then
9588 for J
in 0 .. Scope_Stack
.Last
loop
9593 Write_Name
(Chars
(E
));
9594 Write_Str
(" from ");
9595 Write_Location
(Sloc
(N
));
9600 -----------------------
9601 -- Transfer_Entities --
9602 -----------------------
9604 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
9605 Ent
: Entity_Id
:= First_Entity
(From
);
9612 if (Last_Entity
(To
)) = Empty
then
9613 Set_First_Entity
(To
, Ent
);
9615 Set_Next_Entity
(Last_Entity
(To
), Ent
);
9618 Set_Last_Entity
(To
, Last_Entity
(From
));
9620 while Present
(Ent
) loop
9621 Set_Scope
(Ent
, To
);
9623 if not Is_Public
(Ent
) then
9624 Set_Public_Status
(Ent
);
9627 and then Ekind
(Ent
) = E_Record_Subtype
9630 -- The components of the propagated Itype must be public
9636 Comp
:= First_Entity
(Ent
);
9637 while Present
(Comp
) loop
9638 Set_Is_Public
(Comp
);
9648 Set_First_Entity
(From
, Empty
);
9649 Set_Last_Entity
(From
, Empty
);
9650 end Transfer_Entities
;
9652 -----------------------
9653 -- Type_Access_Level --
9654 -----------------------
9656 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
9660 Btyp
:= Base_Type
(Typ
);
9662 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
9663 -- simply use the level where the type is declared. This is true for
9664 -- stand-alone object declarations, and for anonymous access types
9665 -- associated with components the level is the same as that of the
9666 -- enclosing composite type. However, special treatment is needed for
9667 -- the cases of access parameters, return objects of an anonymous access
9668 -- type, and, in Ada 95, access discriminants of limited types.
9670 if Ekind
(Btyp
) in Access_Kind
then
9671 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
9673 -- If the type is a nonlocal anonymous access type (such as for
9674 -- an access parameter) we treat it as being declared at the
9675 -- library level to ensure that names such as X.all'access don't
9676 -- fail static accessibility checks.
9678 if not Is_Local_Anonymous_Access
(Typ
) then
9679 return Scope_Depth
(Standard_Standard
);
9681 -- If this is a return object, the accessibility level is that of
9682 -- the result subtype of the enclosing function. The test here is
9683 -- little complicated, because we have to account for extended
9684 -- return statements that have been rewritten as blocks, in which
9685 -- case we have to find and the Is_Return_Object attribute of the
9686 -- itype's associated object. It would be nice to find a way to
9687 -- simplify this test, but it doesn't seem worthwhile to add a new
9688 -- flag just for purposes of this test. ???
9690 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
9693 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
9694 N_Object_Declaration
9695 and then Is_Return_Object
9696 (Defining_Identifier
9697 (Associated_Node_For_Itype
(Btyp
))))
9703 Scop
:= Scope
(Scope
(Btyp
));
9704 while Present
(Scop
) loop
9705 exit when Ekind
(Scop
) = E_Function
;
9706 Scop
:= Scope
(Scop
);
9709 -- Treat the return object's type as having the level of the
9710 -- function's result subtype (as per RM05-6.5(5.3/2)).
9712 return Type_Access_Level
(Etype
(Scop
));
9717 Btyp
:= Root_Type
(Btyp
);
9719 -- The accessibility level of anonymous access types associated with
9720 -- discriminants is that of the current instance of the type, and
9721 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
9723 -- AI-402: access discriminants have accessibility based on the
9724 -- object rather than the type in Ada 2005, so the above paragraph
9727 -- ??? Needs completion with rules from AI-416
9729 if Ada_Version
<= Ada_95
9730 and then Ekind
(Typ
) = E_Anonymous_Access_Type
9731 and then Present
(Associated_Node_For_Itype
(Typ
))
9732 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
9733 N_Discriminant_Specification
9735 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
9739 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
9740 end Type_Access_Level
;
9742 --------------------------
9743 -- Unit_Declaration_Node --
9744 --------------------------
9746 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
9747 N
: Node_Id
:= Parent
(Unit_Id
);
9750 -- Predefined operators do not have a full function declaration
9752 if Ekind
(Unit_Id
) = E_Operator
then
9756 -- Isn't there some better way to express the following ???
9758 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
9759 and then Nkind
(N
) /= N_Formal_Package_Declaration
9760 and then Nkind
(N
) /= N_Function_Instantiation
9761 and then Nkind
(N
) /= N_Generic_Package_Declaration
9762 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
9763 and then Nkind
(N
) /= N_Package_Declaration
9764 and then Nkind
(N
) /= N_Package_Body
9765 and then Nkind
(N
) /= N_Package_Instantiation
9766 and then Nkind
(N
) /= N_Package_Renaming_Declaration
9767 and then Nkind
(N
) /= N_Procedure_Instantiation
9768 and then Nkind
(N
) /= N_Protected_Body
9769 and then Nkind
(N
) /= N_Subprogram_Declaration
9770 and then Nkind
(N
) /= N_Subprogram_Body
9771 and then Nkind
(N
) /= N_Subprogram_Body_Stub
9772 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
9773 and then Nkind
(N
) /= N_Task_Body
9774 and then Nkind
(N
) /= N_Task_Type_Declaration
9775 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
9776 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
9779 pragma Assert
(Present
(N
));
9783 end Unit_Declaration_Node
;
9785 ------------------------------
9786 -- Universal_Interpretation --
9787 ------------------------------
9789 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
9790 Index
: Interp_Index
;
9794 -- The argument may be a formal parameter of an operator or subprogram
9795 -- with multiple interpretations, or else an expression for an actual.
9797 if Nkind
(Opnd
) = N_Defining_Identifier
9798 or else not Is_Overloaded
(Opnd
)
9800 if Etype
(Opnd
) = Universal_Integer
9801 or else Etype
(Opnd
) = Universal_Real
9803 return Etype
(Opnd
);
9809 Get_First_Interp
(Opnd
, Index
, It
);
9810 while Present
(It
.Typ
) loop
9811 if It
.Typ
= Universal_Integer
9812 or else It
.Typ
= Universal_Real
9817 Get_Next_Interp
(Index
, It
);
9822 end Universal_Interpretation
;
9828 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
9830 -- Recurse to handle unlikely case of multiple levels of qualification
9832 if Nkind
(Expr
) = N_Qualified_Expression
then
9833 return Unqualify
(Expression
(Expr
));
9835 -- Normal case, not a qualified expression
9842 ----------------------
9843 -- Within_Init_Proc --
9844 ----------------------
9846 function Within_Init_Proc
return Boolean is
9851 while not Is_Overloadable
(S
) loop
9852 if S
= Standard_Standard
then
9859 return Is_Init_Proc
(S
);
9860 end Within_Init_Proc
;
9866 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
9867 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
9868 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
9870 function Has_One_Matching_Field
return Boolean;
9871 -- Determines if Expec_Type is a record type with a single component or
9872 -- discriminant whose type matches the found type or is one dimensional
9873 -- array whose component type matches the found type.
9875 ----------------------------
9876 -- Has_One_Matching_Field --
9877 ----------------------------
9879 function Has_One_Matching_Field
return Boolean is
9883 if Is_Array_Type
(Expec_Type
)
9884 and then Number_Dimensions
(Expec_Type
) = 1
9886 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
9890 elsif not Is_Record_Type
(Expec_Type
) then
9894 E
:= First_Entity
(Expec_Type
);
9899 elsif (Ekind
(E
) /= E_Discriminant
9900 and then Ekind
(E
) /= E_Component
)
9901 or else (Chars
(E
) = Name_uTag
9902 or else Chars
(E
) = Name_uParent
)
9911 if not Covers
(Etype
(E
), Found_Type
) then
9914 elsif Present
(Next_Entity
(E
)) then
9921 end Has_One_Matching_Field
;
9923 -- Start of processing for Wrong_Type
9926 -- Don't output message if either type is Any_Type, or if a message
9927 -- has already been posted for this node. We need to do the latter
9928 -- check explicitly (it is ordinarily done in Errout), because we
9929 -- are using ! to force the output of the error messages.
9931 if Expec_Type
= Any_Type
9932 or else Found_Type
= Any_Type
9933 or else Error_Posted
(Expr
)
9937 -- In an instance, there is an ongoing problem with completion of
9938 -- type derived from private types. Their structure is what Gigi
9939 -- expects, but the Etype is the parent type rather than the
9940 -- derived private type itself. Do not flag error in this case. The
9941 -- private completion is an entity without a parent, like an Itype.
9942 -- Similarly, full and partial views may be incorrect in the instance.
9943 -- There is no simple way to insure that it is consistent ???
9945 elsif In_Instance
then
9946 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
9948 (Has_Private_Declaration
(Expected_Type
)
9949 or else Has_Private_Declaration
(Etype
(Expr
)))
9950 and then No
(Parent
(Expected_Type
))
9956 -- An interesting special check. If the expression is parenthesized
9957 -- and its type corresponds to the type of the sole component of the
9958 -- expected record type, or to the component type of the expected one
9959 -- dimensional array type, then assume we have a bad aggregate attempt.
9961 if Nkind
(Expr
) in N_Subexpr
9962 and then Paren_Count
(Expr
) /= 0
9963 and then Has_One_Matching_Field
9965 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
9967 -- Another special check, if we are looking for a pool-specific access
9968 -- type and we found an E_Access_Attribute_Type, then we have the case
9969 -- of an Access attribute being used in a context which needs a pool-
9970 -- specific type, which is never allowed. The one extra check we make
9971 -- is that the expected designated type covers the Found_Type.
9973 elsif Is_Access_Type
(Expec_Type
)
9974 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
9975 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
9976 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
9978 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
9980 Error_Msg_N
("result must be general access type!", Expr
);
9981 Error_Msg_NE
("add ALL to }!", Expr
, Expec_Type
);
9983 -- Another special check, if the expected type is an integer type,
9984 -- but the expression is of type System.Address, and the parent is
9985 -- an addition or subtraction operation whose left operand is the
9986 -- expression in question and whose right operand is of an integral
9987 -- type, then this is an attempt at address arithmetic, so give
9988 -- appropriate message.
9990 elsif Is_Integer_Type
(Expec_Type
)
9991 and then Is_RTE
(Found_Type
, RE_Address
)
9992 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
9994 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
9995 and then Expr
= Left_Opnd
(Parent
(Expr
))
9996 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
9999 ("address arithmetic not predefined in package System",
10002 ("\possible missing with/use of System.Storage_Elements",
10006 -- If the expected type is an anonymous access type, as for access
10007 -- parameters and discriminants, the error is on the designated types.
10009 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
10010 if Comes_From_Source
(Expec_Type
) then
10011 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
10014 ("expected an access type with designated}",
10015 Expr
, Designated_Type
(Expec_Type
));
10018 if Is_Access_Type
(Found_Type
)
10019 and then not Comes_From_Source
(Found_Type
)
10022 ("\\found an access type with designated}!",
10023 Expr
, Designated_Type
(Found_Type
));
10025 if From_With_Type
(Found_Type
) then
10026 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
10027 Error_Msg_Qual_Level
:= 99;
10028 Error_Msg_NE
("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
10029 Error_Msg_Qual_Level
:= 0;
10031 Error_Msg_NE
("found}!", Expr
, Found_Type
);
10035 -- Normal case of one type found, some other type expected
10038 -- If the names of the two types are the same, see if some number
10039 -- of levels of qualification will help. Don't try more than three
10040 -- levels, and if we get to standard, it's no use (and probably
10041 -- represents an error in the compiler) Also do not bother with
10042 -- internal scope names.
10045 Expec_Scope
: Entity_Id
;
10046 Found_Scope
: Entity_Id
;
10049 Expec_Scope
:= Expec_Type
;
10050 Found_Scope
:= Found_Type
;
10052 for Levels
in Int
range 0 .. 3 loop
10053 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
10054 Error_Msg_Qual_Level
:= Levels
;
10058 Expec_Scope
:= Scope
(Expec_Scope
);
10059 Found_Scope
:= Scope
(Found_Scope
);
10061 exit when Expec_Scope
= Standard_Standard
10062 or else Found_Scope
= Standard_Standard
10063 or else not Comes_From_Source
(Expec_Scope
)
10064 or else not Comes_From_Source
(Found_Scope
);
10068 if Is_Record_Type
(Expec_Type
)
10069 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
10071 Error_Msg_NE
("expected}!", Expr
,
10072 Corresponding_Remote_Type
(Expec_Type
));
10074 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
10077 if Is_Entity_Name
(Expr
)
10078 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
10080 Error_Msg_N
("\\found package name!", Expr
);
10082 elsif Is_Entity_Name
(Expr
)
10084 (Ekind
(Entity
(Expr
)) = E_Procedure
10086 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
10088 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
10090 ("found procedure name, possibly missing Access attribute!",
10094 ("\\found procedure name instead of function!", Expr
);
10097 elsif Nkind
(Expr
) = N_Function_Call
10098 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
10099 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
10100 and then No
(Parameter_Associations
(Expr
))
10103 ("found function name, possibly missing Access attribute!",
10106 -- Catch common error: a prefix or infix operator which is not
10107 -- directly visible because the type isn't.
10109 elsif Nkind
(Expr
) in N_Op
10110 and then Is_Overloaded
(Expr
)
10111 and then not Is_Immediately_Visible
(Expec_Type
)
10112 and then not Is_Potentially_Use_Visible
(Expec_Type
)
10113 and then not In_Use
(Expec_Type
)
10114 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
10117 ("operator of the type is not directly visible!", Expr
);
10119 elsif Ekind
(Found_Type
) = E_Void
10120 and then Present
(Parent
(Found_Type
))
10121 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
10123 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
10126 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
10129 Error_Msg_Qual_Level
:= 0;