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 Elists
; use Elists
;
31 with Errout
; use Errout
;
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
(Prag
: Node_Id
; Id
: Entity_Id
) is
216 Items
: constant Node_Id
:= Contract
(Id
);
221 -- The related context must have a contract and the item to be added
224 pragma Assert
(Present
(Items
));
225 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
227 Nam
:= Original_Aspect_Name
(Prag
);
229 -- Contract items related to [generic] packages. The applicable pragmas
235 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
236 if Nam_In
(Nam
, Name_Abstract_State
,
237 Name_Initial_Condition
,
240 Set_Next_Pragma
(Prag
, Classifications
(Items
));
241 Set_Classifications
(Items
, Prag
);
243 -- The pragma is not a proper contract item
249 -- Contract items related to package bodies. The applicable pragmas are:
252 elsif Ekind
(Id
) = E_Package_Body
then
253 if Nam
= Name_Refined_State
then
254 Set_Next_Pragma
(Prag
, Classifications
(Items
));
255 Set_Classifications
(Items
, Prag
);
257 -- The pragma is not a proper contract item
263 -- Contract items related to subprogram or entry declarations. The
264 -- applicable pragmas are:
274 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
275 or else Is_Generic_Subprogram
(Id
)
276 or else Is_Subprogram
(Id
)
278 if Nam_In
(Nam
, Name_Precondition
,
285 -- Before we add a precondition or postcondition to the list,
286 -- make sure we do not have a disallowed duplicate, which can
287 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
288 -- instead of the corresponding aspect.
290 if not From_Aspect_Specification
(Prag
)
291 and then Nam_In
(Nam
, Name_Pre_Class
,
298 N
:= Pre_Post_Conditions
(Items
);
299 while Present
(N
) loop
301 and then Original_Aspect_Name
(N
) = Nam
303 Error_Msg_Sloc
:= Sloc
(N
);
305 ("duplication of aspect for & given#", Prag
, Id
);
308 N
:= Next_Pragma
(N
);
313 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
314 Set_Pre_Post_Conditions
(Items
, Prag
);
316 elsif Nam_In
(Nam
, Name_Contract_Cases
, Name_Test_Case
) then
317 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
318 Set_Contract_Test_Cases
(Items
, Prag
);
320 elsif Nam_In
(Nam
, Name_Depends
, Name_Global
) then
321 Set_Next_Pragma
(Prag
, Classifications
(Items
));
322 Set_Classifications
(Items
, Prag
);
324 -- The pragma is not a proper contract item
330 -- Contract items related to subprogram bodies. The applicable pragmas
335 elsif Ekind
(Id
) = E_Subprogram_Body
then
336 if Nam_In
(Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
337 Set_Next_Pragma
(Prag
, Classifications
(Items
));
338 Set_Classifications
(Items
, Prag
);
340 -- The pragma is not a proper contract item
346 end Add_Contract_Item
;
348 ----------------------------
349 -- Add_Global_Declaration --
350 ----------------------------
352 procedure Add_Global_Declaration
(N
: Node_Id
) is
353 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
356 if No
(Declarations
(Aux_Node
)) then
357 Set_Declarations
(Aux_Node
, New_List
);
360 Append_To
(Declarations
(Aux_Node
), N
);
362 end Add_Global_Declaration
;
368 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
370 function Addressable
(V
: Uint
) return Boolean is
372 return V
= Uint_8
or else
378 function Addressable
(V
: Int
) return Boolean is
386 -----------------------
387 -- Alignment_In_Bits --
388 -----------------------
390 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
392 return Alignment
(E
) * System_Storage_Unit
;
393 end Alignment_In_Bits
;
395 ---------------------------------
396 -- Append_Inherited_Subprogram --
397 ---------------------------------
399 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
400 Par
: constant Entity_Id
:= Alias
(S
);
401 -- The parent subprogram
403 Scop
: constant Entity_Id
:= Scope
(Par
);
404 -- The scope of definition of the parent subprogram
406 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
407 -- The derived type of which S is a primitive operation
413 if Ekind
(Current_Scope
) = E_Package
414 and then In_Private_Part
(Current_Scope
)
415 and then Has_Private_Declaration
(Typ
)
416 and then Is_Tagged_Type
(Typ
)
417 and then Scop
= Current_Scope
419 -- The inherited operation is available at the earliest place after
420 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
421 -- relevant for type extensions. If the parent operation appears
422 -- after the type extension, the operation is not visible.
425 (Visible_Declarations
426 (Package_Specification
(Current_Scope
)));
427 while Present
(Decl
) loop
428 if Nkind
(Decl
) = N_Private_Extension_Declaration
429 and then Defining_Entity
(Decl
) = Typ
431 if Sloc
(Decl
) > Sloc
(Par
) then
432 Next_E
:= Next_Entity
(Par
);
433 Set_Next_Entity
(Par
, S
);
434 Set_Next_Entity
(S
, Next_E
);
446 -- If partial view is not a type extension, or it appears before the
447 -- subprogram declaration, insert normally at end of entity list.
449 Append_Entity
(S
, Current_Scope
);
450 end Append_Inherited_Subprogram
;
452 -----------------------------------------
453 -- Apply_Compile_Time_Constraint_Error --
454 -----------------------------------------
456 procedure Apply_Compile_Time_Constraint_Error
459 Reason
: RT_Exception_Code
;
460 Ent
: Entity_Id
:= Empty
;
461 Typ
: Entity_Id
:= Empty
;
462 Loc
: Source_Ptr
:= No_Location
;
463 Rep
: Boolean := True;
464 Warn
: Boolean := False)
466 Stat
: constant Boolean := Is_Static_Expression
(N
);
467 R_Stat
: constant Node_Id
:=
468 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
479 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
485 -- Now we replace the node by an N_Raise_Constraint_Error node
486 -- This does not need reanalyzing, so set it as analyzed now.
489 Set_Analyzed
(N
, True);
492 Set_Raises_Constraint_Error
(N
);
494 -- Now deal with possible local raise handling
496 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
498 -- If the original expression was marked as static, the result is
499 -- still marked as static, but the Raises_Constraint_Error flag is
500 -- always set so that further static evaluation is not attempted.
503 Set_Is_Static_Expression
(N
);
505 end Apply_Compile_Time_Constraint_Error
;
507 --------------------------------------
508 -- Available_Full_View_Of_Component --
509 --------------------------------------
511 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
512 ST
: constant Entity_Id
:= Scope
(T
);
513 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
515 return In_Open_Scopes
(ST
)
516 and then In_Open_Scopes
(SCT
)
517 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
518 end Available_Full_View_Of_Component
;
524 procedure Bad_Attribute
527 Warn
: Boolean := False)
530 Error_Msg_Warn
:= Warn
;
531 Error_Msg_N
("unrecognized attribute&<", N
);
533 -- Check for possible misspelling
535 Error_Msg_Name_1
:= First_Attribute_Name
;
536 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
537 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
538 Error_Msg_N
-- CODEFIX
539 ("\possible misspelling of %<", N
);
543 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
547 --------------------------------
548 -- Bad_Predicated_Subtype_Use --
549 --------------------------------
551 procedure Bad_Predicated_Subtype_Use
555 Suggest_Static
: Boolean := False)
558 if Has_Predicates
(Typ
) then
559 if Is_Generic_Actual_Type
(Typ
) then
560 Error_Msg_FE
(Msg
& "??", N
, Typ
);
561 Error_Msg_F
("\Program_Error will be raised at run time??", N
);
563 Make_Raise_Program_Error
(Sloc
(N
),
564 Reason
=> PE_Bad_Predicated_Generic_Type
));
567 Error_Msg_FE
(Msg
, N
, Typ
);
570 -- Emit an optional suggestion on how to remedy the error if the
571 -- context warrants it.
573 if Suggest_Static
and then Present
(Static_Predicate
(Typ
)) then
574 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
577 end Bad_Predicated_Subtype_Use
;
579 --------------------------
580 -- Build_Actual_Subtype --
581 --------------------------
583 function Build_Actual_Subtype
585 N
: Node_Or_Entity_Id
) return Node_Id
588 -- Normally Sloc (N), but may point to corresponding body in some cases
590 Constraints
: List_Id
;
596 Disc_Type
: Entity_Id
;
602 if Nkind
(N
) = N_Defining_Identifier
then
603 Obj
:= New_Reference_To
(N
, Loc
);
605 -- If this is a formal parameter of a subprogram declaration, and
606 -- we are compiling the body, we want the declaration for the
607 -- actual subtype to carry the source position of the body, to
608 -- prevent anomalies in gdb when stepping through the code.
610 if Is_Formal
(N
) then
612 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
614 if Nkind
(Decl
) = N_Subprogram_Declaration
615 and then Present
(Corresponding_Body
(Decl
))
617 Loc
:= Sloc
(Corresponding_Body
(Decl
));
626 if Is_Array_Type
(T
) then
627 Constraints
:= New_List
;
628 for J
in 1 .. Number_Dimensions
(T
) loop
630 -- Build an array subtype declaration with the nominal subtype and
631 -- the bounds of the actual. Add the declaration in front of the
632 -- local declarations for the subprogram, for analysis before any
633 -- reference to the formal in the body.
636 Make_Attribute_Reference
(Loc
,
638 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
639 Attribute_Name
=> Name_First
,
640 Expressions
=> New_List
(
641 Make_Integer_Literal
(Loc
, J
)));
644 Make_Attribute_Reference
(Loc
,
646 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
647 Attribute_Name
=> Name_Last
,
648 Expressions
=> New_List
(
649 Make_Integer_Literal
(Loc
, J
)));
651 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
654 -- If the type has unknown discriminants there is no constrained
655 -- subtype to build. This is never called for a formal or for a
656 -- lhs, so returning the type is ok ???
658 elsif Has_Unknown_Discriminants
(T
) then
662 Constraints
:= New_List
;
664 -- Type T is a generic derived type, inherit the discriminants from
667 if Is_Private_Type
(T
)
668 and then No
(Full_View
(T
))
670 -- T was flagged as an error if it was declared as a formal
671 -- derived type with known discriminants. In this case there
672 -- is no need to look at the parent type since T already carries
673 -- its own discriminants.
675 and then not Error_Posted
(T
)
677 Disc_Type
:= Etype
(Base_Type
(T
));
682 Discr
:= First_Discriminant
(Disc_Type
);
683 while Present
(Discr
) loop
684 Append_To
(Constraints
,
685 Make_Selected_Component
(Loc
,
687 Duplicate_Subexpr_No_Checks
(Obj
),
688 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
689 Next_Discriminant
(Discr
);
693 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
694 Set_Is_Internal
(Subt
);
697 Make_Subtype_Declaration
(Loc
,
698 Defining_Identifier
=> Subt
,
699 Subtype_Indication
=>
700 Make_Subtype_Indication
(Loc
,
701 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
703 Make_Index_Or_Discriminant_Constraint
(Loc
,
704 Constraints
=> Constraints
)));
706 Mark_Rewrite_Insertion
(Decl
);
708 end Build_Actual_Subtype
;
710 ---------------------------------------
711 -- Build_Actual_Subtype_Of_Component --
712 ---------------------------------------
714 function Build_Actual_Subtype_Of_Component
716 N
: Node_Id
) return Node_Id
718 Loc
: constant Source_Ptr
:= Sloc
(N
);
719 P
: constant Node_Id
:= Prefix
(N
);
722 Index_Typ
: Entity_Id
;
724 Desig_Typ
: Entity_Id
;
725 -- This is either a copy of T, or if T is an access type, then it is
726 -- the directly designated type of this access type.
728 function Build_Actual_Array_Constraint
return List_Id
;
729 -- If one or more of the bounds of the component depends on
730 -- discriminants, build actual constraint using the discriminants
733 function Build_Actual_Record_Constraint
return List_Id
;
734 -- Similar to previous one, for discriminated components constrained
735 -- by the discriminant of the enclosing object.
737 -----------------------------------
738 -- Build_Actual_Array_Constraint --
739 -----------------------------------
741 function Build_Actual_Array_Constraint
return List_Id
is
742 Constraints
: constant List_Id
:= New_List
;
750 Indx
:= First_Index
(Desig_Typ
);
751 while Present
(Indx
) loop
752 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
753 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
755 if Denotes_Discriminant
(Old_Lo
) then
757 Make_Selected_Component
(Loc
,
758 Prefix
=> New_Copy_Tree
(P
),
759 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
762 Lo
:= New_Copy_Tree
(Old_Lo
);
764 -- The new bound will be reanalyzed in the enclosing
765 -- declaration. For literal bounds that come from a type
766 -- declaration, the type of the context must be imposed, so
767 -- insure that analysis will take place. For non-universal
768 -- types this is not strictly necessary.
770 Set_Analyzed
(Lo
, False);
773 if Denotes_Discriminant
(Old_Hi
) then
775 Make_Selected_Component
(Loc
,
776 Prefix
=> New_Copy_Tree
(P
),
777 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
780 Hi
:= New_Copy_Tree
(Old_Hi
);
781 Set_Analyzed
(Hi
, False);
784 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
789 end Build_Actual_Array_Constraint
;
791 ------------------------------------
792 -- Build_Actual_Record_Constraint --
793 ------------------------------------
795 function Build_Actual_Record_Constraint
return List_Id
is
796 Constraints
: constant List_Id
:= New_List
;
801 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
802 while Present
(D
) loop
803 if Denotes_Discriminant
(Node
(D
)) then
804 D_Val
:= Make_Selected_Component
(Loc
,
805 Prefix
=> New_Copy_Tree
(P
),
806 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
809 D_Val
:= New_Copy_Tree
(Node
(D
));
812 Append
(D_Val
, Constraints
);
817 end Build_Actual_Record_Constraint
;
819 -- Start of processing for Build_Actual_Subtype_Of_Component
822 -- Why the test for Spec_Expression mode here???
824 if In_Spec_Expression
then
827 -- More comments for the rest of this body would be good ???
829 elsif Nkind
(N
) = N_Explicit_Dereference
then
830 if Is_Composite_Type
(T
)
831 and then not Is_Constrained
(T
)
832 and then not (Is_Class_Wide_Type
(T
)
833 and then Is_Constrained
(Root_Type
(T
)))
834 and then not Has_Unknown_Discriminants
(T
)
836 -- If the type of the dereference is already constrained, it is an
839 if Is_Array_Type
(Etype
(N
))
840 and then Is_Constrained
(Etype
(N
))
844 Remove_Side_Effects
(P
);
845 return Build_Actual_Subtype
(T
, N
);
852 if Ekind
(T
) = E_Access_Subtype
then
853 Desig_Typ
:= Designated_Type
(T
);
858 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
859 Id
:= First_Index
(Desig_Typ
);
860 while Present
(Id
) loop
861 Index_Typ
:= Underlying_Type
(Etype
(Id
));
863 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
865 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
867 Remove_Side_Effects
(P
);
869 Build_Component_Subtype
870 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
876 elsif Is_Composite_Type
(Desig_Typ
)
877 and then Has_Discriminants
(Desig_Typ
)
878 and then not Has_Unknown_Discriminants
(Desig_Typ
)
880 if Is_Private_Type
(Desig_Typ
)
881 and then No
(Discriminant_Constraint
(Desig_Typ
))
883 Desig_Typ
:= Full_View
(Desig_Typ
);
886 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
887 while Present
(D
) loop
888 if Denotes_Discriminant
(Node
(D
)) then
889 Remove_Side_Effects
(P
);
891 Build_Component_Subtype
(
892 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
899 -- If none of the above, the actual and nominal subtypes are the same
902 end Build_Actual_Subtype_Of_Component
;
904 -----------------------------
905 -- Build_Component_Subtype --
906 -----------------------------
908 function Build_Component_Subtype
911 T
: Entity_Id
) return Node_Id
917 -- Unchecked_Union components do not require component subtypes
919 if Is_Unchecked_Union
(T
) then
923 Subt
:= Make_Temporary
(Loc
, 'S');
924 Set_Is_Internal
(Subt
);
927 Make_Subtype_Declaration
(Loc
,
928 Defining_Identifier
=> Subt
,
929 Subtype_Indication
=>
930 Make_Subtype_Indication
(Loc
,
931 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
933 Make_Index_Or_Discriminant_Constraint
(Loc
,
936 Mark_Rewrite_Insertion
(Decl
);
938 end Build_Component_Subtype
;
940 ---------------------------
941 -- Build_Default_Subtype --
942 ---------------------------
944 function Build_Default_Subtype
946 N
: Node_Id
) return Entity_Id
948 Loc
: constant Source_Ptr
:= Sloc
(N
);
952 -- The base type that is to be constrained by the defaults
955 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
959 Bas
:= Base_Type
(T
);
961 -- If T is non-private but its base type is private, this is the
962 -- completion of a subtype declaration whose parent type is private
963 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
964 -- are to be found in the full view of the base.
966 if Is_Private_Type
(Bas
) and then Present
(Full_View
(Bas
)) then
967 Bas
:= Full_View
(Bas
);
970 Disc
:= First_Discriminant
(T
);
972 if No
(Discriminant_Default_Value
(Disc
)) then
977 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
978 Constraints
: constant List_Id
:= New_List
;
982 while Present
(Disc
) loop
983 Append_To
(Constraints
,
984 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
985 Next_Discriminant
(Disc
);
989 Make_Subtype_Declaration
(Loc
,
990 Defining_Identifier
=> Act
,
991 Subtype_Indication
=>
992 Make_Subtype_Indication
(Loc
,
993 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
995 Make_Index_Or_Discriminant_Constraint
(Loc
,
996 Constraints
=> Constraints
)));
998 Insert_Action
(N
, Decl
);
1002 end Build_Default_Subtype
;
1004 --------------------------------------------
1005 -- Build_Discriminal_Subtype_Of_Component --
1006 --------------------------------------------
1008 function Build_Discriminal_Subtype_Of_Component
1009 (T
: Entity_Id
) return Node_Id
1011 Loc
: constant Source_Ptr
:= Sloc
(T
);
1015 function Build_Discriminal_Array_Constraint
return List_Id
;
1016 -- If one or more of the bounds of the component depends on
1017 -- discriminants, build actual constraint using the discriminants
1020 function Build_Discriminal_Record_Constraint
return List_Id
;
1021 -- Similar to previous one, for discriminated components constrained by
1022 -- the discriminant of the enclosing object.
1024 ----------------------------------------
1025 -- Build_Discriminal_Array_Constraint --
1026 ----------------------------------------
1028 function Build_Discriminal_Array_Constraint
return List_Id
is
1029 Constraints
: constant List_Id
:= New_List
;
1037 Indx
:= First_Index
(T
);
1038 while Present
(Indx
) loop
1039 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1040 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1042 if Denotes_Discriminant
(Old_Lo
) then
1043 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1046 Lo
:= New_Copy_Tree
(Old_Lo
);
1049 if Denotes_Discriminant
(Old_Hi
) then
1050 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1053 Hi
:= New_Copy_Tree
(Old_Hi
);
1056 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1061 end Build_Discriminal_Array_Constraint
;
1063 -----------------------------------------
1064 -- Build_Discriminal_Record_Constraint --
1065 -----------------------------------------
1067 function Build_Discriminal_Record_Constraint
return List_Id
is
1068 Constraints
: constant List_Id
:= New_List
;
1073 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1074 while Present
(D
) loop
1075 if Denotes_Discriminant
(Node
(D
)) then
1077 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1080 D_Val
:= New_Copy_Tree
(Node
(D
));
1083 Append
(D_Val
, Constraints
);
1088 end Build_Discriminal_Record_Constraint
;
1090 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1093 if Ekind
(T
) = E_Array_Subtype
then
1094 Id
:= First_Index
(T
);
1095 while Present
(Id
) loop
1096 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
1097 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1099 return Build_Component_Subtype
1100 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1106 elsif Ekind
(T
) = E_Record_Subtype
1107 and then Has_Discriminants
(T
)
1108 and then not Has_Unknown_Discriminants
(T
)
1110 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1111 while Present
(D
) loop
1112 if Denotes_Discriminant
(Node
(D
)) then
1113 return Build_Component_Subtype
1114 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1121 -- If none of the above, the actual and nominal subtypes are the same
1124 end Build_Discriminal_Subtype_Of_Component
;
1126 ------------------------------
1127 -- Build_Elaboration_Entity --
1128 ------------------------------
1130 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1131 Loc
: constant Source_Ptr
:= Sloc
(N
);
1133 Elab_Ent
: Entity_Id
;
1135 procedure Set_Package_Name
(Ent
: Entity_Id
);
1136 -- Given an entity, sets the fully qualified name of the entity in
1137 -- Name_Buffer, with components separated by double underscores. This
1138 -- is a recursive routine that climbs the scope chain to Standard.
1140 ----------------------
1141 -- Set_Package_Name --
1142 ----------------------
1144 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1146 if Scope
(Ent
) /= Standard_Standard
then
1147 Set_Package_Name
(Scope
(Ent
));
1150 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1152 Name_Buffer
(Name_Len
+ 1) := '_';
1153 Name_Buffer
(Name_Len
+ 2) := '_';
1154 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1155 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1159 Get_Name_String
(Chars
(Ent
));
1161 end Set_Package_Name
;
1163 -- Start of processing for Build_Elaboration_Entity
1166 -- Ignore if already constructed
1168 if Present
(Elaboration_Entity
(Spec_Id
)) then
1172 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1173 -- no role in analysis.
1179 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1180 -- name with dots replaced by double underscore. We have to manually
1181 -- construct this name, since it will be elaborated in the outer scope,
1182 -- and thus will not have the unit name automatically prepended.
1184 Set_Package_Name
(Spec_Id
);
1185 Add_Str_To_Name_Buffer
("_E");
1187 -- Create elaboration counter
1189 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1190 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1193 Make_Object_Declaration
(Loc
,
1194 Defining_Identifier
=> Elab_Ent
,
1195 Object_Definition
=>
1196 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1197 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1199 Push_Scope
(Standard_Standard
);
1200 Add_Global_Declaration
(Decl
);
1203 -- Reset True_Constant indication, since we will indeed assign a value
1204 -- to the variable in the binder main. We also kill the Current_Value
1205 -- and Last_Assignment fields for the same reason.
1207 Set_Is_True_Constant
(Elab_Ent
, False);
1208 Set_Current_Value
(Elab_Ent
, Empty
);
1209 Set_Last_Assignment
(Elab_Ent
, Empty
);
1211 -- We do not want any further qualification of the name (if we did not
1212 -- do this, we would pick up the name of the generic package in the case
1213 -- of a library level generic instantiation).
1215 Set_Has_Qualified_Name
(Elab_Ent
);
1216 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1217 end Build_Elaboration_Entity
;
1219 --------------------------------
1220 -- Build_Explicit_Dereference --
1221 --------------------------------
1223 procedure Build_Explicit_Dereference
1227 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1230 -- An entity of a type with a reference aspect is overloaded with
1231 -- both interpretations: with and without the dereference. Now that
1232 -- the dereference is made explicit, set the type of the node properly,
1233 -- to prevent anomalies in the backend. Same if the expression is an
1234 -- overloaded function call whose return type has a reference aspect.
1236 if Is_Entity_Name
(Expr
) then
1237 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1239 elsif Nkind
(Expr
) = N_Function_Call
then
1240 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1243 Set_Is_Overloaded
(Expr
, False);
1245 Make_Explicit_Dereference
(Loc
,
1247 Make_Selected_Component
(Loc
,
1248 Prefix
=> Relocate_Node
(Expr
),
1249 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1250 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1251 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1252 end Build_Explicit_Dereference
;
1254 -----------------------------------
1255 -- Cannot_Raise_Constraint_Error --
1256 -----------------------------------
1258 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1260 if Compile_Time_Known_Value
(Expr
) then
1263 elsif Do_Range_Check
(Expr
) then
1266 elsif Raises_Constraint_Error
(Expr
) then
1270 case Nkind
(Expr
) is
1271 when N_Identifier
=>
1274 when N_Expanded_Name
=>
1277 when N_Selected_Component
=>
1278 return not Do_Discriminant_Check
(Expr
);
1280 when N_Attribute_Reference
=>
1281 if Do_Overflow_Check
(Expr
) then
1284 elsif No
(Expressions
(Expr
)) then
1292 N
:= First
(Expressions
(Expr
));
1293 while Present
(N
) loop
1294 if Cannot_Raise_Constraint_Error
(N
) then
1305 when N_Type_Conversion
=>
1306 if Do_Overflow_Check
(Expr
)
1307 or else Do_Length_Check
(Expr
)
1308 or else Do_Tag_Check
(Expr
)
1312 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1315 when N_Unchecked_Type_Conversion
=>
1316 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1319 if Do_Overflow_Check
(Expr
) then
1322 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1329 if Do_Division_Check
(Expr
)
1330 or else Do_Overflow_Check
(Expr
)
1335 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1337 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1356 N_Op_Shift_Right_Arithmetic |
1360 if Do_Overflow_Check
(Expr
) then
1364 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1366 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1373 end Cannot_Raise_Constraint_Error
;
1375 -----------------------------------------
1376 -- Check_Dynamically_Tagged_Expression --
1377 -----------------------------------------
1379 procedure Check_Dynamically_Tagged_Expression
1382 Related_Nod
: Node_Id
)
1385 pragma Assert
(Is_Tagged_Type
(Typ
));
1387 -- In order to avoid spurious errors when analyzing the expanded code,
1388 -- this check is done only for nodes that come from source and for
1389 -- actuals of generic instantiations.
1391 if (Comes_From_Source
(Related_Nod
)
1392 or else In_Generic_Actual
(Expr
))
1393 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1394 or else Is_Dynamically_Tagged
(Expr
))
1395 and then Is_Tagged_Type
(Typ
)
1396 and then not Is_Class_Wide_Type
(Typ
)
1398 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1400 end Check_Dynamically_Tagged_Expression
;
1402 -----------------------------------------------
1403 -- Check_Expression_Against_Static_Predicate --
1404 -----------------------------------------------
1406 procedure Check_Expression_Against_Static_Predicate
1411 -- When the predicate is static and the value of the expression is known
1412 -- at compile time, evaluate the predicate check. A type is non-static
1413 -- when it has aspect Dynamic_Predicate.
1415 if Compile_Time_Known_Value
(Expr
)
1416 and then Has_Predicates
(Typ
)
1417 and then Present
(Static_Predicate
(Typ
))
1418 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
1420 -- Either -gnatc is enabled or the expression is ok
1422 if Operating_Mode
< Generate_Code
1423 or else Eval_Static_Predicate_Check
(Expr
, Typ
)
1427 -- The expression is prohibited by the static predicate
1431 ("?static expression fails static predicate check on &",
1435 end Check_Expression_Against_Static_Predicate
;
1437 --------------------------
1438 -- Check_Fully_Declared --
1439 --------------------------
1441 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1443 if Ekind
(T
) = E_Incomplete_Type
then
1445 -- Ada 2005 (AI-50217): If the type is available through a limited
1446 -- with_clause, verify that its full view has been analyzed.
1448 if From_Limited_With
(T
)
1449 and then Present
(Non_Limited_View
(T
))
1450 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1452 -- The non-limited view is fully declared
1457 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1460 -- Need comments for these tests ???
1462 elsif Has_Private_Component
(T
)
1463 and then not Is_Generic_Type
(Root_Type
(T
))
1464 and then not In_Spec_Expression
1466 -- Special case: if T is the anonymous type created for a single
1467 -- task or protected object, use the name of the source object.
1469 if Is_Concurrent_Type
(T
)
1470 and then not Comes_From_Source
(T
)
1471 and then Nkind
(N
) = N_Object_Declaration
1473 Error_Msg_NE
("type of& has incomplete component", N
,
1474 Defining_Identifier
(N
));
1478 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1481 end Check_Fully_Declared
;
1483 -------------------------------------
1484 -- Check_Function_Writable_Actuals --
1485 -------------------------------------
1487 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
1488 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
1489 Identifiers_List
: Elist_Id
:= No_Elist
;
1490 Error_Node
: Node_Id
:= Empty
;
1492 procedure Collect_Identifiers
(N
: Node_Id
);
1493 -- In a single traversal of subtree N collect in Writable_Actuals_List
1494 -- all the actuals of functions with writable actuals, and in the list
1495 -- Identifiers_List collect all the identifiers that are not actuals of
1496 -- functions with writable actuals. If a writable actual is referenced
1497 -- twice as writable actual then Error_Node is set to reference its
1498 -- second occurrence, the error is reported, and the tree traversal
1501 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
1502 -- Return the entity associated with the function call
1504 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
1505 -- Preanalyze N without reporting errors. Very dubious, you can't just
1506 -- go analyzing things more than once???
1508 -------------------------
1509 -- Collect_Identifiers --
1510 -------------------------
1512 procedure Collect_Identifiers
(N
: Node_Id
) is
1514 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
1515 -- Process a single node during the tree traversal to collect the
1516 -- writable actuals of functions and all the identifiers which are
1517 -- not writable actuals of functions.
1519 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
1520 -- Returns True if List has a node whose Entity is Entity (N)
1522 -------------------------
1523 -- Check_Function_Call --
1524 -------------------------
1526 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
1527 Is_Writable_Actual
: Boolean := False;
1530 if Nkind
(N
) = N_Identifier
then
1532 -- No analysis possible if the entity is not decorated
1534 if No
(Entity
(N
)) then
1537 -- Don't collect identifiers of packages, called functions, etc
1539 elsif Ekind_In
(Entity
(N
), E_Package
,
1546 -- Analyze if N is a writable actual of a function
1548 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
1550 Call
: constant Node_Id
:= Parent
(N
);
1551 Id
: constant Entity_Id
:= Get_Function_Id
(Call
);
1556 Formal
:= First_Formal
(Id
);
1557 Actual
:= First_Actual
(Call
);
1558 while Present
(Actual
) and then Present
(Formal
) loop
1560 if Ekind_In
(Formal
, E_Out_Parameter
,
1563 Is_Writable_Actual
:= True;
1569 Next_Formal
(Formal
);
1570 Next_Actual
(Actual
);
1575 if Is_Writable_Actual
then
1576 if Contains
(Writable_Actuals_List
, N
) then
1578 ("conflict of writable function parameter in "
1579 & "construct with arbitrary order of evaluation", N
);
1584 if Writable_Actuals_List
= No_Elist
then
1585 Writable_Actuals_List
:= New_Elmt_List
;
1588 Append_Elmt
(N
, Writable_Actuals_List
);
1590 if Identifiers_List
= No_Elist
then
1591 Identifiers_List
:= New_Elmt_List
;
1594 Append_Unique_Elmt
(N
, Identifiers_List
);
1607 N
: Node_Id
) return Boolean
1609 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
1614 if List
= No_Elist
then
1618 Elmt
:= First_Elmt
(List
);
1619 while Present
(Elmt
) loop
1620 if Entity
(Node
(Elmt
)) = Entity
(N
) then
1634 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
1635 -- The traversal procedure
1637 -- Start of processing for Collect_Identifiers
1640 if Present
(Error_Node
) then
1644 if Nkind
(N
) in N_Subexpr
1645 and then Is_Static_Expression
(N
)
1651 end Collect_Identifiers
;
1653 ---------------------
1654 -- Get_Function_Id --
1655 ---------------------
1657 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
1658 Nam
: constant Node_Id
:= Name
(Call
);
1662 if Nkind
(Nam
) = N_Explicit_Dereference
then
1664 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
1666 elsif Nkind
(Nam
) = N_Selected_Component
then
1667 Id
:= Entity
(Selector_Name
(Nam
));
1669 elsif Nkind
(Nam
) = N_Indexed_Component
then
1670 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1677 end Get_Function_Id
;
1679 ---------------------------
1680 -- Preanalyze_Expression --
1681 ---------------------------
1683 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
1684 Status
: constant Boolean := Get_Ignore_Errors
;
1686 Set_Ignore_Errors
(True);
1688 Set_Ignore_Errors
(Status
);
1689 end Preanalyze_Without_Errors
;
1691 -- Start of processing for Check_Function_Writable_Actuals
1694 if Ada_Version
< Ada_2012
1695 or else (not (Nkind
(N
) in N_Op
)
1696 and then not (Nkind
(N
) in N_Membership_Test
)
1697 and then not Nkind_In
(N
, N_Range
,
1699 N_Extension_Aggregate
,
1700 N_Full_Type_Declaration
,
1702 N_Procedure_Call_Statement
,
1703 N_Entry_Call_Statement
))
1704 or else (Nkind
(N
) = N_Full_Type_Declaration
1705 and then not Is_Record_Type
(Defining_Identifier
(N
)))
1710 -- If a construct C has two or more direct constituents that are names
1711 -- or expressions whose evaluation may occur in an arbitrary order, at
1712 -- least one of which contains a function call with an in out or out
1713 -- parameter, then the construct is legal only if: for each name N that
1714 -- is passed as a parameter of mode in out or out to some inner function
1715 -- call C2 (not including the construct C itself), there is no other
1716 -- name anywhere within a direct constituent of the construct C other
1717 -- than the one containing C2, that is known to refer to the same
1718 -- object (RM 6.4.1(6.17/3)).
1722 Collect_Identifiers
(Low_Bound
(N
));
1723 Collect_Identifiers
(High_Bound
(N
));
1725 when N_Op | N_Membership_Test
=>
1729 Collect_Identifiers
(Left_Opnd
(N
));
1731 if Present
(Right_Opnd
(N
)) then
1732 Collect_Identifiers
(Right_Opnd
(N
));
1735 if Nkind_In
(N
, N_In
, N_Not_In
)
1736 and then Present
(Alternatives
(N
))
1738 Expr
:= First
(Alternatives
(N
));
1739 while Present
(Expr
) loop
1740 Collect_Identifiers
(Expr
);
1747 when N_Full_Type_Declaration
=>
1749 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
1750 -- Return the record part of this record type definition
1752 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
1753 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
1755 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
1756 return Record_Extension_Part
(Type_Def
);
1760 end Get_Record_Part
;
1763 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
1764 Rec
: Node_Id
:= Get_Record_Part
(N
);
1767 -- No need to perform any analysis if the record has no
1770 if No
(Rec
) or else No
(Component_List
(Rec
)) then
1774 -- Collect the identifiers starting from the deepest
1775 -- derivation. Done to report the error in the deepest
1779 if Present
(Component_List
(Rec
)) then
1780 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
1781 while Present
(Comp
) loop
1782 if Nkind
(Comp
) = N_Component_Declaration
1783 and then Present
(Expression
(Comp
))
1785 Collect_Identifiers
(Expression
(Comp
));
1792 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
1793 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
1796 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
1797 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
1801 when N_Subprogram_Call |
1802 N_Entry_Call_Statement
=>
1804 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
1809 Formal
:= First_Formal
(Id
);
1810 Actual
:= First_Actual
(N
);
1811 while Present
(Actual
) and then Present
(Formal
) loop
1812 if Ekind_In
(Formal
, E_Out_Parameter
,
1815 Collect_Identifiers
(Actual
);
1818 Next_Formal
(Formal
);
1819 Next_Actual
(Actual
);
1824 N_Extension_Aggregate
=>
1828 Comp_Expr
: Node_Id
;
1831 -- Handle the N_Others_Choice of array aggregates with static
1832 -- bounds. There is no need to perform this analysis in
1833 -- aggregates without static bounds since we cannot evaluate
1834 -- if the N_Others_Choice covers several elements. There is
1835 -- no need to handle the N_Others choice of record aggregates
1836 -- since at this stage it has been already expanded by
1837 -- Resolve_Record_Aggregate.
1839 if Is_Array_Type
(Etype
(N
))
1840 and then Nkind
(N
) = N_Aggregate
1841 and then Present
(Aggregate_Bounds
(N
))
1842 and then Compile_Time_Known_Bounds
(Etype
(N
))
1843 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
1844 > Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
1847 Count_Components
: Uint
:= Uint_0
;
1848 Num_Components
: Uint
;
1849 Others_Assoc
: Node_Id
;
1850 Others_Choice
: Node_Id
:= Empty
;
1851 Others_Box_Present
: Boolean := False;
1854 -- Count positional associations
1856 if Present
(Expressions
(N
)) then
1857 Comp_Expr
:= First
(Expressions
(N
));
1858 while Present
(Comp_Expr
) loop
1859 Count_Components
:= Count_Components
+ 1;
1864 -- Count the rest of elements and locate the N_Others
1867 Assoc
:= First
(Component_Associations
(N
));
1868 while Present
(Assoc
) loop
1869 Choice
:= First
(Choices
(Assoc
));
1870 while Present
(Choice
) loop
1871 if Nkind
(Choice
) = N_Others_Choice
then
1872 Others_Assoc
:= Assoc
;
1873 Others_Choice
:= Choice
;
1874 Others_Box_Present
:= Box_Present
(Assoc
);
1876 -- Count several components
1878 elsif Nkind_In
(Choice
, N_Range
,
1879 N_Subtype_Indication
)
1880 or else (Is_Entity_Name
(Choice
)
1881 and then Is_Type
(Entity
(Choice
)))
1886 Get_Index_Bounds
(Choice
, L
, H
);
1888 (Compile_Time_Known_Value
(L
)
1889 and then Compile_Time_Known_Value
(H
));
1892 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
1895 -- Count single component. No other case available
1896 -- since we are handling an aggregate with static
1900 pragma Assert
(Is_Static_Expression
(Choice
)
1901 or else Nkind
(Choice
) = N_Identifier
1902 or else Nkind
(Choice
) = N_Integer_Literal
);
1904 Count_Components
:= Count_Components
+ 1;
1914 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
1915 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
1917 pragma Assert
(Count_Components
<= Num_Components
);
1919 -- Handle the N_Others choice if it covers several
1922 if Present
(Others_Choice
)
1923 and then (Num_Components
- Count_Components
) > 1
1925 if not Others_Box_Present
then
1927 -- At this stage, if expansion is active, the
1928 -- expression of the others choice has not been
1929 -- analyzed. Hence we generate a duplicate and
1930 -- we analyze it silently to have available the
1931 -- minimum decoration required to collect the
1934 if not Expander_Active
then
1935 Comp_Expr
:= Expression
(Others_Assoc
);
1938 New_Copy_Tree
(Expression
(Others_Assoc
));
1939 Preanalyze_Without_Errors
(Comp_Expr
);
1942 Collect_Identifiers
(Comp_Expr
);
1944 if Writable_Actuals_List
/= No_Elist
then
1946 -- As suggested by Robert, at current stage we
1947 -- report occurrences of this case as warnings.
1950 ("conflict of writable function parameter in "
1951 & "construct with arbitrary order of "
1953 Node
(First_Elmt
(Writable_Actuals_List
)));
1960 -- Handle ancestor part of extension aggregates
1962 if Nkind
(N
) = N_Extension_Aggregate
then
1963 Collect_Identifiers
(Ancestor_Part
(N
));
1966 -- Handle positional associations
1968 if Present
(Expressions
(N
)) then
1969 Comp_Expr
:= First
(Expressions
(N
));
1970 while Present
(Comp_Expr
) loop
1971 if not Is_Static_Expression
(Comp_Expr
) then
1972 Collect_Identifiers
(Comp_Expr
);
1979 -- Handle discrete associations
1981 if Present
(Component_Associations
(N
)) then
1982 Assoc
:= First
(Component_Associations
(N
));
1983 while Present
(Assoc
) loop
1985 if not Box_Present
(Assoc
) then
1986 Choice
:= First
(Choices
(Assoc
));
1987 while Present
(Choice
) loop
1989 -- For now we skip discriminants since it requires
1990 -- performing the analysis in two phases: first one
1991 -- analyzing discriminants and second one analyzing
1992 -- the rest of components since discriminants are
1993 -- evaluated prior to components: too much extra
1994 -- work to detect a corner case???
1996 if Nkind
(Choice
) in N_Has_Entity
1997 and then Present
(Entity
(Choice
))
1998 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2002 elsif Box_Present
(Assoc
) then
2006 if not Analyzed
(Expression
(Assoc
)) then
2008 New_Copy_Tree
(Expression
(Assoc
));
2009 Set_Parent
(Comp_Expr
, Parent
(N
));
2010 Preanalyze_Without_Errors
(Comp_Expr
);
2012 Comp_Expr
:= Expression
(Assoc
);
2015 Collect_Identifiers
(Comp_Expr
);
2031 -- No further action needed if we already reported an error
2033 if Present
(Error_Node
) then
2037 -- Check if some writable argument of a function is referenced
2039 if Writable_Actuals_List
/= No_Elist
2040 and then Identifiers_List
/= No_Elist
2047 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2048 while Present
(Elmt_1
) loop
2049 Elmt_2
:= First_Elmt
(Identifiers_List
);
2050 while Present
(Elmt_2
) loop
2051 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2053 ("conflict of writable function parameter in construct "
2054 & "with arbitrary order of evaluation",
2065 end Check_Function_Writable_Actuals
;
2067 --------------------------------
2068 -- Check_Implicit_Dereference --
2069 --------------------------------
2071 procedure Check_Implicit_Dereference
(Nam
: Node_Id
; Typ
: Entity_Id
) is
2076 if Ada_Version
< Ada_2012
2077 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2081 elsif not Comes_From_Source
(Nam
) then
2084 elsif Is_Entity_Name
(Nam
)
2085 and then Is_Type
(Entity
(Nam
))
2090 Disc
:= First_Discriminant
(Typ
);
2091 while Present
(Disc
) loop
2092 if Has_Implicit_Dereference
(Disc
) then
2093 Desig
:= Designated_Type
(Etype
(Disc
));
2094 Add_One_Interp
(Nam
, Disc
, Desig
);
2098 Next_Discriminant
(Disc
);
2101 end Check_Implicit_Dereference
;
2103 ----------------------------------
2104 -- Check_Internal_Protected_Use --
2105 ----------------------------------
2107 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2113 while Present
(S
) loop
2114 if S
= Standard_Standard
then
2117 elsif Ekind
(S
) = E_Function
2118 and then Ekind
(Scope
(S
)) = E_Protected_Type
2127 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2128 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2130 ("within protected function cannot use protected "
2131 & "procedure in renaming or as generic actual", N
);
2133 elsif Nkind
(N
) = N_Attribute_Reference
then
2135 ("within protected function cannot take access of "
2136 & " protected procedure", N
);
2140 ("within protected function, protected object is constant", N
);
2142 ("\cannot call operation that may modify it", N
);
2145 end Check_Internal_Protected_Use
;
2147 ---------------------------------------
2148 -- Check_Later_Vs_Basic_Declarations --
2149 ---------------------------------------
2151 procedure Check_Later_Vs_Basic_Declarations
2153 During_Parsing
: Boolean)
2155 Body_Sloc
: Source_Ptr
;
2158 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2159 -- Return whether Decl is considered as a declarative item.
2160 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2161 -- When During_Parsing is False, the semantics of SPARK is followed.
2163 -------------------------------
2164 -- Is_Later_Declarative_Item --
2165 -------------------------------
2167 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2169 if Nkind
(Decl
) in N_Later_Decl_Item
then
2172 elsif Nkind
(Decl
) = N_Pragma
then
2175 elsif During_Parsing
then
2178 -- In SPARK, a package declaration is not considered as a later
2179 -- declarative item.
2181 elsif Nkind
(Decl
) = N_Package_Declaration
then
2184 -- In SPARK, a renaming is considered as a later declarative item
2186 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2192 end Is_Later_Declarative_Item
;
2194 -- Start of Check_Later_Vs_Basic_Declarations
2197 Decl
:= First
(Decls
);
2199 -- Loop through sequence of basic declarative items
2201 Outer
: while Present
(Decl
) loop
2202 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2203 and then Nkind
(Decl
) not in N_Body_Stub
2207 -- Once a body is encountered, we only allow later declarative
2208 -- items. The inner loop checks the rest of the list.
2211 Body_Sloc
:= Sloc
(Decl
);
2213 Inner
: while Present
(Decl
) loop
2214 if not Is_Later_Declarative_Item
(Decl
) then
2215 if During_Parsing
then
2216 if Ada_Version
= Ada_83
then
2217 Error_Msg_Sloc
:= Body_Sloc
;
2219 ("(Ada 83) decl cannot appear after body#", Decl
);
2222 Error_Msg_Sloc
:= Body_Sloc
;
2223 Check_SPARK_Restriction
2224 ("decl cannot appear after body#", Decl
);
2232 end Check_Later_Vs_Basic_Declarations
;
2234 -------------------------
2235 -- Check_Nested_Access --
2236 -------------------------
2238 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2239 Scop
: constant Entity_Id
:= Current_Scope
;
2240 Current_Subp
: Entity_Id
;
2241 Enclosing
: Entity_Id
;
2244 -- Currently only enabled for VM back-ends for efficiency, should we
2245 -- enable it more systematically ???
2247 -- Check for Is_Imported needs commenting below ???
2249 if VM_Target
/= No_VM
2250 and then (Ekind
(Ent
) = E_Variable
2252 Ekind
(Ent
) = E_Constant
2254 Ekind
(Ent
) = E_Loop_Parameter
)
2255 and then Scope
(Ent
) /= Empty
2256 and then not Is_Library_Level_Entity
(Ent
)
2257 and then not Is_Imported
(Ent
)
2259 if Is_Subprogram
(Scop
)
2260 or else Is_Generic_Subprogram
(Scop
)
2261 or else Is_Entry
(Scop
)
2263 Current_Subp
:= Scop
;
2265 Current_Subp
:= Current_Subprogram
;
2268 Enclosing
:= Enclosing_Subprogram
(Ent
);
2270 if Enclosing
/= Empty
2271 and then Enclosing
/= Current_Subp
2273 Set_Has_Up_Level_Access
(Ent
, True);
2276 end Check_Nested_Access
;
2278 ---------------------------
2279 -- Check_No_Hidden_State --
2280 ---------------------------
2282 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2283 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2284 -- Determine whether the entity of a package denoted by Pkg has a null
2287 -----------------------------
2288 -- Has_Null_Abstract_State --
2289 -----------------------------
2291 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2292 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2295 -- Check first available state of related package. A null abstract
2296 -- state always appears as the sole element of the state list.
2300 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2301 end Has_Null_Abstract_State
;
2305 Context
: Entity_Id
:= Empty
;
2306 Not_Visible
: Boolean := False;
2309 -- Start of processing for Check_No_Hidden_State
2312 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2314 -- Find the proper context where the object or state appears
2317 while Present
(Scop
) loop
2320 -- Keep track of the context's visibility
2322 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2324 -- Prevent the search from going too far
2326 if Context
= Standard_Standard
then
2329 -- Objects and states that appear immediately within a subprogram or
2330 -- inside a construct nested within a subprogram do not introduce a
2331 -- hidden state. They behave as local variable declarations.
2333 elsif Is_Subprogram
(Context
) then
2336 -- When examining a package body, use the entity of the spec as it
2337 -- carries the abstract state declarations.
2339 elsif Ekind
(Context
) = E_Package_Body
then
2340 Context
:= Spec_Entity
(Context
);
2343 -- Stop the traversal when a package subject to a null abstract state
2346 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2347 and then Has_Null_Abstract_State
(Context
)
2352 Scop
:= Scope
(Scop
);
2355 -- At this point we know that there is at least one package with a null
2356 -- abstract state in visibility. Emit an error message unconditionally
2357 -- if the entity being processed is a state because the placement of the
2358 -- related package is irrelevant. This is not the case for objects as
2359 -- the intermediate context matters.
2361 if Present
(Context
)
2362 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
2364 Error_Msg_N
("cannot introduce hidden state &", Id
);
2365 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
2367 end Check_No_Hidden_State
;
2369 ------------------------------------------
2370 -- Check_Potentially_Blocking_Operation --
2371 ------------------------------------------
2373 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2377 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2378 -- When pragma Detect_Blocking is active, the run time will raise
2379 -- Program_Error. Here we only issue a warning, since we generally
2380 -- support the use of potentially blocking operations in the absence
2383 -- Indirect blocking through a subprogram call cannot be diagnosed
2384 -- statically without interprocedural analysis, so we do not attempt
2387 S
:= Scope
(Current_Scope
);
2388 while Present
(S
) and then S
/= Standard_Standard
loop
2389 if Is_Protected_Type
(S
) then
2391 ("potentially blocking operation in protected operation??", N
);
2397 end Check_Potentially_Blocking_Operation
;
2399 ------------------------------
2400 -- Check_Unprotected_Access --
2401 ------------------------------
2403 procedure Check_Unprotected_Access
2407 Cont_Encl_Typ
: Entity_Id
;
2408 Pref_Encl_Typ
: Entity_Id
;
2410 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
2411 -- Check whether Obj is a private component of a protected object.
2412 -- Return the protected type where the component resides, Empty
2415 function Is_Public_Operation
return Boolean;
2416 -- Verify that the enclosing operation is callable from outside the
2417 -- protected object, to minimize false positives.
2419 ------------------------------
2420 -- Enclosing_Protected_Type --
2421 ------------------------------
2423 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
2425 if Is_Entity_Name
(Obj
) then
2427 Ent
: Entity_Id
:= Entity
(Obj
);
2430 -- The object can be a renaming of a private component, use
2431 -- the original record component.
2433 if Is_Prival
(Ent
) then
2434 Ent
:= Prival_Link
(Ent
);
2437 if Is_Protected_Type
(Scope
(Ent
)) then
2443 -- For indexed and selected components, recursively check the prefix
2445 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
2446 return Enclosing_Protected_Type
(Prefix
(Obj
));
2448 -- The object does not denote a protected component
2453 end Enclosing_Protected_Type
;
2455 -------------------------
2456 -- Is_Public_Operation --
2457 -------------------------
2459 function Is_Public_Operation
return Boolean is
2466 and then S
/= Pref_Encl_Typ
2468 if Scope
(S
) = Pref_Encl_Typ
then
2469 E
:= First_Entity
(Pref_Encl_Typ
);
2471 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
2484 end Is_Public_Operation
;
2486 -- Start of processing for Check_Unprotected_Access
2489 if Nkind
(Expr
) = N_Attribute_Reference
2490 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
2492 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
2493 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
2495 -- Check whether we are trying to export a protected component to a
2496 -- context with an equal or lower access level.
2498 if Present
(Pref_Encl_Typ
)
2499 and then No
(Cont_Encl_Typ
)
2500 and then Is_Public_Operation
2501 and then Scope_Depth
(Pref_Encl_Typ
) >=
2502 Object_Access_Level
(Context
)
2505 ("??possible unprotected access to protected data", Expr
);
2508 end Check_Unprotected_Access
;
2514 procedure Check_VMS
(Construct
: Node_Id
) is
2516 if not OpenVMS_On_Target
then
2518 ("this construct is allowed only in Open'V'M'S", Construct
);
2522 ------------------------
2523 -- Collect_Interfaces --
2524 ------------------------
2526 procedure Collect_Interfaces
2528 Ifaces_List
: out Elist_Id
;
2529 Exclude_Parents
: Boolean := False;
2530 Use_Full_View
: Boolean := True)
2532 procedure Collect
(Typ
: Entity_Id
);
2533 -- Subsidiary subprogram used to traverse the whole list
2534 -- of directly and indirectly implemented interfaces
2540 procedure Collect
(Typ
: Entity_Id
) is
2541 Ancestor
: Entity_Id
;
2549 -- Handle private types
2552 and then Is_Private_Type
(Typ
)
2553 and then Present
(Full_View
(Typ
))
2555 Full_T
:= Full_View
(Typ
);
2558 -- Include the ancestor if we are generating the whole list of
2559 -- abstract interfaces.
2561 if Etype
(Full_T
) /= Typ
2563 -- Protect the frontend against wrong sources. For example:
2566 -- type A is tagged null record;
2567 -- type B is new A with private;
2568 -- type C is new A with private;
2570 -- type B is new C with null record;
2571 -- type C is new B with null record;
2574 and then Etype
(Full_T
) /= T
2576 Ancestor
:= Etype
(Full_T
);
2579 if Is_Interface
(Ancestor
)
2580 and then not Exclude_Parents
2582 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
2586 -- Traverse the graph of ancestor interfaces
2588 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
2589 Id
:= First
(Abstract_Interface_List
(Full_T
));
2590 while Present
(Id
) loop
2591 Iface
:= Etype
(Id
);
2593 -- Protect against wrong uses. For example:
2594 -- type I is interface;
2595 -- type O is tagged null record;
2596 -- type Wrong is new I and O with null record; -- ERROR
2598 if Is_Interface
(Iface
) then
2600 and then Etype
(T
) /= T
2601 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
2606 Append_Unique_Elmt
(Iface
, Ifaces_List
);
2615 -- Start of processing for Collect_Interfaces
2618 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
2619 Ifaces_List
:= New_Elmt_List
;
2621 end Collect_Interfaces
;
2623 ----------------------------------
2624 -- Collect_Interface_Components --
2625 ----------------------------------
2627 procedure Collect_Interface_Components
2628 (Tagged_Type
: Entity_Id
;
2629 Components_List
: out Elist_Id
)
2631 procedure Collect
(Typ
: Entity_Id
);
2632 -- Subsidiary subprogram used to climb to the parents
2638 procedure Collect
(Typ
: Entity_Id
) is
2639 Tag_Comp
: Entity_Id
;
2640 Parent_Typ
: Entity_Id
;
2643 -- Handle private types
2645 if Present
(Full_View
(Etype
(Typ
))) then
2646 Parent_Typ
:= Full_View
(Etype
(Typ
));
2648 Parent_Typ
:= Etype
(Typ
);
2651 if Parent_Typ
/= Typ
2653 -- Protect the frontend against wrong sources. For example:
2656 -- type A is tagged null record;
2657 -- type B is new A with private;
2658 -- type C is new A with private;
2660 -- type B is new C with null record;
2661 -- type C is new B with null record;
2664 and then Parent_Typ
/= Tagged_Type
2666 Collect
(Parent_Typ
);
2669 -- Collect the components containing tags of secondary dispatch
2672 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
2673 while Present
(Tag_Comp
) loop
2674 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
2675 Append_Elmt
(Tag_Comp
, Components_List
);
2677 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
2681 -- Start of processing for Collect_Interface_Components
2684 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
2685 and then Is_Tagged_Type
(Tagged_Type
));
2687 Components_List
:= New_Elmt_List
;
2688 Collect
(Tagged_Type
);
2689 end Collect_Interface_Components
;
2691 -----------------------------
2692 -- Collect_Interfaces_Info --
2693 -----------------------------
2695 procedure Collect_Interfaces_Info
2697 Ifaces_List
: out Elist_Id
;
2698 Components_List
: out Elist_Id
;
2699 Tags_List
: out Elist_Id
)
2701 Comps_List
: Elist_Id
;
2702 Comp_Elmt
: Elmt_Id
;
2703 Comp_Iface
: Entity_Id
;
2704 Iface_Elmt
: Elmt_Id
;
2707 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
2708 -- Search for the secondary tag associated with the interface type
2709 -- Iface that is implemented by T.
2715 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
2718 if not Is_CPP_Class
(T
) then
2719 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
2721 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
2725 and then Is_Tag
(Node
(ADT
))
2726 and then Related_Type
(Node
(ADT
)) /= Iface
2728 -- Skip secondary dispatch table referencing thunks to user
2729 -- defined primitives covered by this interface.
2731 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
2734 -- Skip secondary dispatch tables of Ada types
2736 if not Is_CPP_Class
(T
) then
2738 -- Skip secondary dispatch table referencing thunks to
2739 -- predefined primitives.
2741 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
2744 -- Skip secondary dispatch table referencing user-defined
2745 -- primitives covered by this interface.
2747 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
2750 -- Skip secondary dispatch table referencing predefined
2753 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
2758 pragma Assert
(Is_Tag
(Node
(ADT
)));
2762 -- Start of processing for Collect_Interfaces_Info
2765 Collect_Interfaces
(T
, Ifaces_List
);
2766 Collect_Interface_Components
(T
, Comps_List
);
2768 -- Search for the record component and tag associated with each
2769 -- interface type of T.
2771 Components_List
:= New_Elmt_List
;
2772 Tags_List
:= New_Elmt_List
;
2774 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
2775 while Present
(Iface_Elmt
) loop
2776 Iface
:= Node
(Iface_Elmt
);
2778 -- Associate the primary tag component and the primary dispatch table
2779 -- with all the interfaces that are parents of T
2781 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
2782 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
2783 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
2785 -- Otherwise search for the tag component and secondary dispatch
2789 Comp_Elmt
:= First_Elmt
(Comps_List
);
2790 while Present
(Comp_Elmt
) loop
2791 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
2793 if Comp_Iface
= Iface
2794 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
2796 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
2797 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
2801 Next_Elmt
(Comp_Elmt
);
2803 pragma Assert
(Present
(Comp_Elmt
));
2806 Next_Elmt
(Iface_Elmt
);
2808 end Collect_Interfaces_Info
;
2810 ---------------------
2811 -- Collect_Parents --
2812 ---------------------
2814 procedure Collect_Parents
2816 List
: out Elist_Id
;
2817 Use_Full_View
: Boolean := True)
2819 Current_Typ
: Entity_Id
:= T
;
2820 Parent_Typ
: Entity_Id
;
2823 List
:= New_Elmt_List
;
2825 -- No action if the if the type has no parents
2827 if T
= Etype
(T
) then
2832 Parent_Typ
:= Etype
(Current_Typ
);
2834 if Is_Private_Type
(Parent_Typ
)
2835 and then Present
(Full_View
(Parent_Typ
))
2836 and then Use_Full_View
2838 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
2841 Append_Elmt
(Parent_Typ
, List
);
2843 exit when Parent_Typ
= Current_Typ
;
2844 Current_Typ
:= Parent_Typ
;
2846 end Collect_Parents
;
2848 ----------------------------------
2849 -- Collect_Primitive_Operations --
2850 ----------------------------------
2852 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
2853 B_Type
: constant Entity_Id
:= Base_Type
(T
);
2854 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
2855 B_Scope
: Entity_Id
:= Scope
(B_Type
);
2859 Is_Type_In_Pkg
: Boolean;
2860 Formal_Derived
: Boolean := False;
2863 function Match
(E
: Entity_Id
) return Boolean;
2864 -- True if E's base type is B_Type, or E is of an anonymous access type
2865 -- and the base type of its designated type is B_Type.
2871 function Match
(E
: Entity_Id
) return Boolean is
2872 Etyp
: Entity_Id
:= Etype
(E
);
2875 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
2876 Etyp
:= Designated_Type
(Etyp
);
2879 return Base_Type
(Etyp
) = B_Type
;
2882 -- Start of processing for Collect_Primitive_Operations
2885 -- For tagged types, the primitive operations are collected as they
2886 -- are declared, and held in an explicit list which is simply returned.
2888 if Is_Tagged_Type
(B_Type
) then
2889 return Primitive_Operations
(B_Type
);
2891 -- An untagged generic type that is a derived type inherits the
2892 -- primitive operations of its parent type. Other formal types only
2893 -- have predefined operators, which are not explicitly represented.
2895 elsif Is_Generic_Type
(B_Type
) then
2896 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
2897 and then Nkind
(Formal_Type_Definition
(B_Decl
))
2898 = N_Formal_Derived_Type_Definition
2900 Formal_Derived
:= True;
2902 return New_Elmt_List
;
2906 Op_List
:= New_Elmt_List
;
2908 if B_Scope
= Standard_Standard
then
2909 if B_Type
= Standard_String
then
2910 Append_Elmt
(Standard_Op_Concat
, Op_List
);
2912 elsif B_Type
= Standard_Wide_String
then
2913 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
2919 -- Locate the primitive subprograms of the type
2922 -- The primitive operations appear after the base type, except
2923 -- if the derivation happens within the private part of B_Scope
2924 -- and the type is a private type, in which case both the type
2925 -- and some primitive operations may appear before the base
2926 -- type, and the list of candidates starts after the type.
2928 if In_Open_Scopes
(B_Scope
)
2929 and then Scope
(T
) = B_Scope
2930 and then In_Private_Part
(B_Scope
)
2932 Id
:= Next_Entity
(T
);
2934 Id
:= Next_Entity
(B_Type
);
2937 -- Set flag if this is a type in a package spec
2940 Is_Package_Or_Generic_Package
(B_Scope
)
2942 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
2945 while Present
(Id
) loop
2947 -- Test whether the result type or any of the parameter types of
2948 -- each subprogram following the type match that type when the
2949 -- type is declared in a package spec, is a derived type, or the
2950 -- subprogram is marked as primitive. (The Is_Primitive test is
2951 -- needed to find primitives of nonderived types in declarative
2952 -- parts that happen to override the predefined "=" operator.)
2954 -- Note that generic formal subprograms are not considered to be
2955 -- primitive operations and thus are never inherited.
2957 if Is_Overloadable
(Id
)
2958 and then (Is_Type_In_Pkg
2959 or else Is_Derived_Type
(B_Type
)
2960 or else Is_Primitive
(Id
))
2961 and then Nkind
(Parent
(Parent
(Id
)))
2962 not in N_Formal_Subprogram_Declaration
2970 Formal
:= First_Formal
(Id
);
2971 while Present
(Formal
) loop
2972 if Match
(Formal
) then
2977 Next_Formal
(Formal
);
2981 -- For a formal derived type, the only primitives are the ones
2982 -- inherited from the parent type. Operations appearing in the
2983 -- package declaration are not primitive for it.
2986 and then (not Formal_Derived
2987 or else Present
(Alias
(Id
)))
2989 -- In the special case of an equality operator aliased to
2990 -- an overriding dispatching equality belonging to the same
2991 -- type, we don't include it in the list of primitives.
2992 -- This avoids inheriting multiple equality operators when
2993 -- deriving from untagged private types whose full type is
2994 -- tagged, which can otherwise cause ambiguities. Note that
2995 -- this should only happen for this kind of untagged parent
2996 -- type, since normally dispatching operations are inherited
2997 -- using the type's Primitive_Operations list.
2999 if Chars
(Id
) = Name_Op_Eq
3000 and then Is_Dispatching_Operation
(Id
)
3001 and then Present
(Alias
(Id
))
3002 and then Present
(Overridden_Operation
(Alias
(Id
)))
3003 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3004 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3008 -- Include the subprogram in the list of primitives
3011 Append_Elmt
(Id
, Op_List
);
3018 -- For a type declared in System, some of its operations may
3019 -- appear in the target-specific extension to System.
3022 and then B_Scope
= RTU_Entity
(System
)
3023 and then Present_System_Aux
3025 B_Scope
:= System_Aux_Id
;
3026 Id
:= First_Entity
(System_Aux_Id
);
3032 end Collect_Primitive_Operations
;
3034 -----------------------------------
3035 -- Compile_Time_Constraint_Error --
3036 -----------------------------------
3038 function Compile_Time_Constraint_Error
3041 Ent
: Entity_Id
:= Empty
;
3042 Loc
: Source_Ptr
:= No_Location
;
3043 Warn
: Boolean := False) return Node_Id
3045 Msgc
: String (1 .. Msg
'Length + 3);
3046 -- Copy of message, with room for possible ?? and ! at end
3056 -- A static constraint error in an instance body is not a fatal error.
3057 -- we choose to inhibit the message altogether, because there is no
3058 -- obvious node (for now) on which to post it. On the other hand the
3059 -- offending node must be replaced with a constraint_error in any case.
3061 -- No messages are generated if we already posted an error on this node
3063 if not Error_Posted
(N
) then
3064 if Loc
/= No_Location
then
3070 Msgc
(1 .. Msg
'Length) := Msg
;
3073 -- Message is a warning, even in Ada 95 case
3075 if Msg
(Msg
'Last) = '?' then
3078 -- In Ada 83, all messages are warnings. In the private part and
3079 -- the body of an instance, constraint_checks are only warnings.
3080 -- We also make this a warning if the Warn parameter is set.
3083 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
3091 elsif In_Instance_Not_Visible
then
3098 -- Otherwise we have a real error message (Ada 95 static case)
3099 -- and we make this an unconditional message. Note that in the
3100 -- warning case we do not make the message unconditional, it seems
3101 -- quite reasonable to delete messages like this (about exceptions
3102 -- that will be raised) in dead code.
3110 -- Should we generate a warning? The answer is not quite yes. The
3111 -- very annoying exception occurs in the case of a short circuit
3112 -- operator where the left operand is static and decisive. Climb
3113 -- parents to see if that is the case we have here. Conditional
3114 -- expressions with decisive conditions are a similar situation.
3122 -- And then with False as left operand
3124 if Nkind
(P
) = N_And_Then
3125 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3126 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
3131 -- OR ELSE with True as left operand
3133 elsif Nkind
(P
) = N_Or_Else
3134 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3135 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
3142 elsif Nkind
(P
) = N_If_Expression
then
3144 Cond
: constant Node_Id
:= First
(Expressions
(P
));
3145 Texp
: constant Node_Id
:= Next
(Cond
);
3146 Fexp
: constant Node_Id
:= Next
(Texp
);
3149 if Compile_Time_Known_Value
(Cond
) then
3151 -- Condition is True and we are in the right operand
3153 if Is_True
(Expr_Value
(Cond
))
3154 and then OldP
= Fexp
3159 -- Condition is False and we are in the left operand
3161 elsif Is_False
(Expr_Value
(Cond
))
3162 and then OldP
= Texp
3170 -- Special case for component association in aggregates, where
3171 -- we want to keep climbing up to the parent aggregate.
3173 elsif Nkind
(P
) = N_Component_Association
3174 and then Nkind
(Parent
(P
)) = N_Aggregate
3178 -- Keep going if within subexpression
3181 exit when Nkind
(P
) not in N_Subexpr
;
3186 if Present
(Ent
) then
3187 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
3189 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
3194 -- Check whether the context is an Init_Proc
3196 if Inside_Init_Proc
then
3198 Conc_Typ
: constant Entity_Id
:=
3199 Corresponding_Concurrent_Type
3200 (Entity
(Parameter_Type
(First
3201 (Parameter_Specifications
3202 (Parent
(Current_Scope
))))));
3205 -- Don't complain if the corresponding concurrent type
3206 -- doesn't come from source (i.e. a single task/protected
3209 if Present
(Conc_Typ
)
3210 and then not Comes_From_Source
(Conc_Typ
)
3213 ("\??& will be raised at run time",
3214 N
, Standard_Constraint_Error
, Eloc
);
3218 ("\??& will be raised for objects of this type",
3219 N
, Standard_Constraint_Error
, Eloc
);
3225 ("\??& will be raised at run time",
3226 N
, Standard_Constraint_Error
, Eloc
);
3231 ("\static expression fails Constraint_Check", Eloc
);
3232 Set_Error_Posted
(N
);
3238 end Compile_Time_Constraint_Error
;
3240 -----------------------
3241 -- Conditional_Delay --
3242 -----------------------
3244 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
3246 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
3247 Set_Has_Delayed_Freeze
(New_Ent
);
3249 end Conditional_Delay
;
3251 ----------------------------
3252 -- Contains_Refined_State --
3253 ----------------------------
3255 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
3256 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
3257 -- Determine whether a dependency list mentions a state with a visible
3260 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
3261 -- Determine whether a global list mentions a state with a visible
3264 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
3265 -- Determine whether Item is a reference to an abstract state with a
3266 -- visible refinement.
3268 -----------------------------
3269 -- Has_State_In_Dependency --
3270 -----------------------------
3272 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
3277 -- A null dependency list does not mention any states
3279 if Nkind
(List
) = N_Null
then
3282 -- Dependency clauses appear as component associations of an
3285 elsif Nkind
(List
) = N_Aggregate
3286 and then Present
(Component_Associations
(List
))
3288 Clause
:= First
(Component_Associations
(List
));
3289 while Present
(Clause
) loop
3291 -- Inspect the outputs of a dependency clause
3293 Output
:= First
(Choices
(Clause
));
3294 while Present
(Output
) loop
3295 if Is_Refined_State
(Output
) then
3302 -- Inspect the outputs of a dependency clause
3304 if Is_Refined_State
(Expression
(Clause
)) then
3311 -- If we get here, then none of the dependency clauses mention a
3312 -- state with visible refinement.
3316 -- An illegal pragma managed to sneak in
3319 raise Program_Error
;
3321 end Has_State_In_Dependency
;
3323 -------------------------
3324 -- Has_State_In_Global --
3325 -------------------------
3327 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
3331 -- A null global list does not mention any states
3333 if Nkind
(List
) = N_Null
then
3336 -- Simple global list or moded global list declaration
3338 elsif Nkind
(List
) = N_Aggregate
then
3340 -- The declaration of a simple global list appear as a collection
3343 if Present
(Expressions
(List
)) then
3344 Item
:= First
(Expressions
(List
));
3345 while Present
(Item
) loop
3346 if Is_Refined_State
(Item
) then
3353 -- The declaration of a moded global list appears as a collection
3354 -- of component associations where individual choices denote
3358 Item
:= First
(Component_Associations
(List
));
3359 while Present
(Item
) loop
3360 if Has_State_In_Global
(Expression
(Item
)) then
3368 -- If we get here, then the simple/moded global list did not
3369 -- mention any states with a visible refinement.
3373 -- Single global item declaration
3375 elsif Is_Entity_Name
(List
) then
3376 return Is_Refined_State
(List
);
3378 -- An illegal pragma managed to sneak in
3381 raise Program_Error
;
3383 end Has_State_In_Global
;
3385 ----------------------
3386 -- Is_Refined_State --
3387 ----------------------
3389 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
3391 Item_Id
: Entity_Id
;
3394 if Nkind
(Item
) = N_Null
then
3397 -- States cannot be subject to attribute 'Result. This case arises
3398 -- in dependency relations.
3400 elsif Nkind
(Item
) = N_Attribute_Reference
3401 and then Attribute_Name
(Item
) = Name_Result
3405 -- Multiple items appear as an aggregate. This case arises in
3406 -- dependency relations.
3408 elsif Nkind
(Item
) = N_Aggregate
3409 and then Present
(Expressions
(Item
))
3411 Elmt
:= First
(Expressions
(Item
));
3412 while Present
(Elmt
) loop
3413 if Is_Refined_State
(Elmt
) then
3420 -- If we get here, then none of the inputs or outputs reference a
3421 -- state with visible refinement.
3428 Item_Id
:= Entity_Of
(Item
);
3431 Ekind
(Item_Id
) = E_Abstract_State
3432 and then Has_Visible_Refinement
(Item_Id
);
3434 end Is_Refined_State
;
3438 Arg
: constant Node_Id
:=
3439 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
3440 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3442 -- Start of processing for Contains_Refined_State
3445 if Nam
= Name_Depends
then
3446 return Has_State_In_Dependency
(Arg
);
3448 else pragma Assert
(Nam
= Name_Global
);
3449 return Has_State_In_Global
(Arg
);
3451 end Contains_Refined_State
;
3453 -------------------------
3454 -- Copy_Component_List --
3455 -------------------------
3457 function Copy_Component_List
3459 Loc
: Source_Ptr
) return List_Id
3462 Comps
: constant List_Id
:= New_List
;
3465 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
3466 while Present
(Comp
) loop
3467 if Comes_From_Source
(Comp
) then
3469 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
3472 Make_Component_Declaration
(Loc
,
3473 Defining_Identifier
=>
3474 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
3475 Component_Definition
=>
3477 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
3481 Next_Component
(Comp
);
3485 end Copy_Component_List
;
3487 -------------------------
3488 -- Copy_Parameter_List --
3489 -------------------------
3491 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
3492 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
3497 if No
(First_Formal
(Subp_Id
)) then
3501 Formal
:= First_Formal
(Subp_Id
);
3502 while Present
(Formal
) loop
3504 (Make_Parameter_Specification
(Loc
,
3505 Defining_Identifier
=>
3506 Make_Defining_Identifier
(Sloc
(Formal
),
3507 Chars
=> Chars
(Formal
)),
3508 In_Present
=> In_Present
(Parent
(Formal
)),
3509 Out_Present
=> Out_Present
(Parent
(Formal
)),
3511 New_Reference_To
(Etype
(Formal
), Loc
),
3513 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
3516 Next_Formal
(Formal
);
3521 end Copy_Parameter_List
;
3523 --------------------------------
3524 -- Corresponding_Generic_Type --
3525 --------------------------------
3527 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
3533 if not Is_Generic_Actual_Type
(T
) then
3536 -- If the actual is the actual of an enclosing instance, resolution
3537 -- was correct in the generic.
3539 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
3540 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
3542 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
3549 if Is_Wrapper_Package
(Inst
) then
3550 Inst
:= Related_Instance
(Inst
);
3555 (Specification
(Unit_Declaration_Node
(Inst
)));
3557 -- Generic actual has the same name as the corresponding formal
3559 Typ
:= First_Entity
(Gen
);
3560 while Present
(Typ
) loop
3561 if Chars
(Typ
) = Chars
(T
) then
3570 end Corresponding_Generic_Type
;
3572 --------------------
3573 -- Current_Entity --
3574 --------------------
3576 -- The currently visible definition for a given identifier is the
3577 -- one most chained at the start of the visibility chain, i.e. the
3578 -- one that is referenced by the Node_Id value of the name of the
3579 -- given identifier.
3581 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
3583 return Get_Name_Entity_Id
(Chars
(N
));
3586 -----------------------------
3587 -- Current_Entity_In_Scope --
3588 -----------------------------
3590 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
3592 CS
: constant Entity_Id
:= Current_Scope
;
3594 Transient_Case
: constant Boolean := Scope_Is_Transient
;
3597 E
:= Get_Name_Entity_Id
(Chars
(N
));
3599 and then Scope
(E
) /= CS
3600 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
3606 end Current_Entity_In_Scope
;
3612 function Current_Scope
return Entity_Id
is
3614 if Scope_Stack
.Last
= -1 then
3615 return Standard_Standard
;
3618 C
: constant Entity_Id
:=
3619 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
3624 return Standard_Standard
;
3630 ------------------------
3631 -- Current_Subprogram --
3632 ------------------------
3634 function Current_Subprogram
return Entity_Id
is
3635 Scop
: constant Entity_Id
:= Current_Scope
;
3637 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
3640 return Enclosing_Subprogram
(Scop
);
3642 end Current_Subprogram
;
3644 ----------------------------------
3645 -- Deepest_Type_Access_Level --
3646 ----------------------------------
3648 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
3650 if Ekind
(Typ
) = E_Anonymous_Access_Type
3651 and then not Is_Local_Anonymous_Access
(Typ
)
3652 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
3654 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
3658 Scope_Depth
(Enclosing_Dynamic_Scope
3659 (Defining_Identifier
3660 (Associated_Node_For_Itype
(Typ
))));
3662 -- For generic formal type, return Int'Last (infinite).
3663 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
3665 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
3666 return UI_From_Int
(Int
'Last);
3669 return Type_Access_Level
(Typ
);
3671 end Deepest_Type_Access_Level
;
3673 ---------------------
3674 -- Defining_Entity --
3675 ---------------------
3677 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
3678 K
: constant Node_Kind
:= Nkind
(N
);
3679 Err
: Entity_Id
:= Empty
;
3684 N_Subprogram_Declaration |
3685 N_Abstract_Subprogram_Declaration |
3687 N_Package_Declaration |
3688 N_Subprogram_Renaming_Declaration |
3689 N_Subprogram_Body_Stub |
3690 N_Generic_Subprogram_Declaration |
3691 N_Generic_Package_Declaration |
3692 N_Formal_Subprogram_Declaration |
3693 N_Expression_Function
3695 return Defining_Entity
(Specification
(N
));
3698 N_Component_Declaration |
3699 N_Defining_Program_Unit_Name |
3700 N_Discriminant_Specification |
3702 N_Entry_Declaration |
3703 N_Entry_Index_Specification |
3704 N_Exception_Declaration |
3705 N_Exception_Renaming_Declaration |
3706 N_Formal_Object_Declaration |
3707 N_Formal_Package_Declaration |
3708 N_Formal_Type_Declaration |
3709 N_Full_Type_Declaration |
3710 N_Implicit_Label_Declaration |
3711 N_Incomplete_Type_Declaration |
3712 N_Loop_Parameter_Specification |
3713 N_Number_Declaration |
3714 N_Object_Declaration |
3715 N_Object_Renaming_Declaration |
3716 N_Package_Body_Stub |
3717 N_Parameter_Specification |
3718 N_Private_Extension_Declaration |
3719 N_Private_Type_Declaration |
3721 N_Protected_Body_Stub |
3722 N_Protected_Type_Declaration |
3723 N_Single_Protected_Declaration |
3724 N_Single_Task_Declaration |
3725 N_Subtype_Declaration |
3728 N_Task_Type_Declaration
3730 return Defining_Identifier
(N
);
3733 return Defining_Entity
(Proper_Body
(N
));
3736 N_Function_Instantiation |
3737 N_Function_Specification |
3738 N_Generic_Function_Renaming_Declaration |
3739 N_Generic_Package_Renaming_Declaration |
3740 N_Generic_Procedure_Renaming_Declaration |
3742 N_Package_Instantiation |
3743 N_Package_Renaming_Declaration |
3744 N_Package_Specification |
3745 N_Procedure_Instantiation |
3746 N_Procedure_Specification
3749 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
3752 if Nkind
(Nam
) in N_Entity
then
3755 -- For Error, make up a name and attach to declaration
3756 -- so we can continue semantic analysis
3758 elsif Nam
= Error
then
3759 Err
:= Make_Temporary
(Sloc
(N
), 'T');
3760 Set_Defining_Unit_Name
(N
, Err
);
3763 -- If not an entity, get defining identifier
3766 return Defining_Identifier
(Nam
);
3770 when N_Block_Statement
=>
3771 return Entity
(Identifier
(N
));
3774 raise Program_Error
;
3777 end Defining_Entity
;
3779 --------------------------
3780 -- Denotes_Discriminant --
3781 --------------------------
3783 function Denotes_Discriminant
3785 Check_Concurrent
: Boolean := False) return Boolean
3789 if not Is_Entity_Name
(N
)
3790 or else No
(Entity
(N
))
3797 -- If we are checking for a protected type, the discriminant may have
3798 -- been rewritten as the corresponding discriminal of the original type
3799 -- or of the corresponding concurrent record, depending on whether we
3800 -- are in the spec or body of the protected type.
3802 return Ekind
(E
) = E_Discriminant
3805 and then Ekind
(E
) = E_In_Parameter
3806 and then Present
(Discriminal_Link
(E
))
3808 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
3810 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
3812 end Denotes_Discriminant
;
3814 -------------------------
3815 -- Denotes_Same_Object --
3816 -------------------------
3818 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
3819 Obj1
: Node_Id
:= A1
;
3820 Obj2
: Node_Id
:= A2
;
3822 function Has_Prefix
(N
: Node_Id
) return Boolean;
3823 -- Return True if N has attribute Prefix
3825 function Is_Renaming
(N
: Node_Id
) return Boolean;
3826 -- Return true if N names a renaming entity
3828 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
3829 -- For renamings, return False if the prefix of any dereference within
3830 -- the renamed object_name is a variable, or any expression within the
3831 -- renamed object_name contains references to variables or calls on
3832 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
3838 function Has_Prefix
(N
: Node_Id
) return Boolean is
3842 N_Attribute_Reference
,
3844 N_Explicit_Dereference
,
3845 N_Indexed_Component
,
3847 N_Selected_Component
,
3855 function Is_Renaming
(N
: Node_Id
) return Boolean is
3857 return Is_Entity_Name
(N
)
3858 and then Present
(Renamed_Entity
(Entity
(N
)));
3861 -----------------------
3862 -- Is_Valid_Renaming --
3863 -----------------------
3865 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
3867 function Check_Renaming
(N
: Node_Id
) return Boolean;
3868 -- Recursive function used to traverse all the prefixes of N
3870 function Check_Renaming
(N
: Node_Id
) return Boolean is
3873 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
3878 if Nkind
(N
) = N_Indexed_Component
then
3883 Indx
:= First
(Expressions
(N
));
3884 while Present
(Indx
) loop
3885 if not Is_OK_Static_Expression
(Indx
) then
3894 if Has_Prefix
(N
) then
3896 P
: constant Node_Id
:= Prefix
(N
);
3899 if Nkind
(N
) = N_Explicit_Dereference
3900 and then Is_Variable
(P
)
3904 elsif Is_Entity_Name
(P
)
3905 and then Ekind
(Entity
(P
)) = E_Function
3909 elsif Nkind
(P
) = N_Function_Call
then
3913 -- Recursion to continue traversing the prefix of the
3914 -- renaming expression
3916 return Check_Renaming
(P
);
3923 -- Start of processing for Is_Valid_Renaming
3926 return Check_Renaming
(N
);
3927 end Is_Valid_Renaming
;
3929 -- Start of processing for Denotes_Same_Object
3932 -- Both names statically denote the same stand-alone object or parameter
3933 -- (RM 6.4.1(6.5/3))
3935 if Is_Entity_Name
(Obj1
)
3936 and then Is_Entity_Name
(Obj2
)
3937 and then Entity
(Obj1
) = Entity
(Obj2
)
3942 -- For renamings, the prefix of any dereference within the renamed
3943 -- object_name is not a variable, and any expression within the
3944 -- renamed object_name contains no references to variables nor
3945 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
3947 if Is_Renaming
(Obj1
) then
3948 if Is_Valid_Renaming
(Obj1
) then
3949 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
3955 if Is_Renaming
(Obj2
) then
3956 if Is_Valid_Renaming
(Obj2
) then
3957 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
3963 -- No match if not same node kind (such cases are handled by
3964 -- Denotes_Same_Prefix)
3966 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
3969 -- After handling valid renamings, one of the two names statically
3970 -- denoted a renaming declaration whose renamed object_name is known
3971 -- to denote the same object as the other (RM 6.4.1(6.10/3))
3973 elsif Is_Entity_Name
(Obj1
) then
3974 if Is_Entity_Name
(Obj2
) then
3975 return Entity
(Obj1
) = Entity
(Obj2
);
3980 -- Both names are selected_components, their prefixes are known to
3981 -- denote the same object, and their selector_names denote the same
3982 -- component (RM 6.4.1(6.6/3)
3984 elsif Nkind
(Obj1
) = N_Selected_Component
then
3985 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
3987 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
3989 -- Both names are dereferences and the dereferenced names are known to
3990 -- denote the same object (RM 6.4.1(6.7/3))
3992 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
3993 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
3995 -- Both names are indexed_components, their prefixes are known to denote
3996 -- the same object, and each of the pairs of corresponding index values
3997 -- are either both static expressions with the same static value or both
3998 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4000 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4001 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4009 Indx1
:= First
(Expressions
(Obj1
));
4010 Indx2
:= First
(Expressions
(Obj2
));
4011 while Present
(Indx1
) loop
4013 -- Indexes must denote the same static value or same object
4015 if Is_OK_Static_Expression
(Indx1
) then
4016 if not Is_OK_Static_Expression
(Indx2
) then
4019 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4023 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4035 -- Both names are slices, their prefixes are known to denote the same
4036 -- object, and the two slices have statically matching index constraints
4037 -- (RM 6.4.1(6.9/3))
4039 elsif Nkind
(Obj1
) = N_Slice
4040 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4043 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4046 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4047 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4049 -- Check whether bounds are statically identical. There is no
4050 -- attempt to detect partial overlap of slices.
4052 return Denotes_Same_Object
(Lo1
, Lo2
)
4053 and then Denotes_Same_Object
(Hi1
, Hi2
);
4056 -- In the recursion, literals appear as indexes.
4058 elsif Nkind
(Obj1
) = N_Integer_Literal
4059 and then Nkind
(Obj2
) = N_Integer_Literal
4061 return Intval
(Obj1
) = Intval
(Obj2
);
4066 end Denotes_Same_Object
;
4068 -------------------------
4069 -- Denotes_Same_Prefix --
4070 -------------------------
4072 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
4075 if Is_Entity_Name
(A1
) then
4076 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
4077 and then not Is_Access_Type
(Etype
(A1
))
4079 return Denotes_Same_Object
(A1
, Prefix
(A2
))
4080 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
4085 elsif Is_Entity_Name
(A2
) then
4086 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
4088 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4090 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4093 Root1
, Root2
: Node_Id
;
4094 Depth1
, Depth2
: Int
:= 0;
4097 Root1
:= Prefix
(A1
);
4098 while not Is_Entity_Name
(Root1
) loop
4100 (Root1
, N_Selected_Component
, N_Indexed_Component
)
4104 Root1
:= Prefix
(Root1
);
4107 Depth1
:= Depth1
+ 1;
4110 Root2
:= Prefix
(A2
);
4111 while not Is_Entity_Name
(Root2
) loop
4113 (Root2
, N_Selected_Component
, N_Indexed_Component
)
4117 Root2
:= Prefix
(Root2
);
4120 Depth2
:= Depth2
+ 1;
4123 -- If both have the same depth and they do not denote the same
4124 -- object, they are disjoint and no warning is needed.
4126 if Depth1
= Depth2
then
4129 elsif Depth1
> Depth2
then
4130 Root1
:= Prefix
(A1
);
4131 for I
in 1 .. Depth1
- Depth2
- 1 loop
4132 Root1
:= Prefix
(Root1
);
4135 return Denotes_Same_Object
(Root1
, A2
);
4138 Root2
:= Prefix
(A2
);
4139 for I
in 1 .. Depth2
- Depth1
- 1 loop
4140 Root2
:= Prefix
(Root2
);
4143 return Denotes_Same_Object
(A1
, Root2
);
4150 end Denotes_Same_Prefix
;
4152 ----------------------
4153 -- Denotes_Variable --
4154 ----------------------
4156 function Denotes_Variable
(N
: Node_Id
) return Boolean is
4158 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
4159 end Denotes_Variable
;
4161 -----------------------------
4162 -- Depends_On_Discriminant --
4163 -----------------------------
4165 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
4170 Get_Index_Bounds
(N
, L
, H
);
4171 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
4172 end Depends_On_Discriminant
;
4174 -------------------------
4175 -- Designate_Same_Unit --
4176 -------------------------
4178 function Designate_Same_Unit
4180 Name2
: Node_Id
) return Boolean
4182 K1
: constant Node_Kind
:= Nkind
(Name1
);
4183 K2
: constant Node_Kind
:= Nkind
(Name2
);
4185 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
4186 -- Returns the parent unit name node of a defining program unit name
4187 -- or the prefix if N is a selected component or an expanded name.
4189 function Select_Node
(N
: Node_Id
) return Node_Id
;
4190 -- Returns the defining identifier node of a defining program unit
4191 -- name or the selector node if N is a selected component or an
4198 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
4200 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4212 function Select_Node
(N
: Node_Id
) return Node_Id
is
4214 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4215 return Defining_Identifier
(N
);
4218 return Selector_Name
(N
);
4222 -- Start of processing for Designate_Next_Unit
4225 if (K1
= N_Identifier
or else
4226 K1
= N_Defining_Identifier
)
4228 (K2
= N_Identifier
or else
4229 K2
= N_Defining_Identifier
)
4231 return Chars
(Name1
) = Chars
(Name2
);
4234 (K1
= N_Expanded_Name
or else
4235 K1
= N_Selected_Component
or else
4236 K1
= N_Defining_Program_Unit_Name
)
4238 (K2
= N_Expanded_Name
or else
4239 K2
= N_Selected_Component
or else
4240 K2
= N_Defining_Program_Unit_Name
)
4243 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
4245 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
4250 end Designate_Same_Unit
;
4252 ------------------------------------------
4253 -- function Dynamic_Accessibility_Level --
4254 ------------------------------------------
4256 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
4258 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
4260 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
4261 -- Construct an integer literal representing an accessibility level
4262 -- with its type set to Natural.
4264 ------------------------
4265 -- Make_Level_Literal --
4266 ------------------------
4268 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
4269 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
4271 Set_Etype
(Result
, Standard_Natural
);
4273 end Make_Level_Literal
;
4275 -- Start of processing for Dynamic_Accessibility_Level
4278 if Is_Entity_Name
(Expr
) then
4281 if Present
(Renamed_Object
(E
)) then
4282 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
4285 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
4286 if Present
(Extra_Accessibility
(E
)) then
4287 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
4292 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4294 case Nkind
(Expr
) is
4296 -- For access discriminant, the level of the enclosing object
4298 when N_Selected_Component
=>
4299 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
4300 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
4301 E_Anonymous_Access_Type
4303 return Make_Level_Literal
(Object_Access_Level
(Expr
));
4306 when N_Attribute_Reference
=>
4307 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
4309 -- For X'Access, the level of the prefix X
4311 when Attribute_Access
=>
4312 return Make_Level_Literal
4313 (Object_Access_Level
(Prefix
(Expr
)));
4315 -- Treat the unchecked attributes as library-level
4317 when Attribute_Unchecked_Access |
4318 Attribute_Unrestricted_Access
=>
4319 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
4321 -- No other access-valued attributes
4324 raise Program_Error
;
4329 -- Unimplemented: depends on context. As an actual parameter where
4330 -- formal type is anonymous, use
4331 -- Scope_Depth (Current_Scope) + 1.
4332 -- For other cases, see 3.10.2(14/3) and following. ???
4336 when N_Type_Conversion
=>
4337 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
4339 -- Handle type conversions introduced for a rename of an
4340 -- Ada 2012 stand-alone object of an anonymous access type.
4342 return Dynamic_Accessibility_Level
(Expression
(Expr
));
4349 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
4350 end Dynamic_Accessibility_Level
;
4352 -----------------------------------
4353 -- Effective_Extra_Accessibility --
4354 -----------------------------------
4356 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
4358 if Present
(Renamed_Object
(Id
))
4359 and then Is_Entity_Name
(Renamed_Object
(Id
))
4361 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
4363 return Extra_Accessibility
(Id
);
4365 end Effective_Extra_Accessibility
;
4367 ------------------------------
4368 -- Enclosing_Comp_Unit_Node --
4369 ------------------------------
4371 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
4372 Current_Node
: Node_Id
;
4376 while Present
(Current_Node
)
4377 and then Nkind
(Current_Node
) /= N_Compilation_Unit
4379 Current_Node
:= Parent
(Current_Node
);
4382 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
4385 return Current_Node
;
4387 end Enclosing_Comp_Unit_Node
;
4389 --------------------------
4390 -- Enclosing_CPP_Parent --
4391 --------------------------
4393 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
4394 Parent_Typ
: Entity_Id
:= Typ
;
4397 while not Is_CPP_Class
(Parent_Typ
)
4398 and then Etype
(Parent_Typ
) /= Parent_Typ
4400 Parent_Typ
:= Etype
(Parent_Typ
);
4402 if Is_Private_Type
(Parent_Typ
) then
4403 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4407 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
4409 end Enclosing_CPP_Parent
;
4411 ----------------------------
4412 -- Enclosing_Generic_Body --
4413 ----------------------------
4415 function Enclosing_Generic_Body
4416 (N
: Node_Id
) return Node_Id
4424 while Present
(P
) loop
4425 if Nkind
(P
) = N_Package_Body
4426 or else Nkind
(P
) = N_Subprogram_Body
4428 Spec
:= Corresponding_Spec
(P
);
4430 if Present
(Spec
) then
4431 Decl
:= Unit_Declaration_Node
(Spec
);
4433 if Nkind
(Decl
) = N_Generic_Package_Declaration
4434 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4445 end Enclosing_Generic_Body
;
4447 ----------------------------
4448 -- Enclosing_Generic_Unit --
4449 ----------------------------
4451 function Enclosing_Generic_Unit
4452 (N
: Node_Id
) return Node_Id
4460 while Present
(P
) loop
4461 if Nkind
(P
) = N_Generic_Package_Declaration
4462 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
4466 elsif Nkind
(P
) = N_Package_Body
4467 or else Nkind
(P
) = N_Subprogram_Body
4469 Spec
:= Corresponding_Spec
(P
);
4471 if Present
(Spec
) then
4472 Decl
:= Unit_Declaration_Node
(Spec
);
4474 if Nkind
(Decl
) = N_Generic_Package_Declaration
4475 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4486 end Enclosing_Generic_Unit
;
4488 -------------------------------
4489 -- Enclosing_Lib_Unit_Entity --
4490 -------------------------------
4492 function Enclosing_Lib_Unit_Entity
4493 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
4495 Unit_Entity
: Entity_Id
;
4498 -- Look for enclosing library unit entity by following scope links.
4499 -- Equivalent to, but faster than indexing through the scope stack.
4502 while (Present
(Scope
(Unit_Entity
))
4503 and then Scope
(Unit_Entity
) /= Standard_Standard
)
4504 and not Is_Child_Unit
(Unit_Entity
)
4506 Unit_Entity
:= Scope
(Unit_Entity
);
4510 end Enclosing_Lib_Unit_Entity
;
4512 -----------------------
4513 -- Enclosing_Package --
4514 -----------------------
4516 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
4517 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4520 if Dynamic_Scope
= Standard_Standard
then
4521 return Standard_Standard
;
4523 elsif Dynamic_Scope
= Empty
then
4526 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
4529 return Dynamic_Scope
;
4532 return Enclosing_Package
(Dynamic_Scope
);
4534 end Enclosing_Package
;
4536 --------------------------
4537 -- Enclosing_Subprogram --
4538 --------------------------
4540 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
4541 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4544 if Dynamic_Scope
= Standard_Standard
then
4547 elsif Dynamic_Scope
= Empty
then
4550 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
4551 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
4553 elsif Ekind
(Dynamic_Scope
) = E_Block
4554 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
4556 return Enclosing_Subprogram
(Dynamic_Scope
);
4558 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
4559 return Get_Task_Body_Procedure
(Dynamic_Scope
);
4561 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
4562 and then Present
(Full_View
(Dynamic_Scope
))
4563 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
4565 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
4567 -- No body is generated if the protected operation is eliminated
4569 elsif Convention
(Dynamic_Scope
) = Convention_Protected
4570 and then not Is_Eliminated
(Dynamic_Scope
)
4571 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
4573 return Protected_Body_Subprogram
(Dynamic_Scope
);
4576 return Dynamic_Scope
;
4578 end Enclosing_Subprogram
;
4580 ------------------------
4581 -- Ensure_Freeze_Node --
4582 ------------------------
4584 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
4587 if No
(Freeze_Node
(E
)) then
4588 FN
:= Make_Freeze_Entity
(Sloc
(E
));
4589 Set_Has_Delayed_Freeze
(E
);
4590 Set_Freeze_Node
(E
, FN
);
4591 Set_Access_Types_To_Process
(FN
, No_Elist
);
4592 Set_TSS_Elist
(FN
, No_Elist
);
4595 end Ensure_Freeze_Node
;
4601 procedure Enter_Name
(Def_Id
: Entity_Id
) is
4602 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
4603 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
4604 S
: constant Entity_Id
:= Current_Scope
;
4607 Generate_Definition
(Def_Id
);
4609 -- Add new name to current scope declarations. Check for duplicate
4610 -- declaration, which may or may not be a genuine error.
4614 -- Case of previous entity entered because of a missing declaration
4615 -- or else a bad subtype indication. Best is to use the new entity,
4616 -- and make the previous one invisible.
4618 if Etype
(E
) = Any_Type
then
4619 Set_Is_Immediately_Visible
(E
, False);
4621 -- Case of renaming declaration constructed for package instances.
4622 -- if there is an explicit declaration with the same identifier,
4623 -- the renaming is not immediately visible any longer, but remains
4624 -- visible through selected component notation.
4626 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
4627 and then not Comes_From_Source
(E
)
4629 Set_Is_Immediately_Visible
(E
, False);
4631 -- The new entity may be the package renaming, which has the same
4632 -- same name as a generic formal which has been seen already.
4634 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
4635 and then not Comes_From_Source
(Def_Id
)
4637 Set_Is_Immediately_Visible
(E
, False);
4639 -- For a fat pointer corresponding to a remote access to subprogram,
4640 -- we use the same identifier as the RAS type, so that the proper
4641 -- name appears in the stub. This type is only retrieved through
4642 -- the RAS type and never by visibility, and is not added to the
4643 -- visibility list (see below).
4645 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
4646 and then Present
(Corresponding_Remote_Type
(Def_Id
))
4650 -- Case of an implicit operation or derived literal. The new entity
4651 -- hides the implicit one, which is removed from all visibility,
4652 -- i.e. the entity list of its scope, and homonym chain of its name.
4654 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
4655 or else Is_Internal
(E
)
4659 Prev_Vis
: Entity_Id
;
4660 Decl
: constant Node_Id
:= Parent
(E
);
4663 -- If E is an implicit declaration, it cannot be the first
4664 -- entity in the scope.
4666 Prev
:= First_Entity
(Current_Scope
);
4667 while Present
(Prev
)
4668 and then Next_Entity
(Prev
) /= E
4675 -- If E is not on the entity chain of the current scope,
4676 -- it is an implicit declaration in the generic formal
4677 -- part of a generic subprogram. When analyzing the body,
4678 -- the generic formals are visible but not on the entity
4679 -- chain of the subprogram. The new entity will become
4680 -- the visible one in the body.
4683 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
4687 Set_Next_Entity
(Prev
, Next_Entity
(E
));
4689 if No
(Next_Entity
(Prev
)) then
4690 Set_Last_Entity
(Current_Scope
, Prev
);
4693 if E
= Current_Entity
(E
) then
4697 Prev_Vis
:= Current_Entity
(E
);
4698 while Homonym
(Prev_Vis
) /= E
loop
4699 Prev_Vis
:= Homonym
(Prev_Vis
);
4703 if Present
(Prev_Vis
) then
4705 -- Skip E in the visibility chain
4707 Set_Homonym
(Prev_Vis
, Homonym
(E
));
4710 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
4715 -- This section of code could use a comment ???
4717 elsif Present
(Etype
(E
))
4718 and then Is_Concurrent_Type
(Etype
(E
))
4723 -- If the homograph is a protected component renaming, it should not
4724 -- be hiding the current entity. Such renamings are treated as weak
4727 elsif Is_Prival
(E
) then
4728 Set_Is_Immediately_Visible
(E
, False);
4730 -- In this case the current entity is a protected component renaming.
4731 -- Perform minimal decoration by setting the scope and return since
4732 -- the prival should not be hiding other visible entities.
4734 elsif Is_Prival
(Def_Id
) then
4735 Set_Scope
(Def_Id
, Current_Scope
);
4738 -- Analogous to privals, the discriminal generated for an entry index
4739 -- parameter acts as a weak declaration. Perform minimal decoration
4740 -- to avoid bogus errors.
4742 elsif Is_Discriminal
(Def_Id
)
4743 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
4745 Set_Scope
(Def_Id
, Current_Scope
);
4748 -- In the body or private part of an instance, a type extension may
4749 -- introduce a component with the same name as that of an actual. The
4750 -- legality rule is not enforced, but the semantics of the full type
4751 -- with two components of same name are not clear at this point???
4753 elsif In_Instance_Not_Visible
then
4756 -- When compiling a package body, some child units may have become
4757 -- visible. They cannot conflict with local entities that hide them.
4759 elsif Is_Child_Unit
(E
)
4760 and then In_Open_Scopes
(Scope
(E
))
4761 and then not Is_Immediately_Visible
(E
)
4765 -- Conversely, with front-end inlining we may compile the parent body
4766 -- first, and a child unit subsequently. The context is now the
4767 -- parent spec, and body entities are not visible.
4769 elsif Is_Child_Unit
(Def_Id
)
4770 and then Is_Package_Body_Entity
(E
)
4771 and then not In_Package_Body
(Current_Scope
)
4775 -- Case of genuine duplicate declaration
4778 Error_Msg_Sloc
:= Sloc
(E
);
4780 -- If the previous declaration is an incomplete type declaration
4781 -- this may be an attempt to complete it with a private type. The
4782 -- following avoids confusing cascaded errors.
4784 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
4785 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
4788 ("incomplete type cannot be completed with a private " &
4789 "declaration", Parent
(Def_Id
));
4790 Set_Is_Immediately_Visible
(E
, False);
4791 Set_Full_View
(E
, Def_Id
);
4793 -- An inherited component of a record conflicts with a new
4794 -- discriminant. The discriminant is inserted first in the scope,
4795 -- but the error should be posted on it, not on the component.
4797 elsif Ekind
(E
) = E_Discriminant
4798 and then Present
(Scope
(Def_Id
))
4799 and then Scope
(Def_Id
) /= Current_Scope
4801 Error_Msg_Sloc
:= Sloc
(Def_Id
);
4802 Error_Msg_N
("& conflicts with declaration#", E
);
4805 -- If the name of the unit appears in its own context clause, a
4806 -- dummy package with the name has already been created, and the
4807 -- error emitted. Try to continue quietly.
4809 elsif Error_Posted
(E
)
4810 and then Sloc
(E
) = No_Location
4811 and then Nkind
(Parent
(E
)) = N_Package_Specification
4812 and then Current_Scope
= Standard_Standard
4814 Set_Scope
(Def_Id
, Current_Scope
);
4818 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
4820 -- Avoid cascaded messages with duplicate components in
4823 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
4828 if Nkind
(Parent
(Parent
(Def_Id
))) =
4829 N_Generic_Subprogram_Declaration
4831 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
4833 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
4836 -- If entity is in standard, then we are in trouble, because it
4837 -- means that we have a library package with a duplicated name.
4838 -- That's hard to recover from, so abort!
4840 if S
= Standard_Standard
then
4841 raise Unrecoverable_Error
;
4843 -- Otherwise we continue with the declaration. Having two
4844 -- identical declarations should not cause us too much trouble!
4852 -- If we fall through, declaration is OK, at least OK enough to continue
4854 -- If Def_Id is a discriminant or a record component we are in the midst
4855 -- of inheriting components in a derived record definition. Preserve
4856 -- their Ekind and Etype.
4858 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
4861 -- If a type is already set, leave it alone (happens when a type
4862 -- declaration is reanalyzed following a call to the optimizer).
4864 elsif Present
(Etype
(Def_Id
)) then
4867 -- Otherwise, the kind E_Void insures that premature uses of the entity
4868 -- will be detected. Any_Type insures that no cascaded errors will occur
4871 Set_Ekind
(Def_Id
, E_Void
);
4872 Set_Etype
(Def_Id
, Any_Type
);
4875 -- Inherited discriminants and components in derived record types are
4876 -- immediately visible. Itypes are not.
4878 -- Unless the Itype is for a record type with a corresponding remote
4879 -- type (what is that about, it was not commented ???)
4881 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
4883 ((not Is_Record_Type
(Def_Id
)
4884 or else No
(Corresponding_Remote_Type
(Def_Id
)))
4885 and then not Is_Itype
(Def_Id
))
4887 Set_Is_Immediately_Visible
(Def_Id
);
4888 Set_Current_Entity
(Def_Id
);
4891 Set_Homonym
(Def_Id
, C
);
4892 Append_Entity
(Def_Id
, S
);
4893 Set_Public_Status
(Def_Id
);
4895 -- Declaring a homonym is not allowed in SPARK ...
4898 and then Restriction_Check_Required
(SPARK_05
)
4901 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
4902 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
4903 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
4906 -- ... unless the new declaration is in a subprogram, and the
4907 -- visible declaration is a variable declaration or a parameter
4908 -- specification outside that subprogram.
4910 if Present
(Enclosing_Subp
)
4911 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
4912 N_Parameter_Specification
)
4913 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
4917 -- ... or the new declaration is in a package, and the visible
4918 -- declaration occurs outside that package.
4920 elsif Present
(Enclosing_Pack
)
4921 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
4925 -- ... or the new declaration is a component declaration in a
4926 -- record type definition.
4928 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
4931 -- Don't issue error for non-source entities
4933 elsif Comes_From_Source
(Def_Id
)
4934 and then Comes_From_Source
(C
)
4936 Error_Msg_Sloc
:= Sloc
(C
);
4937 Check_SPARK_Restriction
4938 ("redeclaration of identifier &#", Def_Id
);
4943 -- Warn if new entity hides an old one
4945 if Warn_On_Hiding
and then Present
(C
)
4947 -- Don't warn for record components since they always have a well
4948 -- defined scope which does not confuse other uses. Note that in
4949 -- some cases, Ekind has not been set yet.
4951 and then Ekind
(C
) /= E_Component
4952 and then Ekind
(C
) /= E_Discriminant
4953 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
4954 and then Ekind
(Def_Id
) /= E_Component
4955 and then Ekind
(Def_Id
) /= E_Discriminant
4956 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
4958 -- Don't warn for one character variables. It is too common to use
4959 -- such variables as locals and will just cause too many false hits.
4961 and then Length_Of_Name
(Chars
(C
)) /= 1
4963 -- Don't warn for non-source entities
4965 and then Comes_From_Source
(C
)
4966 and then Comes_From_Source
(Def_Id
)
4968 -- Don't warn unless entity in question is in extended main source
4970 and then In_Extended_Main_Source_Unit
(Def_Id
)
4972 -- Finally, the hidden entity must be either immediately visible or
4973 -- use visible (i.e. from a used package).
4976 (Is_Immediately_Visible
(C
)
4978 Is_Potentially_Use_Visible
(C
))
4980 Error_Msg_Sloc
:= Sloc
(C
);
4981 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
4989 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
4995 if Is_Entity_Name
(N
) then
4998 -- Follow a possible chain of renamings to reach the root renamed
5001 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5002 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5003 Id
:= Entity
(Renamed_Object
(Id
));
5014 --------------------------
5015 -- Explain_Limited_Type --
5016 --------------------------
5018 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5022 -- For array, component type must be limited
5024 if Is_Array_Type
(T
) then
5025 Error_Msg_Node_2
:= T
;
5027 ("\component type& of type& is limited", N
, Component_Type
(T
));
5028 Explain_Limited_Type
(Component_Type
(T
), N
);
5030 elsif Is_Record_Type
(T
) then
5032 -- No need for extra messages if explicit limited record
5034 if Is_Limited_Record
(Base_Type
(T
)) then
5038 -- Otherwise find a limited component. Check only components that
5039 -- come from source, or inherited components that appear in the
5040 -- source of the ancestor.
5042 C
:= First_Component
(T
);
5043 while Present
(C
) loop
5044 if Is_Limited_Type
(Etype
(C
))
5046 (Comes_From_Source
(C
)
5048 (Present
(Original_Record_Component
(C
))
5050 Comes_From_Source
(Original_Record_Component
(C
))))
5052 Error_Msg_Node_2
:= T
;
5053 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
5054 Explain_Limited_Type
(Etype
(C
), N
);
5061 -- The type may be declared explicitly limited, even if no component
5062 -- of it is limited, in which case we fall out of the loop.
5065 end Explain_Limited_Type
;
5071 procedure Find_Actual
5073 Formal
: out Entity_Id
;
5076 Parnt
: constant Node_Id
:= Parent
(N
);
5080 if (Nkind
(Parnt
) = N_Indexed_Component
5082 Nkind
(Parnt
) = N_Selected_Component
)
5083 and then N
= Prefix
(Parnt
)
5085 Find_Actual
(Parnt
, Formal
, Call
);
5088 elsif Nkind
(Parnt
) = N_Parameter_Association
5089 and then N
= Explicit_Actual_Parameter
(Parnt
)
5091 Call
:= Parent
(Parnt
);
5093 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
5102 -- If we have a call to a subprogram look for the parameter. Note that
5103 -- we exclude overloaded calls, since we don't know enough to be sure
5104 -- of giving the right answer in this case.
5106 if Is_Entity_Name
(Name
(Call
))
5107 and then Present
(Entity
(Name
(Call
)))
5108 and then Is_Overloadable
(Entity
(Name
(Call
)))
5109 and then not Is_Overloaded
(Name
(Call
))
5111 -- Fall here if we are definitely a parameter
5113 Actual
:= First_Actual
(Call
);
5114 Formal
:= First_Formal
(Entity
(Name
(Call
)));
5115 while Present
(Formal
) and then Present
(Actual
) loop
5119 Actual
:= Next_Actual
(Actual
);
5120 Formal
:= Next_Formal
(Formal
);
5125 -- Fall through here if we did not find matching actual
5131 ---------------------------
5132 -- Find_Body_Discriminal --
5133 ---------------------------
5135 function Find_Body_Discriminal
5136 (Spec_Discriminant
: Entity_Id
) return Entity_Id
5142 -- If expansion is suppressed, then the scope can be the concurrent type
5143 -- itself rather than a corresponding concurrent record type.
5145 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
5146 Tsk
:= Scope
(Spec_Discriminant
);
5149 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
5151 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
5154 -- Find discriminant of original concurrent type, and use its current
5155 -- discriminal, which is the renaming within the task/protected body.
5157 Disc
:= First_Discriminant
(Tsk
);
5158 while Present
(Disc
) loop
5159 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
5160 return Discriminal
(Disc
);
5163 Next_Discriminant
(Disc
);
5166 -- That loop should always succeed in finding a matching entry and
5167 -- returning. Fatal error if not.
5169 raise Program_Error
;
5170 end Find_Body_Discriminal
;
5172 -------------------------------------
5173 -- Find_Corresponding_Discriminant --
5174 -------------------------------------
5176 function Find_Corresponding_Discriminant
5178 Typ
: Entity_Id
) return Entity_Id
5180 Par_Disc
: Entity_Id
;
5181 Old_Disc
: Entity_Id
;
5182 New_Disc
: Entity_Id
;
5185 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
5187 -- The original type may currently be private, and the discriminant
5188 -- only appear on its full view.
5190 if Is_Private_Type
(Scope
(Par_Disc
))
5191 and then not Has_Discriminants
(Scope
(Par_Disc
))
5192 and then Present
(Full_View
(Scope
(Par_Disc
)))
5194 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
5196 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
5199 if Is_Class_Wide_Type
(Typ
) then
5200 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
5202 New_Disc
:= First_Discriminant
(Typ
);
5205 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
5206 if Old_Disc
= Par_Disc
then
5209 Next_Discriminant
(Old_Disc
);
5210 Next_Discriminant
(New_Disc
);
5214 -- Should always find it
5216 raise Program_Error
;
5217 end Find_Corresponding_Discriminant
;
5219 ------------------------------------
5220 -- Find_Loop_In_Conditional_Block --
5221 ------------------------------------
5223 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
5229 if Nkind
(Stmt
) = N_If_Statement
then
5230 Stmt
:= First
(Then_Statements
(Stmt
));
5233 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
5235 -- Inspect the statements of the conditional block. In general the loop
5236 -- should be the first statement in the statement sequence of the block,
5237 -- but the finalization machinery may have introduced extra object
5240 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
5241 while Present
(Stmt
) loop
5242 if Nkind
(Stmt
) = N_Loop_Statement
then
5249 -- The expansion of attribute 'Loop_Entry produced a malformed block
5251 raise Program_Error
;
5252 end Find_Loop_In_Conditional_Block
;
5254 --------------------------
5255 -- Find_Overlaid_Entity --
5256 --------------------------
5258 procedure Find_Overlaid_Entity
5260 Ent
: out Entity_Id
;
5266 -- We are looking for one of the two following forms:
5268 -- for X'Address use Y'Address
5272 -- Const : constant Address := expr;
5274 -- for X'Address use Const;
5276 -- In the second case, the expr is either Y'Address, or recursively a
5277 -- constant that eventually references Y'Address.
5282 if Nkind
(N
) = N_Attribute_Definition_Clause
5283 and then Chars
(N
) = Name_Address
5285 Expr
:= Expression
(N
);
5287 -- This loop checks the form of the expression for Y'Address,
5288 -- using recursion to deal with intermediate constants.
5291 -- Check for Y'Address
5293 if Nkind
(Expr
) = N_Attribute_Reference
5294 and then Attribute_Name
(Expr
) = Name_Address
5296 Expr
:= Prefix
(Expr
);
5299 -- Check for Const where Const is a constant entity
5301 elsif Is_Entity_Name
(Expr
)
5302 and then Ekind
(Entity
(Expr
)) = E_Constant
5304 Expr
:= Constant_Value
(Entity
(Expr
));
5306 -- Anything else does not need checking
5313 -- This loop checks the form of the prefix for an entity, using
5314 -- recursion to deal with intermediate components.
5317 -- Check for Y where Y is an entity
5319 if Is_Entity_Name
(Expr
) then
5320 Ent
:= Entity
(Expr
);
5323 -- Check for components
5326 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
5328 Expr
:= Prefix
(Expr
);
5331 -- Anything else does not need checking
5338 end Find_Overlaid_Entity
;
5340 -------------------------
5341 -- Find_Parameter_Type --
5342 -------------------------
5344 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
5346 if Nkind
(Param
) /= N_Parameter_Specification
then
5349 -- For an access parameter, obtain the type from the formal entity
5350 -- itself, because access to subprogram nodes do not carry a type.
5351 -- Shouldn't we always use the formal entity ???
5353 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
5354 return Etype
(Defining_Identifier
(Param
));
5357 return Etype
(Parameter_Type
(Param
));
5359 end Find_Parameter_Type
;
5361 -----------------------------
5362 -- Find_Static_Alternative --
5363 -----------------------------
5365 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
5366 Expr
: constant Node_Id
:= Expression
(N
);
5367 Val
: constant Uint
:= Expr_Value
(Expr
);
5372 Alt
:= First
(Alternatives
(N
));
5375 if Nkind
(Alt
) /= N_Pragma
then
5376 Choice
:= First
(Discrete_Choices
(Alt
));
5377 while Present
(Choice
) loop
5379 -- Others choice, always matches
5381 if Nkind
(Choice
) = N_Others_Choice
then
5384 -- Range, check if value is in the range
5386 elsif Nkind
(Choice
) = N_Range
then
5388 Val
>= Expr_Value
(Low_Bound
(Choice
))
5390 Val
<= Expr_Value
(High_Bound
(Choice
));
5392 -- Choice is a subtype name. Note that we know it must
5393 -- be a static subtype, since otherwise it would have
5394 -- been diagnosed as illegal.
5396 elsif Is_Entity_Name
(Choice
)
5397 and then Is_Type
(Entity
(Choice
))
5399 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
5400 Assume_Valid
=> False);
5402 -- Choice is a subtype indication
5404 elsif Nkind
(Choice
) = N_Subtype_Indication
then
5406 C
: constant Node_Id
:= Constraint
(Choice
);
5407 R
: constant Node_Id
:= Range_Expression
(C
);
5411 Val
>= Expr_Value
(Low_Bound
(R
))
5413 Val
<= Expr_Value
(High_Bound
(R
));
5416 -- Choice is a simple expression
5419 exit Search
when Val
= Expr_Value
(Choice
);
5427 pragma Assert
(Present
(Alt
));
5430 -- The above loop *must* terminate by finding a match, since
5431 -- we know the case statement is valid, and the value of the
5432 -- expression is known at compile time. When we fall out of
5433 -- the loop, Alt points to the alternative that we know will
5434 -- be selected at run time.
5437 end Find_Static_Alternative
;
5443 function First_Actual
(Node
: Node_Id
) return Node_Id
is
5447 if No
(Parameter_Associations
(Node
)) then
5451 N
:= First
(Parameter_Associations
(Node
));
5453 if Nkind
(N
) = N_Parameter_Association
then
5454 return First_Named_Actual
(Node
);
5460 -----------------------
5461 -- Gather_Components --
5462 -----------------------
5464 procedure Gather_Components
5466 Comp_List
: Node_Id
;
5467 Governed_By
: List_Id
;
5469 Report_Errors
: out Boolean)
5473 Discrete_Choice
: Node_Id
;
5474 Comp_Item
: Node_Id
;
5476 Discrim
: Entity_Id
;
5477 Discrim_Name
: Node_Id
;
5478 Discrim_Value
: Node_Id
;
5481 Report_Errors
:= False;
5483 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
5486 elsif Present
(Component_Items
(Comp_List
)) then
5487 Comp_Item
:= First
(Component_Items
(Comp_List
));
5493 while Present
(Comp_Item
) loop
5495 -- Skip the tag of a tagged record, the interface tags, as well
5496 -- as all items that are not user components (anonymous types,
5497 -- rep clauses, Parent field, controller field).
5499 if Nkind
(Comp_Item
) = N_Component_Declaration
then
5501 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
5503 if not Is_Tag
(Comp
)
5504 and then Chars
(Comp
) /= Name_uParent
5506 Append_Elmt
(Comp
, Into
);
5514 if No
(Variant_Part
(Comp_List
)) then
5517 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
5518 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
5521 -- Look for the discriminant that governs this variant part.
5522 -- The discriminant *must* be in the Governed_By List
5524 Assoc
:= First
(Governed_By
);
5525 Find_Constraint
: loop
5526 Discrim
:= First
(Choices
(Assoc
));
5527 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
5528 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
5530 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
5531 Chars
(Discrim_Name
))
5532 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
5533 = Chars
(Discrim_Name
);
5535 if No
(Next
(Assoc
)) then
5536 if not Is_Constrained
(Typ
)
5537 and then Is_Derived_Type
(Typ
)
5538 and then Present
(Stored_Constraint
(Typ
))
5540 -- If the type is a tagged type with inherited discriminants,
5541 -- use the stored constraint on the parent in order to find
5542 -- the values of discriminants that are otherwise hidden by an
5543 -- explicit constraint. Renamed discriminants are handled in
5546 -- If several parent discriminants are renamed by a single
5547 -- discriminant of the derived type, the call to obtain the
5548 -- Corresponding_Discriminant field only retrieves the last
5549 -- of them. We recover the constraint on the others from the
5550 -- Stored_Constraint as well.
5557 D
:= First_Discriminant
(Etype
(Typ
));
5558 C
:= First_Elmt
(Stored_Constraint
(Typ
));
5559 while Present
(D
) and then Present
(C
) loop
5560 if Chars
(Discrim_Name
) = Chars
(D
) then
5561 if Is_Entity_Name
(Node
(C
))
5562 and then Entity
(Node
(C
)) = Entity
(Discrim
)
5564 -- D is renamed by Discrim, whose value is given in
5571 Make_Component_Association
(Sloc
(Typ
),
5573 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
5574 Duplicate_Subexpr_No_Checks
(Node
(C
)));
5576 exit Find_Constraint
;
5579 Next_Discriminant
(D
);
5586 if No
(Next
(Assoc
)) then
5587 Error_Msg_NE
(" missing value for discriminant&",
5588 First
(Governed_By
), Discrim_Name
);
5589 Report_Errors
:= True;
5594 end loop Find_Constraint
;
5596 Discrim_Value
:= Expression
(Assoc
);
5598 if not Is_OK_Static_Expression
(Discrim_Value
) then
5600 ("value for discriminant & must be static!",
5601 Discrim_Value
, Discrim
);
5602 Why_Not_Static
(Discrim_Value
);
5603 Report_Errors
:= True;
5607 Search_For_Discriminant_Value
: declare
5613 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
5616 Find_Discrete_Value
: while Present
(Variant
) loop
5617 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
5618 while Present
(Discrete_Choice
) loop
5619 exit Find_Discrete_Value
when
5620 Nkind
(Discrete_Choice
) = N_Others_Choice
;
5622 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
5624 UI_Low
:= Expr_Value
(Low
);
5625 UI_High
:= Expr_Value
(High
);
5627 exit Find_Discrete_Value
when
5628 UI_Low
<= UI_Discrim_Value
5630 UI_High
>= UI_Discrim_Value
;
5632 Next
(Discrete_Choice
);
5635 Next_Non_Pragma
(Variant
);
5636 end loop Find_Discrete_Value
;
5637 end Search_For_Discriminant_Value
;
5639 if No
(Variant
) then
5641 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
5642 Report_Errors
:= True;
5646 -- If we have found the corresponding choice, recursively add its
5647 -- components to the Into list.
5650 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
5651 end Gather_Components
;
5653 ------------------------
5654 -- Get_Actual_Subtype --
5655 ------------------------
5657 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
5658 Typ
: constant Entity_Id
:= Etype
(N
);
5659 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
5668 -- If what we have is an identifier that references a subprogram
5669 -- formal, or a variable or constant object, then we get the actual
5670 -- subtype from the referenced entity if one has been built.
5672 if Nkind
(N
) = N_Identifier
5674 (Is_Formal
(Entity
(N
))
5675 or else Ekind
(Entity
(N
)) = E_Constant
5676 or else Ekind
(Entity
(N
)) = E_Variable
)
5677 and then Present
(Actual_Subtype
(Entity
(N
)))
5679 return Actual_Subtype
(Entity
(N
));
5681 -- Actual subtype of unchecked union is always itself. We never need
5682 -- the "real" actual subtype. If we did, we couldn't get it anyway
5683 -- because the discriminant is not available. The restrictions on
5684 -- Unchecked_Union are designed to make sure that this is OK.
5686 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
5689 -- Here for the unconstrained case, we must find actual subtype
5690 -- No actual subtype is available, so we must build it on the fly.
5692 -- Checking the type, not the underlying type, for constrainedness
5693 -- seems to be necessary. Maybe all the tests should be on the type???
5695 elsif (not Is_Constrained
(Typ
))
5696 and then (Is_Array_Type
(Utyp
)
5697 or else (Is_Record_Type
(Utyp
)
5698 and then Has_Discriminants
(Utyp
)))
5699 and then not Has_Unknown_Discriminants
(Utyp
)
5700 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
5702 -- Nothing to do if in spec expression (why not???)
5704 if In_Spec_Expression
then
5707 elsif Is_Private_Type
(Typ
)
5708 and then not Has_Discriminants
(Typ
)
5710 -- If the type has no discriminants, there is no subtype to
5711 -- build, even if the underlying type is discriminated.
5715 -- Else build the actual subtype
5718 Decl
:= Build_Actual_Subtype
(Typ
, N
);
5719 Atyp
:= Defining_Identifier
(Decl
);
5721 -- If Build_Actual_Subtype generated a new declaration then use it
5725 -- The actual subtype is an Itype, so analyze the declaration,
5726 -- but do not attach it to the tree, to get the type defined.
5728 Set_Parent
(Decl
, N
);
5729 Set_Is_Itype
(Atyp
);
5730 Analyze
(Decl
, Suppress
=> All_Checks
);
5731 Set_Associated_Node_For_Itype
(Atyp
, N
);
5732 Set_Has_Delayed_Freeze
(Atyp
, False);
5734 -- We need to freeze the actual subtype immediately. This is
5735 -- needed, because otherwise this Itype will not get frozen
5736 -- at all, and it is always safe to freeze on creation because
5737 -- any associated types must be frozen at this point.
5739 Freeze_Itype
(Atyp
, N
);
5742 -- Otherwise we did not build a declaration, so return original
5749 -- For all remaining cases, the actual subtype is the same as
5750 -- the nominal type.
5755 end Get_Actual_Subtype
;
5757 -------------------------------------
5758 -- Get_Actual_Subtype_If_Available --
5759 -------------------------------------
5761 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
5762 Typ
: constant Entity_Id
:= Etype
(N
);
5765 -- If what we have is an identifier that references a subprogram
5766 -- formal, or a variable or constant object, then we get the actual
5767 -- subtype from the referenced entity if one has been built.
5769 if Nkind
(N
) = N_Identifier
5771 (Is_Formal
(Entity
(N
))
5772 or else Ekind
(Entity
(N
)) = E_Constant
5773 or else Ekind
(Entity
(N
)) = E_Variable
)
5774 and then Present
(Actual_Subtype
(Entity
(N
)))
5776 return Actual_Subtype
(Entity
(N
));
5778 -- Otherwise the Etype of N is returned unchanged
5783 end Get_Actual_Subtype_If_Available
;
5785 ------------------------
5786 -- Get_Body_From_Stub --
5787 ------------------------
5789 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
5791 return Proper_Body
(Unit
(Library_Unit
(N
)));
5792 end Get_Body_From_Stub
;
5794 -------------------------------
5795 -- Get_Default_External_Name --
5796 -------------------------------
5798 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
5800 Get_Decoded_Name_String
(Chars
(E
));
5802 if Opt
.External_Name_Imp_Casing
= Uppercase
then
5803 Set_Casing
(All_Upper_Case
);
5805 Set_Casing
(All_Lower_Case
);
5809 Make_String_Literal
(Sloc
(E
),
5810 Strval
=> String_From_Name_Buffer
);
5811 end Get_Default_External_Name
;
5813 --------------------------
5814 -- Get_Enclosing_Object --
5815 --------------------------
5817 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
5819 if Is_Entity_Name
(N
) then
5823 when N_Indexed_Component |
5825 N_Selected_Component
=>
5827 -- If not generating code, a dereference may be left implicit.
5828 -- In thoses cases, return Empty.
5830 if Is_Access_Type
(Etype
(Prefix
(N
))) then
5833 return Get_Enclosing_Object
(Prefix
(N
));
5836 when N_Type_Conversion
=>
5837 return Get_Enclosing_Object
(Expression
(N
));
5843 end Get_Enclosing_Object
;
5845 ---------------------------
5846 -- Get_Enum_Lit_From_Pos --
5847 ---------------------------
5849 function Get_Enum_Lit_From_Pos
5852 Loc
: Source_Ptr
) return Node_Id
5854 Btyp
: Entity_Id
:= Base_Type
(T
);
5858 -- In the case where the literal is of type Character, Wide_Character
5859 -- or Wide_Wide_Character or of a type derived from them, there needs
5860 -- to be some special handling since there is no explicit chain of
5861 -- literals to search. Instead, an N_Character_Literal node is created
5862 -- with the appropriate Char_Code and Chars fields.
5864 if Is_Standard_Character_Type
(T
) then
5865 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
5867 Make_Character_Literal
(Loc
,
5869 Char_Literal_Value
=> Pos
);
5871 -- For all other cases, we have a complete table of literals, and
5872 -- we simply iterate through the chain of literal until the one
5873 -- with the desired position value is found.
5877 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
5878 Btyp
:= Full_View
(Btyp
);
5881 Lit
:= First_Literal
(Btyp
);
5882 for J
in 1 .. UI_To_Int
(Pos
) loop
5886 return New_Occurrence_Of
(Lit
, Loc
);
5888 end Get_Enum_Lit_From_Pos
;
5890 ---------------------------------
5891 -- Get_Ensures_From_CTC_Pragma --
5892 ---------------------------------
5894 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
5895 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
5899 if List_Length
(Args
) = 4 then
5900 Res
:= Pick
(Args
, 4);
5902 elsif List_Length
(Args
) = 3 then
5903 Res
:= Pick
(Args
, 3);
5905 if Chars
(Res
) /= Name_Ensures
then
5914 end Get_Ensures_From_CTC_Pragma
;
5916 ------------------------
5917 -- Get_Generic_Entity --
5918 ------------------------
5920 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
5921 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
5923 if Present
(Renamed_Object
(Ent
)) then
5924 return Renamed_Object
(Ent
);
5928 end Get_Generic_Entity
;
5930 -------------------------------------
5931 -- Get_Incomplete_View_Of_Ancestor --
5932 -------------------------------------
5934 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
5935 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
5936 Par_Scope
: Entity_Id
;
5937 Par_Type
: Entity_Id
;
5940 -- The incomplete view of an ancestor is only relevant for private
5941 -- derived types in child units.
5943 if not Is_Derived_Type
(E
)
5944 or else not Is_Child_Unit
(Cur_Unit
)
5949 Par_Scope
:= Scope
(Cur_Unit
);
5950 if No
(Par_Scope
) then
5954 Par_Type
:= Etype
(Base_Type
(E
));
5956 -- Traverse list of ancestor types until we find one declared in
5957 -- a parent or grandparent unit (two levels seem sufficient).
5959 while Present
(Par_Type
) loop
5960 if Scope
(Par_Type
) = Par_Scope
5961 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
5965 elsif not Is_Derived_Type
(Par_Type
) then
5969 Par_Type
:= Etype
(Base_Type
(Par_Type
));
5973 -- If none found, there is no relevant ancestor type.
5977 end Get_Incomplete_View_Of_Ancestor
;
5979 ----------------------
5980 -- Get_Index_Bounds --
5981 ----------------------
5983 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
5984 Kind
: constant Node_Kind
:= Nkind
(N
);
5988 if Kind
= N_Range
then
5990 H
:= High_Bound
(N
);
5992 elsif Kind
= N_Subtype_Indication
then
5993 R
:= Range_Expression
(Constraint
(N
));
6001 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
6002 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
6005 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
6006 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
6010 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
6011 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
6014 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
6015 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
6019 -- N is an expression, indicating a range with one value
6024 end Get_Index_Bounds
;
6026 ----------------------------------
6027 -- Get_Library_Unit_Name_string --
6028 ----------------------------------
6030 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
6031 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
6034 Get_Unit_Name_String
(Unit_Name_Id
);
6036 -- Remove seven last character (" (spec)" or " (body)")
6038 Name_Len
:= Name_Len
- 7;
6039 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
6040 end Get_Library_Unit_Name_String
;
6042 ------------------------
6043 -- Get_Name_Entity_Id --
6044 ------------------------
6046 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
6048 return Entity_Id
(Get_Name_Table_Info
(Id
));
6049 end Get_Name_Entity_Id
;
6051 ------------------------------
6052 -- Get_Name_From_CTC_Pragma --
6053 ------------------------------
6055 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
6056 Arg
: constant Node_Id
:=
6057 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
6059 return Strval
(Expr_Value_S
(Arg
));
6060 end Get_Name_From_CTC_Pragma
;
6066 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
6068 return Get_Pragma_Id
(Pragma_Name
(N
));
6071 ---------------------------
6072 -- Get_Referenced_Object --
6073 ---------------------------
6075 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
6080 while Is_Entity_Name
(R
)
6081 and then Present
(Renamed_Object
(Entity
(R
)))
6083 R
:= Renamed_Object
(Entity
(R
));
6087 end Get_Referenced_Object
;
6089 ------------------------
6090 -- Get_Renamed_Entity --
6091 ------------------------
6093 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
6098 while Present
(Renamed_Entity
(R
)) loop
6099 R
:= Renamed_Entity
(R
);
6103 end Get_Renamed_Entity
;
6105 ----------------------------------
6106 -- Get_Requires_From_CTC_Pragma --
6107 ----------------------------------
6109 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
6110 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
6114 if List_Length
(Args
) >= 3 then
6115 Res
:= Pick
(Args
, 3);
6117 if Chars
(Res
) /= Name_Requires
then
6126 end Get_Requires_From_CTC_Pragma
;
6128 -------------------------
6129 -- Get_Subprogram_Body --
6130 -------------------------
6132 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
6136 Decl
:= Unit_Declaration_Node
(E
);
6138 if Nkind
(Decl
) = N_Subprogram_Body
then
6141 -- The below comment is bad, because it is possible for
6142 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
6144 else -- Nkind (Decl) = N_Subprogram_Declaration
6146 if Present
(Corresponding_Body
(Decl
)) then
6147 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
6149 -- Imported subprogram case
6155 end Get_Subprogram_Body
;
6157 ---------------------------
6158 -- Get_Subprogram_Entity --
6159 ---------------------------
6161 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
6163 Subp_Id
: Entity_Id
;
6166 if Nkind
(Nod
) = N_Accept_Statement
then
6167 Subp
:= Entry_Direct_Name
(Nod
);
6169 elsif Nkind
(Nod
) = N_Slice
then
6170 Subp
:= Prefix
(Nod
);
6176 -- Strip the subprogram call
6179 if Nkind_In
(Subp
, N_Explicit_Dereference
,
6180 N_Indexed_Component
,
6181 N_Selected_Component
)
6183 Subp
:= Prefix
(Subp
);
6185 elsif Nkind_In
(Subp
, N_Type_Conversion
,
6186 N_Unchecked_Type_Conversion
)
6188 Subp
:= Expression
(Subp
);
6195 -- Extract the entity of the subprogram call
6197 if Is_Entity_Name
(Subp
) then
6198 Subp_Id
:= Entity
(Subp
);
6200 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
6201 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
6204 if Is_Subprogram
(Subp_Id
) then
6210 -- The search did not find a construct that denotes a subprogram
6215 end Get_Subprogram_Entity
;
6217 -----------------------------
6218 -- Get_Task_Body_Procedure --
6219 -----------------------------
6221 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
6223 -- Note: A task type may be the completion of a private type with
6224 -- discriminants. When performing elaboration checks on a task
6225 -- declaration, the current view of the type may be the private one,
6226 -- and the procedure that holds the body of the task is held in its
6229 -- This is an odd function, why not have Task_Body_Procedure do
6230 -- the following digging???
6232 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
6233 end Get_Task_Body_Procedure
;
6235 -----------------------
6236 -- Has_Access_Values --
6237 -----------------------
6239 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
6240 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
6243 -- Case of a private type which is not completed yet. This can only
6244 -- happen in the case of a generic format type appearing directly, or
6245 -- as a component of the type to which this function is being applied
6246 -- at the top level. Return False in this case, since we certainly do
6247 -- not know that the type contains access types.
6252 elsif Is_Access_Type
(Typ
) then
6255 elsif Is_Array_Type
(Typ
) then
6256 return Has_Access_Values
(Component_Type
(Typ
));
6258 elsif Is_Record_Type
(Typ
) then
6263 -- Loop to Check components
6265 Comp
:= First_Component_Or_Discriminant
(Typ
);
6266 while Present
(Comp
) loop
6268 -- Check for access component, tag field does not count, even
6269 -- though it is implemented internally using an access type.
6271 if Has_Access_Values
(Etype
(Comp
))
6272 and then Chars
(Comp
) /= Name_uTag
6277 Next_Component_Or_Discriminant
(Comp
);
6286 end Has_Access_Values
;
6288 ------------------------------
6289 -- Has_Compatible_Alignment --
6290 ------------------------------
6292 function Has_Compatible_Alignment
6294 Expr
: Node_Id
) return Alignment_Result
6296 function Has_Compatible_Alignment_Internal
6299 Default
: Alignment_Result
) return Alignment_Result
;
6300 -- This is the internal recursive function that actually does the work.
6301 -- There is one additional parameter, which says what the result should
6302 -- be if no alignment information is found, and there is no definite
6303 -- indication of compatible alignments. At the outer level, this is set
6304 -- to Unknown, but for internal recursive calls in the case where types
6305 -- are known to be correct, it is set to Known_Compatible.
6307 ---------------------------------------
6308 -- Has_Compatible_Alignment_Internal --
6309 ---------------------------------------
6311 function Has_Compatible_Alignment_Internal
6314 Default
: Alignment_Result
) return Alignment_Result
6316 Result
: Alignment_Result
:= Known_Compatible
;
6317 -- Holds the current status of the result. Note that once a value of
6318 -- Known_Incompatible is set, it is sticky and does not get changed
6319 -- to Unknown (the value in Result only gets worse as we go along,
6322 Offs
: Uint
:= No_Uint
;
6323 -- Set to a factor of the offset from the base object when Expr is a
6324 -- selected or indexed component, based on Component_Bit_Offset and
6325 -- Component_Size respectively. A negative value is used to represent
6326 -- a value which is not known at compile time.
6328 procedure Check_Prefix
;
6329 -- Checks the prefix recursively in the case where the expression
6330 -- is an indexed or selected component.
6332 procedure Set_Result
(R
: Alignment_Result
);
6333 -- If R represents a worse outcome (unknown instead of known
6334 -- compatible, or known incompatible), then set Result to R.
6340 procedure Check_Prefix
is
6342 -- The subtlety here is that in doing a recursive call to check
6343 -- the prefix, we have to decide what to do in the case where we
6344 -- don't find any specific indication of an alignment problem.
6346 -- At the outer level, we normally set Unknown as the result in
6347 -- this case, since we can only set Known_Compatible if we really
6348 -- know that the alignment value is OK, but for the recursive
6349 -- call, in the case where the types match, and we have not
6350 -- specified a peculiar alignment for the object, we are only
6351 -- concerned about suspicious rep clauses, the default case does
6352 -- not affect us, since the compiler will, in the absence of such
6353 -- rep clauses, ensure that the alignment is correct.
6355 if Default
= Known_Compatible
6357 (Etype
(Obj
) = Etype
(Expr
)
6358 and then (Unknown_Alignment
(Obj
)
6360 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
6363 (Has_Compatible_Alignment_Internal
6364 (Obj
, Prefix
(Expr
), Known_Compatible
));
6366 -- In all other cases, we need a full check on the prefix
6370 (Has_Compatible_Alignment_Internal
6371 (Obj
, Prefix
(Expr
), Unknown
));
6379 procedure Set_Result
(R
: Alignment_Result
) is
6386 -- Start of processing for Has_Compatible_Alignment_Internal
6389 -- If Expr is a selected component, we must make sure there is no
6390 -- potentially troublesome component clause, and that the record is
6393 if Nkind
(Expr
) = N_Selected_Component
then
6395 -- Packed record always generate unknown alignment
6397 if Is_Packed
(Etype
(Prefix
(Expr
))) then
6398 Set_Result
(Unknown
);
6401 -- Check prefix and component offset
6404 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
6406 -- If Expr is an indexed component, we must make sure there is no
6407 -- potentially troublesome Component_Size clause and that the array
6408 -- is not bit-packed.
6410 elsif Nkind
(Expr
) = N_Indexed_Component
then
6412 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
6413 Ind
: constant Node_Id
:= First_Index
(Typ
);
6416 -- Bit packed array always generates unknown alignment
6418 if Is_Bit_Packed_Array
(Typ
) then
6419 Set_Result
(Unknown
);
6422 -- Check prefix and component offset
6425 Offs
:= Component_Size
(Typ
);
6427 -- Small optimization: compute the full offset when possible
6430 and then Offs
> Uint_0
6431 and then Present
(Ind
)
6432 and then Nkind
(Ind
) = N_Range
6433 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
6434 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
6436 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
6437 - Expr_Value
(Low_Bound
((Ind
))));
6442 -- If we have a null offset, the result is entirely determined by
6443 -- the base object and has already been computed recursively.
6445 if Offs
= Uint_0
then
6448 -- Case where we know the alignment of the object
6450 elsif Known_Alignment
(Obj
) then
6452 ObjA
: constant Uint
:= Alignment
(Obj
);
6453 ExpA
: Uint
:= No_Uint
;
6454 SizA
: Uint
:= No_Uint
;
6457 -- If alignment of Obj is 1, then we are always OK
6460 Set_Result
(Known_Compatible
);
6462 -- Alignment of Obj is greater than 1, so we need to check
6465 -- If we have an offset, see if it is compatible
6467 if Offs
/= No_Uint
and Offs
> Uint_0
then
6468 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
6469 Set_Result
(Known_Incompatible
);
6472 -- See if Expr is an object with known alignment
6474 elsif Is_Entity_Name
(Expr
)
6475 and then Known_Alignment
(Entity
(Expr
))
6477 ExpA
:= Alignment
(Entity
(Expr
));
6479 -- Otherwise, we can use the alignment of the type of
6480 -- Expr given that we already checked for
6481 -- discombobulating rep clauses for the cases of indexed
6482 -- and selected components above.
6484 elsif Known_Alignment
(Etype
(Expr
)) then
6485 ExpA
:= Alignment
(Etype
(Expr
));
6487 -- Otherwise the alignment is unknown
6490 Set_Result
(Default
);
6493 -- If we got an alignment, see if it is acceptable
6495 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
6496 Set_Result
(Known_Incompatible
);
6499 -- If Expr is not a piece of a larger object, see if size
6500 -- is given. If so, check that it is not too small for the
6501 -- required alignment.
6503 if Offs
/= No_Uint
then
6506 -- See if Expr is an object with known size
6508 elsif Is_Entity_Name
(Expr
)
6509 and then Known_Static_Esize
(Entity
(Expr
))
6511 SizA
:= Esize
(Entity
(Expr
));
6513 -- Otherwise, we check the object size of the Expr type
6515 elsif Known_Static_Esize
(Etype
(Expr
)) then
6516 SizA
:= Esize
(Etype
(Expr
));
6519 -- If we got a size, see if it is a multiple of the Obj
6520 -- alignment, if not, then the alignment cannot be
6521 -- acceptable, since the size is always a multiple of the
6524 if SizA
/= No_Uint
then
6525 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
6526 Set_Result
(Known_Incompatible
);
6532 -- If we do not know required alignment, any non-zero offset is a
6533 -- potential problem (but certainly may be OK, so result is unknown).
6535 elsif Offs
/= No_Uint
then
6536 Set_Result
(Unknown
);
6538 -- If we can't find the result by direct comparison of alignment
6539 -- values, then there is still one case that we can determine known
6540 -- result, and that is when we can determine that the types are the
6541 -- same, and no alignments are specified. Then we known that the
6542 -- alignments are compatible, even if we don't know the alignment
6543 -- value in the front end.
6545 elsif Etype
(Obj
) = Etype
(Expr
) then
6547 -- Types are the same, but we have to check for possible size
6548 -- and alignments on the Expr object that may make the alignment
6549 -- different, even though the types are the same.
6551 if Is_Entity_Name
(Expr
) then
6553 -- First check alignment of the Expr object. Any alignment less
6554 -- than Maximum_Alignment is worrisome since this is the case
6555 -- where we do not know the alignment of Obj.
6557 if Known_Alignment
(Entity
(Expr
))
6559 UI_To_Int
(Alignment
(Entity
(Expr
))) <
6560 Ttypes
.Maximum_Alignment
6562 Set_Result
(Unknown
);
6564 -- Now check size of Expr object. Any size that is not an
6565 -- even multiple of Maximum_Alignment is also worrisome
6566 -- since it may cause the alignment of the object to be less
6567 -- than the alignment of the type.
6569 elsif Known_Static_Esize
(Entity
(Expr
))
6571 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
6572 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
6575 Set_Result
(Unknown
);
6577 -- Otherwise same type is decisive
6580 Set_Result
(Known_Compatible
);
6584 -- Another case to deal with is when there is an explicit size or
6585 -- alignment clause when the types are not the same. If so, then the
6586 -- result is Unknown. We don't need to do this test if the Default is
6587 -- Unknown, since that result will be set in any case.
6589 elsif Default
/= Unknown
6590 and then (Has_Size_Clause
(Etype
(Expr
))
6592 Has_Alignment_Clause
(Etype
(Expr
)))
6594 Set_Result
(Unknown
);
6596 -- If no indication found, set default
6599 Set_Result
(Default
);
6602 -- Return worst result found
6605 end Has_Compatible_Alignment_Internal
;
6607 -- Start of processing for Has_Compatible_Alignment
6610 -- If Obj has no specified alignment, then set alignment from the type
6611 -- alignment. Perhaps we should always do this, but for sure we should
6612 -- do it when there is an address clause since we can do more if the
6613 -- alignment is known.
6615 if Unknown_Alignment
(Obj
) then
6616 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
6619 -- Now do the internal call that does all the work
6621 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
6622 end Has_Compatible_Alignment
;
6624 ----------------------
6625 -- Has_Declarations --
6626 ----------------------
6628 function Has_Declarations
(N
: Node_Id
) return Boolean is
6630 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
6632 N_Compilation_Unit_Aux
,
6638 N_Package_Specification
);
6639 end Has_Declarations
;
6645 function Has_Denormals
(E
: Entity_Id
) return Boolean is
6647 return Is_Floating_Point_Type
(E
)
6648 and then Denorm_On_Target
6649 and then not Vax_Float
(E
);
6652 -------------------------------------------
6653 -- Has_Discriminant_Dependent_Constraint --
6654 -------------------------------------------
6656 function Has_Discriminant_Dependent_Constraint
6657 (Comp
: Entity_Id
) return Boolean
6659 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
6660 Subt_Indic
: constant Node_Id
:=
6661 Subtype_Indication
(Component_Definition
(Comp_Decl
));
6666 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
6667 Constr
:= Constraint
(Subt_Indic
);
6669 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
6670 Assn
:= First
(Constraints
(Constr
));
6671 while Present
(Assn
) loop
6672 case Nkind
(Assn
) is
6673 when N_Subtype_Indication |
6677 if Depends_On_Discriminant
(Assn
) then
6681 when N_Discriminant_Association
=>
6682 if Depends_On_Discriminant
(Expression
(Assn
)) then
6697 end Has_Discriminant_Dependent_Constraint
;
6699 --------------------
6700 -- Has_Infinities --
6701 --------------------
6703 function Has_Infinities
(E
: Entity_Id
) return Boolean is
6706 Is_Floating_Point_Type
(E
)
6707 and then Nkind
(Scalar_Range
(E
)) = N_Range
6708 and then Includes_Infinities
(Scalar_Range
(E
));
6711 --------------------
6712 -- Has_Interfaces --
6713 --------------------
6715 function Has_Interfaces
6717 Use_Full_View
: Boolean := True) return Boolean
6719 Typ
: Entity_Id
:= Base_Type
(T
);
6722 -- Handle concurrent types
6724 if Is_Concurrent_Type
(Typ
) then
6725 Typ
:= Corresponding_Record_Type
(Typ
);
6728 if not Present
(Typ
)
6729 or else not Is_Record_Type
(Typ
)
6730 or else not Is_Tagged_Type
(Typ
)
6735 -- Handle private types
6738 and then Present
(Full_View
(Typ
))
6740 Typ
:= Full_View
(Typ
);
6743 -- Handle concurrent record types
6745 if Is_Concurrent_Record_Type
(Typ
)
6746 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
6752 if Is_Interface
(Typ
)
6754 (Is_Record_Type
(Typ
)
6755 and then Present
(Interfaces
(Typ
))
6756 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
6761 exit when Etype
(Typ
) = Typ
6763 -- Handle private types
6765 or else (Present
(Full_View
(Etype
(Typ
)))
6766 and then Full_View
(Etype
(Typ
)) = Typ
)
6768 -- Protect the frontend against wrong source with cyclic
6771 or else Etype
(Typ
) = T
;
6773 -- Climb to the ancestor type handling private types
6775 if Present
(Full_View
(Etype
(Typ
))) then
6776 Typ
:= Full_View
(Etype
(Typ
));
6785 ---------------------------------
6786 -- Has_No_Obvious_Side_Effects --
6787 ---------------------------------
6789 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
6791 -- For now, just handle literals, constants, and non-volatile
6792 -- variables and expressions combining these with operators or
6793 -- short circuit forms.
6795 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
6798 elsif Nkind
(N
) = N_Character_Literal
then
6801 elsif Nkind
(N
) in N_Unary_Op
then
6802 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
6804 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
6805 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
6807 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
6809 elsif Nkind
(N
) = N_Expression_With_Actions
6811 Is_Empty_List
(Actions
(N
))
6813 return Has_No_Obvious_Side_Effects
(Expression
(N
));
6815 elsif Nkind
(N
) in N_Has_Entity
then
6816 return Present
(Entity
(N
))
6817 and then Ekind_In
(Entity
(N
), E_Variable
,
6819 E_Enumeration_Literal
,
6823 and then not Is_Volatile
(Entity
(N
));
6828 end Has_No_Obvious_Side_Effects
;
6830 ------------------------
6831 -- Has_Null_Exclusion --
6832 ------------------------
6834 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
6837 when N_Access_Definition |
6838 N_Access_Function_Definition |
6839 N_Access_Procedure_Definition |
6840 N_Access_To_Object_Definition |
6842 N_Derived_Type_Definition |
6843 N_Function_Specification |
6844 N_Subtype_Declaration
=>
6845 return Null_Exclusion_Present
(N
);
6847 when N_Component_Definition |
6848 N_Formal_Object_Declaration |
6849 N_Object_Renaming_Declaration
=>
6850 if Present
(Subtype_Mark
(N
)) then
6851 return Null_Exclusion_Present
(N
);
6852 else pragma Assert
(Present
(Access_Definition
(N
)));
6853 return Null_Exclusion_Present
(Access_Definition
(N
));
6856 when N_Discriminant_Specification
=>
6857 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
6858 return Null_Exclusion_Present
(Discriminant_Type
(N
));
6860 return Null_Exclusion_Present
(N
);
6863 when N_Object_Declaration
=>
6864 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
6865 return Null_Exclusion_Present
(Object_Definition
(N
));
6867 return Null_Exclusion_Present
(N
);
6870 when N_Parameter_Specification
=>
6871 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
6872 return Null_Exclusion_Present
(Parameter_Type
(N
));
6874 return Null_Exclusion_Present
(N
);
6881 end Has_Null_Exclusion
;
6883 ------------------------
6884 -- Has_Null_Extension --
6885 ------------------------
6887 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
6888 B
: constant Entity_Id
:= Base_Type
(T
);
6893 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
6894 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
6896 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
6898 if Present
(Ext
) then
6899 if Null_Present
(Ext
) then
6902 Comps
:= Component_List
(Ext
);
6904 -- The null component list is rewritten during analysis to
6905 -- include the parent component. Any other component indicates
6906 -- that the extension was not originally null.
6908 return Null_Present
(Comps
)
6909 or else No
(Next
(First
(Component_Items
(Comps
))));
6918 end Has_Null_Extension
;
6920 -------------------------------
6921 -- Has_Overriding_Initialize --
6922 -------------------------------
6924 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
6925 BT
: constant Entity_Id
:= Base_Type
(T
);
6929 if Is_Controlled
(BT
) then
6930 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
6933 elsif Present
(Primitive_Operations
(BT
)) then
6934 P
:= First_Elmt
(Primitive_Operations
(BT
));
6935 while Present
(P
) loop
6937 Init
: constant Entity_Id
:= Node
(P
);
6938 Formal
: constant Entity_Id
:= First_Formal
(Init
);
6940 if Ekind
(Init
) = E_Procedure
6941 and then Chars
(Init
) = Name_Initialize
6942 and then Comes_From_Source
(Init
)
6943 and then Present
(Formal
)
6944 and then Etype
(Formal
) = BT
6945 and then No
(Next_Formal
(Formal
))
6946 and then (Ada_Version
< Ada_2012
6947 or else not Null_Present
(Parent
(Init
)))
6957 -- Here if type itself does not have a non-null Initialize operation:
6958 -- check immediate ancestor.
6960 if Is_Derived_Type
(BT
)
6961 and then Has_Overriding_Initialize
(Etype
(BT
))
6968 end Has_Overriding_Initialize
;
6970 --------------------------------------
6971 -- Has_Preelaborable_Initialization --
6972 --------------------------------------
6974 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
6977 procedure Check_Components
(E
: Entity_Id
);
6978 -- Check component/discriminant chain, sets Has_PE False if a component
6979 -- or discriminant does not meet the preelaborable initialization rules.
6981 ----------------------
6982 -- Check_Components --
6983 ----------------------
6985 procedure Check_Components
(E
: Entity_Id
) is
6989 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
6990 -- Returns True if and only if the expression denoted by N does not
6991 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
6993 ---------------------------------
6994 -- Is_Preelaborable_Expression --
6995 ---------------------------------
6997 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
7001 Comp_Type
: Entity_Id
;
7002 Is_Array_Aggr
: Boolean;
7005 if Is_Static_Expression
(N
) then
7008 elsif Nkind
(N
) = N_Null
then
7011 -- Attributes are allowed in general, even if their prefix is a
7012 -- formal type. (It seems that certain attributes known not to be
7013 -- static might not be allowed, but there are no rules to prevent
7016 elsif Nkind
(N
) = N_Attribute_Reference
then
7019 -- The name of a discriminant evaluated within its parent type is
7020 -- defined to be preelaborable (10.2.1(8)). Note that we test for
7021 -- names that denote discriminals as well as discriminants to
7022 -- catch references occurring within init procs.
7024 elsif Is_Entity_Name
(N
)
7026 (Ekind
(Entity
(N
)) = E_Discriminant
7028 ((Ekind
(Entity
(N
)) = E_Constant
7029 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
7030 and then Present
(Discriminal_Link
(Entity
(N
)))))
7034 elsif Nkind
(N
) = N_Qualified_Expression
then
7035 return Is_Preelaborable_Expression
(Expression
(N
));
7037 -- For aggregates we have to check that each of the associations
7038 -- is preelaborable.
7040 elsif Nkind
(N
) = N_Aggregate
7041 or else Nkind
(N
) = N_Extension_Aggregate
7043 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
7045 if Is_Array_Aggr
then
7046 Comp_Type
:= Component_Type
(Etype
(N
));
7049 -- Check the ancestor part of extension aggregates, which must
7050 -- be either the name of a type that has preelaborable init or
7051 -- an expression that is preelaborable.
7053 if Nkind
(N
) = N_Extension_Aggregate
then
7055 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
7058 if Is_Entity_Name
(Anc_Part
)
7059 and then Is_Type
(Entity
(Anc_Part
))
7061 if not Has_Preelaborable_Initialization
7067 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
7073 -- Check positional associations
7075 Exp
:= First
(Expressions
(N
));
7076 while Present
(Exp
) loop
7077 if not Is_Preelaborable_Expression
(Exp
) then
7084 -- Check named associations
7086 Assn
:= First
(Component_Associations
(N
));
7087 while Present
(Assn
) loop
7088 Choice
:= First
(Choices
(Assn
));
7089 while Present
(Choice
) loop
7090 if Is_Array_Aggr
then
7091 if Nkind
(Choice
) = N_Others_Choice
then
7094 elsif Nkind
(Choice
) = N_Range
then
7095 if not Is_Static_Range
(Choice
) then
7099 elsif not Is_Static_Expression
(Choice
) then
7104 Comp_Type
:= Etype
(Choice
);
7110 -- If the association has a <> at this point, then we have
7111 -- to check whether the component's type has preelaborable
7112 -- initialization. Note that this only occurs when the
7113 -- association's corresponding component does not have a
7114 -- default expression, the latter case having already been
7115 -- expanded as an expression for the association.
7117 if Box_Present
(Assn
) then
7118 if not Has_Preelaborable_Initialization
(Comp_Type
) then
7122 -- In the expression case we check whether the expression
7123 -- is preelaborable.
7126 not Is_Preelaborable_Expression
(Expression
(Assn
))
7134 -- If we get here then aggregate as a whole is preelaborable
7138 -- All other cases are not preelaborable
7143 end Is_Preelaborable_Expression
;
7145 -- Start of processing for Check_Components
7148 -- Loop through entities of record or protected type
7151 while Present
(Ent
) loop
7153 -- We are interested only in components and discriminants
7160 -- Get default expression if any. If there is no declaration
7161 -- node, it means we have an internal entity. The parent and
7162 -- tag fields are examples of such entities. For such cases,
7163 -- we just test the type of the entity.
7165 if Present
(Declaration_Node
(Ent
)) then
7166 Exp
:= Expression
(Declaration_Node
(Ent
));
7169 when E_Discriminant
=>
7171 -- Note: for a renamed discriminant, the Declaration_Node
7172 -- may point to the one from the ancestor, and have a
7173 -- different expression, so use the proper attribute to
7174 -- retrieve the expression from the derived constraint.
7176 Exp
:= Discriminant_Default_Value
(Ent
);
7179 goto Check_Next_Entity
;
7182 -- A component has PI if it has no default expression and the
7183 -- component type has PI.
7186 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
7191 -- Require the default expression to be preelaborable
7193 elsif not Is_Preelaborable_Expression
(Exp
) then
7198 <<Check_Next_Entity
>>
7201 end Check_Components
;
7203 -- Start of processing for Has_Preelaborable_Initialization
7206 -- Immediate return if already marked as known preelaborable init. This
7207 -- covers types for which this function has already been called once
7208 -- and returned True (in which case the result is cached), and also
7209 -- types to which a pragma Preelaborable_Initialization applies.
7211 if Known_To_Have_Preelab_Init
(E
) then
7215 -- If the type is a subtype representing a generic actual type, then
7216 -- test whether its base type has preelaborable initialization since
7217 -- the subtype representing the actual does not inherit this attribute
7218 -- from the actual or formal. (but maybe it should???)
7220 if Is_Generic_Actual_Type
(E
) then
7221 return Has_Preelaborable_Initialization
(Base_Type
(E
));
7224 -- All elementary types have preelaborable initialization
7226 if Is_Elementary_Type
(E
) then
7229 -- Array types have PI if the component type has PI
7231 elsif Is_Array_Type
(E
) then
7232 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
7234 -- A derived type has preelaborable initialization if its parent type
7235 -- has preelaborable initialization and (in the case of a derived record
7236 -- extension) if the non-inherited components all have preelaborable
7237 -- initialization. However, a user-defined controlled type with an
7238 -- overriding Initialize procedure does not have preelaborable
7241 elsif Is_Derived_Type
(E
) then
7243 -- If the derived type is a private extension then it doesn't have
7244 -- preelaborable initialization.
7246 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
7250 -- First check whether ancestor type has preelaborable initialization
7252 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
7254 -- If OK, check extension components (if any)
7256 if Has_PE
and then Is_Record_Type
(E
) then
7257 Check_Components
(First_Entity
(E
));
7260 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
7261 -- with a user defined Initialize procedure does not have PI.
7264 and then Is_Controlled
(E
)
7265 and then Has_Overriding_Initialize
(E
)
7270 -- Private types not derived from a type having preelaborable init and
7271 -- that are not marked with pragma Preelaborable_Initialization do not
7272 -- have preelaborable initialization.
7274 elsif Is_Private_Type
(E
) then
7277 -- Record type has PI if it is non private and all components have PI
7279 elsif Is_Record_Type
(E
) then
7281 Check_Components
(First_Entity
(E
));
7283 -- Protected types must not have entries, and components must meet
7284 -- same set of rules as for record components.
7286 elsif Is_Protected_Type
(E
) then
7287 if Has_Entries
(E
) then
7291 Check_Components
(First_Entity
(E
));
7292 Check_Components
(First_Private_Entity
(E
));
7295 -- Type System.Address always has preelaborable initialization
7297 elsif Is_RTE
(E
, RE_Address
) then
7300 -- In all other cases, type does not have preelaborable initialization
7306 -- If type has preelaborable initialization, cache result
7309 Set_Known_To_Have_Preelab_Init
(E
);
7313 end Has_Preelaborable_Initialization
;
7315 ---------------------------
7316 -- Has_Private_Component --
7317 ---------------------------
7319 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
7320 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
7321 Component
: Entity_Id
;
7324 if Error_Posted
(Type_Id
)
7325 or else Error_Posted
(Btype
)
7330 if Is_Class_Wide_Type
(Btype
) then
7331 Btype
:= Root_Type
(Btype
);
7334 if Is_Private_Type
(Btype
) then
7336 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
7339 if No
(Full_View
(Btype
)) then
7340 return not Is_Generic_Type
(Btype
)
7341 and then not Is_Generic_Type
(Root_Type
(Btype
));
7343 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
7346 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
7350 elsif Is_Array_Type
(Btype
) then
7351 return Has_Private_Component
(Component_Type
(Btype
));
7353 elsif Is_Record_Type
(Btype
) then
7354 Component
:= First_Component
(Btype
);
7355 while Present
(Component
) loop
7356 if Has_Private_Component
(Etype
(Component
)) then
7360 Next_Component
(Component
);
7365 elsif Is_Protected_Type
(Btype
)
7366 and then Present
(Corresponding_Record_Type
(Btype
))
7368 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
7373 end Has_Private_Component
;
7375 ----------------------
7376 -- Has_Signed_Zeros --
7377 ----------------------
7379 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
7381 return Is_Floating_Point_Type
(E
)
7382 and then Signed_Zeros_On_Target
7383 and then not Vax_Float
(E
);
7384 end Has_Signed_Zeros
;
7386 -----------------------------
7387 -- Has_Static_Array_Bounds --
7388 -----------------------------
7390 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
7391 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
7398 -- Unconstrained types do not have static bounds
7400 if not Is_Constrained
(Typ
) then
7404 -- First treat string literals specially, as the lower bound and length
7405 -- of string literals are not stored like those of arrays.
7407 -- A string literal always has static bounds
7409 if Ekind
(Typ
) = E_String_Literal_Subtype
then
7413 -- Treat all dimensions in turn
7415 Index
:= First_Index
(Typ
);
7416 for Indx
in 1 .. Ndims
loop
7418 -- In case of an erroneous index which is not a discrete type, return
7419 -- that the type is not static.
7421 if not Is_Discrete_Type
(Etype
(Index
))
7422 or else Etype
(Index
) = Any_Type
7427 Get_Index_Bounds
(Index
, Low
, High
);
7429 if Error_Posted
(Low
) or else Error_Posted
(High
) then
7433 if Is_OK_Static_Expression
(Low
)
7435 Is_OK_Static_Expression
(High
)
7445 -- If we fall through the loop, all indexes matched
7448 end Has_Static_Array_Bounds
;
7454 function Has_Stream
(T
: Entity_Id
) return Boolean is
7461 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
7464 elsif Is_Array_Type
(T
) then
7465 return Has_Stream
(Component_Type
(T
));
7467 elsif Is_Record_Type
(T
) then
7468 E
:= First_Component
(T
);
7469 while Present
(E
) loop
7470 if Has_Stream
(Etype
(E
)) then
7479 elsif Is_Private_Type
(T
) then
7480 return Has_Stream
(Underlying_Type
(T
));
7491 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
7493 Get_Name_String
(Chars
(E
));
7494 return Name_Buffer
(Name_Len
) = Suffix
;
7501 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
7503 Get_Name_String
(Chars
(E
));
7504 Add_Char_To_Name_Buffer
(Suffix
);
7512 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
7514 pragma Assert
(Has_Suffix
(E
, Suffix
));
7515 Get_Name_String
(Chars
(E
));
7516 Name_Len
:= Name_Len
- 1;
7520 --------------------------
7521 -- Has_Tagged_Component --
7522 --------------------------
7524 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
7528 if Is_Private_Type
(Typ
)
7529 and then Present
(Underlying_Type
(Typ
))
7531 return Has_Tagged_Component
(Underlying_Type
(Typ
));
7533 elsif Is_Array_Type
(Typ
) then
7534 return Has_Tagged_Component
(Component_Type
(Typ
));
7536 elsif Is_Tagged_Type
(Typ
) then
7539 elsif Is_Record_Type
(Typ
) then
7540 Comp
:= First_Component
(Typ
);
7541 while Present
(Comp
) loop
7542 if Has_Tagged_Component
(Etype
(Comp
)) then
7546 Next_Component
(Comp
);
7554 end Has_Tagged_Component
;
7556 -------------------------
7557 -- Implementation_Kind --
7558 -------------------------
7560 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
7561 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
7564 pragma Assert
(Present
(Impl_Prag
));
7565 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
7566 return Chars
(Get_Pragma_Arg
(Arg
));
7567 end Implementation_Kind
;
7569 --------------------------
7570 -- Implements_Interface --
7571 --------------------------
7573 function Implements_Interface
7574 (Typ_Ent
: Entity_Id
;
7575 Iface_Ent
: Entity_Id
;
7576 Exclude_Parents
: Boolean := False) return Boolean
7578 Ifaces_List
: Elist_Id
;
7580 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
7581 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
7584 if Is_Class_Wide_Type
(Typ
) then
7585 Typ
:= Root_Type
(Typ
);
7588 if not Has_Interfaces
(Typ
) then
7592 if Is_Class_Wide_Type
(Iface
) then
7593 Iface
:= Root_Type
(Iface
);
7596 Collect_Interfaces
(Typ
, Ifaces_List
);
7598 Elmt
:= First_Elmt
(Ifaces_List
);
7599 while Present
(Elmt
) loop
7600 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
7601 and then Exclude_Parents
7605 elsif Node
(Elmt
) = Iface
then
7613 end Implements_Interface
;
7619 function In_Instance
return Boolean is
7620 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
7626 and then S
/= Standard_Standard
7628 if (Ekind
(S
) = E_Function
7629 or else Ekind
(S
) = E_Package
7630 or else Ekind
(S
) = E_Procedure
)
7631 and then Is_Generic_Instance
(S
)
7633 -- A child instance is always compiled in the context of a parent
7634 -- instance. Nevertheless, the actuals are not analyzed in an
7635 -- instance context. We detect this case by examining the current
7636 -- compilation unit, which must be a child instance, and checking
7637 -- that it is not currently on the scope stack.
7639 if Is_Child_Unit
(Curr_Unit
)
7641 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
7642 = N_Package_Instantiation
7643 and then not In_Open_Scopes
(Curr_Unit
)
7657 ----------------------
7658 -- In_Instance_Body --
7659 ----------------------
7661 function In_Instance_Body
return Boolean is
7667 and then S
/= Standard_Standard
7669 if (Ekind
(S
) = E_Function
7670 or else Ekind
(S
) = E_Procedure
)
7671 and then Is_Generic_Instance
(S
)
7675 elsif Ekind
(S
) = E_Package
7676 and then In_Package_Body
(S
)
7677 and then Is_Generic_Instance
(S
)
7686 end In_Instance_Body
;
7688 -----------------------------
7689 -- In_Instance_Not_Visible --
7690 -----------------------------
7692 function In_Instance_Not_Visible
return Boolean is
7698 and then S
/= Standard_Standard
7700 if (Ekind
(S
) = E_Function
7701 or else Ekind
(S
) = E_Procedure
)
7702 and then Is_Generic_Instance
(S
)
7706 elsif Ekind
(S
) = E_Package
7707 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
7708 and then Is_Generic_Instance
(S
)
7717 end In_Instance_Not_Visible
;
7719 ------------------------------
7720 -- In_Instance_Visible_Part --
7721 ------------------------------
7723 function In_Instance_Visible_Part
return Boolean is
7729 and then S
/= Standard_Standard
7731 if Ekind
(S
) = E_Package
7732 and then Is_Generic_Instance
(S
)
7733 and then not In_Package_Body
(S
)
7734 and then not In_Private_Part
(S
)
7743 end In_Instance_Visible_Part
;
7745 ---------------------
7746 -- In_Package_Body --
7747 ---------------------
7749 function In_Package_Body
return Boolean is
7755 and then S
/= Standard_Standard
7757 if Ekind
(S
) = E_Package
7758 and then In_Package_Body
(S
)
7767 end In_Package_Body
;
7769 --------------------------------
7770 -- In_Parameter_Specification --
7771 --------------------------------
7773 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
7778 while Present
(PN
) loop
7779 if Nkind
(PN
) = N_Parameter_Specification
then
7787 end In_Parameter_Specification
;
7789 -------------------------------------
7790 -- In_Reverse_Storage_Order_Object --
7791 -------------------------------------
7793 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
7795 Btyp
: Entity_Id
:= Empty
;
7798 -- Climb up indexed components
7802 case Nkind
(Pref
) is
7803 when N_Selected_Component
=>
7804 Pref
:= Prefix
(Pref
);
7807 when N_Indexed_Component
=>
7808 Pref
:= Prefix
(Pref
);
7816 if Present
(Pref
) then
7817 Btyp
:= Base_Type
(Etype
(Pref
));
7822 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
7823 and then Reverse_Storage_Order
(Btyp
);
7824 end In_Reverse_Storage_Order_Object
;
7826 --------------------------------------
7827 -- In_Subprogram_Or_Concurrent_Unit --
7828 --------------------------------------
7830 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
7835 -- Use scope chain to check successively outer scopes
7841 if K
in Subprogram_Kind
7842 or else K
in Concurrent_Kind
7843 or else K
in Generic_Subprogram_Kind
7847 elsif E
= Standard_Standard
then
7853 end In_Subprogram_Or_Concurrent_Unit
;
7855 ---------------------
7856 -- In_Visible_Part --
7857 ---------------------
7859 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
7862 Is_Package_Or_Generic_Package
(Scope_Id
)
7863 and then In_Open_Scopes
(Scope_Id
)
7864 and then not In_Package_Body
(Scope_Id
)
7865 and then not In_Private_Part
(Scope_Id
);
7866 end In_Visible_Part
;
7868 --------------------------------
7869 -- Incomplete_Or_Private_View --
7870 --------------------------------
7872 function Incomplete_Or_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
7873 function Inspect_Decls
7875 Taft
: Boolean := False) return Entity_Id
;
7876 -- Check whether a declarative region contains the incomplete or private
7883 function Inspect_Decls
7885 Taft
: Boolean := False) return Entity_Id
7891 Decl
:= First
(Decls
);
7892 while Present
(Decl
) loop
7896 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
7897 Match
:= Defining_Identifier
(Decl
);
7901 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
7902 N_Private_Type_Declaration
)
7904 Match
:= Defining_Identifier
(Decl
);
7909 and then Present
(Full_View
(Match
))
7910 and then Full_View
(Match
) = Typ
7925 -- Start of processing for Incomplete_Or_Partial_View
7928 -- Incomplete type case
7930 Prev
:= Current_Entity_In_Scope
(Typ
);
7933 and then Is_Incomplete_Type
(Prev
)
7934 and then Present
(Full_View
(Prev
))
7935 and then Full_View
(Prev
) = Typ
7940 -- Private or Taft amendment type case
7943 Pkg
: constant Entity_Id
:= Scope
(Typ
);
7944 Pkg_Decl
: Node_Id
:= Pkg
;
7947 if Ekind
(Pkg
) = E_Package
then
7948 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
7949 Pkg_Decl
:= Parent
(Pkg_Decl
);
7952 -- It is knows that Typ has a private view, look for it in the
7953 -- visible declarations of the enclosing scope. A special case
7954 -- of this is when the two views have been exchanged - the full
7955 -- appears earlier than the private.
7957 if Has_Private_Declaration
(Typ
) then
7958 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
7960 -- Exchanged view case, look in the private declarations
7963 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
7968 -- Otherwise if this is the package body, then Typ is a potential
7969 -- Taft amendment type. The incomplete view should be located in
7970 -- the private declarations of the enclosing scope.
7972 elsif In_Package_Body
(Pkg
) then
7973 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
7978 -- The type has no incomplete or private view
7981 end Incomplete_Or_Private_View
;
7983 ---------------------------------
7984 -- Insert_Explicit_Dereference --
7985 ---------------------------------
7987 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
7988 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
7989 Ent
: Entity_Id
:= Empty
;
7996 Save_Interps
(N
, New_Prefix
);
7999 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
8000 Prefix
=> New_Prefix
));
8002 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
8004 if Is_Overloaded
(New_Prefix
) then
8006 -- The dereference is also overloaded, and its interpretations are
8007 -- the designated types of the interpretations of the original node.
8009 Set_Etype
(N
, Any_Type
);
8011 Get_First_Interp
(New_Prefix
, I
, It
);
8012 while Present
(It
.Nam
) loop
8015 if Is_Access_Type
(T
) then
8016 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
8019 Get_Next_Interp
(I
, It
);
8025 -- Prefix is unambiguous: mark the original prefix (which might
8026 -- Come_From_Source) as a reference, since the new (relocated) one
8027 -- won't be taken into account.
8029 if Is_Entity_Name
(New_Prefix
) then
8030 Ent
:= Entity
(New_Prefix
);
8033 -- For a retrieval of a subcomponent of some composite object,
8034 -- retrieve the ultimate entity if there is one.
8036 elsif Nkind
(New_Prefix
) = N_Selected_Component
8037 or else Nkind
(New_Prefix
) = N_Indexed_Component
8039 Pref
:= Prefix
(New_Prefix
);
8040 while Present
(Pref
)
8042 (Nkind
(Pref
) = N_Selected_Component
8043 or else Nkind
(Pref
) = N_Indexed_Component
)
8045 Pref
:= Prefix
(Pref
);
8048 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
8049 Ent
:= Entity
(Pref
);
8053 -- Place the reference on the entity node
8055 if Present
(Ent
) then
8056 Generate_Reference
(Ent
, Pref
);
8059 end Insert_Explicit_Dereference
;
8061 ------------------------------------------
8062 -- Inspect_Deferred_Constant_Completion --
8063 ------------------------------------------
8065 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
8069 Decl
:= First
(Decls
);
8070 while Present
(Decl
) loop
8072 -- Deferred constant signature
8074 if Nkind
(Decl
) = N_Object_Declaration
8075 and then Constant_Present
(Decl
)
8076 and then No
(Expression
(Decl
))
8078 -- No need to check internally generated constants
8080 and then Comes_From_Source
(Decl
)
8082 -- The constant is not completed. A full object declaration or a
8083 -- pragma Import complete a deferred constant.
8085 and then not Has_Completion
(Defining_Identifier
(Decl
))
8088 ("constant declaration requires initialization expression",
8089 Defining_Identifier
(Decl
));
8092 Decl
:= Next
(Decl
);
8094 end Inspect_Deferred_Constant_Completion
;
8096 -----------------------------
8097 -- Is_Actual_Out_Parameter --
8098 -----------------------------
8100 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
8104 Find_Actual
(N
, Formal
, Call
);
8105 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
8106 end Is_Actual_Out_Parameter
;
8108 -------------------------
8109 -- Is_Actual_Parameter --
8110 -------------------------
8112 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
8113 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
8117 when N_Parameter_Association
=>
8118 return N
= Explicit_Actual_Parameter
(Parent
(N
));
8120 when N_Subprogram_Call
=>
8121 return Is_List_Member
(N
)
8123 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
8128 end Is_Actual_Parameter
;
8130 --------------------------------
8131 -- Is_Actual_Tagged_Parameter --
8132 --------------------------------
8134 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
8138 Find_Actual
(N
, Formal
, Call
);
8139 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
8140 end Is_Actual_Tagged_Parameter
;
8142 ---------------------
8143 -- Is_Aliased_View --
8144 ---------------------
8146 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
8150 if Is_Entity_Name
(Obj
) then
8157 or else (Present
(Renamed_Object
(E
))
8158 and then Is_Aliased_View
(Renamed_Object
(E
)))))
8160 or else ((Is_Formal
(E
)
8161 or else Ekind
(E
) = E_Generic_In_Out_Parameter
8162 or else Ekind
(E
) = E_Generic_In_Parameter
)
8163 and then Is_Tagged_Type
(Etype
(E
)))
8165 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
8167 -- Current instance of type, either directly or as rewritten
8168 -- reference to the current object.
8170 or else (Is_Entity_Name
(Original_Node
(Obj
))
8171 and then Present
(Entity
(Original_Node
(Obj
)))
8172 and then Is_Type
(Entity
(Original_Node
(Obj
))))
8174 or else (Is_Type
(E
) and then E
= Current_Scope
)
8176 or else (Is_Incomplete_Or_Private_Type
(E
)
8177 and then Full_View
(E
) = Current_Scope
)
8179 -- Ada 2012 AI05-0053: the return object of an extended return
8180 -- statement is aliased if its type is immutably limited.
8182 or else (Is_Return_Object
(E
)
8183 and then Is_Limited_View
(Etype
(E
)));
8185 elsif Nkind
(Obj
) = N_Selected_Component
then
8186 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
8188 elsif Nkind
(Obj
) = N_Indexed_Component
then
8189 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
8191 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
8192 and then Has_Aliased_Components
8193 (Designated_Type
(Etype
(Prefix
(Obj
)))));
8195 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
8196 return Is_Tagged_Type
(Etype
(Obj
))
8197 and then Is_Aliased_View
(Expression
(Obj
));
8199 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
8200 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
8205 end Is_Aliased_View
;
8207 -------------------------
8208 -- Is_Ancestor_Package --
8209 -------------------------
8211 function Is_Ancestor_Package
8213 E2
: Entity_Id
) return Boolean
8220 and then Par
/= Standard_Standard
8230 end Is_Ancestor_Package
;
8232 ----------------------
8233 -- Is_Atomic_Object --
8234 ----------------------
8236 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
8238 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
8239 -- Determines if given object has atomic components
8241 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
8242 -- If prefix is an implicit dereference, examine designated type
8244 ----------------------
8245 -- Is_Atomic_Prefix --
8246 ----------------------
8248 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
8250 if Is_Access_Type
(Etype
(N
)) then
8252 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
8254 return Object_Has_Atomic_Components
(N
);
8256 end Is_Atomic_Prefix
;
8258 ----------------------------------
8259 -- Object_Has_Atomic_Components --
8260 ----------------------------------
8262 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
8264 if Has_Atomic_Components
(Etype
(N
))
8265 or else Is_Atomic
(Etype
(N
))
8269 elsif Is_Entity_Name
(N
)
8270 and then (Has_Atomic_Components
(Entity
(N
))
8271 or else Is_Atomic
(Entity
(N
)))
8275 elsif Nkind
(N
) = N_Selected_Component
8276 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
8280 elsif Nkind
(N
) = N_Indexed_Component
8281 or else Nkind
(N
) = N_Selected_Component
8283 return Is_Atomic_Prefix
(Prefix
(N
));
8288 end Object_Has_Atomic_Components
;
8290 -- Start of processing for Is_Atomic_Object
8293 -- Predicate is not relevant to subprograms
8295 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
8298 elsif Is_Atomic
(Etype
(N
))
8299 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
8303 elsif Nkind
(N
) = N_Selected_Component
8304 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
8308 elsif Nkind
(N
) = N_Indexed_Component
8309 or else Nkind
(N
) = N_Selected_Component
8311 return Is_Atomic_Prefix
(Prefix
(N
));
8316 end Is_Atomic_Object
;
8318 -------------------------
8319 -- Is_Attribute_Result --
8320 -------------------------
8322 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
8325 Nkind
(N
) = N_Attribute_Reference
8326 and then Attribute_Name
(N
) = Name_Result
;
8327 end Is_Attribute_Result
;
8329 ------------------------------------
8330 -- Is_Body_Or_Package_Declaration --
8331 ------------------------------------
8333 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
8335 return Nkind_In
(N
, N_Entry_Body
,
8337 N_Package_Declaration
,
8341 end Is_Body_Or_Package_Declaration
;
8343 -----------------------
8344 -- Is_Bounded_String --
8345 -----------------------
8347 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
8348 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
8351 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
8352 -- Super_String, or one of the [Wide_]Wide_ versions. This will
8353 -- be True for all the Bounded_String types in instances of the
8354 -- Generic_Bounded_Length generics, and for types derived from those.
8356 return Present
(Under
)
8357 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
8358 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
8359 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
8360 end Is_Bounded_String
;
8362 -------------------------
8363 -- Is_Child_Or_Sibling --
8364 -------------------------
8366 function Is_Child_Or_Sibling
8367 (Pack_1
: Entity_Id
;
8369 Private_Child
: Boolean) return Boolean
8371 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
8372 -- Given an arbitrary package, return the number of "climbs" necessary
8373 -- to reach scope Standard_Standard.
8375 procedure Equalize_Depths
8376 (Pack
: in out Entity_Id
;
8378 Depth_To_Reach
: Nat
);
8379 -- Given an arbitrary package, its depth and a target depth to reach,
8380 -- climb the scope chain until the said depth is reached. The pointer
8381 -- to the package and its depth a modified during the climb.
8383 function Is_Child
(Pack
: Entity_Id
) return Boolean;
8384 -- Given a package Pack, determine whether it is a child package that
8385 -- satisfies the privacy requirement (if set).
8387 ----------------------------
8388 -- Distance_From_Standard --
8389 ----------------------------
8391 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
8398 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
8400 Scop
:= Scope
(Scop
);
8404 end Distance_From_Standard
;
8406 ---------------------
8407 -- Equalize_Depths --
8408 ---------------------
8410 procedure Equalize_Depths
8411 (Pack
: in out Entity_Id
;
8413 Depth_To_Reach
: Nat
)
8416 -- The package must be at a greater or equal depth
8418 if Depth
< Depth_To_Reach
then
8419 raise Program_Error
;
8422 -- Climb the scope chain until the desired depth is reached
8424 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
8425 Pack
:= Scope
(Pack
);
8428 end Equalize_Depths
;
8434 function Is_Child
(Pack
: Entity_Id
) return Boolean is
8436 if Is_Child_Unit
(Pack
) then
8437 if Private_Child
then
8438 return Is_Private_Descendant
(Pack
);
8443 -- The package is nested, it cannot act a child or a sibling
8452 P_1
: Entity_Id
:= Pack_1
;
8453 P_1_Child
: Boolean := False;
8454 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
8455 P_2
: Entity_Id
:= Pack_2
;
8456 P_2_Child
: Boolean := False;
8457 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
8459 -- Start of processing for Is_Child_Or_Sibling
8463 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
8465 -- Both packages denote the same entity, therefore they cannot be
8466 -- children or siblings.
8471 -- One of the packages is at a deeper level than the other. Note that
8472 -- both may still come from differen hierarchies.
8480 elsif P_1_Depth
> P_2_Depth
then
8481 Equalize_Depths
(P_1
, P_1_Depth
, P_2_Depth
);
8490 elsif P_2_Depth
> P_1_Depth
then
8491 Equalize_Depths
(P_2
, P_2_Depth
, P_1_Depth
);
8495 -- At this stage the package pointers have been elevated to the same
8496 -- depth. If the related entities are the same, then one package is a
8497 -- potential child of the other:
8501 -- X became P_1 P_2 or vica versa
8507 return Is_Child
(Pack_1
);
8508 else pragma Assert
(P_2_Child
);
8509 return Is_Child
(Pack_2
);
8512 -- The packages may come from the same package chain or from entirely
8513 -- different hierarcies. To determine this, climb the scope stack until
8514 -- a common root is found.
8516 -- (root) (root 1) (root 2)
8521 while Present
(P_1
) and then Present
(P_2
) loop
8523 -- The two packages may be siblings
8526 return Is_Child
(Pack_1
) and then Is_Child
(Pack_2
);
8535 end Is_Child_Or_Sibling
;
8537 -----------------------------
8538 -- Is_Concurrent_Interface --
8539 -----------------------------
8541 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
8546 (Is_Protected_Interface
(T
)
8547 or else Is_Synchronized_Interface
(T
)
8548 or else Is_Task_Interface
(T
));
8549 end Is_Concurrent_Interface
;
8551 -----------------------
8552 -- Is_Constant_Bound --
8553 -----------------------
8555 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
8557 if Compile_Time_Known_Value
(Exp
) then
8560 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
8561 return Is_Constant_Object
(Entity
(Exp
))
8562 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
8564 elsif Nkind
(Exp
) in N_Binary_Op
then
8565 return Is_Constant_Bound
(Left_Opnd
(Exp
))
8566 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
8567 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
8572 end Is_Constant_Bound
;
8574 --------------------------------------
8575 -- Is_Controlling_Limited_Procedure --
8576 --------------------------------------
8578 function Is_Controlling_Limited_Procedure
8579 (Proc_Nam
: Entity_Id
) return Boolean
8581 Param_Typ
: Entity_Id
:= Empty
;
8584 if Ekind
(Proc_Nam
) = E_Procedure
8585 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
8587 Param_Typ
:= Etype
(Parameter_Type
(First
(
8588 Parameter_Specifications
(Parent
(Proc_Nam
)))));
8590 -- In this case where an Itype was created, the procedure call has been
8593 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
8594 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
8596 Present
(Parameter_Associations
8597 (Associated_Node_For_Itype
(Proc_Nam
)))
8600 Etype
(First
(Parameter_Associations
8601 (Associated_Node_For_Itype
(Proc_Nam
))));
8604 if Present
(Param_Typ
) then
8606 Is_Interface
(Param_Typ
)
8607 and then Is_Limited_Record
(Param_Typ
);
8611 end Is_Controlling_Limited_Procedure
;
8613 -----------------------------
8614 -- Is_CPP_Constructor_Call --
8615 -----------------------------
8617 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
8619 return Nkind
(N
) = N_Function_Call
8620 and then Is_CPP_Class
(Etype
(Etype
(N
)))
8621 and then Is_Constructor
(Entity
(Name
(N
)))
8622 and then Is_Imported
(Entity
(Name
(N
)));
8623 end Is_CPP_Constructor_Call
;
8629 function Is_Delegate
(T
: Entity_Id
) return Boolean is
8630 Desig_Type
: Entity_Id
;
8633 if VM_Target
/= CLI_Target
then
8637 -- Access-to-subprograms are delegates in CIL
8639 if Ekind
(T
) = E_Access_Subprogram_Type
then
8643 if Ekind
(T
) not in Access_Kind
then
8645 -- A delegate is a managed pointer. If no designated type is defined
8646 -- it means that it's not a delegate.
8651 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
8653 if not Is_Tagged_Type
(Desig_Type
) then
8657 -- Test if the type is inherited from [mscorlib]System.Delegate
8659 while Etype
(Desig_Type
) /= Desig_Type
loop
8660 if Chars
(Scope
(Desig_Type
)) /= No_Name
8661 and then Is_Imported
(Scope
(Desig_Type
))
8662 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
8667 Desig_Type
:= Etype
(Desig_Type
);
8673 ----------------------------------------------
8674 -- Is_Dependent_Component_Of_Mutable_Object --
8675 ----------------------------------------------
8677 function Is_Dependent_Component_Of_Mutable_Object
8678 (Object
: Node_Id
) return Boolean
8681 Prefix_Type
: Entity_Id
;
8682 P_Aliased
: Boolean := False;
8685 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
8686 -- Returns True if and only if Comp is declared within a variant part
8688 --------------------------------
8689 -- Is_Declared_Within_Variant --
8690 --------------------------------
8692 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
8693 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
8694 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
8696 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
8697 end Is_Declared_Within_Variant
;
8699 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
8702 if Is_Variable
(Object
) then
8704 if Nkind
(Object
) = N_Selected_Component
then
8705 P
:= Prefix
(Object
);
8706 Prefix_Type
:= Etype
(P
);
8708 if Is_Entity_Name
(P
) then
8710 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
8711 Prefix_Type
:= Base_Type
(Prefix_Type
);
8714 if Is_Aliased
(Entity
(P
)) then
8718 -- A discriminant check on a selected component may be expanded
8719 -- into a dereference when removing side-effects. Recover the
8720 -- original node and its type, which may be unconstrained.
8722 elsif Nkind
(P
) = N_Explicit_Dereference
8723 and then not (Comes_From_Source
(P
))
8725 P
:= Original_Node
(P
);
8726 Prefix_Type
:= Etype
(P
);
8729 -- Check for prefix being an aliased component???
8735 -- A heap object is constrained by its initial value
8737 -- Ada 2005 (AI-363): Always assume the object could be mutable in
8738 -- the dereferenced case, since the access value might denote an
8739 -- unconstrained aliased object, whereas in Ada 95 the designated
8740 -- object is guaranteed to be constrained. A worst-case assumption
8741 -- has to apply in Ada 2005 because we can't tell at compile time
8742 -- whether the object is "constrained by its initial value"
8743 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
8744 -- semantic rules -- these rules are acknowledged to need fixing).
8746 if Ada_Version
< Ada_2005
then
8747 if Is_Access_Type
(Prefix_Type
)
8748 or else Nkind
(P
) = N_Explicit_Dereference
8753 elsif Ada_Version
>= Ada_2005
then
8754 if Is_Access_Type
(Prefix_Type
) then
8756 -- If the access type is pool-specific, and there is no
8757 -- constrained partial view of the designated type, then the
8758 -- designated object is known to be constrained.
8760 if Ekind
(Prefix_Type
) = E_Access_Type
8761 and then not Object_Type_Has_Constrained_Partial_View
8762 (Typ
=> Designated_Type
(Prefix_Type
),
8763 Scop
=> Current_Scope
)
8767 -- Otherwise (general access type, or there is a constrained
8768 -- partial view of the designated type), we need to check
8769 -- based on the designated type.
8772 Prefix_Type
:= Designated_Type
(Prefix_Type
);
8778 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
8780 -- As per AI-0017, the renaming is illegal in a generic body, even
8781 -- if the subtype is indefinite.
8783 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
8785 if not Is_Constrained
(Prefix_Type
)
8786 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
8788 (Is_Generic_Type
(Prefix_Type
)
8789 and then Ekind
(Current_Scope
) = E_Generic_Package
8790 and then In_Package_Body
(Current_Scope
)))
8792 and then (Is_Declared_Within_Variant
(Comp
)
8793 or else Has_Discriminant_Dependent_Constraint
(Comp
))
8794 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
8798 -- If the prefix is of an access type at this point, then we want
8799 -- to return False, rather than calling this function recursively
8800 -- on the access object (which itself might be a discriminant-
8801 -- dependent component of some other object, but that isn't
8802 -- relevant to checking the object passed to us). This avoids
8803 -- issuing wrong errors when compiling with -gnatc, where there
8804 -- can be implicit dereferences that have not been expanded.
8806 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
8811 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
8814 elsif Nkind
(Object
) = N_Indexed_Component
8815 or else Nkind
(Object
) = N_Slice
8817 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
8819 -- A type conversion that Is_Variable is a view conversion:
8820 -- go back to the denoted object.
8822 elsif Nkind
(Object
) = N_Type_Conversion
then
8824 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
8829 end Is_Dependent_Component_Of_Mutable_Object
;
8831 ---------------------
8832 -- Is_Dereferenced --
8833 ---------------------
8835 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
8836 P
: constant Node_Id
:= Parent
(N
);
8839 (Nkind
(P
) = N_Selected_Component
8841 Nkind
(P
) = N_Explicit_Dereference
8843 Nkind
(P
) = N_Indexed_Component
8845 Nkind
(P
) = N_Slice
)
8846 and then Prefix
(P
) = N
;
8847 end Is_Dereferenced
;
8849 ----------------------
8850 -- Is_Descendent_Of --
8851 ----------------------
8853 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
8858 pragma Assert
(Nkind
(T1
) in N_Entity
);
8859 pragma Assert
(Nkind
(T2
) in N_Entity
);
8861 T
:= Base_Type
(T1
);
8863 -- Immediate return if the types match
8868 -- Comment needed here ???
8870 elsif Ekind
(T
) = E_Class_Wide_Type
then
8871 return Etype
(T
) = T2
;
8879 -- Done if we found the type we are looking for
8884 -- Done if no more derivations to check
8891 -- Following test catches error cases resulting from prev errors
8893 elsif No
(Etyp
) then
8896 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
8899 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
8903 T
:= Base_Type
(Etyp
);
8906 end Is_Descendent_Of
;
8908 ----------------------------
8909 -- Is_Expression_Function --
8910 ----------------------------
8912 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
8916 if Ekind
(Subp
) /= E_Function
then
8920 Decl
:= Unit_Declaration_Node
(Subp
);
8921 return Nkind
(Decl
) = N_Subprogram_Declaration
8923 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
8925 (Present
(Corresponding_Body
(Decl
))
8927 Nkind
(Original_Node
8928 (Unit_Declaration_Node
8929 (Corresponding_Body
(Decl
)))) =
8930 N_Expression_Function
));
8932 end Is_Expression_Function
;
8938 function Is_False
(U
: Uint
) return Boolean is
8943 ---------------------------
8944 -- Is_Fixed_Model_Number --
8945 ---------------------------
8947 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
8948 S
: constant Ureal
:= Small_Value
(T
);
8949 M
: Urealp
.Save_Mark
;
8953 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
8956 end Is_Fixed_Model_Number
;
8958 -------------------------------
8959 -- Is_Fully_Initialized_Type --
8960 -------------------------------
8962 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
8964 -- In Ada2012, a scalar type with an aspect Default_Value
8965 -- is fully initialized.
8967 if Is_Scalar_Type
(Typ
) then
8968 return Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
);
8970 elsif Is_Access_Type
(Typ
) then
8973 elsif Is_Array_Type
(Typ
) then
8974 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
8975 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
8980 -- An interesting case, if we have a constrained type one of whose
8981 -- bounds is known to be null, then there are no elements to be
8982 -- initialized, so all the elements are initialized!
8984 if Is_Constrained
(Typ
) then
8987 Indx_Typ
: Entity_Id
;
8991 Indx
:= First_Index
(Typ
);
8992 while Present
(Indx
) loop
8993 if Etype
(Indx
) = Any_Type
then
8996 -- If index is a range, use directly
8998 elsif Nkind
(Indx
) = N_Range
then
8999 Lbd
:= Low_Bound
(Indx
);
9000 Hbd
:= High_Bound
(Indx
);
9003 Indx_Typ
:= Etype
(Indx
);
9005 if Is_Private_Type
(Indx_Typ
) then
9006 Indx_Typ
:= Full_View
(Indx_Typ
);
9009 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
9012 Lbd
:= Type_Low_Bound
(Indx_Typ
);
9013 Hbd
:= Type_High_Bound
(Indx_Typ
);
9017 if Compile_Time_Known_Value
(Lbd
)
9018 and then Compile_Time_Known_Value
(Hbd
)
9020 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
9030 -- If no null indexes, then type is not fully initialized
9036 elsif Is_Record_Type
(Typ
) then
9037 if Has_Discriminants
(Typ
)
9039 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
9040 and then Is_Fully_Initialized_Variant
(Typ
)
9045 -- We consider bounded string types to be fully initialized, because
9046 -- otherwise we get false alarms when the Data component is not
9047 -- default-initialized.
9049 if Is_Bounded_String
(Typ
) then
9053 -- Controlled records are considered to be fully initialized if
9054 -- there is a user defined Initialize routine. This may not be
9055 -- entirely correct, but as the spec notes, we are guessing here
9056 -- what is best from the point of view of issuing warnings.
9058 if Is_Controlled
(Typ
) then
9060 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
9063 if Present
(Utyp
) then
9065 Init
: constant Entity_Id
:=
9067 (Underlying_Type
(Typ
), Name_Initialize
));
9071 and then Comes_From_Source
(Init
)
9073 Is_Predefined_File_Name
9074 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
9078 elsif Has_Null_Extension
(Typ
)
9080 Is_Fully_Initialized_Type
9081 (Etype
(Base_Type
(Typ
)))
9090 -- Otherwise see if all record components are initialized
9096 Ent
:= First_Entity
(Typ
);
9097 while Present
(Ent
) loop
9098 if Ekind
(Ent
) = E_Component
9099 and then (No
(Parent
(Ent
))
9100 or else No
(Expression
(Parent
(Ent
))))
9101 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
9103 -- Special VM case for tag components, which need to be
9104 -- defined in this case, but are never initialized as VMs
9105 -- are using other dispatching mechanisms. Ignore this
9106 -- uninitialized case. Note that this applies both to the
9107 -- uTag entry and the main vtable pointer (CPP_Class case).
9109 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
9118 -- No uninitialized components, so type is fully initialized.
9119 -- Note that this catches the case of no components as well.
9123 elsif Is_Concurrent_Type
(Typ
) then
9126 elsif Is_Private_Type
(Typ
) then
9128 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
9134 return Is_Fully_Initialized_Type
(U
);
9141 end Is_Fully_Initialized_Type
;
9143 ----------------------------------
9144 -- Is_Fully_Initialized_Variant --
9145 ----------------------------------
9147 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
9148 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9149 Constraints
: constant List_Id
:= New_List
;
9150 Components
: constant Elist_Id
:= New_Elmt_List
;
9151 Comp_Elmt
: Elmt_Id
;
9153 Comp_List
: Node_Id
;
9155 Discr_Val
: Node_Id
;
9157 Report_Errors
: Boolean;
9158 pragma Warnings
(Off
, Report_Errors
);
9161 if Serious_Errors_Detected
> 0 then
9165 if Is_Record_Type
(Typ
)
9166 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
9167 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
9169 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
9171 Discr
:= First_Discriminant
(Typ
);
9172 while Present
(Discr
) loop
9173 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
9174 Discr_Val
:= Expression
(Parent
(Discr
));
9176 if Present
(Discr_Val
)
9177 and then Is_OK_Static_Expression
(Discr_Val
)
9179 Append_To
(Constraints
,
9180 Make_Component_Association
(Loc
,
9181 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
9182 Expression
=> New_Copy
(Discr_Val
)));
9190 Next_Discriminant
(Discr
);
9195 Comp_List
=> Comp_List
,
9196 Governed_By
=> Constraints
,
9198 Report_Errors
=> Report_Errors
);
9200 -- Check that each component present is fully initialized
9202 Comp_Elmt
:= First_Elmt
(Components
);
9203 while Present
(Comp_Elmt
) loop
9204 Comp_Id
:= Node
(Comp_Elmt
);
9206 if Ekind
(Comp_Id
) = E_Component
9207 and then (No
(Parent
(Comp_Id
))
9208 or else No
(Expression
(Parent
(Comp_Id
))))
9209 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
9214 Next_Elmt
(Comp_Elmt
);
9219 elsif Is_Private_Type
(Typ
) then
9221 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
9227 return Is_Fully_Initialized_Variant
(U
);
9234 end Is_Fully_Initialized_Variant
;
9236 ----------------------------
9237 -- Is_Inherited_Operation --
9238 ----------------------------
9240 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
9241 pragma Assert
(Is_Overloadable
(E
));
9242 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
9244 return Kind
= N_Full_Type_Declaration
9245 or else Kind
= N_Private_Extension_Declaration
9246 or else Kind
= N_Subtype_Declaration
9247 or else (Ekind
(E
) = E_Enumeration_Literal
9248 and then Is_Derived_Type
(Etype
(E
)));
9249 end Is_Inherited_Operation
;
9251 -------------------------------------
9252 -- Is_Inherited_Operation_For_Type --
9253 -------------------------------------
9255 function Is_Inherited_Operation_For_Type
9257 Typ
: Entity_Id
) return Boolean
9260 -- Check that the operation has been created by the type declaration
9262 return Is_Inherited_Operation
(E
)
9263 and then Defining_Identifier
(Parent
(E
)) = Typ
;
9264 end Is_Inherited_Operation_For_Type
;
9270 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
9271 Ifaces_List
: Elist_Id
;
9272 Iface_Elmt
: Elmt_Id
;
9276 if Is_Class_Wide_Type
(Typ
)
9278 Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
9279 Name_Reversible_Iterator
)
9281 Is_Predefined_File_Name
9282 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
9286 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
9290 Collect_Interfaces
(Typ
, Ifaces_List
);
9292 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
9293 while Present
(Iface_Elmt
) loop
9294 Iface
:= Node
(Iface_Elmt
);
9295 if Chars
(Iface
) = Name_Forward_Iterator
9297 Is_Predefined_File_Name
9298 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
9303 Next_Elmt
(Iface_Elmt
);
9314 -- We seem to have a lot of overlapping functions that do similar things
9315 -- (testing for left hand sides or lvalues???). Anyway, since this one is
9316 -- purely syntactic, it should be in Sem_Aux I would think???
9318 function Is_LHS
(N
: Node_Id
) return Boolean is
9319 P
: constant Node_Id
:= Parent
(N
);
9322 if Nkind
(P
) = N_Assignment_Statement
then
9323 return Name
(P
) = N
;
9326 Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
9328 return N
= Prefix
(P
) and then Is_LHS
(P
);
9335 -----------------------------
9336 -- Is_Library_Level_Entity --
9337 -----------------------------
9339 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
9341 -- The following is a small optimization, and it also properly handles
9342 -- discriminals, which in task bodies might appear in expressions before
9343 -- the corresponding procedure has been created, and which therefore do
9344 -- not have an assigned scope.
9346 if Is_Formal
(E
) then
9350 -- Normal test is simply that the enclosing dynamic scope is Standard
9352 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
9353 end Is_Library_Level_Entity
;
9355 --------------------------------
9356 -- Is_Limited_Class_Wide_Type --
9357 --------------------------------
9359 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
9362 Is_Class_Wide_Type
(Typ
)
9363 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
9364 end Is_Limited_Class_Wide_Type
;
9366 ---------------------------------
9367 -- Is_Local_Variable_Reference --
9368 ---------------------------------
9370 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
9372 if not Is_Entity_Name
(Expr
) then
9377 Ent
: constant Entity_Id
:= Entity
(Expr
);
9378 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
9380 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
9383 return Present
(Sub
) and then Sub
= Current_Subprogram
;
9387 end Is_Local_Variable_Reference
;
9389 -------------------------
9390 -- Is_Object_Reference --
9391 -------------------------
9393 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
9395 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
9396 -- Determine whether N is the name of an internally-generated renaming
9398 --------------------------------------
9399 -- Is_Internally_Generated_Renaming --
9400 --------------------------------------
9402 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
9407 while Present
(P
) loop
9408 if Nkind
(P
) = N_Object_Renaming_Declaration
then
9409 return not Comes_From_Source
(P
);
9410 elsif Is_List_Member
(P
) then
9418 end Is_Internally_Generated_Renaming
;
9420 -- Start of processing for Is_Object_Reference
9423 if Is_Entity_Name
(N
) then
9424 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
9428 when N_Indexed_Component | N_Slice
=>
9430 Is_Object_Reference
(Prefix
(N
))
9431 or else Is_Access_Type
(Etype
(Prefix
(N
)));
9433 -- In Ada 95, a function call is a constant object; a procedure
9436 when N_Function_Call
=>
9437 return Etype
(N
) /= Standard_Void_Type
;
9439 -- Attributes 'Input, 'Old and 'Result produce objects
9441 when N_Attribute_Reference
=>
9444 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
9446 when N_Selected_Component
=>
9448 Is_Object_Reference
(Selector_Name
(N
))
9450 (Is_Object_Reference
(Prefix
(N
))
9451 or else Is_Access_Type
(Etype
(Prefix
(N
))));
9453 when N_Explicit_Dereference
=>
9456 -- A view conversion of a tagged object is an object reference
9458 when N_Type_Conversion
=>
9459 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
9460 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
9461 and then Is_Object_Reference
(Expression
(N
));
9463 -- An unchecked type conversion is considered to be an object if
9464 -- the operand is an object (this construction arises only as a
9465 -- result of expansion activities).
9467 when N_Unchecked_Type_Conversion
=>
9470 -- Allow string literals to act as objects as long as they appear
9471 -- in internally-generated renamings. The expansion of iterators
9472 -- may generate such renamings when the range involves a string
9475 when N_String_Literal
=>
9476 return Is_Internally_Generated_Renaming
(Parent
(N
));
9478 -- AI05-0003: In Ada 2012 a qualified expression is a name.
9479 -- This allows disambiguation of function calls and the use
9480 -- of aggregates in more contexts.
9482 when N_Qualified_Expression
=>
9483 if Ada_Version
< Ada_2012
then
9486 return Is_Object_Reference
(Expression
(N
))
9487 or else Nkind
(Expression
(N
)) = N_Aggregate
;
9494 end Is_Object_Reference
;
9496 -----------------------------------
9497 -- Is_OK_Variable_For_Out_Formal --
9498 -----------------------------------
9500 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
9502 Note_Possible_Modification
(AV
, Sure
=> True);
9504 -- We must reject parenthesized variable names. Comes_From_Source is
9505 -- checked because there are currently cases where the compiler violates
9506 -- this rule (e.g. passing a task object to its controlled Initialize
9507 -- routine). This should be properly documented in sinfo???
9509 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
9512 -- A variable is always allowed
9514 elsif Is_Variable
(AV
) then
9517 -- Unchecked conversions are allowed only if they come from the
9518 -- generated code, which sometimes uses unchecked conversions for out
9519 -- parameters in cases where code generation is unaffected. We tell
9520 -- source unchecked conversions by seeing if they are rewrites of
9521 -- an original Unchecked_Conversion function call, or of an explicit
9522 -- conversion of a function call or an aggregate (as may happen in the
9523 -- expansion of a packed array aggregate).
9525 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
9526 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
9529 elsif Comes_From_Source
(AV
)
9530 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
9534 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
9535 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
9541 -- Normal type conversions are allowed if argument is a variable
9543 elsif Nkind
(AV
) = N_Type_Conversion
then
9544 if Is_Variable
(Expression
(AV
))
9545 and then Paren_Count
(Expression
(AV
)) = 0
9547 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
9550 -- We also allow a non-parenthesized expression that raises
9551 -- constraint error if it rewrites what used to be a variable
9553 elsif Raises_Constraint_Error
(Expression
(AV
))
9554 and then Paren_Count
(Expression
(AV
)) = 0
9555 and then Is_Variable
(Original_Node
(Expression
(AV
)))
9559 -- Type conversion of something other than a variable
9565 -- If this node is rewritten, then test the original form, if that is
9566 -- OK, then we consider the rewritten node OK (for example, if the
9567 -- original node is a conversion, then Is_Variable will not be true
9568 -- but we still want to allow the conversion if it converts a variable).
9570 elsif Original_Node
(AV
) /= AV
then
9572 -- In Ada 2012, the explicit dereference may be a rewritten call to a
9573 -- Reference function.
9575 if Ada_Version
>= Ada_2012
9576 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
9578 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
9583 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
9586 -- All other non-variables are rejected
9591 end Is_OK_Variable_For_Out_Formal
;
9593 -----------------------------------
9594 -- Is_Partially_Initialized_Type --
9595 -----------------------------------
9597 function Is_Partially_Initialized_Type
9599 Include_Implicit
: Boolean := True) return Boolean
9602 if Is_Scalar_Type
(Typ
) then
9605 elsif Is_Access_Type
(Typ
) then
9606 return Include_Implicit
;
9608 elsif Is_Array_Type
(Typ
) then
9610 -- If component type is partially initialized, so is array type
9612 if Is_Partially_Initialized_Type
9613 (Component_Type
(Typ
), Include_Implicit
)
9617 -- Otherwise we are only partially initialized if we are fully
9618 -- initialized (this is the empty array case, no point in us
9619 -- duplicating that code here).
9622 return Is_Fully_Initialized_Type
(Typ
);
9625 elsif Is_Record_Type
(Typ
) then
9627 -- A discriminated type is always partially initialized if in
9630 if Has_Discriminants
(Typ
) and then Include_Implicit
then
9633 -- A tagged type is always partially initialized
9635 elsif Is_Tagged_Type
(Typ
) then
9638 -- Case of non-discriminated record
9644 Component_Present
: Boolean := False;
9645 -- Set True if at least one component is present. If no
9646 -- components are present, then record type is fully
9647 -- initialized (another odd case, like the null array).
9650 -- Loop through components
9652 Ent
:= First_Entity
(Typ
);
9653 while Present
(Ent
) loop
9654 if Ekind
(Ent
) = E_Component
then
9655 Component_Present
:= True;
9657 -- If a component has an initialization expression then
9658 -- the enclosing record type is partially initialized
9660 if Present
(Parent
(Ent
))
9661 and then Present
(Expression
(Parent
(Ent
)))
9665 -- If a component is of a type which is itself partially
9666 -- initialized, then the enclosing record type is also.
9668 elsif Is_Partially_Initialized_Type
9669 (Etype
(Ent
), Include_Implicit
)
9678 -- No initialized components found. If we found any components
9679 -- they were all uninitialized so the result is false.
9681 if Component_Present
then
9684 -- But if we found no components, then all the components are
9685 -- initialized so we consider the type to be initialized.
9693 -- Concurrent types are always fully initialized
9695 elsif Is_Concurrent_Type
(Typ
) then
9698 -- For a private type, go to underlying type. If there is no underlying
9699 -- type then just assume this partially initialized. Not clear if this
9700 -- can happen in a non-error case, but no harm in testing for this.
9702 elsif Is_Private_Type
(Typ
) then
9704 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
9709 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
9713 -- For any other type (are there any?) assume partially initialized
9718 end Is_Partially_Initialized_Type
;
9720 ------------------------------------
9721 -- Is_Potentially_Persistent_Type --
9722 ------------------------------------
9724 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
9729 -- For private type, test corresponding full type
9731 if Is_Private_Type
(T
) then
9732 return Is_Potentially_Persistent_Type
(Full_View
(T
));
9734 -- Scalar types are potentially persistent
9736 elsif Is_Scalar_Type
(T
) then
9739 -- Record type is potentially persistent if not tagged and the types of
9740 -- all it components are potentially persistent, and no component has
9741 -- an initialization expression.
9743 elsif Is_Record_Type
(T
)
9744 and then not Is_Tagged_Type
(T
)
9745 and then not Is_Partially_Initialized_Type
(T
)
9747 Comp
:= First_Component
(T
);
9748 while Present
(Comp
) loop
9749 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
9758 -- Array type is potentially persistent if its component type is
9759 -- potentially persistent and if all its constraints are static.
9761 elsif Is_Array_Type
(T
) then
9762 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
9766 Indx
:= First_Index
(T
);
9767 while Present
(Indx
) loop
9768 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
9777 -- All other types are not potentially persistent
9782 end Is_Potentially_Persistent_Type
;
9784 ---------------------------------
9785 -- Is_Protected_Self_Reference --
9786 ---------------------------------
9788 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
9790 function In_Access_Definition
(N
: Node_Id
) return Boolean;
9791 -- Returns true if N belongs to an access definition
9793 --------------------------
9794 -- In_Access_Definition --
9795 --------------------------
9797 function In_Access_Definition
(N
: Node_Id
) return Boolean is
9802 while Present
(P
) loop
9803 if Nkind
(P
) = N_Access_Definition
then
9811 end In_Access_Definition
;
9813 -- Start of processing for Is_Protected_Self_Reference
9816 -- Verify that prefix is analyzed and has the proper form. Note that
9817 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
9818 -- which also produce the address of an entity, do not analyze their
9819 -- prefix because they denote entities that are not necessarily visible.
9820 -- Neither of them can apply to a protected type.
9822 return Ada_Version
>= Ada_2005
9823 and then Is_Entity_Name
(N
)
9824 and then Present
(Entity
(N
))
9825 and then Is_Protected_Type
(Entity
(N
))
9826 and then In_Open_Scopes
(Entity
(N
))
9827 and then not In_Access_Definition
(N
);
9828 end Is_Protected_Self_Reference
;
9830 -----------------------------
9831 -- Is_RCI_Pkg_Spec_Or_Body --
9832 -----------------------------
9834 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
9836 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
9837 -- Return True if the unit of Cunit is an RCI package declaration
9839 ---------------------------
9840 -- Is_RCI_Pkg_Decl_Cunit --
9841 ---------------------------
9843 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
9844 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
9847 if Nkind
(The_Unit
) /= N_Package_Declaration
then
9851 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
9852 end Is_RCI_Pkg_Decl_Cunit
;
9854 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
9857 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
9859 (Nkind
(Unit
(Cunit
)) = N_Package_Body
9860 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
9861 end Is_RCI_Pkg_Spec_Or_Body
;
9863 -----------------------------------------
9864 -- Is_Remote_Access_To_Class_Wide_Type --
9865 -----------------------------------------
9867 function Is_Remote_Access_To_Class_Wide_Type
9868 (E
: Entity_Id
) return Boolean
9871 -- A remote access to class-wide type is a general access to object type
9872 -- declared in the visible part of a Remote_Types or Remote_Call_
9875 return Ekind
(E
) = E_General_Access_Type
9876 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
9877 end Is_Remote_Access_To_Class_Wide_Type
;
9879 -----------------------------------------
9880 -- Is_Remote_Access_To_Subprogram_Type --
9881 -----------------------------------------
9883 function Is_Remote_Access_To_Subprogram_Type
9884 (E
: Entity_Id
) return Boolean
9887 return (Ekind
(E
) = E_Access_Subprogram_Type
9888 or else (Ekind
(E
) = E_Record_Type
9889 and then Present
(Corresponding_Remote_Type
(E
))))
9890 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
9891 end Is_Remote_Access_To_Subprogram_Type
;
9893 --------------------
9894 -- Is_Remote_Call --
9895 --------------------
9897 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
9899 if Nkind
(N
) not in N_Subprogram_Call
then
9901 -- An entry call cannot be remote
9905 elsif Nkind
(Name
(N
)) in N_Has_Entity
9906 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
9908 -- A subprogram declared in the spec of a RCI package is remote
9912 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
9913 and then Is_Remote_Access_To_Subprogram_Type
9914 (Etype
(Prefix
(Name
(N
))))
9916 -- The dereference of a RAS is a remote call
9920 elsif Present
(Controlling_Argument
(N
))
9921 and then Is_Remote_Access_To_Class_Wide_Type
9922 (Etype
(Controlling_Argument
(N
)))
9924 -- Any primitive operation call with a controlling argument of
9925 -- a RACW type is a remote call.
9930 -- All other calls are local calls
9935 ----------------------
9936 -- Is_Renamed_Entry --
9937 ----------------------
9939 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
9940 Orig_Node
: Node_Id
:= Empty
;
9941 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
9943 function Is_Entry
(Nam
: Node_Id
) return Boolean;
9944 -- Determine whether Nam is an entry. Traverse selectors if there are
9945 -- nested selected components.
9951 function Is_Entry
(Nam
: Node_Id
) return Boolean is
9953 if Nkind
(Nam
) = N_Selected_Component
then
9954 return Is_Entry
(Selector_Name
(Nam
));
9957 return Ekind
(Entity
(Nam
)) = E_Entry
;
9960 -- Start of processing for Is_Renamed_Entry
9963 if Present
(Alias
(Proc_Nam
)) then
9964 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
9967 -- Look for a rewritten subprogram renaming declaration
9969 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
9970 and then Present
(Original_Node
(Subp_Decl
))
9972 Orig_Node
:= Original_Node
(Subp_Decl
);
9975 -- The rewritten subprogram is actually an entry
9977 if Present
(Orig_Node
)
9978 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
9979 and then Is_Entry
(Name
(Orig_Node
))
9985 end Is_Renamed_Entry
;
9987 ----------------------------
9988 -- Is_Reversible_Iterator --
9989 ----------------------------
9991 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
9992 Ifaces_List
: Elist_Id
;
9993 Iface_Elmt
: Elmt_Id
;
9997 if Is_Class_Wide_Type
(Typ
)
9998 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
10000 Is_Predefined_File_Name
10001 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
10005 elsif not Is_Tagged_Type
(Typ
)
10006 or else not Is_Derived_Type
(Typ
)
10011 Collect_Interfaces
(Typ
, Ifaces_List
);
10013 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
10014 while Present
(Iface_Elmt
) loop
10015 Iface
:= Node
(Iface_Elmt
);
10016 if Chars
(Iface
) = Name_Reversible_Iterator
10018 Is_Predefined_File_Name
10019 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
10024 Next_Elmt
(Iface_Elmt
);
10029 end Is_Reversible_Iterator
;
10031 ----------------------
10032 -- Is_Selector_Name --
10033 ----------------------
10035 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
10037 if not Is_List_Member
(N
) then
10039 P
: constant Node_Id
:= Parent
(N
);
10040 K
: constant Node_Kind
:= Nkind
(P
);
10043 (K
= N_Expanded_Name
or else
10044 K
= N_Generic_Association
or else
10045 K
= N_Parameter_Association
or else
10046 K
= N_Selected_Component
)
10047 and then Selector_Name
(P
) = N
;
10052 L
: constant List_Id
:= List_Containing
(N
);
10053 P
: constant Node_Id
:= Parent
(L
);
10055 return (Nkind
(P
) = N_Discriminant_Association
10056 and then Selector_Names
(P
) = L
)
10058 (Nkind
(P
) = N_Component_Association
10059 and then Choices
(P
) = L
);
10062 end Is_Selector_Name
;
10064 ----------------------------------
10065 -- Is_SPARK_Initialization_Expr --
10066 ----------------------------------
10068 function Is_SPARK_Initialization_Expr
(N
: Node_Id
) return Boolean is
10071 Comp_Assn
: Node_Id
;
10072 Orig_N
: constant Node_Id
:= Original_Node
(N
);
10077 if not Comes_From_Source
(Orig_N
) then
10081 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
10083 case Nkind
(Orig_N
) is
10084 when N_Character_Literal |
10085 N_Integer_Literal |
10087 N_String_Literal
=>
10090 when N_Identifier |
10092 if Is_Entity_Name
(Orig_N
)
10093 and then Present
(Entity
(Orig_N
)) -- needed in some cases
10095 case Ekind
(Entity
(Orig_N
)) is
10097 E_Enumeration_Literal |
10102 if Is_Type
(Entity
(Orig_N
)) then
10110 when N_Qualified_Expression |
10111 N_Type_Conversion
=>
10112 Is_Ok
:= Is_SPARK_Initialization_Expr
(Expression
(Orig_N
));
10115 Is_Ok
:= Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
10119 N_Membership_Test
=>
10120 Is_Ok
:= Is_SPARK_Initialization_Expr
(Left_Opnd
(Orig_N
))
10121 and then Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
10124 N_Extension_Aggregate
=>
10125 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
10126 Is_Ok
:= Is_SPARK_Initialization_Expr
(Ancestor_Part
(Orig_N
));
10129 Expr
:= First
(Expressions
(Orig_N
));
10130 while Present
(Expr
) loop
10131 if not Is_SPARK_Initialization_Expr
(Expr
) then
10139 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
10140 while Present
(Comp_Assn
) loop
10141 Expr
:= Expression
(Comp_Assn
);
10142 if Present
(Expr
) -- needed for box association
10143 and then not Is_SPARK_Initialization_Expr
(Expr
)
10152 when N_Attribute_Reference
=>
10153 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
10154 Is_Ok
:= Is_SPARK_Initialization_Expr
(Prefix
(Orig_N
));
10157 Expr
:= First
(Expressions
(Orig_N
));
10158 while Present
(Expr
) loop
10159 if not Is_SPARK_Initialization_Expr
(Expr
) then
10167 -- Selected components might be expanded named not yet resolved, so
10168 -- default on the safe side. (Eg on sparklex.ads)
10170 when N_Selected_Component
=>
10179 end Is_SPARK_Initialization_Expr
;
10181 -------------------------------
10182 -- Is_SPARK_Object_Reference --
10183 -------------------------------
10185 function Is_SPARK_Object_Reference
(N
: Node_Id
) return Boolean is
10187 if Is_Entity_Name
(N
) then
10188 return Present
(Entity
(N
))
10190 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
10191 or else Ekind
(Entity
(N
)) in Formal_Kind
);
10195 when N_Selected_Component
=>
10196 return Is_SPARK_Object_Reference
(Prefix
(N
));
10202 end Is_SPARK_Object_Reference
;
10208 function Is_Statement
(N
: Node_Id
) return Boolean is
10211 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
10212 or else Nkind
(N
) = N_Procedure_Call_Statement
;
10215 --------------------------------------------------
10216 -- Is_Subprogram_Stub_Without_Prior_Declaration --
10217 --------------------------------------------------
10219 function Is_Subprogram_Stub_Without_Prior_Declaration
10220 (N
: Node_Id
) return Boolean
10223 -- A subprogram stub without prior declaration serves as declaration for
10224 -- the actual subprogram body. As such, it has an attached defining
10225 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
10227 return Nkind
(N
) = N_Subprogram_Body_Stub
10228 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
10229 end Is_Subprogram_Stub_Without_Prior_Declaration
;
10231 ---------------------------------
10232 -- Is_Synchronized_Tagged_Type --
10233 ---------------------------------
10235 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
10236 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
10239 -- A task or protected type derived from an interface is a tagged type.
10240 -- Such a tagged type is called a synchronized tagged type, as are
10241 -- synchronized interfaces and private extensions whose declaration
10242 -- includes the reserved word synchronized.
10244 return (Is_Tagged_Type
(E
)
10245 and then (Kind
= E_Task_Type
10246 or else Kind
= E_Protected_Type
))
10249 and then Is_Synchronized_Interface
(E
))
10251 (Ekind
(E
) = E_Record_Type_With_Private
10252 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
10253 and then (Synchronized_Present
(Parent
(E
))
10254 or else Is_Synchronized_Interface
(Etype
(E
))));
10255 end Is_Synchronized_Tagged_Type
;
10261 function Is_Transfer
(N
: Node_Id
) return Boolean is
10262 Kind
: constant Node_Kind
:= Nkind
(N
);
10265 if Kind
= N_Simple_Return_Statement
10267 Kind
= N_Extended_Return_Statement
10269 Kind
= N_Goto_Statement
10271 Kind
= N_Raise_Statement
10273 Kind
= N_Requeue_Statement
10277 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
10278 and then No
(Condition
(N
))
10282 elsif Kind
= N_Procedure_Call_Statement
10283 and then Is_Entity_Name
(Name
(N
))
10284 and then Present
(Entity
(Name
(N
)))
10285 and then No_Return
(Entity
(Name
(N
)))
10289 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
10301 function Is_True
(U
: Uint
) return Boolean is
10306 -------------------------------
10307 -- Is_Universal_Numeric_Type --
10308 -------------------------------
10310 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
10312 return T
= Universal_Integer
or else T
= Universal_Real
;
10313 end Is_Universal_Numeric_Type
;
10315 -------------------
10316 -- Is_Value_Type --
10317 -------------------
10319 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
10321 return VM_Target
= CLI_Target
10322 and then Nkind
(T
) in N_Has_Chars
10323 and then Chars
(T
) /= No_Name
10324 and then Get_Name_String
(Chars
(T
)) = "valuetype";
10327 ----------------------------
10328 -- Is_Variable_Size_Array --
10329 ----------------------------
10331 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
10335 pragma Assert
(Is_Array_Type
(E
));
10337 -- Check if some index is initialized with a non-constant value
10339 Idx
:= First_Index
(E
);
10340 while Present
(Idx
) loop
10341 if Nkind
(Idx
) = N_Range
then
10342 if not Is_Constant_Bound
(Low_Bound
(Idx
))
10343 or else not Is_Constant_Bound
(High_Bound
(Idx
))
10349 Idx
:= Next_Index
(Idx
);
10353 end Is_Variable_Size_Array
;
10355 -----------------------------
10356 -- Is_Variable_Size_Record --
10357 -----------------------------
10359 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
10361 Comp_Typ
: Entity_Id
;
10364 pragma Assert
(Is_Record_Type
(E
));
10366 Comp
:= First_Entity
(E
);
10367 while Present
(Comp
) loop
10368 Comp_Typ
:= Etype
(Comp
);
10370 -- Recursive call if the record type has discriminants
10372 if Is_Record_Type
(Comp_Typ
)
10373 and then Has_Discriminants
(Comp_Typ
)
10374 and then Is_Variable_Size_Record
(Comp_Typ
)
10378 elsif Is_Array_Type
(Comp_Typ
)
10379 and then Is_Variable_Size_Array
(Comp_Typ
)
10384 Next_Entity
(Comp
);
10388 end Is_Variable_Size_Record
;
10390 ---------------------
10391 -- Is_VMS_Operator --
10392 ---------------------
10394 function Is_VMS_Operator
(Op
: Entity_Id
) return Boolean is
10396 -- The VMS operators are declared in a child of System that is loaded
10397 -- through pragma Extend_System. In some rare cases a program is run
10398 -- with this extension but without indicating that the target is VMS.
10400 return Ekind
(Op
) = E_Function
10401 and then Is_Intrinsic_Subprogram
(Op
)
10403 ((Present_System_Aux
and then Scope
(Op
) = System_Aux_Id
)
10406 and then Scope
(Scope
(Op
)) = RTU_Entity
(System
)));
10407 end Is_VMS_Operator
;
10413 function Is_Variable
10415 Use_Original_Node
: Boolean := True) return Boolean
10417 Orig_Node
: Node_Id
;
10419 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
10420 -- Within a protected function, the private components of the enclosing
10421 -- protected type are constants. A function nested within a (protected)
10422 -- procedure is not itself protected. Within the body of a protected
10423 -- function the current instance of the protected type is a constant.
10425 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
10426 -- Prefixes can involve implicit dereferences, in which case we must
10427 -- test for the case of a reference of a constant access type, which can
10428 -- can never be a variable.
10430 ---------------------------
10431 -- In_Protected_Function --
10432 ---------------------------
10434 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
10439 -- E is the current instance of a type
10441 if Is_Type
(E
) then
10450 if not Is_Protected_Type
(Prot
) then
10454 S
:= Current_Scope
;
10455 while Present
(S
) and then S
/= Prot
loop
10456 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
10465 end In_Protected_Function
;
10467 ------------------------
10468 -- Is_Variable_Prefix --
10469 ------------------------
10471 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
10473 if Is_Access_Type
(Etype
(P
)) then
10474 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
10476 -- For the case of an indexed component whose prefix has a packed
10477 -- array type, the prefix has been rewritten into a type conversion.
10478 -- Determine variable-ness from the converted expression.
10480 elsif Nkind
(P
) = N_Type_Conversion
10481 and then not Comes_From_Source
(P
)
10482 and then Is_Array_Type
(Etype
(P
))
10483 and then Is_Packed
(Etype
(P
))
10485 return Is_Variable
(Expression
(P
));
10488 return Is_Variable
(P
);
10490 end Is_Variable_Prefix
;
10492 -- Start of processing for Is_Variable
10495 -- Check if we perform the test on the original node since this may be a
10496 -- test of syntactic categories which must not be disturbed by whatever
10497 -- rewriting might have occurred. For example, an aggregate, which is
10498 -- certainly NOT a variable, could be turned into a variable by
10501 if Use_Original_Node
then
10502 Orig_Node
:= Original_Node
(N
);
10507 -- Definitely OK if Assignment_OK is set. Since this is something that
10508 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
10510 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
10513 -- Normally we go to the original node, but there is one exception where
10514 -- we use the rewritten node, namely when it is an explicit dereference.
10515 -- The generated code may rewrite a prefix which is an access type with
10516 -- an explicit dereference. The dereference is a variable, even though
10517 -- the original node may not be (since it could be a constant of the
10520 -- In Ada 2005 we have a further case to consider: the prefix may be a
10521 -- function call given in prefix notation. The original node appears to
10522 -- be a selected component, but we need to examine the call.
10524 elsif Nkind
(N
) = N_Explicit_Dereference
10525 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
10526 and then Present
(Etype
(Orig_Node
))
10527 and then Is_Access_Type
(Etype
(Orig_Node
))
10529 -- Note that if the prefix is an explicit dereference that does not
10530 -- come from source, we must check for a rewritten function call in
10531 -- prefixed notation before other forms of rewriting, to prevent a
10535 (Nkind
(Orig_Node
) = N_Function_Call
10536 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
10538 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
10540 -- in Ada 2012, the dereference may have been added for a type with
10541 -- a declared implicit dereference aspect.
10543 elsif Nkind
(N
) = N_Explicit_Dereference
10544 and then Present
(Etype
(Orig_Node
))
10545 and then Ada_Version
>= Ada_2012
10546 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
10550 -- A function call is never a variable
10552 elsif Nkind
(N
) = N_Function_Call
then
10555 -- All remaining checks use the original node
10557 elsif Is_Entity_Name
(Orig_Node
)
10558 and then Present
(Entity
(Orig_Node
))
10561 E
: constant Entity_Id
:= Entity
(Orig_Node
);
10562 K
: constant Entity_Kind
:= Ekind
(E
);
10565 return (K
= E_Variable
10566 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
10567 or else (K
= E_Component
10568 and then not In_Protected_Function
(E
))
10569 or else K
= E_Out_Parameter
10570 or else K
= E_In_Out_Parameter
10571 or else K
= E_Generic_In_Out_Parameter
10573 -- Current instance of type. If this is a protected type, check
10574 -- we are not within the body of one of its protected functions.
10576 or else (Is_Type
(E
)
10577 and then In_Open_Scopes
(E
)
10578 and then not In_Protected_Function
(E
))
10580 or else (Is_Incomplete_Or_Private_Type
(E
)
10581 and then In_Open_Scopes
(Full_View
(E
)));
10585 case Nkind
(Orig_Node
) is
10586 when N_Indexed_Component | N_Slice
=>
10587 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
10589 when N_Selected_Component
=>
10590 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
10591 and then Is_Variable
(Selector_Name
(Orig_Node
));
10593 -- For an explicit dereference, the type of the prefix cannot
10594 -- be an access to constant or an access to subprogram.
10596 when N_Explicit_Dereference
=>
10598 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
10600 return Is_Access_Type
(Typ
)
10601 and then not Is_Access_Constant
(Root_Type
(Typ
))
10602 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
10605 -- The type conversion is the case where we do not deal with the
10606 -- context dependent special case of an actual parameter. Thus
10607 -- the type conversion is only considered a variable for the
10608 -- purposes of this routine if the target type is tagged. However,
10609 -- a type conversion is considered to be a variable if it does not
10610 -- come from source (this deals for example with the conversions
10611 -- of expressions to their actual subtypes).
10613 when N_Type_Conversion
=>
10614 return Is_Variable
(Expression
(Orig_Node
))
10616 (not Comes_From_Source
(Orig_Node
)
10618 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
10620 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
10622 -- GNAT allows an unchecked type conversion as a variable. This
10623 -- only affects the generation of internal expanded code, since
10624 -- calls to instantiations of Unchecked_Conversion are never
10625 -- considered variables (since they are function calls).
10627 when N_Unchecked_Type_Conversion
=>
10628 return Is_Variable
(Expression
(Orig_Node
));
10636 ---------------------------
10637 -- Is_Visibly_Controlled --
10638 ---------------------------
10640 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
10641 Root
: constant Entity_Id
:= Root_Type
(T
);
10643 return Chars
(Scope
(Root
)) = Name_Finalization
10644 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
10645 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
10646 end Is_Visibly_Controlled
;
10648 ------------------------
10649 -- Is_Volatile_Object --
10650 ------------------------
10652 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
10654 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
10655 -- Determines if given object has volatile components
10657 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
10658 -- If prefix is an implicit dereference, examine designated type
10660 ------------------------
10661 -- Is_Volatile_Prefix --
10662 ------------------------
10664 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
10665 Typ
: constant Entity_Id
:= Etype
(N
);
10668 if Is_Access_Type
(Typ
) then
10670 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
10673 return Is_Volatile
(Dtyp
)
10674 or else Has_Volatile_Components
(Dtyp
);
10678 return Object_Has_Volatile_Components
(N
);
10680 end Is_Volatile_Prefix
;
10682 ------------------------------------
10683 -- Object_Has_Volatile_Components --
10684 ------------------------------------
10686 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
10687 Typ
: constant Entity_Id
:= Etype
(N
);
10690 if Is_Volatile
(Typ
)
10691 or else Has_Volatile_Components
(Typ
)
10695 elsif Is_Entity_Name
(N
)
10696 and then (Has_Volatile_Components
(Entity
(N
))
10697 or else Is_Volatile
(Entity
(N
)))
10701 elsif Nkind
(N
) = N_Indexed_Component
10702 or else Nkind
(N
) = N_Selected_Component
10704 return Is_Volatile_Prefix
(Prefix
(N
));
10709 end Object_Has_Volatile_Components
;
10711 -- Start of processing for Is_Volatile_Object
10714 if Is_Volatile
(Etype
(N
))
10715 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
10719 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
10720 and then Is_Volatile_Prefix
(Prefix
(N
))
10724 elsif Nkind
(N
) = N_Selected_Component
10725 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
10732 end Is_Volatile_Object
;
10734 ---------------------------
10735 -- Itype_Has_Declaration --
10736 ---------------------------
10738 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
10740 pragma Assert
(Is_Itype
(Id
));
10741 return Present
(Parent
(Id
))
10742 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
10743 N_Subtype_Declaration
)
10744 and then Defining_Entity
(Parent
(Id
)) = Id
;
10745 end Itype_Has_Declaration
;
10747 -------------------------
10748 -- Kill_Current_Values --
10749 -------------------------
10751 procedure Kill_Current_Values
10753 Last_Assignment_Only
: Boolean := False)
10756 -- ??? do we have to worry about clearing cached checks?
10758 if Is_Assignable
(Ent
) then
10759 Set_Last_Assignment
(Ent
, Empty
);
10762 if Is_Object
(Ent
) then
10763 if not Last_Assignment_Only
then
10765 Set_Current_Value
(Ent
, Empty
);
10767 if not Can_Never_Be_Null
(Ent
) then
10768 Set_Is_Known_Non_Null
(Ent
, False);
10771 Set_Is_Known_Null
(Ent
, False);
10773 -- Reset Is_Known_Valid unless type is always valid, or if we have
10774 -- a loop parameter (loop parameters are always valid, since their
10775 -- bounds are defined by the bounds given in the loop header).
10777 if not Is_Known_Valid
(Etype
(Ent
))
10778 and then Ekind
(Ent
) /= E_Loop_Parameter
10780 Set_Is_Known_Valid
(Ent
, False);
10784 end Kill_Current_Values
;
10786 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
10789 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
10790 -- Clear current value for entity E and all entities chained to E
10792 ------------------------------------------
10793 -- Kill_Current_Values_For_Entity_Chain --
10794 ------------------------------------------
10796 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
10800 while Present
(Ent
) loop
10801 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
10804 end Kill_Current_Values_For_Entity_Chain
;
10806 -- Start of processing for Kill_Current_Values
10809 -- Kill all saved checks, a special case of killing saved values
10811 if not Last_Assignment_Only
then
10815 -- Loop through relevant scopes, which includes the current scope and
10816 -- any parent scopes if the current scope is a block or a package.
10818 S
:= Current_Scope
;
10821 -- Clear current values of all entities in current scope
10823 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
10825 -- If scope is a package, also clear current values of all private
10826 -- entities in the scope.
10828 if Is_Package_Or_Generic_Package
(S
)
10829 or else Is_Concurrent_Type
(S
)
10831 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
10834 -- If this is a not a subprogram, deal with parents
10836 if not Is_Subprogram
(S
) then
10838 exit Scope_Loop
when S
= Standard_Standard
;
10842 end loop Scope_Loop
;
10843 end Kill_Current_Values
;
10845 --------------------------
10846 -- Kill_Size_Check_Code --
10847 --------------------------
10849 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
10851 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
10852 and then Present
(Size_Check_Code
(E
))
10854 Remove
(Size_Check_Code
(E
));
10855 Set_Size_Check_Code
(E
, Empty
);
10857 end Kill_Size_Check_Code
;
10859 --------------------------
10860 -- Known_To_Be_Assigned --
10861 --------------------------
10863 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
10864 P
: constant Node_Id
:= Parent
(N
);
10869 -- Test left side of assignment
10871 when N_Assignment_Statement
=>
10872 return N
= Name
(P
);
10874 -- Function call arguments are never lvalues
10876 when N_Function_Call
=>
10879 -- Positional parameter for procedure or accept call
10881 when N_Procedure_Call_Statement |
10890 Proc
:= Get_Subprogram_Entity
(P
);
10896 -- If we are not a list member, something is strange, so
10897 -- be conservative and return False.
10899 if not Is_List_Member
(N
) then
10903 -- We are going to find the right formal by stepping forward
10904 -- through the formals, as we step backwards in the actuals.
10906 Form
:= First_Formal
(Proc
);
10909 -- If no formal, something is weird, so be conservative
10910 -- and return False.
10917 exit when No
(Act
);
10918 Next_Formal
(Form
);
10921 return Ekind
(Form
) /= E_In_Parameter
;
10924 -- Named parameter for procedure or accept call
10926 when N_Parameter_Association
=>
10932 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
10938 -- Loop through formals to find the one that matches
10940 Form
:= First_Formal
(Proc
);
10942 -- If no matching formal, that's peculiar, some kind of
10943 -- previous error, so return False to be conservative.
10944 -- Actually this also happens in legal code in the case
10945 -- where P is a parameter association for an Extra_Formal???
10951 -- Else test for match
10953 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
10954 return Ekind
(Form
) /= E_In_Parameter
;
10957 Next_Formal
(Form
);
10961 -- Test for appearing in a conversion that itself appears
10962 -- in an lvalue context, since this should be an lvalue.
10964 when N_Type_Conversion
=>
10965 return Known_To_Be_Assigned
(P
);
10967 -- All other references are definitely not known to be modifications
10973 end Known_To_Be_Assigned
;
10975 ---------------------------
10976 -- Last_Source_Statement --
10977 ---------------------------
10979 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
10983 N
:= Last
(Statements
(HSS
));
10984 while Present
(N
) loop
10985 exit when Comes_From_Source
(N
);
10990 end Last_Source_Statement
;
10992 ----------------------------------
10993 -- Matching_Static_Array_Bounds --
10994 ----------------------------------
10996 function Matching_Static_Array_Bounds
10998 R_Typ
: Node_Id
) return Boolean
11000 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
11001 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
11013 if L_Ndims
/= R_Ndims
then
11017 -- Unconstrained types do not have static bounds
11019 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
11023 -- First treat specially the first dimension, as the lower bound and
11024 -- length of string literals are not stored like those of arrays.
11026 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
11027 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
11028 L_Len
:= String_Literal_Length
(L_Typ
);
11030 L_Index
:= First_Index
(L_Typ
);
11031 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
11033 if Is_OK_Static_Expression
(L_Low
)
11034 and then Is_OK_Static_Expression
(L_High
)
11036 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
11039 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
11046 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
11047 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
11048 R_Len
:= String_Literal_Length
(R_Typ
);
11050 R_Index
:= First_Index
(R_Typ
);
11051 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
11053 if Is_OK_Static_Expression
(R_Low
)
11054 and then Is_OK_Static_Expression
(R_High
)
11056 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
11059 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
11066 if Is_OK_Static_Expression
(L_Low
)
11067 and then Is_OK_Static_Expression
(R_Low
)
11068 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
11069 and then L_Len
= R_Len
11076 -- Then treat all other dimensions
11078 for Indx
in 2 .. L_Ndims
loop
11082 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
11083 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
11085 if Is_OK_Static_Expression
(L_Low
)
11086 and then Is_OK_Static_Expression
(L_High
)
11087 and then Is_OK_Static_Expression
(R_Low
)
11088 and then Is_OK_Static_Expression
(R_High
)
11089 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
11090 and then Expr_Value
(L_High
) = Expr_Value
(R_High
)
11098 -- If we fall through the loop, all indexes matched
11101 end Matching_Static_Array_Bounds
;
11103 -------------------
11104 -- May_Be_Lvalue --
11105 -------------------
11107 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
11108 P
: constant Node_Id
:= Parent
(N
);
11113 -- Test left side of assignment
11115 when N_Assignment_Statement
=>
11116 return N
= Name
(P
);
11118 -- Test prefix of component or attribute. Note that the prefix of an
11119 -- explicit or implicit dereference cannot be an l-value.
11121 when N_Attribute_Reference
=>
11122 return N
= Prefix
(P
)
11123 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
11125 -- For an expanded name, the name is an lvalue if the expanded name
11126 -- is an lvalue, but the prefix is never an lvalue, since it is just
11127 -- the scope where the name is found.
11129 when N_Expanded_Name
=>
11130 if N
= Prefix
(P
) then
11131 return May_Be_Lvalue
(P
);
11136 -- For a selected component A.B, A is certainly an lvalue if A.B is.
11137 -- B is a little interesting, if we have A.B := 3, there is some
11138 -- discussion as to whether B is an lvalue or not, we choose to say
11139 -- it is. Note however that A is not an lvalue if it is of an access
11140 -- type since this is an implicit dereference.
11142 when N_Selected_Component
=>
11144 and then Present
(Etype
(N
))
11145 and then Is_Access_Type
(Etype
(N
))
11149 return May_Be_Lvalue
(P
);
11152 -- For an indexed component or slice, the index or slice bounds is
11153 -- never an lvalue. The prefix is an lvalue if the indexed component
11154 -- or slice is an lvalue, except if it is an access type, where we
11155 -- have an implicit dereference.
11157 when N_Indexed_Component | N_Slice
=>
11159 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
11163 return May_Be_Lvalue
(P
);
11166 -- Prefix of a reference is an lvalue if the reference is an lvalue
11168 when N_Reference
=>
11169 return May_Be_Lvalue
(P
);
11171 -- Prefix of explicit dereference is never an lvalue
11173 when N_Explicit_Dereference
=>
11176 -- Positional parameter for subprogram, entry, or accept call.
11177 -- In older versions of Ada function call arguments are never
11178 -- lvalues. In Ada 2012 functions can have in-out parameters.
11180 when N_Subprogram_Call |
11181 N_Entry_Call_Statement |
11184 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
11188 -- The following mechanism is clumsy and fragile. A single flag
11189 -- set in Resolve_Actuals would be preferable ???
11197 Proc
:= Get_Subprogram_Entity
(P
);
11203 -- If we are not a list member, something is strange, so be
11204 -- conservative and return True.
11206 if not Is_List_Member
(N
) then
11210 -- We are going to find the right formal by stepping forward
11211 -- through the formals, as we step backwards in the actuals.
11213 Form
:= First_Formal
(Proc
);
11216 -- If no formal, something is weird, so be conservative and
11224 exit when No
(Act
);
11225 Next_Formal
(Form
);
11228 return Ekind
(Form
) /= E_In_Parameter
;
11231 -- Named parameter for procedure or accept call
11233 when N_Parameter_Association
=>
11239 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
11245 -- Loop through formals to find the one that matches
11247 Form
:= First_Formal
(Proc
);
11249 -- If no matching formal, that's peculiar, some kind of
11250 -- previous error, so return True to be conservative.
11251 -- Actually happens with legal code for an unresolved call
11252 -- where we may get the wrong homonym???
11258 -- Else test for match
11260 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
11261 return Ekind
(Form
) /= E_In_Parameter
;
11264 Next_Formal
(Form
);
11268 -- Test for appearing in a conversion that itself appears in an
11269 -- lvalue context, since this should be an lvalue.
11271 when N_Type_Conversion
=>
11272 return May_Be_Lvalue
(P
);
11274 -- Test for appearance in object renaming declaration
11276 when N_Object_Renaming_Declaration
=>
11279 -- All other references are definitely not lvalues
11287 -----------------------
11288 -- Mark_Coextensions --
11289 -----------------------
11291 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
11292 Is_Dynamic
: Boolean;
11293 -- Indicates whether the context causes nested coextensions to be
11294 -- dynamic or static
11296 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
11297 -- Recognize an allocator node and label it as a dynamic coextension
11299 --------------------
11300 -- Mark_Allocator --
11301 --------------------
11303 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
11305 if Nkind
(N
) = N_Allocator
then
11307 Set_Is_Dynamic_Coextension
(N
);
11309 -- If the allocator expression is potentially dynamic, it may
11310 -- be expanded out of order and require dynamic allocation
11311 -- anyway, so we treat the coextension itself as dynamic.
11312 -- Potential optimization ???
11314 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
11315 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
11317 Set_Is_Dynamic_Coextension
(N
);
11319 Set_Is_Static_Coextension
(N
);
11324 end Mark_Allocator
;
11326 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
11328 -- Start of processing Mark_Coextensions
11331 case Nkind
(Context_Nod
) is
11333 -- Comment here ???
11335 when N_Assignment_Statement
=>
11336 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
11338 -- An allocator that is a component of a returned aggregate
11339 -- must be dynamic.
11341 when N_Simple_Return_Statement
=>
11343 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
11346 Nkind
(Expr
) = N_Allocator
11348 (Nkind
(Expr
) = N_Qualified_Expression
11349 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
11352 -- An alloctor within an object declaration in an extended return
11353 -- statement is of necessity dynamic.
11355 when N_Object_Declaration
=>
11356 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
11358 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
11360 -- This routine should not be called for constructs which may not
11361 -- contain coextensions.
11364 raise Program_Error
;
11367 Mark_Allocators
(Root_Nod
);
11368 end Mark_Coextensions
;
11374 function Must_Inline
(Subp
: Entity_Id
) return Boolean is
11377 (Optimization_Level
= 0
11379 -- AAMP and VM targets have no support for inlining in the backend.
11380 -- Hence we do as much inlining as possible in the front end.
11382 or else AAMP_On_Target
11383 or else VM_Target
/= No_VM
)
11384 and then Has_Pragma_Inline
(Subp
)
11385 and then (Has_Pragma_Inline_Always
(Subp
) or else Front_End_Inlining
);
11388 ----------------------
11389 -- Needs_One_Actual --
11390 ----------------------
11392 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
11393 Formal
: Entity_Id
;
11396 -- Ada 2005 or later, and formals present
11398 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
11399 Formal
:= Next_Formal
(First_Formal
(E
));
11400 while Present
(Formal
) loop
11401 if No
(Default_Value
(Formal
)) then
11405 Next_Formal
(Formal
);
11410 -- Ada 83/95 or no formals
11415 end Needs_One_Actual
;
11417 ------------------------
11418 -- New_Copy_List_Tree --
11419 ------------------------
11421 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
11426 if List
= No_List
then
11433 while Present
(E
) loop
11434 Append
(New_Copy_Tree
(E
), NL
);
11440 end New_Copy_List_Tree
;
11442 -------------------
11443 -- New_Copy_Tree --
11444 -------------------
11446 use Atree
.Unchecked_Access
;
11447 use Atree_Private_Part
;
11449 -- Our approach here requires a two pass traversal of the tree. The
11450 -- first pass visits all nodes that eventually will be copied looking
11451 -- for defining Itypes. If any defining Itypes are found, then they are
11452 -- copied, and an entry is added to the replacement map. In the second
11453 -- phase, the tree is copied, using the replacement map to replace any
11454 -- Itype references within the copied tree.
11456 -- The following hash tables are used if the Map supplied has more
11457 -- than hash threshold entries to speed up access to the map. If
11458 -- there are fewer entries, then the map is searched sequentially
11459 -- (because setting up a hash table for only a few entries takes
11460 -- more time than it saves.
11462 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
11463 -- Hash function used for hash operations
11465 -------------------
11466 -- New_Copy_Hash --
11467 -------------------
11469 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
11471 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
11478 -- The hash table NCT_Assoc associates old entities in the table
11479 -- with their corresponding new entities (i.e. the pairs of entries
11480 -- presented in the original Map argument are Key-Element pairs).
11482 package NCT_Assoc
is new Simple_HTable
(
11483 Header_Num
=> NCT_Header_Num
,
11484 Element
=> Entity_Id
,
11485 No_Element
=> Empty
,
11487 Hash
=> New_Copy_Hash
,
11488 Equal
=> Types
."=");
11490 ---------------------
11491 -- NCT_Itype_Assoc --
11492 ---------------------
11494 -- The hash table NCT_Itype_Assoc contains entries only for those
11495 -- old nodes which have a non-empty Associated_Node_For_Itype set.
11496 -- The key is the associated node, and the element is the new node
11497 -- itself (NOT the associated node for the new node).
11499 package NCT_Itype_Assoc
is new Simple_HTable
(
11500 Header_Num
=> NCT_Header_Num
,
11501 Element
=> Entity_Id
,
11502 No_Element
=> Empty
,
11504 Hash
=> New_Copy_Hash
,
11505 Equal
=> Types
."=");
11507 -- Start of processing for New_Copy_Tree function
11509 function New_Copy_Tree
11511 Map
: Elist_Id
:= No_Elist
;
11512 New_Sloc
: Source_Ptr
:= No_Location
;
11513 New_Scope
: Entity_Id
:= Empty
) return Node_Id
11515 Actual_Map
: Elist_Id
:= Map
;
11516 -- This is the actual map for the copy. It is initialized with the
11517 -- given elements, and then enlarged as required for Itypes that are
11518 -- copied during the first phase of the copy operation. The visit
11519 -- procedures add elements to this map as Itypes are encountered.
11520 -- The reason we cannot use Map directly, is that it may well be
11521 -- (and normally is) initialized to No_Elist, and if we have mapped
11522 -- entities, we have to reset it to point to a real Elist.
11524 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
11525 -- Called during second phase to map entities into their corresponding
11526 -- copies using Actual_Map. If the argument is not an entity, or is not
11527 -- in Actual_Map, then it is returned unchanged.
11529 procedure Build_NCT_Hash_Tables
;
11530 -- Builds hash tables (number of elements >= threshold value)
11532 function Copy_Elist_With_Replacement
11533 (Old_Elist
: Elist_Id
) return Elist_Id
;
11534 -- Called during second phase to copy element list doing replacements
11536 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
11537 -- Called during the second phase to process a copied Itype. The actual
11538 -- copy happened during the first phase (so that we could make the entry
11539 -- in the mapping), but we still have to deal with the descendents of
11540 -- the copied Itype and copy them where necessary.
11542 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
11543 -- Called during second phase to copy list doing replacements
11545 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
11546 -- Called during second phase to copy node doing replacements
11548 procedure Visit_Elist
(E
: Elist_Id
);
11549 -- Called during first phase to visit all elements of an Elist
11551 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
11552 -- Visit a single field, recursing to call Visit_Node or Visit_List
11553 -- if the field is a syntactic descendent of the current node (i.e.
11554 -- its parent is Node N).
11556 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
11557 -- Called during first phase to visit subsidiary fields of a defining
11558 -- Itype, and also create a copy and make an entry in the replacement
11559 -- map for the new copy.
11561 procedure Visit_List
(L
: List_Id
);
11562 -- Called during first phase to visit all elements of a List
11564 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
11565 -- Called during first phase to visit a node and all its subtrees
11571 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
11576 if not Has_Extension
(N
) or else No
(Actual_Map
) then
11579 elsif NCT_Hash_Tables_Used
then
11580 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
11582 if Present
(Ent
) then
11588 -- No hash table used, do serial search
11591 E
:= First_Elmt
(Actual_Map
);
11592 while Present
(E
) loop
11593 if Node
(E
) = N
then
11594 return Node
(Next_Elmt
(E
));
11596 E
:= Next_Elmt
(Next_Elmt
(E
));
11604 ---------------------------
11605 -- Build_NCT_Hash_Tables --
11606 ---------------------------
11608 procedure Build_NCT_Hash_Tables
is
11612 if NCT_Hash_Table_Setup
then
11614 NCT_Itype_Assoc
.Reset
;
11617 Elmt
:= First_Elmt
(Actual_Map
);
11618 while Present
(Elmt
) loop
11619 Ent
:= Node
(Elmt
);
11621 -- Get new entity, and associate old and new
11624 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
11626 if Is_Type
(Ent
) then
11628 Anode
: constant Entity_Id
:=
11629 Associated_Node_For_Itype
(Ent
);
11632 if Present
(Anode
) then
11634 -- Enter a link between the associated node of the
11635 -- old Itype and the new Itype, for updating later
11636 -- when node is copied.
11638 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
11646 NCT_Hash_Tables_Used
:= True;
11647 NCT_Hash_Table_Setup
:= True;
11648 end Build_NCT_Hash_Tables
;
11650 ---------------------------------
11651 -- Copy_Elist_With_Replacement --
11652 ---------------------------------
11654 function Copy_Elist_With_Replacement
11655 (Old_Elist
: Elist_Id
) return Elist_Id
11658 New_Elist
: Elist_Id
;
11661 if No
(Old_Elist
) then
11665 New_Elist
:= New_Elmt_List
;
11667 M
:= First_Elmt
(Old_Elist
);
11668 while Present
(M
) loop
11669 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
11675 end Copy_Elist_With_Replacement
;
11677 ---------------------------------
11678 -- Copy_Itype_With_Replacement --
11679 ---------------------------------
11681 -- This routine exactly parallels its phase one analog Visit_Itype,
11683 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
11685 -- Translate Next_Entity, Scope and Etype fields, in case they
11686 -- reference entities that have been mapped into copies.
11688 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
11689 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
11691 if Present
(New_Scope
) then
11692 Set_Scope
(New_Itype
, New_Scope
);
11694 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
11697 -- Copy referenced fields
11699 if Is_Discrete_Type
(New_Itype
) then
11700 Set_Scalar_Range
(New_Itype
,
11701 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
11703 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
11704 Set_Discriminant_Constraint
(New_Itype
,
11705 Copy_Elist_With_Replacement
11706 (Discriminant_Constraint
(New_Itype
)));
11708 elsif Is_Array_Type
(New_Itype
) then
11709 if Present
(First_Index
(New_Itype
)) then
11710 Set_First_Index
(New_Itype
,
11711 First
(Copy_List_With_Replacement
11712 (List_Containing
(First_Index
(New_Itype
)))));
11715 if Is_Packed
(New_Itype
) then
11716 Set_Packed_Array_Type
(New_Itype
,
11717 Copy_Node_With_Replacement
11718 (Packed_Array_Type
(New_Itype
)));
11721 end Copy_Itype_With_Replacement
;
11723 --------------------------------
11724 -- Copy_List_With_Replacement --
11725 --------------------------------
11727 function Copy_List_With_Replacement
11728 (Old_List
: List_Id
) return List_Id
11730 New_List
: List_Id
;
11734 if Old_List
= No_List
then
11738 New_List
:= Empty_List
;
11740 E
:= First
(Old_List
);
11741 while Present
(E
) loop
11742 Append
(Copy_Node_With_Replacement
(E
), New_List
);
11748 end Copy_List_With_Replacement
;
11750 --------------------------------
11751 -- Copy_Node_With_Replacement --
11752 --------------------------------
11754 function Copy_Node_With_Replacement
11755 (Old_Node
: Node_Id
) return Node_Id
11757 New_Node
: Node_Id
;
11759 procedure Adjust_Named_Associations
11760 (Old_Node
: Node_Id
;
11761 New_Node
: Node_Id
);
11762 -- If a call node has named associations, these are chained through
11763 -- the First_Named_Actual, Next_Named_Actual links. These must be
11764 -- propagated separately to the new parameter list, because these
11765 -- are not syntactic fields.
11767 function Copy_Field_With_Replacement
11768 (Field
: Union_Id
) return Union_Id
;
11769 -- Given Field, which is a field of Old_Node, return a copy of it
11770 -- if it is a syntactic field (i.e. its parent is Node), setting
11771 -- the parent of the copy to poit to New_Node. Otherwise returns
11772 -- the field (possibly mapped if it is an entity).
11774 -------------------------------
11775 -- Adjust_Named_Associations --
11776 -------------------------------
11778 procedure Adjust_Named_Associations
11779 (Old_Node
: Node_Id
;
11780 New_Node
: Node_Id
)
11785 Old_Next
: Node_Id
;
11786 New_Next
: Node_Id
;
11789 Old_E
:= First
(Parameter_Associations
(Old_Node
));
11790 New_E
:= First
(Parameter_Associations
(New_Node
));
11791 while Present
(Old_E
) loop
11792 if Nkind
(Old_E
) = N_Parameter_Association
11793 and then Present
(Next_Named_Actual
(Old_E
))
11795 if First_Named_Actual
(Old_Node
)
11796 = Explicit_Actual_Parameter
(Old_E
)
11798 Set_First_Named_Actual
11799 (New_Node
, Explicit_Actual_Parameter
(New_E
));
11802 -- Now scan parameter list from the beginning,to locate
11803 -- next named actual, which can be out of order.
11805 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
11806 New_Next
:= First
(Parameter_Associations
(New_Node
));
11808 while Nkind
(Old_Next
) /= N_Parameter_Association
11809 or else Explicit_Actual_Parameter
(Old_Next
)
11810 /= Next_Named_Actual
(Old_E
)
11816 Set_Next_Named_Actual
11817 (New_E
, Explicit_Actual_Parameter
(New_Next
));
11823 end Adjust_Named_Associations
;
11825 ---------------------------------
11826 -- Copy_Field_With_Replacement --
11827 ---------------------------------
11829 function Copy_Field_With_Replacement
11830 (Field
: Union_Id
) return Union_Id
11833 if Field
= Union_Id
(Empty
) then
11836 elsif Field
in Node_Range
then
11838 Old_N
: constant Node_Id
:= Node_Id
(Field
);
11842 -- If syntactic field, as indicated by the parent pointer
11843 -- being set, then copy the referenced node recursively.
11845 if Parent
(Old_N
) = Old_Node
then
11846 New_N
:= Copy_Node_With_Replacement
(Old_N
);
11848 if New_N
/= Old_N
then
11849 Set_Parent
(New_N
, New_Node
);
11852 -- For semantic fields, update possible entity reference
11853 -- from the replacement map.
11856 New_N
:= Assoc
(Old_N
);
11859 return Union_Id
(New_N
);
11862 elsif Field
in List_Range
then
11864 Old_L
: constant List_Id
:= List_Id
(Field
);
11868 -- If syntactic field, as indicated by the parent pointer,
11869 -- then recursively copy the entire referenced list.
11871 if Parent
(Old_L
) = Old_Node
then
11872 New_L
:= Copy_List_With_Replacement
(Old_L
);
11873 Set_Parent
(New_L
, New_Node
);
11875 -- For semantic list, just returned unchanged
11881 return Union_Id
(New_L
);
11884 -- Anything other than a list or a node is returned unchanged
11889 end Copy_Field_With_Replacement
;
11891 -- Start of processing for Copy_Node_With_Replacement
11894 if Old_Node
<= Empty_Or_Error
then
11897 elsif Has_Extension
(Old_Node
) then
11898 return Assoc
(Old_Node
);
11901 New_Node
:= New_Copy
(Old_Node
);
11903 -- If the node we are copying is the associated node of a
11904 -- previously copied Itype, then adjust the associated node
11905 -- of the copy of that Itype accordingly.
11907 if Present
(Actual_Map
) then
11913 -- Case of hash table used
11915 if NCT_Hash_Tables_Used
then
11916 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
11918 if Present
(Ent
) then
11919 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
11922 -- Case of no hash table used
11925 E
:= First_Elmt
(Actual_Map
);
11926 while Present
(E
) loop
11927 if Is_Itype
(Node
(E
))
11929 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
11931 Set_Associated_Node_For_Itype
11932 (Node
(Next_Elmt
(E
)), New_Node
);
11935 E
:= Next_Elmt
(Next_Elmt
(E
));
11941 -- Recursively copy descendents
11944 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
11946 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
11948 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
11950 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
11952 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
11954 -- Adjust Sloc of new node if necessary
11956 if New_Sloc
/= No_Location
then
11957 Set_Sloc
(New_Node
, New_Sloc
);
11959 -- If we adjust the Sloc, then we are essentially making
11960 -- a completely new node, so the Comes_From_Source flag
11961 -- should be reset to the proper default value.
11963 Nodes
.Table
(New_Node
).Comes_From_Source
:=
11964 Default_Node
.Comes_From_Source
;
11967 -- If the node is call and has named associations,
11968 -- set the corresponding links in the copy.
11970 if (Nkind
(Old_Node
) = N_Function_Call
11971 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
11973 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
11974 and then Present
(First_Named_Actual
(Old_Node
))
11976 Adjust_Named_Associations
(Old_Node
, New_Node
);
11979 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
11980 -- The replacement mechanism applies to entities, and is not used
11981 -- here. Eventually we may need a more general graph-copying
11982 -- routine. For now, do a sequential search to find desired node.
11984 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
11985 and then Present
(First_Real_Statement
(Old_Node
))
11988 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
11992 N1
:= First
(Statements
(Old_Node
));
11993 N2
:= First
(Statements
(New_Node
));
11995 while N1
/= Old_F
loop
12000 Set_First_Real_Statement
(New_Node
, N2
);
12005 -- All done, return copied node
12008 end Copy_Node_With_Replacement
;
12014 procedure Visit_Elist
(E
: Elist_Id
) is
12017 if Present
(E
) then
12018 Elmt
:= First_Elmt
(E
);
12020 while Elmt
/= No_Elmt
loop
12021 Visit_Node
(Node
(Elmt
));
12031 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
12033 if F
= Union_Id
(Empty
) then
12036 elsif F
in Node_Range
then
12038 -- Copy node if it is syntactic, i.e. its parent pointer is
12039 -- set to point to the field that referenced it (certain
12040 -- Itypes will also meet this criterion, which is fine, since
12041 -- these are clearly Itypes that do need to be copied, since
12042 -- we are copying their parent.)
12044 if Parent
(Node_Id
(F
)) = N
then
12045 Visit_Node
(Node_Id
(F
));
12048 -- Another case, if we are pointing to an Itype, then we want
12049 -- to copy it if its associated node is somewhere in the tree
12052 -- Note: the exclusion of self-referential copies is just an
12053 -- optimization, since the search of the already copied list
12054 -- would catch it, but it is a common case (Etype pointing
12055 -- to itself for an Itype that is a base type).
12057 elsif Has_Extension
(Node_Id
(F
))
12058 and then Is_Itype
(Entity_Id
(F
))
12059 and then Node_Id
(F
) /= N
12065 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
12066 while Present
(P
) loop
12068 Visit_Node
(Node_Id
(F
));
12075 -- An Itype whose parent is not being copied definitely
12076 -- should NOT be copied, since it does not belong in any
12077 -- sense to the copied subtree.
12083 elsif F
in List_Range
12084 and then Parent
(List_Id
(F
)) = N
12086 Visit_List
(List_Id
(F
));
12095 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
12096 New_Itype
: Entity_Id
;
12101 -- Itypes that describe the designated type of access to subprograms
12102 -- have the structure of subprogram declarations, with signatures,
12103 -- etc. Either we duplicate the signatures completely, or choose to
12104 -- share such itypes, which is fine because their elaboration will
12105 -- have no side effects.
12107 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
12111 New_Itype
:= New_Copy
(Old_Itype
);
12113 -- The new Itype has all the attributes of the old one, and
12114 -- we just copy the contents of the entity. However, the back-end
12115 -- needs different names for debugging purposes, so we create a
12116 -- new internal name for it in all cases.
12118 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
12120 -- If our associated node is an entity that has already been copied,
12121 -- then set the associated node of the copy to point to the right
12122 -- copy. If we have copied an Itype that is itself the associated
12123 -- node of some previously copied Itype, then we set the right
12124 -- pointer in the other direction.
12126 if Present
(Actual_Map
) then
12128 -- Case of hash tables used
12130 if NCT_Hash_Tables_Used
then
12132 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
12134 if Present
(Ent
) then
12135 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
12138 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
12139 if Present
(Ent
) then
12140 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
12142 -- If the hash table has no association for this Itype and
12143 -- its associated node, enter one now.
12146 NCT_Itype_Assoc
.Set
12147 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
12150 -- Case of hash tables not used
12153 E
:= First_Elmt
(Actual_Map
);
12154 while Present
(E
) loop
12155 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
12156 Set_Associated_Node_For_Itype
12157 (New_Itype
, Node
(Next_Elmt
(E
)));
12160 if Is_Type
(Node
(E
))
12162 Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
12164 Set_Associated_Node_For_Itype
12165 (Node
(Next_Elmt
(E
)), New_Itype
);
12168 E
:= Next_Elmt
(Next_Elmt
(E
));
12173 if Present
(Freeze_Node
(New_Itype
)) then
12174 Set_Is_Frozen
(New_Itype
, False);
12175 Set_Freeze_Node
(New_Itype
, Empty
);
12178 -- Add new association to map
12180 if No
(Actual_Map
) then
12181 Actual_Map
:= New_Elmt_List
;
12184 Append_Elmt
(Old_Itype
, Actual_Map
);
12185 Append_Elmt
(New_Itype
, Actual_Map
);
12187 if NCT_Hash_Tables_Used
then
12188 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
12191 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
12193 if NCT_Table_Entries
> NCT_Hash_Threshold
then
12194 Build_NCT_Hash_Tables
;
12198 -- If a record subtype is simply copied, the entity list will be
12199 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
12201 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
12202 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
12205 -- Visit descendents that eventually get copied
12207 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
12209 if Is_Discrete_Type
(Old_Itype
) then
12210 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
12212 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
12213 -- ??? This should involve call to Visit_Field
12214 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
12216 elsif Is_Array_Type
(Old_Itype
) then
12217 if Present
(First_Index
(Old_Itype
)) then
12218 Visit_Field
(Union_Id
(List_Containing
12219 (First_Index
(Old_Itype
))),
12223 if Is_Packed
(Old_Itype
) then
12224 Visit_Field
(Union_Id
(Packed_Array_Type
(Old_Itype
)),
12234 procedure Visit_List
(L
: List_Id
) is
12237 if L
/= No_List
then
12240 while Present
(N
) loop
12251 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
12253 -- Start of processing for Visit_Node
12256 -- Handle case of an Itype, which must be copied
12258 if Has_Extension
(N
)
12259 and then Is_Itype
(N
)
12261 -- Nothing to do if already in the list. This can happen with an
12262 -- Itype entity that appears more than once in the tree.
12263 -- Note that we do not want to visit descendents in this case.
12265 -- Test for already in list when hash table is used
12267 if NCT_Hash_Tables_Used
then
12268 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
12272 -- Test for already in list when hash table not used
12278 if Present
(Actual_Map
) then
12279 E
:= First_Elmt
(Actual_Map
);
12280 while Present
(E
) loop
12281 if Node
(E
) = N
then
12284 E
:= Next_Elmt
(Next_Elmt
(E
));
12294 -- Visit descendents
12296 Visit_Field
(Field1
(N
), N
);
12297 Visit_Field
(Field2
(N
), N
);
12298 Visit_Field
(Field3
(N
), N
);
12299 Visit_Field
(Field4
(N
), N
);
12300 Visit_Field
(Field5
(N
), N
);
12303 -- Start of processing for New_Copy_Tree
12308 -- See if we should use hash table
12310 if No
(Actual_Map
) then
12311 NCT_Hash_Tables_Used
:= False;
12318 NCT_Table_Entries
:= 0;
12320 Elmt
:= First_Elmt
(Actual_Map
);
12321 while Present
(Elmt
) loop
12322 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
12327 if NCT_Table_Entries
> NCT_Hash_Threshold
then
12328 Build_NCT_Hash_Tables
;
12330 NCT_Hash_Tables_Used
:= False;
12335 -- Hash table set up if required, now start phase one by visiting
12336 -- top node (we will recursively visit the descendents).
12338 Visit_Node
(Source
);
12340 -- Now the second phase of the copy can start. First we process
12341 -- all the mapped entities, copying their descendents.
12343 if Present
(Actual_Map
) then
12346 New_Itype
: Entity_Id
;
12348 Elmt
:= First_Elmt
(Actual_Map
);
12349 while Present
(Elmt
) loop
12351 New_Itype
:= Node
(Elmt
);
12352 Copy_Itype_With_Replacement
(New_Itype
);
12358 -- Now we can copy the actual tree
12360 return Copy_Node_With_Replacement
(Source
);
12363 -------------------------
12364 -- New_External_Entity --
12365 -------------------------
12367 function New_External_Entity
12368 (Kind
: Entity_Kind
;
12369 Scope_Id
: Entity_Id
;
12370 Sloc_Value
: Source_Ptr
;
12371 Related_Id
: Entity_Id
;
12372 Suffix
: Character;
12373 Suffix_Index
: Nat
:= 0;
12374 Prefix
: Character := ' ') return Entity_Id
12376 N
: constant Entity_Id
:=
12377 Make_Defining_Identifier
(Sloc_Value
,
12379 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
12382 Set_Ekind
(N
, Kind
);
12383 Set_Is_Internal
(N
, True);
12384 Append_Entity
(N
, Scope_Id
);
12385 Set_Public_Status
(N
);
12387 if Kind
in Type_Kind
then
12388 Init_Size_Align
(N
);
12392 end New_External_Entity
;
12394 -------------------------
12395 -- New_Internal_Entity --
12396 -------------------------
12398 function New_Internal_Entity
12399 (Kind
: Entity_Kind
;
12400 Scope_Id
: Entity_Id
;
12401 Sloc_Value
: Source_Ptr
;
12402 Id_Char
: Character) return Entity_Id
12404 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
12407 Set_Ekind
(N
, Kind
);
12408 Set_Is_Internal
(N
, True);
12409 Append_Entity
(N
, Scope_Id
);
12411 if Kind
in Type_Kind
then
12412 Init_Size_Align
(N
);
12416 end New_Internal_Entity
;
12422 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
12426 -- If we are pointing at a positional parameter, it is a member of a
12427 -- node list (the list of parameters), and the next parameter is the
12428 -- next node on the list, unless we hit a parameter association, then
12429 -- we shift to using the chain whose head is the First_Named_Actual in
12430 -- the parent, and then is threaded using the Next_Named_Actual of the
12431 -- Parameter_Association. All this fiddling is because the original node
12432 -- list is in the textual call order, and what we need is the
12433 -- declaration order.
12435 if Is_List_Member
(Actual_Id
) then
12436 N
:= Next
(Actual_Id
);
12438 if Nkind
(N
) = N_Parameter_Association
then
12439 return First_Named_Actual
(Parent
(Actual_Id
));
12445 return Next_Named_Actual
(Parent
(Actual_Id
));
12449 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
12451 Actual_Id
:= Next_Actual
(Actual_Id
);
12454 ---------------------
12455 -- No_Scalar_Parts --
12456 ---------------------
12458 function No_Scalar_Parts
(T
: Entity_Id
) return Boolean is
12462 if Is_Scalar_Type
(T
) then
12465 elsif Is_Array_Type
(T
) then
12466 return No_Scalar_Parts
(Component_Type
(T
));
12468 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
12469 C
:= First_Component_Or_Discriminant
(T
);
12470 while Present
(C
) loop
12471 if not No_Scalar_Parts
(Etype
(C
)) then
12474 Next_Component_Or_Discriminant
(C
);
12480 end No_Scalar_Parts
;
12482 -----------------------
12483 -- Normalize_Actuals --
12484 -----------------------
12486 -- Chain actuals according to formals of subprogram. If there are no named
12487 -- associations, the chain is simply the list of Parameter Associations,
12488 -- since the order is the same as the declaration order. If there are named
12489 -- associations, then the First_Named_Actual field in the N_Function_Call
12490 -- or N_Procedure_Call_Statement node points to the Parameter_Association
12491 -- node for the parameter that comes first in declaration order. The
12492 -- remaining named parameters are then chained in declaration order using
12493 -- Next_Named_Actual.
12495 -- This routine also verifies that the number of actuals is compatible with
12496 -- the number and default values of formals, but performs no type checking
12497 -- (type checking is done by the caller).
12499 -- If the matching succeeds, Success is set to True and the caller proceeds
12500 -- with type-checking. If the match is unsuccessful, then Success is set to
12501 -- False, and the caller attempts a different interpretation, if there is
12504 -- If the flag Report is on, the call is not overloaded, and a failure to
12505 -- match can be reported here, rather than in the caller.
12507 procedure Normalize_Actuals
12511 Success
: out Boolean)
12513 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
12514 Actual
: Node_Id
:= Empty
;
12515 Formal
: Entity_Id
;
12516 Last
: Node_Id
:= Empty
;
12517 First_Named
: Node_Id
:= Empty
;
12520 Formals_To_Match
: Integer := 0;
12521 Actuals_To_Match
: Integer := 0;
12523 procedure Chain
(A
: Node_Id
);
12524 -- Add named actual at the proper place in the list, using the
12525 -- Next_Named_Actual link.
12527 function Reporting
return Boolean;
12528 -- Determines if an error is to be reported. To report an error, we
12529 -- need Report to be True, and also we do not report errors caused
12530 -- by calls to init procs that occur within other init procs. Such
12531 -- errors must always be cascaded errors, since if all the types are
12532 -- declared correctly, the compiler will certainly build decent calls!
12538 procedure Chain
(A
: Node_Id
) is
12542 -- Call node points to first actual in list
12544 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
12547 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
12551 Set_Next_Named_Actual
(Last
, Empty
);
12558 function Reporting
return Boolean is
12563 elsif not Within_Init_Proc
then
12566 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
12574 -- Start of processing for Normalize_Actuals
12577 if Is_Access_Type
(S
) then
12579 -- The name in the call is a function call that returns an access
12580 -- to subprogram. The designated type has the list of formals.
12582 Formal
:= First_Formal
(Designated_Type
(S
));
12584 Formal
:= First_Formal
(S
);
12587 while Present
(Formal
) loop
12588 Formals_To_Match
:= Formals_To_Match
+ 1;
12589 Next_Formal
(Formal
);
12592 -- Find if there is a named association, and verify that no positional
12593 -- associations appear after named ones.
12595 if Present
(Actuals
) then
12596 Actual
:= First
(Actuals
);
12599 while Present
(Actual
)
12600 and then Nkind
(Actual
) /= N_Parameter_Association
12602 Actuals_To_Match
:= Actuals_To_Match
+ 1;
12606 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
12608 -- Most common case: positional notation, no defaults
12613 elsif Actuals_To_Match
> Formals_To_Match
then
12615 -- Too many actuals: will not work
12618 if Is_Entity_Name
(Name
(N
)) then
12619 Error_Msg_N
("too many arguments in call to&", Name
(N
));
12621 Error_Msg_N
("too many arguments in call", N
);
12629 First_Named
:= Actual
;
12631 while Present
(Actual
) loop
12632 if Nkind
(Actual
) /= N_Parameter_Association
then
12634 ("positional parameters not allowed after named ones", Actual
);
12639 Actuals_To_Match
:= Actuals_To_Match
+ 1;
12645 if Present
(Actuals
) then
12646 Actual
:= First
(Actuals
);
12649 Formal
:= First_Formal
(S
);
12650 while Present
(Formal
) loop
12652 -- Match the formals in order. If the corresponding actual is
12653 -- positional, nothing to do. Else scan the list of named actuals
12654 -- to find the one with the right name.
12656 if Present
(Actual
)
12657 and then Nkind
(Actual
) /= N_Parameter_Association
12660 Actuals_To_Match
:= Actuals_To_Match
- 1;
12661 Formals_To_Match
:= Formals_To_Match
- 1;
12664 -- For named parameters, search the list of actuals to find
12665 -- one that matches the next formal name.
12667 Actual
:= First_Named
;
12669 while Present
(Actual
) loop
12670 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
12673 Actuals_To_Match
:= Actuals_To_Match
- 1;
12674 Formals_To_Match
:= Formals_To_Match
- 1;
12682 if Ekind
(Formal
) /= E_In_Parameter
12683 or else No
(Default_Value
(Formal
))
12686 if (Comes_From_Source
(S
)
12687 or else Sloc
(S
) = Standard_Location
)
12688 and then Is_Overloadable
(S
)
12692 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
12694 (Nkind
(Parent
(N
)) = N_Function_Call
12696 Nkind
(Parent
(N
)) = N_Parameter_Association
))
12697 and then Ekind
(S
) /= E_Function
12699 Set_Etype
(N
, Etype
(S
));
12701 Error_Msg_Name_1
:= Chars
(S
);
12702 Error_Msg_Sloc
:= Sloc
(S
);
12704 ("missing argument for parameter & " &
12705 "in call to % declared #", N
, Formal
);
12708 elsif Is_Overloadable
(S
) then
12709 Error_Msg_Name_1
:= Chars
(S
);
12711 -- Point to type derivation that generated the
12714 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
12717 ("missing argument for parameter & " &
12718 "in call to % (inherited) #", N
, Formal
);
12722 ("missing argument for parameter &", N
, Formal
);
12730 Formals_To_Match
:= Formals_To_Match
- 1;
12735 Next_Formal
(Formal
);
12738 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
12745 -- Find some superfluous named actual that did not get
12746 -- attached to the list of associations.
12748 Actual
:= First
(Actuals
);
12749 while Present
(Actual
) loop
12750 if Nkind
(Actual
) = N_Parameter_Association
12751 and then Actual
/= Last
12752 and then No
(Next_Named_Actual
(Actual
))
12754 Error_Msg_N
("unmatched actual & in call",
12755 Selector_Name
(Actual
));
12766 end Normalize_Actuals
;
12768 --------------------------------
12769 -- Note_Possible_Modification --
12770 --------------------------------
12772 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
12773 Modification_Comes_From_Source
: constant Boolean :=
12774 Comes_From_Source
(Parent
(N
));
12780 -- Loop to find referenced entity, if there is one
12787 if Is_Entity_Name
(Exp
) then
12788 Ent
:= Entity
(Exp
);
12790 -- If the entity is missing, it is an undeclared identifier,
12791 -- and there is nothing to annotate.
12797 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
12799 P
: constant Node_Id
:= Prefix
(Exp
);
12802 -- In formal verification mode, keep track of all reads and
12803 -- writes through explicit dereferences.
12806 SPARK_Specific
.Generate_Dereference
(N
, 'm');
12809 if Nkind
(P
) = N_Selected_Component
12811 Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
12813 -- Case of a reference to an entry formal
12815 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
12817 elsif Nkind
(P
) = N_Identifier
12818 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
12819 and then Present
(Expression
(Parent
(Entity
(P
))))
12820 and then Nkind
(Expression
(Parent
(Entity
(P
))))
12823 -- Case of a reference to a value on which side effects have
12826 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
12835 elsif Nkind_In
(Exp
, N_Type_Conversion
,
12836 N_Unchecked_Type_Conversion
)
12838 Exp
:= Expression
(Exp
);
12841 elsif Nkind_In
(Exp
, N_Slice
,
12842 N_Indexed_Component
,
12843 N_Selected_Component
)
12845 Exp
:= Prefix
(Exp
);
12852 -- Now look for entity being referenced
12854 if Present
(Ent
) then
12855 if Is_Object
(Ent
) then
12856 if Comes_From_Source
(Exp
)
12857 or else Modification_Comes_From_Source
12859 -- Give warning if pragma unmodified given and we are
12860 -- sure this is a modification.
12862 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
12864 ("??pragma Unmodified given for &!", N
, Ent
);
12867 Set_Never_Set_In_Source
(Ent
, False);
12870 Set_Is_True_Constant
(Ent
, False);
12871 Set_Current_Value
(Ent
, Empty
);
12872 Set_Is_Known_Null
(Ent
, False);
12874 if not Can_Never_Be_Null
(Ent
) then
12875 Set_Is_Known_Non_Null
(Ent
, False);
12878 -- Follow renaming chain
12880 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
12881 and then Present
(Renamed_Object
(Ent
))
12883 Exp
:= Renamed_Object
(Ent
);
12886 -- The expression may be the renaming of a subcomponent of an
12887 -- array or container. The assignment to the subcomponent is
12888 -- a modification of the container.
12890 elsif Comes_From_Source
(Original_Node
(Exp
))
12891 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
12892 N_Indexed_Component
)
12894 Exp
:= Prefix
(Original_Node
(Exp
));
12898 -- Generate a reference only if the assignment comes from
12899 -- source. This excludes, for example, calls to a dispatching
12900 -- assignment operation when the left-hand side is tagged.
12902 -- Why is SPARK mode different here ???
12904 if Modification_Comes_From_Source
or SPARK_Mode
then
12905 Generate_Reference
(Ent
, Exp
, 'm');
12907 -- If the target of the assignment is the bound variable
12908 -- in an iterator, indicate that the corresponding array
12909 -- or container is also modified.
12911 if Ada_Version
>= Ada_2012
12913 Nkind
(Parent
(Ent
)) = N_Iterator_Specification
12916 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
12919 -- TBD : in the full version of the construct, the
12920 -- domain of iteration can be given by an expression.
12922 if Is_Entity_Name
(Domain
) then
12923 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
12924 Set_Is_True_Constant
(Entity
(Domain
), False);
12925 Set_Never_Set_In_Source
(Entity
(Domain
), False);
12931 Check_Nested_Access
(Ent
);
12936 -- If we are sure this is a modification from source, and we know
12937 -- this modifies a constant, then give an appropriate warning.
12939 if Overlays_Constant
(Ent
)
12940 and then Modification_Comes_From_Source
12944 A
: constant Node_Id
:= Address_Clause
(Ent
);
12946 if Present
(A
) then
12948 Exp
: constant Node_Id
:= Expression
(A
);
12950 if Nkind
(Exp
) = N_Attribute_Reference
12951 and then Attribute_Name
(Exp
) = Name_Address
12952 and then Is_Entity_Name
(Prefix
(Exp
))
12954 Error_Msg_Sloc
:= Sloc
(A
);
12956 ("constant& may be modified via address "
12957 & "clause#??", N
, Entity
(Prefix
(Exp
)));
12967 end Note_Possible_Modification
;
12969 -------------------------
12970 -- Object_Access_Level --
12971 -------------------------
12973 -- Returns the static accessibility level of the view denoted by Obj. Note
12974 -- that the value returned is the result of a call to Scope_Depth. Only
12975 -- scope depths associated with dynamic scopes can actually be returned.
12976 -- Since only relative levels matter for accessibility checking, the fact
12977 -- that the distance between successive levels of accessibility is not
12978 -- always one is immaterial (invariant: if level(E2) is deeper than
12979 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
12981 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
12982 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
12983 -- Determine whether N is a construct of the form
12984 -- Some_Type (Operand._tag'Address)
12985 -- This construct appears in the context of dispatching calls.
12987 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
12988 -- An explicit dereference is created when removing side-effects from
12989 -- expressions for constraint checking purposes. In this case a local
12990 -- access type is created for it. The correct access level is that of
12991 -- the original source node. We detect this case by noting that the
12992 -- prefix of the dereference is created by an object declaration whose
12993 -- initial expression is a reference.
12995 -----------------------------
12996 -- Is_Interface_Conversion --
12997 -----------------------------
12999 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
13002 Nkind
(N
) = N_Unchecked_Type_Conversion
13003 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
13004 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
13005 end Is_Interface_Conversion
;
13011 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
13012 Pref
: constant Node_Id
:= Prefix
(Obj
);
13014 if Is_Entity_Name
(Pref
)
13015 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
13016 and then Present
(Expression
(Parent
(Entity
(Pref
))))
13017 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
13019 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
13029 -- Start of processing for Object_Access_Level
13032 if Nkind
(Obj
) = N_Defining_Identifier
13033 or else Is_Entity_Name
(Obj
)
13035 if Nkind
(Obj
) = N_Defining_Identifier
then
13041 if Is_Prival
(E
) then
13042 E
:= Prival_Link
(E
);
13045 -- If E is a type then it denotes a current instance. For this case
13046 -- we add one to the normal accessibility level of the type to ensure
13047 -- that current instances are treated as always being deeper than
13048 -- than the level of any visible named access type (see 3.10.2(21)).
13050 if Is_Type
(E
) then
13051 return Type_Access_Level
(E
) + 1;
13053 elsif Present
(Renamed_Object
(E
)) then
13054 return Object_Access_Level
(Renamed_Object
(E
));
13056 -- Similarly, if E is a component of the current instance of a
13057 -- protected type, any instance of it is assumed to be at a deeper
13058 -- level than the type. For a protected object (whose type is an
13059 -- anonymous protected type) its components are at the same level
13060 -- as the type itself.
13062 elsif not Is_Overloadable
(E
)
13063 and then Ekind
(Scope
(E
)) = E_Protected_Type
13064 and then Comes_From_Source
(Scope
(E
))
13066 return Type_Access_Level
(Scope
(E
)) + 1;
13069 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
13072 elsif Nkind
(Obj
) = N_Selected_Component
then
13073 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
13074 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13076 return Object_Access_Level
(Prefix
(Obj
));
13079 elsif Nkind
(Obj
) = N_Indexed_Component
then
13080 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
13081 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13083 return Object_Access_Level
(Prefix
(Obj
));
13086 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
13088 -- If the prefix is a selected access discriminant then we make a
13089 -- recursive call on the prefix, which will in turn check the level
13090 -- of the prefix object of the selected discriminant.
13092 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
13093 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
13095 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
13097 return Object_Access_Level
(Prefix
(Obj
));
13099 -- Detect an interface conversion in the context of a dispatching
13100 -- call. Use the original form of the conversion to find the access
13101 -- level of the operand.
13103 elsif Is_Interface
(Etype
(Obj
))
13104 and then Is_Interface_Conversion
(Prefix
(Obj
))
13105 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
13107 return Object_Access_Level
(Original_Node
(Obj
));
13109 elsif not Comes_From_Source
(Obj
) then
13111 Ref
: constant Node_Id
:= Reference_To
(Obj
);
13113 if Present
(Ref
) then
13114 return Object_Access_Level
(Ref
);
13116 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13121 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13124 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
13125 return Object_Access_Level
(Expression
(Obj
));
13127 elsif Nkind
(Obj
) = N_Function_Call
then
13129 -- Function results are objects, so we get either the access level of
13130 -- the function or, in the case of an indirect call, the level of the
13131 -- access-to-subprogram type. (This code is used for Ada 95, but it
13132 -- looks wrong, because it seems that we should be checking the level
13133 -- of the call itself, even for Ada 95. However, using the Ada 2005
13134 -- version of the code causes regressions in several tests that are
13135 -- compiled with -gnat95. ???)
13137 if Ada_Version
< Ada_2005
then
13138 if Is_Entity_Name
(Name
(Obj
)) then
13139 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
13141 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
13144 -- For Ada 2005, the level of the result object of a function call is
13145 -- defined to be the level of the call's innermost enclosing master.
13146 -- We determine that by querying the depth of the innermost enclosing
13150 Return_Master_Scope_Depth_Of_Call
: declare
13152 function Innermost_Master_Scope_Depth
13153 (N
: Node_Id
) return Uint
;
13154 -- Returns the scope depth of the given node's innermost
13155 -- enclosing dynamic scope (effectively the accessibility
13156 -- level of the innermost enclosing master).
13158 ----------------------------------
13159 -- Innermost_Master_Scope_Depth --
13160 ----------------------------------
13162 function Innermost_Master_Scope_Depth
13163 (N
: Node_Id
) return Uint
13165 Node_Par
: Node_Id
:= Parent
(N
);
13168 -- Locate the nearest enclosing node (by traversing Parents)
13169 -- that Defining_Entity can be applied to, and return the
13170 -- depth of that entity's nearest enclosing dynamic scope.
13172 while Present
(Node_Par
) loop
13173 case Nkind
(Node_Par
) is
13174 when N_Component_Declaration |
13175 N_Entry_Declaration |
13176 N_Formal_Object_Declaration |
13177 N_Formal_Type_Declaration |
13178 N_Full_Type_Declaration |
13179 N_Incomplete_Type_Declaration |
13180 N_Loop_Parameter_Specification |
13181 N_Object_Declaration |
13182 N_Protected_Type_Declaration |
13183 N_Private_Extension_Declaration |
13184 N_Private_Type_Declaration |
13185 N_Subtype_Declaration |
13186 N_Function_Specification |
13187 N_Procedure_Specification |
13188 N_Task_Type_Declaration |
13190 N_Generic_Instantiation |
13192 N_Implicit_Label_Declaration |
13193 N_Package_Declaration |
13194 N_Single_Task_Declaration |
13195 N_Subprogram_Declaration |
13196 N_Generic_Declaration |
13197 N_Renaming_Declaration |
13198 N_Block_Statement |
13199 N_Formal_Subprogram_Declaration |
13200 N_Abstract_Subprogram_Declaration |
13202 N_Exception_Declaration |
13203 N_Formal_Package_Declaration |
13204 N_Number_Declaration |
13205 N_Package_Specification |
13206 N_Parameter_Specification |
13207 N_Single_Protected_Declaration |
13211 (Nearest_Dynamic_Scope
13212 (Defining_Entity
(Node_Par
)));
13218 Node_Par
:= Parent
(Node_Par
);
13221 pragma Assert
(False);
13223 -- Should never reach the following return
13225 return Scope_Depth
(Current_Scope
) + 1;
13226 end Innermost_Master_Scope_Depth
;
13228 -- Start of processing for Return_Master_Scope_Depth_Of_Call
13231 return Innermost_Master_Scope_Depth
(Obj
);
13232 end Return_Master_Scope_Depth_Of_Call
;
13235 -- For convenience we handle qualified expressions, even though they
13236 -- aren't technically object names.
13238 elsif Nkind
(Obj
) = N_Qualified_Expression
then
13239 return Object_Access_Level
(Expression
(Obj
));
13241 -- Otherwise return the scope level of Standard. (If there are cases
13242 -- that fall through to this point they will be treated as having
13243 -- global accessibility for now. ???)
13246 return Scope_Depth
(Standard_Standard
);
13248 end Object_Access_Level
;
13250 --------------------------
13251 -- Original_Aspect_Name --
13252 --------------------------
13254 function Original_Aspect_Name
(N
: Node_Id
) return Name_Id
is
13259 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
13262 if Is_Rewrite_Substitution
(Pras
)
13263 and then Nkind
(Original_Node
(Pras
)) = N_Pragma
13265 Pras
:= Original_Node
(Pras
);
13268 -- Case where we came from aspect specication
13270 if Nkind
(Pras
) = N_Pragma
and then From_Aspect_Specification
(Pras
) then
13271 Pras
:= Corresponding_Aspect
(Pras
);
13274 -- Get name from aspect or pragma
13276 if Nkind
(Pras
) = N_Pragma
then
13277 Name
:= Pragma_Name
(Pras
);
13279 Name
:= Chars
(Identifier
(Pras
));
13282 -- Deal with 'Class
13284 if Class_Present
(Pras
) then
13287 -- Names that need converting to special _xxx form
13295 Name
:= Name_uPost
;
13297 when Name_Invariant
=>
13298 Name
:= Name_uInvariant
;
13300 when Name_Type_Invariant |
13301 Name_Type_Invariant_Class
=>
13302 Name
:= Name_uType_Invariant
;
13304 -- Nothing to do for other cases (e.g. a Check that derived
13305 -- from Pre_Class and has the flag set). Also we do nothing
13306 -- if the name is already in special _xxx form.
13314 end Original_Aspect_Name
;
13315 --------------------------------------
13316 -- Original_Corresponding_Operation --
13317 --------------------------------------
13319 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
13321 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
13324 -- If S is an inherited primitive S2 the original corresponding
13325 -- operation of S is the original corresponding operation of S2
13327 if Present
(Alias
(S
))
13328 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
13330 return Original_Corresponding_Operation
(Alias
(S
));
13332 -- If S overrides an inherited subprogram S2 the original corresponding
13333 -- operation of S is the original corresponding operation of S2
13335 elsif Present
(Overridden_Operation
(S
)) then
13336 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
13338 -- otherwise it is S itself
13343 end Original_Corresponding_Operation
;
13345 -----------------------
13346 -- Private_Component --
13347 -----------------------
13349 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
13350 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
13352 function Trace_Components
13354 Check
: Boolean) return Entity_Id
;
13355 -- Recursive function that does the work, and checks against circular
13356 -- definition for each subcomponent type.
13358 ----------------------
13359 -- Trace_Components --
13360 ----------------------
13362 function Trace_Components
13364 Check
: Boolean) return Entity_Id
13366 Btype
: constant Entity_Id
:= Base_Type
(T
);
13367 Component
: Entity_Id
;
13369 Candidate
: Entity_Id
:= Empty
;
13372 if Check
and then Btype
= Ancestor
then
13373 Error_Msg_N
("circular type definition", Type_Id
);
13377 if Is_Private_Type
(Btype
)
13378 and then not Is_Generic_Type
(Btype
)
13380 if Present
(Full_View
(Btype
))
13381 and then Is_Record_Type
(Full_View
(Btype
))
13382 and then not Is_Frozen
(Btype
)
13384 -- To indicate that the ancestor depends on a private type, the
13385 -- current Btype is sufficient. However, to check for circular
13386 -- definition we must recurse on the full view.
13388 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
13390 if Candidate
= Any_Type
then
13400 elsif Is_Array_Type
(Btype
) then
13401 return Trace_Components
(Component_Type
(Btype
), True);
13403 elsif Is_Record_Type
(Btype
) then
13404 Component
:= First_Entity
(Btype
);
13405 while Present
(Component
)
13406 and then Comes_From_Source
(Component
)
13408 -- Skip anonymous types generated by constrained components
13410 if not Is_Type
(Component
) then
13411 P
:= Trace_Components
(Etype
(Component
), True);
13413 if Present
(P
) then
13414 if P
= Any_Type
then
13422 Next_Entity
(Component
);
13430 end Trace_Components
;
13432 -- Start of processing for Private_Component
13435 return Trace_Components
(Type_Id
, False);
13436 end Private_Component
;
13438 ---------------------------
13439 -- Primitive_Names_Match --
13440 ---------------------------
13442 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
13444 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
13445 -- Given an internal name, returns the corresponding non-internal name
13447 ------------------------
13448 -- Non_Internal_Name --
13449 ------------------------
13451 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
13453 Get_Name_String
(Chars
(E
));
13454 Name_Len
:= Name_Len
- 1;
13456 end Non_Internal_Name
;
13458 -- Start of processing for Primitive_Names_Match
13461 pragma Assert
(Present
(E1
) and then Present
(E2
));
13463 return Chars
(E1
) = Chars
(E2
)
13465 (not Is_Internal_Name
(Chars
(E1
))
13466 and then Is_Internal_Name
(Chars
(E2
))
13467 and then Non_Internal_Name
(E2
) = Chars
(E1
))
13469 (not Is_Internal_Name
(Chars
(E2
))
13470 and then Is_Internal_Name
(Chars
(E1
))
13471 and then Non_Internal_Name
(E1
) = Chars
(E2
))
13473 (Is_Predefined_Dispatching_Operation
(E1
)
13474 and then Is_Predefined_Dispatching_Operation
(E2
)
13475 and then Same_TSS
(E1
, E2
))
13477 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
13478 end Primitive_Names_Match
;
13480 -----------------------
13481 -- Process_End_Label --
13482 -----------------------
13484 procedure Process_End_Label
13493 Label_Ref
: Boolean;
13494 -- Set True if reference to end label itself is required
13497 -- Gets set to the operator symbol or identifier that references the
13498 -- entity Ent. For the child unit case, this is the identifier from the
13499 -- designator. For other cases, this is simply Endl.
13501 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
13502 -- N is an identifier node that appears as a parent unit reference in
13503 -- the case where Ent is a child unit. This procedure generates an
13504 -- appropriate cross-reference entry. E is the corresponding entity.
13506 -------------------------
13507 -- Generate_Parent_Ref --
13508 -------------------------
13510 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
13512 -- If names do not match, something weird, skip reference
13514 if Chars
(E
) = Chars
(N
) then
13516 -- Generate the reference. We do NOT consider this as a reference
13517 -- for unreferenced symbol purposes.
13519 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
13521 if Style_Check
then
13522 Style
.Check_Identifier
(N
, E
);
13525 end Generate_Parent_Ref
;
13527 -- Start of processing for Process_End_Label
13530 -- If no node, ignore. This happens in some error situations, and
13531 -- also for some internally generated structures where no end label
13532 -- references are required in any case.
13538 -- Nothing to do if no End_Label, happens for internally generated
13539 -- constructs where we don't want an end label reference anyway. Also
13540 -- nothing to do if Endl is a string literal, which means there was
13541 -- some prior error (bad operator symbol)
13543 Endl
:= End_Label
(N
);
13545 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
13549 -- Reference node is not in extended main source unit
13551 if not In_Extended_Main_Source_Unit
(N
) then
13553 -- Generally we do not collect references except for the extended
13554 -- main source unit. The one exception is the 'e' entry for a
13555 -- package spec, where it is useful for a client to have the
13556 -- ending information to define scopes.
13562 Label_Ref
:= False;
13564 -- For this case, we can ignore any parent references, but we
13565 -- need the package name itself for the 'e' entry.
13567 if Nkind
(Endl
) = N_Designator
then
13568 Endl
:= Identifier
(Endl
);
13572 -- Reference is in extended main source unit
13577 -- For designator, generate references for the parent entries
13579 if Nkind
(Endl
) = N_Designator
then
13581 -- Generate references for the prefix if the END line comes from
13582 -- source (otherwise we do not need these references) We climb the
13583 -- scope stack to find the expected entities.
13585 if Comes_From_Source
(Endl
) then
13586 Nam
:= Name
(Endl
);
13587 Scop
:= Current_Scope
;
13588 while Nkind
(Nam
) = N_Selected_Component
loop
13589 Scop
:= Scope
(Scop
);
13590 exit when No
(Scop
);
13591 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
13592 Nam
:= Prefix
(Nam
);
13595 if Present
(Scop
) then
13596 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
13600 Endl
:= Identifier
(Endl
);
13604 -- If the end label is not for the given entity, then either we have
13605 -- some previous error, or this is a generic instantiation for which
13606 -- we do not need to make a cross-reference in this case anyway. In
13607 -- either case we simply ignore the call.
13609 if Chars
(Ent
) /= Chars
(Endl
) then
13613 -- If label was really there, then generate a normal reference and then
13614 -- adjust the location in the end label to point past the name (which
13615 -- should almost always be the semicolon).
13617 Loc
:= Sloc
(Endl
);
13619 if Comes_From_Source
(Endl
) then
13621 -- If a label reference is required, then do the style check and
13622 -- generate an l-type cross-reference entry for the label
13625 if Style_Check
then
13626 Style
.Check_Identifier
(Endl
, Ent
);
13629 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
13632 -- Set the location to point past the label (normally this will
13633 -- mean the semicolon immediately following the label). This is
13634 -- done for the sake of the 'e' or 't' entry generated below.
13636 Get_Decoded_Name_String
(Chars
(Endl
));
13637 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
13640 -- In SPARK mode, no missing label is allowed for packages and
13641 -- subprogram bodies. Detect those cases by testing whether
13642 -- Process_End_Label was called for a body (Typ = 't') or a package.
13644 if Restriction_Check_Required
(SPARK_05
)
13645 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
13647 Error_Msg_Node_1
:= Endl
;
13648 Check_SPARK_Restriction
("`END &` required", Endl
, Force
=> True);
13652 -- Now generate the e/t reference
13654 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
13656 -- Restore Sloc, in case modified above, since we have an identifier
13657 -- and the normal Sloc should be left set in the tree.
13659 Set_Sloc
(Endl
, Loc
);
13660 end Process_End_Label
;
13666 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
13667 Seen
: Boolean := False;
13669 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
13670 -- Determine whether node N denotes a reference to Id. If this is the
13671 -- case, set global flag Seen to True and stop the traversal.
13677 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
13679 if Is_Entity_Name
(N
)
13680 and then Present
(Entity
(N
))
13681 and then Entity
(N
) = Id
13690 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
13692 -- Start of processing for Referenced
13695 Inspect_Expression
(Expr
);
13699 ------------------------------------
13700 -- References_Generic_Formal_Type --
13701 ------------------------------------
13703 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
13705 function Process
(N
: Node_Id
) return Traverse_Result
;
13706 -- Process one node in search for generic formal type
13712 function Process
(N
: Node_Id
) return Traverse_Result
is
13714 if Nkind
(N
) in N_Has_Entity
then
13716 E
: constant Entity_Id
:= Entity
(N
);
13718 if Present
(E
) then
13719 if Is_Generic_Type
(E
) then
13721 elsif Present
(Etype
(E
))
13722 and then Is_Generic_Type
(Etype
(E
))
13733 function Traverse
is new Traverse_Func
(Process
);
13734 -- Traverse tree to look for generic type
13737 if Inside_A_Generic
then
13738 return Traverse
(N
) = Abandon
;
13742 end References_Generic_Formal_Type
;
13744 --------------------
13745 -- Remove_Homonym --
13746 --------------------
13748 procedure Remove_Homonym
(E
: Entity_Id
) is
13749 Prev
: Entity_Id
:= Empty
;
13753 if E
= Current_Entity
(E
) then
13754 if Present
(Homonym
(E
)) then
13755 Set_Current_Entity
(Homonym
(E
));
13757 Set_Name_Entity_Id
(Chars
(E
), Empty
);
13761 H
:= Current_Entity
(E
);
13762 while Present
(H
) and then H
/= E
loop
13767 -- If E is not on the homonym chain, nothing to do
13769 if Present
(H
) then
13770 Set_Homonym
(Prev
, Homonym
(E
));
13773 end Remove_Homonym
;
13775 ---------------------
13776 -- Rep_To_Pos_Flag --
13777 ---------------------
13779 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
13781 return New_Occurrence_Of
13782 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
13783 end Rep_To_Pos_Flag
;
13785 --------------------
13786 -- Require_Entity --
13787 --------------------
13789 procedure Require_Entity
(N
: Node_Id
) is
13791 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
13792 if Total_Errors_Detected
/= 0 then
13793 Set_Entity
(N
, Any_Id
);
13795 raise Program_Error
;
13798 end Require_Entity
;
13800 ------------------------------
13801 -- Requires_Transient_Scope --
13802 ------------------------------
13804 -- A transient scope is required when variable-sized temporaries are
13805 -- allocated in the primary or secondary stack, or when finalization
13806 -- actions must be generated before the next instruction.
13808 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
13809 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
13811 -- Start of processing for Requires_Transient_Scope
13814 -- This is a private type which is not completed yet. This can only
13815 -- happen in a default expression (of a formal parameter or of a
13816 -- record component). Do not expand transient scope in this case
13821 -- Do not expand transient scope for non-existent procedure return
13823 elsif Typ
= Standard_Void_Type
then
13826 -- Elementary types do not require a transient scope
13828 elsif Is_Elementary_Type
(Typ
) then
13831 -- Generally, indefinite subtypes require a transient scope, since the
13832 -- back end cannot generate temporaries, since this is not a valid type
13833 -- for declaring an object. It might be possible to relax this in the
13834 -- future, e.g. by declaring the maximum possible space for the type.
13836 elsif Is_Indefinite_Subtype
(Typ
) then
13839 -- Functions returning tagged types may dispatch on result so their
13840 -- returned value is allocated on the secondary stack. Controlled
13841 -- type temporaries need finalization.
13843 elsif Is_Tagged_Type
(Typ
)
13844 or else Has_Controlled_Component
(Typ
)
13846 return not Is_Value_Type
(Typ
);
13850 elsif Is_Record_Type
(Typ
) then
13854 Comp
:= First_Entity
(Typ
);
13855 while Present
(Comp
) loop
13856 if Ekind
(Comp
) = E_Component
13857 and then Requires_Transient_Scope
(Etype
(Comp
))
13861 Next_Entity
(Comp
);
13868 -- String literal types never require transient scope
13870 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
13873 -- Array type. Note that we already know that this is a constrained
13874 -- array, since unconstrained arrays will fail the indefinite test.
13876 elsif Is_Array_Type
(Typ
) then
13878 -- If component type requires a transient scope, the array does too
13880 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
13883 -- Otherwise, we only need a transient scope if the size depends on
13884 -- the value of one or more discriminants.
13887 return Size_Depends_On_Discriminant
(Typ
);
13890 -- All other cases do not require a transient scope
13895 end Requires_Transient_Scope
;
13897 --------------------------
13898 -- Reset_Analyzed_Flags --
13899 --------------------------
13901 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
13903 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
13904 -- Function used to reset Analyzed flags in tree. Note that we do
13905 -- not reset Analyzed flags in entities, since there is no need to
13906 -- reanalyze entities, and indeed, it is wrong to do so, since it
13907 -- can result in generating auxiliary stuff more than once.
13909 --------------------
13910 -- Clear_Analyzed --
13911 --------------------
13913 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
13915 if not Has_Extension
(N
) then
13916 Set_Analyzed
(N
, False);
13920 end Clear_Analyzed
;
13922 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
13924 -- Start of processing for Reset_Analyzed_Flags
13927 Reset_Analyzed
(N
);
13928 end Reset_Analyzed_Flags
;
13930 --------------------------------
13931 -- Returns_Unconstrained_Type --
13932 --------------------------------
13934 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
13936 return Ekind
(Subp
) = E_Function
13937 and then not Is_Scalar_Type
(Etype
(Subp
))
13938 and then not Is_Access_Type
(Etype
(Subp
))
13939 and then not Is_Constrained
(Etype
(Subp
));
13940 end Returns_Unconstrained_Type
;
13942 ---------------------------
13943 -- Safe_To_Capture_Value --
13944 ---------------------------
13946 function Safe_To_Capture_Value
13949 Cond
: Boolean := False) return Boolean
13952 -- The only entities for which we track constant values are variables
13953 -- which are not renamings, constants, out parameters, and in out
13954 -- parameters, so check if we have this case.
13956 -- Note: it may seem odd to track constant values for constants, but in
13957 -- fact this routine is used for other purposes than simply capturing
13958 -- the value. In particular, the setting of Known[_Non]_Null.
13960 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
13962 Ekind
(Ent
) = E_Constant
13964 Ekind
(Ent
) = E_Out_Parameter
13966 Ekind
(Ent
) = E_In_Out_Parameter
13970 -- For conditionals, we also allow loop parameters and all formals,
13971 -- including in parameters.
13975 (Ekind
(Ent
) = E_Loop_Parameter
13977 Ekind
(Ent
) = E_In_Parameter
)
13981 -- For all other cases, not just unsafe, but impossible to capture
13982 -- Current_Value, since the above are the only entities which have
13983 -- Current_Value fields.
13989 -- Skip if volatile or aliased, since funny things might be going on in
13990 -- these cases which we cannot necessarily track. Also skip any variable
13991 -- for which an address clause is given, or whose address is taken. Also
13992 -- never capture value of library level variables (an attempt to do so
13993 -- can occur in the case of package elaboration code).
13995 if Treat_As_Volatile
(Ent
)
13996 or else Is_Aliased
(Ent
)
13997 or else Present
(Address_Clause
(Ent
))
13998 or else Address_Taken
(Ent
)
13999 or else (Is_Library_Level_Entity
(Ent
)
14000 and then Ekind
(Ent
) = E_Variable
)
14005 -- OK, all above conditions are met. We also require that the scope of
14006 -- the reference be the same as the scope of the entity, not counting
14007 -- packages and blocks and loops.
14010 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
14011 R_Scope
: Entity_Id
;
14014 R_Scope
:= Current_Scope
;
14015 while R_Scope
/= Standard_Standard
loop
14016 exit when R_Scope
= E_Scope
;
14018 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
14021 R_Scope
:= Scope
(R_Scope
);
14026 -- We also require that the reference does not appear in a context
14027 -- where it is not sure to be executed (i.e. a conditional context
14028 -- or an exception handler). We skip this if Cond is True, since the
14029 -- capturing of values from conditional tests handles this ok.
14042 -- Seems dubious that case expressions are not handled here ???
14045 while Present
(P
) loop
14046 if Nkind
(P
) = N_If_Statement
14047 or else Nkind
(P
) = N_Case_Statement
14048 or else (Nkind
(P
) in N_Short_Circuit
14049 and then Desc
= Right_Opnd
(P
))
14050 or else (Nkind
(P
) = N_If_Expression
14051 and then Desc
/= First
(Expressions
(P
)))
14052 or else Nkind
(P
) = N_Exception_Handler
14053 or else Nkind
(P
) = N_Selective_Accept
14054 or else Nkind
(P
) = N_Conditional_Entry_Call
14055 or else Nkind
(P
) = N_Timed_Entry_Call
14056 or else Nkind
(P
) = N_Asynchronous_Select
14063 -- A special Ada 2012 case: the original node may be part
14064 -- of the else_actions of a conditional expression, in which
14065 -- case it might not have been expanded yet, and appears in
14066 -- a non-syntactic list of actions. In that case it is clearly
14067 -- not safe to save a value.
14070 and then Is_List_Member
(Desc
)
14071 and then No
(Parent
(List_Containing
(Desc
)))
14079 -- OK, looks safe to set value
14082 end Safe_To_Capture_Value
;
14088 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
14089 K1
: constant Node_Kind
:= Nkind
(N1
);
14090 K2
: constant Node_Kind
:= Nkind
(N2
);
14093 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
14094 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
14096 return Chars
(N1
) = Chars
(N2
);
14098 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
14099 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
14101 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
14102 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
14113 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
14114 N1
: constant Node_Id
:= Original_Node
(Node1
);
14115 N2
: constant Node_Id
:= Original_Node
(Node2
);
14116 -- We do the tests on original nodes, since we are most interested
14117 -- in the original source, not any expansion that got in the way.
14119 K1
: constant Node_Kind
:= Nkind
(N1
);
14120 K2
: constant Node_Kind
:= Nkind
(N2
);
14123 -- First case, both are entities with same entity
14125 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
14127 EN1
: constant Entity_Id
:= Entity
(N1
);
14128 EN2
: constant Entity_Id
:= Entity
(N2
);
14130 if Present
(EN1
) and then Present
(EN2
)
14131 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
14132 or else Is_Formal
(EN1
))
14140 -- Second case, selected component with same selector, same record
14142 if K1
= N_Selected_Component
14143 and then K2
= N_Selected_Component
14144 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
14146 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
14148 -- Third case, indexed component with same subscripts, same array
14150 elsif K1
= N_Indexed_Component
14151 and then K2
= N_Indexed_Component
14152 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
14157 E1
:= First
(Expressions
(N1
));
14158 E2
:= First
(Expressions
(N2
));
14159 while Present
(E1
) loop
14160 if not Same_Value
(E1
, E2
) then
14171 -- Fourth case, slice of same array with same bounds
14174 and then K2
= N_Slice
14175 and then Nkind
(Discrete_Range
(N1
)) = N_Range
14176 and then Nkind
(Discrete_Range
(N2
)) = N_Range
14177 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
14178 Low_Bound
(Discrete_Range
(N2
)))
14179 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
14180 High_Bound
(Discrete_Range
(N2
)))
14182 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
14184 -- All other cases, not clearly the same object
14195 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
14200 elsif not Is_Constrained
(T1
)
14201 and then not Is_Constrained
(T2
)
14202 and then Base_Type
(T1
) = Base_Type
(T2
)
14206 -- For now don't bother with case of identical constraints, to be
14207 -- fiddled with later on perhaps (this is only used for optimization
14208 -- purposes, so it is not critical to do a best possible job)
14219 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
14221 if Compile_Time_Known_Value
(Node1
)
14222 and then Compile_Time_Known_Value
(Node2
)
14223 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
14226 elsif Same_Object
(Node1
, Node2
) then
14233 ------------------------
14234 -- Scope_Is_Transient --
14235 ------------------------
14237 function Scope_Is_Transient
return Boolean is
14239 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
14240 end Scope_Is_Transient
;
14246 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
14251 while Scop
/= Standard_Standard
loop
14252 Scop
:= Scope
(Scop
);
14254 if Scop
= Scope2
then
14262 --------------------------
14263 -- Scope_Within_Or_Same --
14264 --------------------------
14266 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
14271 while Scop
/= Standard_Standard
loop
14272 if Scop
= Scope2
then
14275 Scop
:= Scope
(Scop
);
14280 end Scope_Within_Or_Same
;
14282 --------------------
14283 -- Set_Convention --
14284 --------------------
14286 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
14288 Basic_Set_Convention
(E
, Val
);
14291 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
14292 and then Has_Foreign_Convention
(E
)
14294 Set_Can_Use_Internal_Rep
(E
, False);
14296 end Set_Convention
;
14298 ------------------------
14299 -- Set_Current_Entity --
14300 ------------------------
14302 -- The given entity is to be set as the currently visible definition of its
14303 -- associated name (i.e. the Node_Id associated with its name). All we have
14304 -- to do is to get the name from the identifier, and then set the
14305 -- associated Node_Id to point to the given entity.
14307 procedure Set_Current_Entity
(E
: Entity_Id
) is
14309 Set_Name_Entity_Id
(Chars
(E
), E
);
14310 end Set_Current_Entity
;
14312 ---------------------------
14313 -- Set_Debug_Info_Needed --
14314 ---------------------------
14316 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
14318 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
14319 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
14320 -- Used to set debug info in a related node if not set already
14322 --------------------------------------
14323 -- Set_Debug_Info_Needed_If_Not_Set --
14324 --------------------------------------
14326 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
14329 and then not Needs_Debug_Info
(E
)
14331 Set_Debug_Info_Needed
(E
);
14333 -- For a private type, indicate that the full view also needs
14334 -- debug information.
14337 and then Is_Private_Type
(E
)
14338 and then Present
(Full_View
(E
))
14340 Set_Debug_Info_Needed
(Full_View
(E
));
14343 end Set_Debug_Info_Needed_If_Not_Set
;
14345 -- Start of processing for Set_Debug_Info_Needed
14348 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
14349 -- indicates that Debug_Info_Needed is never required for the entity.
14352 or else Debug_Info_Off
(T
)
14357 -- Set flag in entity itself. Note that we will go through the following
14358 -- circuitry even if the flag is already set on T. That's intentional,
14359 -- it makes sure that the flag will be set in subsidiary entities.
14361 Set_Needs_Debug_Info
(T
);
14363 -- Set flag on subsidiary entities if not set already
14365 if Is_Object
(T
) then
14366 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
14368 elsif Is_Type
(T
) then
14369 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
14371 if Is_Record_Type
(T
) then
14373 Ent
: Entity_Id
:= First_Entity
(T
);
14375 while Present
(Ent
) loop
14376 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
14381 -- For a class wide subtype, we also need debug information
14382 -- for the equivalent type.
14384 if Ekind
(T
) = E_Class_Wide_Subtype
then
14385 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
14388 elsif Is_Array_Type
(T
) then
14389 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
14392 Indx
: Node_Id
:= First_Index
(T
);
14394 while Present
(Indx
) loop
14395 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
14396 Indx
:= Next_Index
(Indx
);
14400 -- For a packed array type, we also need debug information for
14401 -- the type used to represent the packed array. Conversely, we
14402 -- also need it for the former if we need it for the latter.
14404 if Is_Packed
(T
) then
14405 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
14408 if Is_Packed_Array_Type
(T
) then
14409 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
14412 elsif Is_Access_Type
(T
) then
14413 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
14415 elsif Is_Private_Type
(T
) then
14416 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
14418 elsif Is_Protected_Type
(T
) then
14419 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
14422 end Set_Debug_Info_Needed
;
14424 ---------------------------------
14425 -- Set_Entity_With_Style_Check --
14426 ---------------------------------
14428 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
14429 Val_Actual
: Entity_Id
;
14433 -- Unconditionally set the entity
14435 Set_Entity
(N
, Val
);
14437 -- Check for No_Implementation_Identifiers
14439 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
14441 -- We have an implementation defined entity if it is marked as
14442 -- implementation defined, or is defined in a package marked as
14443 -- implementation defined. However, library packages themselves
14444 -- are excluded (we don't want to flag Interfaces itself, just
14445 -- the entities within it).
14447 if (Is_Implementation_Defined
(Val
)
14449 Is_Implementation_Defined
(Scope
(Val
)))
14450 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
14451 and then Is_Library_Level_Entity
(Val
))
14453 Check_Restriction
(No_Implementation_Identifiers
, N
);
14457 -- Do the style check
14460 and then not Suppress_Style_Checks
(Val
)
14461 and then not In_Instance
14463 if Nkind
(N
) = N_Identifier
then
14465 elsif Nkind
(N
) = N_Expanded_Name
then
14466 Nod
:= Selector_Name
(N
);
14471 -- A special situation arises for derived operations, where we want
14472 -- to do the check against the parent (since the Sloc of the derived
14473 -- operation points to the derived type declaration itself).
14476 while not Comes_From_Source
(Val_Actual
)
14477 and then Nkind
(Val_Actual
) in N_Entity
14478 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
14479 or else Is_Subprogram
(Val_Actual
)
14480 or else Is_Generic_Subprogram
(Val_Actual
))
14481 and then Present
(Alias
(Val_Actual
))
14483 Val_Actual
:= Alias
(Val_Actual
);
14486 -- Renaming declarations for generic actuals do not come from source,
14487 -- and have a different name from that of the entity they rename, so
14488 -- there is no style check to perform here.
14490 if Chars
(Nod
) = Chars
(Val_Actual
) then
14491 Style
.Check_Identifier
(Nod
, Val_Actual
);
14495 Set_Entity
(N
, Val
);
14496 end Set_Entity_With_Style_Check
;
14498 ------------------------
14499 -- Set_Name_Entity_Id --
14500 ------------------------
14502 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
14504 Set_Name_Table_Info
(Id
, Int
(Val
));
14505 end Set_Name_Entity_Id
;
14507 ---------------------
14508 -- Set_Next_Actual --
14509 ---------------------
14511 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
14513 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
14514 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
14516 end Set_Next_Actual
;
14518 ----------------------------------
14519 -- Set_Optimize_Alignment_Flags --
14520 ----------------------------------
14522 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
14524 if Optimize_Alignment
= 'S' then
14525 Set_Optimize_Alignment_Space
(E
);
14526 elsif Optimize_Alignment
= 'T' then
14527 Set_Optimize_Alignment_Time
(E
);
14529 end Set_Optimize_Alignment_Flags
;
14531 -----------------------
14532 -- Set_Public_Status --
14533 -----------------------
14535 procedure Set_Public_Status
(Id
: Entity_Id
) is
14536 S
: constant Entity_Id
:= Current_Scope
;
14538 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
14539 -- Determines if E is defined within handled statement sequence or
14540 -- an if statement, returns True if so, False otherwise.
14542 ----------------------
14543 -- Within_HSS_Or_If --
14544 ----------------------
14546 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
14549 N
:= Declaration_Node
(E
);
14556 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
14562 end Within_HSS_Or_If
;
14564 -- Start of processing for Set_Public_Status
14567 -- Everything in the scope of Standard is public
14569 if S
= Standard_Standard
then
14570 Set_Is_Public
(Id
);
14572 -- Entity is definitely not public if enclosing scope is not public
14574 elsif not Is_Public
(S
) then
14577 -- An object or function declaration that occurs in a handled sequence
14578 -- of statements or within an if statement is the declaration for a
14579 -- temporary object or local subprogram generated by the expander. It
14580 -- never needs to be made public and furthermore, making it public can
14581 -- cause back end problems.
14583 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
14584 N_Function_Specification
)
14585 and then Within_HSS_Or_If
(Id
)
14589 -- Entities in public packages or records are public
14591 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
14592 Set_Is_Public
(Id
);
14594 -- The bounds of an entry family declaration can generate object
14595 -- declarations that are visible to the back-end, e.g. in the
14596 -- the declaration of a composite type that contains tasks.
14598 elsif Is_Concurrent_Type
(S
)
14599 and then not Has_Completion
(S
)
14600 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
14602 Set_Is_Public
(Id
);
14604 end Set_Public_Status
;
14606 -----------------------------
14607 -- Set_Referenced_Modified --
14608 -----------------------------
14610 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
14614 -- Deal with indexed or selected component where prefix is modified
14616 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
14617 Pref
:= Prefix
(N
);
14619 -- If prefix is access type, then it is the designated object that is
14620 -- being modified, which means we have no entity to set the flag on.
14622 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
14625 -- Otherwise chase the prefix
14628 Set_Referenced_Modified
(Pref
, Out_Param
);
14631 -- Otherwise see if we have an entity name (only other case to process)
14633 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
14634 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
14635 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
14637 end Set_Referenced_Modified
;
14639 ----------------------------
14640 -- Set_Scope_Is_Transient --
14641 ----------------------------
14643 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
14645 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
14646 end Set_Scope_Is_Transient
;
14648 -------------------
14649 -- Set_Size_Info --
14650 -------------------
14652 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
14654 -- We copy Esize, but not RM_Size, since in general RM_Size is
14655 -- subtype specific and does not get inherited by all subtypes.
14657 Set_Esize
(T1
, Esize
(T2
));
14658 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
14660 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
14662 Is_Discrete_Or_Fixed_Point_Type
(T2
)
14664 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
14667 Set_Alignment
(T1
, Alignment
(T2
));
14670 --------------------
14671 -- Static_Boolean --
14672 --------------------
14674 function Static_Boolean
(N
: Node_Id
) return Uint
is
14676 Analyze_And_Resolve
(N
, Standard_Boolean
);
14679 or else Error_Posted
(N
)
14680 or else Etype
(N
) = Any_Type
14685 if Is_Static_Expression
(N
) then
14686 if not Raises_Constraint_Error
(N
) then
14687 return Expr_Value
(N
);
14692 elsif Etype
(N
) = Any_Type
then
14696 Flag_Non_Static_Expr
14697 ("static boolean expression required here", N
);
14700 end Static_Boolean
;
14702 --------------------
14703 -- Static_Integer --
14704 --------------------
14706 function Static_Integer
(N
: Node_Id
) return Uint
is
14708 Analyze_And_Resolve
(N
, Any_Integer
);
14711 or else Error_Posted
(N
)
14712 or else Etype
(N
) = Any_Type
14717 if Is_Static_Expression
(N
) then
14718 if not Raises_Constraint_Error
(N
) then
14719 return Expr_Value
(N
);
14724 elsif Etype
(N
) = Any_Type
then
14728 Flag_Non_Static_Expr
14729 ("static integer expression required here", N
);
14732 end Static_Integer
;
14734 --------------------------
14735 -- Statically_Different --
14736 --------------------------
14738 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
14739 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
14740 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
14742 return Is_Entity_Name
(R1
)
14743 and then Is_Entity_Name
(R2
)
14744 and then Entity
(R1
) /= Entity
(R2
)
14745 and then not Is_Formal
(Entity
(R1
))
14746 and then not Is_Formal
(Entity
(R2
));
14747 end Statically_Different
;
14749 --------------------------------------
14750 -- Subject_To_Loop_Entry_Attributes --
14751 --------------------------------------
14753 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
14759 -- The expansion mechanism transform a loop subject to at least one
14760 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
14761 -- the conditional part.
14763 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
14764 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
14766 Stmt
:= Original_Node
(N
);
14770 Nkind
(Stmt
) = N_Loop_Statement
14771 and then Present
(Identifier
(Stmt
))
14772 and then Present
(Entity
(Identifier
(Stmt
)))
14773 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
14774 end Subject_To_Loop_Entry_Attributes
;
14776 -----------------------------
14777 -- Subprogram_Access_Level --
14778 -----------------------------
14780 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
14782 if Present
(Alias
(Subp
)) then
14783 return Subprogram_Access_Level
(Alias
(Subp
));
14785 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
14787 end Subprogram_Access_Level
;
14789 -------------------------------
14790 -- Support_Atomic_Primitives --
14791 -------------------------------
14793 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
14797 -- Verify the alignment of Typ is known
14799 if not Known_Alignment
(Typ
) then
14803 if Known_Static_Esize
(Typ
) then
14804 Size
:= UI_To_Int
(Esize
(Typ
));
14806 -- If the Esize (Object_Size) is unknown at compile time, look at the
14807 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
14809 elsif Known_Static_RM_Size
(Typ
) then
14810 Size
:= UI_To_Int
(RM_Size
(Typ
));
14812 -- Otherwise, the size is considered to be unknown.
14818 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
14819 -- Typ is properly aligned.
14822 when 8 |
16 |
32 |
64 =>
14823 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
14827 end Support_Atomic_Primitives
;
14833 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
14835 if Debug_Flag_W
then
14836 for J
in 0 .. Scope_Stack
.Last
loop
14841 Write_Name
(Chars
(E
));
14842 Write_Str
(" from ");
14843 Write_Location
(Sloc
(N
));
14848 -----------------------
14849 -- Transfer_Entities --
14850 -----------------------
14852 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
14853 Ent
: Entity_Id
:= First_Entity
(From
);
14860 if (Last_Entity
(To
)) = Empty
then
14861 Set_First_Entity
(To
, Ent
);
14863 Set_Next_Entity
(Last_Entity
(To
), Ent
);
14866 Set_Last_Entity
(To
, Last_Entity
(From
));
14868 while Present
(Ent
) loop
14869 Set_Scope
(Ent
, To
);
14871 if not Is_Public
(Ent
) then
14872 Set_Public_Status
(Ent
);
14875 and then Ekind
(Ent
) = E_Record_Subtype
14878 -- The components of the propagated Itype must be public
14884 Comp
:= First_Entity
(Ent
);
14885 while Present
(Comp
) loop
14886 Set_Is_Public
(Comp
);
14887 Next_Entity
(Comp
);
14896 Set_First_Entity
(From
, Empty
);
14897 Set_Last_Entity
(From
, Empty
);
14898 end Transfer_Entities
;
14900 -----------------------
14901 -- Type_Access_Level --
14902 -----------------------
14904 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
14908 Btyp
:= Base_Type
(Typ
);
14910 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
14911 -- simply use the level where the type is declared. This is true for
14912 -- stand-alone object declarations, and for anonymous access types
14913 -- associated with components the level is the same as that of the
14914 -- enclosing composite type. However, special treatment is needed for
14915 -- the cases of access parameters, return objects of an anonymous access
14916 -- type, and, in Ada 95, access discriminants of limited types.
14918 if Ekind
(Btyp
) in Access_Kind
then
14919 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
14921 -- If the type is a nonlocal anonymous access type (such as for
14922 -- an access parameter) we treat it as being declared at the
14923 -- library level to ensure that names such as X.all'access don't
14924 -- fail static accessibility checks.
14926 if not Is_Local_Anonymous_Access
(Typ
) then
14927 return Scope_Depth
(Standard_Standard
);
14929 -- If this is a return object, the accessibility level is that of
14930 -- the result subtype of the enclosing function. The test here is
14931 -- little complicated, because we have to account for extended
14932 -- return statements that have been rewritten as blocks, in which
14933 -- case we have to find and the Is_Return_Object attribute of the
14934 -- itype's associated object. It would be nice to find a way to
14935 -- simplify this test, but it doesn't seem worthwhile to add a new
14936 -- flag just for purposes of this test. ???
14938 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
14941 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
14942 N_Object_Declaration
14943 and then Is_Return_Object
14944 (Defining_Identifier
14945 (Associated_Node_For_Itype
(Btyp
))))
14951 Scop
:= Scope
(Scope
(Btyp
));
14952 while Present
(Scop
) loop
14953 exit when Ekind
(Scop
) = E_Function
;
14954 Scop
:= Scope
(Scop
);
14957 -- Treat the return object's type as having the level of the
14958 -- function's result subtype (as per RM05-6.5(5.3/2)).
14960 return Type_Access_Level
(Etype
(Scop
));
14965 Btyp
:= Root_Type
(Btyp
);
14967 -- The accessibility level of anonymous access types associated with
14968 -- discriminants is that of the current instance of the type, and
14969 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
14971 -- AI-402: access discriminants have accessibility based on the
14972 -- object rather than the type in Ada 2005, so the above paragraph
14975 -- ??? Needs completion with rules from AI-416
14977 if Ada_Version
<= Ada_95
14978 and then Ekind
(Typ
) = E_Anonymous_Access_Type
14979 and then Present
(Associated_Node_For_Itype
(Typ
))
14980 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
14981 N_Discriminant_Specification
14983 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
14987 -- Return library level for a generic formal type. This is done because
14988 -- RM(10.3.2) says that "The statically deeper relationship does not
14989 -- apply to ... a descendant of a generic formal type". Rather than
14990 -- checking at each point where a static accessibility check is
14991 -- performed to see if we are dealing with a formal type, this rule is
14992 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
14993 -- return extreme values for a formal type; Deepest_Type_Access_Level
14994 -- returns Int'Last. By calling the appropriate function from among the
14995 -- two, we ensure that the static accessibility check will pass if we
14996 -- happen to run into a formal type. More specifically, we should call
14997 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
14998 -- call occurs as part of a static accessibility check and the error
14999 -- case is the case where the type's level is too shallow (as opposed
15002 if Is_Generic_Type
(Root_Type
(Btyp
)) then
15003 return Scope_Depth
(Standard_Standard
);
15006 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
15007 end Type_Access_Level
;
15009 ------------------------------------
15010 -- Type_Without_Stream_Operation --
15011 ------------------------------------
15013 function Type_Without_Stream_Operation
15015 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
15017 BT
: constant Entity_Id
:= Base_Type
(T
);
15018 Op_Missing
: Boolean;
15021 if not Restriction_Active
(No_Default_Stream_Attributes
) then
15025 if Is_Elementary_Type
(T
) then
15026 if Op
= TSS_Null
then
15028 No
(TSS
(BT
, TSS_Stream_Read
))
15029 or else No
(TSS
(BT
, TSS_Stream_Write
));
15032 Op_Missing
:= No
(TSS
(BT
, Op
));
15041 elsif Is_Array_Type
(T
) then
15042 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
15044 elsif Is_Record_Type
(T
) then
15050 Comp
:= First_Component
(T
);
15051 while Present
(Comp
) loop
15052 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
15054 if Present
(C_Typ
) then
15058 Next_Component
(Comp
);
15064 elsif Is_Private_Type
(T
)
15065 and then Present
(Full_View
(T
))
15067 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
15071 end Type_Without_Stream_Operation
;
15073 ----------------------------
15074 -- Unique_Defining_Entity --
15075 ----------------------------
15077 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
15079 return Unique_Entity
(Defining_Entity
(N
));
15080 end Unique_Defining_Entity
;
15082 -------------------
15083 -- Unique_Entity --
15084 -------------------
15086 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
15087 U
: Entity_Id
:= E
;
15093 if Present
(Full_View
(E
)) then
15094 U
:= Full_View
(E
);
15098 if Present
(Full_View
(E
)) then
15099 U
:= Full_View
(E
);
15102 when E_Package_Body
=>
15105 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
15109 U
:= Corresponding_Spec
(P
);
15111 when E_Subprogram_Body
=>
15114 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
15120 if Nkind
(P
) = N_Subprogram_Body_Stub
then
15121 if Present
(Library_Unit
(P
)) then
15123 -- Get to the function or procedure (generic) entity through
15124 -- the body entity.
15127 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
15130 U
:= Corresponding_Spec
(P
);
15133 when Formal_Kind
=>
15134 if Present
(Spec_Entity
(E
)) then
15135 U
:= Spec_Entity
(E
);
15149 function Unique_Name
(E
: Entity_Id
) return String is
15151 -- Names of E_Subprogram_Body or E_Package_Body entities are not
15152 -- reliable, as they may not include the overloading suffix. Instead,
15153 -- when looking for the name of E or one of its enclosing scope, we get
15154 -- the name of the corresponding Unique_Entity.
15156 function Get_Scoped_Name
(E
: Entity_Id
) return String;
15157 -- Return the name of E prefixed by all the names of the scopes to which
15158 -- E belongs, except for Standard.
15160 ---------------------
15161 -- Get_Scoped_Name --
15162 ---------------------
15164 function Get_Scoped_Name
(E
: Entity_Id
) return String is
15165 Name
: constant String := Get_Name_String
(Chars
(E
));
15167 if Has_Fully_Qualified_Name
(E
)
15168 or else Scope
(E
) = Standard_Standard
15172 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
15174 end Get_Scoped_Name
;
15176 -- Start of processing for Unique_Name
15179 if E
= Standard_Standard
then
15180 return Get_Name_String
(Name_Standard
);
15182 elsif Scope
(E
) = Standard_Standard
15183 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
15185 return Get_Name_String
(Name_Standard
) & "__" &
15186 Get_Name_String
(Chars
(E
));
15188 elsif Ekind
(E
) = E_Enumeration_Literal
then
15189 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
15192 return Get_Scoped_Name
(Unique_Entity
(E
));
15196 ---------------------
15197 -- Unit_Is_Visible --
15198 ---------------------
15200 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
15201 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
15202 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
15204 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
15205 -- For a child unit, check whether unit appears in a with_clause
15208 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
15209 -- Scan the context clause of one compilation unit looking for a
15210 -- with_clause for the unit in question.
15212 ----------------------------
15213 -- Unit_In_Parent_Context --
15214 ----------------------------
15216 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
15218 if Unit_In_Context
(Par_Unit
) then
15221 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
15222 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
15227 end Unit_In_Parent_Context
;
15229 ---------------------
15230 -- Unit_In_Context --
15231 ---------------------
15233 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
15237 Clause
:= First
(Context_Items
(Comp_Unit
));
15238 while Present
(Clause
) loop
15239 if Nkind
(Clause
) = N_With_Clause
then
15240 if Library_Unit
(Clause
) = U
then
15243 -- The with_clause may denote a renaming of the unit we are
15244 -- looking for, eg. Text_IO which renames Ada.Text_IO.
15247 Renamed_Entity
(Entity
(Name
(Clause
))) =
15248 Defining_Entity
(Unit
(U
))
15258 end Unit_In_Context
;
15260 -- Start of processing for Unit_Is_Visible
15263 -- The currrent unit is directly visible
15268 elsif Unit_In_Context
(Curr
) then
15271 -- If the current unit is a body, check the context of the spec
15273 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
15275 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
15276 and then not Acts_As_Spec
(Unit
(Curr
)))
15278 if Unit_In_Context
(Library_Unit
(Curr
)) then
15283 -- If the spec is a child unit, examine the parents
15285 if Is_Child_Unit
(Curr_Entity
) then
15286 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
15288 Unit_In_Parent_Context
15289 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
15291 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
15297 end Unit_Is_Visible
;
15299 ------------------------------
15300 -- Universal_Interpretation --
15301 ------------------------------
15303 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
15304 Index
: Interp_Index
;
15308 -- The argument may be a formal parameter of an operator or subprogram
15309 -- with multiple interpretations, or else an expression for an actual.
15311 if Nkind
(Opnd
) = N_Defining_Identifier
15312 or else not Is_Overloaded
(Opnd
)
15314 if Etype
(Opnd
) = Universal_Integer
15315 or else Etype
(Opnd
) = Universal_Real
15317 return Etype
(Opnd
);
15323 Get_First_Interp
(Opnd
, Index
, It
);
15324 while Present
(It
.Typ
) loop
15325 if It
.Typ
= Universal_Integer
15326 or else It
.Typ
= Universal_Real
15331 Get_Next_Interp
(Index
, It
);
15336 end Universal_Interpretation
;
15342 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
15344 -- Recurse to handle unlikely case of multiple levels of qualification
15346 if Nkind
(Expr
) = N_Qualified_Expression
then
15347 return Unqualify
(Expression
(Expr
));
15349 -- Normal case, not a qualified expression
15356 -----------------------
15357 -- Visible_Ancestors --
15358 -----------------------
15360 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
15366 pragma Assert
(Is_Record_Type
(Typ
)
15367 and then Is_Tagged_Type
(Typ
));
15369 -- Collect all the parents and progenitors of Typ. If the full-view of
15370 -- private parents and progenitors is available then it is used to
15371 -- generate the list of visible ancestors; otherwise their partial
15372 -- view is added to the resulting list.
15377 Use_Full_View
=> True);
15381 Ifaces_List
=> List_2
,
15382 Exclude_Parents
=> True,
15383 Use_Full_View
=> True);
15385 -- Join the two lists. Avoid duplications because an interface may
15386 -- simultaneously be parent and progenitor of a type.
15388 Elmt
:= First_Elmt
(List_2
);
15389 while Present
(Elmt
) loop
15390 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
15395 end Visible_Ancestors
;
15397 ----------------------
15398 -- Within_Init_Proc --
15399 ----------------------
15401 function Within_Init_Proc
return Boolean is
15405 S
:= Current_Scope
;
15406 while not Is_Overloadable
(S
) loop
15407 if S
= Standard_Standard
then
15414 return Is_Init_Proc
(S
);
15415 end Within_Init_Proc
;
15421 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
15422 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
15423 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
15425 Matching_Field
: Entity_Id
;
15426 -- Entity to give a more precise suggestion on how to write a one-
15427 -- element positional aggregate.
15429 function Has_One_Matching_Field
return Boolean;
15430 -- Determines if Expec_Type is a record type with a single component or
15431 -- discriminant whose type matches the found type or is one dimensional
15432 -- array whose component type matches the found type. In the case of
15433 -- one discriminant, we ignore the variant parts. That's not accurate,
15434 -- but good enough for the warning.
15436 ----------------------------
15437 -- Has_One_Matching_Field --
15438 ----------------------------
15440 function Has_One_Matching_Field
return Boolean is
15444 Matching_Field
:= Empty
;
15446 if Is_Array_Type
(Expec_Type
)
15447 and then Number_Dimensions
(Expec_Type
) = 1
15449 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
15451 -- Use type name if available. This excludes multidimensional
15452 -- arrays and anonymous arrays.
15454 if Comes_From_Source
(Expec_Type
) then
15455 Matching_Field
:= Expec_Type
;
15457 -- For an assignment, use name of target
15459 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
15460 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
15462 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
15467 elsif not Is_Record_Type
(Expec_Type
) then
15471 E
:= First_Entity
(Expec_Type
);
15476 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
15477 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
15486 if not Covers
(Etype
(E
), Found_Type
) then
15489 elsif Present
(Next_Entity
(E
))
15490 and then (Ekind
(E
) = E_Component
15491 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
15496 Matching_Field
:= E
;
15500 end Has_One_Matching_Field
;
15502 -- Start of processing for Wrong_Type
15505 -- Don't output message if either type is Any_Type, or if a message
15506 -- has already been posted for this node. We need to do the latter
15507 -- check explicitly (it is ordinarily done in Errout), because we
15508 -- are using ! to force the output of the error messages.
15510 if Expec_Type
= Any_Type
15511 or else Found_Type
= Any_Type
15512 or else Error_Posted
(Expr
)
15516 -- If one of the types is a Taft-Amendment type and the other it its
15517 -- completion, it must be an illegal use of a TAT in the spec, for
15518 -- which an error was already emitted. Avoid cascaded errors.
15520 elsif Is_Incomplete_Type
(Expec_Type
)
15521 and then Has_Completion_In_Body
(Expec_Type
)
15522 and then Full_View
(Expec_Type
) = Etype
(Expr
)
15526 elsif Is_Incomplete_Type
(Etype
(Expr
))
15527 and then Has_Completion_In_Body
(Etype
(Expr
))
15528 and then Full_View
(Etype
(Expr
)) = Expec_Type
15532 -- In an instance, there is an ongoing problem with completion of
15533 -- type derived from private types. Their structure is what Gigi
15534 -- expects, but the Etype is the parent type rather than the
15535 -- derived private type itself. Do not flag error in this case. The
15536 -- private completion is an entity without a parent, like an Itype.
15537 -- Similarly, full and partial views may be incorrect in the instance.
15538 -- There is no simple way to insure that it is consistent ???
15540 elsif In_Instance
then
15541 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
15543 (Has_Private_Declaration
(Expected_Type
)
15544 or else Has_Private_Declaration
(Etype
(Expr
)))
15545 and then No
(Parent
(Expected_Type
))
15551 -- An interesting special check. If the expression is parenthesized
15552 -- and its type corresponds to the type of the sole component of the
15553 -- expected record type, or to the component type of the expected one
15554 -- dimensional array type, then assume we have a bad aggregate attempt.
15556 if Nkind
(Expr
) in N_Subexpr
15557 and then Paren_Count
(Expr
) /= 0
15558 and then Has_One_Matching_Field
15560 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
15561 if Present
(Matching_Field
) then
15562 if Is_Array_Type
(Expec_Type
) then
15564 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
15568 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
15572 -- Another special check, if we are looking for a pool-specific access
15573 -- type and we found an E_Access_Attribute_Type, then we have the case
15574 -- of an Access attribute being used in a context which needs a pool-
15575 -- specific type, which is never allowed. The one extra check we make
15576 -- is that the expected designated type covers the Found_Type.
15578 elsif Is_Access_Type
(Expec_Type
)
15579 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
15580 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
15581 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
15583 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
15585 Error_Msg_N
-- CODEFIX
15586 ("result must be general access type!", Expr
);
15587 Error_Msg_NE
-- CODEFIX
15588 ("add ALL to }!", Expr
, Expec_Type
);
15590 -- Another special check, if the expected type is an integer type,
15591 -- but the expression is of type System.Address, and the parent is
15592 -- an addition or subtraction operation whose left operand is the
15593 -- expression in question and whose right operand is of an integral
15594 -- type, then this is an attempt at address arithmetic, so give
15595 -- appropriate message.
15597 elsif Is_Integer_Type
(Expec_Type
)
15598 and then Is_RTE
(Found_Type
, RE_Address
)
15599 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
15601 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
15602 and then Expr
= Left_Opnd
(Parent
(Expr
))
15603 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
15606 ("address arithmetic not predefined in package System",
15609 ("\possible missing with/use of System.Storage_Elements",
15613 -- If the expected type is an anonymous access type, as for access
15614 -- parameters and discriminants, the error is on the designated types.
15616 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
15617 if Comes_From_Source
(Expec_Type
) then
15618 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
15621 ("expected an access type with designated}",
15622 Expr
, Designated_Type
(Expec_Type
));
15625 if Is_Access_Type
(Found_Type
)
15626 and then not Comes_From_Source
(Found_Type
)
15629 ("\\found an access type with designated}!",
15630 Expr
, Designated_Type
(Found_Type
));
15632 if From_Limited_With
(Found_Type
) then
15633 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
15634 Error_Msg_Qual_Level
:= 99;
15635 Error_Msg_NE
-- CODEFIX
15636 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
15637 Error_Msg_Qual_Level
:= 0;
15639 Error_Msg_NE
("found}!", Expr
, Found_Type
);
15643 -- Normal case of one type found, some other type expected
15646 -- If the names of the two types are the same, see if some number
15647 -- of levels of qualification will help. Don't try more than three
15648 -- levels, and if we get to standard, it's no use (and probably
15649 -- represents an error in the compiler) Also do not bother with
15650 -- internal scope names.
15653 Expec_Scope
: Entity_Id
;
15654 Found_Scope
: Entity_Id
;
15657 Expec_Scope
:= Expec_Type
;
15658 Found_Scope
:= Found_Type
;
15660 for Levels
in Int
range 0 .. 3 loop
15661 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
15662 Error_Msg_Qual_Level
:= Levels
;
15666 Expec_Scope
:= Scope
(Expec_Scope
);
15667 Found_Scope
:= Scope
(Found_Scope
);
15669 exit when Expec_Scope
= Standard_Standard
15670 or else Found_Scope
= Standard_Standard
15671 or else not Comes_From_Source
(Expec_Scope
)
15672 or else not Comes_From_Source
(Found_Scope
);
15676 if Is_Record_Type
(Expec_Type
)
15677 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
15679 Error_Msg_NE
("expected}!", Expr
,
15680 Corresponding_Remote_Type
(Expec_Type
));
15682 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
15685 if Is_Entity_Name
(Expr
)
15686 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
15688 Error_Msg_N
("\\found package name!", Expr
);
15690 elsif Is_Entity_Name
(Expr
)
15692 (Ekind
(Entity
(Expr
)) = E_Procedure
15694 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
15696 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
15698 ("found procedure name, possibly missing Access attribute!",
15702 ("\\found procedure name instead of function!", Expr
);
15705 elsif Nkind
(Expr
) = N_Function_Call
15706 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
15707 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
15708 and then No
(Parameter_Associations
(Expr
))
15711 ("found function name, possibly missing Access attribute!",
15714 -- Catch common error: a prefix or infix operator which is not
15715 -- directly visible because the type isn't.
15717 elsif Nkind
(Expr
) in N_Op
15718 and then Is_Overloaded
(Expr
)
15719 and then not Is_Immediately_Visible
(Expec_Type
)
15720 and then not Is_Potentially_Use_Visible
(Expec_Type
)
15721 and then not In_Use
(Expec_Type
)
15722 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
15725 ("operator of the type is not directly visible!", Expr
);
15727 elsif Ekind
(Found_Type
) = E_Void
15728 and then Present
(Parent
(Found_Type
))
15729 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
15731 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
15734 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
15737 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
15738 -- of the same modular type, and (M1 and M2) = 0 was intended.
15740 if Expec_Type
= Standard_Boolean
15741 and then Is_Modular_Integer_Type
(Found_Type
)
15742 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
15743 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
15746 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
15747 L
: constant Node_Id
:= Left_Opnd
(Op
);
15748 R
: constant Node_Id
:= Right_Opnd
(Op
);
15750 -- The case for the message is when the left operand of the
15751 -- comparison is the same modular type, or when it is an
15752 -- integer literal (or other universal integer expression),
15753 -- which would have been typed as the modular type if the
15754 -- parens had been there.
15756 if (Etype
(L
) = Found_Type
15758 Etype
(L
) = Universal_Integer
)
15759 and then Is_Integer_Type
(Etype
(R
))
15762 ("\\possible missing parens for modular operation", Expr
);
15767 -- Reset error message qualification indication
15769 Error_Msg_Qual_Level
:= 0;