1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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_Ch11
; use Exp_Ch11
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Util
; use Exp_Util
;
35 with Fname
; use Fname
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
.Sp
; use Namet
.Sp
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
42 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Attr
; use Sem_Attr
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Disp
; use Sem_Disp
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Type
; use Sem_Type
;
55 with Sinfo
; use Sinfo
;
56 with Sinput
; use Sinput
;
57 with Stand
; use Stand
;
59 with Stringt
; use Stringt
;
60 with Targparm
; use Targparm
;
61 with Tbuild
; use Tbuild
;
62 with Ttypes
; use Ttypes
;
63 with Uname
; use Uname
;
65 with GNAT
.HTable
; use GNAT
.HTable
;
67 package body Sem_Util
is
69 ----------------------------------------
70 -- Global_Variables for New_Copy_Tree --
71 ----------------------------------------
73 -- These global variables are used by New_Copy_Tree. See description
74 -- of the body of this subprogram for details. Global variables can be
75 -- safely used by New_Copy_Tree, since there is no case of a recursive
76 -- call from the processing inside New_Copy_Tree.
78 NCT_Hash_Threshold
: constant := 20;
79 -- If there are more than this number of pairs of entries in the
80 -- map, then Hash_Tables_Used will be set, and the hash tables will
81 -- be initialized and used for the searches.
83 NCT_Hash_Tables_Used
: Boolean := False;
84 -- Set to True if hash tables are in use
86 NCT_Table_Entries
: Nat
:= 0;
87 -- Count entries in table to see if threshold is reached
89 NCT_Hash_Table_Setup
: Boolean := False;
90 -- Set to True if hash table contains data. We set this True if we
91 -- setup the hash table with data, and leave it set permanently
92 -- from then on, this is a signal that second and subsequent users
93 -- of the hash table must clear the old entries before reuse.
95 subtype NCT_Header_Num
is Int
range 0 .. 511;
96 -- Defines range of headers in hash tables (512 headers)
98 -----------------------
99 -- Local Subprograms --
100 -----------------------
102 function Build_Component_Subtype
105 T
: Entity_Id
) return Node_Id
;
106 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
107 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
108 -- Loc is the source location, T is the original subtype.
110 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
111 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
112 -- with discriminants whose default values are static, examine only the
113 -- components in the selected variant to determine whether all of them
116 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
117 -- T is a derived tagged type. Check whether the type extension is null.
118 -- If the parent type is fully initialized, T can be treated as such.
120 ------------------------------
121 -- Abstract_Interface_List --
122 ------------------------------
124 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
128 if Is_Concurrent_Type
(Typ
) then
130 -- If we are dealing with a synchronized subtype, go to the base
131 -- type, whose declaration has the interface list.
133 -- Shouldn't this be Declaration_Node???
135 Nod
:= Parent
(Base_Type
(Typ
));
137 if Nkind
(Nod
) = N_Full_Type_Declaration
then
141 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
142 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
143 Nod
:= Type_Definition
(Parent
(Typ
));
145 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
146 if Present
(Full_View
(Typ
))
147 and then Nkind
(Parent
(Full_View
(Typ
)))
148 = N_Full_Type_Declaration
150 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
152 -- If the full-view is not available we cannot do anything else
153 -- here (the source has errors).
159 -- Support for generic formals with interfaces is still missing ???
161 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
166 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
170 elsif Ekind
(Typ
) = E_Record_Subtype
then
171 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
173 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
175 -- Recurse, because parent may still be a private extension. Also
176 -- note that the full view of the subtype or the full view of its
177 -- base type may (both) be unavailable.
179 return Abstract_Interface_List
(Etype
(Typ
));
181 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
182 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
183 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
185 Nod
:= Type_Definition
(Parent
(Typ
));
189 return Interface_List
(Nod
);
190 end Abstract_Interface_List
;
192 --------------------------------
193 -- Add_Access_Type_To_Process --
194 --------------------------------
196 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
200 Ensure_Freeze_Node
(E
);
201 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
205 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
209 end Add_Access_Type_To_Process
;
211 -----------------------
212 -- Add_Contract_Item --
213 -----------------------
215 procedure Add_Contract_Item
(Item
: Node_Id
; Subp_Id
: Entity_Id
) is
216 Items
: constant Node_Id
:= Contract
(Subp_Id
);
220 if Present
(Items
) and then Nkind
(Item
) = N_Pragma
then
221 Nam
:= Pragma_Name
(Item
);
223 if Nam_In
(Nam
, Name_Precondition
, Name_Postcondition
) then
224 Set_Next_Pragma
(Item
, Pre_Post_Conditions
(Items
));
225 Set_Pre_Post_Conditions
(Items
, Item
);
227 elsif Nam_In
(Nam
, Name_Contract_Cases
, Name_Test_Case
) then
228 Set_Next_Pragma
(Item
, Contract_Test_Cases
(Items
));
229 Set_Contract_Test_Cases
(Items
, Item
);
231 elsif Nam_In
(Nam
, Name_Depends
, Name_Global
) then
232 Set_Next_Pragma
(Item
, Classifications
(Items
));
233 Set_Classifications
(Items
, Item
);
235 -- The pragma is not a proper contract item
241 -- The subprogram has not been properly decorated or the item is illegal
246 end Add_Contract_Item
;
248 ----------------------------
249 -- Add_Global_Declaration --
250 ----------------------------
252 procedure Add_Global_Declaration
(N
: Node_Id
) is
253 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
256 if No
(Declarations
(Aux_Node
)) then
257 Set_Declarations
(Aux_Node
, New_List
);
260 Append_To
(Declarations
(Aux_Node
), N
);
262 end Add_Global_Declaration
;
268 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
270 function Addressable
(V
: Uint
) return Boolean is
272 return V
= Uint_8
or else
278 function Addressable
(V
: Int
) return Boolean is
286 -----------------------
287 -- Alignment_In_Bits --
288 -----------------------
290 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
292 return Alignment
(E
) * System_Storage_Unit
;
293 end Alignment_In_Bits
;
295 ---------------------------------
296 -- Append_Inherited_Subprogram --
297 ---------------------------------
299 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
300 Par
: constant Entity_Id
:= Alias
(S
);
301 -- The parent subprogram
303 Scop
: constant Entity_Id
:= Scope
(Par
);
304 -- The scope of definition of the parent subprogram
306 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
307 -- The derived type of which S is a primitive operation
313 if Ekind
(Current_Scope
) = E_Package
314 and then In_Private_Part
(Current_Scope
)
315 and then Has_Private_Declaration
(Typ
)
316 and then Is_Tagged_Type
(Typ
)
317 and then Scop
= Current_Scope
319 -- The inherited operation is available at the earliest place after
320 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
321 -- relevant for type extensions. If the parent operation appears
322 -- after the type extension, the operation is not visible.
325 (Visible_Declarations
326 (Specification
(Unit_Declaration_Node
(Current_Scope
))));
327 while Present
(Decl
) loop
328 if Nkind
(Decl
) = N_Private_Extension_Declaration
329 and then Defining_Entity
(Decl
) = Typ
331 if Sloc
(Decl
) > Sloc
(Par
) then
332 Next_E
:= Next_Entity
(Par
);
333 Set_Next_Entity
(Par
, S
);
334 Set_Next_Entity
(S
, Next_E
);
346 -- If partial view is not a type extension, or it appears before the
347 -- subprogram declaration, insert normally at end of entity list.
349 Append_Entity
(S
, Current_Scope
);
350 end Append_Inherited_Subprogram
;
352 -----------------------------------------
353 -- Apply_Compile_Time_Constraint_Error --
354 -----------------------------------------
356 procedure Apply_Compile_Time_Constraint_Error
359 Reason
: RT_Exception_Code
;
360 Ent
: Entity_Id
:= Empty
;
361 Typ
: Entity_Id
:= Empty
;
362 Loc
: Source_Ptr
:= No_Location
;
363 Rep
: Boolean := True;
364 Warn
: Boolean := False)
366 Stat
: constant Boolean := Is_Static_Expression
(N
);
367 R_Stat
: constant Node_Id
:=
368 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
379 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
385 -- Now we replace the node by an N_Raise_Constraint_Error node
386 -- This does not need reanalyzing, so set it as analyzed now.
389 Set_Analyzed
(N
, True);
392 Set_Raises_Constraint_Error
(N
);
394 -- Now deal with possible local raise handling
396 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
398 -- If the original expression was marked as static, the result is
399 -- still marked as static, but the Raises_Constraint_Error flag is
400 -- always set so that further static evaluation is not attempted.
403 Set_Is_Static_Expression
(N
);
405 end Apply_Compile_Time_Constraint_Error
;
407 --------------------------------------
408 -- Available_Full_View_Of_Component --
409 --------------------------------------
411 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
412 ST
: constant Entity_Id
:= Scope
(T
);
413 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
415 return In_Open_Scopes
(ST
)
416 and then In_Open_Scopes
(SCT
)
417 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
418 end Available_Full_View_Of_Component
;
424 procedure Bad_Attribute
427 Warn
: Boolean := False)
430 Error_Msg_Warn
:= Warn
;
431 Error_Msg_N
("unrecognized attribute&<", N
);
433 -- Check for possible misspelling
435 Error_Msg_Name_1
:= First_Attribute_Name
;
436 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
437 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
438 Error_Msg_N
-- CODEFIX
439 ("\possible misspelling of %<", N
);
443 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
447 --------------------------------
448 -- Bad_Predicated_Subtype_Use --
449 --------------------------------
451 procedure Bad_Predicated_Subtype_Use
455 Suggest_Static
: Boolean := False)
458 if Has_Predicates
(Typ
) then
459 if Is_Generic_Actual_Type
(Typ
) then
460 Error_Msg_FE
(Msg
& "??", N
, Typ
);
461 Error_Msg_F
("\Program_Error will be raised at run time??", N
);
463 Make_Raise_Program_Error
(Sloc
(N
),
464 Reason
=> PE_Bad_Predicated_Generic_Type
));
467 Error_Msg_FE
(Msg
, N
, Typ
);
470 -- Emit an optional suggestion on how to remedy the error if the
471 -- context warrants it.
473 if Suggest_Static
and then Present
(Static_Predicate
(Typ
)) then
474 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
477 end Bad_Predicated_Subtype_Use
;
479 --------------------------
480 -- Build_Actual_Subtype --
481 --------------------------
483 function Build_Actual_Subtype
485 N
: Node_Or_Entity_Id
) return Node_Id
488 -- Normally Sloc (N), but may point to corresponding body in some cases
490 Constraints
: List_Id
;
496 Disc_Type
: Entity_Id
;
502 if Nkind
(N
) = N_Defining_Identifier
then
503 Obj
:= New_Reference_To
(N
, Loc
);
505 -- If this is a formal parameter of a subprogram declaration, and
506 -- we are compiling the body, we want the declaration for the
507 -- actual subtype to carry the source position of the body, to
508 -- prevent anomalies in gdb when stepping through the code.
510 if Is_Formal
(N
) then
512 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
514 if Nkind
(Decl
) = N_Subprogram_Declaration
515 and then Present
(Corresponding_Body
(Decl
))
517 Loc
:= Sloc
(Corresponding_Body
(Decl
));
526 if Is_Array_Type
(T
) then
527 Constraints
:= New_List
;
528 for J
in 1 .. Number_Dimensions
(T
) loop
530 -- Build an array subtype declaration with the nominal subtype and
531 -- the bounds of the actual. Add the declaration in front of the
532 -- local declarations for the subprogram, for analysis before any
533 -- reference to the formal in the body.
536 Make_Attribute_Reference
(Loc
,
538 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
539 Attribute_Name
=> Name_First
,
540 Expressions
=> New_List
(
541 Make_Integer_Literal
(Loc
, J
)));
544 Make_Attribute_Reference
(Loc
,
546 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
547 Attribute_Name
=> Name_Last
,
548 Expressions
=> New_List
(
549 Make_Integer_Literal
(Loc
, J
)));
551 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
554 -- If the type has unknown discriminants there is no constrained
555 -- subtype to build. This is never called for a formal or for a
556 -- lhs, so returning the type is ok ???
558 elsif Has_Unknown_Discriminants
(T
) then
562 Constraints
:= New_List
;
564 -- Type T is a generic derived type, inherit the discriminants from
567 if Is_Private_Type
(T
)
568 and then No
(Full_View
(T
))
570 -- T was flagged as an error if it was declared as a formal
571 -- derived type with known discriminants. In this case there
572 -- is no need to look at the parent type since T already carries
573 -- its own discriminants.
575 and then not Error_Posted
(T
)
577 Disc_Type
:= Etype
(Base_Type
(T
));
582 Discr
:= First_Discriminant
(Disc_Type
);
583 while Present
(Discr
) loop
584 Append_To
(Constraints
,
585 Make_Selected_Component
(Loc
,
587 Duplicate_Subexpr_No_Checks
(Obj
),
588 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
589 Next_Discriminant
(Discr
);
593 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
594 Set_Is_Internal
(Subt
);
597 Make_Subtype_Declaration
(Loc
,
598 Defining_Identifier
=> Subt
,
599 Subtype_Indication
=>
600 Make_Subtype_Indication
(Loc
,
601 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
603 Make_Index_Or_Discriminant_Constraint
(Loc
,
604 Constraints
=> Constraints
)));
606 Mark_Rewrite_Insertion
(Decl
);
608 end Build_Actual_Subtype
;
610 ---------------------------------------
611 -- Build_Actual_Subtype_Of_Component --
612 ---------------------------------------
614 function Build_Actual_Subtype_Of_Component
616 N
: Node_Id
) return Node_Id
618 Loc
: constant Source_Ptr
:= Sloc
(N
);
619 P
: constant Node_Id
:= Prefix
(N
);
622 Index_Typ
: Entity_Id
;
624 Desig_Typ
: Entity_Id
;
625 -- This is either a copy of T, or if T is an access type, then it is
626 -- the directly designated type of this access type.
628 function Build_Actual_Array_Constraint
return List_Id
;
629 -- If one or more of the bounds of the component depends on
630 -- discriminants, build actual constraint using the discriminants
633 function Build_Actual_Record_Constraint
return List_Id
;
634 -- Similar to previous one, for discriminated components constrained
635 -- by the discriminant of the enclosing object.
637 -----------------------------------
638 -- Build_Actual_Array_Constraint --
639 -----------------------------------
641 function Build_Actual_Array_Constraint
return List_Id
is
642 Constraints
: constant List_Id
:= New_List
;
650 Indx
:= First_Index
(Desig_Typ
);
651 while Present
(Indx
) loop
652 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
653 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
655 if Denotes_Discriminant
(Old_Lo
) then
657 Make_Selected_Component
(Loc
,
658 Prefix
=> New_Copy_Tree
(P
),
659 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
662 Lo
:= New_Copy_Tree
(Old_Lo
);
664 -- The new bound will be reanalyzed in the enclosing
665 -- declaration. For literal bounds that come from a type
666 -- declaration, the type of the context must be imposed, so
667 -- insure that analysis will take place. For non-universal
668 -- types this is not strictly necessary.
670 Set_Analyzed
(Lo
, False);
673 if Denotes_Discriminant
(Old_Hi
) then
675 Make_Selected_Component
(Loc
,
676 Prefix
=> New_Copy_Tree
(P
),
677 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
680 Hi
:= New_Copy_Tree
(Old_Hi
);
681 Set_Analyzed
(Hi
, False);
684 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
689 end Build_Actual_Array_Constraint
;
691 ------------------------------------
692 -- Build_Actual_Record_Constraint --
693 ------------------------------------
695 function Build_Actual_Record_Constraint
return List_Id
is
696 Constraints
: constant List_Id
:= New_List
;
701 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
702 while Present
(D
) loop
703 if Denotes_Discriminant
(Node
(D
)) then
704 D_Val
:= Make_Selected_Component
(Loc
,
705 Prefix
=> New_Copy_Tree
(P
),
706 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
709 D_Val
:= New_Copy_Tree
(Node
(D
));
712 Append
(D_Val
, Constraints
);
717 end Build_Actual_Record_Constraint
;
719 -- Start of processing for Build_Actual_Subtype_Of_Component
722 -- Why the test for Spec_Expression mode here???
724 if In_Spec_Expression
then
727 -- More comments for the rest of this body would be good ???
729 elsif Nkind
(N
) = N_Explicit_Dereference
then
730 if Is_Composite_Type
(T
)
731 and then not Is_Constrained
(T
)
732 and then not (Is_Class_Wide_Type
(T
)
733 and then Is_Constrained
(Root_Type
(T
)))
734 and then not Has_Unknown_Discriminants
(T
)
736 -- If the type of the dereference is already constrained, it is an
739 if Is_Array_Type
(Etype
(N
))
740 and then Is_Constrained
(Etype
(N
))
744 Remove_Side_Effects
(P
);
745 return Build_Actual_Subtype
(T
, N
);
752 if Ekind
(T
) = E_Access_Subtype
then
753 Desig_Typ
:= Designated_Type
(T
);
758 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
759 Id
:= First_Index
(Desig_Typ
);
760 while Present
(Id
) loop
761 Index_Typ
:= Underlying_Type
(Etype
(Id
));
763 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
765 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
767 Remove_Side_Effects
(P
);
769 Build_Component_Subtype
770 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
776 elsif Is_Composite_Type
(Desig_Typ
)
777 and then Has_Discriminants
(Desig_Typ
)
778 and then not Has_Unknown_Discriminants
(Desig_Typ
)
780 if Is_Private_Type
(Desig_Typ
)
781 and then No
(Discriminant_Constraint
(Desig_Typ
))
783 Desig_Typ
:= Full_View
(Desig_Typ
);
786 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
787 while Present
(D
) loop
788 if Denotes_Discriminant
(Node
(D
)) then
789 Remove_Side_Effects
(P
);
791 Build_Component_Subtype
(
792 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
799 -- If none of the above, the actual and nominal subtypes are the same
802 end Build_Actual_Subtype_Of_Component
;
804 -----------------------------
805 -- Build_Component_Subtype --
806 -----------------------------
808 function Build_Component_Subtype
811 T
: Entity_Id
) return Node_Id
817 -- Unchecked_Union components do not require component subtypes
819 if Is_Unchecked_Union
(T
) then
823 Subt
:= Make_Temporary
(Loc
, 'S');
824 Set_Is_Internal
(Subt
);
827 Make_Subtype_Declaration
(Loc
,
828 Defining_Identifier
=> Subt
,
829 Subtype_Indication
=>
830 Make_Subtype_Indication
(Loc
,
831 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
833 Make_Index_Or_Discriminant_Constraint
(Loc
,
836 Mark_Rewrite_Insertion
(Decl
);
838 end Build_Component_Subtype
;
840 ---------------------------
841 -- Build_Default_Subtype --
842 ---------------------------
844 function Build_Default_Subtype
846 N
: Node_Id
) return Entity_Id
848 Loc
: constant Source_Ptr
:= Sloc
(N
);
852 -- The base type that is to be constrained by the defaults
855 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
859 Bas
:= Base_Type
(T
);
861 -- If T is non-private but its base type is private, this is the
862 -- completion of a subtype declaration whose parent type is private
863 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
864 -- are to be found in the full view of the base.
866 if Is_Private_Type
(Bas
) and then Present
(Full_View
(Bas
)) then
867 Bas
:= Full_View
(Bas
);
870 Disc
:= First_Discriminant
(T
);
872 if No
(Discriminant_Default_Value
(Disc
)) then
877 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
878 Constraints
: constant List_Id
:= New_List
;
882 while Present
(Disc
) loop
883 Append_To
(Constraints
,
884 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
885 Next_Discriminant
(Disc
);
889 Make_Subtype_Declaration
(Loc
,
890 Defining_Identifier
=> Act
,
891 Subtype_Indication
=>
892 Make_Subtype_Indication
(Loc
,
893 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
895 Make_Index_Or_Discriminant_Constraint
(Loc
,
896 Constraints
=> Constraints
)));
898 Insert_Action
(N
, Decl
);
902 end Build_Default_Subtype
;
904 --------------------------------------------
905 -- Build_Discriminal_Subtype_Of_Component --
906 --------------------------------------------
908 function Build_Discriminal_Subtype_Of_Component
909 (T
: Entity_Id
) return Node_Id
911 Loc
: constant Source_Ptr
:= Sloc
(T
);
915 function Build_Discriminal_Array_Constraint
return List_Id
;
916 -- If one or more of the bounds of the component depends on
917 -- discriminants, build actual constraint using the discriminants
920 function Build_Discriminal_Record_Constraint
return List_Id
;
921 -- Similar to previous one, for discriminated components constrained by
922 -- the discriminant of the enclosing object.
924 ----------------------------------------
925 -- Build_Discriminal_Array_Constraint --
926 ----------------------------------------
928 function Build_Discriminal_Array_Constraint
return List_Id
is
929 Constraints
: constant List_Id
:= New_List
;
937 Indx
:= First_Index
(T
);
938 while Present
(Indx
) loop
939 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
940 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
942 if Denotes_Discriminant
(Old_Lo
) then
943 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
946 Lo
:= New_Copy_Tree
(Old_Lo
);
949 if Denotes_Discriminant
(Old_Hi
) then
950 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
953 Hi
:= New_Copy_Tree
(Old_Hi
);
956 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
961 end Build_Discriminal_Array_Constraint
;
963 -----------------------------------------
964 -- Build_Discriminal_Record_Constraint --
965 -----------------------------------------
967 function Build_Discriminal_Record_Constraint
return List_Id
is
968 Constraints
: constant List_Id
:= New_List
;
973 D
:= First_Elmt
(Discriminant_Constraint
(T
));
974 while Present
(D
) loop
975 if Denotes_Discriminant
(Node
(D
)) then
977 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
980 D_Val
:= New_Copy_Tree
(Node
(D
));
983 Append
(D_Val
, Constraints
);
988 end Build_Discriminal_Record_Constraint
;
990 -- Start of processing for Build_Discriminal_Subtype_Of_Component
993 if Ekind
(T
) = E_Array_Subtype
then
994 Id
:= First_Index
(T
);
995 while Present
(Id
) loop
996 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
997 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
999 return Build_Component_Subtype
1000 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1006 elsif Ekind
(T
) = E_Record_Subtype
1007 and then Has_Discriminants
(T
)
1008 and then not Has_Unknown_Discriminants
(T
)
1010 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1011 while Present
(D
) loop
1012 if Denotes_Discriminant
(Node
(D
)) then
1013 return Build_Component_Subtype
1014 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1021 -- If none of the above, the actual and nominal subtypes are the same
1024 end Build_Discriminal_Subtype_Of_Component
;
1026 ------------------------------
1027 -- Build_Elaboration_Entity --
1028 ------------------------------
1030 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1031 Loc
: constant Source_Ptr
:= Sloc
(N
);
1033 Elab_Ent
: Entity_Id
;
1035 procedure Set_Package_Name
(Ent
: Entity_Id
);
1036 -- Given an entity, sets the fully qualified name of the entity in
1037 -- Name_Buffer, with components separated by double underscores. This
1038 -- is a recursive routine that climbs the scope chain to Standard.
1040 ----------------------
1041 -- Set_Package_Name --
1042 ----------------------
1044 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1046 if Scope
(Ent
) /= Standard_Standard
then
1047 Set_Package_Name
(Scope
(Ent
));
1050 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1052 Name_Buffer
(Name_Len
+ 1) := '_';
1053 Name_Buffer
(Name_Len
+ 2) := '_';
1054 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1055 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1059 Get_Name_String
(Chars
(Ent
));
1061 end Set_Package_Name
;
1063 -- Start of processing for Build_Elaboration_Entity
1066 -- Ignore if already constructed
1068 if Present
(Elaboration_Entity
(Spec_Id
)) then
1072 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1073 -- name with dots replaced by double underscore. We have to manually
1074 -- construct this name, since it will be elaborated in the outer scope,
1075 -- and thus will not have the unit name automatically prepended.
1077 Set_Package_Name
(Spec_Id
);
1078 Add_Str_To_Name_Buffer
("_E");
1080 -- Create elaboration counter
1082 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1083 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1086 Make_Object_Declaration
(Loc
,
1087 Defining_Identifier
=> Elab_Ent
,
1088 Object_Definition
=>
1089 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1090 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1092 Push_Scope
(Standard_Standard
);
1093 Add_Global_Declaration
(Decl
);
1096 -- Reset True_Constant indication, since we will indeed assign a value
1097 -- to the variable in the binder main. We also kill the Current_Value
1098 -- and Last_Assignment fields for the same reason.
1100 Set_Is_True_Constant
(Elab_Ent
, False);
1101 Set_Current_Value
(Elab_Ent
, Empty
);
1102 Set_Last_Assignment
(Elab_Ent
, Empty
);
1104 -- We do not want any further qualification of the name (if we did not
1105 -- do this, we would pick up the name of the generic package in the case
1106 -- of a library level generic instantiation).
1108 Set_Has_Qualified_Name
(Elab_Ent
);
1109 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1110 end Build_Elaboration_Entity
;
1112 --------------------------------
1113 -- Build_Explicit_Dereference --
1114 --------------------------------
1116 procedure Build_Explicit_Dereference
1120 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1123 -- An entity of a type with a reference aspect is overloaded with
1124 -- both interpretations: with and without the dereference. Now that
1125 -- the dereference is made explicit, set the type of the node properly,
1126 -- to prevent anomalies in the backend. Same if the expression is an
1127 -- overloaded function call whose return type has a reference aspect.
1129 if Is_Entity_Name
(Expr
) then
1130 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1132 elsif Nkind
(Expr
) = N_Function_Call
then
1133 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1136 Set_Is_Overloaded
(Expr
, False);
1138 Make_Explicit_Dereference
(Loc
,
1140 Make_Selected_Component
(Loc
,
1141 Prefix
=> Relocate_Node
(Expr
),
1142 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1143 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1144 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1145 end Build_Explicit_Dereference
;
1147 -----------------------------------
1148 -- Cannot_Raise_Constraint_Error --
1149 -----------------------------------
1151 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1153 if Compile_Time_Known_Value
(Expr
) then
1156 elsif Do_Range_Check
(Expr
) then
1159 elsif Raises_Constraint_Error
(Expr
) then
1163 case Nkind
(Expr
) is
1164 when N_Identifier
=>
1167 when N_Expanded_Name
=>
1170 when N_Selected_Component
=>
1171 return not Do_Discriminant_Check
(Expr
);
1173 when N_Attribute_Reference
=>
1174 if Do_Overflow_Check
(Expr
) then
1177 elsif No
(Expressions
(Expr
)) then
1185 N
:= First
(Expressions
(Expr
));
1186 while Present
(N
) loop
1187 if Cannot_Raise_Constraint_Error
(N
) then
1198 when N_Type_Conversion
=>
1199 if Do_Overflow_Check
(Expr
)
1200 or else Do_Length_Check
(Expr
)
1201 or else Do_Tag_Check
(Expr
)
1205 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1208 when N_Unchecked_Type_Conversion
=>
1209 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1212 if Do_Overflow_Check
(Expr
) then
1215 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1222 if Do_Division_Check
(Expr
)
1223 or else Do_Overflow_Check
(Expr
)
1228 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1230 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1249 N_Op_Shift_Right_Arithmetic |
1253 if Do_Overflow_Check
(Expr
) then
1257 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1259 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1266 end Cannot_Raise_Constraint_Error
;
1268 -----------------------------------------
1269 -- Check_Dynamically_Tagged_Expression --
1270 -----------------------------------------
1272 procedure Check_Dynamically_Tagged_Expression
1275 Related_Nod
: Node_Id
)
1278 pragma Assert
(Is_Tagged_Type
(Typ
));
1280 -- In order to avoid spurious errors when analyzing the expanded code,
1281 -- this check is done only for nodes that come from source and for
1282 -- actuals of generic instantiations.
1284 if (Comes_From_Source
(Related_Nod
)
1285 or else In_Generic_Actual
(Expr
))
1286 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1287 or else Is_Dynamically_Tagged
(Expr
))
1288 and then Is_Tagged_Type
(Typ
)
1289 and then not Is_Class_Wide_Type
(Typ
)
1291 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1293 end Check_Dynamically_Tagged_Expression
;
1295 -----------------------------------------------
1296 -- Check_Expression_Against_Static_Predicate --
1297 -----------------------------------------------
1299 procedure Check_Expression_Against_Static_Predicate
1304 -- When the predicate is static and the value of the expression is known
1305 -- at compile time, evaluate the predicate check. A type is non-static
1306 -- when it has aspect Dynamic_Predicate.
1308 if Compile_Time_Known_Value
(Expr
)
1309 and then Has_Predicates
(Typ
)
1310 and then Present
(Static_Predicate
(Typ
))
1311 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
1313 -- Either -gnatc is enabled or the expression is ok
1315 if Operating_Mode
< Generate_Code
1316 or else Eval_Static_Predicate_Check
(Expr
, Typ
)
1320 -- The expression is prohibited by the static predicate
1324 ("?static expression fails static predicate check on &",
1328 end Check_Expression_Against_Static_Predicate
;
1330 --------------------------
1331 -- Check_Fully_Declared --
1332 --------------------------
1334 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1336 if Ekind
(T
) = E_Incomplete_Type
then
1338 -- Ada 2005 (AI-50217): If the type is available through a limited
1339 -- with_clause, verify that its full view has been analyzed.
1341 if From_With_Type
(T
)
1342 and then Present
(Non_Limited_View
(T
))
1343 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1345 -- The non-limited view is fully declared
1350 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1353 -- Need comments for these tests ???
1355 elsif Has_Private_Component
(T
)
1356 and then not Is_Generic_Type
(Root_Type
(T
))
1357 and then not In_Spec_Expression
1359 -- Special case: if T is the anonymous type created for a single
1360 -- task or protected object, use the name of the source object.
1362 if Is_Concurrent_Type
(T
)
1363 and then not Comes_From_Source
(T
)
1364 and then Nkind
(N
) = N_Object_Declaration
1366 Error_Msg_NE
("type of& has incomplete component", N
,
1367 Defining_Identifier
(N
));
1371 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1374 end Check_Fully_Declared
;
1376 -------------------------------------
1377 -- Check_Function_Writable_Actuals --
1378 -------------------------------------
1380 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
1381 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
1382 Identifiers_List
: Elist_Id
:= No_Elist
;
1383 Error_Node
: Node_Id
:= Empty
;
1385 procedure Collect_Identifiers
(N
: Node_Id
);
1386 -- In a single traversal of subtree N collect in Writable_Actuals_List
1387 -- all the actuals of functions with writable actuals, and in the list
1388 -- Identifiers_List collect all the identifiers that are not actuals of
1389 -- functions with writable actuals. If a writable actual is referenced
1390 -- twice as writable actual then Error_Node is set to reference its
1391 -- second occurrence, the error is reported, and the tree traversal
1394 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
1395 -- Return the entity associated with the function call
1397 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
1398 -- Preanalyze N without reporting errors. Very dubious, you can't just
1399 -- go analyzing things more than once???
1401 -------------------------
1402 -- Collect_Identifiers --
1403 -------------------------
1405 procedure Collect_Identifiers
(N
: Node_Id
) is
1407 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
1408 -- Process a single node during the tree traversal to collect the
1409 -- writable actuals of functions and all the identifiers which are
1410 -- not writable actuals of functions.
1412 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
1413 -- Returns True if List has a node whose Entity is Entity (N)
1415 -------------------------
1416 -- Check_Function_Call --
1417 -------------------------
1419 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
1420 Is_Writable_Actual
: Boolean := False;
1423 if Nkind
(N
) = N_Identifier
then
1425 -- No analysis possible if the entity is not decorated
1427 if No
(Entity
(N
)) then
1430 -- Don't collect identifiers of packages, called functions, etc
1432 elsif Ekind_In
(Entity
(N
), E_Package
,
1439 -- Analyze if N is a writable actual of a function
1441 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
1443 Call
: constant Node_Id
:= Parent
(N
);
1444 Id
: constant Entity_Id
:= Get_Function_Id
(Call
);
1449 Formal
:= First_Formal
(Id
);
1450 Actual
:= First_Actual
(Call
);
1451 while Present
(Actual
) and then Present
(Formal
) loop
1453 if Ekind_In
(Formal
, E_Out_Parameter
,
1456 Is_Writable_Actual
:= True;
1462 Next_Formal
(Formal
);
1463 Next_Actual
(Actual
);
1468 if Is_Writable_Actual
then
1469 if Contains
(Writable_Actuals_List
, N
) then
1471 ("conflict of writable function parameter in "
1472 & "construct with arbitrary order of evaluation", N
);
1477 if Writable_Actuals_List
= No_Elist
then
1478 Writable_Actuals_List
:= New_Elmt_List
;
1481 Append_Elmt
(N
, Writable_Actuals_List
);
1483 if Identifiers_List
= No_Elist
then
1484 Identifiers_List
:= New_Elmt_List
;
1487 Append_Unique_Elmt
(N
, Identifiers_List
);
1500 N
: Node_Id
) return Boolean
1502 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
1507 if List
= No_Elist
then
1511 Elmt
:= First_Elmt
(List
);
1512 while Present
(Elmt
) loop
1513 if Entity
(Node
(Elmt
)) = Entity
(N
) then
1527 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
1528 -- The traversal procedure
1530 -- Start of processing for Collect_Identifiers
1533 if Present
(Error_Node
) then
1537 if Nkind
(N
) in N_Subexpr
1538 and then Is_Static_Expression
(N
)
1544 end Collect_Identifiers
;
1546 ---------------------
1547 -- Get_Function_Id --
1548 ---------------------
1550 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
1551 Nam
: constant Node_Id
:= Name
(Call
);
1555 if Nkind
(Nam
) = N_Explicit_Dereference
then
1557 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
1559 elsif Nkind
(Nam
) = N_Selected_Component
then
1560 Id
:= Entity
(Selector_Name
(Nam
));
1562 elsif Nkind
(Nam
) = N_Indexed_Component
then
1563 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1570 end Get_Function_Id
;
1572 ---------------------------
1573 -- Preanalyze_Expression --
1574 ---------------------------
1576 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
1577 Status
: constant Boolean := Get_Ignore_Errors
;
1579 Set_Ignore_Errors
(True);
1581 Set_Ignore_Errors
(Status
);
1582 end Preanalyze_Without_Errors
;
1584 -- Start of processing for Check_Function_Writable_Actuals
1587 if Ada_Version
< Ada_2012
1588 or else (not (Nkind
(N
) in N_Op
)
1589 and then not (Nkind
(N
) in N_Membership_Test
)
1590 and then not Nkind_In
(N
, N_Range
,
1592 N_Extension_Aggregate
,
1593 N_Full_Type_Declaration
,
1595 N_Procedure_Call_Statement
,
1596 N_Entry_Call_Statement
))
1597 or else (Nkind
(N
) = N_Full_Type_Declaration
1598 and then not Is_Record_Type
(Defining_Identifier
(N
)))
1603 -- If a construct C has two or more direct constituents that are names
1604 -- or expressions whose evaluation may occur in an arbitrary order, at
1605 -- least one of which contains a function call with an in out or out
1606 -- parameter, then the construct is legal only if: for each name N that
1607 -- is passed as a parameter of mode in out or out to some inner function
1608 -- call C2 (not including the construct C itself), there is no other
1609 -- name anywhere within a direct constituent of the construct C other
1610 -- than the one containing C2, that is known to refer to the same
1611 -- object (RM 6.4.1(6.17/3)).
1615 Collect_Identifiers
(Low_Bound
(N
));
1616 Collect_Identifiers
(High_Bound
(N
));
1618 when N_Op | N_Membership_Test
=>
1622 Collect_Identifiers
(Left_Opnd
(N
));
1624 if Present
(Right_Opnd
(N
)) then
1625 Collect_Identifiers
(Right_Opnd
(N
));
1628 if Nkind_In
(N
, N_In
, N_Not_In
)
1629 and then Present
(Alternatives
(N
))
1631 Expr
:= First
(Alternatives
(N
));
1632 while Present
(Expr
) loop
1633 Collect_Identifiers
(Expr
);
1640 when N_Full_Type_Declaration
=>
1642 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
1643 -- Return the record part of this record type definition
1645 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
1646 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
1648 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
1649 return Record_Extension_Part
(Type_Def
);
1653 end Get_Record_Part
;
1656 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
1657 Rec
: Node_Id
:= Get_Record_Part
(N
);
1660 -- No need to perform any analysis if the record has no
1663 if No
(Rec
) or else No
(Component_List
(Rec
)) then
1667 -- Collect the identifiers starting from the deepest
1668 -- derivation. Done to report the error in the deepest
1672 if Present
(Component_List
(Rec
)) then
1673 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
1674 while Present
(Comp
) loop
1675 if Nkind
(Comp
) = N_Component_Declaration
1676 and then Present
(Expression
(Comp
))
1678 Collect_Identifiers
(Expression
(Comp
));
1685 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
1686 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
1689 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
1690 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
1694 when N_Subprogram_Call |
1695 N_Entry_Call_Statement
=>
1697 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
1702 Formal
:= First_Formal
(Id
);
1703 Actual
:= First_Actual
(N
);
1704 while Present
(Actual
) and then Present
(Formal
) loop
1705 if Ekind_In
(Formal
, E_Out_Parameter
,
1708 Collect_Identifiers
(Actual
);
1711 Next_Formal
(Formal
);
1712 Next_Actual
(Actual
);
1717 N_Extension_Aggregate
=>
1721 Comp_Expr
: Node_Id
;
1724 -- Handle the N_Others_Choice of array aggregates with static
1725 -- bounds. There is no need to perform this analysis in
1726 -- aggregates without static bounds since we cannot evaluate
1727 -- if the N_Others_Choice covers several elements. There is
1728 -- no need to handle the N_Others choice of record aggregates
1729 -- since at this stage it has been already expanded by
1730 -- Resolve_Record_Aggregate.
1732 if Is_Array_Type
(Etype
(N
))
1733 and then Nkind
(N
) = N_Aggregate
1734 and then Present
(Aggregate_Bounds
(N
))
1735 and then Compile_Time_Known_Bounds
(Etype
(N
))
1736 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
1737 > Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
1740 Count_Components
: Uint
:= Uint_0
;
1741 Num_Components
: Uint
;
1742 Others_Assoc
: Node_Id
;
1743 Others_Choice
: Node_Id
:= Empty
;
1744 Others_Box_Present
: Boolean := False;
1747 -- Count positional associations
1749 if Present
(Expressions
(N
)) then
1750 Comp_Expr
:= First
(Expressions
(N
));
1751 while Present
(Comp_Expr
) loop
1752 Count_Components
:= Count_Components
+ 1;
1757 -- Count the rest of elements and locate the N_Others
1760 Assoc
:= First
(Component_Associations
(N
));
1761 while Present
(Assoc
) loop
1762 Choice
:= First
(Choices
(Assoc
));
1763 while Present
(Choice
) loop
1764 if Nkind
(Choice
) = N_Others_Choice
then
1765 Others_Assoc
:= Assoc
;
1766 Others_Choice
:= Choice
;
1767 Others_Box_Present
:= Box_Present
(Assoc
);
1769 -- Count several components
1771 elsif Nkind_In
(Choice
, N_Range
,
1772 N_Subtype_Indication
)
1773 or else (Is_Entity_Name
(Choice
)
1774 and then Is_Type
(Entity
(Choice
)))
1779 Get_Index_Bounds
(Choice
, L
, H
);
1781 (Compile_Time_Known_Value
(L
)
1782 and then Compile_Time_Known_Value
(H
));
1785 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
1788 -- Count single component. No other case available
1789 -- since we are handling an aggregate with static
1793 pragma Assert
(Is_Static_Expression
(Choice
)
1794 or else Nkind
(Choice
) = N_Identifier
1795 or else Nkind
(Choice
) = N_Integer_Literal
);
1797 Count_Components
:= Count_Components
+ 1;
1807 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
1808 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
1810 pragma Assert
(Count_Components
<= Num_Components
);
1812 -- Handle the N_Others choice if it covers several
1815 if Present
(Others_Choice
)
1816 and then (Num_Components
- Count_Components
) > 1
1818 if not Others_Box_Present
then
1820 -- At this stage, if expansion is active, the
1821 -- expression of the others choice has not been
1822 -- analyzed. Hence we generate a duplicate and
1823 -- we analyze it silently to have available the
1824 -- minimum decoration required to collect the
1827 if not Expander_Active
then
1828 Comp_Expr
:= Expression
(Others_Assoc
);
1831 New_Copy_Tree
(Expression
(Others_Assoc
));
1832 Preanalyze_Without_Errors
(Comp_Expr
);
1835 Collect_Identifiers
(Comp_Expr
);
1837 if Writable_Actuals_List
/= No_Elist
then
1839 -- As suggested by Robert, at current stage we
1840 -- report occurrences of this case as warnings.
1843 ("conflict of writable function parameter in "
1844 & "construct with arbitrary order of "
1846 Node
(First_Elmt
(Writable_Actuals_List
)));
1853 -- Handle ancestor part of extension aggregates
1855 if Nkind
(N
) = N_Extension_Aggregate
then
1856 Collect_Identifiers
(Ancestor_Part
(N
));
1859 -- Handle positional associations
1861 if Present
(Expressions
(N
)) then
1862 Comp_Expr
:= First
(Expressions
(N
));
1863 while Present
(Comp_Expr
) loop
1864 if not Is_Static_Expression
(Comp_Expr
) then
1865 Collect_Identifiers
(Comp_Expr
);
1872 -- Handle discrete associations
1874 if Present
(Component_Associations
(N
)) then
1875 Assoc
:= First
(Component_Associations
(N
));
1876 while Present
(Assoc
) loop
1878 if not Box_Present
(Assoc
) then
1879 Choice
:= First
(Choices
(Assoc
));
1880 while Present
(Choice
) loop
1882 -- For now we skip discriminants since it requires
1883 -- performing the analysis in two phases: first one
1884 -- analyzing discriminants and second one analyzing
1885 -- the rest of components since discriminants are
1886 -- evaluated prior to components: too much extra
1887 -- work to detect a corner case???
1889 if Nkind
(Choice
) in N_Has_Entity
1890 and then Present
(Entity
(Choice
))
1891 and then Ekind
(Entity
(Choice
)) = E_Discriminant
1895 elsif Box_Present
(Assoc
) then
1899 if not Analyzed
(Expression
(Assoc
)) then
1901 New_Copy_Tree
(Expression
(Assoc
));
1902 Set_Parent
(Comp_Expr
, Parent
(N
));
1903 Preanalyze_Without_Errors
(Comp_Expr
);
1905 Comp_Expr
:= Expression
(Assoc
);
1908 Collect_Identifiers
(Comp_Expr
);
1924 -- No further action needed if we already reported an error
1926 if Present
(Error_Node
) then
1930 -- Check if some writable argument of a function is referenced
1932 if Writable_Actuals_List
/= No_Elist
1933 and then Identifiers_List
/= No_Elist
1940 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
1941 while Present
(Elmt_1
) loop
1942 Elmt_2
:= First_Elmt
(Identifiers_List
);
1943 while Present
(Elmt_2
) loop
1944 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
1946 ("conflict of writable function parameter in construct "
1947 & "with arbitrary order of evaluation",
1958 end Check_Function_Writable_Actuals
;
1960 --------------------------------
1961 -- Check_Implicit_Dereference --
1962 --------------------------------
1964 procedure Check_Implicit_Dereference
(Nam
: Node_Id
; Typ
: Entity_Id
) is
1969 if Ada_Version
< Ada_2012
1970 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
1974 elsif not Comes_From_Source
(Nam
) then
1977 elsif Is_Entity_Name
(Nam
)
1978 and then Is_Type
(Entity
(Nam
))
1983 Disc
:= First_Discriminant
(Typ
);
1984 while Present
(Disc
) loop
1985 if Has_Implicit_Dereference
(Disc
) then
1986 Desig
:= Designated_Type
(Etype
(Disc
));
1987 Add_One_Interp
(Nam
, Disc
, Desig
);
1991 Next_Discriminant
(Disc
);
1994 end Check_Implicit_Dereference
;
1996 ----------------------------------
1997 -- Check_Internal_Protected_Use --
1998 ----------------------------------
2000 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2006 while Present
(S
) loop
2007 if S
= Standard_Standard
then
2010 elsif Ekind
(S
) = E_Function
2011 and then Ekind
(Scope
(S
)) = E_Protected_Type
2020 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2021 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2023 ("within protected function cannot use protected "
2024 & "procedure in renaming or as generic actual", N
);
2026 elsif Nkind
(N
) = N_Attribute_Reference
then
2028 ("within protected function cannot take access of "
2029 & " protected procedure", N
);
2033 ("within protected function, protected object is constant", N
);
2035 ("\cannot call operation that may modify it", N
);
2038 end Check_Internal_Protected_Use
;
2040 ---------------------------------------
2041 -- Check_Later_Vs_Basic_Declarations --
2042 ---------------------------------------
2044 procedure Check_Later_Vs_Basic_Declarations
2046 During_Parsing
: Boolean)
2048 Body_Sloc
: Source_Ptr
;
2051 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2052 -- Return whether Decl is considered as a declarative item.
2053 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2054 -- When During_Parsing is False, the semantics of SPARK is followed.
2056 -------------------------------
2057 -- Is_Later_Declarative_Item --
2058 -------------------------------
2060 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2062 if Nkind
(Decl
) in N_Later_Decl_Item
then
2065 elsif Nkind
(Decl
) = N_Pragma
then
2068 elsif During_Parsing
then
2071 -- In SPARK, a package declaration is not considered as a later
2072 -- declarative item.
2074 elsif Nkind
(Decl
) = N_Package_Declaration
then
2077 -- In SPARK, a renaming is considered as a later declarative item
2079 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2085 end Is_Later_Declarative_Item
;
2087 -- Start of Check_Later_Vs_Basic_Declarations
2090 Decl
:= First
(Decls
);
2092 -- Loop through sequence of basic declarative items
2094 Outer
: while Present
(Decl
) loop
2095 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2096 and then Nkind
(Decl
) not in N_Body_Stub
2100 -- Once a body is encountered, we only allow later declarative
2101 -- items. The inner loop checks the rest of the list.
2104 Body_Sloc
:= Sloc
(Decl
);
2106 Inner
: while Present
(Decl
) loop
2107 if not Is_Later_Declarative_Item
(Decl
) then
2108 if During_Parsing
then
2109 if Ada_Version
= Ada_83
then
2110 Error_Msg_Sloc
:= Body_Sloc
;
2112 ("(Ada 83) decl cannot appear after body#", Decl
);
2115 Error_Msg_Sloc
:= Body_Sloc
;
2116 Check_SPARK_Restriction
2117 ("decl cannot appear after body#", Decl
);
2125 end Check_Later_Vs_Basic_Declarations
;
2127 -------------------------
2128 -- Check_Nested_Access --
2129 -------------------------
2131 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2132 Scop
: constant Entity_Id
:= Current_Scope
;
2133 Current_Subp
: Entity_Id
;
2134 Enclosing
: Entity_Id
;
2137 -- Currently only enabled for VM back-ends for efficiency, should we
2138 -- enable it more systematically ???
2140 -- Check for Is_Imported needs commenting below ???
2142 if VM_Target
/= No_VM
2143 and then (Ekind
(Ent
) = E_Variable
2145 Ekind
(Ent
) = E_Constant
2147 Ekind
(Ent
) = E_Loop_Parameter
)
2148 and then Scope
(Ent
) /= Empty
2149 and then not Is_Library_Level_Entity
(Ent
)
2150 and then not Is_Imported
(Ent
)
2152 if Is_Subprogram
(Scop
)
2153 or else Is_Generic_Subprogram
(Scop
)
2154 or else Is_Entry
(Scop
)
2156 Current_Subp
:= Scop
;
2158 Current_Subp
:= Current_Subprogram
;
2161 Enclosing
:= Enclosing_Subprogram
(Ent
);
2163 if Enclosing
/= Empty
2164 and then Enclosing
/= Current_Subp
2166 Set_Has_Up_Level_Access
(Ent
, True);
2169 end Check_Nested_Access
;
2171 ---------------------------
2172 -- Check_No_Hidden_State --
2173 ---------------------------
2175 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2176 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2177 -- Determine whether the entity of a package denoted by Pkg has a null
2180 -----------------------------
2181 -- Has_Null_Abstract_State --
2182 -----------------------------
2184 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2185 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2188 -- Check first available state of related package. A null abstract
2189 -- state always appears as the sole element of the state list.
2193 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2194 end Has_Null_Abstract_State
;
2198 Context
: Entity_Id
:= Empty
;
2199 Not_Visible
: Boolean := False;
2202 -- Start of processing for Check_No_Hidden_State
2205 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2207 -- Find the proper context where the object or state appears
2210 while Present
(Scop
) loop
2213 -- Keep track of the context's visibility
2215 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2217 -- Prevent the search from going too far
2219 if Context
= Standard_Standard
then
2222 -- Objects and states that appear immediately within a subprogram or
2223 -- inside a construct nested within a subprogram do not introduce a
2224 -- hidden state. They behave as local variable declarations.
2226 elsif Is_Subprogram
(Context
) then
2229 -- When examining a package body, use the entity of the spec as it
2230 -- carries the abstract state declarations.
2232 elsif Ekind
(Context
) = E_Package_Body
then
2233 Context
:= Spec_Entity
(Context
);
2236 -- Stop the traversal when a package subject to a null abstract state
2239 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2240 and then Has_Null_Abstract_State
(Context
)
2245 Scop
:= Scope
(Scop
);
2248 -- At this point we know that there is at least one package with a null
2249 -- abstract state in visibility. Emit an error message unconditionally
2250 -- if the entity being processed is a state because the placement of the
2251 -- related package is irrelevant. This is not the case for objects as
2252 -- the intermediate context matters.
2254 if Present
(Context
)
2255 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
2257 Error_Msg_N
("cannot introduce hidden state &", Id
);
2258 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
2260 end Check_No_Hidden_State
;
2262 ------------------------------------------
2263 -- Check_Potentially_Blocking_Operation --
2264 ------------------------------------------
2266 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2270 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2271 -- When pragma Detect_Blocking is active, the run time will raise
2272 -- Program_Error. Here we only issue a warning, since we generally
2273 -- support the use of potentially blocking operations in the absence
2276 -- Indirect blocking through a subprogram call cannot be diagnosed
2277 -- statically without interprocedural analysis, so we do not attempt
2280 S
:= Scope
(Current_Scope
);
2281 while Present
(S
) and then S
/= Standard_Standard
loop
2282 if Is_Protected_Type
(S
) then
2284 ("potentially blocking operation in protected operation??", N
);
2290 end Check_Potentially_Blocking_Operation
;
2292 ------------------------------
2293 -- Check_Unprotected_Access --
2294 ------------------------------
2296 procedure Check_Unprotected_Access
2300 Cont_Encl_Typ
: Entity_Id
;
2301 Pref_Encl_Typ
: Entity_Id
;
2303 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
2304 -- Check whether Obj is a private component of a protected object.
2305 -- Return the protected type where the component resides, Empty
2308 function Is_Public_Operation
return Boolean;
2309 -- Verify that the enclosing operation is callable from outside the
2310 -- protected object, to minimize false positives.
2312 ------------------------------
2313 -- Enclosing_Protected_Type --
2314 ------------------------------
2316 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
2318 if Is_Entity_Name
(Obj
) then
2320 Ent
: Entity_Id
:= Entity
(Obj
);
2323 -- The object can be a renaming of a private component, use
2324 -- the original record component.
2326 if Is_Prival
(Ent
) then
2327 Ent
:= Prival_Link
(Ent
);
2330 if Is_Protected_Type
(Scope
(Ent
)) then
2336 -- For indexed and selected components, recursively check the prefix
2338 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
2339 return Enclosing_Protected_Type
(Prefix
(Obj
));
2341 -- The object does not denote a protected component
2346 end Enclosing_Protected_Type
;
2348 -------------------------
2349 -- Is_Public_Operation --
2350 -------------------------
2352 function Is_Public_Operation
return Boolean is
2359 and then S
/= Pref_Encl_Typ
2361 if Scope
(S
) = Pref_Encl_Typ
then
2362 E
:= First_Entity
(Pref_Encl_Typ
);
2364 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
2377 end Is_Public_Operation
;
2379 -- Start of processing for Check_Unprotected_Access
2382 if Nkind
(Expr
) = N_Attribute_Reference
2383 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
2385 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
2386 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
2388 -- Check whether we are trying to export a protected component to a
2389 -- context with an equal or lower access level.
2391 if Present
(Pref_Encl_Typ
)
2392 and then No
(Cont_Encl_Typ
)
2393 and then Is_Public_Operation
2394 and then Scope_Depth
(Pref_Encl_Typ
) >=
2395 Object_Access_Level
(Context
)
2398 ("??possible unprotected access to protected data", Expr
);
2401 end Check_Unprotected_Access
;
2407 procedure Check_VMS
(Construct
: Node_Id
) is
2409 if not OpenVMS_On_Target
then
2411 ("this construct is allowed only in Open'V'M'S", Construct
);
2415 ------------------------
2416 -- Collect_Interfaces --
2417 ------------------------
2419 procedure Collect_Interfaces
2421 Ifaces_List
: out Elist_Id
;
2422 Exclude_Parents
: Boolean := False;
2423 Use_Full_View
: Boolean := True)
2425 procedure Collect
(Typ
: Entity_Id
);
2426 -- Subsidiary subprogram used to traverse the whole list
2427 -- of directly and indirectly implemented interfaces
2433 procedure Collect
(Typ
: Entity_Id
) is
2434 Ancestor
: Entity_Id
;
2442 -- Handle private types
2445 and then Is_Private_Type
(Typ
)
2446 and then Present
(Full_View
(Typ
))
2448 Full_T
:= Full_View
(Typ
);
2451 -- Include the ancestor if we are generating the whole list of
2452 -- abstract interfaces.
2454 if Etype
(Full_T
) /= Typ
2456 -- Protect the frontend against wrong sources. For example:
2459 -- type A is tagged null record;
2460 -- type B is new A with private;
2461 -- type C is new A with private;
2463 -- type B is new C with null record;
2464 -- type C is new B with null record;
2467 and then Etype
(Full_T
) /= T
2469 Ancestor
:= Etype
(Full_T
);
2472 if Is_Interface
(Ancestor
)
2473 and then not Exclude_Parents
2475 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
2479 -- Traverse the graph of ancestor interfaces
2481 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
2482 Id
:= First
(Abstract_Interface_List
(Full_T
));
2483 while Present
(Id
) loop
2484 Iface
:= Etype
(Id
);
2486 -- Protect against wrong uses. For example:
2487 -- type I is interface;
2488 -- type O is tagged null record;
2489 -- type Wrong is new I and O with null record; -- ERROR
2491 if Is_Interface
(Iface
) then
2493 and then Etype
(T
) /= T
2494 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
2499 Append_Unique_Elmt
(Iface
, Ifaces_List
);
2508 -- Start of processing for Collect_Interfaces
2511 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
2512 Ifaces_List
:= New_Elmt_List
;
2514 end Collect_Interfaces
;
2516 ----------------------------------
2517 -- Collect_Interface_Components --
2518 ----------------------------------
2520 procedure Collect_Interface_Components
2521 (Tagged_Type
: Entity_Id
;
2522 Components_List
: out Elist_Id
)
2524 procedure Collect
(Typ
: Entity_Id
);
2525 -- Subsidiary subprogram used to climb to the parents
2531 procedure Collect
(Typ
: Entity_Id
) is
2532 Tag_Comp
: Entity_Id
;
2533 Parent_Typ
: Entity_Id
;
2536 -- Handle private types
2538 if Present
(Full_View
(Etype
(Typ
))) then
2539 Parent_Typ
:= Full_View
(Etype
(Typ
));
2541 Parent_Typ
:= Etype
(Typ
);
2544 if Parent_Typ
/= Typ
2546 -- Protect the frontend against wrong sources. For example:
2549 -- type A is tagged null record;
2550 -- type B is new A with private;
2551 -- type C is new A with private;
2553 -- type B is new C with null record;
2554 -- type C is new B with null record;
2557 and then Parent_Typ
/= Tagged_Type
2559 Collect
(Parent_Typ
);
2562 -- Collect the components containing tags of secondary dispatch
2565 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
2566 while Present
(Tag_Comp
) loop
2567 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
2568 Append_Elmt
(Tag_Comp
, Components_List
);
2570 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
2574 -- Start of processing for Collect_Interface_Components
2577 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
2578 and then Is_Tagged_Type
(Tagged_Type
));
2580 Components_List
:= New_Elmt_List
;
2581 Collect
(Tagged_Type
);
2582 end Collect_Interface_Components
;
2584 -----------------------------
2585 -- Collect_Interfaces_Info --
2586 -----------------------------
2588 procedure Collect_Interfaces_Info
2590 Ifaces_List
: out Elist_Id
;
2591 Components_List
: out Elist_Id
;
2592 Tags_List
: out Elist_Id
)
2594 Comps_List
: Elist_Id
;
2595 Comp_Elmt
: Elmt_Id
;
2596 Comp_Iface
: Entity_Id
;
2597 Iface_Elmt
: Elmt_Id
;
2600 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
2601 -- Search for the secondary tag associated with the interface type
2602 -- Iface that is implemented by T.
2608 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
2611 if not Is_CPP_Class
(T
) then
2612 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
2614 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
2618 and then Is_Tag
(Node
(ADT
))
2619 and then Related_Type
(Node
(ADT
)) /= Iface
2621 -- Skip secondary dispatch table referencing thunks to user
2622 -- defined primitives covered by this interface.
2624 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
2627 -- Skip secondary dispatch tables of Ada types
2629 if not Is_CPP_Class
(T
) then
2631 -- Skip secondary dispatch table referencing thunks to
2632 -- predefined primitives.
2634 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
2637 -- Skip secondary dispatch table referencing user-defined
2638 -- primitives covered by this interface.
2640 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
2643 -- Skip secondary dispatch table referencing predefined
2646 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
2651 pragma Assert
(Is_Tag
(Node
(ADT
)));
2655 -- Start of processing for Collect_Interfaces_Info
2658 Collect_Interfaces
(T
, Ifaces_List
);
2659 Collect_Interface_Components
(T
, Comps_List
);
2661 -- Search for the record component and tag associated with each
2662 -- interface type of T.
2664 Components_List
:= New_Elmt_List
;
2665 Tags_List
:= New_Elmt_List
;
2667 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
2668 while Present
(Iface_Elmt
) loop
2669 Iface
:= Node
(Iface_Elmt
);
2671 -- Associate the primary tag component and the primary dispatch table
2672 -- with all the interfaces that are parents of T
2674 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
2675 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
2676 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
2678 -- Otherwise search for the tag component and secondary dispatch
2682 Comp_Elmt
:= First_Elmt
(Comps_List
);
2683 while Present
(Comp_Elmt
) loop
2684 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
2686 if Comp_Iface
= Iface
2687 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
2689 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
2690 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
2694 Next_Elmt
(Comp_Elmt
);
2696 pragma Assert
(Present
(Comp_Elmt
));
2699 Next_Elmt
(Iface_Elmt
);
2701 end Collect_Interfaces_Info
;
2703 ---------------------
2704 -- Collect_Parents --
2705 ---------------------
2707 procedure Collect_Parents
2709 List
: out Elist_Id
;
2710 Use_Full_View
: Boolean := True)
2712 Current_Typ
: Entity_Id
:= T
;
2713 Parent_Typ
: Entity_Id
;
2716 List
:= New_Elmt_List
;
2718 -- No action if the if the type has no parents
2720 if T
= Etype
(T
) then
2725 Parent_Typ
:= Etype
(Current_Typ
);
2727 if Is_Private_Type
(Parent_Typ
)
2728 and then Present
(Full_View
(Parent_Typ
))
2729 and then Use_Full_View
2731 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
2734 Append_Elmt
(Parent_Typ
, List
);
2736 exit when Parent_Typ
= Current_Typ
;
2737 Current_Typ
:= Parent_Typ
;
2739 end Collect_Parents
;
2741 ----------------------------------
2742 -- Collect_Primitive_Operations --
2743 ----------------------------------
2745 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
2746 B_Type
: constant Entity_Id
:= Base_Type
(T
);
2747 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
2748 B_Scope
: Entity_Id
:= Scope
(B_Type
);
2752 Is_Type_In_Pkg
: Boolean;
2753 Formal_Derived
: Boolean := False;
2756 function Match
(E
: Entity_Id
) return Boolean;
2757 -- True if E's base type is B_Type, or E is of an anonymous access type
2758 -- and the base type of its designated type is B_Type.
2764 function Match
(E
: Entity_Id
) return Boolean is
2765 Etyp
: Entity_Id
:= Etype
(E
);
2768 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
2769 Etyp
:= Designated_Type
(Etyp
);
2772 return Base_Type
(Etyp
) = B_Type
;
2775 -- Start of processing for Collect_Primitive_Operations
2778 -- For tagged types, the primitive operations are collected as they
2779 -- are declared, and held in an explicit list which is simply returned.
2781 if Is_Tagged_Type
(B_Type
) then
2782 return Primitive_Operations
(B_Type
);
2784 -- An untagged generic type that is a derived type inherits the
2785 -- primitive operations of its parent type. Other formal types only
2786 -- have predefined operators, which are not explicitly represented.
2788 elsif Is_Generic_Type
(B_Type
) then
2789 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
2790 and then Nkind
(Formal_Type_Definition
(B_Decl
))
2791 = N_Formal_Derived_Type_Definition
2793 Formal_Derived
:= True;
2795 return New_Elmt_List
;
2799 Op_List
:= New_Elmt_List
;
2801 if B_Scope
= Standard_Standard
then
2802 if B_Type
= Standard_String
then
2803 Append_Elmt
(Standard_Op_Concat
, Op_List
);
2805 elsif B_Type
= Standard_Wide_String
then
2806 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
2812 -- Locate the primitive subprograms of the type
2815 -- The primitive operations appear after the base type, except
2816 -- if the derivation happens within the private part of B_Scope
2817 -- and the type is a private type, in which case both the type
2818 -- and some primitive operations may appear before the base
2819 -- type, and the list of candidates starts after the type.
2821 if In_Open_Scopes
(B_Scope
)
2822 and then Scope
(T
) = B_Scope
2823 and then In_Private_Part
(B_Scope
)
2825 Id
:= Next_Entity
(T
);
2827 Id
:= Next_Entity
(B_Type
);
2830 -- Set flag if this is a type in a package spec
2833 Is_Package_Or_Generic_Package
(B_Scope
)
2835 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
2838 while Present
(Id
) loop
2840 -- Test whether the result type or any of the parameter types of
2841 -- each subprogram following the type match that type when the
2842 -- type is declared in a package spec, is a derived type, or the
2843 -- subprogram is marked as primitive. (The Is_Primitive test is
2844 -- needed to find primitives of nonderived types in declarative
2845 -- parts that happen to override the predefined "=" operator.)
2847 -- Note that generic formal subprograms are not considered to be
2848 -- primitive operations and thus are never inherited.
2850 if Is_Overloadable
(Id
)
2851 and then (Is_Type_In_Pkg
2852 or else Is_Derived_Type
(B_Type
)
2853 or else Is_Primitive
(Id
))
2854 and then Nkind
(Parent
(Parent
(Id
)))
2855 not in N_Formal_Subprogram_Declaration
2863 Formal
:= First_Formal
(Id
);
2864 while Present
(Formal
) loop
2865 if Match
(Formal
) then
2870 Next_Formal
(Formal
);
2874 -- For a formal derived type, the only primitives are the ones
2875 -- inherited from the parent type. Operations appearing in the
2876 -- package declaration are not primitive for it.
2879 and then (not Formal_Derived
2880 or else Present
(Alias
(Id
)))
2882 -- In the special case of an equality operator aliased to
2883 -- an overriding dispatching equality belonging to the same
2884 -- type, we don't include it in the list of primitives.
2885 -- This avoids inheriting multiple equality operators when
2886 -- deriving from untagged private types whose full type is
2887 -- tagged, which can otherwise cause ambiguities. Note that
2888 -- this should only happen for this kind of untagged parent
2889 -- type, since normally dispatching operations are inherited
2890 -- using the type's Primitive_Operations list.
2892 if Chars
(Id
) = Name_Op_Eq
2893 and then Is_Dispatching_Operation
(Id
)
2894 and then Present
(Alias
(Id
))
2895 and then Present
(Overridden_Operation
(Alias
(Id
)))
2896 and then Base_Type
(Etype
(First_Entity
(Id
))) =
2897 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
2901 -- Include the subprogram in the list of primitives
2904 Append_Elmt
(Id
, Op_List
);
2911 -- For a type declared in System, some of its operations may
2912 -- appear in the target-specific extension to System.
2915 and then B_Scope
= RTU_Entity
(System
)
2916 and then Present_System_Aux
2918 B_Scope
:= System_Aux_Id
;
2919 Id
:= First_Entity
(System_Aux_Id
);
2925 end Collect_Primitive_Operations
;
2927 -----------------------------------
2928 -- Compile_Time_Constraint_Error --
2929 -----------------------------------
2931 function Compile_Time_Constraint_Error
2934 Ent
: Entity_Id
:= Empty
;
2935 Loc
: Source_Ptr
:= No_Location
;
2936 Warn
: Boolean := False) return Node_Id
2938 Msgc
: String (1 .. Msg
'Length + 3);
2939 -- Copy of message, with room for possible ?? and ! at end
2949 -- A static constraint error in an instance body is not a fatal error.
2950 -- we choose to inhibit the message altogether, because there is no
2951 -- obvious node (for now) on which to post it. On the other hand the
2952 -- offending node must be replaced with a constraint_error in any case.
2954 -- No messages are generated if we already posted an error on this node
2956 if not Error_Posted
(N
) then
2957 if Loc
/= No_Location
then
2963 Msgc
(1 .. Msg
'Length) := Msg
;
2966 -- Message is a warning, even in Ada 95 case
2968 if Msg
(Msg
'Last) = '?' then
2971 -- In Ada 83, all messages are warnings. In the private part and
2972 -- the body of an instance, constraint_checks are only warnings.
2973 -- We also make this a warning if the Warn parameter is set.
2976 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
2984 elsif In_Instance_Not_Visible
then
2991 -- Otherwise we have a real error message (Ada 95 static case)
2992 -- and we make this an unconditional message. Note that in the
2993 -- warning case we do not make the message unconditional, it seems
2994 -- quite reasonable to delete messages like this (about exceptions
2995 -- that will be raised) in dead code.
3003 -- Should we generate a warning? The answer is not quite yes. The
3004 -- very annoying exception occurs in the case of a short circuit
3005 -- operator where the left operand is static and decisive. Climb
3006 -- parents to see if that is the case we have here. Conditional
3007 -- expressions with decisive conditions are a similar situation.
3015 -- And then with False as left operand
3017 if Nkind
(P
) = N_And_Then
3018 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3019 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
3024 -- OR ELSE with True as left operand
3026 elsif Nkind
(P
) = N_Or_Else
3027 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3028 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
3035 elsif Nkind
(P
) = N_If_Expression
then
3037 Cond
: constant Node_Id
:= First
(Expressions
(P
));
3038 Texp
: constant Node_Id
:= Next
(Cond
);
3039 Fexp
: constant Node_Id
:= Next
(Texp
);
3042 if Compile_Time_Known_Value
(Cond
) then
3044 -- Condition is True and we are in the right operand
3046 if Is_True
(Expr_Value
(Cond
))
3047 and then OldP
= Fexp
3052 -- Condition is False and we are in the left operand
3054 elsif Is_False
(Expr_Value
(Cond
))
3055 and then OldP
= Texp
3063 -- Special case for component association in aggregates, where
3064 -- we want to keep climbing up to the parent aggregate.
3066 elsif Nkind
(P
) = N_Component_Association
3067 and then Nkind
(Parent
(P
)) = N_Aggregate
3071 -- Keep going if within subexpression
3074 exit when Nkind
(P
) not in N_Subexpr
;
3079 if Present
(Ent
) then
3080 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
3082 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
3087 -- Check whether the context is an Init_Proc
3089 if Inside_Init_Proc
then
3091 Conc_Typ
: constant Entity_Id
:=
3092 Corresponding_Concurrent_Type
3093 (Entity
(Parameter_Type
(First
3094 (Parameter_Specifications
3095 (Parent
(Current_Scope
))))));
3098 -- Don't complain if the corresponding concurrent type
3099 -- doesn't come from source (i.e. a single task/protected
3102 if Present
(Conc_Typ
)
3103 and then not Comes_From_Source
(Conc_Typ
)
3106 ("\??& will be raised at run time",
3107 N
, Standard_Constraint_Error
, Eloc
);
3111 ("\??& will be raised for objects of this type",
3112 N
, Standard_Constraint_Error
, Eloc
);
3118 ("\??& will be raised at run time",
3119 N
, Standard_Constraint_Error
, Eloc
);
3124 ("\static expression fails Constraint_Check", Eloc
);
3125 Set_Error_Posted
(N
);
3131 end Compile_Time_Constraint_Error
;
3133 -----------------------
3134 -- Conditional_Delay --
3135 -----------------------
3137 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
3139 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
3140 Set_Has_Delayed_Freeze
(New_Ent
);
3142 end Conditional_Delay
;
3144 -------------------------
3145 -- Copy_Component_List --
3146 -------------------------
3148 function Copy_Component_List
3150 Loc
: Source_Ptr
) return List_Id
3153 Comps
: constant List_Id
:= New_List
;
3156 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
3157 while Present
(Comp
) loop
3158 if Comes_From_Source
(Comp
) then
3160 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
3163 Make_Component_Declaration
(Loc
,
3164 Defining_Identifier
=>
3165 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
3166 Component_Definition
=>
3168 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
3172 Next_Component
(Comp
);
3176 end Copy_Component_List
;
3178 -------------------------
3179 -- Copy_Parameter_List --
3180 -------------------------
3182 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
3183 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
3188 if No
(First_Formal
(Subp_Id
)) then
3192 Formal
:= First_Formal
(Subp_Id
);
3193 while Present
(Formal
) loop
3195 (Make_Parameter_Specification
(Loc
,
3196 Defining_Identifier
=>
3197 Make_Defining_Identifier
(Sloc
(Formal
),
3198 Chars
=> Chars
(Formal
)),
3199 In_Present
=> In_Present
(Parent
(Formal
)),
3200 Out_Present
=> Out_Present
(Parent
(Formal
)),
3202 New_Reference_To
(Etype
(Formal
), Loc
),
3204 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
3207 Next_Formal
(Formal
);
3212 end Copy_Parameter_List
;
3214 --------------------------------
3215 -- Corresponding_Generic_Type --
3216 --------------------------------
3218 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
3224 if not Is_Generic_Actual_Type
(T
) then
3227 -- If the actual is the actual of an enclosing instance, resolution
3228 -- was correct in the generic.
3230 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
3231 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
3233 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
3240 if Is_Wrapper_Package
(Inst
) then
3241 Inst
:= Related_Instance
(Inst
);
3246 (Specification
(Unit_Declaration_Node
(Inst
)));
3248 -- Generic actual has the same name as the corresponding formal
3250 Typ
:= First_Entity
(Gen
);
3251 while Present
(Typ
) loop
3252 if Chars
(Typ
) = Chars
(T
) then
3261 end Corresponding_Generic_Type
;
3263 --------------------
3264 -- Current_Entity --
3265 --------------------
3267 -- The currently visible definition for a given identifier is the
3268 -- one most chained at the start of the visibility chain, i.e. the
3269 -- one that is referenced by the Node_Id value of the name of the
3270 -- given identifier.
3272 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
3274 return Get_Name_Entity_Id
(Chars
(N
));
3277 -----------------------------
3278 -- Current_Entity_In_Scope --
3279 -----------------------------
3281 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
3283 CS
: constant Entity_Id
:= Current_Scope
;
3285 Transient_Case
: constant Boolean := Scope_Is_Transient
;
3288 E
:= Get_Name_Entity_Id
(Chars
(N
));
3290 and then Scope
(E
) /= CS
3291 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
3297 end Current_Entity_In_Scope
;
3303 function Current_Scope
return Entity_Id
is
3305 if Scope_Stack
.Last
= -1 then
3306 return Standard_Standard
;
3309 C
: constant Entity_Id
:=
3310 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
3315 return Standard_Standard
;
3321 ------------------------
3322 -- Current_Subprogram --
3323 ------------------------
3325 function Current_Subprogram
return Entity_Id
is
3326 Scop
: constant Entity_Id
:= Current_Scope
;
3328 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
3331 return Enclosing_Subprogram
(Scop
);
3333 end Current_Subprogram
;
3335 ----------------------------------
3336 -- Deepest_Type_Access_Level --
3337 ----------------------------------
3339 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
3341 if Ekind
(Typ
) = E_Anonymous_Access_Type
3342 and then not Is_Local_Anonymous_Access
(Typ
)
3343 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
3345 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
3349 Scope_Depth
(Enclosing_Dynamic_Scope
3350 (Defining_Identifier
3351 (Associated_Node_For_Itype
(Typ
))));
3353 -- For generic formal type, return Int'Last (infinite).
3354 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
3356 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
3357 return UI_From_Int
(Int
'Last);
3360 return Type_Access_Level
(Typ
);
3362 end Deepest_Type_Access_Level
;
3364 ---------------------
3365 -- Defining_Entity --
3366 ---------------------
3368 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
3369 K
: constant Node_Kind
:= Nkind
(N
);
3370 Err
: Entity_Id
:= Empty
;
3375 N_Subprogram_Declaration |
3376 N_Abstract_Subprogram_Declaration |
3378 N_Package_Declaration |
3379 N_Subprogram_Renaming_Declaration |
3380 N_Subprogram_Body_Stub |
3381 N_Generic_Subprogram_Declaration |
3382 N_Generic_Package_Declaration |
3383 N_Formal_Subprogram_Declaration |
3384 N_Expression_Function
3386 return Defining_Entity
(Specification
(N
));
3389 N_Component_Declaration |
3390 N_Defining_Program_Unit_Name |
3391 N_Discriminant_Specification |
3393 N_Entry_Declaration |
3394 N_Entry_Index_Specification |
3395 N_Exception_Declaration |
3396 N_Exception_Renaming_Declaration |
3397 N_Formal_Object_Declaration |
3398 N_Formal_Package_Declaration |
3399 N_Formal_Type_Declaration |
3400 N_Full_Type_Declaration |
3401 N_Implicit_Label_Declaration |
3402 N_Incomplete_Type_Declaration |
3403 N_Loop_Parameter_Specification |
3404 N_Number_Declaration |
3405 N_Object_Declaration |
3406 N_Object_Renaming_Declaration |
3407 N_Package_Body_Stub |
3408 N_Parameter_Specification |
3409 N_Private_Extension_Declaration |
3410 N_Private_Type_Declaration |
3412 N_Protected_Body_Stub |
3413 N_Protected_Type_Declaration |
3414 N_Single_Protected_Declaration |
3415 N_Single_Task_Declaration |
3416 N_Subtype_Declaration |
3419 N_Task_Type_Declaration
3421 return Defining_Identifier
(N
);
3424 return Defining_Entity
(Proper_Body
(N
));
3427 N_Function_Instantiation |
3428 N_Function_Specification |
3429 N_Generic_Function_Renaming_Declaration |
3430 N_Generic_Package_Renaming_Declaration |
3431 N_Generic_Procedure_Renaming_Declaration |
3433 N_Package_Instantiation |
3434 N_Package_Renaming_Declaration |
3435 N_Package_Specification |
3436 N_Procedure_Instantiation |
3437 N_Procedure_Specification
3440 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
3443 if Nkind
(Nam
) in N_Entity
then
3446 -- For Error, make up a name and attach to declaration
3447 -- so we can continue semantic analysis
3449 elsif Nam
= Error
then
3450 Err
:= Make_Temporary
(Sloc
(N
), 'T');
3451 Set_Defining_Unit_Name
(N
, Err
);
3454 -- If not an entity, get defining identifier
3457 return Defining_Identifier
(Nam
);
3461 when N_Block_Statement
=>
3462 return Entity
(Identifier
(N
));
3465 raise Program_Error
;
3468 end Defining_Entity
;
3470 --------------------------
3471 -- Denotes_Discriminant --
3472 --------------------------
3474 function Denotes_Discriminant
3476 Check_Concurrent
: Boolean := False) return Boolean
3480 if not Is_Entity_Name
(N
)
3481 or else No
(Entity
(N
))
3488 -- If we are checking for a protected type, the discriminant may have
3489 -- been rewritten as the corresponding discriminal of the original type
3490 -- or of the corresponding concurrent record, depending on whether we
3491 -- are in the spec or body of the protected type.
3493 return Ekind
(E
) = E_Discriminant
3496 and then Ekind
(E
) = E_In_Parameter
3497 and then Present
(Discriminal_Link
(E
))
3499 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
3501 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
3503 end Denotes_Discriminant
;
3505 -------------------------
3506 -- Denotes_Same_Object --
3507 -------------------------
3509 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
3510 Obj1
: Node_Id
:= A1
;
3511 Obj2
: Node_Id
:= A2
;
3513 function Has_Prefix
(N
: Node_Id
) return Boolean;
3514 -- Return True if N has attribute Prefix
3516 function Is_Renaming
(N
: Node_Id
) return Boolean;
3517 -- Return true if N names a renaming entity
3519 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
3520 -- For renamings, return False if the prefix of any dereference within
3521 -- the renamed object_name is a variable, or any expression within the
3522 -- renamed object_name contains references to variables or calls on
3523 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
3529 function Has_Prefix
(N
: Node_Id
) return Boolean is
3533 N_Attribute_Reference
,
3535 N_Explicit_Dereference
,
3536 N_Indexed_Component
,
3538 N_Selected_Component
,
3546 function Is_Renaming
(N
: Node_Id
) return Boolean is
3548 return Is_Entity_Name
(N
)
3549 and then Present
(Renamed_Entity
(Entity
(N
)));
3552 -----------------------
3553 -- Is_Valid_Renaming --
3554 -----------------------
3556 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
3558 function Check_Renaming
(N
: Node_Id
) return Boolean;
3559 -- Recursive function used to traverse all the prefixes of N
3561 function Check_Renaming
(N
: Node_Id
) return Boolean is
3564 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
3569 if Nkind
(N
) = N_Indexed_Component
then
3574 Indx
:= First
(Expressions
(N
));
3575 while Present
(Indx
) loop
3576 if not Is_OK_Static_Expression
(Indx
) then
3585 if Has_Prefix
(N
) then
3587 P
: constant Node_Id
:= Prefix
(N
);
3590 if Nkind
(N
) = N_Explicit_Dereference
3591 and then Is_Variable
(P
)
3595 elsif Is_Entity_Name
(P
)
3596 and then Ekind
(Entity
(P
)) = E_Function
3600 elsif Nkind
(P
) = N_Function_Call
then
3604 -- Recursion to continue traversing the prefix of the
3605 -- renaming expression
3607 return Check_Renaming
(P
);
3614 -- Start of processing for Is_Valid_Renaming
3617 return Check_Renaming
(N
);
3618 end Is_Valid_Renaming
;
3620 -- Start of processing for Denotes_Same_Object
3623 -- Both names statically denote the same stand-alone object or parameter
3624 -- (RM 6.4.1(6.5/3))
3626 if Is_Entity_Name
(Obj1
)
3627 and then Is_Entity_Name
(Obj2
)
3628 and then Entity
(Obj1
) = Entity
(Obj2
)
3633 -- For renamings, the prefix of any dereference within the renamed
3634 -- object_name is not a variable, and any expression within the
3635 -- renamed object_name contains no references to variables nor
3636 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
3638 if Is_Renaming
(Obj1
) then
3639 if Is_Valid_Renaming
(Obj1
) then
3640 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
3646 if Is_Renaming
(Obj2
) then
3647 if Is_Valid_Renaming
(Obj2
) then
3648 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
3654 -- No match if not same node kind (such cases are handled by
3655 -- Denotes_Same_Prefix)
3657 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
3660 -- After handling valid renamings, one of the two names statically
3661 -- denoted a renaming declaration whose renamed object_name is known
3662 -- to denote the same object as the other (RM 6.4.1(6.10/3))
3664 elsif Is_Entity_Name
(Obj1
) then
3665 if Is_Entity_Name
(Obj2
) then
3666 return Entity
(Obj1
) = Entity
(Obj2
);
3671 -- Both names are selected_components, their prefixes are known to
3672 -- denote the same object, and their selector_names denote the same
3673 -- component (RM 6.4.1(6.6/3)
3675 elsif Nkind
(Obj1
) = N_Selected_Component
then
3676 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
3678 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
3680 -- Both names are dereferences and the dereferenced names are known to
3681 -- denote the same object (RM 6.4.1(6.7/3))
3683 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
3684 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
3686 -- Both names are indexed_components, their prefixes are known to denote
3687 -- the same object, and each of the pairs of corresponding index values
3688 -- are either both static expressions with the same static value or both
3689 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
3691 elsif Nkind
(Obj1
) = N_Indexed_Component
then
3692 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
3700 Indx1
:= First
(Expressions
(Obj1
));
3701 Indx2
:= First
(Expressions
(Obj2
));
3702 while Present
(Indx1
) loop
3704 -- Indexes must denote the same static value or same object
3706 if Is_OK_Static_Expression
(Indx1
) then
3707 if not Is_OK_Static_Expression
(Indx2
) then
3710 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
3714 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
3726 -- Both names are slices, their prefixes are known to denote the same
3727 -- object, and the two slices have statically matching index constraints
3728 -- (RM 6.4.1(6.9/3))
3730 elsif Nkind
(Obj1
) = N_Slice
3731 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
3734 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
3737 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
3738 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
3740 -- Check whether bounds are statically identical. There is no
3741 -- attempt to detect partial overlap of slices.
3743 return Denotes_Same_Object
(Lo1
, Lo2
)
3744 and then Denotes_Same_Object
(Hi1
, Hi2
);
3747 -- In the recursion, literals appear as indexes.
3749 elsif Nkind
(Obj1
) = N_Integer_Literal
3750 and then Nkind
(Obj2
) = N_Integer_Literal
3752 return Intval
(Obj1
) = Intval
(Obj2
);
3757 end Denotes_Same_Object
;
3759 -------------------------
3760 -- Denotes_Same_Prefix --
3761 -------------------------
3763 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
3766 if Is_Entity_Name
(A1
) then
3767 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
3768 and then not Is_Access_Type
(Etype
(A1
))
3770 return Denotes_Same_Object
(A1
, Prefix
(A2
))
3771 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
3776 elsif Is_Entity_Name
(A2
) then
3777 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
3779 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
3781 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
3784 Root1
, Root2
: Node_Id
;
3785 Depth1
, Depth2
: Int
:= 0;
3788 Root1
:= Prefix
(A1
);
3789 while not Is_Entity_Name
(Root1
) loop
3791 (Root1
, N_Selected_Component
, N_Indexed_Component
)
3795 Root1
:= Prefix
(Root1
);
3798 Depth1
:= Depth1
+ 1;
3801 Root2
:= Prefix
(A2
);
3802 while not Is_Entity_Name
(Root2
) loop
3804 (Root2
, N_Selected_Component
, N_Indexed_Component
)
3808 Root2
:= Prefix
(Root2
);
3811 Depth2
:= Depth2
+ 1;
3814 -- If both have the same depth and they do not denote the same
3815 -- object, they are disjoint and no warning is needed.
3817 if Depth1
= Depth2
then
3820 elsif Depth1
> Depth2
then
3821 Root1
:= Prefix
(A1
);
3822 for I
in 1 .. Depth1
- Depth2
- 1 loop
3823 Root1
:= Prefix
(Root1
);
3826 return Denotes_Same_Object
(Root1
, A2
);
3829 Root2
:= Prefix
(A2
);
3830 for I
in 1 .. Depth2
- Depth1
- 1 loop
3831 Root2
:= Prefix
(Root2
);
3834 return Denotes_Same_Object
(A1
, Root2
);
3841 end Denotes_Same_Prefix
;
3843 ----------------------
3844 -- Denotes_Variable --
3845 ----------------------
3847 function Denotes_Variable
(N
: Node_Id
) return Boolean is
3849 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
3850 end Denotes_Variable
;
3852 -----------------------------
3853 -- Depends_On_Discriminant --
3854 -----------------------------
3856 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
3861 Get_Index_Bounds
(N
, L
, H
);
3862 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
3863 end Depends_On_Discriminant
;
3865 -------------------------
3866 -- Designate_Same_Unit --
3867 -------------------------
3869 function Designate_Same_Unit
3871 Name2
: Node_Id
) return Boolean
3873 K1
: constant Node_Kind
:= Nkind
(Name1
);
3874 K2
: constant Node_Kind
:= Nkind
(Name2
);
3876 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
3877 -- Returns the parent unit name node of a defining program unit name
3878 -- or the prefix if N is a selected component or an expanded name.
3880 function Select_Node
(N
: Node_Id
) return Node_Id
;
3881 -- Returns the defining identifier node of a defining program unit
3882 -- name or the selector node if N is a selected component or an
3889 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
3891 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
3903 function Select_Node
(N
: Node_Id
) return Node_Id
is
3905 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
3906 return Defining_Identifier
(N
);
3909 return Selector_Name
(N
);
3913 -- Start of processing for Designate_Next_Unit
3916 if (K1
= N_Identifier
or else
3917 K1
= N_Defining_Identifier
)
3919 (K2
= N_Identifier
or else
3920 K2
= N_Defining_Identifier
)
3922 return Chars
(Name1
) = Chars
(Name2
);
3925 (K1
= N_Expanded_Name
or else
3926 K1
= N_Selected_Component
or else
3927 K1
= N_Defining_Program_Unit_Name
)
3929 (K2
= N_Expanded_Name
or else
3930 K2
= N_Selected_Component
or else
3931 K2
= N_Defining_Program_Unit_Name
)
3934 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
3936 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
3941 end Designate_Same_Unit
;
3943 ------------------------------------------
3944 -- function Dynamic_Accessibility_Level --
3945 ------------------------------------------
3947 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
3949 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
3951 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
3952 -- Construct an integer literal representing an accessibility level
3953 -- with its type set to Natural.
3955 ------------------------
3956 -- Make_Level_Literal --
3957 ------------------------
3959 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
3960 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
3962 Set_Etype
(Result
, Standard_Natural
);
3964 end Make_Level_Literal
;
3966 -- Start of processing for Dynamic_Accessibility_Level
3969 if Is_Entity_Name
(Expr
) then
3972 if Present
(Renamed_Object
(E
)) then
3973 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
3976 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
3977 if Present
(Extra_Accessibility
(E
)) then
3978 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
3983 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
3985 case Nkind
(Expr
) is
3987 -- For access discriminant, the level of the enclosing object
3989 when N_Selected_Component
=>
3990 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
3991 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
3992 E_Anonymous_Access_Type
3994 return Make_Level_Literal
(Object_Access_Level
(Expr
));
3997 when N_Attribute_Reference
=>
3998 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
4000 -- For X'Access, the level of the prefix X
4002 when Attribute_Access
=>
4003 return Make_Level_Literal
4004 (Object_Access_Level
(Prefix
(Expr
)));
4006 -- Treat the unchecked attributes as library-level
4008 when Attribute_Unchecked_Access |
4009 Attribute_Unrestricted_Access
=>
4010 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
4012 -- No other access-valued attributes
4015 raise Program_Error
;
4020 -- Unimplemented: depends on context. As an actual parameter where
4021 -- formal type is anonymous, use
4022 -- Scope_Depth (Current_Scope) + 1.
4023 -- For other cases, see 3.10.2(14/3) and following. ???
4027 when N_Type_Conversion
=>
4028 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
4030 -- Handle type conversions introduced for a rename of an
4031 -- Ada 2012 stand-alone object of an anonymous access type.
4033 return Dynamic_Accessibility_Level
(Expression
(Expr
));
4040 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
4041 end Dynamic_Accessibility_Level
;
4043 -----------------------------------
4044 -- Effective_Extra_Accessibility --
4045 -----------------------------------
4047 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
4049 if Present
(Renamed_Object
(Id
))
4050 and then Is_Entity_Name
(Renamed_Object
(Id
))
4052 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
4054 return Extra_Accessibility
(Id
);
4056 end Effective_Extra_Accessibility
;
4058 ------------------------------
4059 -- Enclosing_Comp_Unit_Node --
4060 ------------------------------
4062 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
4063 Current_Node
: Node_Id
;
4067 while Present
(Current_Node
)
4068 and then Nkind
(Current_Node
) /= N_Compilation_Unit
4070 Current_Node
:= Parent
(Current_Node
);
4073 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
4076 return Current_Node
;
4078 end Enclosing_Comp_Unit_Node
;
4080 --------------------------
4081 -- Enclosing_CPP_Parent --
4082 --------------------------
4084 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
4085 Parent_Typ
: Entity_Id
:= Typ
;
4088 while not Is_CPP_Class
(Parent_Typ
)
4089 and then Etype
(Parent_Typ
) /= Parent_Typ
4091 Parent_Typ
:= Etype
(Parent_Typ
);
4093 if Is_Private_Type
(Parent_Typ
) then
4094 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4098 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
4100 end Enclosing_CPP_Parent
;
4102 ----------------------------
4103 -- Enclosing_Generic_Body --
4104 ----------------------------
4106 function Enclosing_Generic_Body
4107 (N
: Node_Id
) return Node_Id
4115 while Present
(P
) loop
4116 if Nkind
(P
) = N_Package_Body
4117 or else Nkind
(P
) = N_Subprogram_Body
4119 Spec
:= Corresponding_Spec
(P
);
4121 if Present
(Spec
) then
4122 Decl
:= Unit_Declaration_Node
(Spec
);
4124 if Nkind
(Decl
) = N_Generic_Package_Declaration
4125 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4136 end Enclosing_Generic_Body
;
4138 ----------------------------
4139 -- Enclosing_Generic_Unit --
4140 ----------------------------
4142 function Enclosing_Generic_Unit
4143 (N
: Node_Id
) return Node_Id
4151 while Present
(P
) loop
4152 if Nkind
(P
) = N_Generic_Package_Declaration
4153 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
4157 elsif Nkind
(P
) = N_Package_Body
4158 or else Nkind
(P
) = N_Subprogram_Body
4160 Spec
:= Corresponding_Spec
(P
);
4162 if Present
(Spec
) then
4163 Decl
:= Unit_Declaration_Node
(Spec
);
4165 if Nkind
(Decl
) = N_Generic_Package_Declaration
4166 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4177 end Enclosing_Generic_Unit
;
4179 -------------------------------
4180 -- Enclosing_Lib_Unit_Entity --
4181 -------------------------------
4183 function Enclosing_Lib_Unit_Entity
4184 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
4186 Unit_Entity
: Entity_Id
;
4189 -- Look for enclosing library unit entity by following scope links.
4190 -- Equivalent to, but faster than indexing through the scope stack.
4193 while (Present
(Scope
(Unit_Entity
))
4194 and then Scope
(Unit_Entity
) /= Standard_Standard
)
4195 and not Is_Child_Unit
(Unit_Entity
)
4197 Unit_Entity
:= Scope
(Unit_Entity
);
4201 end Enclosing_Lib_Unit_Entity
;
4203 -----------------------
4204 -- Enclosing_Package --
4205 -----------------------
4207 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
4208 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4211 if Dynamic_Scope
= Standard_Standard
then
4212 return Standard_Standard
;
4214 elsif Dynamic_Scope
= Empty
then
4217 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
4220 return Dynamic_Scope
;
4223 return Enclosing_Package
(Dynamic_Scope
);
4225 end Enclosing_Package
;
4227 --------------------------
4228 -- Enclosing_Subprogram --
4229 --------------------------
4231 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
4232 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4235 if Dynamic_Scope
= Standard_Standard
then
4238 elsif Dynamic_Scope
= Empty
then
4241 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
4242 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
4244 elsif Ekind
(Dynamic_Scope
) = E_Block
4245 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
4247 return Enclosing_Subprogram
(Dynamic_Scope
);
4249 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
4250 return Get_Task_Body_Procedure
(Dynamic_Scope
);
4252 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
4253 and then Present
(Full_View
(Dynamic_Scope
))
4254 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
4256 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
4258 -- No body is generated if the protected operation is eliminated
4260 elsif Convention
(Dynamic_Scope
) = Convention_Protected
4261 and then not Is_Eliminated
(Dynamic_Scope
)
4262 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
4264 return Protected_Body_Subprogram
(Dynamic_Scope
);
4267 return Dynamic_Scope
;
4269 end Enclosing_Subprogram
;
4271 ------------------------
4272 -- Ensure_Freeze_Node --
4273 ------------------------
4275 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
4279 if No
(Freeze_Node
(E
)) then
4280 FN
:= Make_Freeze_Entity
(Sloc
(E
));
4281 Set_Has_Delayed_Freeze
(E
);
4282 Set_Freeze_Node
(E
, FN
);
4283 Set_Access_Types_To_Process
(FN
, No_Elist
);
4284 Set_TSS_Elist
(FN
, No_Elist
);
4287 end Ensure_Freeze_Node
;
4293 procedure Enter_Name
(Def_Id
: Entity_Id
) is
4294 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
4295 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
4296 S
: constant Entity_Id
:= Current_Scope
;
4299 Generate_Definition
(Def_Id
);
4301 -- Add new name to current scope declarations. Check for duplicate
4302 -- declaration, which may or may not be a genuine error.
4306 -- Case of previous entity entered because of a missing declaration
4307 -- or else a bad subtype indication. Best is to use the new entity,
4308 -- and make the previous one invisible.
4310 if Etype
(E
) = Any_Type
then
4311 Set_Is_Immediately_Visible
(E
, False);
4313 -- Case of renaming declaration constructed for package instances.
4314 -- if there is an explicit declaration with the same identifier,
4315 -- the renaming is not immediately visible any longer, but remains
4316 -- visible through selected component notation.
4318 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
4319 and then not Comes_From_Source
(E
)
4321 Set_Is_Immediately_Visible
(E
, False);
4323 -- The new entity may be the package renaming, which has the same
4324 -- same name as a generic formal which has been seen already.
4326 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
4327 and then not Comes_From_Source
(Def_Id
)
4329 Set_Is_Immediately_Visible
(E
, False);
4331 -- For a fat pointer corresponding to a remote access to subprogram,
4332 -- we use the same identifier as the RAS type, so that the proper
4333 -- name appears in the stub. This type is only retrieved through
4334 -- the RAS type and never by visibility, and is not added to the
4335 -- visibility list (see below).
4337 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
4338 and then Present
(Corresponding_Remote_Type
(Def_Id
))
4342 -- Case of an implicit operation or derived literal. The new entity
4343 -- hides the implicit one, which is removed from all visibility,
4344 -- i.e. the entity list of its scope, and homonym chain of its name.
4346 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
4347 or else Is_Internal
(E
)
4351 Prev_Vis
: Entity_Id
;
4352 Decl
: constant Node_Id
:= Parent
(E
);
4355 -- If E is an implicit declaration, it cannot be the first
4356 -- entity in the scope.
4358 Prev
:= First_Entity
(Current_Scope
);
4359 while Present
(Prev
)
4360 and then Next_Entity
(Prev
) /= E
4367 -- If E is not on the entity chain of the current scope,
4368 -- it is an implicit declaration in the generic formal
4369 -- part of a generic subprogram. When analyzing the body,
4370 -- the generic formals are visible but not on the entity
4371 -- chain of the subprogram. The new entity will become
4372 -- the visible one in the body.
4375 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
4379 Set_Next_Entity
(Prev
, Next_Entity
(E
));
4381 if No
(Next_Entity
(Prev
)) then
4382 Set_Last_Entity
(Current_Scope
, Prev
);
4385 if E
= Current_Entity
(E
) then
4389 Prev_Vis
:= Current_Entity
(E
);
4390 while Homonym
(Prev_Vis
) /= E
loop
4391 Prev_Vis
:= Homonym
(Prev_Vis
);
4395 if Present
(Prev_Vis
) then
4397 -- Skip E in the visibility chain
4399 Set_Homonym
(Prev_Vis
, Homonym
(E
));
4402 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
4407 -- This section of code could use a comment ???
4409 elsif Present
(Etype
(E
))
4410 and then Is_Concurrent_Type
(Etype
(E
))
4415 -- If the homograph is a protected component renaming, it should not
4416 -- be hiding the current entity. Such renamings are treated as weak
4419 elsif Is_Prival
(E
) then
4420 Set_Is_Immediately_Visible
(E
, False);
4422 -- In this case the current entity is a protected component renaming.
4423 -- Perform minimal decoration by setting the scope and return since
4424 -- the prival should not be hiding other visible entities.
4426 elsif Is_Prival
(Def_Id
) then
4427 Set_Scope
(Def_Id
, Current_Scope
);
4430 -- Analogous to privals, the discriminal generated for an entry index
4431 -- parameter acts as a weak declaration. Perform minimal decoration
4432 -- to avoid bogus errors.
4434 elsif Is_Discriminal
(Def_Id
)
4435 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
4437 Set_Scope
(Def_Id
, Current_Scope
);
4440 -- In the body or private part of an instance, a type extension may
4441 -- introduce a component with the same name as that of an actual. The
4442 -- legality rule is not enforced, but the semantics of the full type
4443 -- with two components of same name are not clear at this point???
4445 elsif In_Instance_Not_Visible
then
4448 -- When compiling a package body, some child units may have become
4449 -- visible. They cannot conflict with local entities that hide them.
4451 elsif Is_Child_Unit
(E
)
4452 and then In_Open_Scopes
(Scope
(E
))
4453 and then not Is_Immediately_Visible
(E
)
4457 -- Conversely, with front-end inlining we may compile the parent body
4458 -- first, and a child unit subsequently. The context is now the
4459 -- parent spec, and body entities are not visible.
4461 elsif Is_Child_Unit
(Def_Id
)
4462 and then Is_Package_Body_Entity
(E
)
4463 and then not In_Package_Body
(Current_Scope
)
4467 -- Case of genuine duplicate declaration
4470 Error_Msg_Sloc
:= Sloc
(E
);
4472 -- If the previous declaration is an incomplete type declaration
4473 -- this may be an attempt to complete it with a private type. The
4474 -- following avoids confusing cascaded errors.
4476 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
4477 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
4480 ("incomplete type cannot be completed with a private " &
4481 "declaration", Parent
(Def_Id
));
4482 Set_Is_Immediately_Visible
(E
, False);
4483 Set_Full_View
(E
, Def_Id
);
4485 -- An inherited component of a record conflicts with a new
4486 -- discriminant. The discriminant is inserted first in the scope,
4487 -- but the error should be posted on it, not on the component.
4489 elsif Ekind
(E
) = E_Discriminant
4490 and then Present
(Scope
(Def_Id
))
4491 and then Scope
(Def_Id
) /= Current_Scope
4493 Error_Msg_Sloc
:= Sloc
(Def_Id
);
4494 Error_Msg_N
("& conflicts with declaration#", E
);
4497 -- If the name of the unit appears in its own context clause, a
4498 -- dummy package with the name has already been created, and the
4499 -- error emitted. Try to continue quietly.
4501 elsif Error_Posted
(E
)
4502 and then Sloc
(E
) = No_Location
4503 and then Nkind
(Parent
(E
)) = N_Package_Specification
4504 and then Current_Scope
= Standard_Standard
4506 Set_Scope
(Def_Id
, Current_Scope
);
4510 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
4512 -- Avoid cascaded messages with duplicate components in
4515 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
4520 if Nkind
(Parent
(Parent
(Def_Id
))) =
4521 N_Generic_Subprogram_Declaration
4523 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
4525 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
4528 -- If entity is in standard, then we are in trouble, because it
4529 -- means that we have a library package with a duplicated name.
4530 -- That's hard to recover from, so abort!
4532 if S
= Standard_Standard
then
4533 raise Unrecoverable_Error
;
4535 -- Otherwise we continue with the declaration. Having two
4536 -- identical declarations should not cause us too much trouble!
4544 -- If we fall through, declaration is OK, at least OK enough to continue
4546 -- If Def_Id is a discriminant or a record component we are in the midst
4547 -- of inheriting components in a derived record definition. Preserve
4548 -- their Ekind and Etype.
4550 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
4553 -- If a type is already set, leave it alone (happens when a type
4554 -- declaration is reanalyzed following a call to the optimizer).
4556 elsif Present
(Etype
(Def_Id
)) then
4559 -- Otherwise, the kind E_Void insures that premature uses of the entity
4560 -- will be detected. Any_Type insures that no cascaded errors will occur
4563 Set_Ekind
(Def_Id
, E_Void
);
4564 Set_Etype
(Def_Id
, Any_Type
);
4567 -- Inherited discriminants and components in derived record types are
4568 -- immediately visible. Itypes are not.
4570 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
4571 or else (No
(Corresponding_Remote_Type
(Def_Id
))
4572 and then not Is_Itype
(Def_Id
))
4574 Set_Is_Immediately_Visible
(Def_Id
);
4575 Set_Current_Entity
(Def_Id
);
4578 Set_Homonym
(Def_Id
, C
);
4579 Append_Entity
(Def_Id
, S
);
4580 Set_Public_Status
(Def_Id
);
4582 -- Declaring a homonym is not allowed in SPARK ...
4585 and then Restriction_Check_Required
(SPARK_05
)
4588 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
4589 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
4590 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
4593 -- ... unless the new declaration is in a subprogram, and the
4594 -- visible declaration is a variable declaration or a parameter
4595 -- specification outside that subprogram.
4597 if Present
(Enclosing_Subp
)
4598 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
4599 N_Parameter_Specification
)
4600 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
4604 -- ... or the new declaration is in a package, and the visible
4605 -- declaration occurs outside that package.
4607 elsif Present
(Enclosing_Pack
)
4608 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
4612 -- ... or the new declaration is a component declaration in a
4613 -- record type definition.
4615 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
4618 -- Don't issue error for non-source entities
4620 elsif Comes_From_Source
(Def_Id
)
4621 and then Comes_From_Source
(C
)
4623 Error_Msg_Sloc
:= Sloc
(C
);
4624 Check_SPARK_Restriction
4625 ("redeclaration of identifier &#", Def_Id
);
4630 -- Warn if new entity hides an old one
4632 if Warn_On_Hiding
and then Present
(C
)
4634 -- Don't warn for record components since they always have a well
4635 -- defined scope which does not confuse other uses. Note that in
4636 -- some cases, Ekind has not been set yet.
4638 and then Ekind
(C
) /= E_Component
4639 and then Ekind
(C
) /= E_Discriminant
4640 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
4641 and then Ekind
(Def_Id
) /= E_Component
4642 and then Ekind
(Def_Id
) /= E_Discriminant
4643 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
4645 -- Don't warn for one character variables. It is too common to use
4646 -- such variables as locals and will just cause too many false hits.
4648 and then Length_Of_Name
(Chars
(C
)) /= 1
4650 -- Don't warn for non-source entities
4652 and then Comes_From_Source
(C
)
4653 and then Comes_From_Source
(Def_Id
)
4655 -- Don't warn unless entity in question is in extended main source
4657 and then In_Extended_Main_Source_Unit
(Def_Id
)
4659 -- Finally, the hidden entity must be either immediately visible or
4660 -- use visible (i.e. from a used package).
4663 (Is_Immediately_Visible
(C
)
4665 Is_Potentially_Use_Visible
(C
))
4667 Error_Msg_Sloc
:= Sloc
(C
);
4668 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
4672 --------------------------
4673 -- Explain_Limited_Type --
4674 --------------------------
4676 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
4680 -- For array, component type must be limited
4682 if Is_Array_Type
(T
) then
4683 Error_Msg_Node_2
:= T
;
4685 ("\component type& of type& is limited", N
, Component_Type
(T
));
4686 Explain_Limited_Type
(Component_Type
(T
), N
);
4688 elsif Is_Record_Type
(T
) then
4690 -- No need for extra messages if explicit limited record
4692 if Is_Limited_Record
(Base_Type
(T
)) then
4696 -- Otherwise find a limited component. Check only components that
4697 -- come from source, or inherited components that appear in the
4698 -- source of the ancestor.
4700 C
:= First_Component
(T
);
4701 while Present
(C
) loop
4702 if Is_Limited_Type
(Etype
(C
))
4704 (Comes_From_Source
(C
)
4706 (Present
(Original_Record_Component
(C
))
4708 Comes_From_Source
(Original_Record_Component
(C
))))
4710 Error_Msg_Node_2
:= T
;
4711 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
4712 Explain_Limited_Type
(Etype
(C
), N
);
4719 -- The type may be declared explicitly limited, even if no component
4720 -- of it is limited, in which case we fall out of the loop.
4723 end Explain_Limited_Type
;
4729 procedure Find_Actual
4731 Formal
: out Entity_Id
;
4734 Parnt
: constant Node_Id
:= Parent
(N
);
4738 if (Nkind
(Parnt
) = N_Indexed_Component
4740 Nkind
(Parnt
) = N_Selected_Component
)
4741 and then N
= Prefix
(Parnt
)
4743 Find_Actual
(Parnt
, Formal
, Call
);
4746 elsif Nkind
(Parnt
) = N_Parameter_Association
4747 and then N
= Explicit_Actual_Parameter
(Parnt
)
4749 Call
:= Parent
(Parnt
);
4751 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
4760 -- If we have a call to a subprogram look for the parameter. Note that
4761 -- we exclude overloaded calls, since we don't know enough to be sure
4762 -- of giving the right answer in this case.
4764 if Is_Entity_Name
(Name
(Call
))
4765 and then Present
(Entity
(Name
(Call
)))
4766 and then Is_Overloadable
(Entity
(Name
(Call
)))
4767 and then not Is_Overloaded
(Name
(Call
))
4769 -- Fall here if we are definitely a parameter
4771 Actual
:= First_Actual
(Call
);
4772 Formal
:= First_Formal
(Entity
(Name
(Call
)));
4773 while Present
(Formal
) and then Present
(Actual
) loop
4777 Actual
:= Next_Actual
(Actual
);
4778 Formal
:= Next_Formal
(Formal
);
4783 -- Fall through here if we did not find matching actual
4789 ---------------------------
4790 -- Find_Body_Discriminal --
4791 ---------------------------
4793 function Find_Body_Discriminal
4794 (Spec_Discriminant
: Entity_Id
) return Entity_Id
4800 -- If expansion is suppressed, then the scope can be the concurrent type
4801 -- itself rather than a corresponding concurrent record type.
4803 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
4804 Tsk
:= Scope
(Spec_Discriminant
);
4807 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
4809 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
4812 -- Find discriminant of original concurrent type, and use its current
4813 -- discriminal, which is the renaming within the task/protected body.
4815 Disc
:= First_Discriminant
(Tsk
);
4816 while Present
(Disc
) loop
4817 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
4818 return Discriminal
(Disc
);
4821 Next_Discriminant
(Disc
);
4824 -- That loop should always succeed in finding a matching entry and
4825 -- returning. Fatal error if not.
4827 raise Program_Error
;
4828 end Find_Body_Discriminal
;
4830 -------------------------------------
4831 -- Find_Corresponding_Discriminant --
4832 -------------------------------------
4834 function Find_Corresponding_Discriminant
4836 Typ
: Entity_Id
) return Entity_Id
4838 Par_Disc
: Entity_Id
;
4839 Old_Disc
: Entity_Id
;
4840 New_Disc
: Entity_Id
;
4843 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
4845 -- The original type may currently be private, and the discriminant
4846 -- only appear on its full view.
4848 if Is_Private_Type
(Scope
(Par_Disc
))
4849 and then not Has_Discriminants
(Scope
(Par_Disc
))
4850 and then Present
(Full_View
(Scope
(Par_Disc
)))
4852 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
4854 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
4857 if Is_Class_Wide_Type
(Typ
) then
4858 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
4860 New_Disc
:= First_Discriminant
(Typ
);
4863 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
4864 if Old_Disc
= Par_Disc
then
4867 Next_Discriminant
(Old_Disc
);
4868 Next_Discriminant
(New_Disc
);
4872 -- Should always find it
4874 raise Program_Error
;
4875 end Find_Corresponding_Discriminant
;
4877 ------------------------------------
4878 -- Find_Loop_In_Conditional_Block --
4879 ------------------------------------
4881 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
4887 if Nkind
(Stmt
) = N_If_Statement
then
4888 Stmt
:= First
(Then_Statements
(Stmt
));
4891 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
4893 -- Inspect the statements of the conditional block. In general the loop
4894 -- should be the first statement in the statement sequence of the block,
4895 -- but the finalization machinery may have introduced extra object
4898 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
4899 while Present
(Stmt
) loop
4900 if Nkind
(Stmt
) = N_Loop_Statement
then
4907 -- The expansion of attribute 'Loop_Entry produced a malformed block
4909 raise Program_Error
;
4910 end Find_Loop_In_Conditional_Block
;
4912 --------------------------
4913 -- Find_Overlaid_Entity --
4914 --------------------------
4916 procedure Find_Overlaid_Entity
4918 Ent
: out Entity_Id
;
4924 -- We are looking for one of the two following forms:
4926 -- for X'Address use Y'Address
4930 -- Const : constant Address := expr;
4932 -- for X'Address use Const;
4934 -- In the second case, the expr is either Y'Address, or recursively a
4935 -- constant that eventually references Y'Address.
4940 if Nkind
(N
) = N_Attribute_Definition_Clause
4941 and then Chars
(N
) = Name_Address
4943 Expr
:= Expression
(N
);
4945 -- This loop checks the form of the expression for Y'Address,
4946 -- using recursion to deal with intermediate constants.
4949 -- Check for Y'Address
4951 if Nkind
(Expr
) = N_Attribute_Reference
4952 and then Attribute_Name
(Expr
) = Name_Address
4954 Expr
:= Prefix
(Expr
);
4957 -- Check for Const where Const is a constant entity
4959 elsif Is_Entity_Name
(Expr
)
4960 and then Ekind
(Entity
(Expr
)) = E_Constant
4962 Expr
:= Constant_Value
(Entity
(Expr
));
4964 -- Anything else does not need checking
4971 -- This loop checks the form of the prefix for an entity, using
4972 -- recursion to deal with intermediate components.
4975 -- Check for Y where Y is an entity
4977 if Is_Entity_Name
(Expr
) then
4978 Ent
:= Entity
(Expr
);
4981 -- Check for components
4984 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
4986 Expr
:= Prefix
(Expr
);
4989 -- Anything else does not need checking
4996 end Find_Overlaid_Entity
;
4998 -------------------------
4999 -- Find_Parameter_Type --
5000 -------------------------
5002 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
5004 if Nkind
(Param
) /= N_Parameter_Specification
then
5007 -- For an access parameter, obtain the type from the formal entity
5008 -- itself, because access to subprogram nodes do not carry a type.
5009 -- Shouldn't we always use the formal entity ???
5011 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
5012 return Etype
(Defining_Identifier
(Param
));
5015 return Etype
(Parameter_Type
(Param
));
5017 end Find_Parameter_Type
;
5019 -----------------------------
5020 -- Find_Static_Alternative --
5021 -----------------------------
5023 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
5024 Expr
: constant Node_Id
:= Expression
(N
);
5025 Val
: constant Uint
:= Expr_Value
(Expr
);
5030 Alt
:= First
(Alternatives
(N
));
5033 if Nkind
(Alt
) /= N_Pragma
then
5034 Choice
:= First
(Discrete_Choices
(Alt
));
5035 while Present
(Choice
) loop
5037 -- Others choice, always matches
5039 if Nkind
(Choice
) = N_Others_Choice
then
5042 -- Range, check if value is in the range
5044 elsif Nkind
(Choice
) = N_Range
then
5046 Val
>= Expr_Value
(Low_Bound
(Choice
))
5048 Val
<= Expr_Value
(High_Bound
(Choice
));
5050 -- Choice is a subtype name. Note that we know it must
5051 -- be a static subtype, since otherwise it would have
5052 -- been diagnosed as illegal.
5054 elsif Is_Entity_Name
(Choice
)
5055 and then Is_Type
(Entity
(Choice
))
5057 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
5058 Assume_Valid
=> False);
5060 -- Choice is a subtype indication
5062 elsif Nkind
(Choice
) = N_Subtype_Indication
then
5064 C
: constant Node_Id
:= Constraint
(Choice
);
5065 R
: constant Node_Id
:= Range_Expression
(C
);
5069 Val
>= Expr_Value
(Low_Bound
(R
))
5071 Val
<= Expr_Value
(High_Bound
(R
));
5074 -- Choice is a simple expression
5077 exit Search
when Val
= Expr_Value
(Choice
);
5085 pragma Assert
(Present
(Alt
));
5088 -- The above loop *must* terminate by finding a match, since
5089 -- we know the case statement is valid, and the value of the
5090 -- expression is known at compile time. When we fall out of
5091 -- the loop, Alt points to the alternative that we know will
5092 -- be selected at run time.
5095 end Find_Static_Alternative
;
5101 function First_Actual
(Node
: Node_Id
) return Node_Id
is
5105 if No
(Parameter_Associations
(Node
)) then
5109 N
:= First
(Parameter_Associations
(Node
));
5111 if Nkind
(N
) = N_Parameter_Association
then
5112 return First_Named_Actual
(Node
);
5118 -----------------------
5119 -- Gather_Components --
5120 -----------------------
5122 procedure Gather_Components
5124 Comp_List
: Node_Id
;
5125 Governed_By
: List_Id
;
5127 Report_Errors
: out Boolean)
5131 Discrete_Choice
: Node_Id
;
5132 Comp_Item
: Node_Id
;
5134 Discrim
: Entity_Id
;
5135 Discrim_Name
: Node_Id
;
5136 Discrim_Value
: Node_Id
;
5139 Report_Errors
:= False;
5141 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
5144 elsif Present
(Component_Items
(Comp_List
)) then
5145 Comp_Item
:= First
(Component_Items
(Comp_List
));
5151 while Present
(Comp_Item
) loop
5153 -- Skip the tag of a tagged record, the interface tags, as well
5154 -- as all items that are not user components (anonymous types,
5155 -- rep clauses, Parent field, controller field).
5157 if Nkind
(Comp_Item
) = N_Component_Declaration
then
5159 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
5161 if not Is_Tag
(Comp
)
5162 and then Chars
(Comp
) /= Name_uParent
5164 Append_Elmt
(Comp
, Into
);
5172 if No
(Variant_Part
(Comp_List
)) then
5175 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
5176 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
5179 -- Look for the discriminant that governs this variant part.
5180 -- The discriminant *must* be in the Governed_By List
5182 Assoc
:= First
(Governed_By
);
5183 Find_Constraint
: loop
5184 Discrim
:= First
(Choices
(Assoc
));
5185 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
5186 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
5188 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
5189 = Chars
(Discrim_Name
))
5190 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
5191 = Chars
(Discrim_Name
);
5193 if No
(Next
(Assoc
)) then
5194 if not Is_Constrained
(Typ
)
5195 and then Is_Derived_Type
(Typ
)
5196 and then Present
(Stored_Constraint
(Typ
))
5198 -- If the type is a tagged type with inherited discriminants,
5199 -- use the stored constraint on the parent in order to find
5200 -- the values of discriminants that are otherwise hidden by an
5201 -- explicit constraint. Renamed discriminants are handled in
5204 -- If several parent discriminants are renamed by a single
5205 -- discriminant of the derived type, the call to obtain the
5206 -- Corresponding_Discriminant field only retrieves the last
5207 -- of them. We recover the constraint on the others from the
5208 -- Stored_Constraint as well.
5215 D
:= First_Discriminant
(Etype
(Typ
));
5216 C
:= First_Elmt
(Stored_Constraint
(Typ
));
5217 while Present
(D
) and then Present
(C
) loop
5218 if Chars
(Discrim_Name
) = Chars
(D
) then
5219 if Is_Entity_Name
(Node
(C
))
5220 and then Entity
(Node
(C
)) = Entity
(Discrim
)
5222 -- D is renamed by Discrim, whose value is given in
5229 Make_Component_Association
(Sloc
(Typ
),
5231 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
5232 Duplicate_Subexpr_No_Checks
(Node
(C
)));
5234 exit Find_Constraint
;
5237 Next_Discriminant
(D
);
5244 if No
(Next
(Assoc
)) then
5245 Error_Msg_NE
(" missing value for discriminant&",
5246 First
(Governed_By
), Discrim_Name
);
5247 Report_Errors
:= True;
5252 end loop Find_Constraint
;
5254 Discrim_Value
:= Expression
(Assoc
);
5256 if not Is_OK_Static_Expression
(Discrim_Value
) then
5258 ("value for discriminant & must be static!",
5259 Discrim_Value
, Discrim
);
5260 Why_Not_Static
(Discrim_Value
);
5261 Report_Errors
:= True;
5265 Search_For_Discriminant_Value
: declare
5271 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
5274 Find_Discrete_Value
: while Present
(Variant
) loop
5275 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
5276 while Present
(Discrete_Choice
) loop
5278 exit Find_Discrete_Value
when
5279 Nkind
(Discrete_Choice
) = N_Others_Choice
;
5281 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
5283 UI_Low
:= Expr_Value
(Low
);
5284 UI_High
:= Expr_Value
(High
);
5286 exit Find_Discrete_Value
when
5287 UI_Low
<= UI_Discrim_Value
5289 UI_High
>= UI_Discrim_Value
;
5291 Next
(Discrete_Choice
);
5294 Next_Non_Pragma
(Variant
);
5295 end loop Find_Discrete_Value
;
5296 end Search_For_Discriminant_Value
;
5298 if No
(Variant
) then
5300 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
5301 Report_Errors
:= True;
5305 -- If we have found the corresponding choice, recursively add its
5306 -- components to the Into list.
5308 Gather_Components
(Empty
,
5309 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
5310 end Gather_Components
;
5312 ------------------------
5313 -- Get_Actual_Subtype --
5314 ------------------------
5316 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
5317 Typ
: constant Entity_Id
:= Etype
(N
);
5318 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
5327 -- If what we have is an identifier that references a subprogram
5328 -- formal, or a variable or constant object, then we get the actual
5329 -- subtype from the referenced entity if one has been built.
5331 if Nkind
(N
) = N_Identifier
5333 (Is_Formal
(Entity
(N
))
5334 or else Ekind
(Entity
(N
)) = E_Constant
5335 or else Ekind
(Entity
(N
)) = E_Variable
)
5336 and then Present
(Actual_Subtype
(Entity
(N
)))
5338 return Actual_Subtype
(Entity
(N
));
5340 -- Actual subtype of unchecked union is always itself. We never need
5341 -- the "real" actual subtype. If we did, we couldn't get it anyway
5342 -- because the discriminant is not available. The restrictions on
5343 -- Unchecked_Union are designed to make sure that this is OK.
5345 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
5348 -- Here for the unconstrained case, we must find actual subtype
5349 -- No actual subtype is available, so we must build it on the fly.
5351 -- Checking the type, not the underlying type, for constrainedness
5352 -- seems to be necessary. Maybe all the tests should be on the type???
5354 elsif (not Is_Constrained
(Typ
))
5355 and then (Is_Array_Type
(Utyp
)
5356 or else (Is_Record_Type
(Utyp
)
5357 and then Has_Discriminants
(Utyp
)))
5358 and then not Has_Unknown_Discriminants
(Utyp
)
5359 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
5361 -- Nothing to do if in spec expression (why not???)
5363 if In_Spec_Expression
then
5366 elsif Is_Private_Type
(Typ
)
5367 and then not Has_Discriminants
(Typ
)
5369 -- If the type has no discriminants, there is no subtype to
5370 -- build, even if the underlying type is discriminated.
5374 -- Else build the actual subtype
5377 Decl
:= Build_Actual_Subtype
(Typ
, N
);
5378 Atyp
:= Defining_Identifier
(Decl
);
5380 -- If Build_Actual_Subtype generated a new declaration then use it
5384 -- The actual subtype is an Itype, so analyze the declaration,
5385 -- but do not attach it to the tree, to get the type defined.
5387 Set_Parent
(Decl
, N
);
5388 Set_Is_Itype
(Atyp
);
5389 Analyze
(Decl
, Suppress
=> All_Checks
);
5390 Set_Associated_Node_For_Itype
(Atyp
, N
);
5391 Set_Has_Delayed_Freeze
(Atyp
, False);
5393 -- We need to freeze the actual subtype immediately. This is
5394 -- needed, because otherwise this Itype will not get frozen
5395 -- at all, and it is always safe to freeze on creation because
5396 -- any associated types must be frozen at this point.
5398 Freeze_Itype
(Atyp
, N
);
5401 -- Otherwise we did not build a declaration, so return original
5408 -- For all remaining cases, the actual subtype is the same as
5409 -- the nominal type.
5414 end Get_Actual_Subtype
;
5416 -------------------------------------
5417 -- Get_Actual_Subtype_If_Available --
5418 -------------------------------------
5420 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
5421 Typ
: constant Entity_Id
:= Etype
(N
);
5424 -- If what we have is an identifier that references a subprogram
5425 -- formal, or a variable or constant object, then we get the actual
5426 -- subtype from the referenced entity if one has been built.
5428 if Nkind
(N
) = N_Identifier
5430 (Is_Formal
(Entity
(N
))
5431 or else Ekind
(Entity
(N
)) = E_Constant
5432 or else Ekind
(Entity
(N
)) = E_Variable
)
5433 and then Present
(Actual_Subtype
(Entity
(N
)))
5435 return Actual_Subtype
(Entity
(N
));
5437 -- Otherwise the Etype of N is returned unchanged
5442 end Get_Actual_Subtype_If_Available
;
5444 ------------------------
5445 -- Get_Body_From_Stub --
5446 ------------------------
5448 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
5450 return Proper_Body
(Unit
(Library_Unit
(N
)));
5451 end Get_Body_From_Stub
;
5453 -------------------------------
5454 -- Get_Default_External_Name --
5455 -------------------------------
5457 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
5459 Get_Decoded_Name_String
(Chars
(E
));
5461 if Opt
.External_Name_Imp_Casing
= Uppercase
then
5462 Set_Casing
(All_Upper_Case
);
5464 Set_Casing
(All_Lower_Case
);
5468 Make_String_Literal
(Sloc
(E
),
5469 Strval
=> String_From_Name_Buffer
);
5470 end Get_Default_External_Name
;
5472 --------------------------
5473 -- Get_Enclosing_Object --
5474 --------------------------
5476 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
5478 if Is_Entity_Name
(N
) then
5482 when N_Indexed_Component |
5484 N_Selected_Component
=>
5486 -- If not generating code, a dereference may be left implicit.
5487 -- In thoses cases, return Empty.
5489 if Is_Access_Type
(Etype
(Prefix
(N
))) then
5492 return Get_Enclosing_Object
(Prefix
(N
));
5495 when N_Type_Conversion
=>
5496 return Get_Enclosing_Object
(Expression
(N
));
5502 end Get_Enclosing_Object
;
5504 ---------------------------
5505 -- Get_Enum_Lit_From_Pos --
5506 ---------------------------
5508 function Get_Enum_Lit_From_Pos
5511 Loc
: Source_Ptr
) return Node_Id
5513 Btyp
: Entity_Id
:= Base_Type
(T
);
5517 -- In the case where the literal is of type Character, Wide_Character
5518 -- or Wide_Wide_Character or of a type derived from them, there needs
5519 -- to be some special handling since there is no explicit chain of
5520 -- literals to search. Instead, an N_Character_Literal node is created
5521 -- with the appropriate Char_Code and Chars fields.
5523 if Is_Standard_Character_Type
(T
) then
5524 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
5526 Make_Character_Literal
(Loc
,
5528 Char_Literal_Value
=> Pos
);
5530 -- For all other cases, we have a complete table of literals, and
5531 -- we simply iterate through the chain of literal until the one
5532 -- with the desired position value is found.
5536 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
5537 Btyp
:= Full_View
(Btyp
);
5540 Lit
:= First_Literal
(Btyp
);
5541 for J
in 1 .. UI_To_Int
(Pos
) loop
5545 return New_Occurrence_Of
(Lit
, Loc
);
5547 end Get_Enum_Lit_From_Pos
;
5549 ---------------------------------
5550 -- Get_Ensures_From_CTC_Pragma --
5551 ---------------------------------
5553 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
5554 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
5558 if List_Length
(Args
) = 4 then
5559 Res
:= Pick
(Args
, 4);
5561 elsif List_Length
(Args
) = 3 then
5562 Res
:= Pick
(Args
, 3);
5564 if Chars
(Res
) /= Name_Ensures
then
5573 end Get_Ensures_From_CTC_Pragma
;
5575 ------------------------
5576 -- Get_Generic_Entity --
5577 ------------------------
5579 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
5580 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
5582 if Present
(Renamed_Object
(Ent
)) then
5583 return Renamed_Object
(Ent
);
5587 end Get_Generic_Entity
;
5589 -------------------------------------
5590 -- Get_Incomplete_View_Of_Ancestor --
5591 -------------------------------------
5593 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
5594 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
5595 Par_Scope
: Entity_Id
;
5596 Par_Type
: Entity_Id
;
5599 -- The incomplete view of an ancestor is only relevant for private
5600 -- derived types in child units.
5602 if not Is_Derived_Type
(E
)
5603 or else not Is_Child_Unit
(Cur_Unit
)
5608 Par_Scope
:= Scope
(Cur_Unit
);
5609 if No
(Par_Scope
) then
5613 Par_Type
:= Etype
(Base_Type
(E
));
5615 -- Traverse list of ancestor types until we find one declared in
5616 -- a parent or grandparent unit (two levels seem sufficient).
5618 while Present
(Par_Type
) loop
5619 if Scope
(Par_Type
) = Par_Scope
5620 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
5624 elsif not Is_Derived_Type
(Par_Type
) then
5628 Par_Type
:= Etype
(Base_Type
(Par_Type
));
5632 -- If none found, there is no relevant ancestor type.
5636 end Get_Incomplete_View_Of_Ancestor
;
5638 ----------------------
5639 -- Get_Index_Bounds --
5640 ----------------------
5642 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
5643 Kind
: constant Node_Kind
:= Nkind
(N
);
5647 if Kind
= N_Range
then
5649 H
:= High_Bound
(N
);
5651 elsif Kind
= N_Subtype_Indication
then
5652 R
:= Range_Expression
(Constraint
(N
));
5660 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
5661 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
5664 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
5665 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
5669 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
5670 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
5673 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
5674 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
5678 -- N is an expression, indicating a range with one value
5683 end Get_Index_Bounds
;
5685 ----------------------------------
5686 -- Get_Library_Unit_Name_string --
5687 ----------------------------------
5689 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
5690 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
5693 Get_Unit_Name_String
(Unit_Name_Id
);
5695 -- Remove seven last character (" (spec)" or " (body)")
5697 Name_Len
:= Name_Len
- 7;
5698 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
5699 end Get_Library_Unit_Name_String
;
5701 ------------------------
5702 -- Get_Name_Entity_Id --
5703 ------------------------
5705 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
5707 return Entity_Id
(Get_Name_Table_Info
(Id
));
5708 end Get_Name_Entity_Id
;
5710 ------------------------------
5711 -- Get_Name_From_CTC_Pragma --
5712 ------------------------------
5714 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
5715 Arg
: constant Node_Id
:=
5716 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
5718 return Strval
(Expr_Value_S
(Arg
));
5719 end Get_Name_From_CTC_Pragma
;
5725 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
5727 return Get_Pragma_Id
(Pragma_Name
(N
));
5730 ---------------------------
5731 -- Get_Referenced_Object --
5732 ---------------------------
5734 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
5739 while Is_Entity_Name
(R
)
5740 and then Present
(Renamed_Object
(Entity
(R
)))
5742 R
:= Renamed_Object
(Entity
(R
));
5746 end Get_Referenced_Object
;
5748 ------------------------
5749 -- Get_Renamed_Entity --
5750 ------------------------
5752 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
5757 while Present
(Renamed_Entity
(R
)) loop
5758 R
:= Renamed_Entity
(R
);
5762 end Get_Renamed_Entity
;
5764 ----------------------------------
5765 -- Get_Requires_From_CTC_Pragma --
5766 ----------------------------------
5768 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
5769 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
5773 if List_Length
(Args
) >= 3 then
5774 Res
:= Pick
(Args
, 3);
5776 if Chars
(Res
) /= Name_Requires
then
5785 end Get_Requires_From_CTC_Pragma
;
5787 -------------------------
5788 -- Get_Subprogram_Body --
5789 -------------------------
5791 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
5795 Decl
:= Unit_Declaration_Node
(E
);
5797 if Nkind
(Decl
) = N_Subprogram_Body
then
5800 -- The below comment is bad, because it is possible for
5801 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
5803 else -- Nkind (Decl) = N_Subprogram_Declaration
5805 if Present
(Corresponding_Body
(Decl
)) then
5806 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
5808 -- Imported subprogram case
5814 end Get_Subprogram_Body
;
5816 ---------------------------
5817 -- Get_Subprogram_Entity --
5818 ---------------------------
5820 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
5822 Subp_Id
: Entity_Id
;
5825 if Nkind
(Nod
) = N_Accept_Statement
then
5826 Subp
:= Entry_Direct_Name
(Nod
);
5828 elsif Nkind
(Nod
) = N_Slice
then
5829 Subp
:= Prefix
(Nod
);
5835 -- Strip the subprogram call
5838 if Nkind_In
(Subp
, N_Explicit_Dereference
,
5839 N_Indexed_Component
,
5840 N_Selected_Component
)
5842 Subp
:= Prefix
(Subp
);
5844 elsif Nkind_In
(Subp
, N_Type_Conversion
,
5845 N_Unchecked_Type_Conversion
)
5847 Subp
:= Expression
(Subp
);
5854 -- Extract the entity of the subprogram call
5856 if Is_Entity_Name
(Subp
) then
5857 Subp_Id
:= Entity
(Subp
);
5859 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
5860 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
5863 if Is_Subprogram
(Subp_Id
) then
5869 -- The search did not find a construct that denotes a subprogram
5874 end Get_Subprogram_Entity
;
5876 -----------------------------
5877 -- Get_Task_Body_Procedure --
5878 -----------------------------
5880 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
5882 -- Note: A task type may be the completion of a private type with
5883 -- discriminants. When performing elaboration checks on a task
5884 -- declaration, the current view of the type may be the private one,
5885 -- and the procedure that holds the body of the task is held in its
5888 -- This is an odd function, why not have Task_Body_Procedure do
5889 -- the following digging???
5891 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
5892 end Get_Task_Body_Procedure
;
5894 -----------------------
5895 -- Has_Access_Values --
5896 -----------------------
5898 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
5899 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
5902 -- Case of a private type which is not completed yet. This can only
5903 -- happen in the case of a generic format type appearing directly, or
5904 -- as a component of the type to which this function is being applied
5905 -- at the top level. Return False in this case, since we certainly do
5906 -- not know that the type contains access types.
5911 elsif Is_Access_Type
(Typ
) then
5914 elsif Is_Array_Type
(Typ
) then
5915 return Has_Access_Values
(Component_Type
(Typ
));
5917 elsif Is_Record_Type
(Typ
) then
5922 -- Loop to Check components
5924 Comp
:= First_Component_Or_Discriminant
(Typ
);
5925 while Present
(Comp
) loop
5927 -- Check for access component, tag field does not count, even
5928 -- though it is implemented internally using an access type.
5930 if Has_Access_Values
(Etype
(Comp
))
5931 and then Chars
(Comp
) /= Name_uTag
5936 Next_Component_Or_Discriminant
(Comp
);
5945 end Has_Access_Values
;
5947 ------------------------------
5948 -- Has_Compatible_Alignment --
5949 ------------------------------
5951 function Has_Compatible_Alignment
5953 Expr
: Node_Id
) return Alignment_Result
5955 function Has_Compatible_Alignment_Internal
5958 Default
: Alignment_Result
) return Alignment_Result
;
5959 -- This is the internal recursive function that actually does the work.
5960 -- There is one additional parameter, which says what the result should
5961 -- be if no alignment information is found, and there is no definite
5962 -- indication of compatible alignments. At the outer level, this is set
5963 -- to Unknown, but for internal recursive calls in the case where types
5964 -- are known to be correct, it is set to Known_Compatible.
5966 ---------------------------------------
5967 -- Has_Compatible_Alignment_Internal --
5968 ---------------------------------------
5970 function Has_Compatible_Alignment_Internal
5973 Default
: Alignment_Result
) return Alignment_Result
5975 Result
: Alignment_Result
:= Known_Compatible
;
5976 -- Holds the current status of the result. Note that once a value of
5977 -- Known_Incompatible is set, it is sticky and does not get changed
5978 -- to Unknown (the value in Result only gets worse as we go along,
5981 Offs
: Uint
:= No_Uint
;
5982 -- Set to a factor of the offset from the base object when Expr is a
5983 -- selected or indexed component, based on Component_Bit_Offset and
5984 -- Component_Size respectively. A negative value is used to represent
5985 -- a value which is not known at compile time.
5987 procedure Check_Prefix
;
5988 -- Checks the prefix recursively in the case where the expression
5989 -- is an indexed or selected component.
5991 procedure Set_Result
(R
: Alignment_Result
);
5992 -- If R represents a worse outcome (unknown instead of known
5993 -- compatible, or known incompatible), then set Result to R.
5999 procedure Check_Prefix
is
6001 -- The subtlety here is that in doing a recursive call to check
6002 -- the prefix, we have to decide what to do in the case where we
6003 -- don't find any specific indication of an alignment problem.
6005 -- At the outer level, we normally set Unknown as the result in
6006 -- this case, since we can only set Known_Compatible if we really
6007 -- know that the alignment value is OK, but for the recursive
6008 -- call, in the case where the types match, and we have not
6009 -- specified a peculiar alignment for the object, we are only
6010 -- concerned about suspicious rep clauses, the default case does
6011 -- not affect us, since the compiler will, in the absence of such
6012 -- rep clauses, ensure that the alignment is correct.
6014 if Default
= Known_Compatible
6016 (Etype
(Obj
) = Etype
(Expr
)
6017 and then (Unknown_Alignment
(Obj
)
6019 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
6022 (Has_Compatible_Alignment_Internal
6023 (Obj
, Prefix
(Expr
), Known_Compatible
));
6025 -- In all other cases, we need a full check on the prefix
6029 (Has_Compatible_Alignment_Internal
6030 (Obj
, Prefix
(Expr
), Unknown
));
6038 procedure Set_Result
(R
: Alignment_Result
) is
6045 -- Start of processing for Has_Compatible_Alignment_Internal
6048 -- If Expr is a selected component, we must make sure there is no
6049 -- potentially troublesome component clause, and that the record is
6052 if Nkind
(Expr
) = N_Selected_Component
then
6054 -- Packed record always generate unknown alignment
6056 if Is_Packed
(Etype
(Prefix
(Expr
))) then
6057 Set_Result
(Unknown
);
6060 -- Check prefix and component offset
6063 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
6065 -- If Expr is an indexed component, we must make sure there is no
6066 -- potentially troublesome Component_Size clause and that the array
6067 -- is not bit-packed.
6069 elsif Nkind
(Expr
) = N_Indexed_Component
then
6071 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
6072 Ind
: constant Node_Id
:= First_Index
(Typ
);
6075 -- Bit packed array always generates unknown alignment
6077 if Is_Bit_Packed_Array
(Typ
) then
6078 Set_Result
(Unknown
);
6081 -- Check prefix and component offset
6084 Offs
:= Component_Size
(Typ
);
6086 -- Small optimization: compute the full offset when possible
6089 and then Offs
> Uint_0
6090 and then Present
(Ind
)
6091 and then Nkind
(Ind
) = N_Range
6092 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
6093 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
6095 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
6096 - Expr_Value
(Low_Bound
((Ind
))));
6101 -- If we have a null offset, the result is entirely determined by
6102 -- the base object and has already been computed recursively.
6104 if Offs
= Uint_0
then
6107 -- Case where we know the alignment of the object
6109 elsif Known_Alignment
(Obj
) then
6111 ObjA
: constant Uint
:= Alignment
(Obj
);
6112 ExpA
: Uint
:= No_Uint
;
6113 SizA
: Uint
:= No_Uint
;
6116 -- If alignment of Obj is 1, then we are always OK
6119 Set_Result
(Known_Compatible
);
6121 -- Alignment of Obj is greater than 1, so we need to check
6124 -- If we have an offset, see if it is compatible
6126 if Offs
/= No_Uint
and Offs
> Uint_0
then
6127 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
6128 Set_Result
(Known_Incompatible
);
6131 -- See if Expr is an object with known alignment
6133 elsif Is_Entity_Name
(Expr
)
6134 and then Known_Alignment
(Entity
(Expr
))
6136 ExpA
:= Alignment
(Entity
(Expr
));
6138 -- Otherwise, we can use the alignment of the type of
6139 -- Expr given that we already checked for
6140 -- discombobulating rep clauses for the cases of indexed
6141 -- and selected components above.
6143 elsif Known_Alignment
(Etype
(Expr
)) then
6144 ExpA
:= Alignment
(Etype
(Expr
));
6146 -- Otherwise the alignment is unknown
6149 Set_Result
(Default
);
6152 -- If we got an alignment, see if it is acceptable
6154 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
6155 Set_Result
(Known_Incompatible
);
6158 -- If Expr is not a piece of a larger object, see if size
6159 -- is given. If so, check that it is not too small for the
6160 -- required alignment.
6162 if Offs
/= No_Uint
then
6165 -- See if Expr is an object with known size
6167 elsif Is_Entity_Name
(Expr
)
6168 and then Known_Static_Esize
(Entity
(Expr
))
6170 SizA
:= Esize
(Entity
(Expr
));
6172 -- Otherwise, we check the object size of the Expr type
6174 elsif Known_Static_Esize
(Etype
(Expr
)) then
6175 SizA
:= Esize
(Etype
(Expr
));
6178 -- If we got a size, see if it is a multiple of the Obj
6179 -- alignment, if not, then the alignment cannot be
6180 -- acceptable, since the size is always a multiple of the
6183 if SizA
/= No_Uint
then
6184 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
6185 Set_Result
(Known_Incompatible
);
6191 -- If we do not know required alignment, any non-zero offset is a
6192 -- potential problem (but certainly may be OK, so result is unknown).
6194 elsif Offs
/= No_Uint
then
6195 Set_Result
(Unknown
);
6197 -- If we can't find the result by direct comparison of alignment
6198 -- values, then there is still one case that we can determine known
6199 -- result, and that is when we can determine that the types are the
6200 -- same, and no alignments are specified. Then we known that the
6201 -- alignments are compatible, even if we don't know the alignment
6202 -- value in the front end.
6204 elsif Etype
(Obj
) = Etype
(Expr
) then
6206 -- Types are the same, but we have to check for possible size
6207 -- and alignments on the Expr object that may make the alignment
6208 -- different, even though the types are the same.
6210 if Is_Entity_Name
(Expr
) then
6212 -- First check alignment of the Expr object. Any alignment less
6213 -- than Maximum_Alignment is worrisome since this is the case
6214 -- where we do not know the alignment of Obj.
6216 if Known_Alignment
(Entity
(Expr
))
6218 UI_To_Int
(Alignment
(Entity
(Expr
))) <
6219 Ttypes
.Maximum_Alignment
6221 Set_Result
(Unknown
);
6223 -- Now check size of Expr object. Any size that is not an
6224 -- even multiple of Maximum_Alignment is also worrisome
6225 -- since it may cause the alignment of the object to be less
6226 -- than the alignment of the type.
6228 elsif Known_Static_Esize
(Entity
(Expr
))
6230 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
6231 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
6234 Set_Result
(Unknown
);
6236 -- Otherwise same type is decisive
6239 Set_Result
(Known_Compatible
);
6243 -- Another case to deal with is when there is an explicit size or
6244 -- alignment clause when the types are not the same. If so, then the
6245 -- result is Unknown. We don't need to do this test if the Default is
6246 -- Unknown, since that result will be set in any case.
6248 elsif Default
/= Unknown
6249 and then (Has_Size_Clause
(Etype
(Expr
))
6251 Has_Alignment_Clause
(Etype
(Expr
)))
6253 Set_Result
(Unknown
);
6255 -- If no indication found, set default
6258 Set_Result
(Default
);
6261 -- Return worst result found
6264 end Has_Compatible_Alignment_Internal
;
6266 -- Start of processing for Has_Compatible_Alignment
6269 -- If Obj has no specified alignment, then set alignment from the type
6270 -- alignment. Perhaps we should always do this, but for sure we should
6271 -- do it when there is an address clause since we can do more if the
6272 -- alignment is known.
6274 if Unknown_Alignment
(Obj
) then
6275 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
6278 -- Now do the internal call that does all the work
6280 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
6281 end Has_Compatible_Alignment
;
6283 ----------------------
6284 -- Has_Declarations --
6285 ----------------------
6287 function Has_Declarations
(N
: Node_Id
) return Boolean is
6289 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
6291 N_Compilation_Unit_Aux
,
6297 N_Package_Specification
);
6298 end Has_Declarations
;
6304 function Has_Denormals
(E
: Entity_Id
) return Boolean is
6306 return Is_Floating_Point_Type
(E
)
6307 and then Denorm_On_Target
6308 and then not Vax_Float
(E
);
6311 -------------------------------------------
6312 -- Has_Discriminant_Dependent_Constraint --
6313 -------------------------------------------
6315 function Has_Discriminant_Dependent_Constraint
6316 (Comp
: Entity_Id
) return Boolean
6318 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
6319 Subt_Indic
: constant Node_Id
:=
6320 Subtype_Indication
(Component_Definition
(Comp_Decl
));
6325 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
6326 Constr
:= Constraint
(Subt_Indic
);
6328 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
6329 Assn
:= First
(Constraints
(Constr
));
6330 while Present
(Assn
) loop
6331 case Nkind
(Assn
) is
6332 when N_Subtype_Indication |
6336 if Depends_On_Discriminant
(Assn
) then
6340 when N_Discriminant_Association
=>
6341 if Depends_On_Discriminant
(Expression
(Assn
)) then
6356 end Has_Discriminant_Dependent_Constraint
;
6358 --------------------
6359 -- Has_Infinities --
6360 --------------------
6362 function Has_Infinities
(E
: Entity_Id
) return Boolean is
6365 Is_Floating_Point_Type
(E
)
6366 and then Nkind
(Scalar_Range
(E
)) = N_Range
6367 and then Includes_Infinities
(Scalar_Range
(E
));
6370 --------------------
6371 -- Has_Interfaces --
6372 --------------------
6374 function Has_Interfaces
6376 Use_Full_View
: Boolean := True) return Boolean
6378 Typ
: Entity_Id
:= Base_Type
(T
);
6381 -- Handle concurrent types
6383 if Is_Concurrent_Type
(Typ
) then
6384 Typ
:= Corresponding_Record_Type
(Typ
);
6387 if not Present
(Typ
)
6388 or else not Is_Record_Type
(Typ
)
6389 or else not Is_Tagged_Type
(Typ
)
6394 -- Handle private types
6397 and then Present
(Full_View
(Typ
))
6399 Typ
:= Full_View
(Typ
);
6402 -- Handle concurrent record types
6404 if Is_Concurrent_Record_Type
(Typ
)
6405 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
6411 if Is_Interface
(Typ
)
6413 (Is_Record_Type
(Typ
)
6414 and then Present
(Interfaces
(Typ
))
6415 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
6420 exit when Etype
(Typ
) = Typ
6422 -- Handle private types
6424 or else (Present
(Full_View
(Etype
(Typ
)))
6425 and then Full_View
(Etype
(Typ
)) = Typ
)
6427 -- Protect the frontend against wrong source with cyclic
6430 or else Etype
(Typ
) = T
;
6432 -- Climb to the ancestor type handling private types
6434 if Present
(Full_View
(Etype
(Typ
))) then
6435 Typ
:= Full_View
(Etype
(Typ
));
6444 ------------------------
6445 -- Has_Null_Exclusion --
6446 ------------------------
6448 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
6451 when N_Access_Definition |
6452 N_Access_Function_Definition |
6453 N_Access_Procedure_Definition |
6454 N_Access_To_Object_Definition |
6456 N_Derived_Type_Definition |
6457 N_Function_Specification |
6458 N_Subtype_Declaration
=>
6459 return Null_Exclusion_Present
(N
);
6461 when N_Component_Definition |
6462 N_Formal_Object_Declaration |
6463 N_Object_Renaming_Declaration
=>
6464 if Present
(Subtype_Mark
(N
)) then
6465 return Null_Exclusion_Present
(N
);
6466 else pragma Assert
(Present
(Access_Definition
(N
)));
6467 return Null_Exclusion_Present
(Access_Definition
(N
));
6470 when N_Discriminant_Specification
=>
6471 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
6472 return Null_Exclusion_Present
(Discriminant_Type
(N
));
6474 return Null_Exclusion_Present
(N
);
6477 when N_Object_Declaration
=>
6478 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
6479 return Null_Exclusion_Present
(Object_Definition
(N
));
6481 return Null_Exclusion_Present
(N
);
6484 when N_Parameter_Specification
=>
6485 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
6486 return Null_Exclusion_Present
(Parameter_Type
(N
));
6488 return Null_Exclusion_Present
(N
);
6495 end Has_Null_Exclusion
;
6497 ------------------------
6498 -- Has_Null_Extension --
6499 ------------------------
6501 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
6502 B
: constant Entity_Id
:= Base_Type
(T
);
6507 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
6508 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
6510 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
6512 if Present
(Ext
) then
6513 if Null_Present
(Ext
) then
6516 Comps
:= Component_List
(Ext
);
6518 -- The null component list is rewritten during analysis to
6519 -- include the parent component. Any other component indicates
6520 -- that the extension was not originally null.
6522 return Null_Present
(Comps
)
6523 or else No
(Next
(First
(Component_Items
(Comps
))));
6532 end Has_Null_Extension
;
6534 -------------------------------
6535 -- Has_Overriding_Initialize --
6536 -------------------------------
6538 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
6539 BT
: constant Entity_Id
:= Base_Type
(T
);
6543 if Is_Controlled
(BT
) then
6544 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
6547 elsif Present
(Primitive_Operations
(BT
)) then
6548 P
:= First_Elmt
(Primitive_Operations
(BT
));
6549 while Present
(P
) loop
6551 Init
: constant Entity_Id
:= Node
(P
);
6552 Formal
: constant Entity_Id
:= First_Formal
(Init
);
6554 if Ekind
(Init
) = E_Procedure
6555 and then Chars
(Init
) = Name_Initialize
6556 and then Comes_From_Source
(Init
)
6557 and then Present
(Formal
)
6558 and then Etype
(Formal
) = BT
6559 and then No
(Next_Formal
(Formal
))
6560 and then (Ada_Version
< Ada_2012
6561 or else not Null_Present
(Parent
(Init
)))
6571 -- Here if type itself does not have a non-null Initialize operation:
6572 -- check immediate ancestor.
6574 if Is_Derived_Type
(BT
)
6575 and then Has_Overriding_Initialize
(Etype
(BT
))
6582 end Has_Overriding_Initialize
;
6584 --------------------------------------
6585 -- Has_Preelaborable_Initialization --
6586 --------------------------------------
6588 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
6591 procedure Check_Components
(E
: Entity_Id
);
6592 -- Check component/discriminant chain, sets Has_PE False if a component
6593 -- or discriminant does not meet the preelaborable initialization rules.
6595 ----------------------
6596 -- Check_Components --
6597 ----------------------
6599 procedure Check_Components
(E
: Entity_Id
) is
6603 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
6604 -- Returns True if and only if the expression denoted by N does not
6605 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
6607 ---------------------------------
6608 -- Is_Preelaborable_Expression --
6609 ---------------------------------
6611 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
6615 Comp_Type
: Entity_Id
;
6616 Is_Array_Aggr
: Boolean;
6619 if Is_Static_Expression
(N
) then
6622 elsif Nkind
(N
) = N_Null
then
6625 -- Attributes are allowed in general, even if their prefix is a
6626 -- formal type. (It seems that certain attributes known not to be
6627 -- static might not be allowed, but there are no rules to prevent
6630 elsif Nkind
(N
) = N_Attribute_Reference
then
6633 -- The name of a discriminant evaluated within its parent type is
6634 -- defined to be preelaborable (10.2.1(8)). Note that we test for
6635 -- names that denote discriminals as well as discriminants to
6636 -- catch references occurring within init procs.
6638 elsif Is_Entity_Name
(N
)
6640 (Ekind
(Entity
(N
)) = E_Discriminant
6642 ((Ekind
(Entity
(N
)) = E_Constant
6643 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
6644 and then Present
(Discriminal_Link
(Entity
(N
)))))
6648 elsif Nkind
(N
) = N_Qualified_Expression
then
6649 return Is_Preelaborable_Expression
(Expression
(N
));
6651 -- For aggregates we have to check that each of the associations
6652 -- is preelaborable.
6654 elsif Nkind
(N
) = N_Aggregate
6655 or else Nkind
(N
) = N_Extension_Aggregate
6657 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
6659 if Is_Array_Aggr
then
6660 Comp_Type
:= Component_Type
(Etype
(N
));
6663 -- Check the ancestor part of extension aggregates, which must
6664 -- be either the name of a type that has preelaborable init or
6665 -- an expression that is preelaborable.
6667 if Nkind
(N
) = N_Extension_Aggregate
then
6669 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
6672 if Is_Entity_Name
(Anc_Part
)
6673 and then Is_Type
(Entity
(Anc_Part
))
6675 if not Has_Preelaborable_Initialization
6681 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
6687 -- Check positional associations
6689 Exp
:= First
(Expressions
(N
));
6690 while Present
(Exp
) loop
6691 if not Is_Preelaborable_Expression
(Exp
) then
6698 -- Check named associations
6700 Assn
:= First
(Component_Associations
(N
));
6701 while Present
(Assn
) loop
6702 Choice
:= First
(Choices
(Assn
));
6703 while Present
(Choice
) loop
6704 if Is_Array_Aggr
then
6705 if Nkind
(Choice
) = N_Others_Choice
then
6708 elsif Nkind
(Choice
) = N_Range
then
6709 if not Is_Static_Range
(Choice
) then
6713 elsif not Is_Static_Expression
(Choice
) then
6718 Comp_Type
:= Etype
(Choice
);
6724 -- If the association has a <> at this point, then we have
6725 -- to check whether the component's type has preelaborable
6726 -- initialization. Note that this only occurs when the
6727 -- association's corresponding component does not have a
6728 -- default expression, the latter case having already been
6729 -- expanded as an expression for the association.
6731 if Box_Present
(Assn
) then
6732 if not Has_Preelaborable_Initialization
(Comp_Type
) then
6736 -- In the expression case we check whether the expression
6737 -- is preelaborable.
6740 not Is_Preelaborable_Expression
(Expression
(Assn
))
6748 -- If we get here then aggregate as a whole is preelaborable
6752 -- All other cases are not preelaborable
6757 end Is_Preelaborable_Expression
;
6759 -- Start of processing for Check_Components
6762 -- Loop through entities of record or protected type
6765 while Present
(Ent
) loop
6767 -- We are interested only in components and discriminants
6774 -- Get default expression if any. If there is no declaration
6775 -- node, it means we have an internal entity. The parent and
6776 -- tag fields are examples of such entities. For such cases,
6777 -- we just test the type of the entity.
6779 if Present
(Declaration_Node
(Ent
)) then
6780 Exp
:= Expression
(Declaration_Node
(Ent
));
6783 when E_Discriminant
=>
6785 -- Note: for a renamed discriminant, the Declaration_Node
6786 -- may point to the one from the ancestor, and have a
6787 -- different expression, so use the proper attribute to
6788 -- retrieve the expression from the derived constraint.
6790 Exp
:= Discriminant_Default_Value
(Ent
);
6793 goto Check_Next_Entity
;
6796 -- A component has PI if it has no default expression and the
6797 -- component type has PI.
6800 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
6805 -- Require the default expression to be preelaborable
6807 elsif not Is_Preelaborable_Expression
(Exp
) then
6812 <<Check_Next_Entity
>>
6815 end Check_Components
;
6817 -- Start of processing for Has_Preelaborable_Initialization
6820 -- Immediate return if already marked as known preelaborable init. This
6821 -- covers types for which this function has already been called once
6822 -- and returned True (in which case the result is cached), and also
6823 -- types to which a pragma Preelaborable_Initialization applies.
6825 if Known_To_Have_Preelab_Init
(E
) then
6829 -- If the type is a subtype representing a generic actual type, then
6830 -- test whether its base type has preelaborable initialization since
6831 -- the subtype representing the actual does not inherit this attribute
6832 -- from the actual or formal. (but maybe it should???)
6834 if Is_Generic_Actual_Type
(E
) then
6835 return Has_Preelaborable_Initialization
(Base_Type
(E
));
6838 -- All elementary types have preelaborable initialization
6840 if Is_Elementary_Type
(E
) then
6843 -- Array types have PI if the component type has PI
6845 elsif Is_Array_Type
(E
) then
6846 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
6848 -- A derived type has preelaborable initialization if its parent type
6849 -- has preelaborable initialization and (in the case of a derived record
6850 -- extension) if the non-inherited components all have preelaborable
6851 -- initialization. However, a user-defined controlled type with an
6852 -- overriding Initialize procedure does not have preelaborable
6855 elsif Is_Derived_Type
(E
) then
6857 -- If the derived type is a private extension then it doesn't have
6858 -- preelaborable initialization.
6860 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
6864 -- First check whether ancestor type has preelaborable initialization
6866 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
6868 -- If OK, check extension components (if any)
6870 if Has_PE
and then Is_Record_Type
(E
) then
6871 Check_Components
(First_Entity
(E
));
6874 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
6875 -- with a user defined Initialize procedure does not have PI.
6878 and then Is_Controlled
(E
)
6879 and then Has_Overriding_Initialize
(E
)
6884 -- Private types not derived from a type having preelaborable init and
6885 -- that are not marked with pragma Preelaborable_Initialization do not
6886 -- have preelaborable initialization.
6888 elsif Is_Private_Type
(E
) then
6891 -- Record type has PI if it is non private and all components have PI
6893 elsif Is_Record_Type
(E
) then
6895 Check_Components
(First_Entity
(E
));
6897 -- Protected types must not have entries, and components must meet
6898 -- same set of rules as for record components.
6900 elsif Is_Protected_Type
(E
) then
6901 if Has_Entries
(E
) then
6905 Check_Components
(First_Entity
(E
));
6906 Check_Components
(First_Private_Entity
(E
));
6909 -- Type System.Address always has preelaborable initialization
6911 elsif Is_RTE
(E
, RE_Address
) then
6914 -- In all other cases, type does not have preelaborable initialization
6920 -- If type has preelaborable initialization, cache result
6923 Set_Known_To_Have_Preelab_Init
(E
);
6927 end Has_Preelaborable_Initialization
;
6929 ---------------------------
6930 -- Has_Private_Component --
6931 ---------------------------
6933 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
6934 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
6935 Component
: Entity_Id
;
6938 if Error_Posted
(Type_Id
)
6939 or else Error_Posted
(Btype
)
6944 if Is_Class_Wide_Type
(Btype
) then
6945 Btype
:= Root_Type
(Btype
);
6948 if Is_Private_Type
(Btype
) then
6950 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
6953 if No
(Full_View
(Btype
)) then
6954 return not Is_Generic_Type
(Btype
)
6955 and then not Is_Generic_Type
(Root_Type
(Btype
));
6957 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
6960 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
6964 elsif Is_Array_Type
(Btype
) then
6965 return Has_Private_Component
(Component_Type
(Btype
));
6967 elsif Is_Record_Type
(Btype
) then
6968 Component
:= First_Component
(Btype
);
6969 while Present
(Component
) loop
6970 if Has_Private_Component
(Etype
(Component
)) then
6974 Next_Component
(Component
);
6979 elsif Is_Protected_Type
(Btype
)
6980 and then Present
(Corresponding_Record_Type
(Btype
))
6982 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
6987 end Has_Private_Component
;
6989 ----------------------
6990 -- Has_Signed_Zeros --
6991 ----------------------
6993 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
6995 return Is_Floating_Point_Type
(E
)
6996 and then Signed_Zeros_On_Target
6997 and then not Vax_Float
(E
);
6998 end Has_Signed_Zeros
;
7000 -----------------------------
7001 -- Has_Static_Array_Bounds --
7002 -----------------------------
7004 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
7005 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
7012 -- Unconstrained types do not have static bounds
7014 if not Is_Constrained
(Typ
) then
7018 -- First treat string literals specially, as the lower bound and length
7019 -- of string literals are not stored like those of arrays.
7021 -- A string literal always has static bounds
7023 if Ekind
(Typ
) = E_String_Literal_Subtype
then
7027 -- Treat all dimensions in turn
7029 Index
:= First_Index
(Typ
);
7030 for Indx
in 1 .. Ndims
loop
7032 -- In case of an erroneous index which is not a discrete type, return
7033 -- that the type is not static.
7035 if not Is_Discrete_Type
(Etype
(Index
))
7036 or else Etype
(Index
) = Any_Type
7041 Get_Index_Bounds
(Index
, Low
, High
);
7043 if Error_Posted
(Low
) or else Error_Posted
(High
) then
7047 if Is_OK_Static_Expression
(Low
)
7049 Is_OK_Static_Expression
(High
)
7059 -- If we fall through the loop, all indexes matched
7062 end Has_Static_Array_Bounds
;
7068 function Has_Stream
(T
: Entity_Id
) return Boolean is
7075 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
7078 elsif Is_Array_Type
(T
) then
7079 return Has_Stream
(Component_Type
(T
));
7081 elsif Is_Record_Type
(T
) then
7082 E
:= First_Component
(T
);
7083 while Present
(E
) loop
7084 if Has_Stream
(Etype
(E
)) then
7093 elsif Is_Private_Type
(T
) then
7094 return Has_Stream
(Underlying_Type
(T
));
7105 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
7107 Get_Name_String
(Chars
(E
));
7108 return Name_Buffer
(Name_Len
) = Suffix
;
7115 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
7117 Get_Name_String
(Chars
(E
));
7118 Add_Char_To_Name_Buffer
(Suffix
);
7126 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
7128 pragma Assert
(Has_Suffix
(E
, Suffix
));
7129 Get_Name_String
(Chars
(E
));
7130 Name_Len
:= Name_Len
- 1;
7134 --------------------------
7135 -- Has_Tagged_Component --
7136 --------------------------
7138 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
7142 if Is_Private_Type
(Typ
)
7143 and then Present
(Underlying_Type
(Typ
))
7145 return Has_Tagged_Component
(Underlying_Type
(Typ
));
7147 elsif Is_Array_Type
(Typ
) then
7148 return Has_Tagged_Component
(Component_Type
(Typ
));
7150 elsif Is_Tagged_Type
(Typ
) then
7153 elsif Is_Record_Type
(Typ
) then
7154 Comp
:= First_Component
(Typ
);
7155 while Present
(Comp
) loop
7156 if Has_Tagged_Component
(Etype
(Comp
)) then
7160 Next_Component
(Comp
);
7168 end Has_Tagged_Component
;
7170 -------------------------
7171 -- Implementation_Kind --
7172 -------------------------
7174 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
7175 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
7178 pragma Assert
(Present
(Impl_Prag
));
7179 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
7180 return Chars
(Get_Pragma_Arg
(Arg
));
7181 end Implementation_Kind
;
7183 --------------------------
7184 -- Implements_Interface --
7185 --------------------------
7187 function Implements_Interface
7188 (Typ_Ent
: Entity_Id
;
7189 Iface_Ent
: Entity_Id
;
7190 Exclude_Parents
: Boolean := False) return Boolean
7192 Ifaces_List
: Elist_Id
;
7194 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
7195 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
7198 if Is_Class_Wide_Type
(Typ
) then
7199 Typ
:= Root_Type
(Typ
);
7202 if not Has_Interfaces
(Typ
) then
7206 if Is_Class_Wide_Type
(Iface
) then
7207 Iface
:= Root_Type
(Iface
);
7210 Collect_Interfaces
(Typ
, Ifaces_List
);
7212 Elmt
:= First_Elmt
(Ifaces_List
);
7213 while Present
(Elmt
) loop
7214 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
7215 and then Exclude_Parents
7219 elsif Node
(Elmt
) = Iface
then
7227 end Implements_Interface
;
7233 function In_Instance
return Boolean is
7234 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
7240 and then S
/= Standard_Standard
7242 if (Ekind
(S
) = E_Function
7243 or else Ekind
(S
) = E_Package
7244 or else Ekind
(S
) = E_Procedure
)
7245 and then Is_Generic_Instance
(S
)
7247 -- A child instance is always compiled in the context of a parent
7248 -- instance. Nevertheless, the actuals are not analyzed in an
7249 -- instance context. We detect this case by examining the current
7250 -- compilation unit, which must be a child instance, and checking
7251 -- that it is not currently on the scope stack.
7253 if Is_Child_Unit
(Curr_Unit
)
7255 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
7256 = N_Package_Instantiation
7257 and then not In_Open_Scopes
(Curr_Unit
)
7271 ----------------------
7272 -- In_Instance_Body --
7273 ----------------------
7275 function In_Instance_Body
return Boolean is
7281 and then S
/= Standard_Standard
7283 if (Ekind
(S
) = E_Function
7284 or else Ekind
(S
) = E_Procedure
)
7285 and then Is_Generic_Instance
(S
)
7289 elsif Ekind
(S
) = E_Package
7290 and then In_Package_Body
(S
)
7291 and then Is_Generic_Instance
(S
)
7300 end In_Instance_Body
;
7302 -----------------------------
7303 -- In_Instance_Not_Visible --
7304 -----------------------------
7306 function In_Instance_Not_Visible
return Boolean is
7312 and then S
/= Standard_Standard
7314 if (Ekind
(S
) = E_Function
7315 or else Ekind
(S
) = E_Procedure
)
7316 and then Is_Generic_Instance
(S
)
7320 elsif Ekind
(S
) = E_Package
7321 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
7322 and then Is_Generic_Instance
(S
)
7331 end In_Instance_Not_Visible
;
7333 ------------------------------
7334 -- In_Instance_Visible_Part --
7335 ------------------------------
7337 function In_Instance_Visible_Part
return Boolean is
7343 and then S
/= Standard_Standard
7345 if Ekind
(S
) = E_Package
7346 and then Is_Generic_Instance
(S
)
7347 and then not In_Package_Body
(S
)
7348 and then not In_Private_Part
(S
)
7357 end In_Instance_Visible_Part
;
7359 ---------------------
7360 -- In_Package_Body --
7361 ---------------------
7363 function In_Package_Body
return Boolean is
7369 and then S
/= Standard_Standard
7371 if Ekind
(S
) = E_Package
7372 and then In_Package_Body
(S
)
7381 end In_Package_Body
;
7383 --------------------------------
7384 -- In_Parameter_Specification --
7385 --------------------------------
7387 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
7392 while Present
(PN
) loop
7393 if Nkind
(PN
) = N_Parameter_Specification
then
7401 end In_Parameter_Specification
;
7403 -------------------------------------
7404 -- In_Reverse_Storage_Order_Object --
7405 -------------------------------------
7407 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
7409 Btyp
: Entity_Id
:= Empty
;
7412 -- Climb up indexed components
7416 case Nkind
(Pref
) is
7417 when N_Selected_Component
=>
7418 Pref
:= Prefix
(Pref
);
7421 when N_Indexed_Component
=>
7422 Pref
:= Prefix
(Pref
);
7430 if Present
(Pref
) then
7431 Btyp
:= Base_Type
(Etype
(Pref
));
7436 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
7437 and then Reverse_Storage_Order
(Btyp
);
7438 end In_Reverse_Storage_Order_Object
;
7440 --------------------------------------
7441 -- In_Subprogram_Or_Concurrent_Unit --
7442 --------------------------------------
7444 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
7449 -- Use scope chain to check successively outer scopes
7455 if K
in Subprogram_Kind
7456 or else K
in Concurrent_Kind
7457 or else K
in Generic_Subprogram_Kind
7461 elsif E
= Standard_Standard
then
7467 end In_Subprogram_Or_Concurrent_Unit
;
7469 ---------------------
7470 -- In_Visible_Part --
7471 ---------------------
7473 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
7476 Is_Package_Or_Generic_Package
(Scope_Id
)
7477 and then In_Open_Scopes
(Scope_Id
)
7478 and then not In_Package_Body
(Scope_Id
)
7479 and then not In_Private_Part
(Scope_Id
);
7480 end In_Visible_Part
;
7482 --------------------------------
7483 -- Incomplete_Or_Private_View --
7484 --------------------------------
7486 function Incomplete_Or_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
7487 function Inspect_Decls
7489 Taft
: Boolean := False) return Entity_Id
;
7490 -- Check whether a declarative region contains the incomplete or private
7497 function Inspect_Decls
7499 Taft
: Boolean := False) return Entity_Id
7505 Decl
:= First
(Decls
);
7506 while Present
(Decl
) loop
7510 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
7511 Match
:= Defining_Identifier
(Decl
);
7515 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
7516 N_Private_Type_Declaration
)
7518 Match
:= Defining_Identifier
(Decl
);
7523 and then Present
(Full_View
(Match
))
7524 and then Full_View
(Match
) = Typ
7539 -- Start of processing for Incomplete_Or_Partial_View
7542 -- Incomplete type case
7544 Prev
:= Current_Entity_In_Scope
(Typ
);
7547 and then Is_Incomplete_Type
(Prev
)
7548 and then Present
(Full_View
(Prev
))
7549 and then Full_View
(Prev
) = Typ
7554 -- Private or Taft amendment type case
7557 Pkg
: constant Entity_Id
:= Scope
(Typ
);
7558 Pkg_Decl
: Node_Id
:= Pkg
;
7561 if Ekind
(Pkg
) = E_Package
then
7562 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
7563 Pkg_Decl
:= Parent
(Pkg_Decl
);
7566 -- It is knows that Typ has a private view, look for it in the
7567 -- visible declarations of the enclosing scope. A special case
7568 -- of this is when the two views have been exchanged - the full
7569 -- appears earlier than the private.
7571 if Has_Private_Declaration
(Typ
) then
7572 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
7574 -- Exchanged view case, look in the private declarations
7577 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
7582 -- Otherwise if this is the package body, then Typ is a potential
7583 -- Taft amendment type. The incomplete view should be located in
7584 -- the private declarations of the enclosing scope.
7586 elsif In_Package_Body
(Pkg
) then
7587 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
7592 -- The type has no incomplete or private view
7595 end Incomplete_Or_Private_View
;
7597 ---------------------------------
7598 -- Insert_Explicit_Dereference --
7599 ---------------------------------
7601 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
7602 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
7603 Ent
: Entity_Id
:= Empty
;
7610 Save_Interps
(N
, New_Prefix
);
7613 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
7614 Prefix
=> New_Prefix
));
7616 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
7618 if Is_Overloaded
(New_Prefix
) then
7620 -- The dereference is also overloaded, and its interpretations are
7621 -- the designated types of the interpretations of the original node.
7623 Set_Etype
(N
, Any_Type
);
7625 Get_First_Interp
(New_Prefix
, I
, It
);
7626 while Present
(It
.Nam
) loop
7629 if Is_Access_Type
(T
) then
7630 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
7633 Get_Next_Interp
(I
, It
);
7639 -- Prefix is unambiguous: mark the original prefix (which might
7640 -- Come_From_Source) as a reference, since the new (relocated) one
7641 -- won't be taken into account.
7643 if Is_Entity_Name
(New_Prefix
) then
7644 Ent
:= Entity
(New_Prefix
);
7647 -- For a retrieval of a subcomponent of some composite object,
7648 -- retrieve the ultimate entity if there is one.
7650 elsif Nkind
(New_Prefix
) = N_Selected_Component
7651 or else Nkind
(New_Prefix
) = N_Indexed_Component
7653 Pref
:= Prefix
(New_Prefix
);
7654 while Present
(Pref
)
7656 (Nkind
(Pref
) = N_Selected_Component
7657 or else Nkind
(Pref
) = N_Indexed_Component
)
7659 Pref
:= Prefix
(Pref
);
7662 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
7663 Ent
:= Entity
(Pref
);
7667 -- Place the reference on the entity node
7669 if Present
(Ent
) then
7670 Generate_Reference
(Ent
, Pref
);
7673 end Insert_Explicit_Dereference
;
7675 ------------------------------------------
7676 -- Inspect_Deferred_Constant_Completion --
7677 ------------------------------------------
7679 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
7683 Decl
:= First
(Decls
);
7684 while Present
(Decl
) loop
7686 -- Deferred constant signature
7688 if Nkind
(Decl
) = N_Object_Declaration
7689 and then Constant_Present
(Decl
)
7690 and then No
(Expression
(Decl
))
7692 -- No need to check internally generated constants
7694 and then Comes_From_Source
(Decl
)
7696 -- The constant is not completed. A full object declaration or a
7697 -- pragma Import complete a deferred constant.
7699 and then not Has_Completion
(Defining_Identifier
(Decl
))
7702 ("constant declaration requires initialization expression",
7703 Defining_Identifier
(Decl
));
7706 Decl
:= Next
(Decl
);
7708 end Inspect_Deferred_Constant_Completion
;
7710 -----------------------------
7711 -- Is_Actual_Out_Parameter --
7712 -----------------------------
7714 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
7718 Find_Actual
(N
, Formal
, Call
);
7719 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
7720 end Is_Actual_Out_Parameter
;
7722 -------------------------
7723 -- Is_Actual_Parameter --
7724 -------------------------
7726 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
7727 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
7731 when N_Parameter_Association
=>
7732 return N
= Explicit_Actual_Parameter
(Parent
(N
));
7734 when N_Subprogram_Call
=>
7735 return Is_List_Member
(N
)
7737 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
7742 end Is_Actual_Parameter
;
7744 --------------------------------
7745 -- Is_Actual_Tagged_Parameter --
7746 --------------------------------
7748 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
7752 Find_Actual
(N
, Formal
, Call
);
7753 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
7754 end Is_Actual_Tagged_Parameter
;
7756 ---------------------
7757 -- Is_Aliased_View --
7758 ---------------------
7760 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
7764 if Is_Entity_Name
(Obj
) then
7771 or else (Present
(Renamed_Object
(E
))
7772 and then Is_Aliased_View
(Renamed_Object
(E
)))))
7774 or else ((Is_Formal
(E
)
7775 or else Ekind
(E
) = E_Generic_In_Out_Parameter
7776 or else Ekind
(E
) = E_Generic_In_Parameter
)
7777 and then Is_Tagged_Type
(Etype
(E
)))
7779 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
7781 -- Current instance of type, either directly or as rewritten
7782 -- reference to the current object.
7784 or else (Is_Entity_Name
(Original_Node
(Obj
))
7785 and then Present
(Entity
(Original_Node
(Obj
)))
7786 and then Is_Type
(Entity
(Original_Node
(Obj
))))
7788 or else (Is_Type
(E
) and then E
= Current_Scope
)
7790 or else (Is_Incomplete_Or_Private_Type
(E
)
7791 and then Full_View
(E
) = Current_Scope
)
7793 -- Ada 2012 AI05-0053: the return object of an extended return
7794 -- statement is aliased if its type is immutably limited.
7796 or else (Is_Return_Object
(E
)
7797 and then Is_Immutably_Limited_Type
(Etype
(E
)));
7799 elsif Nkind
(Obj
) = N_Selected_Component
then
7800 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
7802 elsif Nkind
(Obj
) = N_Indexed_Component
then
7803 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
7805 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
7806 and then Has_Aliased_Components
7807 (Designated_Type
(Etype
(Prefix
(Obj
)))));
7809 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
7810 return Is_Tagged_Type
(Etype
(Obj
))
7811 and then Is_Aliased_View
(Expression
(Obj
));
7813 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
7814 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
7819 end Is_Aliased_View
;
7821 -------------------------
7822 -- Is_Ancestor_Package --
7823 -------------------------
7825 function Is_Ancestor_Package
7827 E2
: Entity_Id
) return Boolean
7834 and then Par
/= Standard_Standard
7844 end Is_Ancestor_Package
;
7846 ----------------------
7847 -- Is_Atomic_Object --
7848 ----------------------
7850 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
7852 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
7853 -- Determines if given object has atomic components
7855 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
7856 -- If prefix is an implicit dereference, examine designated type
7858 ----------------------
7859 -- Is_Atomic_Prefix --
7860 ----------------------
7862 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
7864 if Is_Access_Type
(Etype
(N
)) then
7866 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
7868 return Object_Has_Atomic_Components
(N
);
7870 end Is_Atomic_Prefix
;
7872 ----------------------------------
7873 -- Object_Has_Atomic_Components --
7874 ----------------------------------
7876 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
7878 if Has_Atomic_Components
(Etype
(N
))
7879 or else Is_Atomic
(Etype
(N
))
7883 elsif Is_Entity_Name
(N
)
7884 and then (Has_Atomic_Components
(Entity
(N
))
7885 or else Is_Atomic
(Entity
(N
)))
7889 elsif Nkind
(N
) = N_Selected_Component
7890 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
7894 elsif Nkind
(N
) = N_Indexed_Component
7895 or else Nkind
(N
) = N_Selected_Component
7897 return Is_Atomic_Prefix
(Prefix
(N
));
7902 end Object_Has_Atomic_Components
;
7904 -- Start of processing for Is_Atomic_Object
7907 -- Predicate is not relevant to subprograms
7909 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
7912 elsif Is_Atomic
(Etype
(N
))
7913 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
7917 elsif Nkind
(N
) = N_Selected_Component
7918 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
7922 elsif Nkind
(N
) = N_Indexed_Component
7923 or else Nkind
(N
) = N_Selected_Component
7925 return Is_Atomic_Prefix
(Prefix
(N
));
7930 end Is_Atomic_Object
;
7932 ------------------------------------
7933 -- Is_Body_Or_Package_Declaration --
7934 ------------------------------------
7936 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
7938 return Nkind_In
(N
, N_Entry_Body
,
7940 N_Package_Declaration
,
7944 end Is_Body_Or_Package_Declaration
;
7946 -----------------------
7947 -- Is_Bounded_String --
7948 -----------------------
7950 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
7951 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
7954 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
7955 -- Super_String, or one of the [Wide_]Wide_ versions. This will
7956 -- be True for all the Bounded_String types in instances of the
7957 -- Generic_Bounded_Length generics, and for types derived from those.
7959 return Present
(Under
)
7960 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
7961 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
7962 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
7963 end Is_Bounded_String
;
7965 -----------------------------
7966 -- Is_Concurrent_Interface --
7967 -----------------------------
7969 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
7974 (Is_Protected_Interface
(T
)
7975 or else Is_Synchronized_Interface
(T
)
7976 or else Is_Task_Interface
(T
));
7977 end Is_Concurrent_Interface
;
7979 -----------------------
7980 -- Is_Constant_Bound --
7981 -----------------------
7983 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
7985 if Compile_Time_Known_Value
(Exp
) then
7988 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
7989 return Is_Constant_Object
(Entity
(Exp
))
7990 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
7992 elsif Nkind
(Exp
) in N_Binary_Op
then
7993 return Is_Constant_Bound
(Left_Opnd
(Exp
))
7994 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
7995 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
8000 end Is_Constant_Bound
;
8002 --------------------------------------
8003 -- Is_Controlling_Limited_Procedure --
8004 --------------------------------------
8006 function Is_Controlling_Limited_Procedure
8007 (Proc_Nam
: Entity_Id
) return Boolean
8009 Param_Typ
: Entity_Id
:= Empty
;
8012 if Ekind
(Proc_Nam
) = E_Procedure
8013 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
8015 Param_Typ
:= Etype
(Parameter_Type
(First
(
8016 Parameter_Specifications
(Parent
(Proc_Nam
)))));
8018 -- In this case where an Itype was created, the procedure call has been
8021 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
8022 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
8024 Present
(Parameter_Associations
8025 (Associated_Node_For_Itype
(Proc_Nam
)))
8028 Etype
(First
(Parameter_Associations
8029 (Associated_Node_For_Itype
(Proc_Nam
))));
8032 if Present
(Param_Typ
) then
8034 Is_Interface
(Param_Typ
)
8035 and then Is_Limited_Record
(Param_Typ
);
8039 end Is_Controlling_Limited_Procedure
;
8041 -----------------------------
8042 -- Is_CPP_Constructor_Call --
8043 -----------------------------
8045 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
8047 return Nkind
(N
) = N_Function_Call
8048 and then Is_CPP_Class
(Etype
(Etype
(N
)))
8049 and then Is_Constructor
(Entity
(Name
(N
)))
8050 and then Is_Imported
(Entity
(Name
(N
)));
8051 end Is_CPP_Constructor_Call
;
8057 function Is_Delegate
(T
: Entity_Id
) return Boolean is
8058 Desig_Type
: Entity_Id
;
8061 if VM_Target
/= CLI_Target
then
8065 -- Access-to-subprograms are delegates in CIL
8067 if Ekind
(T
) = E_Access_Subprogram_Type
then
8071 if Ekind
(T
) not in Access_Kind
then
8073 -- A delegate is a managed pointer. If no designated type is defined
8074 -- it means that it's not a delegate.
8079 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
8081 if not Is_Tagged_Type
(Desig_Type
) then
8085 -- Test if the type is inherited from [mscorlib]System.Delegate
8087 while Etype
(Desig_Type
) /= Desig_Type
loop
8088 if Chars
(Scope
(Desig_Type
)) /= No_Name
8089 and then Is_Imported
(Scope
(Desig_Type
))
8090 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
8095 Desig_Type
:= Etype
(Desig_Type
);
8101 ----------------------------------------------
8102 -- Is_Dependent_Component_Of_Mutable_Object --
8103 ----------------------------------------------
8105 function Is_Dependent_Component_Of_Mutable_Object
8106 (Object
: Node_Id
) return Boolean
8109 Prefix_Type
: Entity_Id
;
8110 P_Aliased
: Boolean := False;
8113 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
8114 -- Returns True if and only if Comp is declared within a variant part
8116 --------------------------------
8117 -- Is_Declared_Within_Variant --
8118 --------------------------------
8120 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
8121 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
8122 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
8124 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
8125 end Is_Declared_Within_Variant
;
8127 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
8130 if Is_Variable
(Object
) then
8132 if Nkind
(Object
) = N_Selected_Component
then
8133 P
:= Prefix
(Object
);
8134 Prefix_Type
:= Etype
(P
);
8136 if Is_Entity_Name
(P
) then
8138 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
8139 Prefix_Type
:= Base_Type
(Prefix_Type
);
8142 if Is_Aliased
(Entity
(P
)) then
8146 -- A discriminant check on a selected component may be expanded
8147 -- into a dereference when removing side-effects. Recover the
8148 -- original node and its type, which may be unconstrained.
8150 elsif Nkind
(P
) = N_Explicit_Dereference
8151 and then not (Comes_From_Source
(P
))
8153 P
:= Original_Node
(P
);
8154 Prefix_Type
:= Etype
(P
);
8157 -- Check for prefix being an aliased component???
8163 -- A heap object is constrained by its initial value
8165 -- Ada 2005 (AI-363): Always assume the object could be mutable in
8166 -- the dereferenced case, since the access value might denote an
8167 -- unconstrained aliased object, whereas in Ada 95 the designated
8168 -- object is guaranteed to be constrained. A worst-case assumption
8169 -- has to apply in Ada 2005 because we can't tell at compile time
8170 -- whether the object is "constrained by its initial value"
8171 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
8172 -- semantic rules -- these rules are acknowledged to need fixing).
8174 if Ada_Version
< Ada_2005
then
8175 if Is_Access_Type
(Prefix_Type
)
8176 or else Nkind
(P
) = N_Explicit_Dereference
8181 elsif Ada_Version
>= Ada_2005
then
8182 if Is_Access_Type
(Prefix_Type
) then
8184 -- If the access type is pool-specific, and there is no
8185 -- constrained partial view of the designated type, then the
8186 -- designated object is known to be constrained.
8188 if Ekind
(Prefix_Type
) = E_Access_Type
8189 and then not Object_Type_Has_Constrained_Partial_View
8190 (Typ
=> Designated_Type
(Prefix_Type
),
8191 Scop
=> Current_Scope
)
8195 -- Otherwise (general access type, or there is a constrained
8196 -- partial view of the designated type), we need to check
8197 -- based on the designated type.
8200 Prefix_Type
:= Designated_Type
(Prefix_Type
);
8206 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
8208 -- As per AI-0017, the renaming is illegal in a generic body, even
8209 -- if the subtype is indefinite.
8211 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
8213 if not Is_Constrained
(Prefix_Type
)
8214 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
8216 (Is_Generic_Type
(Prefix_Type
)
8217 and then Ekind
(Current_Scope
) = E_Generic_Package
8218 and then In_Package_Body
(Current_Scope
)))
8220 and then (Is_Declared_Within_Variant
(Comp
)
8221 or else Has_Discriminant_Dependent_Constraint
(Comp
))
8222 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
8226 -- If the prefix is of an access type at this point, then we want
8227 -- to return False, rather than calling this function recursively
8228 -- on the access object (which itself might be a discriminant-
8229 -- dependent component of some other object, but that isn't
8230 -- relevant to checking the object passed to us). This avoids
8231 -- issuing wrong errors when compiling with -gnatc, where there
8232 -- can be implicit dereferences that have not been expanded.
8234 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
8239 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
8242 elsif Nkind
(Object
) = N_Indexed_Component
8243 or else Nkind
(Object
) = N_Slice
8245 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
8247 -- A type conversion that Is_Variable is a view conversion:
8248 -- go back to the denoted object.
8250 elsif Nkind
(Object
) = N_Type_Conversion
then
8252 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
8257 end Is_Dependent_Component_Of_Mutable_Object
;
8259 ---------------------
8260 -- Is_Dereferenced --
8261 ---------------------
8263 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
8264 P
: constant Node_Id
:= Parent
(N
);
8267 (Nkind
(P
) = N_Selected_Component
8269 Nkind
(P
) = N_Explicit_Dereference
8271 Nkind
(P
) = N_Indexed_Component
8273 Nkind
(P
) = N_Slice
)
8274 and then Prefix
(P
) = N
;
8275 end Is_Dereferenced
;
8277 ----------------------
8278 -- Is_Descendent_Of --
8279 ----------------------
8281 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
8286 pragma Assert
(Nkind
(T1
) in N_Entity
);
8287 pragma Assert
(Nkind
(T2
) in N_Entity
);
8289 T
:= Base_Type
(T1
);
8291 -- Immediate return if the types match
8296 -- Comment needed here ???
8298 elsif Ekind
(T
) = E_Class_Wide_Type
then
8299 return Etype
(T
) = T2
;
8307 -- Done if we found the type we are looking for
8312 -- Done if no more derivations to check
8319 -- Following test catches error cases resulting from prev errors
8321 elsif No
(Etyp
) then
8324 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
8327 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
8331 T
:= Base_Type
(Etyp
);
8334 end Is_Descendent_Of
;
8336 ----------------------------
8337 -- Is_Expression_Function --
8338 ----------------------------
8340 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
8344 if Ekind
(Subp
) /= E_Function
then
8348 Decl
:= Unit_Declaration_Node
(Subp
);
8349 return Nkind
(Decl
) = N_Subprogram_Declaration
8351 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
8353 (Present
(Corresponding_Body
(Decl
))
8355 Nkind
(Original_Node
8356 (Unit_Declaration_Node
8357 (Corresponding_Body
(Decl
)))) =
8358 N_Expression_Function
));
8360 end Is_Expression_Function
;
8366 function Is_False
(U
: Uint
) return Boolean is
8371 ---------------------------
8372 -- Is_Fixed_Model_Number --
8373 ---------------------------
8375 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
8376 S
: constant Ureal
:= Small_Value
(T
);
8377 M
: Urealp
.Save_Mark
;
8381 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
8384 end Is_Fixed_Model_Number
;
8386 -------------------------------
8387 -- Is_Fully_Initialized_Type --
8388 -------------------------------
8390 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
8392 -- In Ada2012, a scalar type with an aspect Default_Value
8393 -- is fully initialized.
8395 if Is_Scalar_Type
(Typ
) then
8396 return Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
);
8398 elsif Is_Access_Type
(Typ
) then
8401 elsif Is_Array_Type
(Typ
) then
8402 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
8403 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
8408 -- An interesting case, if we have a constrained type one of whose
8409 -- bounds is known to be null, then there are no elements to be
8410 -- initialized, so all the elements are initialized!
8412 if Is_Constrained
(Typ
) then
8415 Indx_Typ
: Entity_Id
;
8419 Indx
:= First_Index
(Typ
);
8420 while Present
(Indx
) loop
8421 if Etype
(Indx
) = Any_Type
then
8424 -- If index is a range, use directly
8426 elsif Nkind
(Indx
) = N_Range
then
8427 Lbd
:= Low_Bound
(Indx
);
8428 Hbd
:= High_Bound
(Indx
);
8431 Indx_Typ
:= Etype
(Indx
);
8433 if Is_Private_Type
(Indx_Typ
) then
8434 Indx_Typ
:= Full_View
(Indx_Typ
);
8437 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
8440 Lbd
:= Type_Low_Bound
(Indx_Typ
);
8441 Hbd
:= Type_High_Bound
(Indx_Typ
);
8445 if Compile_Time_Known_Value
(Lbd
)
8446 and then Compile_Time_Known_Value
(Hbd
)
8448 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
8458 -- If no null indexes, then type is not fully initialized
8464 elsif Is_Record_Type
(Typ
) then
8465 if Has_Discriminants
(Typ
)
8467 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
8468 and then Is_Fully_Initialized_Variant
(Typ
)
8473 -- We consider bounded string types to be fully initialized, because
8474 -- otherwise we get false alarms when the Data component is not
8475 -- default-initialized.
8477 if Is_Bounded_String
(Typ
) then
8481 -- Controlled records are considered to be fully initialized if
8482 -- there is a user defined Initialize routine. This may not be
8483 -- entirely correct, but as the spec notes, we are guessing here
8484 -- what is best from the point of view of issuing warnings.
8486 if Is_Controlled
(Typ
) then
8488 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
8491 if Present
(Utyp
) then
8493 Init
: constant Entity_Id
:=
8495 (Underlying_Type
(Typ
), Name_Initialize
));
8499 and then Comes_From_Source
(Init
)
8501 Is_Predefined_File_Name
8502 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
8506 elsif Has_Null_Extension
(Typ
)
8508 Is_Fully_Initialized_Type
8509 (Etype
(Base_Type
(Typ
)))
8518 -- Otherwise see if all record components are initialized
8524 Ent
:= First_Entity
(Typ
);
8525 while Present
(Ent
) loop
8526 if Ekind
(Ent
) = E_Component
8527 and then (No
(Parent
(Ent
))
8528 or else No
(Expression
(Parent
(Ent
))))
8529 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
8531 -- Special VM case for tag components, which need to be
8532 -- defined in this case, but are never initialized as VMs
8533 -- are using other dispatching mechanisms. Ignore this
8534 -- uninitialized case. Note that this applies both to the
8535 -- uTag entry and the main vtable pointer (CPP_Class case).
8537 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
8546 -- No uninitialized components, so type is fully initialized.
8547 -- Note that this catches the case of no components as well.
8551 elsif Is_Concurrent_Type
(Typ
) then
8554 elsif Is_Private_Type
(Typ
) then
8556 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
8562 return Is_Fully_Initialized_Type
(U
);
8569 end Is_Fully_Initialized_Type
;
8571 ----------------------------------
8572 -- Is_Fully_Initialized_Variant --
8573 ----------------------------------
8575 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
8576 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8577 Constraints
: constant List_Id
:= New_List
;
8578 Components
: constant Elist_Id
:= New_Elmt_List
;
8579 Comp_Elmt
: Elmt_Id
;
8581 Comp_List
: Node_Id
;
8583 Discr_Val
: Node_Id
;
8585 Report_Errors
: Boolean;
8586 pragma Warnings
(Off
, Report_Errors
);
8589 if Serious_Errors_Detected
> 0 then
8593 if Is_Record_Type
(Typ
)
8594 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
8595 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
8597 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
8599 Discr
:= First_Discriminant
(Typ
);
8600 while Present
(Discr
) loop
8601 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
8602 Discr_Val
:= Expression
(Parent
(Discr
));
8604 if Present
(Discr_Val
)
8605 and then Is_OK_Static_Expression
(Discr_Val
)
8607 Append_To
(Constraints
,
8608 Make_Component_Association
(Loc
,
8609 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
8610 Expression
=> New_Copy
(Discr_Val
)));
8618 Next_Discriminant
(Discr
);
8623 Comp_List
=> Comp_List
,
8624 Governed_By
=> Constraints
,
8626 Report_Errors
=> Report_Errors
);
8628 -- Check that each component present is fully initialized
8630 Comp_Elmt
:= First_Elmt
(Components
);
8631 while Present
(Comp_Elmt
) loop
8632 Comp_Id
:= Node
(Comp_Elmt
);
8634 if Ekind
(Comp_Id
) = E_Component
8635 and then (No
(Parent
(Comp_Id
))
8636 or else No
(Expression
(Parent
(Comp_Id
))))
8637 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
8642 Next_Elmt
(Comp_Elmt
);
8647 elsif Is_Private_Type
(Typ
) then
8649 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
8655 return Is_Fully_Initialized_Variant
(U
);
8661 end Is_Fully_Initialized_Variant
;
8663 ----------------------------
8664 -- Is_Inherited_Operation --
8665 ----------------------------
8667 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
8668 pragma Assert
(Is_Overloadable
(E
));
8669 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
8671 return Kind
= N_Full_Type_Declaration
8672 or else Kind
= N_Private_Extension_Declaration
8673 or else Kind
= N_Subtype_Declaration
8674 or else (Ekind
(E
) = E_Enumeration_Literal
8675 and then Is_Derived_Type
(Etype
(E
)));
8676 end Is_Inherited_Operation
;
8678 -------------------------------------
8679 -- Is_Inherited_Operation_For_Type --
8680 -------------------------------------
8682 function Is_Inherited_Operation_For_Type
8684 Typ
: Entity_Id
) return Boolean
8687 -- Check that the operation has been created by the type declaration
8689 return Is_Inherited_Operation
(E
)
8690 and then Defining_Identifier
(Parent
(E
)) = Typ
;
8691 end Is_Inherited_Operation_For_Type
;
8697 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
8698 Ifaces_List
: Elist_Id
;
8699 Iface_Elmt
: Elmt_Id
;
8703 if Is_Class_Wide_Type
(Typ
)
8705 Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
8706 Name_Reversible_Iterator
)
8708 Is_Predefined_File_Name
8709 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
8713 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
8717 Collect_Interfaces
(Typ
, Ifaces_List
);
8719 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8720 while Present
(Iface_Elmt
) loop
8721 Iface
:= Node
(Iface_Elmt
);
8722 if Chars
(Iface
) = Name_Forward_Iterator
8724 Is_Predefined_File_Name
8725 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
8730 Next_Elmt
(Iface_Elmt
);
8741 -- We seem to have a lot of overlapping functions that do similar things
8742 -- (testing for left hand sides or lvalues???). Anyway, since this one is
8743 -- purely syntactic, it should be in Sem_Aux I would think???
8745 function Is_LHS
(N
: Node_Id
) return Boolean is
8746 P
: constant Node_Id
:= Parent
(N
);
8749 if Nkind
(P
) = N_Assignment_Statement
then
8750 return Name
(P
) = N
;
8753 Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
8755 return N
= Prefix
(P
) and then Is_LHS
(P
);
8762 -----------------------------
8763 -- Is_Library_Level_Entity --
8764 -----------------------------
8766 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
8768 -- The following is a small optimization, and it also properly handles
8769 -- discriminals, which in task bodies might appear in expressions before
8770 -- the corresponding procedure has been created, and which therefore do
8771 -- not have an assigned scope.
8773 if Is_Formal
(E
) then
8777 -- Normal test is simply that the enclosing dynamic scope is Standard
8779 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
8780 end Is_Library_Level_Entity
;
8782 --------------------------------
8783 -- Is_Limited_Class_Wide_Type --
8784 --------------------------------
8786 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
8789 Is_Class_Wide_Type
(Typ
)
8790 and then (Is_Limited_Type
(Typ
) or else From_With_Type
(Typ
));
8791 end Is_Limited_Class_Wide_Type
;
8793 ---------------------------------
8794 -- Is_Local_Variable_Reference --
8795 ---------------------------------
8797 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
8799 if not Is_Entity_Name
(Expr
) then
8804 Ent
: constant Entity_Id
:= Entity
(Expr
);
8805 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
8807 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
8810 return Present
(Sub
) and then Sub
= Current_Subprogram
;
8814 end Is_Local_Variable_Reference
;
8816 -------------------------
8817 -- Is_Object_Reference --
8818 -------------------------
8820 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
8822 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
8823 -- Determine whether N is the name of an internally-generated renaming
8825 --------------------------------------
8826 -- Is_Internally_Generated_Renaming --
8827 --------------------------------------
8829 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
8834 while Present
(P
) loop
8835 if Nkind
(P
) = N_Object_Renaming_Declaration
then
8836 return not Comes_From_Source
(P
);
8837 elsif Is_List_Member
(P
) then
8845 end Is_Internally_Generated_Renaming
;
8847 -- Start of processing for Is_Object_Reference
8850 if Is_Entity_Name
(N
) then
8851 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
8855 when N_Indexed_Component | N_Slice
=>
8857 Is_Object_Reference
(Prefix
(N
))
8858 or else Is_Access_Type
(Etype
(Prefix
(N
)));
8860 -- In Ada 95, a function call is a constant object; a procedure
8863 when N_Function_Call
=>
8864 return Etype
(N
) /= Standard_Void_Type
;
8866 -- Attributes 'Input and 'Result produce objects
8868 when N_Attribute_Reference
=>
8869 return Nam_In
(Attribute_Name
(N
), Name_Input
, Name_Result
);
8871 when N_Selected_Component
=>
8873 Is_Object_Reference
(Selector_Name
(N
))
8875 (Is_Object_Reference
(Prefix
(N
))
8876 or else Is_Access_Type
(Etype
(Prefix
(N
))));
8878 when N_Explicit_Dereference
=>
8881 -- A view conversion of a tagged object is an object reference
8883 when N_Type_Conversion
=>
8884 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
8885 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
8886 and then Is_Object_Reference
(Expression
(N
));
8888 -- An unchecked type conversion is considered to be an object if
8889 -- the operand is an object (this construction arises only as a
8890 -- result of expansion activities).
8892 when N_Unchecked_Type_Conversion
=>
8895 -- Allow string literals to act as objects as long as they appear
8896 -- in internally-generated renamings. The expansion of iterators
8897 -- may generate such renamings when the range involves a string
8900 when N_String_Literal
=>
8901 return Is_Internally_Generated_Renaming
(Parent
(N
));
8903 -- AI05-0003: In Ada 2012 a qualified expression is a name.
8904 -- This allows disambiguation of function calls and the use
8905 -- of aggregates in more contexts.
8907 when N_Qualified_Expression
=>
8908 if Ada_Version
< Ada_2012
then
8911 return Is_Object_Reference
(Expression
(N
))
8912 or else Nkind
(Expression
(N
)) = N_Aggregate
;
8919 end Is_Object_Reference
;
8921 -----------------------------------
8922 -- Is_OK_Variable_For_Out_Formal --
8923 -----------------------------------
8925 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
8927 Note_Possible_Modification
(AV
, Sure
=> True);
8929 -- We must reject parenthesized variable names. Comes_From_Source is
8930 -- checked because there are currently cases where the compiler violates
8931 -- this rule (e.g. passing a task object to its controlled Initialize
8932 -- routine). This should be properly documented in sinfo???
8934 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
8937 -- A variable is always allowed
8939 elsif Is_Variable
(AV
) then
8942 -- Unchecked conversions are allowed only if they come from the
8943 -- generated code, which sometimes uses unchecked conversions for out
8944 -- parameters in cases where code generation is unaffected. We tell
8945 -- source unchecked conversions by seeing if they are rewrites of
8946 -- an original Unchecked_Conversion function call, or of an explicit
8947 -- conversion of a function call or an aggregate (as may happen in the
8948 -- expansion of a packed array aggregate).
8950 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
8951 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
8954 elsif Comes_From_Source
(AV
)
8955 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
8959 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
8960 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
8966 -- Normal type conversions are allowed if argument is a variable
8968 elsif Nkind
(AV
) = N_Type_Conversion
then
8969 if Is_Variable
(Expression
(AV
))
8970 and then Paren_Count
(Expression
(AV
)) = 0
8972 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
8975 -- We also allow a non-parenthesized expression that raises
8976 -- constraint error if it rewrites what used to be a variable
8978 elsif Raises_Constraint_Error
(Expression
(AV
))
8979 and then Paren_Count
(Expression
(AV
)) = 0
8980 and then Is_Variable
(Original_Node
(Expression
(AV
)))
8984 -- Type conversion of something other than a variable
8990 -- If this node is rewritten, then test the original form, if that is
8991 -- OK, then we consider the rewritten node OK (for example, if the
8992 -- original node is a conversion, then Is_Variable will not be true
8993 -- but we still want to allow the conversion if it converts a variable).
8995 elsif Original_Node
(AV
) /= AV
then
8997 -- In Ada 2012, the explicit dereference may be a rewritten call to a
8998 -- Reference function.
9000 if Ada_Version
>= Ada_2012
9001 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
9003 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
9008 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
9011 -- All other non-variables are rejected
9016 end Is_OK_Variable_For_Out_Formal
;
9018 -----------------------------------
9019 -- Is_Partially_Initialized_Type --
9020 -----------------------------------
9022 function Is_Partially_Initialized_Type
9024 Include_Implicit
: Boolean := True) return Boolean
9027 if Is_Scalar_Type
(Typ
) then
9030 elsif Is_Access_Type
(Typ
) then
9031 return Include_Implicit
;
9033 elsif Is_Array_Type
(Typ
) then
9035 -- If component type is partially initialized, so is array type
9037 if Is_Partially_Initialized_Type
9038 (Component_Type
(Typ
), Include_Implicit
)
9042 -- Otherwise we are only partially initialized if we are fully
9043 -- initialized (this is the empty array case, no point in us
9044 -- duplicating that code here).
9047 return Is_Fully_Initialized_Type
(Typ
);
9050 elsif Is_Record_Type
(Typ
) then
9052 -- A discriminated type is always partially initialized if in
9055 if Has_Discriminants
(Typ
) and then Include_Implicit
then
9058 -- A tagged type is always partially initialized
9060 elsif Is_Tagged_Type
(Typ
) then
9063 -- Case of non-discriminated record
9069 Component_Present
: Boolean := False;
9070 -- Set True if at least one component is present. If no
9071 -- components are present, then record type is fully
9072 -- initialized (another odd case, like the null array).
9075 -- Loop through components
9077 Ent
:= First_Entity
(Typ
);
9078 while Present
(Ent
) loop
9079 if Ekind
(Ent
) = E_Component
then
9080 Component_Present
:= True;
9082 -- If a component has an initialization expression then
9083 -- the enclosing record type is partially initialized
9085 if Present
(Parent
(Ent
))
9086 and then Present
(Expression
(Parent
(Ent
)))
9090 -- If a component is of a type which is itself partially
9091 -- initialized, then the enclosing record type is also.
9093 elsif Is_Partially_Initialized_Type
9094 (Etype
(Ent
), Include_Implicit
)
9103 -- No initialized components found. If we found any components
9104 -- they were all uninitialized so the result is false.
9106 if Component_Present
then
9109 -- But if we found no components, then all the components are
9110 -- initialized so we consider the type to be initialized.
9118 -- Concurrent types are always fully initialized
9120 elsif Is_Concurrent_Type
(Typ
) then
9123 -- For a private type, go to underlying type. If there is no underlying
9124 -- type then just assume this partially initialized. Not clear if this
9125 -- can happen in a non-error case, but no harm in testing for this.
9127 elsif Is_Private_Type
(Typ
) then
9129 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
9134 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
9138 -- For any other type (are there any?) assume partially initialized
9143 end Is_Partially_Initialized_Type
;
9145 ------------------------------------
9146 -- Is_Potentially_Persistent_Type --
9147 ------------------------------------
9149 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
9154 -- For private type, test corresponding full type
9156 if Is_Private_Type
(T
) then
9157 return Is_Potentially_Persistent_Type
(Full_View
(T
));
9159 -- Scalar types are potentially persistent
9161 elsif Is_Scalar_Type
(T
) then
9164 -- Record type is potentially persistent if not tagged and the types of
9165 -- all it components are potentially persistent, and no component has
9166 -- an initialization expression.
9168 elsif Is_Record_Type
(T
)
9169 and then not Is_Tagged_Type
(T
)
9170 and then not Is_Partially_Initialized_Type
(T
)
9172 Comp
:= First_Component
(T
);
9173 while Present
(Comp
) loop
9174 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
9183 -- Array type is potentially persistent if its component type is
9184 -- potentially persistent and if all its constraints are static.
9186 elsif Is_Array_Type
(T
) then
9187 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
9191 Indx
:= First_Index
(T
);
9192 while Present
(Indx
) loop
9193 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
9202 -- All other types are not potentially persistent
9207 end Is_Potentially_Persistent_Type
;
9209 ---------------------------------
9210 -- Is_Protected_Self_Reference --
9211 ---------------------------------
9213 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
9215 function In_Access_Definition
(N
: Node_Id
) return Boolean;
9216 -- Returns true if N belongs to an access definition
9218 --------------------------
9219 -- In_Access_Definition --
9220 --------------------------
9222 function In_Access_Definition
(N
: Node_Id
) return Boolean is
9227 while Present
(P
) loop
9228 if Nkind
(P
) = N_Access_Definition
then
9236 end In_Access_Definition
;
9238 -- Start of processing for Is_Protected_Self_Reference
9241 -- Verify that prefix is analyzed and has the proper form. Note that
9242 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
9243 -- which also produce the address of an entity, do not analyze their
9244 -- prefix because they denote entities that are not necessarily visible.
9245 -- Neither of them can apply to a protected type.
9247 return Ada_Version
>= Ada_2005
9248 and then Is_Entity_Name
(N
)
9249 and then Present
(Entity
(N
))
9250 and then Is_Protected_Type
(Entity
(N
))
9251 and then In_Open_Scopes
(Entity
(N
))
9252 and then not In_Access_Definition
(N
);
9253 end Is_Protected_Self_Reference
;
9255 -----------------------------
9256 -- Is_RCI_Pkg_Spec_Or_Body --
9257 -----------------------------
9259 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
9261 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
9262 -- Return True if the unit of Cunit is an RCI package declaration
9264 ---------------------------
9265 -- Is_RCI_Pkg_Decl_Cunit --
9266 ---------------------------
9268 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
9269 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
9272 if Nkind
(The_Unit
) /= N_Package_Declaration
then
9276 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
9277 end Is_RCI_Pkg_Decl_Cunit
;
9279 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
9282 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
9284 (Nkind
(Unit
(Cunit
)) = N_Package_Body
9285 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
9286 end Is_RCI_Pkg_Spec_Or_Body
;
9288 -----------------------------------------
9289 -- Is_Remote_Access_To_Class_Wide_Type --
9290 -----------------------------------------
9292 function Is_Remote_Access_To_Class_Wide_Type
9293 (E
: Entity_Id
) return Boolean
9296 -- A remote access to class-wide type is a general access to object type
9297 -- declared in the visible part of a Remote_Types or Remote_Call_
9300 return Ekind
(E
) = E_General_Access_Type
9301 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
9302 end Is_Remote_Access_To_Class_Wide_Type
;
9304 -----------------------------------------
9305 -- Is_Remote_Access_To_Subprogram_Type --
9306 -----------------------------------------
9308 function Is_Remote_Access_To_Subprogram_Type
9309 (E
: Entity_Id
) return Boolean
9312 return (Ekind
(E
) = E_Access_Subprogram_Type
9313 or else (Ekind
(E
) = E_Record_Type
9314 and then Present
(Corresponding_Remote_Type
(E
))))
9315 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
9316 end Is_Remote_Access_To_Subprogram_Type
;
9318 --------------------
9319 -- Is_Remote_Call --
9320 --------------------
9322 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
9324 if Nkind
(N
) not in N_Subprogram_Call
then
9326 -- An entry call cannot be remote
9330 elsif Nkind
(Name
(N
)) in N_Has_Entity
9331 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
9333 -- A subprogram declared in the spec of a RCI package is remote
9337 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
9338 and then Is_Remote_Access_To_Subprogram_Type
9339 (Etype
(Prefix
(Name
(N
))))
9341 -- The dereference of a RAS is a remote call
9345 elsif Present
(Controlling_Argument
(N
))
9346 and then Is_Remote_Access_To_Class_Wide_Type
9347 (Etype
(Controlling_Argument
(N
)))
9349 -- Any primitive operation call with a controlling argument of
9350 -- a RACW type is a remote call.
9355 -- All other calls are local calls
9360 ----------------------
9361 -- Is_Renamed_Entry --
9362 ----------------------
9364 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
9365 Orig_Node
: Node_Id
:= Empty
;
9366 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
9368 function Is_Entry
(Nam
: Node_Id
) return Boolean;
9369 -- Determine whether Nam is an entry. Traverse selectors if there are
9370 -- nested selected components.
9376 function Is_Entry
(Nam
: Node_Id
) return Boolean is
9378 if Nkind
(Nam
) = N_Selected_Component
then
9379 return Is_Entry
(Selector_Name
(Nam
));
9382 return Ekind
(Entity
(Nam
)) = E_Entry
;
9385 -- Start of processing for Is_Renamed_Entry
9388 if Present
(Alias
(Proc_Nam
)) then
9389 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
9392 -- Look for a rewritten subprogram renaming declaration
9394 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
9395 and then Present
(Original_Node
(Subp_Decl
))
9397 Orig_Node
:= Original_Node
(Subp_Decl
);
9400 -- The rewritten subprogram is actually an entry
9402 if Present
(Orig_Node
)
9403 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
9404 and then Is_Entry
(Name
(Orig_Node
))
9410 end Is_Renamed_Entry
;
9412 ----------------------------
9413 -- Is_Reversible_Iterator --
9414 ----------------------------
9416 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
9417 Ifaces_List
: Elist_Id
;
9418 Iface_Elmt
: Elmt_Id
;
9422 if Is_Class_Wide_Type
(Typ
)
9423 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
9425 Is_Predefined_File_Name
9426 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
9430 elsif not Is_Tagged_Type
(Typ
)
9431 or else not Is_Derived_Type
(Typ
)
9436 Collect_Interfaces
(Typ
, Ifaces_List
);
9438 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
9439 while Present
(Iface_Elmt
) loop
9440 Iface
:= Node
(Iface_Elmt
);
9441 if Chars
(Iface
) = Name_Reversible_Iterator
9443 Is_Predefined_File_Name
9444 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
9449 Next_Elmt
(Iface_Elmt
);
9454 end Is_Reversible_Iterator
;
9456 ----------------------
9457 -- Is_Selector_Name --
9458 ----------------------
9460 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
9462 if not Is_List_Member
(N
) then
9464 P
: constant Node_Id
:= Parent
(N
);
9465 K
: constant Node_Kind
:= Nkind
(P
);
9468 (K
= N_Expanded_Name
or else
9469 K
= N_Generic_Association
or else
9470 K
= N_Parameter_Association
or else
9471 K
= N_Selected_Component
)
9472 and then Selector_Name
(P
) = N
;
9477 L
: constant List_Id
:= List_Containing
(N
);
9478 P
: constant Node_Id
:= Parent
(L
);
9480 return (Nkind
(P
) = N_Discriminant_Association
9481 and then Selector_Names
(P
) = L
)
9483 (Nkind
(P
) = N_Component_Association
9484 and then Choices
(P
) = L
);
9487 end Is_Selector_Name
;
9489 ----------------------------------
9490 -- Is_SPARK_Initialization_Expr --
9491 ----------------------------------
9493 function Is_SPARK_Initialization_Expr
(N
: Node_Id
) return Boolean is
9496 Comp_Assn
: Node_Id
;
9497 Orig_N
: constant Node_Id
:= Original_Node
(N
);
9502 if not Comes_From_Source
(Orig_N
) then
9506 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
9508 case Nkind
(Orig_N
) is
9509 when N_Character_Literal |
9517 if Is_Entity_Name
(Orig_N
)
9518 and then Present
(Entity
(Orig_N
)) -- needed in some cases
9520 case Ekind
(Entity
(Orig_N
)) is
9522 E_Enumeration_Literal |
9527 if Is_Type
(Entity
(Orig_N
)) then
9535 when N_Qualified_Expression |
9536 N_Type_Conversion
=>
9537 Is_Ok
:= Is_SPARK_Initialization_Expr
(Expression
(Orig_N
));
9540 Is_Ok
:= Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
9544 N_Membership_Test
=>
9545 Is_Ok
:= Is_SPARK_Initialization_Expr
(Left_Opnd
(Orig_N
))
9546 and then Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
9549 N_Extension_Aggregate
=>
9550 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
9551 Is_Ok
:= Is_SPARK_Initialization_Expr
(Ancestor_Part
(Orig_N
));
9554 Expr
:= First
(Expressions
(Orig_N
));
9555 while Present
(Expr
) loop
9556 if not Is_SPARK_Initialization_Expr
(Expr
) then
9564 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
9565 while Present
(Comp_Assn
) loop
9566 Expr
:= Expression
(Comp_Assn
);
9567 if Present
(Expr
) -- needed for box association
9568 and then not Is_SPARK_Initialization_Expr
(Expr
)
9577 when N_Attribute_Reference
=>
9578 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
9579 Is_Ok
:= Is_SPARK_Initialization_Expr
(Prefix
(Orig_N
));
9582 Expr
:= First
(Expressions
(Orig_N
));
9583 while Present
(Expr
) loop
9584 if not Is_SPARK_Initialization_Expr
(Expr
) then
9592 -- Selected components might be expanded named not yet resolved, so
9593 -- default on the safe side. (Eg on sparklex.ads)
9595 when N_Selected_Component
=>
9604 end Is_SPARK_Initialization_Expr
;
9606 -------------------------------
9607 -- Is_SPARK_Object_Reference --
9608 -------------------------------
9610 function Is_SPARK_Object_Reference
(N
: Node_Id
) return Boolean is
9612 if Is_Entity_Name
(N
) then
9613 return Present
(Entity
(N
))
9615 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
9616 or else Ekind
(Entity
(N
)) in Formal_Kind
);
9620 when N_Selected_Component
=>
9621 return Is_SPARK_Object_Reference
(Prefix
(N
));
9627 end Is_SPARK_Object_Reference
;
9633 function Is_Statement
(N
: Node_Id
) return Boolean is
9636 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
9637 or else Nkind
(N
) = N_Procedure_Call_Statement
;
9640 --------------------------------------------------
9641 -- Is_Subprogram_Stub_Without_Prior_Declaration --
9642 --------------------------------------------------
9644 function Is_Subprogram_Stub_Without_Prior_Declaration
9645 (N
: Node_Id
) return Boolean
9648 -- A subprogram stub without prior declaration serves as declaration for
9649 -- the actual subprogram body. As such, it has an attached defining
9650 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
9652 return Nkind
(N
) = N_Subprogram_Body_Stub
9653 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
9654 end Is_Subprogram_Stub_Without_Prior_Declaration
;
9656 ---------------------------------
9657 -- Is_Synchronized_Tagged_Type --
9658 ---------------------------------
9660 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
9661 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
9664 -- A task or protected type derived from an interface is a tagged type.
9665 -- Such a tagged type is called a synchronized tagged type, as are
9666 -- synchronized interfaces and private extensions whose declaration
9667 -- includes the reserved word synchronized.
9669 return (Is_Tagged_Type
(E
)
9670 and then (Kind
= E_Task_Type
9671 or else Kind
= E_Protected_Type
))
9674 and then Is_Synchronized_Interface
(E
))
9676 (Ekind
(E
) = E_Record_Type_With_Private
9677 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
9678 and then (Synchronized_Present
(Parent
(E
))
9679 or else Is_Synchronized_Interface
(Etype
(E
))));
9680 end Is_Synchronized_Tagged_Type
;
9686 function Is_Transfer
(N
: Node_Id
) return Boolean is
9687 Kind
: constant Node_Kind
:= Nkind
(N
);
9690 if Kind
= N_Simple_Return_Statement
9692 Kind
= N_Extended_Return_Statement
9694 Kind
= N_Goto_Statement
9696 Kind
= N_Raise_Statement
9698 Kind
= N_Requeue_Statement
9702 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
9703 and then No
(Condition
(N
))
9707 elsif Kind
= N_Procedure_Call_Statement
9708 and then Is_Entity_Name
(Name
(N
))
9709 and then Present
(Entity
(Name
(N
)))
9710 and then No_Return
(Entity
(Name
(N
)))
9714 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
9726 function Is_True
(U
: Uint
) return Boolean is
9731 -------------------------------
9732 -- Is_Universal_Numeric_Type --
9733 -------------------------------
9735 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
9737 return T
= Universal_Integer
or else T
= Universal_Real
;
9738 end Is_Universal_Numeric_Type
;
9744 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
9746 return VM_Target
= CLI_Target
9747 and then Nkind
(T
) in N_Has_Chars
9748 and then Chars
(T
) /= No_Name
9749 and then Get_Name_String
(Chars
(T
)) = "valuetype";
9752 ----------------------------
9753 -- Is_Variable_Size_Array --
9754 ----------------------------
9756 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
9760 pragma Assert
(Is_Array_Type
(E
));
9762 -- Check if some index is initialized with a non-constant value
9764 Idx
:= First_Index
(E
);
9765 while Present
(Idx
) loop
9766 if Nkind
(Idx
) = N_Range
then
9767 if not Is_Constant_Bound
(Low_Bound
(Idx
))
9768 or else not Is_Constant_Bound
(High_Bound
(Idx
))
9774 Idx
:= Next_Index
(Idx
);
9778 end Is_Variable_Size_Array
;
9780 -----------------------------
9781 -- Is_Variable_Size_Record --
9782 -----------------------------
9784 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
9786 Comp_Typ
: Entity_Id
;
9789 pragma Assert
(Is_Record_Type
(E
));
9791 Comp
:= First_Entity
(E
);
9792 while Present
(Comp
) loop
9793 Comp_Typ
:= Etype
(Comp
);
9795 -- Recursive call if the record type has discriminants
9797 if Is_Record_Type
(Comp_Typ
)
9798 and then Has_Discriminants
(Comp_Typ
)
9799 and then Is_Variable_Size_Record
(Comp_Typ
)
9803 elsif Is_Array_Type
(Comp_Typ
)
9804 and then Is_Variable_Size_Array
(Comp_Typ
)
9813 end Is_Variable_Size_Record
;
9815 ---------------------
9816 -- Is_VMS_Operator --
9817 ---------------------
9819 function Is_VMS_Operator
(Op
: Entity_Id
) return Boolean is
9821 -- The VMS operators are declared in a child of System that is loaded
9822 -- through pragma Extend_System. In some rare cases a program is run
9823 -- with this extension but without indicating that the target is VMS.
9825 return Ekind
(Op
) = E_Function
9826 and then Is_Intrinsic_Subprogram
(Op
)
9828 ((Present_System_Aux
and then Scope
(Op
) = System_Aux_Id
)
9831 and then Scope
(Scope
(Op
)) = RTU_Entity
(System
)));
9832 end Is_VMS_Operator
;
9838 function Is_Variable
9840 Use_Original_Node
: Boolean := True) return Boolean
9842 Orig_Node
: Node_Id
;
9844 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
9845 -- Within a protected function, the private components of the enclosing
9846 -- protected type are constants. A function nested within a (protected)
9847 -- procedure is not itself protected.
9849 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
9850 -- Prefixes can involve implicit dereferences, in which case we must
9851 -- test for the case of a reference of a constant access type, which can
9852 -- can never be a variable.
9854 ---------------------------
9855 -- In_Protected_Function --
9856 ---------------------------
9858 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
9859 Prot
: constant Entity_Id
:= Scope
(E
);
9863 if not Is_Protected_Type
(Prot
) then
9867 while Present
(S
) and then S
/= Prot
loop
9868 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
9877 end In_Protected_Function
;
9879 ------------------------
9880 -- Is_Variable_Prefix --
9881 ------------------------
9883 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
9885 if Is_Access_Type
(Etype
(P
)) then
9886 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
9888 -- For the case of an indexed component whose prefix has a packed
9889 -- array type, the prefix has been rewritten into a type conversion.
9890 -- Determine variable-ness from the converted expression.
9892 elsif Nkind
(P
) = N_Type_Conversion
9893 and then not Comes_From_Source
(P
)
9894 and then Is_Array_Type
(Etype
(P
))
9895 and then Is_Packed
(Etype
(P
))
9897 return Is_Variable
(Expression
(P
));
9900 return Is_Variable
(P
);
9902 end Is_Variable_Prefix
;
9904 -- Start of processing for Is_Variable
9907 -- Check if we perform the test on the original node since this may be a
9908 -- test of syntactic categories which must not be disturbed by whatever
9909 -- rewriting might have occurred. For example, an aggregate, which is
9910 -- certainly NOT a variable, could be turned into a variable by
9913 if Use_Original_Node
then
9914 Orig_Node
:= Original_Node
(N
);
9919 -- Definitely OK if Assignment_OK is set. Since this is something that
9920 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
9922 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
9925 -- Normally we go to the original node, but there is one exception where
9926 -- we use the rewritten node, namely when it is an explicit dereference.
9927 -- The generated code may rewrite a prefix which is an access type with
9928 -- an explicit dereference. The dereference is a variable, even though
9929 -- the original node may not be (since it could be a constant of the
9932 -- In Ada 2005 we have a further case to consider: the prefix may be a
9933 -- function call given in prefix notation. The original node appears to
9934 -- be a selected component, but we need to examine the call.
9936 elsif Nkind
(N
) = N_Explicit_Dereference
9937 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
9938 and then Present
(Etype
(Orig_Node
))
9939 and then Is_Access_Type
(Etype
(Orig_Node
))
9941 -- Note that if the prefix is an explicit dereference that does not
9942 -- come from source, we must check for a rewritten function call in
9943 -- prefixed notation before other forms of rewriting, to prevent a
9947 (Nkind
(Orig_Node
) = N_Function_Call
9948 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
9950 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
9952 -- in Ada 2012, the dereference may have been added for a type with
9953 -- a declared implicit dereference aspect.
9955 elsif Nkind
(N
) = N_Explicit_Dereference
9956 and then Present
(Etype
(Orig_Node
))
9957 and then Ada_Version
>= Ada_2012
9958 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
9962 -- A function call is never a variable
9964 elsif Nkind
(N
) = N_Function_Call
then
9967 -- All remaining checks use the original node
9969 elsif Is_Entity_Name
(Orig_Node
)
9970 and then Present
(Entity
(Orig_Node
))
9973 E
: constant Entity_Id
:= Entity
(Orig_Node
);
9974 K
: constant Entity_Kind
:= Ekind
(E
);
9977 return (K
= E_Variable
9978 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
9979 or else (K
= E_Component
9980 and then not In_Protected_Function
(E
))
9981 or else K
= E_Out_Parameter
9982 or else K
= E_In_Out_Parameter
9983 or else K
= E_Generic_In_Out_Parameter
9985 -- Current instance of type
9987 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
9988 or else (Is_Incomplete_Or_Private_Type
(E
)
9989 and then In_Open_Scopes
(Full_View
(E
)));
9993 case Nkind
(Orig_Node
) is
9994 when N_Indexed_Component | N_Slice
=>
9995 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
9997 when N_Selected_Component
=>
9998 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
9999 and then Is_Variable
(Selector_Name
(Orig_Node
));
10001 -- For an explicit dereference, the type of the prefix cannot
10002 -- be an access to constant or an access to subprogram.
10004 when N_Explicit_Dereference
=>
10006 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
10008 return Is_Access_Type
(Typ
)
10009 and then not Is_Access_Constant
(Root_Type
(Typ
))
10010 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
10013 -- The type conversion is the case where we do not deal with the
10014 -- context dependent special case of an actual parameter. Thus
10015 -- the type conversion is only considered a variable for the
10016 -- purposes of this routine if the target type is tagged. However,
10017 -- a type conversion is considered to be a variable if it does not
10018 -- come from source (this deals for example with the conversions
10019 -- of expressions to their actual subtypes).
10021 when N_Type_Conversion
=>
10022 return Is_Variable
(Expression
(Orig_Node
))
10024 (not Comes_From_Source
(Orig_Node
)
10026 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
10028 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
10030 -- GNAT allows an unchecked type conversion as a variable. This
10031 -- only affects the generation of internal expanded code, since
10032 -- calls to instantiations of Unchecked_Conversion are never
10033 -- considered variables (since they are function calls).
10035 when N_Unchecked_Type_Conversion
=>
10036 return Is_Variable
(Expression
(Orig_Node
));
10044 ---------------------------
10045 -- Is_Visibly_Controlled --
10046 ---------------------------
10048 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
10049 Root
: constant Entity_Id
:= Root_Type
(T
);
10051 return Chars
(Scope
(Root
)) = Name_Finalization
10052 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
10053 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
10054 end Is_Visibly_Controlled
;
10056 ------------------------
10057 -- Is_Volatile_Object --
10058 ------------------------
10060 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
10062 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
10063 -- Determines if given object has volatile components
10065 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
10066 -- If prefix is an implicit dereference, examine designated type
10068 ------------------------
10069 -- Is_Volatile_Prefix --
10070 ------------------------
10072 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
10073 Typ
: constant Entity_Id
:= Etype
(N
);
10076 if Is_Access_Type
(Typ
) then
10078 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
10081 return Is_Volatile
(Dtyp
)
10082 or else Has_Volatile_Components
(Dtyp
);
10086 return Object_Has_Volatile_Components
(N
);
10088 end Is_Volatile_Prefix
;
10090 ------------------------------------
10091 -- Object_Has_Volatile_Components --
10092 ------------------------------------
10094 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
10095 Typ
: constant Entity_Id
:= Etype
(N
);
10098 if Is_Volatile
(Typ
)
10099 or else Has_Volatile_Components
(Typ
)
10103 elsif Is_Entity_Name
(N
)
10104 and then (Has_Volatile_Components
(Entity
(N
))
10105 or else Is_Volatile
(Entity
(N
)))
10109 elsif Nkind
(N
) = N_Indexed_Component
10110 or else Nkind
(N
) = N_Selected_Component
10112 return Is_Volatile_Prefix
(Prefix
(N
));
10117 end Object_Has_Volatile_Components
;
10119 -- Start of processing for Is_Volatile_Object
10122 if Is_Volatile
(Etype
(N
))
10123 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
10127 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
10128 and then Is_Volatile_Prefix
(Prefix
(N
))
10132 elsif Nkind
(N
) = N_Selected_Component
10133 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
10140 end Is_Volatile_Object
;
10142 ---------------------------
10143 -- Itype_Has_Declaration --
10144 ---------------------------
10146 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
10148 pragma Assert
(Is_Itype
(Id
));
10149 return Present
(Parent
(Id
))
10150 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
10151 N_Subtype_Declaration
)
10152 and then Defining_Entity
(Parent
(Id
)) = Id
;
10153 end Itype_Has_Declaration
;
10155 -------------------------
10156 -- Kill_Current_Values --
10157 -------------------------
10159 procedure Kill_Current_Values
10161 Last_Assignment_Only
: Boolean := False)
10164 -- ??? do we have to worry about clearing cached checks?
10166 if Is_Assignable
(Ent
) then
10167 Set_Last_Assignment
(Ent
, Empty
);
10170 if Is_Object
(Ent
) then
10171 if not Last_Assignment_Only
then
10173 Set_Current_Value
(Ent
, Empty
);
10175 if not Can_Never_Be_Null
(Ent
) then
10176 Set_Is_Known_Non_Null
(Ent
, False);
10179 Set_Is_Known_Null
(Ent
, False);
10181 -- Reset Is_Known_Valid unless type is always valid, or if we have
10182 -- a loop parameter (loop parameters are always valid, since their
10183 -- bounds are defined by the bounds given in the loop header).
10185 if not Is_Known_Valid
(Etype
(Ent
))
10186 and then Ekind
(Ent
) /= E_Loop_Parameter
10188 Set_Is_Known_Valid
(Ent
, False);
10192 end Kill_Current_Values
;
10194 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
10197 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
10198 -- Clear current value for entity E and all entities chained to E
10200 ------------------------------------------
10201 -- Kill_Current_Values_For_Entity_Chain --
10202 ------------------------------------------
10204 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
10208 while Present
(Ent
) loop
10209 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
10212 end Kill_Current_Values_For_Entity_Chain
;
10214 -- Start of processing for Kill_Current_Values
10217 -- Kill all saved checks, a special case of killing saved values
10219 if not Last_Assignment_Only
then
10223 -- Loop through relevant scopes, which includes the current scope and
10224 -- any parent scopes if the current scope is a block or a package.
10226 S
:= Current_Scope
;
10229 -- Clear current values of all entities in current scope
10231 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
10233 -- If scope is a package, also clear current values of all private
10234 -- entities in the scope.
10236 if Is_Package_Or_Generic_Package
(S
)
10237 or else Is_Concurrent_Type
(S
)
10239 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
10242 -- If this is a not a subprogram, deal with parents
10244 if not Is_Subprogram
(S
) then
10246 exit Scope_Loop
when S
= Standard_Standard
;
10250 end loop Scope_Loop
;
10251 end Kill_Current_Values
;
10253 --------------------------
10254 -- Kill_Size_Check_Code --
10255 --------------------------
10257 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
10259 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
10260 and then Present
(Size_Check_Code
(E
))
10262 Remove
(Size_Check_Code
(E
));
10263 Set_Size_Check_Code
(E
, Empty
);
10265 end Kill_Size_Check_Code
;
10267 --------------------------
10268 -- Known_To_Be_Assigned --
10269 --------------------------
10271 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
10272 P
: constant Node_Id
:= Parent
(N
);
10277 -- Test left side of assignment
10279 when N_Assignment_Statement
=>
10280 return N
= Name
(P
);
10282 -- Function call arguments are never lvalues
10284 when N_Function_Call
=>
10287 -- Positional parameter for procedure or accept call
10289 when N_Procedure_Call_Statement |
10298 Proc
:= Get_Subprogram_Entity
(P
);
10304 -- If we are not a list member, something is strange, so
10305 -- be conservative and return False.
10307 if not Is_List_Member
(N
) then
10311 -- We are going to find the right formal by stepping forward
10312 -- through the formals, as we step backwards in the actuals.
10314 Form
:= First_Formal
(Proc
);
10317 -- If no formal, something is weird, so be conservative
10318 -- and return False.
10325 exit when No
(Act
);
10326 Next_Formal
(Form
);
10329 return Ekind
(Form
) /= E_In_Parameter
;
10332 -- Named parameter for procedure or accept call
10334 when N_Parameter_Association
=>
10340 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
10346 -- Loop through formals to find the one that matches
10348 Form
:= First_Formal
(Proc
);
10350 -- If no matching formal, that's peculiar, some kind of
10351 -- previous error, so return False to be conservative.
10352 -- Actually this also happens in legal code in the case
10353 -- where P is a parameter association for an Extra_Formal???
10359 -- Else test for match
10361 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
10362 return Ekind
(Form
) /= E_In_Parameter
;
10365 Next_Formal
(Form
);
10369 -- Test for appearing in a conversion that itself appears
10370 -- in an lvalue context, since this should be an lvalue.
10372 when N_Type_Conversion
=>
10373 return Known_To_Be_Assigned
(P
);
10375 -- All other references are definitely not known to be modifications
10381 end Known_To_Be_Assigned
;
10383 ---------------------------
10384 -- Last_Source_Statement --
10385 ---------------------------
10387 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
10391 N
:= Last
(Statements
(HSS
));
10392 while Present
(N
) loop
10393 exit when Comes_From_Source
(N
);
10398 end Last_Source_Statement
;
10400 ----------------------------------
10401 -- Matching_Static_Array_Bounds --
10402 ----------------------------------
10404 function Matching_Static_Array_Bounds
10406 R_Typ
: Node_Id
) return Boolean
10408 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
10409 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
10421 if L_Ndims
/= R_Ndims
then
10425 -- Unconstrained types do not have static bounds
10427 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
10431 -- First treat specially the first dimension, as the lower bound and
10432 -- length of string literals are not stored like those of arrays.
10434 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
10435 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
10436 L_Len
:= String_Literal_Length
(L_Typ
);
10438 L_Index
:= First_Index
(L_Typ
);
10439 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
10441 if Is_OK_Static_Expression
(L_Low
)
10442 and then Is_OK_Static_Expression
(L_High
)
10444 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
10447 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
10454 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
10455 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
10456 R_Len
:= String_Literal_Length
(R_Typ
);
10458 R_Index
:= First_Index
(R_Typ
);
10459 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
10461 if Is_OK_Static_Expression
(R_Low
)
10462 and then Is_OK_Static_Expression
(R_High
)
10464 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
10467 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
10474 if Is_OK_Static_Expression
(L_Low
)
10475 and then Is_OK_Static_Expression
(R_Low
)
10476 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
10477 and then L_Len
= R_Len
10484 -- Then treat all other dimensions
10486 for Indx
in 2 .. L_Ndims
loop
10490 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
10491 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
10493 if Is_OK_Static_Expression
(L_Low
)
10494 and then Is_OK_Static_Expression
(L_High
)
10495 and then Is_OK_Static_Expression
(R_Low
)
10496 and then Is_OK_Static_Expression
(R_High
)
10497 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
10498 and then Expr_Value
(L_High
) = Expr_Value
(R_High
)
10506 -- If we fall through the loop, all indexes matched
10509 end Matching_Static_Array_Bounds
;
10511 -------------------
10512 -- May_Be_Lvalue --
10513 -------------------
10515 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
10516 P
: constant Node_Id
:= Parent
(N
);
10521 -- Test left side of assignment
10523 when N_Assignment_Statement
=>
10524 return N
= Name
(P
);
10526 -- Test prefix of component or attribute. Note that the prefix of an
10527 -- explicit or implicit dereference cannot be an l-value.
10529 when N_Attribute_Reference
=>
10530 return N
= Prefix
(P
)
10531 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
10533 -- For an expanded name, the name is an lvalue if the expanded name
10534 -- is an lvalue, but the prefix is never an lvalue, since it is just
10535 -- the scope where the name is found.
10537 when N_Expanded_Name
=>
10538 if N
= Prefix
(P
) then
10539 return May_Be_Lvalue
(P
);
10544 -- For a selected component A.B, A is certainly an lvalue if A.B is.
10545 -- B is a little interesting, if we have A.B := 3, there is some
10546 -- discussion as to whether B is an lvalue or not, we choose to say
10547 -- it is. Note however that A is not an lvalue if it is of an access
10548 -- type since this is an implicit dereference.
10550 when N_Selected_Component
=>
10552 and then Present
(Etype
(N
))
10553 and then Is_Access_Type
(Etype
(N
))
10557 return May_Be_Lvalue
(P
);
10560 -- For an indexed component or slice, the index or slice bounds is
10561 -- never an lvalue. The prefix is an lvalue if the indexed component
10562 -- or slice is an lvalue, except if it is an access type, where we
10563 -- have an implicit dereference.
10565 when N_Indexed_Component | N_Slice
=>
10567 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
10571 return May_Be_Lvalue
(P
);
10574 -- Prefix of a reference is an lvalue if the reference is an lvalue
10576 when N_Reference
=>
10577 return May_Be_Lvalue
(P
);
10579 -- Prefix of explicit dereference is never an lvalue
10581 when N_Explicit_Dereference
=>
10584 -- Positional parameter for subprogram, entry, or accept call.
10585 -- In older versions of Ada function call arguments are never
10586 -- lvalues. In Ada 2012 functions can have in-out parameters.
10588 when N_Subprogram_Call |
10589 N_Entry_Call_Statement |
10592 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
10596 -- The following mechanism is clumsy and fragile. A single flag
10597 -- set in Resolve_Actuals would be preferable ???
10605 Proc
:= Get_Subprogram_Entity
(P
);
10611 -- If we are not a list member, something is strange, so be
10612 -- conservative and return True.
10614 if not Is_List_Member
(N
) then
10618 -- We are going to find the right formal by stepping forward
10619 -- through the formals, as we step backwards in the actuals.
10621 Form
:= First_Formal
(Proc
);
10624 -- If no formal, something is weird, so be conservative and
10632 exit when No
(Act
);
10633 Next_Formal
(Form
);
10636 return Ekind
(Form
) /= E_In_Parameter
;
10639 -- Named parameter for procedure or accept call
10641 when N_Parameter_Association
=>
10647 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
10653 -- Loop through formals to find the one that matches
10655 Form
:= First_Formal
(Proc
);
10657 -- If no matching formal, that's peculiar, some kind of
10658 -- previous error, so return True to be conservative.
10659 -- Actually happens with legal code for an unresolved call
10660 -- where we may get the wrong homonym???
10666 -- Else test for match
10668 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
10669 return Ekind
(Form
) /= E_In_Parameter
;
10672 Next_Formal
(Form
);
10676 -- Test for appearing in a conversion that itself appears in an
10677 -- lvalue context, since this should be an lvalue.
10679 when N_Type_Conversion
=>
10680 return May_Be_Lvalue
(P
);
10682 -- Test for appearance in object renaming declaration
10684 when N_Object_Renaming_Declaration
=>
10687 -- All other references are definitely not lvalues
10695 -----------------------
10696 -- Mark_Coextensions --
10697 -----------------------
10699 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
10700 Is_Dynamic
: Boolean;
10701 -- Indicates whether the context causes nested coextensions to be
10702 -- dynamic or static
10704 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
10705 -- Recognize an allocator node and label it as a dynamic coextension
10707 --------------------
10708 -- Mark_Allocator --
10709 --------------------
10711 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
10713 if Nkind
(N
) = N_Allocator
then
10715 Set_Is_Dynamic_Coextension
(N
);
10717 -- If the allocator expression is potentially dynamic, it may
10718 -- be expanded out of order and require dynamic allocation
10719 -- anyway, so we treat the coextension itself as dynamic.
10720 -- Potential optimization ???
10722 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
10723 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
10725 Set_Is_Dynamic_Coextension
(N
);
10727 Set_Is_Static_Coextension
(N
);
10732 end Mark_Allocator
;
10734 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
10736 -- Start of processing Mark_Coextensions
10739 case Nkind
(Context_Nod
) is
10741 -- Comment here ???
10743 when N_Assignment_Statement
=>
10744 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
10746 -- An allocator that is a component of a returned aggregate
10747 -- must be dynamic.
10749 when N_Simple_Return_Statement
=>
10751 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
10754 Nkind
(Expr
) = N_Allocator
10756 (Nkind
(Expr
) = N_Qualified_Expression
10757 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
10760 -- An alloctor within an object declaration in an extended return
10761 -- statement is of necessity dynamic.
10763 when N_Object_Declaration
=>
10764 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
10766 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
10768 -- This routine should not be called for constructs which may not
10769 -- contain coextensions.
10772 raise Program_Error
;
10775 Mark_Allocators
(Root_Nod
);
10776 end Mark_Coextensions
;
10782 function Must_Inline
(Subp
: Entity_Id
) return Boolean is
10785 (Optimization_Level
= 0
10787 -- AAMP and VM targets have no support for inlining in the backend.
10788 -- Hence we do as much inlining as possible in the front end.
10790 or else AAMP_On_Target
10791 or else VM_Target
/= No_VM
)
10792 and then Has_Pragma_Inline
(Subp
)
10793 and then (Has_Pragma_Inline_Always
(Subp
) or else Front_End_Inlining
);
10796 ----------------------
10797 -- Needs_One_Actual --
10798 ----------------------
10800 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
10801 Formal
: Entity_Id
;
10804 -- Ada 2005 or later, and formals present
10806 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
10807 Formal
:= Next_Formal
(First_Formal
(E
));
10808 while Present
(Formal
) loop
10809 if No
(Default_Value
(Formal
)) then
10813 Next_Formal
(Formal
);
10818 -- Ada 83/95 or no formals
10823 end Needs_One_Actual
;
10825 ------------------------
10826 -- New_Copy_List_Tree --
10827 ------------------------
10829 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
10834 if List
= No_List
then
10841 while Present
(E
) loop
10842 Append
(New_Copy_Tree
(E
), NL
);
10848 end New_Copy_List_Tree
;
10850 -------------------
10851 -- New_Copy_Tree --
10852 -------------------
10854 use Atree
.Unchecked_Access
;
10855 use Atree_Private_Part
;
10857 -- Our approach here requires a two pass traversal of the tree. The
10858 -- first pass visits all nodes that eventually will be copied looking
10859 -- for defining Itypes. If any defining Itypes are found, then they are
10860 -- copied, and an entry is added to the replacement map. In the second
10861 -- phase, the tree is copied, using the replacement map to replace any
10862 -- Itype references within the copied tree.
10864 -- The following hash tables are used if the Map supplied has more
10865 -- than hash threshold entries to speed up access to the map. If
10866 -- there are fewer entries, then the map is searched sequentially
10867 -- (because setting up a hash table for only a few entries takes
10868 -- more time than it saves.
10870 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
10871 -- Hash function used for hash operations
10873 -------------------
10874 -- New_Copy_Hash --
10875 -------------------
10877 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
10879 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
10886 -- The hash table NCT_Assoc associates old entities in the table
10887 -- with their corresponding new entities (i.e. the pairs of entries
10888 -- presented in the original Map argument are Key-Element pairs).
10890 package NCT_Assoc
is new Simple_HTable
(
10891 Header_Num
=> NCT_Header_Num
,
10892 Element
=> Entity_Id
,
10893 No_Element
=> Empty
,
10895 Hash
=> New_Copy_Hash
,
10896 Equal
=> Types
."=");
10898 ---------------------
10899 -- NCT_Itype_Assoc --
10900 ---------------------
10902 -- The hash table NCT_Itype_Assoc contains entries only for those
10903 -- old nodes which have a non-empty Associated_Node_For_Itype set.
10904 -- The key is the associated node, and the element is the new node
10905 -- itself (NOT the associated node for the new node).
10907 package NCT_Itype_Assoc
is new Simple_HTable
(
10908 Header_Num
=> NCT_Header_Num
,
10909 Element
=> Entity_Id
,
10910 No_Element
=> Empty
,
10912 Hash
=> New_Copy_Hash
,
10913 Equal
=> Types
."=");
10915 -- Start of processing for New_Copy_Tree function
10917 function New_Copy_Tree
10919 Map
: Elist_Id
:= No_Elist
;
10920 New_Sloc
: Source_Ptr
:= No_Location
;
10921 New_Scope
: Entity_Id
:= Empty
) return Node_Id
10923 Actual_Map
: Elist_Id
:= Map
;
10924 -- This is the actual map for the copy. It is initialized with the
10925 -- given elements, and then enlarged as required for Itypes that are
10926 -- copied during the first phase of the copy operation. The visit
10927 -- procedures add elements to this map as Itypes are encountered.
10928 -- The reason we cannot use Map directly, is that it may well be
10929 -- (and normally is) initialized to No_Elist, and if we have mapped
10930 -- entities, we have to reset it to point to a real Elist.
10932 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
10933 -- Called during second phase to map entities into their corresponding
10934 -- copies using Actual_Map. If the argument is not an entity, or is not
10935 -- in Actual_Map, then it is returned unchanged.
10937 procedure Build_NCT_Hash_Tables
;
10938 -- Builds hash tables (number of elements >= threshold value)
10940 function Copy_Elist_With_Replacement
10941 (Old_Elist
: Elist_Id
) return Elist_Id
;
10942 -- Called during second phase to copy element list doing replacements
10944 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
10945 -- Called during the second phase to process a copied Itype. The actual
10946 -- copy happened during the first phase (so that we could make the entry
10947 -- in the mapping), but we still have to deal with the descendents of
10948 -- the copied Itype and copy them where necessary.
10950 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
10951 -- Called during second phase to copy list doing replacements
10953 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
10954 -- Called during second phase to copy node doing replacements
10956 procedure Visit_Elist
(E
: Elist_Id
);
10957 -- Called during first phase to visit all elements of an Elist
10959 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
10960 -- Visit a single field, recursing to call Visit_Node or Visit_List
10961 -- if the field is a syntactic descendent of the current node (i.e.
10962 -- its parent is Node N).
10964 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
10965 -- Called during first phase to visit subsidiary fields of a defining
10966 -- Itype, and also create a copy and make an entry in the replacement
10967 -- map for the new copy.
10969 procedure Visit_List
(L
: List_Id
);
10970 -- Called during first phase to visit all elements of a List
10972 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
10973 -- Called during first phase to visit a node and all its subtrees
10979 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
10984 if not Has_Extension
(N
) or else No
(Actual_Map
) then
10987 elsif NCT_Hash_Tables_Used
then
10988 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
10990 if Present
(Ent
) then
10996 -- No hash table used, do serial search
10999 E
:= First_Elmt
(Actual_Map
);
11000 while Present
(E
) loop
11001 if Node
(E
) = N
then
11002 return Node
(Next_Elmt
(E
));
11004 E
:= Next_Elmt
(Next_Elmt
(E
));
11012 ---------------------------
11013 -- Build_NCT_Hash_Tables --
11014 ---------------------------
11016 procedure Build_NCT_Hash_Tables
is
11020 if NCT_Hash_Table_Setup
then
11022 NCT_Itype_Assoc
.Reset
;
11025 Elmt
:= First_Elmt
(Actual_Map
);
11026 while Present
(Elmt
) loop
11027 Ent
:= Node
(Elmt
);
11029 -- Get new entity, and associate old and new
11032 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
11034 if Is_Type
(Ent
) then
11036 Anode
: constant Entity_Id
:=
11037 Associated_Node_For_Itype
(Ent
);
11040 if Present
(Anode
) then
11042 -- Enter a link between the associated node of the
11043 -- old Itype and the new Itype, for updating later
11044 -- when node is copied.
11046 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
11054 NCT_Hash_Tables_Used
:= True;
11055 NCT_Hash_Table_Setup
:= True;
11056 end Build_NCT_Hash_Tables
;
11058 ---------------------------------
11059 -- Copy_Elist_With_Replacement --
11060 ---------------------------------
11062 function Copy_Elist_With_Replacement
11063 (Old_Elist
: Elist_Id
) return Elist_Id
11066 New_Elist
: Elist_Id
;
11069 if No
(Old_Elist
) then
11073 New_Elist
:= New_Elmt_List
;
11075 M
:= First_Elmt
(Old_Elist
);
11076 while Present
(M
) loop
11077 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
11083 end Copy_Elist_With_Replacement
;
11085 ---------------------------------
11086 -- Copy_Itype_With_Replacement --
11087 ---------------------------------
11089 -- This routine exactly parallels its phase one analog Visit_Itype,
11091 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
11093 -- Translate Next_Entity, Scope and Etype fields, in case they
11094 -- reference entities that have been mapped into copies.
11096 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
11097 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
11099 if Present
(New_Scope
) then
11100 Set_Scope
(New_Itype
, New_Scope
);
11102 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
11105 -- Copy referenced fields
11107 if Is_Discrete_Type
(New_Itype
) then
11108 Set_Scalar_Range
(New_Itype
,
11109 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
11111 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
11112 Set_Discriminant_Constraint
(New_Itype
,
11113 Copy_Elist_With_Replacement
11114 (Discriminant_Constraint
(New_Itype
)));
11116 elsif Is_Array_Type
(New_Itype
) then
11117 if Present
(First_Index
(New_Itype
)) then
11118 Set_First_Index
(New_Itype
,
11119 First
(Copy_List_With_Replacement
11120 (List_Containing
(First_Index
(New_Itype
)))));
11123 if Is_Packed
(New_Itype
) then
11124 Set_Packed_Array_Type
(New_Itype
,
11125 Copy_Node_With_Replacement
11126 (Packed_Array_Type
(New_Itype
)));
11129 end Copy_Itype_With_Replacement
;
11131 --------------------------------
11132 -- Copy_List_With_Replacement --
11133 --------------------------------
11135 function Copy_List_With_Replacement
11136 (Old_List
: List_Id
) return List_Id
11138 New_List
: List_Id
;
11142 if Old_List
= No_List
then
11146 New_List
:= Empty_List
;
11148 E
:= First
(Old_List
);
11149 while Present
(E
) loop
11150 Append
(Copy_Node_With_Replacement
(E
), New_List
);
11156 end Copy_List_With_Replacement
;
11158 --------------------------------
11159 -- Copy_Node_With_Replacement --
11160 --------------------------------
11162 function Copy_Node_With_Replacement
11163 (Old_Node
: Node_Id
) return Node_Id
11165 New_Node
: Node_Id
;
11167 procedure Adjust_Named_Associations
11168 (Old_Node
: Node_Id
;
11169 New_Node
: Node_Id
);
11170 -- If a call node has named associations, these are chained through
11171 -- the First_Named_Actual, Next_Named_Actual links. These must be
11172 -- propagated separately to the new parameter list, because these
11173 -- are not syntactic fields.
11175 function Copy_Field_With_Replacement
11176 (Field
: Union_Id
) return Union_Id
;
11177 -- Given Field, which is a field of Old_Node, return a copy of it
11178 -- if it is a syntactic field (i.e. its parent is Node), setting
11179 -- the parent of the copy to poit to New_Node. Otherwise returns
11180 -- the field (possibly mapped if it is an entity).
11182 -------------------------------
11183 -- Adjust_Named_Associations --
11184 -------------------------------
11186 procedure Adjust_Named_Associations
11187 (Old_Node
: Node_Id
;
11188 New_Node
: Node_Id
)
11193 Old_Next
: Node_Id
;
11194 New_Next
: Node_Id
;
11197 Old_E
:= First
(Parameter_Associations
(Old_Node
));
11198 New_E
:= First
(Parameter_Associations
(New_Node
));
11199 while Present
(Old_E
) loop
11200 if Nkind
(Old_E
) = N_Parameter_Association
11201 and then Present
(Next_Named_Actual
(Old_E
))
11203 if First_Named_Actual
(Old_Node
)
11204 = Explicit_Actual_Parameter
(Old_E
)
11206 Set_First_Named_Actual
11207 (New_Node
, Explicit_Actual_Parameter
(New_E
));
11210 -- Now scan parameter list from the beginning,to locate
11211 -- next named actual, which can be out of order.
11213 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
11214 New_Next
:= First
(Parameter_Associations
(New_Node
));
11216 while Nkind
(Old_Next
) /= N_Parameter_Association
11217 or else Explicit_Actual_Parameter
(Old_Next
)
11218 /= Next_Named_Actual
(Old_E
)
11224 Set_Next_Named_Actual
11225 (New_E
, Explicit_Actual_Parameter
(New_Next
));
11231 end Adjust_Named_Associations
;
11233 ---------------------------------
11234 -- Copy_Field_With_Replacement --
11235 ---------------------------------
11237 function Copy_Field_With_Replacement
11238 (Field
: Union_Id
) return Union_Id
11241 if Field
= Union_Id
(Empty
) then
11244 elsif Field
in Node_Range
then
11246 Old_N
: constant Node_Id
:= Node_Id
(Field
);
11250 -- If syntactic field, as indicated by the parent pointer
11251 -- being set, then copy the referenced node recursively.
11253 if Parent
(Old_N
) = Old_Node
then
11254 New_N
:= Copy_Node_With_Replacement
(Old_N
);
11256 if New_N
/= Old_N
then
11257 Set_Parent
(New_N
, New_Node
);
11260 -- For semantic fields, update possible entity reference
11261 -- from the replacement map.
11264 New_N
:= Assoc
(Old_N
);
11267 return Union_Id
(New_N
);
11270 elsif Field
in List_Range
then
11272 Old_L
: constant List_Id
:= List_Id
(Field
);
11276 -- If syntactic field, as indicated by the parent pointer,
11277 -- then recursively copy the entire referenced list.
11279 if Parent
(Old_L
) = Old_Node
then
11280 New_L
:= Copy_List_With_Replacement
(Old_L
);
11281 Set_Parent
(New_L
, New_Node
);
11283 -- For semantic list, just returned unchanged
11289 return Union_Id
(New_L
);
11292 -- Anything other than a list or a node is returned unchanged
11297 end Copy_Field_With_Replacement
;
11299 -- Start of processing for Copy_Node_With_Replacement
11302 if Old_Node
<= Empty_Or_Error
then
11305 elsif Has_Extension
(Old_Node
) then
11306 return Assoc
(Old_Node
);
11309 New_Node
:= New_Copy
(Old_Node
);
11311 -- If the node we are copying is the associated node of a
11312 -- previously copied Itype, then adjust the associated node
11313 -- of the copy of that Itype accordingly.
11315 if Present
(Actual_Map
) then
11321 -- Case of hash table used
11323 if NCT_Hash_Tables_Used
then
11324 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
11326 if Present
(Ent
) then
11327 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
11330 -- Case of no hash table used
11333 E
:= First_Elmt
(Actual_Map
);
11334 while Present
(E
) loop
11335 if Is_Itype
(Node
(E
))
11337 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
11339 Set_Associated_Node_For_Itype
11340 (Node
(Next_Elmt
(E
)), New_Node
);
11343 E
:= Next_Elmt
(Next_Elmt
(E
));
11349 -- Recursively copy descendents
11352 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
11354 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
11356 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
11358 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
11360 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
11362 -- Adjust Sloc of new node if necessary
11364 if New_Sloc
/= No_Location
then
11365 Set_Sloc
(New_Node
, New_Sloc
);
11367 -- If we adjust the Sloc, then we are essentially making
11368 -- a completely new node, so the Comes_From_Source flag
11369 -- should be reset to the proper default value.
11371 Nodes
.Table
(New_Node
).Comes_From_Source
:=
11372 Default_Node
.Comes_From_Source
;
11375 -- If the node is call and has named associations,
11376 -- set the corresponding links in the copy.
11378 if (Nkind
(Old_Node
) = N_Function_Call
11379 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
11381 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
11382 and then Present
(First_Named_Actual
(Old_Node
))
11384 Adjust_Named_Associations
(Old_Node
, New_Node
);
11387 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
11388 -- The replacement mechanism applies to entities, and is not used
11389 -- here. Eventually we may need a more general graph-copying
11390 -- routine. For now, do a sequential search to find desired node.
11392 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
11393 and then Present
(First_Real_Statement
(Old_Node
))
11396 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
11400 N1
:= First
(Statements
(Old_Node
));
11401 N2
:= First
(Statements
(New_Node
));
11403 while N1
/= Old_F
loop
11408 Set_First_Real_Statement
(New_Node
, N2
);
11413 -- All done, return copied node
11416 end Copy_Node_With_Replacement
;
11422 procedure Visit_Elist
(E
: Elist_Id
) is
11425 if Present
(E
) then
11426 Elmt
:= First_Elmt
(E
);
11428 while Elmt
/= No_Elmt
loop
11429 Visit_Node
(Node
(Elmt
));
11439 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
11441 if F
= Union_Id
(Empty
) then
11444 elsif F
in Node_Range
then
11446 -- Copy node if it is syntactic, i.e. its parent pointer is
11447 -- set to point to the field that referenced it (certain
11448 -- Itypes will also meet this criterion, which is fine, since
11449 -- these are clearly Itypes that do need to be copied, since
11450 -- we are copying their parent.)
11452 if Parent
(Node_Id
(F
)) = N
then
11453 Visit_Node
(Node_Id
(F
));
11456 -- Another case, if we are pointing to an Itype, then we want
11457 -- to copy it if its associated node is somewhere in the tree
11460 -- Note: the exclusion of self-referential copies is just an
11461 -- optimization, since the search of the already copied list
11462 -- would catch it, but it is a common case (Etype pointing
11463 -- to itself for an Itype that is a base type).
11465 elsif Has_Extension
(Node_Id
(F
))
11466 and then Is_Itype
(Entity_Id
(F
))
11467 and then Node_Id
(F
) /= N
11473 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
11474 while Present
(P
) loop
11476 Visit_Node
(Node_Id
(F
));
11483 -- An Itype whose parent is not being copied definitely
11484 -- should NOT be copied, since it does not belong in any
11485 -- sense to the copied subtree.
11491 elsif F
in List_Range
11492 and then Parent
(List_Id
(F
)) = N
11494 Visit_List
(List_Id
(F
));
11503 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
11504 New_Itype
: Entity_Id
;
11509 -- Itypes that describe the designated type of access to subprograms
11510 -- have the structure of subprogram declarations, with signatures,
11511 -- etc. Either we duplicate the signatures completely, or choose to
11512 -- share such itypes, which is fine because their elaboration will
11513 -- have no side effects.
11515 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
11519 New_Itype
:= New_Copy
(Old_Itype
);
11521 -- The new Itype has all the attributes of the old one, and
11522 -- we just copy the contents of the entity. However, the back-end
11523 -- needs different names for debugging purposes, so we create a
11524 -- new internal name for it in all cases.
11526 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
11528 -- If our associated node is an entity that has already been copied,
11529 -- then set the associated node of the copy to point to the right
11530 -- copy. If we have copied an Itype that is itself the associated
11531 -- node of some previously copied Itype, then we set the right
11532 -- pointer in the other direction.
11534 if Present
(Actual_Map
) then
11536 -- Case of hash tables used
11538 if NCT_Hash_Tables_Used
then
11540 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
11542 if Present
(Ent
) then
11543 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
11546 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
11547 if Present
(Ent
) then
11548 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
11550 -- If the hash table has no association for this Itype and
11551 -- its associated node, enter one now.
11554 NCT_Itype_Assoc
.Set
11555 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
11558 -- Case of hash tables not used
11561 E
:= First_Elmt
(Actual_Map
);
11562 while Present
(E
) loop
11563 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
11564 Set_Associated_Node_For_Itype
11565 (New_Itype
, Node
(Next_Elmt
(E
)));
11568 if Is_Type
(Node
(E
))
11570 Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
11572 Set_Associated_Node_For_Itype
11573 (Node
(Next_Elmt
(E
)), New_Itype
);
11576 E
:= Next_Elmt
(Next_Elmt
(E
));
11581 if Present
(Freeze_Node
(New_Itype
)) then
11582 Set_Is_Frozen
(New_Itype
, False);
11583 Set_Freeze_Node
(New_Itype
, Empty
);
11586 -- Add new association to map
11588 if No
(Actual_Map
) then
11589 Actual_Map
:= New_Elmt_List
;
11592 Append_Elmt
(Old_Itype
, Actual_Map
);
11593 Append_Elmt
(New_Itype
, Actual_Map
);
11595 if NCT_Hash_Tables_Used
then
11596 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
11599 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
11601 if NCT_Table_Entries
> NCT_Hash_Threshold
then
11602 Build_NCT_Hash_Tables
;
11606 -- If a record subtype is simply copied, the entity list will be
11607 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
11609 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
11610 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
11613 -- Visit descendents that eventually get copied
11615 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
11617 if Is_Discrete_Type
(Old_Itype
) then
11618 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
11620 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
11621 -- ??? This should involve call to Visit_Field
11622 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
11624 elsif Is_Array_Type
(Old_Itype
) then
11625 if Present
(First_Index
(Old_Itype
)) then
11626 Visit_Field
(Union_Id
(List_Containing
11627 (First_Index
(Old_Itype
))),
11631 if Is_Packed
(Old_Itype
) then
11632 Visit_Field
(Union_Id
(Packed_Array_Type
(Old_Itype
)),
11642 procedure Visit_List
(L
: List_Id
) is
11645 if L
/= No_List
then
11648 while Present
(N
) loop
11659 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
11661 -- Start of processing for Visit_Node
11664 -- Handle case of an Itype, which must be copied
11666 if Has_Extension
(N
)
11667 and then Is_Itype
(N
)
11669 -- Nothing to do if already in the list. This can happen with an
11670 -- Itype entity that appears more than once in the tree.
11671 -- Note that we do not want to visit descendents in this case.
11673 -- Test for already in list when hash table is used
11675 if NCT_Hash_Tables_Used
then
11676 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
11680 -- Test for already in list when hash table not used
11686 if Present
(Actual_Map
) then
11687 E
:= First_Elmt
(Actual_Map
);
11688 while Present
(E
) loop
11689 if Node
(E
) = N
then
11692 E
:= Next_Elmt
(Next_Elmt
(E
));
11702 -- Visit descendents
11704 Visit_Field
(Field1
(N
), N
);
11705 Visit_Field
(Field2
(N
), N
);
11706 Visit_Field
(Field3
(N
), N
);
11707 Visit_Field
(Field4
(N
), N
);
11708 Visit_Field
(Field5
(N
), N
);
11711 -- Start of processing for New_Copy_Tree
11716 -- See if we should use hash table
11718 if No
(Actual_Map
) then
11719 NCT_Hash_Tables_Used
:= False;
11726 NCT_Table_Entries
:= 0;
11728 Elmt
:= First_Elmt
(Actual_Map
);
11729 while Present
(Elmt
) loop
11730 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
11735 if NCT_Table_Entries
> NCT_Hash_Threshold
then
11736 Build_NCT_Hash_Tables
;
11738 NCT_Hash_Tables_Used
:= False;
11743 -- Hash table set up if required, now start phase one by visiting
11744 -- top node (we will recursively visit the descendents).
11746 Visit_Node
(Source
);
11748 -- Now the second phase of the copy can start. First we process
11749 -- all the mapped entities, copying their descendents.
11751 if Present
(Actual_Map
) then
11754 New_Itype
: Entity_Id
;
11756 Elmt
:= First_Elmt
(Actual_Map
);
11757 while Present
(Elmt
) loop
11759 New_Itype
:= Node
(Elmt
);
11760 Copy_Itype_With_Replacement
(New_Itype
);
11766 -- Now we can copy the actual tree
11768 return Copy_Node_With_Replacement
(Source
);
11771 -------------------------
11772 -- New_External_Entity --
11773 -------------------------
11775 function New_External_Entity
11776 (Kind
: Entity_Kind
;
11777 Scope_Id
: Entity_Id
;
11778 Sloc_Value
: Source_Ptr
;
11779 Related_Id
: Entity_Id
;
11780 Suffix
: Character;
11781 Suffix_Index
: Nat
:= 0;
11782 Prefix
: Character := ' ') return Entity_Id
11784 N
: constant Entity_Id
:=
11785 Make_Defining_Identifier
(Sloc_Value
,
11787 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
11790 Set_Ekind
(N
, Kind
);
11791 Set_Is_Internal
(N
, True);
11792 Append_Entity
(N
, Scope_Id
);
11793 Set_Public_Status
(N
);
11795 if Kind
in Type_Kind
then
11796 Init_Size_Align
(N
);
11800 end New_External_Entity
;
11802 -------------------------
11803 -- New_Internal_Entity --
11804 -------------------------
11806 function New_Internal_Entity
11807 (Kind
: Entity_Kind
;
11808 Scope_Id
: Entity_Id
;
11809 Sloc_Value
: Source_Ptr
;
11810 Id_Char
: Character) return Entity_Id
11812 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
11815 Set_Ekind
(N
, Kind
);
11816 Set_Is_Internal
(N
, True);
11817 Append_Entity
(N
, Scope_Id
);
11819 if Kind
in Type_Kind
then
11820 Init_Size_Align
(N
);
11824 end New_Internal_Entity
;
11830 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
11834 -- If we are pointing at a positional parameter, it is a member of a
11835 -- node list (the list of parameters), and the next parameter is the
11836 -- next node on the list, unless we hit a parameter association, then
11837 -- we shift to using the chain whose head is the First_Named_Actual in
11838 -- the parent, and then is threaded using the Next_Named_Actual of the
11839 -- Parameter_Association. All this fiddling is because the original node
11840 -- list is in the textual call order, and what we need is the
11841 -- declaration order.
11843 if Is_List_Member
(Actual_Id
) then
11844 N
:= Next
(Actual_Id
);
11846 if Nkind
(N
) = N_Parameter_Association
then
11847 return First_Named_Actual
(Parent
(Actual_Id
));
11853 return Next_Named_Actual
(Parent
(Actual_Id
));
11857 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
11859 Actual_Id
:= Next_Actual
(Actual_Id
);
11862 ---------------------
11863 -- No_Scalar_Parts --
11864 ---------------------
11866 function No_Scalar_Parts
(T
: Entity_Id
) return Boolean is
11870 if Is_Scalar_Type
(T
) then
11873 elsif Is_Array_Type
(T
) then
11874 return No_Scalar_Parts
(Component_Type
(T
));
11876 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
11877 C
:= First_Component_Or_Discriminant
(T
);
11878 while Present
(C
) loop
11879 if not No_Scalar_Parts
(Etype
(C
)) then
11882 Next_Component_Or_Discriminant
(C
);
11888 end No_Scalar_Parts
;
11890 -----------------------
11891 -- Normalize_Actuals --
11892 -----------------------
11894 -- Chain actuals according to formals of subprogram. If there are no named
11895 -- associations, the chain is simply the list of Parameter Associations,
11896 -- since the order is the same as the declaration order. If there are named
11897 -- associations, then the First_Named_Actual field in the N_Function_Call
11898 -- or N_Procedure_Call_Statement node points to the Parameter_Association
11899 -- node for the parameter that comes first in declaration order. The
11900 -- remaining named parameters are then chained in declaration order using
11901 -- Next_Named_Actual.
11903 -- This routine also verifies that the number of actuals is compatible with
11904 -- the number and default values of formals, but performs no type checking
11905 -- (type checking is done by the caller).
11907 -- If the matching succeeds, Success is set to True and the caller proceeds
11908 -- with type-checking. If the match is unsuccessful, then Success is set to
11909 -- False, and the caller attempts a different interpretation, if there is
11912 -- If the flag Report is on, the call is not overloaded, and a failure to
11913 -- match can be reported here, rather than in the caller.
11915 procedure Normalize_Actuals
11919 Success
: out Boolean)
11921 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
11922 Actual
: Node_Id
:= Empty
;
11923 Formal
: Entity_Id
;
11924 Last
: Node_Id
:= Empty
;
11925 First_Named
: Node_Id
:= Empty
;
11928 Formals_To_Match
: Integer := 0;
11929 Actuals_To_Match
: Integer := 0;
11931 procedure Chain
(A
: Node_Id
);
11932 -- Add named actual at the proper place in the list, using the
11933 -- Next_Named_Actual link.
11935 function Reporting
return Boolean;
11936 -- Determines if an error is to be reported. To report an error, we
11937 -- need Report to be True, and also we do not report errors caused
11938 -- by calls to init procs that occur within other init procs. Such
11939 -- errors must always be cascaded errors, since if all the types are
11940 -- declared correctly, the compiler will certainly build decent calls!
11946 procedure Chain
(A
: Node_Id
) is
11950 -- Call node points to first actual in list
11952 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
11955 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
11959 Set_Next_Named_Actual
(Last
, Empty
);
11966 function Reporting
return Boolean is
11971 elsif not Within_Init_Proc
then
11974 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
11982 -- Start of processing for Normalize_Actuals
11985 if Is_Access_Type
(S
) then
11987 -- The name in the call is a function call that returns an access
11988 -- to subprogram. The designated type has the list of formals.
11990 Formal
:= First_Formal
(Designated_Type
(S
));
11992 Formal
:= First_Formal
(S
);
11995 while Present
(Formal
) loop
11996 Formals_To_Match
:= Formals_To_Match
+ 1;
11997 Next_Formal
(Formal
);
12000 -- Find if there is a named association, and verify that no positional
12001 -- associations appear after named ones.
12003 if Present
(Actuals
) then
12004 Actual
:= First
(Actuals
);
12007 while Present
(Actual
)
12008 and then Nkind
(Actual
) /= N_Parameter_Association
12010 Actuals_To_Match
:= Actuals_To_Match
+ 1;
12014 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
12016 -- Most common case: positional notation, no defaults
12021 elsif Actuals_To_Match
> Formals_To_Match
then
12023 -- Too many actuals: will not work
12026 if Is_Entity_Name
(Name
(N
)) then
12027 Error_Msg_N
("too many arguments in call to&", Name
(N
));
12029 Error_Msg_N
("too many arguments in call", N
);
12037 First_Named
:= Actual
;
12039 while Present
(Actual
) loop
12040 if Nkind
(Actual
) /= N_Parameter_Association
then
12042 ("positional parameters not allowed after named ones", Actual
);
12047 Actuals_To_Match
:= Actuals_To_Match
+ 1;
12053 if Present
(Actuals
) then
12054 Actual
:= First
(Actuals
);
12057 Formal
:= First_Formal
(S
);
12058 while Present
(Formal
) loop
12060 -- Match the formals in order. If the corresponding actual is
12061 -- positional, nothing to do. Else scan the list of named actuals
12062 -- to find the one with the right name.
12064 if Present
(Actual
)
12065 and then Nkind
(Actual
) /= N_Parameter_Association
12068 Actuals_To_Match
:= Actuals_To_Match
- 1;
12069 Formals_To_Match
:= Formals_To_Match
- 1;
12072 -- For named parameters, search the list of actuals to find
12073 -- one that matches the next formal name.
12075 Actual
:= First_Named
;
12077 while Present
(Actual
) loop
12078 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
12081 Actuals_To_Match
:= Actuals_To_Match
- 1;
12082 Formals_To_Match
:= Formals_To_Match
- 1;
12090 if Ekind
(Formal
) /= E_In_Parameter
12091 or else No
(Default_Value
(Formal
))
12094 if (Comes_From_Source
(S
)
12095 or else Sloc
(S
) = Standard_Location
)
12096 and then Is_Overloadable
(S
)
12100 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
12102 (Nkind
(Parent
(N
)) = N_Function_Call
12104 Nkind
(Parent
(N
)) = N_Parameter_Association
))
12105 and then Ekind
(S
) /= E_Function
12107 Set_Etype
(N
, Etype
(S
));
12109 Error_Msg_Name_1
:= Chars
(S
);
12110 Error_Msg_Sloc
:= Sloc
(S
);
12112 ("missing argument for parameter & " &
12113 "in call to % declared #", N
, Formal
);
12116 elsif Is_Overloadable
(S
) then
12117 Error_Msg_Name_1
:= Chars
(S
);
12119 -- Point to type derivation that generated the
12122 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
12125 ("missing argument for parameter & " &
12126 "in call to % (inherited) #", N
, Formal
);
12130 ("missing argument for parameter &", N
, Formal
);
12138 Formals_To_Match
:= Formals_To_Match
- 1;
12143 Next_Formal
(Formal
);
12146 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
12153 -- Find some superfluous named actual that did not get
12154 -- attached to the list of associations.
12156 Actual
:= First
(Actuals
);
12157 while Present
(Actual
) loop
12158 if Nkind
(Actual
) = N_Parameter_Association
12159 and then Actual
/= Last
12160 and then No
(Next_Named_Actual
(Actual
))
12162 Error_Msg_N
("unmatched actual & in call",
12163 Selector_Name
(Actual
));
12174 end Normalize_Actuals
;
12176 --------------------------------
12177 -- Note_Possible_Modification --
12178 --------------------------------
12180 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
12181 Modification_Comes_From_Source
: constant Boolean :=
12182 Comes_From_Source
(Parent
(N
));
12188 -- Loop to find referenced entity, if there is one
12195 if Is_Entity_Name
(Exp
) then
12196 Ent
:= Entity
(Exp
);
12198 -- If the entity is missing, it is an undeclared identifier,
12199 -- and there is nothing to annotate.
12205 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
12207 P
: constant Node_Id
:= Prefix
(Exp
);
12210 -- In formal verification mode, keep track of all reads and
12211 -- writes through explicit dereferences.
12214 SPARK_Specific
.Generate_Dereference
(N
, 'm');
12217 if Nkind
(P
) = N_Selected_Component
12219 Entry_Formal
(Entity
(Selector_Name
(P
))))
12221 -- Case of a reference to an entry formal
12223 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
12225 elsif Nkind
(P
) = N_Identifier
12226 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
12227 and then Present
(Expression
(Parent
(Entity
(P
))))
12228 and then Nkind
(Expression
(Parent
(Entity
(P
))))
12231 -- Case of a reference to a value on which side effects have
12234 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
12243 elsif Nkind
(Exp
) = N_Type_Conversion
12244 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
12246 Exp
:= Expression
(Exp
);
12249 elsif Nkind
(Exp
) = N_Slice
12250 or else Nkind
(Exp
) = N_Indexed_Component
12251 or else Nkind
(Exp
) = N_Selected_Component
12253 Exp
:= Prefix
(Exp
);
12260 -- Now look for entity being referenced
12262 if Present
(Ent
) then
12263 if Is_Object
(Ent
) then
12264 if Comes_From_Source
(Exp
)
12265 or else Modification_Comes_From_Source
12267 -- Give warning if pragma unmodified given and we are
12268 -- sure this is a modification.
12270 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
12272 ("??pragma Unmodified given for &!", N
, Ent
);
12275 Set_Never_Set_In_Source
(Ent
, False);
12278 Set_Is_True_Constant
(Ent
, False);
12279 Set_Current_Value
(Ent
, Empty
);
12280 Set_Is_Known_Null
(Ent
, False);
12282 if not Can_Never_Be_Null
(Ent
) then
12283 Set_Is_Known_Non_Null
(Ent
, False);
12286 -- Follow renaming chain
12288 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
12289 and then Present
(Renamed_Object
(Ent
))
12291 Exp
:= Renamed_Object
(Ent
);
12294 -- The expression may be the renaming of a subcomponent of an
12295 -- array or container. The assignment to the subcomponent is
12296 -- a modification of the container.
12298 elsif Comes_From_Source
(Original_Node
(Exp
))
12299 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
12300 N_Indexed_Component
)
12302 Exp
:= Prefix
(Original_Node
(Exp
));
12306 -- Generate a reference only if the assignment comes from
12307 -- source. This excludes, for example, calls to a dispatching
12308 -- assignment operation when the left-hand side is tagged.
12310 if Modification_Comes_From_Source
or else SPARK_Mode
then
12311 Generate_Reference
(Ent
, Exp
, 'm');
12313 -- If the target of the assignment is the bound variable
12314 -- in an iterator, indicate that the corresponding array
12315 -- or container is also modified.
12317 if Ada_Version
>= Ada_2012
12319 Nkind
(Parent
(Ent
)) = N_Iterator_Specification
12322 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
12325 -- TBD : in the full version of the construct, the
12326 -- domain of iteration can be given by an expression.
12328 if Is_Entity_Name
(Domain
) then
12329 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
12330 Set_Is_True_Constant
(Entity
(Domain
), False);
12331 Set_Never_Set_In_Source
(Entity
(Domain
), False);
12337 Check_Nested_Access
(Ent
);
12342 -- If we are sure this is a modification from source, and we know
12343 -- this modifies a constant, then give an appropriate warning.
12345 if Overlays_Constant
(Ent
)
12346 and then Modification_Comes_From_Source
12350 A
: constant Node_Id
:= Address_Clause
(Ent
);
12352 if Present
(A
) then
12354 Exp
: constant Node_Id
:= Expression
(A
);
12356 if Nkind
(Exp
) = N_Attribute_Reference
12357 and then Attribute_Name
(Exp
) = Name_Address
12358 and then Is_Entity_Name
(Prefix
(Exp
))
12360 Error_Msg_Sloc
:= Sloc
(A
);
12362 ("constant& may be modified via address "
12363 & "clause#??", N
, Entity
(Prefix
(Exp
)));
12373 end Note_Possible_Modification
;
12375 -------------------------
12376 -- Object_Access_Level --
12377 -------------------------
12379 -- Returns the static accessibility level of the view denoted by Obj. Note
12380 -- that the value returned is the result of a call to Scope_Depth. Only
12381 -- scope depths associated with dynamic scopes can actually be returned.
12382 -- Since only relative levels matter for accessibility checking, the fact
12383 -- that the distance between successive levels of accessibility is not
12384 -- always one is immaterial (invariant: if level(E2) is deeper than
12385 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
12387 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
12388 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
12389 -- Determine whether N is a construct of the form
12390 -- Some_Type (Operand._tag'Address)
12391 -- This construct appears in the context of dispatching calls.
12393 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
12394 -- An explicit dereference is created when removing side-effects from
12395 -- expressions for constraint checking purposes. In this case a local
12396 -- access type is created for it. The correct access level is that of
12397 -- the original source node. We detect this case by noting that the
12398 -- prefix of the dereference is created by an object declaration whose
12399 -- initial expression is a reference.
12401 -----------------------------
12402 -- Is_Interface_Conversion --
12403 -----------------------------
12405 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
12408 Nkind
(N
) = N_Unchecked_Type_Conversion
12409 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
12410 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
12411 end Is_Interface_Conversion
;
12417 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
12418 Pref
: constant Node_Id
:= Prefix
(Obj
);
12420 if Is_Entity_Name
(Pref
)
12421 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
12422 and then Present
(Expression
(Parent
(Entity
(Pref
))))
12423 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
12425 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
12435 -- Start of processing for Object_Access_Level
12438 if Nkind
(Obj
) = N_Defining_Identifier
12439 or else Is_Entity_Name
(Obj
)
12441 if Nkind
(Obj
) = N_Defining_Identifier
then
12447 if Is_Prival
(E
) then
12448 E
:= Prival_Link
(E
);
12451 -- If E is a type then it denotes a current instance. For this case
12452 -- we add one to the normal accessibility level of the type to ensure
12453 -- that current instances are treated as always being deeper than
12454 -- than the level of any visible named access type (see 3.10.2(21)).
12456 if Is_Type
(E
) then
12457 return Type_Access_Level
(E
) + 1;
12459 elsif Present
(Renamed_Object
(E
)) then
12460 return Object_Access_Level
(Renamed_Object
(E
));
12462 -- Similarly, if E is a component of the current instance of a
12463 -- protected type, any instance of it is assumed to be at a deeper
12464 -- level than the type. For a protected object (whose type is an
12465 -- anonymous protected type) its components are at the same level
12466 -- as the type itself.
12468 elsif not Is_Overloadable
(E
)
12469 and then Ekind
(Scope
(E
)) = E_Protected_Type
12470 and then Comes_From_Source
(Scope
(E
))
12472 return Type_Access_Level
(Scope
(E
)) + 1;
12475 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
12478 elsif Nkind
(Obj
) = N_Selected_Component
then
12479 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
12480 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12482 return Object_Access_Level
(Prefix
(Obj
));
12485 elsif Nkind
(Obj
) = N_Indexed_Component
then
12486 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
12487 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12489 return Object_Access_Level
(Prefix
(Obj
));
12492 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
12494 -- If the prefix is a selected access discriminant then we make a
12495 -- recursive call on the prefix, which will in turn check the level
12496 -- of the prefix object of the selected discriminant.
12498 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
12499 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
12501 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
12503 return Object_Access_Level
(Prefix
(Obj
));
12505 -- Detect an interface conversion in the context of a dispatching
12506 -- call. Use the original form of the conversion to find the access
12507 -- level of the operand.
12509 elsif Is_Interface
(Etype
(Obj
))
12510 and then Is_Interface_Conversion
(Prefix
(Obj
))
12511 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
12513 return Object_Access_Level
(Original_Node
(Obj
));
12515 elsif not Comes_From_Source
(Obj
) then
12517 Ref
: constant Node_Id
:= Reference_To
(Obj
);
12519 if Present
(Ref
) then
12520 return Object_Access_Level
(Ref
);
12522 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12527 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12530 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
12531 return Object_Access_Level
(Expression
(Obj
));
12533 elsif Nkind
(Obj
) = N_Function_Call
then
12535 -- Function results are objects, so we get either the access level of
12536 -- the function or, in the case of an indirect call, the level of the
12537 -- access-to-subprogram type. (This code is used for Ada 95, but it
12538 -- looks wrong, because it seems that we should be checking the level
12539 -- of the call itself, even for Ada 95. However, using the Ada 2005
12540 -- version of the code causes regressions in several tests that are
12541 -- compiled with -gnat95. ???)
12543 if Ada_Version
< Ada_2005
then
12544 if Is_Entity_Name
(Name
(Obj
)) then
12545 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
12547 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
12550 -- For Ada 2005, the level of the result object of a function call is
12551 -- defined to be the level of the call's innermost enclosing master.
12552 -- We determine that by querying the depth of the innermost enclosing
12556 Return_Master_Scope_Depth_Of_Call
: declare
12558 function Innermost_Master_Scope_Depth
12559 (N
: Node_Id
) return Uint
;
12560 -- Returns the scope depth of the given node's innermost
12561 -- enclosing dynamic scope (effectively the accessibility
12562 -- level of the innermost enclosing master).
12564 ----------------------------------
12565 -- Innermost_Master_Scope_Depth --
12566 ----------------------------------
12568 function Innermost_Master_Scope_Depth
12569 (N
: Node_Id
) return Uint
12571 Node_Par
: Node_Id
:= Parent
(N
);
12574 -- Locate the nearest enclosing node (by traversing Parents)
12575 -- that Defining_Entity can be applied to, and return the
12576 -- depth of that entity's nearest enclosing dynamic scope.
12578 while Present
(Node_Par
) loop
12579 case Nkind
(Node_Par
) is
12580 when N_Component_Declaration |
12581 N_Entry_Declaration |
12582 N_Formal_Object_Declaration |
12583 N_Formal_Type_Declaration |
12584 N_Full_Type_Declaration |
12585 N_Incomplete_Type_Declaration |
12586 N_Loop_Parameter_Specification |
12587 N_Object_Declaration |
12588 N_Protected_Type_Declaration |
12589 N_Private_Extension_Declaration |
12590 N_Private_Type_Declaration |
12591 N_Subtype_Declaration |
12592 N_Function_Specification |
12593 N_Procedure_Specification |
12594 N_Task_Type_Declaration |
12596 N_Generic_Instantiation |
12598 N_Implicit_Label_Declaration |
12599 N_Package_Declaration |
12600 N_Single_Task_Declaration |
12601 N_Subprogram_Declaration |
12602 N_Generic_Declaration |
12603 N_Renaming_Declaration |
12604 N_Block_Statement |
12605 N_Formal_Subprogram_Declaration |
12606 N_Abstract_Subprogram_Declaration |
12608 N_Exception_Declaration |
12609 N_Formal_Package_Declaration |
12610 N_Number_Declaration |
12611 N_Package_Specification |
12612 N_Parameter_Specification |
12613 N_Single_Protected_Declaration |
12617 (Nearest_Dynamic_Scope
12618 (Defining_Entity
(Node_Par
)));
12624 Node_Par
:= Parent
(Node_Par
);
12627 pragma Assert
(False);
12629 -- Should never reach the following return
12631 return Scope_Depth
(Current_Scope
) + 1;
12632 end Innermost_Master_Scope_Depth
;
12634 -- Start of processing for Return_Master_Scope_Depth_Of_Call
12637 return Innermost_Master_Scope_Depth
(Obj
);
12638 end Return_Master_Scope_Depth_Of_Call
;
12641 -- For convenience we handle qualified expressions, even though they
12642 -- aren't technically object names.
12644 elsif Nkind
(Obj
) = N_Qualified_Expression
then
12645 return Object_Access_Level
(Expression
(Obj
));
12647 -- Otherwise return the scope level of Standard. (If there are cases
12648 -- that fall through to this point they will be treated as having
12649 -- global accessibility for now. ???)
12652 return Scope_Depth
(Standard_Standard
);
12654 end Object_Access_Level
;
12656 --------------------------------------
12657 -- Original_Corresponding_Operation --
12658 --------------------------------------
12660 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
12662 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
12665 -- If S is an inherited primitive S2 the original corresponding
12666 -- operation of S is the original corresponding operation of S2
12668 if Present
(Alias
(S
))
12669 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
12671 return Original_Corresponding_Operation
(Alias
(S
));
12673 -- If S overrides an inherited subprogram S2 the original corresponding
12674 -- operation of S is the original corresponding operation of S2
12676 elsif Present
(Overridden_Operation
(S
)) then
12677 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
12679 -- otherwise it is S itself
12684 end Original_Corresponding_Operation
;
12686 -----------------------
12687 -- Private_Component --
12688 -----------------------
12690 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
12691 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
12693 function Trace_Components
12695 Check
: Boolean) return Entity_Id
;
12696 -- Recursive function that does the work, and checks against circular
12697 -- definition for each subcomponent type.
12699 ----------------------
12700 -- Trace_Components --
12701 ----------------------
12703 function Trace_Components
12705 Check
: Boolean) return Entity_Id
12707 Btype
: constant Entity_Id
:= Base_Type
(T
);
12708 Component
: Entity_Id
;
12710 Candidate
: Entity_Id
:= Empty
;
12713 if Check
and then Btype
= Ancestor
then
12714 Error_Msg_N
("circular type definition", Type_Id
);
12718 if Is_Private_Type
(Btype
)
12719 and then not Is_Generic_Type
(Btype
)
12721 if Present
(Full_View
(Btype
))
12722 and then Is_Record_Type
(Full_View
(Btype
))
12723 and then not Is_Frozen
(Btype
)
12725 -- To indicate that the ancestor depends on a private type, the
12726 -- current Btype is sufficient. However, to check for circular
12727 -- definition we must recurse on the full view.
12729 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
12731 if Candidate
= Any_Type
then
12741 elsif Is_Array_Type
(Btype
) then
12742 return Trace_Components
(Component_Type
(Btype
), True);
12744 elsif Is_Record_Type
(Btype
) then
12745 Component
:= First_Entity
(Btype
);
12746 while Present
(Component
)
12747 and then Comes_From_Source
(Component
)
12749 -- Skip anonymous types generated by constrained components
12751 if not Is_Type
(Component
) then
12752 P
:= Trace_Components
(Etype
(Component
), True);
12754 if Present
(P
) then
12755 if P
= Any_Type
then
12763 Next_Entity
(Component
);
12771 end Trace_Components
;
12773 -- Start of processing for Private_Component
12776 return Trace_Components
(Type_Id
, False);
12777 end Private_Component
;
12779 ---------------------------
12780 -- Primitive_Names_Match --
12781 ---------------------------
12783 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
12785 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
12786 -- Given an internal name, returns the corresponding non-internal name
12788 ------------------------
12789 -- Non_Internal_Name --
12790 ------------------------
12792 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
12794 Get_Name_String
(Chars
(E
));
12795 Name_Len
:= Name_Len
- 1;
12797 end Non_Internal_Name
;
12799 -- Start of processing for Primitive_Names_Match
12802 pragma Assert
(Present
(E1
) and then Present
(E2
));
12804 return Chars
(E1
) = Chars
(E2
)
12806 (not Is_Internal_Name
(Chars
(E1
))
12807 and then Is_Internal_Name
(Chars
(E2
))
12808 and then Non_Internal_Name
(E2
) = Chars
(E1
))
12810 (not Is_Internal_Name
(Chars
(E2
))
12811 and then Is_Internal_Name
(Chars
(E1
))
12812 and then Non_Internal_Name
(E1
) = Chars
(E2
))
12814 (Is_Predefined_Dispatching_Operation
(E1
)
12815 and then Is_Predefined_Dispatching_Operation
(E2
)
12816 and then Same_TSS
(E1
, E2
))
12818 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
12819 end Primitive_Names_Match
;
12821 -----------------------
12822 -- Process_End_Label --
12823 -----------------------
12825 procedure Process_End_Label
12834 Label_Ref
: Boolean;
12835 -- Set True if reference to end label itself is required
12838 -- Gets set to the operator symbol or identifier that references the
12839 -- entity Ent. For the child unit case, this is the identifier from the
12840 -- designator. For other cases, this is simply Endl.
12842 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
12843 -- N is an identifier node that appears as a parent unit reference in
12844 -- the case where Ent is a child unit. This procedure generates an
12845 -- appropriate cross-reference entry. E is the corresponding entity.
12847 -------------------------
12848 -- Generate_Parent_Ref --
12849 -------------------------
12851 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
12853 -- If names do not match, something weird, skip reference
12855 if Chars
(E
) = Chars
(N
) then
12857 -- Generate the reference. We do NOT consider this as a reference
12858 -- for unreferenced symbol purposes.
12860 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
12862 if Style_Check
then
12863 Style
.Check_Identifier
(N
, E
);
12866 end Generate_Parent_Ref
;
12868 -- Start of processing for Process_End_Label
12871 -- If no node, ignore. This happens in some error situations, and
12872 -- also for some internally generated structures where no end label
12873 -- references are required in any case.
12879 -- Nothing to do if no End_Label, happens for internally generated
12880 -- constructs where we don't want an end label reference anyway. Also
12881 -- nothing to do if Endl is a string literal, which means there was
12882 -- some prior error (bad operator symbol)
12884 Endl
:= End_Label
(N
);
12886 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
12890 -- Reference node is not in extended main source unit
12892 if not In_Extended_Main_Source_Unit
(N
) then
12894 -- Generally we do not collect references except for the extended
12895 -- main source unit. The one exception is the 'e' entry for a
12896 -- package spec, where it is useful for a client to have the
12897 -- ending information to define scopes.
12903 Label_Ref
:= False;
12905 -- For this case, we can ignore any parent references, but we
12906 -- need the package name itself for the 'e' entry.
12908 if Nkind
(Endl
) = N_Designator
then
12909 Endl
:= Identifier
(Endl
);
12913 -- Reference is in extended main source unit
12918 -- For designator, generate references for the parent entries
12920 if Nkind
(Endl
) = N_Designator
then
12922 -- Generate references for the prefix if the END line comes from
12923 -- source (otherwise we do not need these references) We climb the
12924 -- scope stack to find the expected entities.
12926 if Comes_From_Source
(Endl
) then
12927 Nam
:= Name
(Endl
);
12928 Scop
:= Current_Scope
;
12929 while Nkind
(Nam
) = N_Selected_Component
loop
12930 Scop
:= Scope
(Scop
);
12931 exit when No
(Scop
);
12932 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
12933 Nam
:= Prefix
(Nam
);
12936 if Present
(Scop
) then
12937 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
12941 Endl
:= Identifier
(Endl
);
12945 -- If the end label is not for the given entity, then either we have
12946 -- some previous error, or this is a generic instantiation for which
12947 -- we do not need to make a cross-reference in this case anyway. In
12948 -- either case we simply ignore the call.
12950 if Chars
(Ent
) /= Chars
(Endl
) then
12954 -- If label was really there, then generate a normal reference and then
12955 -- adjust the location in the end label to point past the name (which
12956 -- should almost always be the semicolon).
12958 Loc
:= Sloc
(Endl
);
12960 if Comes_From_Source
(Endl
) then
12962 -- If a label reference is required, then do the style check and
12963 -- generate an l-type cross-reference entry for the label
12966 if Style_Check
then
12967 Style
.Check_Identifier
(Endl
, Ent
);
12970 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
12973 -- Set the location to point past the label (normally this will
12974 -- mean the semicolon immediately following the label). This is
12975 -- done for the sake of the 'e' or 't' entry generated below.
12977 Get_Decoded_Name_String
(Chars
(Endl
));
12978 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
12981 -- In SPARK mode, no missing label is allowed for packages and
12982 -- subprogram bodies. Detect those cases by testing whether
12983 -- Process_End_Label was called for a body (Typ = 't') or a package.
12985 if Restriction_Check_Required
(SPARK_05
)
12986 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
12988 Error_Msg_Node_1
:= Endl
;
12989 Check_SPARK_Restriction
("`END &` required", Endl
, Force
=> True);
12993 -- Now generate the e/t reference
12995 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
12997 -- Restore Sloc, in case modified above, since we have an identifier
12998 -- and the normal Sloc should be left set in the tree.
13000 Set_Sloc
(Endl
, Loc
);
13001 end Process_End_Label
;
13007 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
13008 Seen
: Boolean := False;
13010 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
13011 -- Determine whether node N denotes a reference to Id. If this is the
13012 -- case, set global flag Seen to True and stop the traversal.
13018 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
13020 if Is_Entity_Name
(N
)
13021 and then Present
(Entity
(N
))
13022 and then Entity
(N
) = Id
13031 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
13033 -- Start of processing for Referenced
13036 Inspect_Expression
(Expr
);
13040 ------------------------------------
13041 -- References_Generic_Formal_Type --
13042 ------------------------------------
13044 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
13046 function Process
(N
: Node_Id
) return Traverse_Result
;
13047 -- Process one node in search for generic formal type
13053 function Process
(N
: Node_Id
) return Traverse_Result
is
13055 if Nkind
(N
) in N_Has_Entity
then
13057 E
: constant Entity_Id
:= Entity
(N
);
13059 if Present
(E
) then
13060 if Is_Generic_Type
(E
) then
13062 elsif Present
(Etype
(E
))
13063 and then Is_Generic_Type
(Etype
(E
))
13074 function Traverse
is new Traverse_Func
(Process
);
13075 -- Traverse tree to look for generic type
13078 if Inside_A_Generic
then
13079 return Traverse
(N
) = Abandon
;
13083 end References_Generic_Formal_Type
;
13085 --------------------
13086 -- Remove_Homonym --
13087 --------------------
13089 procedure Remove_Homonym
(E
: Entity_Id
) is
13090 Prev
: Entity_Id
:= Empty
;
13094 if E
= Current_Entity
(E
) then
13095 if Present
(Homonym
(E
)) then
13096 Set_Current_Entity
(Homonym
(E
));
13098 Set_Name_Entity_Id
(Chars
(E
), Empty
);
13102 H
:= Current_Entity
(E
);
13103 while Present
(H
) and then H
/= E
loop
13108 -- If E is not on the homonym chain, nothing to do
13110 if Present
(H
) then
13111 Set_Homonym
(Prev
, Homonym
(E
));
13114 end Remove_Homonym
;
13116 ---------------------
13117 -- Rep_To_Pos_Flag --
13118 ---------------------
13120 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
13122 return New_Occurrence_Of
13123 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
13124 end Rep_To_Pos_Flag
;
13126 --------------------
13127 -- Require_Entity --
13128 --------------------
13130 procedure Require_Entity
(N
: Node_Id
) is
13132 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
13133 if Total_Errors_Detected
/= 0 then
13134 Set_Entity
(N
, Any_Id
);
13136 raise Program_Error
;
13139 end Require_Entity
;
13141 ------------------------------
13142 -- Requires_Transient_Scope --
13143 ------------------------------
13145 -- A transient scope is required when variable-sized temporaries are
13146 -- allocated in the primary or secondary stack, or when finalization
13147 -- actions must be generated before the next instruction.
13149 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
13150 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
13152 -- Start of processing for Requires_Transient_Scope
13155 -- This is a private type which is not completed yet. This can only
13156 -- happen in a default expression (of a formal parameter or of a
13157 -- record component). Do not expand transient scope in this case
13162 -- Do not expand transient scope for non-existent procedure return
13164 elsif Typ
= Standard_Void_Type
then
13167 -- Elementary types do not require a transient scope
13169 elsif Is_Elementary_Type
(Typ
) then
13172 -- Generally, indefinite subtypes require a transient scope, since the
13173 -- back end cannot generate temporaries, since this is not a valid type
13174 -- for declaring an object. It might be possible to relax this in the
13175 -- future, e.g. by declaring the maximum possible space for the type.
13177 elsif Is_Indefinite_Subtype
(Typ
) then
13180 -- Functions returning tagged types may dispatch on result so their
13181 -- returned value is allocated on the secondary stack. Controlled
13182 -- type temporaries need finalization.
13184 elsif Is_Tagged_Type
(Typ
)
13185 or else Has_Controlled_Component
(Typ
)
13187 return not Is_Value_Type
(Typ
);
13191 elsif Is_Record_Type
(Typ
) then
13195 Comp
:= First_Entity
(Typ
);
13196 while Present
(Comp
) loop
13197 if Ekind
(Comp
) = E_Component
13198 and then Requires_Transient_Scope
(Etype
(Comp
))
13202 Next_Entity
(Comp
);
13209 -- String literal types never require transient scope
13211 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
13214 -- Array type. Note that we already know that this is a constrained
13215 -- array, since unconstrained arrays will fail the indefinite test.
13217 elsif Is_Array_Type
(Typ
) then
13219 -- If component type requires a transient scope, the array does too
13221 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
13224 -- Otherwise, we only need a transient scope if the size depends on
13225 -- the value of one or more discriminants.
13228 return Size_Depends_On_Discriminant
(Typ
);
13231 -- All other cases do not require a transient scope
13236 end Requires_Transient_Scope
;
13238 --------------------------
13239 -- Reset_Analyzed_Flags --
13240 --------------------------
13242 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
13244 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
13245 -- Function used to reset Analyzed flags in tree. Note that we do
13246 -- not reset Analyzed flags in entities, since there is no need to
13247 -- reanalyze entities, and indeed, it is wrong to do so, since it
13248 -- can result in generating auxiliary stuff more than once.
13250 --------------------
13251 -- Clear_Analyzed --
13252 --------------------
13254 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
13256 if not Has_Extension
(N
) then
13257 Set_Analyzed
(N
, False);
13261 end Clear_Analyzed
;
13263 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
13265 -- Start of processing for Reset_Analyzed_Flags
13268 Reset_Analyzed
(N
);
13269 end Reset_Analyzed_Flags
;
13271 --------------------------------
13272 -- Returns_Unconstrained_Type --
13273 --------------------------------
13275 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
13277 return Ekind
(Subp
) = E_Function
13278 and then not Is_Scalar_Type
(Etype
(Subp
))
13279 and then not Is_Access_Type
(Etype
(Subp
))
13280 and then not Is_Constrained
(Etype
(Subp
));
13281 end Returns_Unconstrained_Type
;
13283 ---------------------------
13284 -- Safe_To_Capture_Value --
13285 ---------------------------
13287 function Safe_To_Capture_Value
13290 Cond
: Boolean := False) return Boolean
13293 -- The only entities for which we track constant values are variables
13294 -- which are not renamings, constants, out parameters, and in out
13295 -- parameters, so check if we have this case.
13297 -- Note: it may seem odd to track constant values for constants, but in
13298 -- fact this routine is used for other purposes than simply capturing
13299 -- the value. In particular, the setting of Known[_Non]_Null.
13301 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
13303 Ekind
(Ent
) = E_Constant
13305 Ekind
(Ent
) = E_Out_Parameter
13307 Ekind
(Ent
) = E_In_Out_Parameter
13311 -- For conditionals, we also allow loop parameters and all formals,
13312 -- including in parameters.
13316 (Ekind
(Ent
) = E_Loop_Parameter
13318 Ekind
(Ent
) = E_In_Parameter
)
13322 -- For all other cases, not just unsafe, but impossible to capture
13323 -- Current_Value, since the above are the only entities which have
13324 -- Current_Value fields.
13330 -- Skip if volatile or aliased, since funny things might be going on in
13331 -- these cases which we cannot necessarily track. Also skip any variable
13332 -- for which an address clause is given, or whose address is taken. Also
13333 -- never capture value of library level variables (an attempt to do so
13334 -- can occur in the case of package elaboration code).
13336 if Treat_As_Volatile
(Ent
)
13337 or else Is_Aliased
(Ent
)
13338 or else Present
(Address_Clause
(Ent
))
13339 or else Address_Taken
(Ent
)
13340 or else (Is_Library_Level_Entity
(Ent
)
13341 and then Ekind
(Ent
) = E_Variable
)
13346 -- OK, all above conditions are met. We also require that the scope of
13347 -- the reference be the same as the scope of the entity, not counting
13348 -- packages and blocks and loops.
13351 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
13352 R_Scope
: Entity_Id
;
13355 R_Scope
:= Current_Scope
;
13356 while R_Scope
/= Standard_Standard
loop
13357 exit when R_Scope
= E_Scope
;
13359 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
13362 R_Scope
:= Scope
(R_Scope
);
13367 -- We also require that the reference does not appear in a context
13368 -- where it is not sure to be executed (i.e. a conditional context
13369 -- or an exception handler). We skip this if Cond is True, since the
13370 -- capturing of values from conditional tests handles this ok.
13383 -- Seems dubious that case expressions are not handled here ???
13386 while Present
(P
) loop
13387 if Nkind
(P
) = N_If_Statement
13388 or else Nkind
(P
) = N_Case_Statement
13389 or else (Nkind
(P
) in N_Short_Circuit
13390 and then Desc
= Right_Opnd
(P
))
13391 or else (Nkind
(P
) = N_If_Expression
13392 and then Desc
/= First
(Expressions
(P
)))
13393 or else Nkind
(P
) = N_Exception_Handler
13394 or else Nkind
(P
) = N_Selective_Accept
13395 or else Nkind
(P
) = N_Conditional_Entry_Call
13396 or else Nkind
(P
) = N_Timed_Entry_Call
13397 or else Nkind
(P
) = N_Asynchronous_Select
13404 -- A special Ada 2012 case: the original node may be part
13405 -- of the else_actions of a conditional expression, in which
13406 -- case it might not have been expanded yet, and appears in
13407 -- a non-syntactic list of actions. In that case it is clearly
13408 -- not safe to save a value.
13411 and then Is_List_Member
(Desc
)
13412 and then No
(Parent
(List_Containing
(Desc
)))
13420 -- OK, looks safe to set value
13423 end Safe_To_Capture_Value
;
13429 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
13430 K1
: constant Node_Kind
:= Nkind
(N1
);
13431 K2
: constant Node_Kind
:= Nkind
(N2
);
13434 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
13435 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
13437 return Chars
(N1
) = Chars
(N2
);
13439 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
13440 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
13442 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
13443 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
13454 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
13455 N1
: constant Node_Id
:= Original_Node
(Node1
);
13456 N2
: constant Node_Id
:= Original_Node
(Node2
);
13457 -- We do the tests on original nodes, since we are most interested
13458 -- in the original source, not any expansion that got in the way.
13460 K1
: constant Node_Kind
:= Nkind
(N1
);
13461 K2
: constant Node_Kind
:= Nkind
(N2
);
13464 -- First case, both are entities with same entity
13466 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
13468 EN1
: constant Entity_Id
:= Entity
(N1
);
13469 EN2
: constant Entity_Id
:= Entity
(N2
);
13471 if Present
(EN1
) and then Present
(EN2
)
13472 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
13473 or else Is_Formal
(EN1
))
13481 -- Second case, selected component with same selector, same record
13483 if K1
= N_Selected_Component
13484 and then K2
= N_Selected_Component
13485 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
13487 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
13489 -- Third case, indexed component with same subscripts, same array
13491 elsif K1
= N_Indexed_Component
13492 and then K2
= N_Indexed_Component
13493 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
13498 E1
:= First
(Expressions
(N1
));
13499 E2
:= First
(Expressions
(N2
));
13500 while Present
(E1
) loop
13501 if not Same_Value
(E1
, E2
) then
13512 -- Fourth case, slice of same array with same bounds
13515 and then K2
= N_Slice
13516 and then Nkind
(Discrete_Range
(N1
)) = N_Range
13517 and then Nkind
(Discrete_Range
(N2
)) = N_Range
13518 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
13519 Low_Bound
(Discrete_Range
(N2
)))
13520 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
13521 High_Bound
(Discrete_Range
(N2
)))
13523 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
13525 -- All other cases, not clearly the same object
13536 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
13541 elsif not Is_Constrained
(T1
)
13542 and then not Is_Constrained
(T2
)
13543 and then Base_Type
(T1
) = Base_Type
(T2
)
13547 -- For now don't bother with case of identical constraints, to be
13548 -- fiddled with later on perhaps (this is only used for optimization
13549 -- purposes, so it is not critical to do a best possible job)
13560 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
13562 if Compile_Time_Known_Value
(Node1
)
13563 and then Compile_Time_Known_Value
(Node2
)
13564 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
13567 elsif Same_Object
(Node1
, Node2
) then
13574 ------------------------
13575 -- Scope_Is_Transient --
13576 ------------------------
13578 function Scope_Is_Transient
return Boolean is
13580 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
13581 end Scope_Is_Transient
;
13587 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
13592 while Scop
/= Standard_Standard
loop
13593 Scop
:= Scope
(Scop
);
13595 if Scop
= Scope2
then
13603 --------------------------
13604 -- Scope_Within_Or_Same --
13605 --------------------------
13607 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
13612 while Scop
/= Standard_Standard
loop
13613 if Scop
= Scope2
then
13616 Scop
:= Scope
(Scop
);
13621 end Scope_Within_Or_Same
;
13623 --------------------
13624 -- Set_Convention --
13625 --------------------
13627 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
13629 Basic_Set_Convention
(E
, Val
);
13632 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
13633 and then Has_Foreign_Convention
(E
)
13635 Set_Can_Use_Internal_Rep
(E
, False);
13637 end Set_Convention
;
13639 ------------------------
13640 -- Set_Current_Entity --
13641 ------------------------
13643 -- The given entity is to be set as the currently visible definition of its
13644 -- associated name (i.e. the Node_Id associated with its name). All we have
13645 -- to do is to get the name from the identifier, and then set the
13646 -- associated Node_Id to point to the given entity.
13648 procedure Set_Current_Entity
(E
: Entity_Id
) is
13650 Set_Name_Entity_Id
(Chars
(E
), E
);
13651 end Set_Current_Entity
;
13653 ---------------------------
13654 -- Set_Debug_Info_Needed --
13655 ---------------------------
13657 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
13659 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
13660 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
13661 -- Used to set debug info in a related node if not set already
13663 --------------------------------------
13664 -- Set_Debug_Info_Needed_If_Not_Set --
13665 --------------------------------------
13667 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
13670 and then not Needs_Debug_Info
(E
)
13672 Set_Debug_Info_Needed
(E
);
13674 -- For a private type, indicate that the full view also needs
13675 -- debug information.
13678 and then Is_Private_Type
(E
)
13679 and then Present
(Full_View
(E
))
13681 Set_Debug_Info_Needed
(Full_View
(E
));
13684 end Set_Debug_Info_Needed_If_Not_Set
;
13686 -- Start of processing for Set_Debug_Info_Needed
13689 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
13690 -- indicates that Debug_Info_Needed is never required for the entity.
13693 or else Debug_Info_Off
(T
)
13698 -- Set flag in entity itself. Note that we will go through the following
13699 -- circuitry even if the flag is already set on T. That's intentional,
13700 -- it makes sure that the flag will be set in subsidiary entities.
13702 Set_Needs_Debug_Info
(T
);
13704 -- Set flag on subsidiary entities if not set already
13706 if Is_Object
(T
) then
13707 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
13709 elsif Is_Type
(T
) then
13710 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
13712 if Is_Record_Type
(T
) then
13714 Ent
: Entity_Id
:= First_Entity
(T
);
13716 while Present
(Ent
) loop
13717 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
13722 -- For a class wide subtype, we also need debug information
13723 -- for the equivalent type.
13725 if Ekind
(T
) = E_Class_Wide_Subtype
then
13726 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
13729 elsif Is_Array_Type
(T
) then
13730 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
13733 Indx
: Node_Id
:= First_Index
(T
);
13735 while Present
(Indx
) loop
13736 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
13737 Indx
:= Next_Index
(Indx
);
13741 -- For a packed array type, we also need debug information for
13742 -- the type used to represent the packed array. Conversely, we
13743 -- also need it for the former if we need it for the latter.
13745 if Is_Packed
(T
) then
13746 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
13749 if Is_Packed_Array_Type
(T
) then
13750 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
13753 elsif Is_Access_Type
(T
) then
13754 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
13756 elsif Is_Private_Type
(T
) then
13757 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
13759 elsif Is_Protected_Type
(T
) then
13760 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
13763 end Set_Debug_Info_Needed
;
13765 ---------------------------------
13766 -- Set_Entity_With_Style_Check --
13767 ---------------------------------
13769 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
13770 Val_Actual
: Entity_Id
;
13774 -- Unconditionally set the entity
13776 Set_Entity
(N
, Val
);
13778 -- Check for No_Implementation_Identifiers
13780 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
13782 -- We have an implementation defined entity if it is marked as
13783 -- implementation defined, or is defined in a package marked as
13784 -- implementation defined. However, library packages themselves
13785 -- are excluded (we don't want to flag Interfaces itself, just
13786 -- the entities within it).
13788 if (Is_Implementation_Defined
(Val
)
13790 Is_Implementation_Defined
(Scope
(Val
)))
13791 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
13792 and then Is_Library_Level_Entity
(Val
))
13794 Check_Restriction
(No_Implementation_Identifiers
, N
);
13798 -- Do the style check
13801 and then not Suppress_Style_Checks
(Val
)
13802 and then not In_Instance
13804 if Nkind
(N
) = N_Identifier
then
13806 elsif Nkind
(N
) = N_Expanded_Name
then
13807 Nod
:= Selector_Name
(N
);
13812 -- A special situation arises for derived operations, where we want
13813 -- to do the check against the parent (since the Sloc of the derived
13814 -- operation points to the derived type declaration itself).
13817 while not Comes_From_Source
(Val_Actual
)
13818 and then Nkind
(Val_Actual
) in N_Entity
13819 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
13820 or else Is_Subprogram
(Val_Actual
)
13821 or else Is_Generic_Subprogram
(Val_Actual
))
13822 and then Present
(Alias
(Val_Actual
))
13824 Val_Actual
:= Alias
(Val_Actual
);
13827 -- Renaming declarations for generic actuals do not come from source,
13828 -- and have a different name from that of the entity they rename, so
13829 -- there is no style check to perform here.
13831 if Chars
(Nod
) = Chars
(Val_Actual
) then
13832 Style
.Check_Identifier
(Nod
, Val_Actual
);
13836 Set_Entity
(N
, Val
);
13837 end Set_Entity_With_Style_Check
;
13839 ------------------------
13840 -- Set_Name_Entity_Id --
13841 ------------------------
13843 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
13845 Set_Name_Table_Info
(Id
, Int
(Val
));
13846 end Set_Name_Entity_Id
;
13848 ---------------------
13849 -- Set_Next_Actual --
13850 ---------------------
13852 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
13854 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
13855 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
13857 end Set_Next_Actual
;
13859 ----------------------------------
13860 -- Set_Optimize_Alignment_Flags --
13861 ----------------------------------
13863 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
13865 if Optimize_Alignment
= 'S' then
13866 Set_Optimize_Alignment_Space
(E
);
13867 elsif Optimize_Alignment
= 'T' then
13868 Set_Optimize_Alignment_Time
(E
);
13870 end Set_Optimize_Alignment_Flags
;
13872 -----------------------
13873 -- Set_Public_Status --
13874 -----------------------
13876 procedure Set_Public_Status
(Id
: Entity_Id
) is
13877 S
: constant Entity_Id
:= Current_Scope
;
13879 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
13880 -- Determines if E is defined within handled statement sequence or
13881 -- an if statement, returns True if so, False otherwise.
13883 ----------------------
13884 -- Within_HSS_Or_If --
13885 ----------------------
13887 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
13890 N
:= Declaration_Node
(E
);
13897 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
13903 end Within_HSS_Or_If
;
13905 -- Start of processing for Set_Public_Status
13908 -- Everything in the scope of Standard is public
13910 if S
= Standard_Standard
then
13911 Set_Is_Public
(Id
);
13913 -- Entity is definitely not public if enclosing scope is not public
13915 elsif not Is_Public
(S
) then
13918 -- An object or function declaration that occurs in a handled sequence
13919 -- of statements or within an if statement is the declaration for a
13920 -- temporary object or local subprogram generated by the expander. It
13921 -- never needs to be made public and furthermore, making it public can
13922 -- cause back end problems.
13924 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
13925 N_Function_Specification
)
13926 and then Within_HSS_Or_If
(Id
)
13930 -- Entities in public packages or records are public
13932 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
13933 Set_Is_Public
(Id
);
13935 -- The bounds of an entry family declaration can generate object
13936 -- declarations that are visible to the back-end, e.g. in the
13937 -- the declaration of a composite type that contains tasks.
13939 elsif Is_Concurrent_Type
(S
)
13940 and then not Has_Completion
(S
)
13941 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
13943 Set_Is_Public
(Id
);
13945 end Set_Public_Status
;
13947 -----------------------------
13948 -- Set_Referenced_Modified --
13949 -----------------------------
13951 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
13955 -- Deal with indexed or selected component where prefix is modified
13957 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
13958 Pref
:= Prefix
(N
);
13960 -- If prefix is access type, then it is the designated object that is
13961 -- being modified, which means we have no entity to set the flag on.
13963 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
13966 -- Otherwise chase the prefix
13969 Set_Referenced_Modified
(Pref
, Out_Param
);
13972 -- Otherwise see if we have an entity name (only other case to process)
13974 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
13975 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
13976 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
13978 end Set_Referenced_Modified
;
13980 ----------------------------
13981 -- Set_Scope_Is_Transient --
13982 ----------------------------
13984 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
13986 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
13987 end Set_Scope_Is_Transient
;
13989 -------------------
13990 -- Set_Size_Info --
13991 -------------------
13993 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
13995 -- We copy Esize, but not RM_Size, since in general RM_Size is
13996 -- subtype specific and does not get inherited by all subtypes.
13998 Set_Esize
(T1
, Esize
(T2
));
13999 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
14001 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
14003 Is_Discrete_Or_Fixed_Point_Type
(T2
)
14005 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
14008 Set_Alignment
(T1
, Alignment
(T2
));
14011 --------------------
14012 -- Static_Boolean --
14013 --------------------
14015 function Static_Boolean
(N
: Node_Id
) return Uint
is
14017 Analyze_And_Resolve
(N
, Standard_Boolean
);
14020 or else Error_Posted
(N
)
14021 or else Etype
(N
) = Any_Type
14026 if Is_Static_Expression
(N
) then
14027 if not Raises_Constraint_Error
(N
) then
14028 return Expr_Value
(N
);
14033 elsif Etype
(N
) = Any_Type
then
14037 Flag_Non_Static_Expr
14038 ("static boolean expression required here", N
);
14041 end Static_Boolean
;
14043 --------------------
14044 -- Static_Integer --
14045 --------------------
14047 function Static_Integer
(N
: Node_Id
) return Uint
is
14049 Analyze_And_Resolve
(N
, Any_Integer
);
14052 or else Error_Posted
(N
)
14053 or else Etype
(N
) = Any_Type
14058 if Is_Static_Expression
(N
) then
14059 if not Raises_Constraint_Error
(N
) then
14060 return Expr_Value
(N
);
14065 elsif Etype
(N
) = Any_Type
then
14069 Flag_Non_Static_Expr
14070 ("static integer expression required here", N
);
14073 end Static_Integer
;
14075 --------------------------
14076 -- Statically_Different --
14077 --------------------------
14079 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
14080 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
14081 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
14083 return Is_Entity_Name
(R1
)
14084 and then Is_Entity_Name
(R2
)
14085 and then Entity
(R1
) /= Entity
(R2
)
14086 and then not Is_Formal
(Entity
(R1
))
14087 and then not Is_Formal
(Entity
(R2
));
14088 end Statically_Different
;
14090 --------------------------------------
14091 -- Subject_To_Loop_Entry_Attributes --
14092 --------------------------------------
14094 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
14100 -- The expansion mechanism transform a loop subject to at least one
14101 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
14102 -- the conditional part.
14104 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
14105 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
14107 Stmt
:= Original_Node
(N
);
14111 Nkind
(Stmt
) = N_Loop_Statement
14112 and then Present
(Identifier
(Stmt
))
14113 and then Present
(Entity
(Identifier
(Stmt
)))
14114 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
14115 end Subject_To_Loop_Entry_Attributes
;
14117 -----------------------------
14118 -- Subprogram_Access_Level --
14119 -----------------------------
14121 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
14123 if Present
(Alias
(Subp
)) then
14124 return Subprogram_Access_Level
(Alias
(Subp
));
14126 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
14128 end Subprogram_Access_Level
;
14130 -------------------------------
14131 -- Support_Atomic_Primitives --
14132 -------------------------------
14134 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
14138 -- Verify the alignment of Typ is known
14140 if not Known_Alignment
(Typ
) then
14144 if Known_Static_Esize
(Typ
) then
14145 Size
:= UI_To_Int
(Esize
(Typ
));
14147 -- If the Esize (Object_Size) is unknown at compile time, look at the
14148 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
14150 elsif Known_Static_RM_Size
(Typ
) then
14151 Size
:= UI_To_Int
(RM_Size
(Typ
));
14153 -- Otherwise, the size is considered to be unknown.
14159 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
14160 -- Typ is properly aligned.
14163 when 8 |
16 |
32 |
64 =>
14164 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
14168 end Support_Atomic_Primitives
;
14174 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
14176 if Debug_Flag_W
then
14177 for J
in 0 .. Scope_Stack
.Last
loop
14182 Write_Name
(Chars
(E
));
14183 Write_Str
(" from ");
14184 Write_Location
(Sloc
(N
));
14189 -----------------------
14190 -- Transfer_Entities --
14191 -----------------------
14193 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
14194 Ent
: Entity_Id
:= First_Entity
(From
);
14201 if (Last_Entity
(To
)) = Empty
then
14202 Set_First_Entity
(To
, Ent
);
14204 Set_Next_Entity
(Last_Entity
(To
), Ent
);
14207 Set_Last_Entity
(To
, Last_Entity
(From
));
14209 while Present
(Ent
) loop
14210 Set_Scope
(Ent
, To
);
14212 if not Is_Public
(Ent
) then
14213 Set_Public_Status
(Ent
);
14216 and then Ekind
(Ent
) = E_Record_Subtype
14219 -- The components of the propagated Itype must be public
14225 Comp
:= First_Entity
(Ent
);
14226 while Present
(Comp
) loop
14227 Set_Is_Public
(Comp
);
14228 Next_Entity
(Comp
);
14237 Set_First_Entity
(From
, Empty
);
14238 Set_Last_Entity
(From
, Empty
);
14239 end Transfer_Entities
;
14241 -----------------------
14242 -- Type_Access_Level --
14243 -----------------------
14245 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
14249 Btyp
:= Base_Type
(Typ
);
14251 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
14252 -- simply use the level where the type is declared. This is true for
14253 -- stand-alone object declarations, and for anonymous access types
14254 -- associated with components the level is the same as that of the
14255 -- enclosing composite type. However, special treatment is needed for
14256 -- the cases of access parameters, return objects of an anonymous access
14257 -- type, and, in Ada 95, access discriminants of limited types.
14259 if Ekind
(Btyp
) in Access_Kind
then
14260 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
14262 -- If the type is a nonlocal anonymous access type (such as for
14263 -- an access parameter) we treat it as being declared at the
14264 -- library level to ensure that names such as X.all'access don't
14265 -- fail static accessibility checks.
14267 if not Is_Local_Anonymous_Access
(Typ
) then
14268 return Scope_Depth
(Standard_Standard
);
14270 -- If this is a return object, the accessibility level is that of
14271 -- the result subtype of the enclosing function. The test here is
14272 -- little complicated, because we have to account for extended
14273 -- return statements that have been rewritten as blocks, in which
14274 -- case we have to find and the Is_Return_Object attribute of the
14275 -- itype's associated object. It would be nice to find a way to
14276 -- simplify this test, but it doesn't seem worthwhile to add a new
14277 -- flag just for purposes of this test. ???
14279 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
14282 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
14283 N_Object_Declaration
14284 and then Is_Return_Object
14285 (Defining_Identifier
14286 (Associated_Node_For_Itype
(Btyp
))))
14292 Scop
:= Scope
(Scope
(Btyp
));
14293 while Present
(Scop
) loop
14294 exit when Ekind
(Scop
) = E_Function
;
14295 Scop
:= Scope
(Scop
);
14298 -- Treat the return object's type as having the level of the
14299 -- function's result subtype (as per RM05-6.5(5.3/2)).
14301 return Type_Access_Level
(Etype
(Scop
));
14306 Btyp
:= Root_Type
(Btyp
);
14308 -- The accessibility level of anonymous access types associated with
14309 -- discriminants is that of the current instance of the type, and
14310 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
14312 -- AI-402: access discriminants have accessibility based on the
14313 -- object rather than the type in Ada 2005, so the above paragraph
14316 -- ??? Needs completion with rules from AI-416
14318 if Ada_Version
<= Ada_95
14319 and then Ekind
(Typ
) = E_Anonymous_Access_Type
14320 and then Present
(Associated_Node_For_Itype
(Typ
))
14321 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
14322 N_Discriminant_Specification
14324 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
14328 -- Return library level for a generic formal type. This is done because
14329 -- RM(10.3.2) says that "The statically deeper relationship does not
14330 -- apply to ... a descendant of a generic formal type". Rather than
14331 -- checking at each point where a static accessibility check is
14332 -- performed to see if we are dealing with a formal type, this rule is
14333 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
14334 -- return extreme values for a formal type; Deepest_Type_Access_Level
14335 -- returns Int'Last. By calling the appropriate function from among the
14336 -- two, we ensure that the static accessibility check will pass if we
14337 -- happen to run into a formal type. More specifically, we should call
14338 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
14339 -- call occurs as part of a static accessibility check and the error
14340 -- case is the case where the type's level is too shallow (as opposed
14343 if Is_Generic_Type
(Root_Type
(Btyp
)) then
14344 return Scope_Depth
(Standard_Standard
);
14347 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
14348 end Type_Access_Level
;
14350 ------------------------------------
14351 -- Type_Without_Stream_Operation --
14352 ------------------------------------
14354 function Type_Without_Stream_Operation
14356 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
14358 BT
: constant Entity_Id
:= Base_Type
(T
);
14359 Op_Missing
: Boolean;
14362 if not Restriction_Active
(No_Default_Stream_Attributes
) then
14366 if Is_Elementary_Type
(T
) then
14367 if Op
= TSS_Null
then
14369 No
(TSS
(BT
, TSS_Stream_Read
))
14370 or else No
(TSS
(BT
, TSS_Stream_Write
));
14373 Op_Missing
:= No
(TSS
(BT
, Op
));
14382 elsif Is_Array_Type
(T
) then
14383 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
14385 elsif Is_Record_Type
(T
) then
14391 Comp
:= First_Component
(T
);
14392 while Present
(Comp
) loop
14393 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
14395 if Present
(C_Typ
) then
14399 Next_Component
(Comp
);
14405 elsif Is_Private_Type
(T
)
14406 and then Present
(Full_View
(T
))
14408 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
14412 end Type_Without_Stream_Operation
;
14414 ----------------------------
14415 -- Unique_Defining_Entity --
14416 ----------------------------
14418 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
14420 return Unique_Entity
(Defining_Entity
(N
));
14421 end Unique_Defining_Entity
;
14423 -------------------
14424 -- Unique_Entity --
14425 -------------------
14427 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
14428 U
: Entity_Id
:= E
;
14434 if Present
(Full_View
(E
)) then
14435 U
:= Full_View
(E
);
14439 if Present
(Full_View
(E
)) then
14440 U
:= Full_View
(E
);
14443 when E_Package_Body
=>
14446 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
14450 U
:= Corresponding_Spec
(P
);
14452 when E_Subprogram_Body
=>
14455 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
14461 if Nkind
(P
) = N_Subprogram_Body_Stub
then
14462 if Present
(Library_Unit
(P
)) then
14464 -- Get to the function or procedure (generic) entity through
14465 -- the body entity.
14468 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
14471 U
:= Corresponding_Spec
(P
);
14474 when Formal_Kind
=>
14475 if Present
(Spec_Entity
(E
)) then
14476 U
:= Spec_Entity
(E
);
14490 function Unique_Name
(E
: Entity_Id
) return String is
14492 -- Names of E_Subprogram_Body or E_Package_Body entities are not
14493 -- reliable, as they may not include the overloading suffix. Instead,
14494 -- when looking for the name of E or one of its enclosing scope, we get
14495 -- the name of the corresponding Unique_Entity.
14497 function Get_Scoped_Name
(E
: Entity_Id
) return String;
14498 -- Return the name of E prefixed by all the names of the scopes to which
14499 -- E belongs, except for Standard.
14501 ---------------------
14502 -- Get_Scoped_Name --
14503 ---------------------
14505 function Get_Scoped_Name
(E
: Entity_Id
) return String is
14506 Name
: constant String := Get_Name_String
(Chars
(E
));
14508 if Has_Fully_Qualified_Name
(E
)
14509 or else Scope
(E
) = Standard_Standard
14513 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
14515 end Get_Scoped_Name
;
14517 -- Start of processing for Unique_Name
14520 if E
= Standard_Standard
then
14521 return Get_Name_String
(Name_Standard
);
14523 elsif Scope
(E
) = Standard_Standard
14524 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
14526 return Get_Name_String
(Name_Standard
) & "__" &
14527 Get_Name_String
(Chars
(E
));
14529 elsif Ekind
(E
) = E_Enumeration_Literal
then
14530 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
14533 return Get_Scoped_Name
(Unique_Entity
(E
));
14537 ---------------------
14538 -- Unit_Is_Visible --
14539 ---------------------
14541 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
14542 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
14543 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
14545 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
14546 -- For a child unit, check whether unit appears in a with_clause
14549 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
14550 -- Scan the context clause of one compilation unit looking for a
14551 -- with_clause for the unit in question.
14553 ----------------------------
14554 -- Unit_In_Parent_Context --
14555 ----------------------------
14557 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
14559 if Unit_In_Context
(Par_Unit
) then
14562 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
14563 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
14568 end Unit_In_Parent_Context
;
14570 ---------------------
14571 -- Unit_In_Context --
14572 ---------------------
14574 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
14578 Clause
:= First
(Context_Items
(Comp_Unit
));
14579 while Present
(Clause
) loop
14580 if Nkind
(Clause
) = N_With_Clause
then
14581 if Library_Unit
(Clause
) = U
then
14584 -- The with_clause may denote a renaming of the unit we are
14585 -- looking for, eg. Text_IO which renames Ada.Text_IO.
14588 Renamed_Entity
(Entity
(Name
(Clause
))) =
14589 Defining_Entity
(Unit
(U
))
14599 end Unit_In_Context
;
14601 -- Start of processing for Unit_Is_Visible
14604 -- The currrent unit is directly visible
14609 elsif Unit_In_Context
(Curr
) then
14612 -- If the current unit is a body, check the context of the spec
14614 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
14616 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
14617 and then not Acts_As_Spec
(Unit
(Curr
)))
14619 if Unit_In_Context
(Library_Unit
(Curr
)) then
14624 -- If the spec is a child unit, examine the parents
14626 if Is_Child_Unit
(Curr_Entity
) then
14627 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
14629 Unit_In_Parent_Context
14630 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
14632 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
14638 end Unit_Is_Visible
;
14640 ------------------------------
14641 -- Universal_Interpretation --
14642 ------------------------------
14644 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
14645 Index
: Interp_Index
;
14649 -- The argument may be a formal parameter of an operator or subprogram
14650 -- with multiple interpretations, or else an expression for an actual.
14652 if Nkind
(Opnd
) = N_Defining_Identifier
14653 or else not Is_Overloaded
(Opnd
)
14655 if Etype
(Opnd
) = Universal_Integer
14656 or else Etype
(Opnd
) = Universal_Real
14658 return Etype
(Opnd
);
14664 Get_First_Interp
(Opnd
, Index
, It
);
14665 while Present
(It
.Typ
) loop
14666 if It
.Typ
= Universal_Integer
14667 or else It
.Typ
= Universal_Real
14672 Get_Next_Interp
(Index
, It
);
14677 end Universal_Interpretation
;
14683 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
14685 -- Recurse to handle unlikely case of multiple levels of qualification
14687 if Nkind
(Expr
) = N_Qualified_Expression
then
14688 return Unqualify
(Expression
(Expr
));
14690 -- Normal case, not a qualified expression
14697 -----------------------
14698 -- Visible_Ancestors --
14699 -----------------------
14701 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
14707 pragma Assert
(Is_Record_Type
(Typ
)
14708 and then Is_Tagged_Type
(Typ
));
14710 -- Collect all the parents and progenitors of Typ. If the full-view of
14711 -- private parents and progenitors is available then it is used to
14712 -- generate the list of visible ancestors; otherwise their partial
14713 -- view is added to the resulting list.
14718 Use_Full_View
=> True);
14722 Ifaces_List
=> List_2
,
14723 Exclude_Parents
=> True,
14724 Use_Full_View
=> True);
14726 -- Join the two lists. Avoid duplications because an interface may
14727 -- simultaneously be parent and progenitor of a type.
14729 Elmt
:= First_Elmt
(List_2
);
14730 while Present
(Elmt
) loop
14731 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
14736 end Visible_Ancestors
;
14738 ----------------------
14739 -- Within_Init_Proc --
14740 ----------------------
14742 function Within_Init_Proc
return Boolean is
14746 S
:= Current_Scope
;
14747 while not Is_Overloadable
(S
) loop
14748 if S
= Standard_Standard
then
14755 return Is_Init_Proc
(S
);
14756 end Within_Init_Proc
;
14762 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
14763 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
14764 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
14766 Matching_Field
: Entity_Id
;
14767 -- Entity to give a more precise suggestion on how to write a one-
14768 -- element positional aggregate.
14770 function Has_One_Matching_Field
return Boolean;
14771 -- Determines if Expec_Type is a record type with a single component or
14772 -- discriminant whose type matches the found type or is one dimensional
14773 -- array whose component type matches the found type. In the case of
14774 -- one discriminant, we ignore the variant parts. That's not accurate,
14775 -- but good enough for the warning.
14777 ----------------------------
14778 -- Has_One_Matching_Field --
14779 ----------------------------
14781 function Has_One_Matching_Field
return Boolean is
14785 Matching_Field
:= Empty
;
14787 if Is_Array_Type
(Expec_Type
)
14788 and then Number_Dimensions
(Expec_Type
) = 1
14790 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
14792 -- Use type name if available. This excludes multidimensional
14793 -- arrays and anonymous arrays.
14795 if Comes_From_Source
(Expec_Type
) then
14796 Matching_Field
:= Expec_Type
;
14798 -- For an assignment, use name of target
14800 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
14801 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
14803 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
14808 elsif not Is_Record_Type
(Expec_Type
) then
14812 E
:= First_Entity
(Expec_Type
);
14817 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
14818 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
14827 if not Covers
(Etype
(E
), Found_Type
) then
14830 elsif Present
(Next_Entity
(E
))
14831 and then (Ekind
(E
) = E_Component
14832 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
14837 Matching_Field
:= E
;
14841 end Has_One_Matching_Field
;
14843 -- Start of processing for Wrong_Type
14846 -- Don't output message if either type is Any_Type, or if a message
14847 -- has already been posted for this node. We need to do the latter
14848 -- check explicitly (it is ordinarily done in Errout), because we
14849 -- are using ! to force the output of the error messages.
14851 if Expec_Type
= Any_Type
14852 or else Found_Type
= Any_Type
14853 or else Error_Posted
(Expr
)
14857 -- If one of the types is a Taft-Amendment type and the other it its
14858 -- completion, it must be an illegal use of a TAT in the spec, for
14859 -- which an error was already emitted. Avoid cascaded errors.
14861 elsif Is_Incomplete_Type
(Expec_Type
)
14862 and then Has_Completion_In_Body
(Expec_Type
)
14863 and then Full_View
(Expec_Type
) = Etype
(Expr
)
14867 elsif Is_Incomplete_Type
(Etype
(Expr
))
14868 and then Has_Completion_In_Body
(Etype
(Expr
))
14869 and then Full_View
(Etype
(Expr
)) = Expec_Type
14873 -- In an instance, there is an ongoing problem with completion of
14874 -- type derived from private types. Their structure is what Gigi
14875 -- expects, but the Etype is the parent type rather than the
14876 -- derived private type itself. Do not flag error in this case. The
14877 -- private completion is an entity without a parent, like an Itype.
14878 -- Similarly, full and partial views may be incorrect in the instance.
14879 -- There is no simple way to insure that it is consistent ???
14881 elsif In_Instance
then
14882 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
14884 (Has_Private_Declaration
(Expected_Type
)
14885 or else Has_Private_Declaration
(Etype
(Expr
)))
14886 and then No
(Parent
(Expected_Type
))
14892 -- An interesting special check. If the expression is parenthesized
14893 -- and its type corresponds to the type of the sole component of the
14894 -- expected record type, or to the component type of the expected one
14895 -- dimensional array type, then assume we have a bad aggregate attempt.
14897 if Nkind
(Expr
) in N_Subexpr
14898 and then Paren_Count
(Expr
) /= 0
14899 and then Has_One_Matching_Field
14901 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
14902 if Present
(Matching_Field
) then
14903 if Is_Array_Type
(Expec_Type
) then
14905 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
14909 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
14913 -- Another special check, if we are looking for a pool-specific access
14914 -- type and we found an E_Access_Attribute_Type, then we have the case
14915 -- of an Access attribute being used in a context which needs a pool-
14916 -- specific type, which is never allowed. The one extra check we make
14917 -- is that the expected designated type covers the Found_Type.
14919 elsif Is_Access_Type
(Expec_Type
)
14920 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
14921 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
14922 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
14924 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
14926 Error_Msg_N
-- CODEFIX
14927 ("result must be general access type!", Expr
);
14928 Error_Msg_NE
-- CODEFIX
14929 ("add ALL to }!", Expr
, Expec_Type
);
14931 -- Another special check, if the expected type is an integer type,
14932 -- but the expression is of type System.Address, and the parent is
14933 -- an addition or subtraction operation whose left operand is the
14934 -- expression in question and whose right operand is of an integral
14935 -- type, then this is an attempt at address arithmetic, so give
14936 -- appropriate message.
14938 elsif Is_Integer_Type
(Expec_Type
)
14939 and then Is_RTE
(Found_Type
, RE_Address
)
14940 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
14942 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
14943 and then Expr
= Left_Opnd
(Parent
(Expr
))
14944 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
14947 ("address arithmetic not predefined in package System",
14950 ("\possible missing with/use of System.Storage_Elements",
14954 -- If the expected type is an anonymous access type, as for access
14955 -- parameters and discriminants, the error is on the designated types.
14957 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
14958 if Comes_From_Source
(Expec_Type
) then
14959 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
14962 ("expected an access type with designated}",
14963 Expr
, Designated_Type
(Expec_Type
));
14966 if Is_Access_Type
(Found_Type
)
14967 and then not Comes_From_Source
(Found_Type
)
14970 ("\\found an access type with designated}!",
14971 Expr
, Designated_Type
(Found_Type
));
14973 if From_With_Type
(Found_Type
) then
14974 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
14975 Error_Msg_Qual_Level
:= 99;
14976 Error_Msg_NE
-- CODEFIX
14977 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
14978 Error_Msg_Qual_Level
:= 0;
14980 Error_Msg_NE
("found}!", Expr
, Found_Type
);
14984 -- Normal case of one type found, some other type expected
14987 -- If the names of the two types are the same, see if some number
14988 -- of levels of qualification will help. Don't try more than three
14989 -- levels, and if we get to standard, it's no use (and probably
14990 -- represents an error in the compiler) Also do not bother with
14991 -- internal scope names.
14994 Expec_Scope
: Entity_Id
;
14995 Found_Scope
: Entity_Id
;
14998 Expec_Scope
:= Expec_Type
;
14999 Found_Scope
:= Found_Type
;
15001 for Levels
in Int
range 0 .. 3 loop
15002 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
15003 Error_Msg_Qual_Level
:= Levels
;
15007 Expec_Scope
:= Scope
(Expec_Scope
);
15008 Found_Scope
:= Scope
(Found_Scope
);
15010 exit when Expec_Scope
= Standard_Standard
15011 or else Found_Scope
= Standard_Standard
15012 or else not Comes_From_Source
(Expec_Scope
)
15013 or else not Comes_From_Source
(Found_Scope
);
15017 if Is_Record_Type
(Expec_Type
)
15018 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
15020 Error_Msg_NE
("expected}!", Expr
,
15021 Corresponding_Remote_Type
(Expec_Type
));
15023 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
15026 if Is_Entity_Name
(Expr
)
15027 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
15029 Error_Msg_N
("\\found package name!", Expr
);
15031 elsif Is_Entity_Name
(Expr
)
15033 (Ekind
(Entity
(Expr
)) = E_Procedure
15035 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
15037 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
15039 ("found procedure name, possibly missing Access attribute!",
15043 ("\\found procedure name instead of function!", Expr
);
15046 elsif Nkind
(Expr
) = N_Function_Call
15047 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
15048 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
15049 and then No
(Parameter_Associations
(Expr
))
15052 ("found function name, possibly missing Access attribute!",
15055 -- Catch common error: a prefix or infix operator which is not
15056 -- directly visible because the type isn't.
15058 elsif Nkind
(Expr
) in N_Op
15059 and then Is_Overloaded
(Expr
)
15060 and then not Is_Immediately_Visible
(Expec_Type
)
15061 and then not Is_Potentially_Use_Visible
(Expec_Type
)
15062 and then not In_Use
(Expec_Type
)
15063 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
15066 ("operator of the type is not directly visible!", Expr
);
15068 elsif Ekind
(Found_Type
) = E_Void
15069 and then Present
(Parent
(Found_Type
))
15070 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
15072 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
15075 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
15078 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
15079 -- of the same modular type, and (M1 and M2) = 0 was intended.
15081 if Expec_Type
= Standard_Boolean
15082 and then Is_Modular_Integer_Type
(Found_Type
)
15083 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
15084 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
15087 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
15088 L
: constant Node_Id
:= Left_Opnd
(Op
);
15089 R
: constant Node_Id
:= Right_Opnd
(Op
);
15091 -- The case for the message is when the left operand of the
15092 -- comparison is the same modular type, or when it is an
15093 -- integer literal (or other universal integer expression),
15094 -- which would have been typed as the modular type if the
15095 -- parens had been there.
15097 if (Etype
(L
) = Found_Type
15099 Etype
(L
) = Universal_Integer
)
15100 and then Is_Integer_Type
(Etype
(R
))
15103 ("\\possible missing parens for modular operation", Expr
);
15108 -- Reset error message qualification indication
15110 Error_Msg_Qual_Level
:= 0;