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_Enabled_Property
118 Prop_Nam
: Name_Id
) return Boolean;
119 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
120 -- Determine whether an abstract state denoted by its entity State_Id has
121 -- enabled property Prop_Name.
123 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
124 -- T is a derived tagged type. Check whether the type extension is null.
125 -- If the parent type is fully initialized, T can be treated as such.
127 ------------------------------
128 -- Abstract_Interface_List --
129 ------------------------------
131 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
135 if Is_Concurrent_Type
(Typ
) then
137 -- If we are dealing with a synchronized subtype, go to the base
138 -- type, whose declaration has the interface list.
140 -- Shouldn't this be Declaration_Node???
142 Nod
:= Parent
(Base_Type
(Typ
));
144 if Nkind
(Nod
) = N_Full_Type_Declaration
then
148 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
149 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
150 Nod
:= Type_Definition
(Parent
(Typ
));
152 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
153 if Present
(Full_View
(Typ
))
154 and then Nkind
(Parent
(Full_View
(Typ
)))
155 = N_Full_Type_Declaration
157 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
159 -- If the full-view is not available we cannot do anything else
160 -- here (the source has errors).
166 -- Support for generic formals with interfaces is still missing ???
168 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
173 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
177 elsif Ekind
(Typ
) = E_Record_Subtype
then
178 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
180 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
182 -- Recurse, because parent may still be a private extension. Also
183 -- note that the full view of the subtype or the full view of its
184 -- base type may (both) be unavailable.
186 return Abstract_Interface_List
(Etype
(Typ
));
188 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
189 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
190 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
192 Nod
:= Type_Definition
(Parent
(Typ
));
196 return Interface_List
(Nod
);
197 end Abstract_Interface_List
;
199 --------------------------------
200 -- Add_Access_Type_To_Process --
201 --------------------------------
203 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
207 Ensure_Freeze_Node
(E
);
208 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
212 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
216 end Add_Access_Type_To_Process
;
218 -----------------------
219 -- Add_Contract_Item --
220 -----------------------
222 procedure Add_Contract_Item
(Prag
: Node_Id
; Id
: Entity_Id
) is
223 Items
: constant Node_Id
:= Contract
(Id
);
228 -- The related context must have a contract and the item to be added
231 pragma Assert
(Present
(Items
));
232 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
234 Nam
:= Original_Aspect_Name
(Prag
);
236 -- Contract items related to [generic] packages or instantiations. The
237 -- applicable pragmas are:
241 -- Part_Of (instantiation only)
243 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
244 if Nam_In
(Nam
, Name_Abstract_State
,
245 Name_Initial_Condition
,
248 Set_Next_Pragma
(Prag
, Classifications
(Items
));
249 Set_Classifications
(Items
, Prag
);
251 -- Indicator Part_Of must be associated with a package instantiation
253 elsif Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) 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 package bodies. The applicable pragmas are:
266 elsif Ekind
(Id
) = E_Package_Body
then
267 if Nam
= Name_Refined_State
then
268 Set_Next_Pragma
(Prag
, Classifications
(Items
));
269 Set_Classifications
(Items
, Prag
);
271 -- The pragma is not a proper contract item
277 -- Contract items related to subprogram or entry declarations. The
278 -- applicable pragmas are:
288 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
289 or else Is_Generic_Subprogram
(Id
)
290 or else Is_Subprogram
(Id
)
292 if Nam_In
(Nam
, Name_Precondition
,
299 -- Before we add a precondition or postcondition to the list,
300 -- make sure we do not have a disallowed duplicate, which can
301 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
302 -- instead of the corresponding aspect.
304 if not From_Aspect_Specification
(Prag
)
305 and then Nam_In
(Nam
, Name_Pre_Class
,
312 N
:= Pre_Post_Conditions
(Items
);
313 while Present
(N
) loop
315 and then Original_Aspect_Name
(N
) = Nam
317 Error_Msg_Sloc
:= Sloc
(N
);
319 ("duplication of aspect for & given#", Prag
, Id
);
322 N
:= Next_Pragma
(N
);
327 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
328 Set_Pre_Post_Conditions
(Items
, Prag
);
330 elsif Nam_In
(Nam
, Name_Contract_Cases
, Name_Test_Case
) then
331 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
332 Set_Contract_Test_Cases
(Items
, Prag
);
334 elsif Nam_In
(Nam
, Name_Depends
, Name_Global
) then
335 Set_Next_Pragma
(Prag
, Classifications
(Items
));
336 Set_Classifications
(Items
, Prag
);
338 -- The pragma is not a proper contract item
344 -- Contract items related to subprogram bodies. The applicable pragmas
350 elsif Ekind
(Id
) = E_Subprogram_Body
then
351 if Nam
= Name_Refined_Post
then
352 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
353 Set_Pre_Post_Conditions
(Items
, Prag
);
355 elsif Nam_In
(Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
356 Set_Next_Pragma
(Prag
, Classifications
(Items
));
357 Set_Classifications
(Items
, Prag
);
359 -- The pragma is not a proper contract item
365 -- Contract items related to variables. The applicable pragmas are:
372 elsif Ekind
(Id
) = E_Variable
then
373 if Nam_In
(Nam
, Name_Async_Readers
,
375 Name_Effective_Reads
,
376 Name_Effective_Writes
,
379 Set_Next_Pragma
(Prag
, Classifications
(Items
));
380 Set_Classifications
(Items
, Prag
);
382 -- The pragma is not a proper contract item
388 end Add_Contract_Item
;
390 ----------------------------
391 -- Add_Global_Declaration --
392 ----------------------------
394 procedure Add_Global_Declaration
(N
: Node_Id
) is
395 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
398 if No
(Declarations
(Aux_Node
)) then
399 Set_Declarations
(Aux_Node
, New_List
);
402 Append_To
(Declarations
(Aux_Node
), N
);
404 end Add_Global_Declaration
;
406 --------------------------------
407 -- Address_Integer_Convert_OK --
408 --------------------------------
410 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
412 if Allow_Integer_Address
413 and then ((Is_Descendent_Of_Address
(T1
)
414 and then Is_Private_Type
(T1
)
415 and then Is_Integer_Type
(T2
))
417 (Is_Descendent_Of_Address
(T2
)
418 and then Is_Private_Type
(T2
)
419 and then Is_Integer_Type
(T1
)))
425 end Address_Integer_Convert_OK
;
431 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
433 function Addressable
(V
: Uint
) return Boolean is
435 return V
= Uint_8
or else
441 function Addressable
(V
: Int
) return Boolean is
449 -----------------------
450 -- Alignment_In_Bits --
451 -----------------------
453 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
455 return Alignment
(E
) * System_Storage_Unit
;
456 end Alignment_In_Bits
;
458 ---------------------------------
459 -- Append_Inherited_Subprogram --
460 ---------------------------------
462 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
463 Par
: constant Entity_Id
:= Alias
(S
);
464 -- The parent subprogram
466 Scop
: constant Entity_Id
:= Scope
(Par
);
467 -- The scope of definition of the parent subprogram
469 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
470 -- The derived type of which S is a primitive operation
476 if Ekind
(Current_Scope
) = E_Package
477 and then In_Private_Part
(Current_Scope
)
478 and then Has_Private_Declaration
(Typ
)
479 and then Is_Tagged_Type
(Typ
)
480 and then Scop
= Current_Scope
482 -- The inherited operation is available at the earliest place after
483 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
484 -- relevant for type extensions. If the parent operation appears
485 -- after the type extension, the operation is not visible.
488 (Visible_Declarations
489 (Package_Specification
(Current_Scope
)));
490 while Present
(Decl
) loop
491 if Nkind
(Decl
) = N_Private_Extension_Declaration
492 and then Defining_Entity
(Decl
) = Typ
494 if Sloc
(Decl
) > Sloc
(Par
) then
495 Next_E
:= Next_Entity
(Par
);
496 Set_Next_Entity
(Par
, S
);
497 Set_Next_Entity
(S
, Next_E
);
509 -- If partial view is not a type extension, or it appears before the
510 -- subprogram declaration, insert normally at end of entity list.
512 Append_Entity
(S
, Current_Scope
);
513 end Append_Inherited_Subprogram
;
515 -----------------------------------------
516 -- Apply_Compile_Time_Constraint_Error --
517 -----------------------------------------
519 procedure Apply_Compile_Time_Constraint_Error
522 Reason
: RT_Exception_Code
;
523 Ent
: Entity_Id
:= Empty
;
524 Typ
: Entity_Id
:= Empty
;
525 Loc
: Source_Ptr
:= No_Location
;
526 Rep
: Boolean := True;
527 Warn
: Boolean := False)
529 Stat
: constant Boolean := Is_Static_Expression
(N
);
530 R_Stat
: constant Node_Id
:=
531 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
542 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
548 -- Now we replace the node by an N_Raise_Constraint_Error node
549 -- This does not need reanalyzing, so set it as analyzed now.
552 Set_Analyzed
(N
, True);
555 Set_Raises_Constraint_Error
(N
);
557 -- Now deal with possible local raise handling
559 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
561 -- If the original expression was marked as static, the result is
562 -- still marked as static, but the Raises_Constraint_Error flag is
563 -- always set so that further static evaluation is not attempted.
566 Set_Is_Static_Expression
(N
);
568 end Apply_Compile_Time_Constraint_Error
;
570 ---------------------------
571 -- Async_Readers_Enabled --
572 ---------------------------
574 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
576 if Ekind
(Id
) = E_Abstract_State
then
577 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
579 else pragma Assert
(Ekind
(Id
) = E_Variable
);
580 return Present
(Get_Pragma
(Id
, Pragma_Async_Readers
));
582 end Async_Readers_Enabled
;
584 ---------------------------
585 -- Async_Writers_Enabled --
586 ---------------------------
588 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
590 if Ekind
(Id
) = E_Abstract_State
then
591 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
593 else pragma Assert
(Ekind
(Id
) = E_Variable
);
594 return Present
(Get_Pragma
(Id
, Pragma_Async_Writers
));
596 end Async_Writers_Enabled
;
598 --------------------------------------
599 -- Available_Full_View_Of_Component --
600 --------------------------------------
602 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
603 ST
: constant Entity_Id
:= Scope
(T
);
604 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
606 return In_Open_Scopes
(ST
)
607 and then In_Open_Scopes
(SCT
)
608 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
609 end Available_Full_View_Of_Component
;
615 procedure Bad_Attribute
618 Warn
: Boolean := False)
621 Error_Msg_Warn
:= Warn
;
622 Error_Msg_N
("unrecognized attribute&<", N
);
624 -- Check for possible misspelling
626 Error_Msg_Name_1
:= First_Attribute_Name
;
627 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
628 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
629 Error_Msg_N
-- CODEFIX
630 ("\possible misspelling of %<", N
);
634 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
638 --------------------------------
639 -- Bad_Predicated_Subtype_Use --
640 --------------------------------
642 procedure Bad_Predicated_Subtype_Use
646 Suggest_Static
: Boolean := False)
649 if Has_Predicates
(Typ
) then
650 if Is_Generic_Actual_Type
(Typ
) then
651 Error_Msg_Warn
:= SPARK_Mode
/= On
;
652 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
653 Error_Msg_F
("\Program_Error [<<", N
);
655 Make_Raise_Program_Error
(Sloc
(N
),
656 Reason
=> PE_Bad_Predicated_Generic_Type
));
659 Error_Msg_FE
(Msg
, N
, Typ
);
662 -- Emit an optional suggestion on how to remedy the error if the
663 -- context warrants it.
665 if Suggest_Static
and then Present
(Static_Predicate
(Typ
)) then
666 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
669 end Bad_Predicated_Subtype_Use
;
671 --------------------------
672 -- Build_Actual_Subtype --
673 --------------------------
675 function Build_Actual_Subtype
677 N
: Node_Or_Entity_Id
) return Node_Id
680 -- Normally Sloc (N), but may point to corresponding body in some cases
682 Constraints
: List_Id
;
688 Disc_Type
: Entity_Id
;
694 if Nkind
(N
) = N_Defining_Identifier
then
695 Obj
:= New_Reference_To
(N
, Loc
);
697 -- If this is a formal parameter of a subprogram declaration, and
698 -- we are compiling the body, we want the declaration for the
699 -- actual subtype to carry the source position of the body, to
700 -- prevent anomalies in gdb when stepping through the code.
702 if Is_Formal
(N
) then
704 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
706 if Nkind
(Decl
) = N_Subprogram_Declaration
707 and then Present
(Corresponding_Body
(Decl
))
709 Loc
:= Sloc
(Corresponding_Body
(Decl
));
718 if Is_Array_Type
(T
) then
719 Constraints
:= New_List
;
720 for J
in 1 .. Number_Dimensions
(T
) loop
722 -- Build an array subtype declaration with the nominal subtype and
723 -- the bounds of the actual. Add the declaration in front of the
724 -- local declarations for the subprogram, for analysis before any
725 -- reference to the formal in the body.
728 Make_Attribute_Reference
(Loc
,
730 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
731 Attribute_Name
=> Name_First
,
732 Expressions
=> New_List
(
733 Make_Integer_Literal
(Loc
, J
)));
736 Make_Attribute_Reference
(Loc
,
738 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
739 Attribute_Name
=> Name_Last
,
740 Expressions
=> New_List
(
741 Make_Integer_Literal
(Loc
, J
)));
743 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
746 -- If the type has unknown discriminants there is no constrained
747 -- subtype to build. This is never called for a formal or for a
748 -- lhs, so returning the type is ok ???
750 elsif Has_Unknown_Discriminants
(T
) then
754 Constraints
:= New_List
;
756 -- Type T is a generic derived type, inherit the discriminants from
759 if Is_Private_Type
(T
)
760 and then No
(Full_View
(T
))
762 -- T was flagged as an error if it was declared as a formal
763 -- derived type with known discriminants. In this case there
764 -- is no need to look at the parent type since T already carries
765 -- its own discriminants.
767 and then not Error_Posted
(T
)
769 Disc_Type
:= Etype
(Base_Type
(T
));
774 Discr
:= First_Discriminant
(Disc_Type
);
775 while Present
(Discr
) loop
776 Append_To
(Constraints
,
777 Make_Selected_Component
(Loc
,
779 Duplicate_Subexpr_No_Checks
(Obj
),
780 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
781 Next_Discriminant
(Discr
);
785 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
786 Set_Is_Internal
(Subt
);
789 Make_Subtype_Declaration
(Loc
,
790 Defining_Identifier
=> Subt
,
791 Subtype_Indication
=>
792 Make_Subtype_Indication
(Loc
,
793 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
795 Make_Index_Or_Discriminant_Constraint
(Loc
,
796 Constraints
=> Constraints
)));
798 Mark_Rewrite_Insertion
(Decl
);
800 end Build_Actual_Subtype
;
802 ---------------------------------------
803 -- Build_Actual_Subtype_Of_Component --
804 ---------------------------------------
806 function Build_Actual_Subtype_Of_Component
808 N
: Node_Id
) return Node_Id
810 Loc
: constant Source_Ptr
:= Sloc
(N
);
811 P
: constant Node_Id
:= Prefix
(N
);
814 Index_Typ
: Entity_Id
;
816 Desig_Typ
: Entity_Id
;
817 -- This is either a copy of T, or if T is an access type, then it is
818 -- the directly designated type of this access type.
820 function Build_Actual_Array_Constraint
return List_Id
;
821 -- If one or more of the bounds of the component depends on
822 -- discriminants, build actual constraint using the discriminants
825 function Build_Actual_Record_Constraint
return List_Id
;
826 -- Similar to previous one, for discriminated components constrained
827 -- by the discriminant of the enclosing object.
829 -----------------------------------
830 -- Build_Actual_Array_Constraint --
831 -----------------------------------
833 function Build_Actual_Array_Constraint
return List_Id
is
834 Constraints
: constant List_Id
:= New_List
;
842 Indx
:= First_Index
(Desig_Typ
);
843 while Present
(Indx
) loop
844 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
845 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
847 if Denotes_Discriminant
(Old_Lo
) then
849 Make_Selected_Component
(Loc
,
850 Prefix
=> New_Copy_Tree
(P
),
851 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
854 Lo
:= New_Copy_Tree
(Old_Lo
);
856 -- The new bound will be reanalyzed in the enclosing
857 -- declaration. For literal bounds that come from a type
858 -- declaration, the type of the context must be imposed, so
859 -- insure that analysis will take place. For non-universal
860 -- types this is not strictly necessary.
862 Set_Analyzed
(Lo
, False);
865 if Denotes_Discriminant
(Old_Hi
) then
867 Make_Selected_Component
(Loc
,
868 Prefix
=> New_Copy_Tree
(P
),
869 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
872 Hi
:= New_Copy_Tree
(Old_Hi
);
873 Set_Analyzed
(Hi
, False);
876 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
881 end Build_Actual_Array_Constraint
;
883 ------------------------------------
884 -- Build_Actual_Record_Constraint --
885 ------------------------------------
887 function Build_Actual_Record_Constraint
return List_Id
is
888 Constraints
: constant List_Id
:= New_List
;
893 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
894 while Present
(D
) loop
895 if Denotes_Discriminant
(Node
(D
)) then
896 D_Val
:= Make_Selected_Component
(Loc
,
897 Prefix
=> New_Copy_Tree
(P
),
898 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
901 D_Val
:= New_Copy_Tree
(Node
(D
));
904 Append
(D_Val
, Constraints
);
909 end Build_Actual_Record_Constraint
;
911 -- Start of processing for Build_Actual_Subtype_Of_Component
914 -- Why the test for Spec_Expression mode here???
916 if In_Spec_Expression
then
919 -- More comments for the rest of this body would be good ???
921 elsif Nkind
(N
) = N_Explicit_Dereference
then
922 if Is_Composite_Type
(T
)
923 and then not Is_Constrained
(T
)
924 and then not (Is_Class_Wide_Type
(T
)
925 and then Is_Constrained
(Root_Type
(T
)))
926 and then not Has_Unknown_Discriminants
(T
)
928 -- If the type of the dereference is already constrained, it is an
931 if Is_Array_Type
(Etype
(N
))
932 and then Is_Constrained
(Etype
(N
))
936 Remove_Side_Effects
(P
);
937 return Build_Actual_Subtype
(T
, N
);
944 if Ekind
(T
) = E_Access_Subtype
then
945 Desig_Typ
:= Designated_Type
(T
);
950 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
951 Id
:= First_Index
(Desig_Typ
);
952 while Present
(Id
) loop
953 Index_Typ
:= Underlying_Type
(Etype
(Id
));
955 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
957 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
959 Remove_Side_Effects
(P
);
961 Build_Component_Subtype
962 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
968 elsif Is_Composite_Type
(Desig_Typ
)
969 and then Has_Discriminants
(Desig_Typ
)
970 and then not Has_Unknown_Discriminants
(Desig_Typ
)
972 if Is_Private_Type
(Desig_Typ
)
973 and then No
(Discriminant_Constraint
(Desig_Typ
))
975 Desig_Typ
:= Full_View
(Desig_Typ
);
978 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
979 while Present
(D
) loop
980 if Denotes_Discriminant
(Node
(D
)) then
981 Remove_Side_Effects
(P
);
983 Build_Component_Subtype
(
984 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
991 -- If none of the above, the actual and nominal subtypes are the same
994 end Build_Actual_Subtype_Of_Component
;
996 -----------------------------
997 -- Build_Component_Subtype --
998 -----------------------------
1000 function Build_Component_Subtype
1003 T
: Entity_Id
) return Node_Id
1009 -- Unchecked_Union components do not require component subtypes
1011 if Is_Unchecked_Union
(T
) then
1015 Subt
:= Make_Temporary
(Loc
, 'S');
1016 Set_Is_Internal
(Subt
);
1019 Make_Subtype_Declaration
(Loc
,
1020 Defining_Identifier
=> Subt
,
1021 Subtype_Indication
=>
1022 Make_Subtype_Indication
(Loc
,
1023 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
1025 Make_Index_Or_Discriminant_Constraint
(Loc
,
1026 Constraints
=> C
)));
1028 Mark_Rewrite_Insertion
(Decl
);
1030 end Build_Component_Subtype
;
1032 ---------------------------
1033 -- Build_Default_Subtype --
1034 ---------------------------
1036 function Build_Default_Subtype
1038 N
: Node_Id
) return Entity_Id
1040 Loc
: constant Source_Ptr
:= Sloc
(N
);
1044 -- The base type that is to be constrained by the defaults
1047 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1051 Bas
:= Base_Type
(T
);
1053 -- If T is non-private but its base type is private, this is the
1054 -- completion of a subtype declaration whose parent type is private
1055 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1056 -- are to be found in the full view of the base.
1058 if Is_Private_Type
(Bas
) and then Present
(Full_View
(Bas
)) then
1059 Bas
:= Full_View
(Bas
);
1062 Disc
:= First_Discriminant
(T
);
1064 if No
(Discriminant_Default_Value
(Disc
)) then
1069 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1070 Constraints
: constant List_Id
:= New_List
;
1074 while Present
(Disc
) loop
1075 Append_To
(Constraints
,
1076 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1077 Next_Discriminant
(Disc
);
1081 Make_Subtype_Declaration
(Loc
,
1082 Defining_Identifier
=> Act
,
1083 Subtype_Indication
=>
1084 Make_Subtype_Indication
(Loc
,
1085 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1087 Make_Index_Or_Discriminant_Constraint
(Loc
,
1088 Constraints
=> Constraints
)));
1090 Insert_Action
(N
, Decl
);
1094 end Build_Default_Subtype
;
1096 --------------------------------------------
1097 -- Build_Discriminal_Subtype_Of_Component --
1098 --------------------------------------------
1100 function Build_Discriminal_Subtype_Of_Component
1101 (T
: Entity_Id
) return Node_Id
1103 Loc
: constant Source_Ptr
:= Sloc
(T
);
1107 function Build_Discriminal_Array_Constraint
return List_Id
;
1108 -- If one or more of the bounds of the component depends on
1109 -- discriminants, build actual constraint using the discriminants
1112 function Build_Discriminal_Record_Constraint
return List_Id
;
1113 -- Similar to previous one, for discriminated components constrained by
1114 -- the discriminant of the enclosing object.
1116 ----------------------------------------
1117 -- Build_Discriminal_Array_Constraint --
1118 ----------------------------------------
1120 function Build_Discriminal_Array_Constraint
return List_Id
is
1121 Constraints
: constant List_Id
:= New_List
;
1129 Indx
:= First_Index
(T
);
1130 while Present
(Indx
) loop
1131 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1132 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1134 if Denotes_Discriminant
(Old_Lo
) then
1135 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1138 Lo
:= New_Copy_Tree
(Old_Lo
);
1141 if Denotes_Discriminant
(Old_Hi
) then
1142 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1145 Hi
:= New_Copy_Tree
(Old_Hi
);
1148 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1153 end Build_Discriminal_Array_Constraint
;
1155 -----------------------------------------
1156 -- Build_Discriminal_Record_Constraint --
1157 -----------------------------------------
1159 function Build_Discriminal_Record_Constraint
return List_Id
is
1160 Constraints
: constant List_Id
:= New_List
;
1165 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1166 while Present
(D
) loop
1167 if Denotes_Discriminant
(Node
(D
)) then
1169 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1172 D_Val
:= New_Copy_Tree
(Node
(D
));
1175 Append
(D_Val
, Constraints
);
1180 end Build_Discriminal_Record_Constraint
;
1182 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1185 if Ekind
(T
) = E_Array_Subtype
then
1186 Id
:= First_Index
(T
);
1187 while Present
(Id
) loop
1188 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
1189 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1191 return Build_Component_Subtype
1192 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1198 elsif Ekind
(T
) = E_Record_Subtype
1199 and then Has_Discriminants
(T
)
1200 and then not Has_Unknown_Discriminants
(T
)
1202 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1203 while Present
(D
) loop
1204 if Denotes_Discriminant
(Node
(D
)) then
1205 return Build_Component_Subtype
1206 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1213 -- If none of the above, the actual and nominal subtypes are the same
1216 end Build_Discriminal_Subtype_Of_Component
;
1218 ------------------------------
1219 -- Build_Elaboration_Entity --
1220 ------------------------------
1222 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1223 Loc
: constant Source_Ptr
:= Sloc
(N
);
1225 Elab_Ent
: Entity_Id
;
1227 procedure Set_Package_Name
(Ent
: Entity_Id
);
1228 -- Given an entity, sets the fully qualified name of the entity in
1229 -- Name_Buffer, with components separated by double underscores. This
1230 -- is a recursive routine that climbs the scope chain to Standard.
1232 ----------------------
1233 -- Set_Package_Name --
1234 ----------------------
1236 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1238 if Scope
(Ent
) /= Standard_Standard
then
1239 Set_Package_Name
(Scope
(Ent
));
1242 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1244 Name_Buffer
(Name_Len
+ 1) := '_';
1245 Name_Buffer
(Name_Len
+ 2) := '_';
1246 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1247 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1251 Get_Name_String
(Chars
(Ent
));
1253 end Set_Package_Name
;
1255 -- Start of processing for Build_Elaboration_Entity
1258 -- Ignore if already constructed
1260 if Present
(Elaboration_Entity
(Spec_Id
)) then
1264 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1265 -- no role in analysis.
1271 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1272 -- name with dots replaced by double underscore. We have to manually
1273 -- construct this name, since it will be elaborated in the outer scope,
1274 -- and thus will not have the unit name automatically prepended.
1276 Set_Package_Name
(Spec_Id
);
1277 Add_Str_To_Name_Buffer
("_E");
1279 -- Create elaboration counter
1281 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1282 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1285 Make_Object_Declaration
(Loc
,
1286 Defining_Identifier
=> Elab_Ent
,
1287 Object_Definition
=>
1288 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1289 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1291 Push_Scope
(Standard_Standard
);
1292 Add_Global_Declaration
(Decl
);
1295 -- Reset True_Constant indication, since we will indeed assign a value
1296 -- to the variable in the binder main. We also kill the Current_Value
1297 -- and Last_Assignment fields for the same reason.
1299 Set_Is_True_Constant
(Elab_Ent
, False);
1300 Set_Current_Value
(Elab_Ent
, Empty
);
1301 Set_Last_Assignment
(Elab_Ent
, Empty
);
1303 -- We do not want any further qualification of the name (if we did not
1304 -- do this, we would pick up the name of the generic package in the case
1305 -- of a library level generic instantiation).
1307 Set_Has_Qualified_Name
(Elab_Ent
);
1308 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1309 end Build_Elaboration_Entity
;
1311 --------------------------------
1312 -- Build_Explicit_Dereference --
1313 --------------------------------
1315 procedure Build_Explicit_Dereference
1319 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1322 -- An entity of a type with a reference aspect is overloaded with
1323 -- both interpretations: with and without the dereference. Now that
1324 -- the dereference is made explicit, set the type of the node properly,
1325 -- to prevent anomalies in the backend. Same if the expression is an
1326 -- overloaded function call whose return type has a reference aspect.
1328 if Is_Entity_Name
(Expr
) then
1329 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1331 elsif Nkind
(Expr
) = N_Function_Call
then
1332 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1335 Set_Is_Overloaded
(Expr
, False);
1337 Make_Explicit_Dereference
(Loc
,
1339 Make_Selected_Component
(Loc
,
1340 Prefix
=> Relocate_Node
(Expr
),
1341 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1342 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1343 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1344 end Build_Explicit_Dereference
;
1346 -----------------------------------
1347 -- Cannot_Raise_Constraint_Error --
1348 -----------------------------------
1350 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1352 if Compile_Time_Known_Value
(Expr
) then
1355 elsif Do_Range_Check
(Expr
) then
1358 elsif Raises_Constraint_Error
(Expr
) then
1362 case Nkind
(Expr
) is
1363 when N_Identifier
=>
1366 when N_Expanded_Name
=>
1369 when N_Selected_Component
=>
1370 return not Do_Discriminant_Check
(Expr
);
1372 when N_Attribute_Reference
=>
1373 if Do_Overflow_Check
(Expr
) then
1376 elsif No
(Expressions
(Expr
)) then
1384 N
:= First
(Expressions
(Expr
));
1385 while Present
(N
) loop
1386 if Cannot_Raise_Constraint_Error
(N
) then
1397 when N_Type_Conversion
=>
1398 if Do_Overflow_Check
(Expr
)
1399 or else Do_Length_Check
(Expr
)
1400 or else Do_Tag_Check
(Expr
)
1404 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1407 when N_Unchecked_Type_Conversion
=>
1408 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1411 if Do_Overflow_Check
(Expr
) then
1414 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1421 if Do_Division_Check
(Expr
)
1422 or else Do_Overflow_Check
(Expr
)
1427 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1429 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1448 N_Op_Shift_Right_Arithmetic |
1452 if Do_Overflow_Check
(Expr
) then
1456 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1458 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1465 end Cannot_Raise_Constraint_Error
;
1467 -----------------------------------------
1468 -- Check_Dynamically_Tagged_Expression --
1469 -----------------------------------------
1471 procedure Check_Dynamically_Tagged_Expression
1474 Related_Nod
: Node_Id
)
1477 pragma Assert
(Is_Tagged_Type
(Typ
));
1479 -- In order to avoid spurious errors when analyzing the expanded code,
1480 -- this check is done only for nodes that come from source and for
1481 -- actuals of generic instantiations.
1483 if (Comes_From_Source
(Related_Nod
)
1484 or else In_Generic_Actual
(Expr
))
1485 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1486 or else Is_Dynamically_Tagged
(Expr
))
1487 and then Is_Tagged_Type
(Typ
)
1488 and then not Is_Class_Wide_Type
(Typ
)
1490 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1492 end Check_Dynamically_Tagged_Expression
;
1494 -----------------------------------------------
1495 -- Check_Expression_Against_Static_Predicate --
1496 -----------------------------------------------
1498 procedure Check_Expression_Against_Static_Predicate
1503 -- When the predicate is static and the value of the expression is known
1504 -- at compile time, evaluate the predicate check. A type is non-static
1505 -- when it has aspect Dynamic_Predicate.
1507 if Compile_Time_Known_Value
(Expr
)
1508 and then Has_Predicates
(Typ
)
1509 and then Present
(Static_Predicate
(Typ
))
1510 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
1512 -- Either -gnatc is enabled or the expression is ok
1514 if Operating_Mode
< Generate_Code
1515 or else Eval_Static_Predicate_Check
(Expr
, Typ
)
1519 -- The expression is prohibited by the static predicate
1523 ("?static expression fails static predicate check on &",
1527 end Check_Expression_Against_Static_Predicate
;
1529 --------------------------
1530 -- Check_Fully_Declared --
1531 --------------------------
1533 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1535 if Ekind
(T
) = E_Incomplete_Type
then
1537 -- Ada 2005 (AI-50217): If the type is available through a limited
1538 -- with_clause, verify that its full view has been analyzed.
1540 if From_Limited_With
(T
)
1541 and then Present
(Non_Limited_View
(T
))
1542 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1544 -- The non-limited view is fully declared
1549 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1552 -- Need comments for these tests ???
1554 elsif Has_Private_Component
(T
)
1555 and then not Is_Generic_Type
(Root_Type
(T
))
1556 and then not In_Spec_Expression
1558 -- Special case: if T is the anonymous type created for a single
1559 -- task or protected object, use the name of the source object.
1561 if Is_Concurrent_Type
(T
)
1562 and then not Comes_From_Source
(T
)
1563 and then Nkind
(N
) = N_Object_Declaration
1565 Error_Msg_NE
("type of& has incomplete component", N
,
1566 Defining_Identifier
(N
));
1570 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1573 end Check_Fully_Declared
;
1575 -------------------------------------
1576 -- Check_Function_Writable_Actuals --
1577 -------------------------------------
1579 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
1580 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
1581 Identifiers_List
: Elist_Id
:= No_Elist
;
1582 Error_Node
: Node_Id
:= Empty
;
1584 procedure Collect_Identifiers
(N
: Node_Id
);
1585 -- In a single traversal of subtree N collect in Writable_Actuals_List
1586 -- all the actuals of functions with writable actuals, and in the list
1587 -- Identifiers_List collect all the identifiers that are not actuals of
1588 -- functions with writable actuals. If a writable actual is referenced
1589 -- twice as writable actual then Error_Node is set to reference its
1590 -- second occurrence, the error is reported, and the tree traversal
1593 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
1594 -- Return the entity associated with the function call
1596 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
1597 -- Preanalyze N without reporting errors. Very dubious, you can't just
1598 -- go analyzing things more than once???
1600 -------------------------
1601 -- Collect_Identifiers --
1602 -------------------------
1604 procedure Collect_Identifiers
(N
: Node_Id
) is
1606 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
1607 -- Process a single node during the tree traversal to collect the
1608 -- writable actuals of functions and all the identifiers which are
1609 -- not writable actuals of functions.
1611 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
1612 -- Returns True if List has a node whose Entity is Entity (N)
1614 -------------------------
1615 -- Check_Function_Call --
1616 -------------------------
1618 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
1619 Is_Writable_Actual
: Boolean := False;
1623 if Nkind
(N
) = N_Identifier
then
1625 -- No analysis possible if the entity is not decorated
1627 if No
(Entity
(N
)) then
1630 -- Don't collect identifiers of packages, called functions, etc
1632 elsif Ekind_In
(Entity
(N
), E_Package
,
1639 -- Analyze if N is a writable actual of a function
1641 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
1643 Call
: constant Node_Id
:= Parent
(N
);
1648 Id
:= Get_Function_Id
(Call
);
1650 Formal
:= First_Formal
(Id
);
1651 Actual
:= First_Actual
(Call
);
1652 while Present
(Actual
) and then Present
(Formal
) loop
1654 if Ekind_In
(Formal
, E_Out_Parameter
,
1657 Is_Writable_Actual
:= True;
1663 Next_Formal
(Formal
);
1664 Next_Actual
(Actual
);
1669 if Is_Writable_Actual
then
1670 if Contains
(Writable_Actuals_List
, N
) then
1672 ("value may be affected by call to& "
1673 & "because order of evaluation is arbitrary", N
, Id
);
1678 if Writable_Actuals_List
= No_Elist
then
1679 Writable_Actuals_List
:= New_Elmt_List
;
1682 Append_Elmt
(N
, Writable_Actuals_List
);
1684 if Identifiers_List
= No_Elist
then
1685 Identifiers_List
:= New_Elmt_List
;
1688 Append_Unique_Elmt
(N
, Identifiers_List
);
1701 N
: Node_Id
) return Boolean
1703 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
1708 if List
= No_Elist
then
1712 Elmt
:= First_Elmt
(List
);
1713 while Present
(Elmt
) loop
1714 if Entity
(Node
(Elmt
)) = Entity
(N
) then
1728 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
1729 -- The traversal procedure
1731 -- Start of processing for Collect_Identifiers
1734 if Present
(Error_Node
) then
1738 if Nkind
(N
) in N_Subexpr
1739 and then Is_Static_Expression
(N
)
1745 end Collect_Identifiers
;
1747 ---------------------
1748 -- Get_Function_Id --
1749 ---------------------
1751 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
1752 Nam
: constant Node_Id
:= Name
(Call
);
1756 if Nkind
(Nam
) = N_Explicit_Dereference
then
1758 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
1760 elsif Nkind
(Nam
) = N_Selected_Component
then
1761 Id
:= Entity
(Selector_Name
(Nam
));
1763 elsif Nkind
(Nam
) = N_Indexed_Component
then
1764 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1771 end Get_Function_Id
;
1773 ---------------------------
1774 -- Preanalyze_Expression --
1775 ---------------------------
1777 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
1778 Status
: constant Boolean := Get_Ignore_Errors
;
1780 Set_Ignore_Errors
(True);
1782 Set_Ignore_Errors
(Status
);
1783 end Preanalyze_Without_Errors
;
1785 -- Start of processing for Check_Function_Writable_Actuals
1788 -- The check only applies to Ada 2012 code, and only to constructs that
1789 -- have multiple constituents whose order of evaluation is not specified
1792 if Ada_Version
< Ada_2012
1793 or else (not (Nkind
(N
) in N_Op
)
1794 and then not (Nkind
(N
) in N_Membership_Test
)
1795 and then not Nkind_In
(N
, N_Range
,
1797 N_Extension_Aggregate
,
1798 N_Full_Type_Declaration
,
1800 N_Procedure_Call_Statement
,
1801 N_Entry_Call_Statement
))
1802 or else (Nkind
(N
) = N_Full_Type_Declaration
1803 and then not Is_Record_Type
(Defining_Identifier
(N
)))
1805 -- In addition, this check only applies to source code, not to code
1806 -- generated by constraint checks.
1808 or else not Comes_From_Source
(N
)
1813 -- If a construct C has two or more direct constituents that are names
1814 -- or expressions whose evaluation may occur in an arbitrary order, at
1815 -- least one of which contains a function call with an in out or out
1816 -- parameter, then the construct is legal only if: for each name N that
1817 -- is passed as a parameter of mode in out or out to some inner function
1818 -- call C2 (not including the construct C itself), there is no other
1819 -- name anywhere within a direct constituent of the construct C other
1820 -- than the one containing C2, that is known to refer to the same
1821 -- object (RM 6.4.1(6.17/3)).
1825 Collect_Identifiers
(Low_Bound
(N
));
1826 Collect_Identifiers
(High_Bound
(N
));
1828 when N_Op | N_Membership_Test
=>
1832 Collect_Identifiers
(Left_Opnd
(N
));
1834 if Present
(Right_Opnd
(N
)) then
1835 Collect_Identifiers
(Right_Opnd
(N
));
1838 if Nkind_In
(N
, N_In
, N_Not_In
)
1839 and then Present
(Alternatives
(N
))
1841 Expr
:= First
(Alternatives
(N
));
1842 while Present
(Expr
) loop
1843 Collect_Identifiers
(Expr
);
1850 when N_Full_Type_Declaration
=>
1852 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
1853 -- Return the record part of this record type definition
1855 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
1856 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
1858 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
1859 return Record_Extension_Part
(Type_Def
);
1863 end Get_Record_Part
;
1866 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
1867 Rec
: Node_Id
:= Get_Record_Part
(N
);
1870 -- No need to perform any analysis if the record has no
1873 if No
(Rec
) or else No
(Component_List
(Rec
)) then
1877 -- Collect the identifiers starting from the deepest
1878 -- derivation. Done to report the error in the deepest
1882 if Present
(Component_List
(Rec
)) then
1883 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
1884 while Present
(Comp
) loop
1885 if Nkind
(Comp
) = N_Component_Declaration
1886 and then Present
(Expression
(Comp
))
1888 Collect_Identifiers
(Expression
(Comp
));
1895 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
1896 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
1899 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
1900 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
1904 when N_Subprogram_Call |
1905 N_Entry_Call_Statement
=>
1907 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
1912 Formal
:= First_Formal
(Id
);
1913 Actual
:= First_Actual
(N
);
1914 while Present
(Actual
) and then Present
(Formal
) loop
1915 if Ekind_In
(Formal
, E_Out_Parameter
,
1918 Collect_Identifiers
(Actual
);
1921 Next_Formal
(Formal
);
1922 Next_Actual
(Actual
);
1927 N_Extension_Aggregate
=>
1931 Comp_Expr
: Node_Id
;
1934 -- Handle the N_Others_Choice of array aggregates with static
1935 -- bounds. There is no need to perform this analysis in
1936 -- aggregates without static bounds since we cannot evaluate
1937 -- if the N_Others_Choice covers several elements. There is
1938 -- no need to handle the N_Others choice of record aggregates
1939 -- since at this stage it has been already expanded by
1940 -- Resolve_Record_Aggregate.
1942 if Is_Array_Type
(Etype
(N
))
1943 and then Nkind
(N
) = N_Aggregate
1944 and then Present
(Aggregate_Bounds
(N
))
1945 and then Compile_Time_Known_Bounds
(Etype
(N
))
1946 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
1947 > Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
1950 Count_Components
: Uint
:= Uint_0
;
1951 Num_Components
: Uint
;
1952 Others_Assoc
: Node_Id
;
1953 Others_Choice
: Node_Id
:= Empty
;
1954 Others_Box_Present
: Boolean := False;
1957 -- Count positional associations
1959 if Present
(Expressions
(N
)) then
1960 Comp_Expr
:= First
(Expressions
(N
));
1961 while Present
(Comp_Expr
) loop
1962 Count_Components
:= Count_Components
+ 1;
1967 -- Count the rest of elements and locate the N_Others
1970 Assoc
:= First
(Component_Associations
(N
));
1971 while Present
(Assoc
) loop
1972 Choice
:= First
(Choices
(Assoc
));
1973 while Present
(Choice
) loop
1974 if Nkind
(Choice
) = N_Others_Choice
then
1975 Others_Assoc
:= Assoc
;
1976 Others_Choice
:= Choice
;
1977 Others_Box_Present
:= Box_Present
(Assoc
);
1979 -- Count several components
1981 elsif Nkind_In
(Choice
, N_Range
,
1982 N_Subtype_Indication
)
1983 or else (Is_Entity_Name
(Choice
)
1984 and then Is_Type
(Entity
(Choice
)))
1989 Get_Index_Bounds
(Choice
, L
, H
);
1991 (Compile_Time_Known_Value
(L
)
1992 and then Compile_Time_Known_Value
(H
));
1995 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
1998 -- Count single component. No other case available
1999 -- since we are handling an aggregate with static
2003 pragma Assert
(Is_Static_Expression
(Choice
)
2004 or else Nkind
(Choice
) = N_Identifier
2005 or else Nkind
(Choice
) = N_Integer_Literal
);
2007 Count_Components
:= Count_Components
+ 1;
2017 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2018 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2020 pragma Assert
(Count_Components
<= Num_Components
);
2022 -- Handle the N_Others choice if it covers several
2025 if Present
(Others_Choice
)
2026 and then (Num_Components
- Count_Components
) > 1
2028 if not Others_Box_Present
then
2030 -- At this stage, if expansion is active, the
2031 -- expression of the others choice has not been
2032 -- analyzed. Hence we generate a duplicate and
2033 -- we analyze it silently to have available the
2034 -- minimum decoration required to collect the
2037 if not Expander_Active
then
2038 Comp_Expr
:= Expression
(Others_Assoc
);
2041 New_Copy_Tree
(Expression
(Others_Assoc
));
2042 Preanalyze_Without_Errors
(Comp_Expr
);
2045 Collect_Identifiers
(Comp_Expr
);
2047 if Writable_Actuals_List
/= No_Elist
then
2049 -- As suggested by Robert, at current stage we
2050 -- report occurrences of this case as warnings.
2053 ("writable function parameter may affect "
2054 & "value in other component because order "
2055 & "of evaluation is unspecified?",
2056 Node
(First_Elmt
(Writable_Actuals_List
)));
2063 -- Handle ancestor part of extension aggregates
2065 if Nkind
(N
) = N_Extension_Aggregate
then
2066 Collect_Identifiers
(Ancestor_Part
(N
));
2069 -- Handle positional associations
2071 if Present
(Expressions
(N
)) then
2072 Comp_Expr
:= First
(Expressions
(N
));
2073 while Present
(Comp_Expr
) loop
2074 if not Is_Static_Expression
(Comp_Expr
) then
2075 Collect_Identifiers
(Comp_Expr
);
2082 -- Handle discrete associations
2084 if Present
(Component_Associations
(N
)) then
2085 Assoc
:= First
(Component_Associations
(N
));
2086 while Present
(Assoc
) loop
2088 if not Box_Present
(Assoc
) then
2089 Choice
:= First
(Choices
(Assoc
));
2090 while Present
(Choice
) loop
2092 -- For now we skip discriminants since it requires
2093 -- performing the analysis in two phases: first one
2094 -- analyzing discriminants and second one analyzing
2095 -- the rest of components since discriminants are
2096 -- evaluated prior to components: too much extra
2097 -- work to detect a corner case???
2099 if Nkind
(Choice
) in N_Has_Entity
2100 and then Present
(Entity
(Choice
))
2101 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2105 elsif Box_Present
(Assoc
) then
2109 if not Analyzed
(Expression
(Assoc
)) then
2111 New_Copy_Tree
(Expression
(Assoc
));
2112 Set_Parent
(Comp_Expr
, Parent
(N
));
2113 Preanalyze_Without_Errors
(Comp_Expr
);
2115 Comp_Expr
:= Expression
(Assoc
);
2118 Collect_Identifiers
(Comp_Expr
);
2134 -- No further action needed if we already reported an error
2136 if Present
(Error_Node
) then
2140 -- Check if some writable argument of a function is referenced
2142 if Writable_Actuals_List
/= No_Elist
2143 and then Identifiers_List
/= No_Elist
2150 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2151 while Present
(Elmt_1
) loop
2152 Elmt_2
:= First_Elmt
(Identifiers_List
);
2153 while Present
(Elmt_2
) loop
2154 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2155 case Nkind
(Parent
(Node
(Elmt_2
))) is
2157 N_Component_Association |
2158 N_Component_Declaration
=>
2160 ("value may be affected by call in other "
2161 & "component because they are evaluated "
2162 & "in unspecified order",
2165 when N_In | N_Not_In
=>
2167 ("value may be affected by call in other "
2168 & "alternative because they are evaluated "
2169 & "in unspecified order",
2174 ("value of actual may be affected by call in "
2175 & "other actual because they are evaluated "
2176 & "in unspecified order",
2188 end Check_Function_Writable_Actuals
;
2190 --------------------------------
2191 -- Check_Implicit_Dereference --
2192 --------------------------------
2194 procedure Check_Implicit_Dereference
(Nam
: Node_Id
; Typ
: Entity_Id
) is
2199 if Ada_Version
< Ada_2012
2200 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2204 elsif not Comes_From_Source
(Nam
) then
2207 elsif Is_Entity_Name
(Nam
)
2208 and then Is_Type
(Entity
(Nam
))
2213 Disc
:= First_Discriminant
(Typ
);
2214 while Present
(Disc
) loop
2215 if Has_Implicit_Dereference
(Disc
) then
2216 Desig
:= Designated_Type
(Etype
(Disc
));
2217 Add_One_Interp
(Nam
, Disc
, Desig
);
2221 Next_Discriminant
(Disc
);
2224 end Check_Implicit_Dereference
;
2226 ----------------------------------
2227 -- Check_Internal_Protected_Use --
2228 ----------------------------------
2230 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2236 while Present
(S
) loop
2237 if S
= Standard_Standard
then
2240 elsif Ekind
(S
) = E_Function
2241 and then Ekind
(Scope
(S
)) = E_Protected_Type
2250 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2252 -- An indirect function call (e.g. a callback within a protected
2253 -- function body) is not statically illegal. If the access type is
2254 -- anonymous and is the type of an access parameter, the scope of Nam
2255 -- will be the protected type, but it is not a protected operation.
2257 if Ekind
(Nam
) = E_Subprogram_Type
2259 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2263 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2265 ("within protected function cannot use protected "
2266 & "procedure in renaming or as generic actual", N
);
2268 elsif Nkind
(N
) = N_Attribute_Reference
then
2270 ("within protected function cannot take access of "
2271 & " protected procedure", N
);
2275 ("within protected function, protected object is constant", N
);
2277 ("\cannot call operation that may modify it", N
);
2280 end Check_Internal_Protected_Use
;
2282 ---------------------------------------
2283 -- Check_Later_Vs_Basic_Declarations --
2284 ---------------------------------------
2286 procedure Check_Later_Vs_Basic_Declarations
2288 During_Parsing
: Boolean)
2290 Body_Sloc
: Source_Ptr
;
2293 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2294 -- Return whether Decl is considered as a declarative item.
2295 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2296 -- When During_Parsing is False, the semantics of SPARK is followed.
2298 -------------------------------
2299 -- Is_Later_Declarative_Item --
2300 -------------------------------
2302 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2304 if Nkind
(Decl
) in N_Later_Decl_Item
then
2307 elsif Nkind
(Decl
) = N_Pragma
then
2310 elsif During_Parsing
then
2313 -- In SPARK, a package declaration is not considered as a later
2314 -- declarative item.
2316 elsif Nkind
(Decl
) = N_Package_Declaration
then
2319 -- In SPARK, a renaming is considered as a later declarative item
2321 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2327 end Is_Later_Declarative_Item
;
2329 -- Start of Check_Later_Vs_Basic_Declarations
2332 Decl
:= First
(Decls
);
2334 -- Loop through sequence of basic declarative items
2336 Outer
: while Present
(Decl
) loop
2337 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2338 and then Nkind
(Decl
) not in N_Body_Stub
2342 -- Once a body is encountered, we only allow later declarative
2343 -- items. The inner loop checks the rest of the list.
2346 Body_Sloc
:= Sloc
(Decl
);
2348 Inner
: while Present
(Decl
) loop
2349 if not Is_Later_Declarative_Item
(Decl
) then
2350 if During_Parsing
then
2351 if Ada_Version
= Ada_83
then
2352 Error_Msg_Sloc
:= Body_Sloc
;
2354 ("(Ada 83) decl cannot appear after body#", Decl
);
2357 Error_Msg_Sloc
:= Body_Sloc
;
2358 Check_SPARK_Restriction
2359 ("decl cannot appear after body#", Decl
);
2367 end Check_Later_Vs_Basic_Declarations
;
2369 -------------------------
2370 -- Check_Nested_Access --
2371 -------------------------
2373 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2374 Scop
: constant Entity_Id
:= Current_Scope
;
2375 Current_Subp
: Entity_Id
;
2376 Enclosing
: Entity_Id
;
2379 -- Currently only enabled for VM back-ends for efficiency, should we
2380 -- enable it more systematically ???
2382 -- Check for Is_Imported needs commenting below ???
2384 if VM_Target
/= No_VM
2385 and then (Ekind
(Ent
) = E_Variable
2387 Ekind
(Ent
) = E_Constant
2389 Ekind
(Ent
) = E_Loop_Parameter
)
2390 and then Scope
(Ent
) /= Empty
2391 and then not Is_Library_Level_Entity
(Ent
)
2392 and then not Is_Imported
(Ent
)
2394 if Is_Subprogram
(Scop
)
2395 or else Is_Generic_Subprogram
(Scop
)
2396 or else Is_Entry
(Scop
)
2398 Current_Subp
:= Scop
;
2400 Current_Subp
:= Current_Subprogram
;
2403 Enclosing
:= Enclosing_Subprogram
(Ent
);
2405 if Enclosing
/= Empty
2406 and then Enclosing
/= Current_Subp
2408 Set_Has_Up_Level_Access
(Ent
, True);
2411 end Check_Nested_Access
;
2413 ---------------------------
2414 -- Check_No_Hidden_State --
2415 ---------------------------
2417 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2418 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2419 -- Determine whether the entity of a package denoted by Pkg has a null
2422 -----------------------------
2423 -- Has_Null_Abstract_State --
2424 -----------------------------
2426 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2427 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2430 -- Check first available state of related package. A null abstract
2431 -- state always appears as the sole element of the state list.
2435 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2436 end Has_Null_Abstract_State
;
2440 Context
: Entity_Id
:= Empty
;
2441 Not_Visible
: Boolean := False;
2444 -- Start of processing for Check_No_Hidden_State
2447 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2449 -- Find the proper context where the object or state appears
2452 while Present
(Scop
) loop
2455 -- Keep track of the context's visibility
2457 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2459 -- Prevent the search from going too far
2461 if Context
= Standard_Standard
then
2464 -- Objects and states that appear immediately within a subprogram or
2465 -- inside a construct nested within a subprogram do not introduce a
2466 -- hidden state. They behave as local variable declarations.
2468 elsif Is_Subprogram
(Context
) then
2471 -- When examining a package body, use the entity of the spec as it
2472 -- carries the abstract state declarations.
2474 elsif Ekind
(Context
) = E_Package_Body
then
2475 Context
:= Spec_Entity
(Context
);
2478 -- Stop the traversal when a package subject to a null abstract state
2481 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2482 and then Has_Null_Abstract_State
(Context
)
2487 Scop
:= Scope
(Scop
);
2490 -- At this point we know that there is at least one package with a null
2491 -- abstract state in visibility. Emit an error message unconditionally
2492 -- if the entity being processed is a state because the placement of the
2493 -- related package is irrelevant. This is not the case for objects as
2494 -- the intermediate context matters.
2496 if Present
(Context
)
2497 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
2499 Error_Msg_N
("cannot introduce hidden state &", Id
);
2500 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
2502 end Check_No_Hidden_State
;
2504 ------------------------------------------
2505 -- Check_Potentially_Blocking_Operation --
2506 ------------------------------------------
2508 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2512 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2513 -- When pragma Detect_Blocking is active, the run time will raise
2514 -- Program_Error. Here we only issue a warning, since we generally
2515 -- support the use of potentially blocking operations in the absence
2518 -- Indirect blocking through a subprogram call cannot be diagnosed
2519 -- statically without interprocedural analysis, so we do not attempt
2522 S
:= Scope
(Current_Scope
);
2523 while Present
(S
) and then S
/= Standard_Standard
loop
2524 if Is_Protected_Type
(S
) then
2526 ("potentially blocking operation in protected operation??", N
);
2532 end Check_Potentially_Blocking_Operation
;
2534 ---------------------------------
2535 -- Check_Result_And_Post_State --
2536 ---------------------------------
2538 procedure Check_Result_And_Post_State
2540 Result_Seen
: in out Boolean)
2542 procedure Check_Expression
(Expr
: Node_Id
);
2543 -- Perform the 'Result and post-state checks on a given expression
2545 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
2546 -- Attempt to find attribute 'Result in a subtree denoted by N
2548 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
2549 -- Determine whether source node N denotes "True" or "False"
2551 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
2552 -- Determine whether a subtree denoted by N mentions any construct that
2553 -- denotes a post-state.
2555 procedure Check_Function_Result
is
2556 new Traverse_Proc
(Is_Function_Result
);
2558 ----------------------
2559 -- Check_Expression --
2560 ----------------------
2562 procedure Check_Expression
(Expr
: Node_Id
) is
2564 if not Is_Trivial_Boolean
(Expr
) then
2565 Check_Function_Result
(Expr
);
2567 if not Mentions_Post_State
(Expr
) then
2568 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
2570 ("contract case refers only to pre-state?T?", Expr
);
2572 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
2574 ("refined postcondition refers only to pre-state?T?",
2579 ("postcondition refers only to pre-state?T?", Prag
);
2583 end Check_Expression
;
2585 ------------------------
2586 -- Is_Function_Result --
2587 ------------------------
2589 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
2591 if Is_Attribute_Result
(N
) then
2592 Result_Seen
:= True;
2595 -- Continue the traversal
2600 end Is_Function_Result
;
2602 ------------------------
2603 -- Is_Trivial_Boolean --
2604 ------------------------
2606 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
2609 Comes_From_Source
(N
)
2610 and then Is_Entity_Name
(N
)
2611 and then (Entity
(N
) = Standard_True
2612 or else Entity
(N
) = Standard_False
);
2613 end Is_Trivial_Boolean
;
2615 -------------------------
2616 -- Mentions_Post_State --
2617 -------------------------
2619 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
2620 Post_State_Seen
: Boolean := False;
2622 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
2623 -- Attempt to find a construct that denotes a post-state. If this is
2624 -- the case, set flag Post_State_Seen.
2630 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
2634 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
2635 Post_State_Seen
:= True;
2638 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
2641 -- The entity may be modifiable through an implicit dereference
2644 or else Ekind
(Ent
) in Assignable_Kind
2645 or else (Is_Access_Type
(Etype
(Ent
))
2646 and then Nkind
(Parent
(N
)) = N_Selected_Component
)
2648 Post_State_Seen
:= True;
2652 elsif Nkind
(N
) = N_Attribute_Reference
then
2653 if Attribute_Name
(N
) = Name_Old
then
2656 elsif Attribute_Name
(N
) = Name_Result
then
2657 Post_State_Seen
:= True;
2665 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
2667 -- Start of processing for Mentions_Post_State
2670 Find_Post_State
(N
);
2672 return Post_State_Seen
;
2673 end Mentions_Post_State
;
2677 Expr
: constant Node_Id
:=
2678 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
2679 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
2682 -- Start of processing for Check_Result_And_Post_State
2685 -- Examine all consequences
2687 if Nam
= Name_Contract_Cases
then
2688 CCase
:= First
(Component_Associations
(Expr
));
2689 while Present
(CCase
) loop
2690 Check_Expression
(Expression
(CCase
));
2695 -- Examine the expression of a postcondition
2697 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
, Name_Refined_Post
));
2698 Check_Expression
(Expr
);
2700 end Check_Result_And_Post_State
;
2702 ------------------------------
2703 -- Check_Unprotected_Access --
2704 ------------------------------
2706 procedure Check_Unprotected_Access
2710 Cont_Encl_Typ
: Entity_Id
;
2711 Pref_Encl_Typ
: Entity_Id
;
2713 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
2714 -- Check whether Obj is a private component of a protected object.
2715 -- Return the protected type where the component resides, Empty
2718 function Is_Public_Operation
return Boolean;
2719 -- Verify that the enclosing operation is callable from outside the
2720 -- protected object, to minimize false positives.
2722 ------------------------------
2723 -- Enclosing_Protected_Type --
2724 ------------------------------
2726 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
2728 if Is_Entity_Name
(Obj
) then
2730 Ent
: Entity_Id
:= Entity
(Obj
);
2733 -- The object can be a renaming of a private component, use
2734 -- the original record component.
2736 if Is_Prival
(Ent
) then
2737 Ent
:= Prival_Link
(Ent
);
2740 if Is_Protected_Type
(Scope
(Ent
)) then
2746 -- For indexed and selected components, recursively check the prefix
2748 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
2749 return Enclosing_Protected_Type
(Prefix
(Obj
));
2751 -- The object does not denote a protected component
2756 end Enclosing_Protected_Type
;
2758 -------------------------
2759 -- Is_Public_Operation --
2760 -------------------------
2762 function Is_Public_Operation
return Boolean is
2769 and then S
/= Pref_Encl_Typ
2771 if Scope
(S
) = Pref_Encl_Typ
then
2772 E
:= First_Entity
(Pref_Encl_Typ
);
2774 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
2787 end Is_Public_Operation
;
2789 -- Start of processing for Check_Unprotected_Access
2792 if Nkind
(Expr
) = N_Attribute_Reference
2793 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
2795 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
2796 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
2798 -- Check whether we are trying to export a protected component to a
2799 -- context with an equal or lower access level.
2801 if Present
(Pref_Encl_Typ
)
2802 and then No
(Cont_Encl_Typ
)
2803 and then Is_Public_Operation
2804 and then Scope_Depth
(Pref_Encl_Typ
) >=
2805 Object_Access_Level
(Context
)
2808 ("??possible unprotected access to protected data", Expr
);
2811 end Check_Unprotected_Access
;
2817 procedure Check_VMS
(Construct
: Node_Id
) is
2819 if not OpenVMS_On_Target
then
2821 ("this construct is allowed only in Open'V'M'S", Construct
);
2825 ------------------------
2826 -- Collect_Interfaces --
2827 ------------------------
2829 procedure Collect_Interfaces
2831 Ifaces_List
: out Elist_Id
;
2832 Exclude_Parents
: Boolean := False;
2833 Use_Full_View
: Boolean := True)
2835 procedure Collect
(Typ
: Entity_Id
);
2836 -- Subsidiary subprogram used to traverse the whole list
2837 -- of directly and indirectly implemented interfaces
2843 procedure Collect
(Typ
: Entity_Id
) is
2844 Ancestor
: Entity_Id
;
2852 -- Handle private types
2855 and then Is_Private_Type
(Typ
)
2856 and then Present
(Full_View
(Typ
))
2858 Full_T
:= Full_View
(Typ
);
2861 -- Include the ancestor if we are generating the whole list of
2862 -- abstract interfaces.
2864 if Etype
(Full_T
) /= Typ
2866 -- Protect the frontend against wrong sources. For example:
2869 -- type A is tagged null record;
2870 -- type B is new A with private;
2871 -- type C is new A with private;
2873 -- type B is new C with null record;
2874 -- type C is new B with null record;
2877 and then Etype
(Full_T
) /= T
2879 Ancestor
:= Etype
(Full_T
);
2882 if Is_Interface
(Ancestor
)
2883 and then not Exclude_Parents
2885 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
2889 -- Traverse the graph of ancestor interfaces
2891 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
2892 Id
:= First
(Abstract_Interface_List
(Full_T
));
2893 while Present
(Id
) loop
2894 Iface
:= Etype
(Id
);
2896 -- Protect against wrong uses. For example:
2897 -- type I is interface;
2898 -- type O is tagged null record;
2899 -- type Wrong is new I and O with null record; -- ERROR
2901 if Is_Interface
(Iface
) then
2903 and then Etype
(T
) /= T
2904 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
2909 Append_Unique_Elmt
(Iface
, Ifaces_List
);
2918 -- Start of processing for Collect_Interfaces
2921 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
2922 Ifaces_List
:= New_Elmt_List
;
2924 end Collect_Interfaces
;
2926 ----------------------------------
2927 -- Collect_Interface_Components --
2928 ----------------------------------
2930 procedure Collect_Interface_Components
2931 (Tagged_Type
: Entity_Id
;
2932 Components_List
: out Elist_Id
)
2934 procedure Collect
(Typ
: Entity_Id
);
2935 -- Subsidiary subprogram used to climb to the parents
2941 procedure Collect
(Typ
: Entity_Id
) is
2942 Tag_Comp
: Entity_Id
;
2943 Parent_Typ
: Entity_Id
;
2946 -- Handle private types
2948 if Present
(Full_View
(Etype
(Typ
))) then
2949 Parent_Typ
:= Full_View
(Etype
(Typ
));
2951 Parent_Typ
:= Etype
(Typ
);
2954 if Parent_Typ
/= Typ
2956 -- Protect the frontend against wrong sources. For example:
2959 -- type A is tagged null record;
2960 -- type B is new A with private;
2961 -- type C is new A with private;
2963 -- type B is new C with null record;
2964 -- type C is new B with null record;
2967 and then Parent_Typ
/= Tagged_Type
2969 Collect
(Parent_Typ
);
2972 -- Collect the components containing tags of secondary dispatch
2975 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
2976 while Present
(Tag_Comp
) loop
2977 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
2978 Append_Elmt
(Tag_Comp
, Components_List
);
2980 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
2984 -- Start of processing for Collect_Interface_Components
2987 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
2988 and then Is_Tagged_Type
(Tagged_Type
));
2990 Components_List
:= New_Elmt_List
;
2991 Collect
(Tagged_Type
);
2992 end Collect_Interface_Components
;
2994 -----------------------------
2995 -- Collect_Interfaces_Info --
2996 -----------------------------
2998 procedure Collect_Interfaces_Info
3000 Ifaces_List
: out Elist_Id
;
3001 Components_List
: out Elist_Id
;
3002 Tags_List
: out Elist_Id
)
3004 Comps_List
: Elist_Id
;
3005 Comp_Elmt
: Elmt_Id
;
3006 Comp_Iface
: Entity_Id
;
3007 Iface_Elmt
: Elmt_Id
;
3010 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3011 -- Search for the secondary tag associated with the interface type
3012 -- Iface that is implemented by T.
3018 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3021 if not Is_CPP_Class
(T
) then
3022 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3024 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3028 and then Is_Tag
(Node
(ADT
))
3029 and then Related_Type
(Node
(ADT
)) /= Iface
3031 -- Skip secondary dispatch table referencing thunks to user
3032 -- defined primitives covered by this interface.
3034 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3037 -- Skip secondary dispatch tables of Ada types
3039 if not Is_CPP_Class
(T
) then
3041 -- Skip secondary dispatch table referencing thunks to
3042 -- predefined primitives.
3044 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3047 -- Skip secondary dispatch table referencing user-defined
3048 -- primitives covered by this interface.
3050 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3053 -- Skip secondary dispatch table referencing predefined
3056 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3061 pragma Assert
(Is_Tag
(Node
(ADT
)));
3065 -- Start of processing for Collect_Interfaces_Info
3068 Collect_Interfaces
(T
, Ifaces_List
);
3069 Collect_Interface_Components
(T
, Comps_List
);
3071 -- Search for the record component and tag associated with each
3072 -- interface type of T.
3074 Components_List
:= New_Elmt_List
;
3075 Tags_List
:= New_Elmt_List
;
3077 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3078 while Present
(Iface_Elmt
) loop
3079 Iface
:= Node
(Iface_Elmt
);
3081 -- Associate the primary tag component and the primary dispatch table
3082 -- with all the interfaces that are parents of T
3084 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3085 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3086 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3088 -- Otherwise search for the tag component and secondary dispatch
3092 Comp_Elmt
:= First_Elmt
(Comps_List
);
3093 while Present
(Comp_Elmt
) loop
3094 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3096 if Comp_Iface
= Iface
3097 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3099 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3100 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3104 Next_Elmt
(Comp_Elmt
);
3106 pragma Assert
(Present
(Comp_Elmt
));
3109 Next_Elmt
(Iface_Elmt
);
3111 end Collect_Interfaces_Info
;
3113 ---------------------
3114 -- Collect_Parents --
3115 ---------------------
3117 procedure Collect_Parents
3119 List
: out Elist_Id
;
3120 Use_Full_View
: Boolean := True)
3122 Current_Typ
: Entity_Id
:= T
;
3123 Parent_Typ
: Entity_Id
;
3126 List
:= New_Elmt_List
;
3128 -- No action if the if the type has no parents
3130 if T
= Etype
(T
) then
3135 Parent_Typ
:= Etype
(Current_Typ
);
3137 if Is_Private_Type
(Parent_Typ
)
3138 and then Present
(Full_View
(Parent_Typ
))
3139 and then Use_Full_View
3141 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3144 Append_Elmt
(Parent_Typ
, List
);
3146 exit when Parent_Typ
= Current_Typ
;
3147 Current_Typ
:= Parent_Typ
;
3149 end Collect_Parents
;
3151 ----------------------------------
3152 -- Collect_Primitive_Operations --
3153 ----------------------------------
3155 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3156 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3157 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3158 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3162 Is_Type_In_Pkg
: Boolean;
3163 Formal_Derived
: Boolean := False;
3166 function Match
(E
: Entity_Id
) return Boolean;
3167 -- True if E's base type is B_Type, or E is of an anonymous access type
3168 -- and the base type of its designated type is B_Type.
3174 function Match
(E
: Entity_Id
) return Boolean is
3175 Etyp
: Entity_Id
:= Etype
(E
);
3178 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
3179 Etyp
:= Designated_Type
(Etyp
);
3182 return Base_Type
(Etyp
) = B_Type
;
3185 -- Start of processing for Collect_Primitive_Operations
3188 -- For tagged types, the primitive operations are collected as they
3189 -- are declared, and held in an explicit list which is simply returned.
3191 if Is_Tagged_Type
(B_Type
) then
3192 return Primitive_Operations
(B_Type
);
3194 -- An untagged generic type that is a derived type inherits the
3195 -- primitive operations of its parent type. Other formal types only
3196 -- have predefined operators, which are not explicitly represented.
3198 elsif Is_Generic_Type
(B_Type
) then
3199 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
3200 and then Nkind
(Formal_Type_Definition
(B_Decl
))
3201 = N_Formal_Derived_Type_Definition
3203 Formal_Derived
:= True;
3205 return New_Elmt_List
;
3209 Op_List
:= New_Elmt_List
;
3211 if B_Scope
= Standard_Standard
then
3212 if B_Type
= Standard_String
then
3213 Append_Elmt
(Standard_Op_Concat
, Op_List
);
3215 elsif B_Type
= Standard_Wide_String
then
3216 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
3222 -- Locate the primitive subprograms of the type
3225 -- The primitive operations appear after the base type, except
3226 -- if the derivation happens within the private part of B_Scope
3227 -- and the type is a private type, in which case both the type
3228 -- and some primitive operations may appear before the base
3229 -- type, and the list of candidates starts after the type.
3231 if In_Open_Scopes
(B_Scope
)
3232 and then Scope
(T
) = B_Scope
3233 and then In_Private_Part
(B_Scope
)
3235 Id
:= Next_Entity
(T
);
3237 Id
:= Next_Entity
(B_Type
);
3240 -- Set flag if this is a type in a package spec
3243 Is_Package_Or_Generic_Package
(B_Scope
)
3245 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
3248 while Present
(Id
) loop
3250 -- Test whether the result type or any of the parameter types of
3251 -- each subprogram following the type match that type when the
3252 -- type is declared in a package spec, is a derived type, or the
3253 -- subprogram is marked as primitive. (The Is_Primitive test is
3254 -- needed to find primitives of nonderived types in declarative
3255 -- parts that happen to override the predefined "=" operator.)
3257 -- Note that generic formal subprograms are not considered to be
3258 -- primitive operations and thus are never inherited.
3260 if Is_Overloadable
(Id
)
3261 and then (Is_Type_In_Pkg
3262 or else Is_Derived_Type
(B_Type
)
3263 or else Is_Primitive
(Id
))
3264 and then Nkind
(Parent
(Parent
(Id
)))
3265 not in N_Formal_Subprogram_Declaration
3273 Formal
:= First_Formal
(Id
);
3274 while Present
(Formal
) loop
3275 if Match
(Formal
) then
3280 Next_Formal
(Formal
);
3284 -- For a formal derived type, the only primitives are the ones
3285 -- inherited from the parent type. Operations appearing in the
3286 -- package declaration are not primitive for it.
3289 and then (not Formal_Derived
3290 or else Present
(Alias
(Id
)))
3292 -- In the special case of an equality operator aliased to
3293 -- an overriding dispatching equality belonging to the same
3294 -- type, we don't include it in the list of primitives.
3295 -- This avoids inheriting multiple equality operators when
3296 -- deriving from untagged private types whose full type is
3297 -- tagged, which can otherwise cause ambiguities. Note that
3298 -- this should only happen for this kind of untagged parent
3299 -- type, since normally dispatching operations are inherited
3300 -- using the type's Primitive_Operations list.
3302 if Chars
(Id
) = Name_Op_Eq
3303 and then Is_Dispatching_Operation
(Id
)
3304 and then Present
(Alias
(Id
))
3305 and then Present
(Overridden_Operation
(Alias
(Id
)))
3306 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3307 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3311 -- Include the subprogram in the list of primitives
3314 Append_Elmt
(Id
, Op_List
);
3321 -- For a type declared in System, some of its operations may
3322 -- appear in the target-specific extension to System.
3325 and then B_Scope
= RTU_Entity
(System
)
3326 and then Present_System_Aux
3328 B_Scope
:= System_Aux_Id
;
3329 Id
:= First_Entity
(System_Aux_Id
);
3335 end Collect_Primitive_Operations
;
3337 -----------------------------------
3338 -- Compile_Time_Constraint_Error --
3339 -----------------------------------
3341 function Compile_Time_Constraint_Error
3344 Ent
: Entity_Id
:= Empty
;
3345 Loc
: Source_Ptr
:= No_Location
;
3346 Warn
: Boolean := False) return Node_Id
3348 Msgc
: String (1 .. Msg
'Length + 3);
3349 -- Copy of message, with room for possible ?? or << and ! at end
3359 -- If this is a warning, convert it into an error if we are in code
3360 -- subject to SPARK_Mode being set ON.
3362 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3364 -- A static constraint error in an instance body is not a fatal error.
3365 -- we choose to inhibit the message altogether, because there is no
3366 -- obvious node (for now) on which to post it. On the other hand the
3367 -- offending node must be replaced with a constraint_error in any case.
3369 -- No messages are generated if we already posted an error on this node
3371 if not Error_Posted
(N
) then
3372 if Loc
/= No_Location
then
3378 -- Copy message to Msgc, converting any ? in the message into
3379 -- < instead, so that we have an error in GNATprove mode.
3383 for J
in 1 .. Msgl
loop
3384 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
3387 Msgc
(J
) := Msg
(J
);
3391 -- Message is a warning, even in Ada 95 case
3393 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
3396 -- In Ada 83, all messages are warnings. In the private part and
3397 -- the body of an instance, constraint_checks are only warnings.
3398 -- We also make this a warning if the Warn parameter is set.
3401 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
3409 elsif In_Instance_Not_Visible
then
3416 -- Otherwise we have a real error message (Ada 95 static case)
3417 -- and we make this an unconditional message. Note that in the
3418 -- warning case we do not make the message unconditional, it seems
3419 -- quite reasonable to delete messages like this (about exceptions
3420 -- that will be raised) in dead code.
3428 -- Should we generate a warning? The answer is not quite yes. The
3429 -- very annoying exception occurs in the case of a short circuit
3430 -- operator where the left operand is static and decisive. Climb
3431 -- parents to see if that is the case we have here. Conditional
3432 -- expressions with decisive conditions are a similar situation.
3440 -- And then with False as left operand
3442 if Nkind
(P
) = N_And_Then
3443 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3444 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
3449 -- OR ELSE with True as left operand
3451 elsif Nkind
(P
) = N_Or_Else
3452 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3453 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
3460 elsif Nkind
(P
) = N_If_Expression
then
3462 Cond
: constant Node_Id
:= First
(Expressions
(P
));
3463 Texp
: constant Node_Id
:= Next
(Cond
);
3464 Fexp
: constant Node_Id
:= Next
(Texp
);
3467 if Compile_Time_Known_Value
(Cond
) then
3469 -- Condition is True and we are in the right operand
3471 if Is_True
(Expr_Value
(Cond
))
3472 and then OldP
= Fexp
3477 -- Condition is False and we are in the left operand
3479 elsif Is_False
(Expr_Value
(Cond
))
3480 and then OldP
= Texp
3488 -- Special case for component association in aggregates, where
3489 -- we want to keep climbing up to the parent aggregate.
3491 elsif Nkind
(P
) = N_Component_Association
3492 and then Nkind
(Parent
(P
)) = N_Aggregate
3496 -- Keep going if within subexpression
3499 exit when Nkind
(P
) not in N_Subexpr
;
3504 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3506 if Present
(Ent
) then
3507 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
3509 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
3514 -- Check whether the context is an Init_Proc
3516 if Inside_Init_Proc
then
3518 Conc_Typ
: constant Entity_Id
:=
3519 Corresponding_Concurrent_Type
3520 (Entity
(Parameter_Type
(First
3521 (Parameter_Specifications
3522 (Parent
(Current_Scope
))))));
3525 -- Don't complain if the corresponding concurrent type
3526 -- doesn't come from source (i.e. a single task/protected
3529 if Present
(Conc_Typ
)
3530 and then not Comes_From_Source
(Conc_Typ
)
3533 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3536 if GNATprove_Mode
then
3538 ("\& would have been raised for objects of this "
3539 & "type", N
, Standard_Constraint_Error
, Eloc
);
3542 ("\& will be raised for objects of this type??",
3543 N
, Standard_Constraint_Error
, Eloc
);
3549 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3553 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
3554 Set_Error_Posted
(N
);
3560 end Compile_Time_Constraint_Error
;
3562 -----------------------
3563 -- Conditional_Delay --
3564 -----------------------
3566 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
3568 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
3569 Set_Has_Delayed_Freeze
(New_Ent
);
3571 end Conditional_Delay
;
3573 ----------------------------
3574 -- Contains_Refined_State --
3575 ----------------------------
3577 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
3578 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
3579 -- Determine whether a dependency list mentions a state with a visible
3582 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
3583 -- Determine whether a global list mentions a state with a visible
3586 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
3587 -- Determine whether Item is a reference to an abstract state with a
3588 -- visible refinement.
3590 -----------------------------
3591 -- Has_State_In_Dependency --
3592 -----------------------------
3594 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
3599 -- A null dependency list does not mention any states
3601 if Nkind
(List
) = N_Null
then
3604 -- Dependency clauses appear as component associations of an
3607 elsif Nkind
(List
) = N_Aggregate
3608 and then Present
(Component_Associations
(List
))
3610 Clause
:= First
(Component_Associations
(List
));
3611 while Present
(Clause
) loop
3613 -- Inspect the outputs of a dependency clause
3615 Output
:= First
(Choices
(Clause
));
3616 while Present
(Output
) loop
3617 if Is_Refined_State
(Output
) then
3624 -- Inspect the outputs of a dependency clause
3626 if Is_Refined_State
(Expression
(Clause
)) then
3633 -- If we get here, then none of the dependency clauses mention a
3634 -- state with visible refinement.
3638 -- An illegal pragma managed to sneak in
3641 raise Program_Error
;
3643 end Has_State_In_Dependency
;
3645 -------------------------
3646 -- Has_State_In_Global --
3647 -------------------------
3649 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
3653 -- A null global list does not mention any states
3655 if Nkind
(List
) = N_Null
then
3658 -- Simple global list or moded global list declaration
3660 elsif Nkind
(List
) = N_Aggregate
then
3662 -- The declaration of a simple global list appear as a collection
3665 if Present
(Expressions
(List
)) then
3666 Item
:= First
(Expressions
(List
));
3667 while Present
(Item
) loop
3668 if Is_Refined_State
(Item
) then
3675 -- The declaration of a moded global list appears as a collection
3676 -- of component associations where individual choices denote
3680 Item
:= First
(Component_Associations
(List
));
3681 while Present
(Item
) loop
3682 if Has_State_In_Global
(Expression
(Item
)) then
3690 -- If we get here, then the simple/moded global list did not
3691 -- mention any states with a visible refinement.
3695 -- Single global item declaration
3697 elsif Is_Entity_Name
(List
) then
3698 return Is_Refined_State
(List
);
3700 -- An illegal pragma managed to sneak in
3703 raise Program_Error
;
3705 end Has_State_In_Global
;
3707 ----------------------
3708 -- Is_Refined_State --
3709 ----------------------
3711 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
3713 Item_Id
: Entity_Id
;
3716 if Nkind
(Item
) = N_Null
then
3719 -- States cannot be subject to attribute 'Result. This case arises
3720 -- in dependency relations.
3722 elsif Nkind
(Item
) = N_Attribute_Reference
3723 and then Attribute_Name
(Item
) = Name_Result
3727 -- Multiple items appear as an aggregate. This case arises in
3728 -- dependency relations.
3730 elsif Nkind
(Item
) = N_Aggregate
3731 and then Present
(Expressions
(Item
))
3733 Elmt
:= First
(Expressions
(Item
));
3734 while Present
(Elmt
) loop
3735 if Is_Refined_State
(Elmt
) then
3742 -- If we get here, then none of the inputs or outputs reference a
3743 -- state with visible refinement.
3750 Item_Id
:= Entity_Of
(Item
);
3754 and then Ekind
(Item_Id
) = E_Abstract_State
3755 and then Has_Visible_Refinement
(Item_Id
);
3757 end Is_Refined_State
;
3761 Arg
: constant Node_Id
:=
3762 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
3763 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3765 -- Start of processing for Contains_Refined_State
3768 if Nam
= Name_Depends
then
3769 return Has_State_In_Dependency
(Arg
);
3771 else pragma Assert
(Nam
= Name_Global
);
3772 return Has_State_In_Global
(Arg
);
3774 end Contains_Refined_State
;
3776 -------------------------
3777 -- Copy_Component_List --
3778 -------------------------
3780 function Copy_Component_List
3782 Loc
: Source_Ptr
) return List_Id
3785 Comps
: constant List_Id
:= New_List
;
3788 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
3789 while Present
(Comp
) loop
3790 if Comes_From_Source
(Comp
) then
3792 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
3795 Make_Component_Declaration
(Loc
,
3796 Defining_Identifier
=>
3797 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
3798 Component_Definition
=>
3800 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
3804 Next_Component
(Comp
);
3808 end Copy_Component_List
;
3810 -------------------------
3811 -- Copy_Parameter_List --
3812 -------------------------
3814 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
3815 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
3820 if No
(First_Formal
(Subp_Id
)) then
3824 Formal
:= First_Formal
(Subp_Id
);
3825 while Present
(Formal
) loop
3827 (Make_Parameter_Specification
(Loc
,
3828 Defining_Identifier
=>
3829 Make_Defining_Identifier
(Sloc
(Formal
),
3830 Chars
=> Chars
(Formal
)),
3831 In_Present
=> In_Present
(Parent
(Formal
)),
3832 Out_Present
=> Out_Present
(Parent
(Formal
)),
3834 New_Reference_To
(Etype
(Formal
), Loc
),
3836 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
3839 Next_Formal
(Formal
);
3844 end Copy_Parameter_List
;
3846 --------------------------------
3847 -- Corresponding_Generic_Type --
3848 --------------------------------
3850 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
3856 if not Is_Generic_Actual_Type
(T
) then
3859 -- If the actual is the actual of an enclosing instance, resolution
3860 -- was correct in the generic.
3862 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
3863 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
3865 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
3872 if Is_Wrapper_Package
(Inst
) then
3873 Inst
:= Related_Instance
(Inst
);
3878 (Specification
(Unit_Declaration_Node
(Inst
)));
3880 -- Generic actual has the same name as the corresponding formal
3882 Typ
:= First_Entity
(Gen
);
3883 while Present
(Typ
) loop
3884 if Chars
(Typ
) = Chars
(T
) then
3893 end Corresponding_Generic_Type
;
3895 --------------------
3896 -- Current_Entity --
3897 --------------------
3899 -- The currently visible definition for a given identifier is the
3900 -- one most chained at the start of the visibility chain, i.e. the
3901 -- one that is referenced by the Node_Id value of the name of the
3902 -- given identifier.
3904 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
3906 return Get_Name_Entity_Id
(Chars
(N
));
3909 -----------------------------
3910 -- Current_Entity_In_Scope --
3911 -----------------------------
3913 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
3915 CS
: constant Entity_Id
:= Current_Scope
;
3917 Transient_Case
: constant Boolean := Scope_Is_Transient
;
3920 E
:= Get_Name_Entity_Id
(Chars
(N
));
3922 and then Scope
(E
) /= CS
3923 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
3929 end Current_Entity_In_Scope
;
3935 function Current_Scope
return Entity_Id
is
3937 if Scope_Stack
.Last
= -1 then
3938 return Standard_Standard
;
3941 C
: constant Entity_Id
:=
3942 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
3947 return Standard_Standard
;
3953 ------------------------
3954 -- Current_Subprogram --
3955 ------------------------
3957 function Current_Subprogram
return Entity_Id
is
3958 Scop
: constant Entity_Id
:= Current_Scope
;
3960 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
3963 return Enclosing_Subprogram
(Scop
);
3965 end Current_Subprogram
;
3967 ----------------------------------
3968 -- Deepest_Type_Access_Level --
3969 ----------------------------------
3971 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
3973 if Ekind
(Typ
) = E_Anonymous_Access_Type
3974 and then not Is_Local_Anonymous_Access
(Typ
)
3975 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
3977 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
3981 Scope_Depth
(Enclosing_Dynamic_Scope
3982 (Defining_Identifier
3983 (Associated_Node_For_Itype
(Typ
))));
3985 -- For generic formal type, return Int'Last (infinite).
3986 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
3988 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
3989 return UI_From_Int
(Int
'Last);
3992 return Type_Access_Level
(Typ
);
3994 end Deepest_Type_Access_Level
;
3996 ----------------------------
3997 -- Default_Initialization --
3998 ----------------------------
4000 function Default_Initialization
4001 (Typ
: Entity_Id
) return Default_Initialization_Kind
4004 Init
: Default_Initialization_Kind
;
4006 FDI
: Boolean := False;
4007 NDI
: Boolean := False;
4008 -- Two flags used to designate whether a record type has at least one
4009 -- fully default initialized component and/or one not fully default
4010 -- initialized component.
4013 -- Access types are always fully default initialized
4015 if Is_Access_Type
(Typ
) then
4016 return Full_Default_Initialization
;
4018 -- An array type subject to aspect/pragma Default_Component_Value is
4019 -- fully default initialized. Otherwise its initialization status is
4020 -- that of its component type.
4022 elsif Is_Array_Type
(Typ
) then
4023 if Present
(Default_Aspect_Component_Value
(Base_Type
(Typ
))) then
4024 return Full_Default_Initialization
;
4026 return Default_Initialization
(Component_Type
(Typ
));
4029 -- The initialization status of a private type depends on its full view
4031 elsif Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
4032 return Default_Initialization
(Full_View
(Typ
));
4034 -- Record and protected types offer several initialization options
4035 -- depending on their components (if any).
4037 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
4038 Comp
:= First_Component
(Typ
);
4040 -- Inspect all components
4042 if Present
(Comp
) then
4043 while Present
(Comp
) loop
4045 -- Do not process internally generated components except for
4046 -- _parent which represents the ancestor portion of a derived
4049 if Comes_From_Source
(Comp
)
4050 or else Chars
(Comp
) = Name_uParent
4052 Init
:= Default_Initialization
(Base_Type
(Etype
(Comp
)));
4054 -- A component with mixed initialization renders the whole
4055 -- record/protected type mixed.
4057 if Init
= Mixed_Initialization
then
4058 return Mixed_Initialization
;
4060 -- The component is fully default initialized when its type
4061 -- is fully default initialized or when the component has an
4062 -- initialization expression. Note that this has precedence
4063 -- given that the component type may lack initialization.
4065 elsif Init
= Full_Default_Initialization
4066 or else Present
(Expression
(Parent
(Comp
)))
4070 -- Components with no possible initialization are ignored
4072 elsif Init
= No_Possible_Initialization
then
4075 -- The component has no full default initialization
4082 Next_Component
(Comp
);
4085 -- Detect a mixed case of initialization
4088 return Mixed_Initialization
;
4091 return Full_Default_Initialization
;
4094 return No_Default_Initialization
;
4096 -- The type either has no components or they are all internally
4100 return No_Possible_Initialization
;
4103 -- The record type is null, there is nothing to initialize
4106 return No_Possible_Initialization
;
4109 -- A scalar type subject to aspect/pragma Default_Value is fully default
4112 elsif Is_Scalar_Type
(Typ
)
4113 and then Present
(Default_Aspect_Value
(Base_Type
(Typ
)))
4115 return Full_Default_Initialization
;
4117 -- Task types are always fully default initialized
4119 elsif Is_Task_Type
(Typ
) then
4120 return Full_Default_Initialization
;
4123 -- The type has no full default initialization
4125 return No_Default_Initialization
;
4126 end Default_Initialization
;
4128 ---------------------
4129 -- Defining_Entity --
4130 ---------------------
4132 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4133 K
: constant Node_Kind
:= Nkind
(N
);
4134 Err
: Entity_Id
:= Empty
;
4139 N_Subprogram_Declaration |
4140 N_Abstract_Subprogram_Declaration |
4142 N_Package_Declaration |
4143 N_Subprogram_Renaming_Declaration |
4144 N_Subprogram_Body_Stub |
4145 N_Generic_Subprogram_Declaration |
4146 N_Generic_Package_Declaration |
4147 N_Formal_Subprogram_Declaration |
4148 N_Expression_Function
4150 return Defining_Entity
(Specification
(N
));
4153 N_Component_Declaration |
4154 N_Defining_Program_Unit_Name |
4155 N_Discriminant_Specification |
4157 N_Entry_Declaration |
4158 N_Entry_Index_Specification |
4159 N_Exception_Declaration |
4160 N_Exception_Renaming_Declaration |
4161 N_Formal_Object_Declaration |
4162 N_Formal_Package_Declaration |
4163 N_Formal_Type_Declaration |
4164 N_Full_Type_Declaration |
4165 N_Implicit_Label_Declaration |
4166 N_Incomplete_Type_Declaration |
4167 N_Loop_Parameter_Specification |
4168 N_Number_Declaration |
4169 N_Object_Declaration |
4170 N_Object_Renaming_Declaration |
4171 N_Package_Body_Stub |
4172 N_Parameter_Specification |
4173 N_Private_Extension_Declaration |
4174 N_Private_Type_Declaration |
4176 N_Protected_Body_Stub |
4177 N_Protected_Type_Declaration |
4178 N_Single_Protected_Declaration |
4179 N_Single_Task_Declaration |
4180 N_Subtype_Declaration |
4183 N_Task_Type_Declaration
4185 return Defining_Identifier
(N
);
4188 return Defining_Entity
(Proper_Body
(N
));
4191 N_Function_Instantiation |
4192 N_Function_Specification |
4193 N_Generic_Function_Renaming_Declaration |
4194 N_Generic_Package_Renaming_Declaration |
4195 N_Generic_Procedure_Renaming_Declaration |
4197 N_Package_Instantiation |
4198 N_Package_Renaming_Declaration |
4199 N_Package_Specification |
4200 N_Procedure_Instantiation |
4201 N_Procedure_Specification
4204 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
4207 if Nkind
(Nam
) in N_Entity
then
4210 -- For Error, make up a name and attach to declaration
4211 -- so we can continue semantic analysis
4213 elsif Nam
= Error
then
4214 Err
:= Make_Temporary
(Sloc
(N
), 'T');
4215 Set_Defining_Unit_Name
(N
, Err
);
4219 -- If not an entity, get defining identifier
4222 return Defining_Identifier
(Nam
);
4226 when N_Block_Statement
=>
4227 return Entity
(Identifier
(N
));
4230 raise Program_Error
;
4233 end Defining_Entity
;
4235 --------------------------
4236 -- Denotes_Discriminant --
4237 --------------------------
4239 function Denotes_Discriminant
4241 Check_Concurrent
: Boolean := False) return Boolean
4245 if not Is_Entity_Name
(N
)
4246 or else No
(Entity
(N
))
4253 -- If we are checking for a protected type, the discriminant may have
4254 -- been rewritten as the corresponding discriminal of the original type
4255 -- or of the corresponding concurrent record, depending on whether we
4256 -- are in the spec or body of the protected type.
4258 return Ekind
(E
) = E_Discriminant
4261 and then Ekind
(E
) = E_In_Parameter
4262 and then Present
(Discriminal_Link
(E
))
4264 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
4266 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
4268 end Denotes_Discriminant
;
4270 -------------------------
4271 -- Denotes_Same_Object --
4272 -------------------------
4274 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
4275 Obj1
: Node_Id
:= A1
;
4276 Obj2
: Node_Id
:= A2
;
4278 function Has_Prefix
(N
: Node_Id
) return Boolean;
4279 -- Return True if N has attribute Prefix
4281 function Is_Renaming
(N
: Node_Id
) return Boolean;
4282 -- Return true if N names a renaming entity
4284 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
4285 -- For renamings, return False if the prefix of any dereference within
4286 -- the renamed object_name is a variable, or any expression within the
4287 -- renamed object_name contains references to variables or calls on
4288 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4294 function Has_Prefix
(N
: Node_Id
) return Boolean is
4298 N_Attribute_Reference
,
4300 N_Explicit_Dereference
,
4301 N_Indexed_Component
,
4303 N_Selected_Component
,
4311 function Is_Renaming
(N
: Node_Id
) return Boolean is
4313 return Is_Entity_Name
(N
)
4314 and then Present
(Renamed_Entity
(Entity
(N
)));
4317 -----------------------
4318 -- Is_Valid_Renaming --
4319 -----------------------
4321 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
4323 function Check_Renaming
(N
: Node_Id
) return Boolean;
4324 -- Recursive function used to traverse all the prefixes of N
4326 function Check_Renaming
(N
: Node_Id
) return Boolean is
4329 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
4334 if Nkind
(N
) = N_Indexed_Component
then
4339 Indx
:= First
(Expressions
(N
));
4340 while Present
(Indx
) loop
4341 if not Is_OK_Static_Expression
(Indx
) then
4350 if Has_Prefix
(N
) then
4352 P
: constant Node_Id
:= Prefix
(N
);
4355 if Nkind
(N
) = N_Explicit_Dereference
4356 and then Is_Variable
(P
)
4360 elsif Is_Entity_Name
(P
)
4361 and then Ekind
(Entity
(P
)) = E_Function
4365 elsif Nkind
(P
) = N_Function_Call
then
4369 -- Recursion to continue traversing the prefix of the
4370 -- renaming expression
4372 return Check_Renaming
(P
);
4379 -- Start of processing for Is_Valid_Renaming
4382 return Check_Renaming
(N
);
4383 end Is_Valid_Renaming
;
4385 -- Start of processing for Denotes_Same_Object
4388 -- Both names statically denote the same stand-alone object or parameter
4389 -- (RM 6.4.1(6.5/3))
4391 if Is_Entity_Name
(Obj1
)
4392 and then Is_Entity_Name
(Obj2
)
4393 and then Entity
(Obj1
) = Entity
(Obj2
)
4398 -- For renamings, the prefix of any dereference within the renamed
4399 -- object_name is not a variable, and any expression within the
4400 -- renamed object_name contains no references to variables nor
4401 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4403 if Is_Renaming
(Obj1
) then
4404 if Is_Valid_Renaming
(Obj1
) then
4405 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
4411 if Is_Renaming
(Obj2
) then
4412 if Is_Valid_Renaming
(Obj2
) then
4413 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
4419 -- No match if not same node kind (such cases are handled by
4420 -- Denotes_Same_Prefix)
4422 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
4425 -- After handling valid renamings, one of the two names statically
4426 -- denoted a renaming declaration whose renamed object_name is known
4427 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4429 elsif Is_Entity_Name
(Obj1
) then
4430 if Is_Entity_Name
(Obj2
) then
4431 return Entity
(Obj1
) = Entity
(Obj2
);
4436 -- Both names are selected_components, their prefixes are known to
4437 -- denote the same object, and their selector_names denote the same
4438 -- component (RM 6.4.1(6.6/3)
4440 elsif Nkind
(Obj1
) = N_Selected_Component
then
4441 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4443 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
4445 -- Both names are dereferences and the dereferenced names are known to
4446 -- denote the same object (RM 6.4.1(6.7/3))
4448 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
4449 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
4451 -- Both names are indexed_components, their prefixes are known to denote
4452 -- the same object, and each of the pairs of corresponding index values
4453 -- are either both static expressions with the same static value or both
4454 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4456 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4457 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4465 Indx1
:= First
(Expressions
(Obj1
));
4466 Indx2
:= First
(Expressions
(Obj2
));
4467 while Present
(Indx1
) loop
4469 -- Indexes must denote the same static value or same object
4471 if Is_OK_Static_Expression
(Indx1
) then
4472 if not Is_OK_Static_Expression
(Indx2
) then
4475 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4479 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4491 -- Both names are slices, their prefixes are known to denote the same
4492 -- object, and the two slices have statically matching index constraints
4493 -- (RM 6.4.1(6.9/3))
4495 elsif Nkind
(Obj1
) = N_Slice
4496 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4499 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4502 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4503 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4505 -- Check whether bounds are statically identical. There is no
4506 -- attempt to detect partial overlap of slices.
4508 return Denotes_Same_Object
(Lo1
, Lo2
)
4509 and then Denotes_Same_Object
(Hi1
, Hi2
);
4512 -- In the recursion, literals appear as indexes.
4514 elsif Nkind
(Obj1
) = N_Integer_Literal
4515 and then Nkind
(Obj2
) = N_Integer_Literal
4517 return Intval
(Obj1
) = Intval
(Obj2
);
4522 end Denotes_Same_Object
;
4524 -------------------------
4525 -- Denotes_Same_Prefix --
4526 -------------------------
4528 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
4531 if Is_Entity_Name
(A1
) then
4532 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
4533 and then not Is_Access_Type
(Etype
(A1
))
4535 return Denotes_Same_Object
(A1
, Prefix
(A2
))
4536 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
4541 elsif Is_Entity_Name
(A2
) then
4542 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
4544 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4546 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4549 Root1
, Root2
: Node_Id
;
4550 Depth1
, Depth2
: Int
:= 0;
4553 Root1
:= Prefix
(A1
);
4554 while not Is_Entity_Name
(Root1
) loop
4556 (Root1
, N_Selected_Component
, N_Indexed_Component
)
4560 Root1
:= Prefix
(Root1
);
4563 Depth1
:= Depth1
+ 1;
4566 Root2
:= Prefix
(A2
);
4567 while not Is_Entity_Name
(Root2
) loop
4569 (Root2
, N_Selected_Component
, N_Indexed_Component
)
4573 Root2
:= Prefix
(Root2
);
4576 Depth2
:= Depth2
+ 1;
4579 -- If both have the same depth and they do not denote the same
4580 -- object, they are disjoint and no warning is needed.
4582 if Depth1
= Depth2
then
4585 elsif Depth1
> Depth2
then
4586 Root1
:= Prefix
(A1
);
4587 for I
in 1 .. Depth1
- Depth2
- 1 loop
4588 Root1
:= Prefix
(Root1
);
4591 return Denotes_Same_Object
(Root1
, A2
);
4594 Root2
:= Prefix
(A2
);
4595 for I
in 1 .. Depth2
- Depth1
- 1 loop
4596 Root2
:= Prefix
(Root2
);
4599 return Denotes_Same_Object
(A1
, Root2
);
4606 end Denotes_Same_Prefix
;
4608 ----------------------
4609 -- Denotes_Variable --
4610 ----------------------
4612 function Denotes_Variable
(N
: Node_Id
) return Boolean is
4614 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
4615 end Denotes_Variable
;
4617 -----------------------------
4618 -- Depends_On_Discriminant --
4619 -----------------------------
4621 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
4626 Get_Index_Bounds
(N
, L
, H
);
4627 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
4628 end Depends_On_Discriminant
;
4630 -------------------------
4631 -- Designate_Same_Unit --
4632 -------------------------
4634 function Designate_Same_Unit
4636 Name2
: Node_Id
) return Boolean
4638 K1
: constant Node_Kind
:= Nkind
(Name1
);
4639 K2
: constant Node_Kind
:= Nkind
(Name2
);
4641 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
4642 -- Returns the parent unit name node of a defining program unit name
4643 -- or the prefix if N is a selected component or an expanded name.
4645 function Select_Node
(N
: Node_Id
) return Node_Id
;
4646 -- Returns the defining identifier node of a defining program unit
4647 -- name or the selector node if N is a selected component or an
4654 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
4656 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4668 function Select_Node
(N
: Node_Id
) return Node_Id
is
4670 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4671 return Defining_Identifier
(N
);
4674 return Selector_Name
(N
);
4678 -- Start of processing for Designate_Next_Unit
4681 if (K1
= N_Identifier
or else
4682 K1
= N_Defining_Identifier
)
4684 (K2
= N_Identifier
or else
4685 K2
= N_Defining_Identifier
)
4687 return Chars
(Name1
) = Chars
(Name2
);
4690 (K1
= N_Expanded_Name
or else
4691 K1
= N_Selected_Component
or else
4692 K1
= N_Defining_Program_Unit_Name
)
4694 (K2
= N_Expanded_Name
or else
4695 K2
= N_Selected_Component
or else
4696 K2
= N_Defining_Program_Unit_Name
)
4699 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
4701 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
4706 end Designate_Same_Unit
;
4708 ------------------------------------------
4709 -- function Dynamic_Accessibility_Level --
4710 ------------------------------------------
4712 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
4714 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
4716 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
4717 -- Construct an integer literal representing an accessibility level
4718 -- with its type set to Natural.
4720 ------------------------
4721 -- Make_Level_Literal --
4722 ------------------------
4724 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
4725 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
4727 Set_Etype
(Result
, Standard_Natural
);
4729 end Make_Level_Literal
;
4731 -- Start of processing for Dynamic_Accessibility_Level
4734 if Is_Entity_Name
(Expr
) then
4737 if Present
(Renamed_Object
(E
)) then
4738 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
4741 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
4742 if Present
(Extra_Accessibility
(E
)) then
4743 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
4748 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4750 case Nkind
(Expr
) is
4752 -- For access discriminant, the level of the enclosing object
4754 when N_Selected_Component
=>
4755 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
4756 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
4757 E_Anonymous_Access_Type
4759 return Make_Level_Literal
(Object_Access_Level
(Expr
));
4762 when N_Attribute_Reference
=>
4763 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
4765 -- For X'Access, the level of the prefix X
4767 when Attribute_Access
=>
4768 return Make_Level_Literal
4769 (Object_Access_Level
(Prefix
(Expr
)));
4771 -- Treat the unchecked attributes as library-level
4773 when Attribute_Unchecked_Access |
4774 Attribute_Unrestricted_Access
=>
4775 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
4777 -- No other access-valued attributes
4780 raise Program_Error
;
4785 -- Unimplemented: depends on context. As an actual parameter where
4786 -- formal type is anonymous, use
4787 -- Scope_Depth (Current_Scope) + 1.
4788 -- For other cases, see 3.10.2(14/3) and following. ???
4792 when N_Type_Conversion
=>
4793 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
4795 -- Handle type conversions introduced for a rename of an
4796 -- Ada 2012 stand-alone object of an anonymous access type.
4798 return Dynamic_Accessibility_Level
(Expression
(Expr
));
4805 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
4806 end Dynamic_Accessibility_Level
;
4808 -----------------------------------
4809 -- Effective_Extra_Accessibility --
4810 -----------------------------------
4812 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
4814 if Present
(Renamed_Object
(Id
))
4815 and then Is_Entity_Name
(Renamed_Object
(Id
))
4817 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
4819 return Extra_Accessibility
(Id
);
4821 end Effective_Extra_Accessibility
;
4823 -----------------------------
4824 -- Effective_Reads_Enabled --
4825 -----------------------------
4827 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
4829 if Ekind
(Id
) = E_Abstract_State
then
4830 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
4832 else pragma Assert
(Ekind
(Id
) = E_Variable
);
4833 return Present
(Get_Pragma
(Id
, Pragma_Effective_Reads
));
4835 end Effective_Reads_Enabled
;
4837 ------------------------------
4838 -- Effective_Writes_Enabled --
4839 ------------------------------
4841 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
4843 if Ekind
(Id
) = E_Abstract_State
then
4844 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
4846 else pragma Assert
(Ekind
(Id
) = E_Variable
);
4847 return Present
(Get_Pragma
(Id
, Pragma_Effective_Writes
));
4849 end Effective_Writes_Enabled
;
4851 ------------------------------
4852 -- Enclosing_Comp_Unit_Node --
4853 ------------------------------
4855 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
4856 Current_Node
: Node_Id
;
4860 while Present
(Current_Node
)
4861 and then Nkind
(Current_Node
) /= N_Compilation_Unit
4863 Current_Node
:= Parent
(Current_Node
);
4866 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
4869 return Current_Node
;
4871 end Enclosing_Comp_Unit_Node
;
4873 --------------------------
4874 -- Enclosing_CPP_Parent --
4875 --------------------------
4877 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
4878 Parent_Typ
: Entity_Id
:= Typ
;
4881 while not Is_CPP_Class
(Parent_Typ
)
4882 and then Etype
(Parent_Typ
) /= Parent_Typ
4884 Parent_Typ
:= Etype
(Parent_Typ
);
4886 if Is_Private_Type
(Parent_Typ
) then
4887 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4891 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
4893 end Enclosing_CPP_Parent
;
4895 ----------------------------
4896 -- Enclosing_Generic_Body --
4897 ----------------------------
4899 function Enclosing_Generic_Body
4900 (N
: Node_Id
) return Node_Id
4908 while Present
(P
) loop
4909 if Nkind
(P
) = N_Package_Body
4910 or else Nkind
(P
) = N_Subprogram_Body
4912 Spec
:= Corresponding_Spec
(P
);
4914 if Present
(Spec
) then
4915 Decl
:= Unit_Declaration_Node
(Spec
);
4917 if Nkind
(Decl
) = N_Generic_Package_Declaration
4918 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4929 end Enclosing_Generic_Body
;
4931 ----------------------------
4932 -- Enclosing_Generic_Unit --
4933 ----------------------------
4935 function Enclosing_Generic_Unit
4936 (N
: Node_Id
) return Node_Id
4944 while Present
(P
) loop
4945 if Nkind
(P
) = N_Generic_Package_Declaration
4946 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
4950 elsif Nkind
(P
) = N_Package_Body
4951 or else Nkind
(P
) = N_Subprogram_Body
4953 Spec
:= Corresponding_Spec
(P
);
4955 if Present
(Spec
) then
4956 Decl
:= Unit_Declaration_Node
(Spec
);
4958 if Nkind
(Decl
) = N_Generic_Package_Declaration
4959 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4970 end Enclosing_Generic_Unit
;
4972 -------------------------------
4973 -- Enclosing_Lib_Unit_Entity --
4974 -------------------------------
4976 function Enclosing_Lib_Unit_Entity
4977 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
4979 Unit_Entity
: Entity_Id
;
4982 -- Look for enclosing library unit entity by following scope links.
4983 -- Equivalent to, but faster than indexing through the scope stack.
4986 while (Present
(Scope
(Unit_Entity
))
4987 and then Scope
(Unit_Entity
) /= Standard_Standard
)
4988 and not Is_Child_Unit
(Unit_Entity
)
4990 Unit_Entity
:= Scope
(Unit_Entity
);
4994 end Enclosing_Lib_Unit_Entity
;
4996 -----------------------
4997 -- Enclosing_Package --
4998 -----------------------
5000 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
5001 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5004 if Dynamic_Scope
= Standard_Standard
then
5005 return Standard_Standard
;
5007 elsif Dynamic_Scope
= Empty
then
5010 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
5013 return Dynamic_Scope
;
5016 return Enclosing_Package
(Dynamic_Scope
);
5018 end Enclosing_Package
;
5020 --------------------------
5021 -- Enclosing_Subprogram --
5022 --------------------------
5024 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5025 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5028 if Dynamic_Scope
= Standard_Standard
then
5031 elsif Dynamic_Scope
= Empty
then
5034 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
5035 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
5037 elsif Ekind
(Dynamic_Scope
) = E_Block
5038 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
5040 return Enclosing_Subprogram
(Dynamic_Scope
);
5042 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
5043 return Get_Task_Body_Procedure
(Dynamic_Scope
);
5045 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
5046 and then Present
(Full_View
(Dynamic_Scope
))
5047 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
5049 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
5051 -- No body is generated if the protected operation is eliminated
5053 elsif Convention
(Dynamic_Scope
) = Convention_Protected
5054 and then not Is_Eliminated
(Dynamic_Scope
)
5055 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
5057 return Protected_Body_Subprogram
(Dynamic_Scope
);
5060 return Dynamic_Scope
;
5062 end Enclosing_Subprogram
;
5064 ------------------------
5065 -- Ensure_Freeze_Node --
5066 ------------------------
5068 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
5071 if No
(Freeze_Node
(E
)) then
5072 FN
:= Make_Freeze_Entity
(Sloc
(E
));
5073 Set_Has_Delayed_Freeze
(E
);
5074 Set_Freeze_Node
(E
, FN
);
5075 Set_Access_Types_To_Process
(FN
, No_Elist
);
5076 Set_TSS_Elist
(FN
, No_Elist
);
5079 end Ensure_Freeze_Node
;
5085 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5086 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5087 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5088 S
: constant Entity_Id
:= Current_Scope
;
5091 Generate_Definition
(Def_Id
);
5093 -- Add new name to current scope declarations. Check for duplicate
5094 -- declaration, which may or may not be a genuine error.
5098 -- Case of previous entity entered because of a missing declaration
5099 -- or else a bad subtype indication. Best is to use the new entity,
5100 -- and make the previous one invisible.
5102 if Etype
(E
) = Any_Type
then
5103 Set_Is_Immediately_Visible
(E
, False);
5105 -- Case of renaming declaration constructed for package instances.
5106 -- if there is an explicit declaration with the same identifier,
5107 -- the renaming is not immediately visible any longer, but remains
5108 -- visible through selected component notation.
5110 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
5111 and then not Comes_From_Source
(E
)
5113 Set_Is_Immediately_Visible
(E
, False);
5115 -- The new entity may be the package renaming, which has the same
5116 -- same name as a generic formal which has been seen already.
5118 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
5119 and then not Comes_From_Source
(Def_Id
)
5121 Set_Is_Immediately_Visible
(E
, False);
5123 -- For a fat pointer corresponding to a remote access to subprogram,
5124 -- we use the same identifier as the RAS type, so that the proper
5125 -- name appears in the stub. This type is only retrieved through
5126 -- the RAS type and never by visibility, and is not added to the
5127 -- visibility list (see below).
5129 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
5130 and then Present
(Corresponding_Remote_Type
(Def_Id
))
5134 -- Case of an implicit operation or derived literal. The new entity
5135 -- hides the implicit one, which is removed from all visibility,
5136 -- i.e. the entity list of its scope, and homonym chain of its name.
5138 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
5139 or else Is_Internal
(E
)
5143 Prev_Vis
: Entity_Id
;
5144 Decl
: constant Node_Id
:= Parent
(E
);
5147 -- If E is an implicit declaration, it cannot be the first
5148 -- entity in the scope.
5150 Prev
:= First_Entity
(Current_Scope
);
5151 while Present
(Prev
)
5152 and then Next_Entity
(Prev
) /= E
5159 -- If E is not on the entity chain of the current scope,
5160 -- it is an implicit declaration in the generic formal
5161 -- part of a generic subprogram. When analyzing the body,
5162 -- the generic formals are visible but not on the entity
5163 -- chain of the subprogram. The new entity will become
5164 -- the visible one in the body.
5167 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
5171 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5173 if No
(Next_Entity
(Prev
)) then
5174 Set_Last_Entity
(Current_Scope
, Prev
);
5177 if E
= Current_Entity
(E
) then
5181 Prev_Vis
:= Current_Entity
(E
);
5182 while Homonym
(Prev_Vis
) /= E
loop
5183 Prev_Vis
:= Homonym
(Prev_Vis
);
5187 if Present
(Prev_Vis
) then
5189 -- Skip E in the visibility chain
5191 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5194 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5199 -- This section of code could use a comment ???
5201 elsif Present
(Etype
(E
))
5202 and then Is_Concurrent_Type
(Etype
(E
))
5207 -- If the homograph is a protected component renaming, it should not
5208 -- be hiding the current entity. Such renamings are treated as weak
5211 elsif Is_Prival
(E
) then
5212 Set_Is_Immediately_Visible
(E
, False);
5214 -- In this case the current entity is a protected component renaming.
5215 -- Perform minimal decoration by setting the scope and return since
5216 -- the prival should not be hiding other visible entities.
5218 elsif Is_Prival
(Def_Id
) then
5219 Set_Scope
(Def_Id
, Current_Scope
);
5222 -- Analogous to privals, the discriminal generated for an entry index
5223 -- parameter acts as a weak declaration. Perform minimal decoration
5224 -- to avoid bogus errors.
5226 elsif Is_Discriminal
(Def_Id
)
5227 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
5229 Set_Scope
(Def_Id
, Current_Scope
);
5232 -- In the body or private part of an instance, a type extension may
5233 -- introduce a component with the same name as that of an actual. The
5234 -- legality rule is not enforced, but the semantics of the full type
5235 -- with two components of same name are not clear at this point???
5237 elsif In_Instance_Not_Visible
then
5240 -- When compiling a package body, some child units may have become
5241 -- visible. They cannot conflict with local entities that hide them.
5243 elsif Is_Child_Unit
(E
)
5244 and then In_Open_Scopes
(Scope
(E
))
5245 and then not Is_Immediately_Visible
(E
)
5249 -- Conversely, with front-end inlining we may compile the parent body
5250 -- first, and a child unit subsequently. The context is now the
5251 -- parent spec, and body entities are not visible.
5253 elsif Is_Child_Unit
(Def_Id
)
5254 and then Is_Package_Body_Entity
(E
)
5255 and then not In_Package_Body
(Current_Scope
)
5259 -- Case of genuine duplicate declaration
5262 Error_Msg_Sloc
:= Sloc
(E
);
5264 -- If the previous declaration is an incomplete type declaration
5265 -- this may be an attempt to complete it with a private type. The
5266 -- following avoids confusing cascaded errors.
5268 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
5269 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
5272 ("incomplete type cannot be completed with a private " &
5273 "declaration", Parent
(Def_Id
));
5274 Set_Is_Immediately_Visible
(E
, False);
5275 Set_Full_View
(E
, Def_Id
);
5277 -- An inherited component of a record conflicts with a new
5278 -- discriminant. The discriminant is inserted first in the scope,
5279 -- but the error should be posted on it, not on the component.
5281 elsif Ekind
(E
) = E_Discriminant
5282 and then Present
(Scope
(Def_Id
))
5283 and then Scope
(Def_Id
) /= Current_Scope
5285 Error_Msg_Sloc
:= Sloc
(Def_Id
);
5286 Error_Msg_N
("& conflicts with declaration#", E
);
5289 -- If the name of the unit appears in its own context clause, a
5290 -- dummy package with the name has already been created, and the
5291 -- error emitted. Try to continue quietly.
5293 elsif Error_Posted
(E
)
5294 and then Sloc
(E
) = No_Location
5295 and then Nkind
(Parent
(E
)) = N_Package_Specification
5296 and then Current_Scope
= Standard_Standard
5298 Set_Scope
(Def_Id
, Current_Scope
);
5302 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
5304 -- Avoid cascaded messages with duplicate components in
5307 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
5312 if Nkind
(Parent
(Parent
(Def_Id
))) =
5313 N_Generic_Subprogram_Declaration
5315 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
5317 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
5320 -- If entity is in standard, then we are in trouble, because it
5321 -- means that we have a library package with a duplicated name.
5322 -- That's hard to recover from, so abort.
5324 if S
= Standard_Standard
then
5325 raise Unrecoverable_Error
;
5327 -- Otherwise we continue with the declaration. Having two
5328 -- identical declarations should not cause us too much trouble.
5336 -- If we fall through, declaration is OK, at least OK enough to continue
5338 -- If Def_Id is a discriminant or a record component we are in the midst
5339 -- of inheriting components in a derived record definition. Preserve
5340 -- their Ekind and Etype.
5342 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
5345 -- If a type is already set, leave it alone (happens when a type
5346 -- declaration is reanalyzed following a call to the optimizer).
5348 elsif Present
(Etype
(Def_Id
)) then
5351 -- Otherwise, the kind E_Void insures that premature uses of the entity
5352 -- will be detected. Any_Type insures that no cascaded errors will occur
5355 Set_Ekind
(Def_Id
, E_Void
);
5356 Set_Etype
(Def_Id
, Any_Type
);
5359 -- Inherited discriminants and components in derived record types are
5360 -- immediately visible. Itypes are not.
5362 -- Unless the Itype is for a record type with a corresponding remote
5363 -- type (what is that about, it was not commented ???)
5365 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
5367 ((not Is_Record_Type
(Def_Id
)
5368 or else No
(Corresponding_Remote_Type
(Def_Id
)))
5369 and then not Is_Itype
(Def_Id
))
5371 Set_Is_Immediately_Visible
(Def_Id
);
5372 Set_Current_Entity
(Def_Id
);
5375 Set_Homonym
(Def_Id
, C
);
5376 Append_Entity
(Def_Id
, S
);
5377 Set_Public_Status
(Def_Id
);
5379 -- Declaring a homonym is not allowed in SPARK ...
5382 and then Restriction_Check_Required
(SPARK_05
)
5385 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
5386 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
5387 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
5390 -- ... unless the new declaration is in a subprogram, and the
5391 -- visible declaration is a variable declaration or a parameter
5392 -- specification outside that subprogram.
5394 if Present
(Enclosing_Subp
)
5395 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
5396 N_Parameter_Specification
)
5397 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
5401 -- ... or the new declaration is in a package, and the visible
5402 -- declaration occurs outside that package.
5404 elsif Present
(Enclosing_Pack
)
5405 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
5409 -- ... or the new declaration is a component declaration in a
5410 -- record type definition.
5412 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
5415 -- Don't issue error for non-source entities
5417 elsif Comes_From_Source
(Def_Id
)
5418 and then Comes_From_Source
(C
)
5420 Error_Msg_Sloc
:= Sloc
(C
);
5421 Check_SPARK_Restriction
5422 ("redeclaration of identifier &#", Def_Id
);
5427 -- Warn if new entity hides an old one
5429 if Warn_On_Hiding
and then Present
(C
)
5431 -- Don't warn for record components since they always have a well
5432 -- defined scope which does not confuse other uses. Note that in
5433 -- some cases, Ekind has not been set yet.
5435 and then Ekind
(C
) /= E_Component
5436 and then Ekind
(C
) /= E_Discriminant
5437 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
5438 and then Ekind
(Def_Id
) /= E_Component
5439 and then Ekind
(Def_Id
) /= E_Discriminant
5440 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
5442 -- Don't warn for one character variables. It is too common to use
5443 -- such variables as locals and will just cause too many false hits.
5445 and then Length_Of_Name
(Chars
(C
)) /= 1
5447 -- Don't warn for non-source entities
5449 and then Comes_From_Source
(C
)
5450 and then Comes_From_Source
(Def_Id
)
5452 -- Don't warn unless entity in question is in extended main source
5454 and then In_Extended_Main_Source_Unit
(Def_Id
)
5456 -- Finally, the hidden entity must be either immediately visible or
5457 -- use visible (i.e. from a used package).
5460 (Is_Immediately_Visible
(C
)
5462 Is_Potentially_Use_Visible
(C
))
5464 Error_Msg_Sloc
:= Sloc
(C
);
5465 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
5473 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
5479 if Is_Entity_Name
(N
) then
5482 -- Follow a possible chain of renamings to reach the root renamed
5485 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5486 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5487 Id
:= Entity
(Renamed_Object
(Id
));
5498 --------------------------
5499 -- Explain_Limited_Type --
5500 --------------------------
5502 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5506 -- For array, component type must be limited
5508 if Is_Array_Type
(T
) then
5509 Error_Msg_Node_2
:= T
;
5511 ("\component type& of type& is limited", N
, Component_Type
(T
));
5512 Explain_Limited_Type
(Component_Type
(T
), N
);
5514 elsif Is_Record_Type
(T
) then
5516 -- No need for extra messages if explicit limited record
5518 if Is_Limited_Record
(Base_Type
(T
)) then
5522 -- Otherwise find a limited component. Check only components that
5523 -- come from source, or inherited components that appear in the
5524 -- source of the ancestor.
5526 C
:= First_Component
(T
);
5527 while Present
(C
) loop
5528 if Is_Limited_Type
(Etype
(C
))
5530 (Comes_From_Source
(C
)
5532 (Present
(Original_Record_Component
(C
))
5534 Comes_From_Source
(Original_Record_Component
(C
))))
5536 Error_Msg_Node_2
:= T
;
5537 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
5538 Explain_Limited_Type
(Etype
(C
), N
);
5545 -- The type may be declared explicitly limited, even if no component
5546 -- of it is limited, in which case we fall out of the loop.
5549 end Explain_Limited_Type
;
5555 procedure Find_Actual
5557 Formal
: out Entity_Id
;
5560 Parnt
: constant Node_Id
:= Parent
(N
);
5564 if (Nkind
(Parnt
) = N_Indexed_Component
5566 Nkind
(Parnt
) = N_Selected_Component
)
5567 and then N
= Prefix
(Parnt
)
5569 Find_Actual
(Parnt
, Formal
, Call
);
5572 elsif Nkind
(Parnt
) = N_Parameter_Association
5573 and then N
= Explicit_Actual_Parameter
(Parnt
)
5575 Call
:= Parent
(Parnt
);
5577 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
5586 -- If we have a call to a subprogram look for the parameter. Note that
5587 -- we exclude overloaded calls, since we don't know enough to be sure
5588 -- of giving the right answer in this case.
5590 if Is_Entity_Name
(Name
(Call
))
5591 and then Present
(Entity
(Name
(Call
)))
5592 and then Is_Overloadable
(Entity
(Name
(Call
)))
5593 and then not Is_Overloaded
(Name
(Call
))
5595 -- Fall here if we are definitely a parameter
5597 Actual
:= First_Actual
(Call
);
5598 Formal
:= First_Formal
(Entity
(Name
(Call
)));
5599 while Present
(Formal
) and then Present
(Actual
) loop
5603 Actual
:= Next_Actual
(Actual
);
5604 Formal
:= Next_Formal
(Formal
);
5609 -- Fall through here if we did not find matching actual
5615 ---------------------------
5616 -- Find_Body_Discriminal --
5617 ---------------------------
5619 function Find_Body_Discriminal
5620 (Spec_Discriminant
: Entity_Id
) return Entity_Id
5626 -- If expansion is suppressed, then the scope can be the concurrent type
5627 -- itself rather than a corresponding concurrent record type.
5629 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
5630 Tsk
:= Scope
(Spec_Discriminant
);
5633 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
5635 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
5638 -- Find discriminant of original concurrent type, and use its current
5639 -- discriminal, which is the renaming within the task/protected body.
5641 Disc
:= First_Discriminant
(Tsk
);
5642 while Present
(Disc
) loop
5643 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
5644 return Discriminal
(Disc
);
5647 Next_Discriminant
(Disc
);
5650 -- That loop should always succeed in finding a matching entry and
5651 -- returning. Fatal error if not.
5653 raise Program_Error
;
5654 end Find_Body_Discriminal
;
5656 -------------------------------------
5657 -- Find_Corresponding_Discriminant --
5658 -------------------------------------
5660 function Find_Corresponding_Discriminant
5662 Typ
: Entity_Id
) return Entity_Id
5664 Par_Disc
: Entity_Id
;
5665 Old_Disc
: Entity_Id
;
5666 New_Disc
: Entity_Id
;
5669 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
5671 -- The original type may currently be private, and the discriminant
5672 -- only appear on its full view.
5674 if Is_Private_Type
(Scope
(Par_Disc
))
5675 and then not Has_Discriminants
(Scope
(Par_Disc
))
5676 and then Present
(Full_View
(Scope
(Par_Disc
)))
5678 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
5680 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
5683 if Is_Class_Wide_Type
(Typ
) then
5684 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
5686 New_Disc
:= First_Discriminant
(Typ
);
5689 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
5690 if Old_Disc
= Par_Disc
then
5693 Next_Discriminant
(Old_Disc
);
5694 Next_Discriminant
(New_Disc
);
5698 -- Should always find it
5700 raise Program_Error
;
5701 end Find_Corresponding_Discriminant
;
5703 ------------------------------------
5704 -- Find_Loop_In_Conditional_Block --
5705 ------------------------------------
5707 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
5713 if Nkind
(Stmt
) = N_If_Statement
then
5714 Stmt
:= First
(Then_Statements
(Stmt
));
5717 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
5719 -- Inspect the statements of the conditional block. In general the loop
5720 -- should be the first statement in the statement sequence of the block,
5721 -- but the finalization machinery may have introduced extra object
5724 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
5725 while Present
(Stmt
) loop
5726 if Nkind
(Stmt
) = N_Loop_Statement
then
5733 -- The expansion of attribute 'Loop_Entry produced a malformed block
5735 raise Program_Error
;
5736 end Find_Loop_In_Conditional_Block
;
5738 --------------------------
5739 -- Find_Overlaid_Entity --
5740 --------------------------
5742 procedure Find_Overlaid_Entity
5744 Ent
: out Entity_Id
;
5750 -- We are looking for one of the two following forms:
5752 -- for X'Address use Y'Address
5756 -- Const : constant Address := expr;
5758 -- for X'Address use Const;
5760 -- In the second case, the expr is either Y'Address, or recursively a
5761 -- constant that eventually references Y'Address.
5766 if Nkind
(N
) = N_Attribute_Definition_Clause
5767 and then Chars
(N
) = Name_Address
5769 Expr
:= Expression
(N
);
5771 -- This loop checks the form of the expression for Y'Address,
5772 -- using recursion to deal with intermediate constants.
5775 -- Check for Y'Address
5777 if Nkind
(Expr
) = N_Attribute_Reference
5778 and then Attribute_Name
(Expr
) = Name_Address
5780 Expr
:= Prefix
(Expr
);
5783 -- Check for Const where Const is a constant entity
5785 elsif Is_Entity_Name
(Expr
)
5786 and then Ekind
(Entity
(Expr
)) = E_Constant
5788 Expr
:= Constant_Value
(Entity
(Expr
));
5790 -- Anything else does not need checking
5797 -- This loop checks the form of the prefix for an entity, using
5798 -- recursion to deal with intermediate components.
5801 -- Check for Y where Y is an entity
5803 if Is_Entity_Name
(Expr
) then
5804 Ent
:= Entity
(Expr
);
5807 -- Check for components
5810 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
5812 Expr
:= Prefix
(Expr
);
5815 -- Anything else does not need checking
5822 end Find_Overlaid_Entity
;
5824 -------------------------
5825 -- Find_Parameter_Type --
5826 -------------------------
5828 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
5830 if Nkind
(Param
) /= N_Parameter_Specification
then
5833 -- For an access parameter, obtain the type from the formal entity
5834 -- itself, because access to subprogram nodes do not carry a type.
5835 -- Shouldn't we always use the formal entity ???
5837 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
5838 return Etype
(Defining_Identifier
(Param
));
5841 return Etype
(Parameter_Type
(Param
));
5843 end Find_Parameter_Type
;
5845 -----------------------------------
5846 -- Find_Placement_In_State_Space --
5847 -----------------------------------
5849 procedure Find_Placement_In_State_Space
5850 (Item_Id
: Entity_Id
;
5851 Placement
: out State_Space_Kind
;
5852 Pack_Id
: out Entity_Id
)
5854 Context
: Entity_Id
;
5857 -- Assume that the item does not appear in the state space of a package
5859 Placement
:= Not_In_Package
;
5862 -- Climb the scope stack and examine the enclosing context
5864 Context
:= Scope
(Item_Id
);
5865 while Present
(Context
) and then Context
/= Standard_Standard
loop
5866 if Ekind
(Context
) = E_Package
then
5869 -- A package body is a cut off point for the traversal as the item
5870 -- cannot be visible to the outside from this point on. Note that
5871 -- this test must be done first as a body is also classified as a
5874 if In_Package_Body
(Context
) then
5875 Placement
:= Body_State_Space
;
5878 -- The private part of a package is a cut off point for the
5879 -- traversal as the item cannot be visible to the outside from
5882 elsif In_Private_Part
(Context
) then
5883 Placement
:= Private_State_Space
;
5886 -- When the item appears in the visible state space of a package,
5887 -- continue to climb the scope stack as this may not be the final
5891 Placement
:= Visible_State_Space
;
5893 -- The visible state space of a child unit acts as the proper
5894 -- placement of an item.
5896 if Is_Child_Unit
(Context
) then
5901 -- The item or its enclosing package appear in a construct that has
5905 Placement
:= Not_In_Package
;
5909 Context
:= Scope
(Context
);
5911 end Find_Placement_In_State_Space
;
5913 -----------------------------
5914 -- Find_Static_Alternative --
5915 -----------------------------
5917 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
5918 Expr
: constant Node_Id
:= Expression
(N
);
5919 Val
: constant Uint
:= Expr_Value
(Expr
);
5924 Alt
:= First
(Alternatives
(N
));
5927 if Nkind
(Alt
) /= N_Pragma
then
5928 Choice
:= First
(Discrete_Choices
(Alt
));
5929 while Present
(Choice
) loop
5931 -- Others choice, always matches
5933 if Nkind
(Choice
) = N_Others_Choice
then
5936 -- Range, check if value is in the range
5938 elsif Nkind
(Choice
) = N_Range
then
5940 Val
>= Expr_Value
(Low_Bound
(Choice
))
5942 Val
<= Expr_Value
(High_Bound
(Choice
));
5944 -- Choice is a subtype name. Note that we know it must
5945 -- be a static subtype, since otherwise it would have
5946 -- been diagnosed as illegal.
5948 elsif Is_Entity_Name
(Choice
)
5949 and then Is_Type
(Entity
(Choice
))
5951 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
5952 Assume_Valid
=> False);
5954 -- Choice is a subtype indication
5956 elsif Nkind
(Choice
) = N_Subtype_Indication
then
5958 C
: constant Node_Id
:= Constraint
(Choice
);
5959 R
: constant Node_Id
:= Range_Expression
(C
);
5963 Val
>= Expr_Value
(Low_Bound
(R
))
5965 Val
<= Expr_Value
(High_Bound
(R
));
5968 -- Choice is a simple expression
5971 exit Search
when Val
= Expr_Value
(Choice
);
5979 pragma Assert
(Present
(Alt
));
5982 -- The above loop *must* terminate by finding a match, since
5983 -- we know the case statement is valid, and the value of the
5984 -- expression is known at compile time. When we fall out of
5985 -- the loop, Alt points to the alternative that we know will
5986 -- be selected at run time.
5989 end Find_Static_Alternative
;
5995 function First_Actual
(Node
: Node_Id
) return Node_Id
is
5999 if No
(Parameter_Associations
(Node
)) then
6003 N
:= First
(Parameter_Associations
(Node
));
6005 if Nkind
(N
) = N_Parameter_Association
then
6006 return First_Named_Actual
(Node
);
6012 -----------------------
6013 -- Gather_Components --
6014 -----------------------
6016 procedure Gather_Components
6018 Comp_List
: Node_Id
;
6019 Governed_By
: List_Id
;
6021 Report_Errors
: out Boolean)
6025 Discrete_Choice
: Node_Id
;
6026 Comp_Item
: Node_Id
;
6028 Discrim
: Entity_Id
;
6029 Discrim_Name
: Node_Id
;
6030 Discrim_Value
: Node_Id
;
6033 Report_Errors
:= False;
6035 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
6038 elsif Present
(Component_Items
(Comp_List
)) then
6039 Comp_Item
:= First
(Component_Items
(Comp_List
));
6045 while Present
(Comp_Item
) loop
6047 -- Skip the tag of a tagged record, the interface tags, as well
6048 -- as all items that are not user components (anonymous types,
6049 -- rep clauses, Parent field, controller field).
6051 if Nkind
(Comp_Item
) = N_Component_Declaration
then
6053 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
6055 if not Is_Tag
(Comp
)
6056 and then Chars
(Comp
) /= Name_uParent
6058 Append_Elmt
(Comp
, Into
);
6066 if No
(Variant_Part
(Comp_List
)) then
6069 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
6070 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
6073 -- Look for the discriminant that governs this variant part.
6074 -- The discriminant *must* be in the Governed_By List
6076 Assoc
:= First
(Governed_By
);
6077 Find_Constraint
: loop
6078 Discrim
:= First
(Choices
(Assoc
));
6079 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
6080 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
6082 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
6083 Chars
(Discrim_Name
))
6084 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
6085 = Chars
(Discrim_Name
);
6087 if No
(Next
(Assoc
)) then
6088 if not Is_Constrained
(Typ
)
6089 and then Is_Derived_Type
(Typ
)
6090 and then Present
(Stored_Constraint
(Typ
))
6092 -- If the type is a tagged type with inherited discriminants,
6093 -- use the stored constraint on the parent in order to find
6094 -- the values of discriminants that are otherwise hidden by an
6095 -- explicit constraint. Renamed discriminants are handled in
6098 -- If several parent discriminants are renamed by a single
6099 -- discriminant of the derived type, the call to obtain the
6100 -- Corresponding_Discriminant field only retrieves the last
6101 -- of them. We recover the constraint on the others from the
6102 -- Stored_Constraint as well.
6109 D
:= First_Discriminant
(Etype
(Typ
));
6110 C
:= First_Elmt
(Stored_Constraint
(Typ
));
6111 while Present
(D
) and then Present
(C
) loop
6112 if Chars
(Discrim_Name
) = Chars
(D
) then
6113 if Is_Entity_Name
(Node
(C
))
6114 and then Entity
(Node
(C
)) = Entity
(Discrim
)
6116 -- D is renamed by Discrim, whose value is given in
6123 Make_Component_Association
(Sloc
(Typ
),
6125 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
6126 Duplicate_Subexpr_No_Checks
(Node
(C
)));
6128 exit Find_Constraint
;
6131 Next_Discriminant
(D
);
6138 if No
(Next
(Assoc
)) then
6139 Error_Msg_NE
(" missing value for discriminant&",
6140 First
(Governed_By
), Discrim_Name
);
6141 Report_Errors
:= True;
6146 end loop Find_Constraint
;
6148 Discrim_Value
:= Expression
(Assoc
);
6150 if not Is_OK_Static_Expression
(Discrim_Value
) then
6152 ("value for discriminant & must be static!",
6153 Discrim_Value
, Discrim
);
6154 Why_Not_Static
(Discrim_Value
);
6155 Report_Errors
:= True;
6159 Search_For_Discriminant_Value
: declare
6165 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
6168 Find_Discrete_Value
: while Present
(Variant
) loop
6169 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
6170 while Present
(Discrete_Choice
) loop
6171 exit Find_Discrete_Value
when
6172 Nkind
(Discrete_Choice
) = N_Others_Choice
;
6174 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
6176 UI_Low
:= Expr_Value
(Low
);
6177 UI_High
:= Expr_Value
(High
);
6179 exit Find_Discrete_Value
when
6180 UI_Low
<= UI_Discrim_Value
6182 UI_High
>= UI_Discrim_Value
;
6184 Next
(Discrete_Choice
);
6187 Next_Non_Pragma
(Variant
);
6188 end loop Find_Discrete_Value
;
6189 end Search_For_Discriminant_Value
;
6191 if No
(Variant
) then
6193 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
6194 Report_Errors
:= True;
6198 -- If we have found the corresponding choice, recursively add its
6199 -- components to the Into list.
6202 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
6203 end Gather_Components
;
6205 ------------------------
6206 -- Get_Actual_Subtype --
6207 ------------------------
6209 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
6210 Typ
: constant Entity_Id
:= Etype
(N
);
6211 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
6220 -- If what we have is an identifier that references a subprogram
6221 -- formal, or a variable or constant object, then we get the actual
6222 -- subtype from the referenced entity if one has been built.
6224 if Nkind
(N
) = N_Identifier
6226 (Is_Formal
(Entity
(N
))
6227 or else Ekind
(Entity
(N
)) = E_Constant
6228 or else Ekind
(Entity
(N
)) = E_Variable
)
6229 and then Present
(Actual_Subtype
(Entity
(N
)))
6231 return Actual_Subtype
(Entity
(N
));
6233 -- Actual subtype of unchecked union is always itself. We never need
6234 -- the "real" actual subtype. If we did, we couldn't get it anyway
6235 -- because the discriminant is not available. The restrictions on
6236 -- Unchecked_Union are designed to make sure that this is OK.
6238 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
6241 -- Here for the unconstrained case, we must find actual subtype
6242 -- No actual subtype is available, so we must build it on the fly.
6244 -- Checking the type, not the underlying type, for constrainedness
6245 -- seems to be necessary. Maybe all the tests should be on the type???
6247 elsif (not Is_Constrained
(Typ
))
6248 and then (Is_Array_Type
(Utyp
)
6249 or else (Is_Record_Type
(Utyp
)
6250 and then Has_Discriminants
(Utyp
)))
6251 and then not Has_Unknown_Discriminants
(Utyp
)
6252 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
6254 -- Nothing to do if in spec expression (why not???)
6256 if In_Spec_Expression
then
6259 elsif Is_Private_Type
(Typ
)
6260 and then not Has_Discriminants
(Typ
)
6262 -- If the type has no discriminants, there is no subtype to
6263 -- build, even if the underlying type is discriminated.
6267 -- Else build the actual subtype
6270 Decl
:= Build_Actual_Subtype
(Typ
, N
);
6271 Atyp
:= Defining_Identifier
(Decl
);
6273 -- If Build_Actual_Subtype generated a new declaration then use it
6277 -- The actual subtype is an Itype, so analyze the declaration,
6278 -- but do not attach it to the tree, to get the type defined.
6280 Set_Parent
(Decl
, N
);
6281 Set_Is_Itype
(Atyp
);
6282 Analyze
(Decl
, Suppress
=> All_Checks
);
6283 Set_Associated_Node_For_Itype
(Atyp
, N
);
6284 Set_Has_Delayed_Freeze
(Atyp
, False);
6286 -- We need to freeze the actual subtype immediately. This is
6287 -- needed, because otherwise this Itype will not get frozen
6288 -- at all, and it is always safe to freeze on creation because
6289 -- any associated types must be frozen at this point.
6291 Freeze_Itype
(Atyp
, N
);
6294 -- Otherwise we did not build a declaration, so return original
6301 -- For all remaining cases, the actual subtype is the same as
6302 -- the nominal type.
6307 end Get_Actual_Subtype
;
6309 -------------------------------------
6310 -- Get_Actual_Subtype_If_Available --
6311 -------------------------------------
6313 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
6314 Typ
: constant Entity_Id
:= Etype
(N
);
6317 -- If what we have is an identifier that references a subprogram
6318 -- formal, or a variable or constant object, then we get the actual
6319 -- subtype from the referenced entity if one has been built.
6321 if Nkind
(N
) = N_Identifier
6323 (Is_Formal
(Entity
(N
))
6324 or else Ekind
(Entity
(N
)) = E_Constant
6325 or else Ekind
(Entity
(N
)) = E_Variable
)
6326 and then Present
(Actual_Subtype
(Entity
(N
)))
6328 return Actual_Subtype
(Entity
(N
));
6330 -- Otherwise the Etype of N is returned unchanged
6335 end Get_Actual_Subtype_If_Available
;
6337 ------------------------
6338 -- Get_Body_From_Stub --
6339 ------------------------
6341 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
6343 return Proper_Body
(Unit
(Library_Unit
(N
)));
6344 end Get_Body_From_Stub
;
6346 -------------------------------
6347 -- Get_Default_External_Name --
6348 -------------------------------
6350 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
6352 Get_Decoded_Name_String
(Chars
(E
));
6354 if Opt
.External_Name_Imp_Casing
= Uppercase
then
6355 Set_Casing
(All_Upper_Case
);
6357 Set_Casing
(All_Lower_Case
);
6361 Make_String_Literal
(Sloc
(E
),
6362 Strval
=> String_From_Name_Buffer
);
6363 end Get_Default_External_Name
;
6365 --------------------------
6366 -- Get_Enclosing_Object --
6367 --------------------------
6369 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
6371 if Is_Entity_Name
(N
) then
6375 when N_Indexed_Component |
6377 N_Selected_Component
=>
6379 -- If not generating code, a dereference may be left implicit.
6380 -- In thoses cases, return Empty.
6382 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6385 return Get_Enclosing_Object
(Prefix
(N
));
6388 when N_Type_Conversion
=>
6389 return Get_Enclosing_Object
(Expression
(N
));
6395 end Get_Enclosing_Object
;
6397 ---------------------------
6398 -- Get_Enum_Lit_From_Pos --
6399 ---------------------------
6401 function Get_Enum_Lit_From_Pos
6404 Loc
: Source_Ptr
) return Node_Id
6406 Btyp
: Entity_Id
:= Base_Type
(T
);
6410 -- In the case where the literal is of type Character, Wide_Character
6411 -- or Wide_Wide_Character or of a type derived from them, there needs
6412 -- to be some special handling since there is no explicit chain of
6413 -- literals to search. Instead, an N_Character_Literal node is created
6414 -- with the appropriate Char_Code and Chars fields.
6416 if Is_Standard_Character_Type
(T
) then
6417 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
6419 Make_Character_Literal
(Loc
,
6421 Char_Literal_Value
=> Pos
);
6423 -- For all other cases, we have a complete table of literals, and
6424 -- we simply iterate through the chain of literal until the one
6425 -- with the desired position value is found.
6429 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
6430 Btyp
:= Full_View
(Btyp
);
6433 Lit
:= First_Literal
(Btyp
);
6434 for J
in 1 .. UI_To_Int
(Pos
) loop
6438 return New_Occurrence_Of
(Lit
, Loc
);
6440 end Get_Enum_Lit_From_Pos
;
6442 ---------------------------------
6443 -- Get_Ensures_From_CTC_Pragma --
6444 ---------------------------------
6446 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
6447 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
6451 if List_Length
(Args
) = 4 then
6452 Res
:= Pick
(Args
, 4);
6454 elsif List_Length
(Args
) = 3 then
6455 Res
:= Pick
(Args
, 3);
6457 if Chars
(Res
) /= Name_Ensures
then
6466 end Get_Ensures_From_CTC_Pragma
;
6468 ------------------------
6469 -- Get_Generic_Entity --
6470 ------------------------
6472 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
6473 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
6475 if Present
(Renamed_Object
(Ent
)) then
6476 return Renamed_Object
(Ent
);
6480 end Get_Generic_Entity
;
6482 -------------------------------------
6483 -- Get_Incomplete_View_Of_Ancestor --
6484 -------------------------------------
6486 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
6487 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
6488 Par_Scope
: Entity_Id
;
6489 Par_Type
: Entity_Id
;
6492 -- The incomplete view of an ancestor is only relevant for private
6493 -- derived types in child units.
6495 if not Is_Derived_Type
(E
)
6496 or else not Is_Child_Unit
(Cur_Unit
)
6501 Par_Scope
:= Scope
(Cur_Unit
);
6502 if No
(Par_Scope
) then
6506 Par_Type
:= Etype
(Base_Type
(E
));
6508 -- Traverse list of ancestor types until we find one declared in
6509 -- a parent or grandparent unit (two levels seem sufficient).
6511 while Present
(Par_Type
) loop
6512 if Scope
(Par_Type
) = Par_Scope
6513 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
6517 elsif not Is_Derived_Type
(Par_Type
) then
6521 Par_Type
:= Etype
(Base_Type
(Par_Type
));
6525 -- If none found, there is no relevant ancestor type.
6529 end Get_Incomplete_View_Of_Ancestor
;
6531 ----------------------
6532 -- Get_Index_Bounds --
6533 ----------------------
6535 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
6536 Kind
: constant Node_Kind
:= Nkind
(N
);
6540 if Kind
= N_Range
then
6542 H
:= High_Bound
(N
);
6544 elsif Kind
= N_Subtype_Indication
then
6545 R
:= Range_Expression
(Constraint
(N
));
6553 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
6554 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
6557 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
6558 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
6562 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
6563 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
6566 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
6567 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
6571 -- N is an expression, indicating a range with one value
6576 end Get_Index_Bounds
;
6578 ----------------------------------
6579 -- Get_Library_Unit_Name_string --
6580 ----------------------------------
6582 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
6583 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
6586 Get_Unit_Name_String
(Unit_Name_Id
);
6588 -- Remove seven last character (" (spec)" or " (body)")
6590 Name_Len
:= Name_Len
- 7;
6591 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
6592 end Get_Library_Unit_Name_String
;
6594 ------------------------
6595 -- Get_Name_Entity_Id --
6596 ------------------------
6598 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
6600 return Entity_Id
(Get_Name_Table_Info
(Id
));
6601 end Get_Name_Entity_Id
;
6603 ------------------------------
6604 -- Get_Name_From_CTC_Pragma --
6605 ------------------------------
6607 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
6608 Arg
: constant Node_Id
:=
6609 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
6611 return Strval
(Expr_Value_S
(Arg
));
6612 end Get_Name_From_CTC_Pragma
;
6618 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
6620 return Get_Pragma_Id
(Pragma_Name
(N
));
6623 ---------------------------
6624 -- Get_Referenced_Object --
6625 ---------------------------
6627 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
6632 while Is_Entity_Name
(R
)
6633 and then Present
(Renamed_Object
(Entity
(R
)))
6635 R
:= Renamed_Object
(Entity
(R
));
6639 end Get_Referenced_Object
;
6641 ------------------------
6642 -- Get_Renamed_Entity --
6643 ------------------------
6645 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
6650 while Present
(Renamed_Entity
(R
)) loop
6651 R
:= Renamed_Entity
(R
);
6655 end Get_Renamed_Entity
;
6657 ----------------------------------
6658 -- Get_Requires_From_CTC_Pragma --
6659 ----------------------------------
6661 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
6662 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
6666 if List_Length
(Args
) >= 3 then
6667 Res
:= Pick
(Args
, 3);
6669 if Chars
(Res
) /= Name_Requires
then
6678 end Get_Requires_From_CTC_Pragma
;
6680 -------------------------
6681 -- Get_Subprogram_Body --
6682 -------------------------
6684 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
6688 Decl
:= Unit_Declaration_Node
(E
);
6690 if Nkind
(Decl
) = N_Subprogram_Body
then
6693 -- The below comment is bad, because it is possible for
6694 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
6696 else -- Nkind (Decl) = N_Subprogram_Declaration
6698 if Present
(Corresponding_Body
(Decl
)) then
6699 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
6701 -- Imported subprogram case
6707 end Get_Subprogram_Body
;
6709 ---------------------------
6710 -- Get_Subprogram_Entity --
6711 ---------------------------
6713 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
6715 Subp_Id
: Entity_Id
;
6718 if Nkind
(Nod
) = N_Accept_Statement
then
6719 Subp
:= Entry_Direct_Name
(Nod
);
6721 elsif Nkind
(Nod
) = N_Slice
then
6722 Subp
:= Prefix
(Nod
);
6728 -- Strip the subprogram call
6731 if Nkind_In
(Subp
, N_Explicit_Dereference
,
6732 N_Indexed_Component
,
6733 N_Selected_Component
)
6735 Subp
:= Prefix
(Subp
);
6737 elsif Nkind_In
(Subp
, N_Type_Conversion
,
6738 N_Unchecked_Type_Conversion
)
6740 Subp
:= Expression
(Subp
);
6747 -- Extract the entity of the subprogram call
6749 if Is_Entity_Name
(Subp
) then
6750 Subp_Id
:= Entity
(Subp
);
6752 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
6753 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
6756 if Is_Subprogram
(Subp_Id
) then
6762 -- The search did not find a construct that denotes a subprogram
6767 end Get_Subprogram_Entity
;
6769 -----------------------------
6770 -- Get_Task_Body_Procedure --
6771 -----------------------------
6773 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
6775 -- Note: A task type may be the completion of a private type with
6776 -- discriminants. When performing elaboration checks on a task
6777 -- declaration, the current view of the type may be the private one,
6778 -- and the procedure that holds the body of the task is held in its
6781 -- This is an odd function, why not have Task_Body_Procedure do
6782 -- the following digging???
6784 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
6785 end Get_Task_Body_Procedure
;
6787 -----------------------
6788 -- Has_Access_Values --
6789 -----------------------
6791 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
6792 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
6795 -- Case of a private type which is not completed yet. This can only
6796 -- happen in the case of a generic format type appearing directly, or
6797 -- as a component of the type to which this function is being applied
6798 -- at the top level. Return False in this case, since we certainly do
6799 -- not know that the type contains access types.
6804 elsif Is_Access_Type
(Typ
) then
6807 elsif Is_Array_Type
(Typ
) then
6808 return Has_Access_Values
(Component_Type
(Typ
));
6810 elsif Is_Record_Type
(Typ
) then
6815 -- Loop to Check components
6817 Comp
:= First_Component_Or_Discriminant
(Typ
);
6818 while Present
(Comp
) loop
6820 -- Check for access component, tag field does not count, even
6821 -- though it is implemented internally using an access type.
6823 if Has_Access_Values
(Etype
(Comp
))
6824 and then Chars
(Comp
) /= Name_uTag
6829 Next_Component_Or_Discriminant
(Comp
);
6838 end Has_Access_Values
;
6840 ------------------------------
6841 -- Has_Compatible_Alignment --
6842 ------------------------------
6844 function Has_Compatible_Alignment
6846 Expr
: Node_Id
) return Alignment_Result
6848 function Has_Compatible_Alignment_Internal
6851 Default
: Alignment_Result
) return Alignment_Result
;
6852 -- This is the internal recursive function that actually does the work.
6853 -- There is one additional parameter, which says what the result should
6854 -- be if no alignment information is found, and there is no definite
6855 -- indication of compatible alignments. At the outer level, this is set
6856 -- to Unknown, but for internal recursive calls in the case where types
6857 -- are known to be correct, it is set to Known_Compatible.
6859 ---------------------------------------
6860 -- Has_Compatible_Alignment_Internal --
6861 ---------------------------------------
6863 function Has_Compatible_Alignment_Internal
6866 Default
: Alignment_Result
) return Alignment_Result
6868 Result
: Alignment_Result
:= Known_Compatible
;
6869 -- Holds the current status of the result. Note that once a value of
6870 -- Known_Incompatible is set, it is sticky and does not get changed
6871 -- to Unknown (the value in Result only gets worse as we go along,
6874 Offs
: Uint
:= No_Uint
;
6875 -- Set to a factor of the offset from the base object when Expr is a
6876 -- selected or indexed component, based on Component_Bit_Offset and
6877 -- Component_Size respectively. A negative value is used to represent
6878 -- a value which is not known at compile time.
6880 procedure Check_Prefix
;
6881 -- Checks the prefix recursively in the case where the expression
6882 -- is an indexed or selected component.
6884 procedure Set_Result
(R
: Alignment_Result
);
6885 -- If R represents a worse outcome (unknown instead of known
6886 -- compatible, or known incompatible), then set Result to R.
6892 procedure Check_Prefix
is
6894 -- The subtlety here is that in doing a recursive call to check
6895 -- the prefix, we have to decide what to do in the case where we
6896 -- don't find any specific indication of an alignment problem.
6898 -- At the outer level, we normally set Unknown as the result in
6899 -- this case, since we can only set Known_Compatible if we really
6900 -- know that the alignment value is OK, but for the recursive
6901 -- call, in the case where the types match, and we have not
6902 -- specified a peculiar alignment for the object, we are only
6903 -- concerned about suspicious rep clauses, the default case does
6904 -- not affect us, since the compiler will, in the absence of such
6905 -- rep clauses, ensure that the alignment is correct.
6907 if Default
= Known_Compatible
6909 (Etype
(Obj
) = Etype
(Expr
)
6910 and then (Unknown_Alignment
(Obj
)
6912 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
6915 (Has_Compatible_Alignment_Internal
6916 (Obj
, Prefix
(Expr
), Known_Compatible
));
6918 -- In all other cases, we need a full check on the prefix
6922 (Has_Compatible_Alignment_Internal
6923 (Obj
, Prefix
(Expr
), Unknown
));
6931 procedure Set_Result
(R
: Alignment_Result
) is
6938 -- Start of processing for Has_Compatible_Alignment_Internal
6941 -- If Expr is a selected component, we must make sure there is no
6942 -- potentially troublesome component clause, and that the record is
6945 if Nkind
(Expr
) = N_Selected_Component
then
6947 -- Packed record always generate unknown alignment
6949 if Is_Packed
(Etype
(Prefix
(Expr
))) then
6950 Set_Result
(Unknown
);
6953 -- Check prefix and component offset
6956 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
6958 -- If Expr is an indexed component, we must make sure there is no
6959 -- potentially troublesome Component_Size clause and that the array
6960 -- is not bit-packed.
6962 elsif Nkind
(Expr
) = N_Indexed_Component
then
6964 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
6965 Ind
: constant Node_Id
:= First_Index
(Typ
);
6968 -- Bit packed array always generates unknown alignment
6970 if Is_Bit_Packed_Array
(Typ
) then
6971 Set_Result
(Unknown
);
6974 -- Check prefix and component offset
6977 Offs
:= Component_Size
(Typ
);
6979 -- Small optimization: compute the full offset when possible
6982 and then Offs
> Uint_0
6983 and then Present
(Ind
)
6984 and then Nkind
(Ind
) = N_Range
6985 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
6986 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
6988 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
6989 - Expr_Value
(Low_Bound
((Ind
))));
6994 -- If we have a null offset, the result is entirely determined by
6995 -- the base object and has already been computed recursively.
6997 if Offs
= Uint_0
then
7000 -- Case where we know the alignment of the object
7002 elsif Known_Alignment
(Obj
) then
7004 ObjA
: constant Uint
:= Alignment
(Obj
);
7005 ExpA
: Uint
:= No_Uint
;
7006 SizA
: Uint
:= No_Uint
;
7009 -- If alignment of Obj is 1, then we are always OK
7012 Set_Result
(Known_Compatible
);
7014 -- Alignment of Obj is greater than 1, so we need to check
7017 -- If we have an offset, see if it is compatible
7019 if Offs
/= No_Uint
and Offs
> Uint_0
then
7020 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
7021 Set_Result
(Known_Incompatible
);
7024 -- See if Expr is an object with known alignment
7026 elsif Is_Entity_Name
(Expr
)
7027 and then Known_Alignment
(Entity
(Expr
))
7029 ExpA
:= Alignment
(Entity
(Expr
));
7031 -- Otherwise, we can use the alignment of the type of
7032 -- Expr given that we already checked for
7033 -- discombobulating rep clauses for the cases of indexed
7034 -- and selected components above.
7036 elsif Known_Alignment
(Etype
(Expr
)) then
7037 ExpA
:= Alignment
(Etype
(Expr
));
7039 -- Otherwise the alignment is unknown
7042 Set_Result
(Default
);
7045 -- If we got an alignment, see if it is acceptable
7047 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
7048 Set_Result
(Known_Incompatible
);
7051 -- If Expr is not a piece of a larger object, see if size
7052 -- is given. If so, check that it is not too small for the
7053 -- required alignment.
7055 if Offs
/= No_Uint
then
7058 -- See if Expr is an object with known size
7060 elsif Is_Entity_Name
(Expr
)
7061 and then Known_Static_Esize
(Entity
(Expr
))
7063 SizA
:= Esize
(Entity
(Expr
));
7065 -- Otherwise, we check the object size of the Expr type
7067 elsif Known_Static_Esize
(Etype
(Expr
)) then
7068 SizA
:= Esize
(Etype
(Expr
));
7071 -- If we got a size, see if it is a multiple of the Obj
7072 -- alignment, if not, then the alignment cannot be
7073 -- acceptable, since the size is always a multiple of the
7076 if SizA
/= No_Uint
then
7077 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
7078 Set_Result
(Known_Incompatible
);
7084 -- If we do not know required alignment, any non-zero offset is a
7085 -- potential problem (but certainly may be OK, so result is unknown).
7087 elsif Offs
/= No_Uint
then
7088 Set_Result
(Unknown
);
7090 -- If we can't find the result by direct comparison of alignment
7091 -- values, then there is still one case that we can determine known
7092 -- result, and that is when we can determine that the types are the
7093 -- same, and no alignments are specified. Then we known that the
7094 -- alignments are compatible, even if we don't know the alignment
7095 -- value in the front end.
7097 elsif Etype
(Obj
) = Etype
(Expr
) then
7099 -- Types are the same, but we have to check for possible size
7100 -- and alignments on the Expr object that may make the alignment
7101 -- different, even though the types are the same.
7103 if Is_Entity_Name
(Expr
) then
7105 -- First check alignment of the Expr object. Any alignment less
7106 -- than Maximum_Alignment is worrisome since this is the case
7107 -- where we do not know the alignment of Obj.
7109 if Known_Alignment
(Entity
(Expr
))
7111 UI_To_Int
(Alignment
(Entity
(Expr
))) <
7112 Ttypes
.Maximum_Alignment
7114 Set_Result
(Unknown
);
7116 -- Now check size of Expr object. Any size that is not an
7117 -- even multiple of Maximum_Alignment is also worrisome
7118 -- since it may cause the alignment of the object to be less
7119 -- than the alignment of the type.
7121 elsif Known_Static_Esize
(Entity
(Expr
))
7123 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
7124 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
7127 Set_Result
(Unknown
);
7129 -- Otherwise same type is decisive
7132 Set_Result
(Known_Compatible
);
7136 -- Another case to deal with is when there is an explicit size or
7137 -- alignment clause when the types are not the same. If so, then the
7138 -- result is Unknown. We don't need to do this test if the Default is
7139 -- Unknown, since that result will be set in any case.
7141 elsif Default
/= Unknown
7142 and then (Has_Size_Clause
(Etype
(Expr
))
7144 Has_Alignment_Clause
(Etype
(Expr
)))
7146 Set_Result
(Unknown
);
7148 -- If no indication found, set default
7151 Set_Result
(Default
);
7154 -- Return worst result found
7157 end Has_Compatible_Alignment_Internal
;
7159 -- Start of processing for Has_Compatible_Alignment
7162 -- If Obj has no specified alignment, then set alignment from the type
7163 -- alignment. Perhaps we should always do this, but for sure we should
7164 -- do it when there is an address clause since we can do more if the
7165 -- alignment is known.
7167 if Unknown_Alignment
(Obj
) then
7168 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
7171 -- Now do the internal call that does all the work
7173 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
7174 end Has_Compatible_Alignment
;
7176 ----------------------
7177 -- Has_Declarations --
7178 ----------------------
7180 function Has_Declarations
(N
: Node_Id
) return Boolean is
7182 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
7184 N_Compilation_Unit_Aux
,
7190 N_Package_Specification
);
7191 end Has_Declarations
;
7197 function Has_Denormals
(E
: Entity_Id
) return Boolean is
7199 return Is_Floating_Point_Type
(E
)
7200 and then Denorm_On_Target
7201 and then not Vax_Float
(E
);
7204 -------------------------------------------
7205 -- Has_Discriminant_Dependent_Constraint --
7206 -------------------------------------------
7208 function Has_Discriminant_Dependent_Constraint
7209 (Comp
: Entity_Id
) return Boolean
7211 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7212 Subt_Indic
: constant Node_Id
:=
7213 Subtype_Indication
(Component_Definition
(Comp_Decl
));
7218 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
7219 Constr
:= Constraint
(Subt_Indic
);
7221 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
7222 Assn
:= First
(Constraints
(Constr
));
7223 while Present
(Assn
) loop
7224 case Nkind
(Assn
) is
7225 when N_Subtype_Indication |
7229 if Depends_On_Discriminant
(Assn
) then
7233 when N_Discriminant_Association
=>
7234 if Depends_On_Discriminant
(Expression
(Assn
)) then
7249 end Has_Discriminant_Dependent_Constraint
;
7251 --------------------------
7252 -- Has_Enabled_Property --
7253 --------------------------
7255 function Has_Enabled_Property
7256 (State_Id
: Node_Id
;
7257 Prop_Nam
: Name_Id
) return Boolean
7259 Decl
: constant Node_Id
:= Parent
(State_Id
);
7266 -- The declaration of an external abstract state appears as an extension
7267 -- aggregate. If this is not the case, properties can never be set.
7269 if Nkind
(Decl
) /= N_Extension_Aggregate
then
7273 -- When External appears as a simple option, it automatically enables
7276 Opt
:= First
(Expressions
(Decl
));
7277 while Present
(Opt
) loop
7278 if Nkind
(Opt
) = N_Identifier
7279 and then Chars
(Opt
) = Name_External
7287 -- When External specifies particular properties, inspect those and
7288 -- find the desired one (if any).
7290 Opt
:= First
(Component_Associations
(Decl
));
7291 while Present
(Opt
) loop
7292 Opt_Nam
:= First
(Choices
(Opt
));
7294 if Nkind
(Opt_Nam
) = N_Identifier
7295 and then Chars
(Opt_Nam
) = Name_External
7297 Props
:= Expression
(Opt
);
7299 -- Multiple properties appear as an aggregate
7301 if Nkind
(Props
) = N_Aggregate
then
7303 -- Simple property form
7305 Prop
:= First
(Expressions
(Props
));
7306 while Present
(Prop
) loop
7307 if Chars
(Prop
) = Prop_Nam
then
7314 -- Property with expression form
7316 Prop
:= First
(Component_Associations
(Props
));
7317 while Present
(Prop
) loop
7318 if Chars
(Prop
) = Prop_Nam
then
7319 return Is_True
(Expr_Value
(Expression
(Prop
)));
7328 return Chars
(Props
) = Prop_Nam
;
7336 end Has_Enabled_Property
;
7338 --------------------
7339 -- Has_Infinities --
7340 --------------------
7342 function Has_Infinities
(E
: Entity_Id
) return Boolean is
7345 Is_Floating_Point_Type
(E
)
7346 and then Nkind
(Scalar_Range
(E
)) = N_Range
7347 and then Includes_Infinities
(Scalar_Range
(E
));
7350 --------------------
7351 -- Has_Interfaces --
7352 --------------------
7354 function Has_Interfaces
7356 Use_Full_View
: Boolean := True) return Boolean
7358 Typ
: Entity_Id
:= Base_Type
(T
);
7361 -- Handle concurrent types
7363 if Is_Concurrent_Type
(Typ
) then
7364 Typ
:= Corresponding_Record_Type
(Typ
);
7367 if not Present
(Typ
)
7368 or else not Is_Record_Type
(Typ
)
7369 or else not Is_Tagged_Type
(Typ
)
7374 -- Handle private types
7377 and then Present
(Full_View
(Typ
))
7379 Typ
:= Full_View
(Typ
);
7382 -- Handle concurrent record types
7384 if Is_Concurrent_Record_Type
(Typ
)
7385 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
7391 if Is_Interface
(Typ
)
7393 (Is_Record_Type
(Typ
)
7394 and then Present
(Interfaces
(Typ
))
7395 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
7400 exit when Etype
(Typ
) = Typ
7402 -- Handle private types
7404 or else (Present
(Full_View
(Etype
(Typ
)))
7405 and then Full_View
(Etype
(Typ
)) = Typ
)
7407 -- Protect the frontend against wrong source with cyclic
7410 or else Etype
(Typ
) = T
;
7412 -- Climb to the ancestor type handling private types
7414 if Present
(Full_View
(Etype
(Typ
))) then
7415 Typ
:= Full_View
(Etype
(Typ
));
7424 ---------------------------------
7425 -- Has_No_Obvious_Side_Effects --
7426 ---------------------------------
7428 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
7430 -- For now, just handle literals, constants, and non-volatile
7431 -- variables and expressions combining these with operators or
7432 -- short circuit forms.
7434 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
7437 elsif Nkind
(N
) = N_Character_Literal
then
7440 elsif Nkind
(N
) in N_Unary_Op
then
7441 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
7443 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
7444 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
7446 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
7448 elsif Nkind
(N
) = N_Expression_With_Actions
7450 Is_Empty_List
(Actions
(N
))
7452 return Has_No_Obvious_Side_Effects
(Expression
(N
));
7454 elsif Nkind
(N
) in N_Has_Entity
then
7455 return Present
(Entity
(N
))
7456 and then Ekind_In
(Entity
(N
), E_Variable
,
7458 E_Enumeration_Literal
,
7462 and then not Is_Volatile
(Entity
(N
));
7467 end Has_No_Obvious_Side_Effects
;
7469 ------------------------
7470 -- Has_Null_Exclusion --
7471 ------------------------
7473 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
7476 when N_Access_Definition |
7477 N_Access_Function_Definition |
7478 N_Access_Procedure_Definition |
7479 N_Access_To_Object_Definition |
7481 N_Derived_Type_Definition |
7482 N_Function_Specification |
7483 N_Subtype_Declaration
=>
7484 return Null_Exclusion_Present
(N
);
7486 when N_Component_Definition |
7487 N_Formal_Object_Declaration |
7488 N_Object_Renaming_Declaration
=>
7489 if Present
(Subtype_Mark
(N
)) then
7490 return Null_Exclusion_Present
(N
);
7491 else pragma Assert
(Present
(Access_Definition
(N
)));
7492 return Null_Exclusion_Present
(Access_Definition
(N
));
7495 when N_Discriminant_Specification
=>
7496 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
7497 return Null_Exclusion_Present
(Discriminant_Type
(N
));
7499 return Null_Exclusion_Present
(N
);
7502 when N_Object_Declaration
=>
7503 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
7504 return Null_Exclusion_Present
(Object_Definition
(N
));
7506 return Null_Exclusion_Present
(N
);
7509 when N_Parameter_Specification
=>
7510 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
7511 return Null_Exclusion_Present
(Parameter_Type
(N
));
7513 return Null_Exclusion_Present
(N
);
7520 end Has_Null_Exclusion
;
7522 ------------------------
7523 -- Has_Null_Extension --
7524 ------------------------
7526 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
7527 B
: constant Entity_Id
:= Base_Type
(T
);
7532 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
7533 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
7535 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
7537 if Present
(Ext
) then
7538 if Null_Present
(Ext
) then
7541 Comps
:= Component_List
(Ext
);
7543 -- The null component list is rewritten during analysis to
7544 -- include the parent component. Any other component indicates
7545 -- that the extension was not originally null.
7547 return Null_Present
(Comps
)
7548 or else No
(Next
(First
(Component_Items
(Comps
))));
7557 end Has_Null_Extension
;
7559 -------------------------------
7560 -- Has_Overriding_Initialize --
7561 -------------------------------
7563 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
7564 BT
: constant Entity_Id
:= Base_Type
(T
);
7568 if Is_Controlled
(BT
) then
7569 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
7572 elsif Present
(Primitive_Operations
(BT
)) then
7573 P
:= First_Elmt
(Primitive_Operations
(BT
));
7574 while Present
(P
) loop
7576 Init
: constant Entity_Id
:= Node
(P
);
7577 Formal
: constant Entity_Id
:= First_Formal
(Init
);
7579 if Ekind
(Init
) = E_Procedure
7580 and then Chars
(Init
) = Name_Initialize
7581 and then Comes_From_Source
(Init
)
7582 and then Present
(Formal
)
7583 and then Etype
(Formal
) = BT
7584 and then No
(Next_Formal
(Formal
))
7585 and then (Ada_Version
< Ada_2012
7586 or else not Null_Present
(Parent
(Init
)))
7596 -- Here if type itself does not have a non-null Initialize operation:
7597 -- check immediate ancestor.
7599 if Is_Derived_Type
(BT
)
7600 and then Has_Overriding_Initialize
(Etype
(BT
))
7607 end Has_Overriding_Initialize
;
7609 --------------------------------------
7610 -- Has_Preelaborable_Initialization --
7611 --------------------------------------
7613 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
7616 procedure Check_Components
(E
: Entity_Id
);
7617 -- Check component/discriminant chain, sets Has_PE False if a component
7618 -- or discriminant does not meet the preelaborable initialization rules.
7620 ----------------------
7621 -- Check_Components --
7622 ----------------------
7624 procedure Check_Components
(E
: Entity_Id
) is
7628 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
7629 -- Returns True if and only if the expression denoted by N does not
7630 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
7632 ---------------------------------
7633 -- Is_Preelaborable_Expression --
7634 ---------------------------------
7636 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
7640 Comp_Type
: Entity_Id
;
7641 Is_Array_Aggr
: Boolean;
7644 if Is_Static_Expression
(N
) then
7647 elsif Nkind
(N
) = N_Null
then
7650 -- Attributes are allowed in general, even if their prefix is a
7651 -- formal type. (It seems that certain attributes known not to be
7652 -- static might not be allowed, but there are no rules to prevent
7655 elsif Nkind
(N
) = N_Attribute_Reference
then
7658 -- The name of a discriminant evaluated within its parent type is
7659 -- defined to be preelaborable (10.2.1(8)). Note that we test for
7660 -- names that denote discriminals as well as discriminants to
7661 -- catch references occurring within init procs.
7663 elsif Is_Entity_Name
(N
)
7665 (Ekind
(Entity
(N
)) = E_Discriminant
7667 ((Ekind
(Entity
(N
)) = E_Constant
7668 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
7669 and then Present
(Discriminal_Link
(Entity
(N
)))))
7673 elsif Nkind
(N
) = N_Qualified_Expression
then
7674 return Is_Preelaborable_Expression
(Expression
(N
));
7676 -- For aggregates we have to check that each of the associations
7677 -- is preelaborable.
7679 elsif Nkind
(N
) = N_Aggregate
7680 or else Nkind
(N
) = N_Extension_Aggregate
7682 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
7684 if Is_Array_Aggr
then
7685 Comp_Type
:= Component_Type
(Etype
(N
));
7688 -- Check the ancestor part of extension aggregates, which must
7689 -- be either the name of a type that has preelaborable init or
7690 -- an expression that is preelaborable.
7692 if Nkind
(N
) = N_Extension_Aggregate
then
7694 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
7697 if Is_Entity_Name
(Anc_Part
)
7698 and then Is_Type
(Entity
(Anc_Part
))
7700 if not Has_Preelaborable_Initialization
7706 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
7712 -- Check positional associations
7714 Exp
:= First
(Expressions
(N
));
7715 while Present
(Exp
) loop
7716 if not Is_Preelaborable_Expression
(Exp
) then
7723 -- Check named associations
7725 Assn
:= First
(Component_Associations
(N
));
7726 while Present
(Assn
) loop
7727 Choice
:= First
(Choices
(Assn
));
7728 while Present
(Choice
) loop
7729 if Is_Array_Aggr
then
7730 if Nkind
(Choice
) = N_Others_Choice
then
7733 elsif Nkind
(Choice
) = N_Range
then
7734 if not Is_Static_Range
(Choice
) then
7738 elsif not Is_Static_Expression
(Choice
) then
7743 Comp_Type
:= Etype
(Choice
);
7749 -- If the association has a <> at this point, then we have
7750 -- to check whether the component's type has preelaborable
7751 -- initialization. Note that this only occurs when the
7752 -- association's corresponding component does not have a
7753 -- default expression, the latter case having already been
7754 -- expanded as an expression for the association.
7756 if Box_Present
(Assn
) then
7757 if not Has_Preelaborable_Initialization
(Comp_Type
) then
7761 -- In the expression case we check whether the expression
7762 -- is preelaborable.
7765 not Is_Preelaborable_Expression
(Expression
(Assn
))
7773 -- If we get here then aggregate as a whole is preelaborable
7777 -- All other cases are not preelaborable
7782 end Is_Preelaborable_Expression
;
7784 -- Start of processing for Check_Components
7787 -- Loop through entities of record or protected type
7790 while Present
(Ent
) loop
7792 -- We are interested only in components and discriminants
7799 -- Get default expression if any. If there is no declaration
7800 -- node, it means we have an internal entity. The parent and
7801 -- tag fields are examples of such entities. For such cases,
7802 -- we just test the type of the entity.
7804 if Present
(Declaration_Node
(Ent
)) then
7805 Exp
:= Expression
(Declaration_Node
(Ent
));
7808 when E_Discriminant
=>
7810 -- Note: for a renamed discriminant, the Declaration_Node
7811 -- may point to the one from the ancestor, and have a
7812 -- different expression, so use the proper attribute to
7813 -- retrieve the expression from the derived constraint.
7815 Exp
:= Discriminant_Default_Value
(Ent
);
7818 goto Check_Next_Entity
;
7821 -- A component has PI if it has no default expression and the
7822 -- component type has PI.
7825 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
7830 -- Require the default expression to be preelaborable
7832 elsif not Is_Preelaborable_Expression
(Exp
) then
7837 <<Check_Next_Entity
>>
7840 end Check_Components
;
7842 -- Start of processing for Has_Preelaborable_Initialization
7845 -- Immediate return if already marked as known preelaborable init. This
7846 -- covers types for which this function has already been called once
7847 -- and returned True (in which case the result is cached), and also
7848 -- types to which a pragma Preelaborable_Initialization applies.
7850 if Known_To_Have_Preelab_Init
(E
) then
7854 -- If the type is a subtype representing a generic actual type, then
7855 -- test whether its base type has preelaborable initialization since
7856 -- the subtype representing the actual does not inherit this attribute
7857 -- from the actual or formal. (but maybe it should???)
7859 if Is_Generic_Actual_Type
(E
) then
7860 return Has_Preelaborable_Initialization
(Base_Type
(E
));
7863 -- All elementary types have preelaborable initialization
7865 if Is_Elementary_Type
(E
) then
7868 -- Array types have PI if the component type has PI
7870 elsif Is_Array_Type
(E
) then
7871 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
7873 -- A derived type has preelaborable initialization if its parent type
7874 -- has preelaborable initialization and (in the case of a derived record
7875 -- extension) if the non-inherited components all have preelaborable
7876 -- initialization. However, a user-defined controlled type with an
7877 -- overriding Initialize procedure does not have preelaborable
7880 elsif Is_Derived_Type
(E
) then
7882 -- If the derived type is a private extension then it doesn't have
7883 -- preelaborable initialization.
7885 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
7889 -- First check whether ancestor type has preelaborable initialization
7891 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
7893 -- If OK, check extension components (if any)
7895 if Has_PE
and then Is_Record_Type
(E
) then
7896 Check_Components
(First_Entity
(E
));
7899 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
7900 -- with a user defined Initialize procedure does not have PI.
7903 and then Is_Controlled
(E
)
7904 and then Has_Overriding_Initialize
(E
)
7909 -- Private types not derived from a type having preelaborable init and
7910 -- that are not marked with pragma Preelaborable_Initialization do not
7911 -- have preelaborable initialization.
7913 elsif Is_Private_Type
(E
) then
7916 -- Record type has PI if it is non private and all components have PI
7918 elsif Is_Record_Type
(E
) then
7920 Check_Components
(First_Entity
(E
));
7922 -- Protected types must not have entries, and components must meet
7923 -- same set of rules as for record components.
7925 elsif Is_Protected_Type
(E
) then
7926 if Has_Entries
(E
) then
7930 Check_Components
(First_Entity
(E
));
7931 Check_Components
(First_Private_Entity
(E
));
7934 -- Type System.Address always has preelaborable initialization
7936 elsif Is_RTE
(E
, RE_Address
) then
7939 -- In all other cases, type does not have preelaborable initialization
7945 -- If type has preelaborable initialization, cache result
7948 Set_Known_To_Have_Preelab_Init
(E
);
7952 end Has_Preelaborable_Initialization
;
7954 ---------------------------
7955 -- Has_Private_Component --
7956 ---------------------------
7958 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
7959 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
7960 Component
: Entity_Id
;
7963 if Error_Posted
(Type_Id
)
7964 or else Error_Posted
(Btype
)
7969 if Is_Class_Wide_Type
(Btype
) then
7970 Btype
:= Root_Type
(Btype
);
7973 if Is_Private_Type
(Btype
) then
7975 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
7978 if No
(Full_View
(Btype
)) then
7979 return not Is_Generic_Type
(Btype
)
7980 and then not Is_Generic_Type
(Root_Type
(Btype
));
7982 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
7985 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
7989 elsif Is_Array_Type
(Btype
) then
7990 return Has_Private_Component
(Component_Type
(Btype
));
7992 elsif Is_Record_Type
(Btype
) then
7993 Component
:= First_Component
(Btype
);
7994 while Present
(Component
) loop
7995 if Has_Private_Component
(Etype
(Component
)) then
7999 Next_Component
(Component
);
8004 elsif Is_Protected_Type
(Btype
)
8005 and then Present
(Corresponding_Record_Type
(Btype
))
8007 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
8012 end Has_Private_Component
;
8014 ----------------------
8015 -- Has_Signed_Zeros --
8016 ----------------------
8018 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
8020 return Is_Floating_Point_Type
(E
)
8021 and then Signed_Zeros_On_Target
8022 and then not Vax_Float
(E
);
8023 end Has_Signed_Zeros
;
8025 -----------------------------
8026 -- Has_Static_Array_Bounds --
8027 -----------------------------
8029 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
8030 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
8037 -- Unconstrained types do not have static bounds
8039 if not Is_Constrained
(Typ
) then
8043 -- First treat string literals specially, as the lower bound and length
8044 -- of string literals are not stored like those of arrays.
8046 -- A string literal always has static bounds
8048 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8052 -- Treat all dimensions in turn
8054 Index
:= First_Index
(Typ
);
8055 for Indx
in 1 .. Ndims
loop
8057 -- In case of an erroneous index which is not a discrete type, return
8058 -- that the type is not static.
8060 if not Is_Discrete_Type
(Etype
(Index
))
8061 or else Etype
(Index
) = Any_Type
8066 Get_Index_Bounds
(Index
, Low
, High
);
8068 if Error_Posted
(Low
) or else Error_Posted
(High
) then
8072 if Is_OK_Static_Expression
(Low
)
8074 Is_OK_Static_Expression
(High
)
8084 -- If we fall through the loop, all indexes matched
8087 end Has_Static_Array_Bounds
;
8093 function Has_Stream
(T
: Entity_Id
) return Boolean is
8100 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
8103 elsif Is_Array_Type
(T
) then
8104 return Has_Stream
(Component_Type
(T
));
8106 elsif Is_Record_Type
(T
) then
8107 E
:= First_Component
(T
);
8108 while Present
(E
) loop
8109 if Has_Stream
(Etype
(E
)) then
8118 elsif Is_Private_Type
(T
) then
8119 return Has_Stream
(Underlying_Type
(T
));
8130 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
8132 Get_Name_String
(Chars
(E
));
8133 return Name_Buffer
(Name_Len
) = Suffix
;
8140 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8142 Get_Name_String
(Chars
(E
));
8143 Add_Char_To_Name_Buffer
(Suffix
);
8151 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8153 pragma Assert
(Has_Suffix
(E
, Suffix
));
8154 Get_Name_String
(Chars
(E
));
8155 Name_Len
:= Name_Len
- 1;
8159 --------------------------
8160 -- Has_Tagged_Component --
8161 --------------------------
8163 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
8167 if Is_Private_Type
(Typ
)
8168 and then Present
(Underlying_Type
(Typ
))
8170 return Has_Tagged_Component
(Underlying_Type
(Typ
));
8172 elsif Is_Array_Type
(Typ
) then
8173 return Has_Tagged_Component
(Component_Type
(Typ
));
8175 elsif Is_Tagged_Type
(Typ
) then
8178 elsif Is_Record_Type
(Typ
) then
8179 Comp
:= First_Component
(Typ
);
8180 while Present
(Comp
) loop
8181 if Has_Tagged_Component
(Etype
(Comp
)) then
8185 Next_Component
(Comp
);
8193 end Has_Tagged_Component
;
8195 ----------------------------
8196 -- Has_Volatile_Component --
8197 ----------------------------
8199 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
8203 if Has_Volatile_Components
(Typ
) then
8206 elsif Is_Array_Type
(Typ
) then
8207 return Is_Volatile
(Component_Type
(Typ
));
8209 elsif Is_Record_Type
(Typ
) then
8210 Comp
:= First_Component
(Typ
);
8211 while Present
(Comp
) loop
8212 if Is_Volatile_Object
(Comp
) then
8216 Comp
:= Next_Component
(Comp
);
8221 end Has_Volatile_Component
;
8223 -------------------------
8224 -- Implementation_Kind --
8225 -------------------------
8227 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
8228 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
8231 pragma Assert
(Present
(Impl_Prag
));
8232 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
8233 return Chars
(Get_Pragma_Arg
(Arg
));
8234 end Implementation_Kind
;
8236 --------------------------
8237 -- Implements_Interface --
8238 --------------------------
8240 function Implements_Interface
8241 (Typ_Ent
: Entity_Id
;
8242 Iface_Ent
: Entity_Id
;
8243 Exclude_Parents
: Boolean := False) return Boolean
8245 Ifaces_List
: Elist_Id
;
8247 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
8248 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
8251 if Is_Class_Wide_Type
(Typ
) then
8252 Typ
:= Root_Type
(Typ
);
8255 if not Has_Interfaces
(Typ
) then
8259 if Is_Class_Wide_Type
(Iface
) then
8260 Iface
:= Root_Type
(Iface
);
8263 Collect_Interfaces
(Typ
, Ifaces_List
);
8265 Elmt
:= First_Elmt
(Ifaces_List
);
8266 while Present
(Elmt
) loop
8267 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
8268 and then Exclude_Parents
8272 elsif Node
(Elmt
) = Iface
then
8280 end Implements_Interface
;
8286 function In_Instance
return Boolean is
8287 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
8293 and then S
/= Standard_Standard
8295 if (Ekind
(S
) = E_Function
8296 or else Ekind
(S
) = E_Package
8297 or else Ekind
(S
) = E_Procedure
)
8298 and then Is_Generic_Instance
(S
)
8300 -- A child instance is always compiled in the context of a parent
8301 -- instance. Nevertheless, the actuals are not analyzed in an
8302 -- instance context. We detect this case by examining the current
8303 -- compilation unit, which must be a child instance, and checking
8304 -- that it is not currently on the scope stack.
8306 if Is_Child_Unit
(Curr_Unit
)
8308 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
8309 = N_Package_Instantiation
8310 and then not In_Open_Scopes
(Curr_Unit
)
8324 ----------------------
8325 -- In_Instance_Body --
8326 ----------------------
8328 function In_Instance_Body
return Boolean is
8334 and then S
/= Standard_Standard
8336 if (Ekind
(S
) = E_Function
8337 or else Ekind
(S
) = E_Procedure
)
8338 and then Is_Generic_Instance
(S
)
8342 elsif Ekind
(S
) = E_Package
8343 and then In_Package_Body
(S
)
8344 and then Is_Generic_Instance
(S
)
8353 end In_Instance_Body
;
8355 -----------------------------
8356 -- In_Instance_Not_Visible --
8357 -----------------------------
8359 function In_Instance_Not_Visible
return Boolean is
8365 and then S
/= Standard_Standard
8367 if (Ekind
(S
) = E_Function
8368 or else Ekind
(S
) = E_Procedure
)
8369 and then Is_Generic_Instance
(S
)
8373 elsif Ekind
(S
) = E_Package
8374 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
8375 and then Is_Generic_Instance
(S
)
8384 end In_Instance_Not_Visible
;
8386 ------------------------------
8387 -- In_Instance_Visible_Part --
8388 ------------------------------
8390 function In_Instance_Visible_Part
return Boolean is
8396 and then S
/= Standard_Standard
8398 if Ekind
(S
) = E_Package
8399 and then Is_Generic_Instance
(S
)
8400 and then not In_Package_Body
(S
)
8401 and then not In_Private_Part
(S
)
8410 end In_Instance_Visible_Part
;
8412 ---------------------
8413 -- In_Package_Body --
8414 ---------------------
8416 function In_Package_Body
return Boolean is
8422 and then S
/= Standard_Standard
8424 if Ekind
(S
) = E_Package
8425 and then In_Package_Body
(S
)
8434 end In_Package_Body
;
8436 --------------------------------
8437 -- In_Parameter_Specification --
8438 --------------------------------
8440 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
8445 while Present
(PN
) loop
8446 if Nkind
(PN
) = N_Parameter_Specification
then
8454 end In_Parameter_Specification
;
8456 --------------------------
8457 -- In_Pragma_Expression --
8458 --------------------------
8460 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
8467 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
8473 end In_Pragma_Expression
;
8475 -------------------------------------
8476 -- In_Reverse_Storage_Order_Object --
8477 -------------------------------------
8479 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
8481 Btyp
: Entity_Id
:= Empty
;
8484 -- Climb up indexed components
8488 case Nkind
(Pref
) is
8489 when N_Selected_Component
=>
8490 Pref
:= Prefix
(Pref
);
8493 when N_Indexed_Component
=>
8494 Pref
:= Prefix
(Pref
);
8502 if Present
(Pref
) then
8503 Btyp
:= Base_Type
(Etype
(Pref
));
8508 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
8509 and then Reverse_Storage_Order
(Btyp
);
8510 end In_Reverse_Storage_Order_Object
;
8512 --------------------------------------
8513 -- In_Subprogram_Or_Concurrent_Unit --
8514 --------------------------------------
8516 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
8521 -- Use scope chain to check successively outer scopes
8527 if K
in Subprogram_Kind
8528 or else K
in Concurrent_Kind
8529 or else K
in Generic_Subprogram_Kind
8533 elsif E
= Standard_Standard
then
8539 end In_Subprogram_Or_Concurrent_Unit
;
8541 ---------------------
8542 -- In_Visible_Part --
8543 ---------------------
8545 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
8548 Is_Package_Or_Generic_Package
(Scope_Id
)
8549 and then In_Open_Scopes
(Scope_Id
)
8550 and then not In_Package_Body
(Scope_Id
)
8551 and then not In_Private_Part
(Scope_Id
);
8552 end In_Visible_Part
;
8554 --------------------------------
8555 -- Incomplete_Or_Private_View --
8556 --------------------------------
8558 function Incomplete_Or_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
8559 function Inspect_Decls
8561 Taft
: Boolean := False) return Entity_Id
;
8562 -- Check whether a declarative region contains the incomplete or private
8569 function Inspect_Decls
8571 Taft
: Boolean := False) return Entity_Id
8577 Decl
:= First
(Decls
);
8578 while Present
(Decl
) loop
8582 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
8583 Match
:= Defining_Identifier
(Decl
);
8587 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
8588 N_Private_Type_Declaration
)
8590 Match
:= Defining_Identifier
(Decl
);
8595 and then Present
(Full_View
(Match
))
8596 and then Full_View
(Match
) = Typ
8611 -- Start of processing for Incomplete_Or_Partial_View
8614 -- Incomplete type case
8616 Prev
:= Current_Entity_In_Scope
(Typ
);
8619 and then Is_Incomplete_Type
(Prev
)
8620 and then Present
(Full_View
(Prev
))
8621 and then Full_View
(Prev
) = Typ
8626 -- Private or Taft amendment type case
8629 Pkg
: constant Entity_Id
:= Scope
(Typ
);
8630 Pkg_Decl
: Node_Id
:= Pkg
;
8633 if Ekind
(Pkg
) = E_Package
then
8634 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
8635 Pkg_Decl
:= Parent
(Pkg_Decl
);
8638 -- It is knows that Typ has a private view, look for it in the
8639 -- visible declarations of the enclosing scope. A special case
8640 -- of this is when the two views have been exchanged - the full
8641 -- appears earlier than the private.
8643 if Has_Private_Declaration
(Typ
) then
8644 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
8646 -- Exchanged view case, look in the private declarations
8649 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
8654 -- Otherwise if this is the package body, then Typ is a potential
8655 -- Taft amendment type. The incomplete view should be located in
8656 -- the private declarations of the enclosing scope.
8658 elsif In_Package_Body
(Pkg
) then
8659 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
8664 -- The type has no incomplete or private view
8667 end Incomplete_Or_Private_View
;
8669 ---------------------------------
8670 -- Insert_Explicit_Dereference --
8671 ---------------------------------
8673 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
8674 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
8675 Ent
: Entity_Id
:= Empty
;
8682 Save_Interps
(N
, New_Prefix
);
8685 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
8686 Prefix
=> New_Prefix
));
8688 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
8690 if Is_Overloaded
(New_Prefix
) then
8692 -- The dereference is also overloaded, and its interpretations are
8693 -- the designated types of the interpretations of the original node.
8695 Set_Etype
(N
, Any_Type
);
8697 Get_First_Interp
(New_Prefix
, I
, It
);
8698 while Present
(It
.Nam
) loop
8701 if Is_Access_Type
(T
) then
8702 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
8705 Get_Next_Interp
(I
, It
);
8711 -- Prefix is unambiguous: mark the original prefix (which might
8712 -- Come_From_Source) as a reference, since the new (relocated) one
8713 -- won't be taken into account.
8715 if Is_Entity_Name
(New_Prefix
) then
8716 Ent
:= Entity
(New_Prefix
);
8719 -- For a retrieval of a subcomponent of some composite object,
8720 -- retrieve the ultimate entity if there is one.
8722 elsif Nkind
(New_Prefix
) = N_Selected_Component
8723 or else Nkind
(New_Prefix
) = N_Indexed_Component
8725 Pref
:= Prefix
(New_Prefix
);
8726 while Present
(Pref
)
8728 (Nkind
(Pref
) = N_Selected_Component
8729 or else Nkind
(Pref
) = N_Indexed_Component
)
8731 Pref
:= Prefix
(Pref
);
8734 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
8735 Ent
:= Entity
(Pref
);
8739 -- Place the reference on the entity node
8741 if Present
(Ent
) then
8742 Generate_Reference
(Ent
, Pref
);
8745 end Insert_Explicit_Dereference
;
8747 ------------------------------------------
8748 -- Inspect_Deferred_Constant_Completion --
8749 ------------------------------------------
8751 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
8755 Decl
:= First
(Decls
);
8756 while Present
(Decl
) loop
8758 -- Deferred constant signature
8760 if Nkind
(Decl
) = N_Object_Declaration
8761 and then Constant_Present
(Decl
)
8762 and then No
(Expression
(Decl
))
8764 -- No need to check internally generated constants
8766 and then Comes_From_Source
(Decl
)
8768 -- The constant is not completed. A full object declaration or a
8769 -- pragma Import complete a deferred constant.
8771 and then not Has_Completion
(Defining_Identifier
(Decl
))
8774 ("constant declaration requires initialization expression",
8775 Defining_Identifier
(Decl
));
8778 Decl
:= Next
(Decl
);
8780 end Inspect_Deferred_Constant_Completion
;
8782 -----------------------------
8783 -- Is_Actual_Out_Parameter --
8784 -----------------------------
8786 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
8790 Find_Actual
(N
, Formal
, Call
);
8791 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
8792 end Is_Actual_Out_Parameter
;
8794 -------------------------
8795 -- Is_Actual_Parameter --
8796 -------------------------
8798 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
8799 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
8803 when N_Parameter_Association
=>
8804 return N
= Explicit_Actual_Parameter
(Parent
(N
));
8806 when N_Subprogram_Call
=>
8807 return Is_List_Member
(N
)
8809 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
8814 end Is_Actual_Parameter
;
8816 --------------------------------
8817 -- Is_Actual_Tagged_Parameter --
8818 --------------------------------
8820 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
8824 Find_Actual
(N
, Formal
, Call
);
8825 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
8826 end Is_Actual_Tagged_Parameter
;
8828 ---------------------
8829 -- Is_Aliased_View --
8830 ---------------------
8832 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
8836 if Is_Entity_Name
(Obj
) then
8843 or else (Present
(Renamed_Object
(E
))
8844 and then Is_Aliased_View
(Renamed_Object
(E
)))))
8846 or else ((Is_Formal
(E
)
8847 or else Ekind
(E
) = E_Generic_In_Out_Parameter
8848 or else Ekind
(E
) = E_Generic_In_Parameter
)
8849 and then Is_Tagged_Type
(Etype
(E
)))
8851 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
8853 -- Current instance of type, either directly or as rewritten
8854 -- reference to the current object.
8856 or else (Is_Entity_Name
(Original_Node
(Obj
))
8857 and then Present
(Entity
(Original_Node
(Obj
)))
8858 and then Is_Type
(Entity
(Original_Node
(Obj
))))
8860 or else (Is_Type
(E
) and then E
= Current_Scope
)
8862 or else (Is_Incomplete_Or_Private_Type
(E
)
8863 and then Full_View
(E
) = Current_Scope
)
8865 -- Ada 2012 AI05-0053: the return object of an extended return
8866 -- statement is aliased if its type is immutably limited.
8868 or else (Is_Return_Object
(E
)
8869 and then Is_Limited_View
(Etype
(E
)));
8871 elsif Nkind
(Obj
) = N_Selected_Component
then
8872 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
8874 elsif Nkind
(Obj
) = N_Indexed_Component
then
8875 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
8877 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
8878 and then Has_Aliased_Components
8879 (Designated_Type
(Etype
(Prefix
(Obj
)))));
8881 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
8882 return Is_Tagged_Type
(Etype
(Obj
))
8883 and then Is_Aliased_View
(Expression
(Obj
));
8885 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
8886 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
8891 end Is_Aliased_View
;
8893 -------------------------
8894 -- Is_Ancestor_Package --
8895 -------------------------
8897 function Is_Ancestor_Package
8899 E2
: Entity_Id
) return Boolean
8906 and then Par
/= Standard_Standard
8916 end Is_Ancestor_Package
;
8918 ----------------------
8919 -- Is_Atomic_Object --
8920 ----------------------
8922 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
8924 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
8925 -- Determines if given object has atomic components
8927 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
8928 -- If prefix is an implicit dereference, examine designated type
8930 ----------------------
8931 -- Is_Atomic_Prefix --
8932 ----------------------
8934 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
8936 if Is_Access_Type
(Etype
(N
)) then
8938 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
8940 return Object_Has_Atomic_Components
(N
);
8942 end Is_Atomic_Prefix
;
8944 ----------------------------------
8945 -- Object_Has_Atomic_Components --
8946 ----------------------------------
8948 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
8950 if Has_Atomic_Components
(Etype
(N
))
8951 or else Is_Atomic
(Etype
(N
))
8955 elsif Is_Entity_Name
(N
)
8956 and then (Has_Atomic_Components
(Entity
(N
))
8957 or else Is_Atomic
(Entity
(N
)))
8961 elsif Nkind
(N
) = N_Selected_Component
8962 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
8966 elsif Nkind
(N
) = N_Indexed_Component
8967 or else Nkind
(N
) = N_Selected_Component
8969 return Is_Atomic_Prefix
(Prefix
(N
));
8974 end Object_Has_Atomic_Components
;
8976 -- Start of processing for Is_Atomic_Object
8979 -- Predicate is not relevant to subprograms
8981 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
8984 elsif Is_Atomic
(Etype
(N
))
8985 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
8989 elsif Nkind
(N
) = N_Selected_Component
8990 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
8994 elsif Nkind
(N
) = N_Indexed_Component
8995 or else Nkind
(N
) = N_Selected_Component
8997 return Is_Atomic_Prefix
(Prefix
(N
));
9002 end Is_Atomic_Object
;
9004 -------------------------
9005 -- Is_Attribute_Result --
9006 -------------------------
9008 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
9011 Nkind
(N
) = N_Attribute_Reference
9012 and then Attribute_Name
(N
) = Name_Result
;
9013 end Is_Attribute_Result
;
9015 ------------------------------------
9016 -- Is_Body_Or_Package_Declaration --
9017 ------------------------------------
9019 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
9021 return Nkind_In
(N
, N_Entry_Body
,
9023 N_Package_Declaration
,
9027 end Is_Body_Or_Package_Declaration
;
9029 -----------------------
9030 -- Is_Bounded_String --
9031 -----------------------
9033 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
9034 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
9037 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9038 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9039 -- be True for all the Bounded_String types in instances of the
9040 -- Generic_Bounded_Length generics, and for types derived from those.
9042 return Present
(Under
)
9043 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
9044 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
9045 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
9046 end Is_Bounded_String
;
9048 -------------------------
9049 -- Is_Child_Or_Sibling --
9050 -------------------------
9052 function Is_Child_Or_Sibling
9053 (Pack_1
: Entity_Id
;
9054 Pack_2
: Entity_Id
) return Boolean
9056 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
9057 -- Given an arbitrary package, return the number of "climbs" necessary
9058 -- to reach scope Standard_Standard.
9060 procedure Equalize_Depths
9061 (Pack
: in out Entity_Id
;
9063 Depth_To_Reach
: Nat
);
9064 -- Given an arbitrary package, its depth and a target depth to reach,
9065 -- climb the scope chain until the said depth is reached. The pointer
9066 -- to the package and its depth a modified during the climb.
9068 ----------------------------
9069 -- Distance_From_Standard --
9070 ----------------------------
9072 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
9079 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
9081 Scop
:= Scope
(Scop
);
9085 end Distance_From_Standard
;
9087 ---------------------
9088 -- Equalize_Depths --
9089 ---------------------
9091 procedure Equalize_Depths
9092 (Pack
: in out Entity_Id
;
9094 Depth_To_Reach
: Nat
)
9097 -- The package must be at a greater or equal depth
9099 if Depth
< Depth_To_Reach
then
9100 raise Program_Error
;
9103 -- Climb the scope chain until the desired depth is reached
9105 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
9106 Pack
:= Scope
(Pack
);
9109 end Equalize_Depths
;
9113 P_1
: Entity_Id
:= Pack_1
;
9114 P_1_Child
: Boolean := False;
9115 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
9116 P_2
: Entity_Id
:= Pack_2
;
9117 P_2_Child
: Boolean := False;
9118 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
9120 -- Start of processing for Is_Child_Or_Sibling
9124 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
9126 -- Both packages denote the same entity, therefore they cannot be
9127 -- children or siblings.
9132 -- One of the packages is at a deeper level than the other. Note that
9133 -- both may still come from differen hierarchies.
9141 elsif P_1_Depth
> P_2_Depth
then
9145 Depth_To_Reach
=> P_2_Depth
);
9154 elsif P_2_Depth
> P_1_Depth
then
9158 Depth_To_Reach
=> P_1_Depth
);
9162 -- At this stage the package pointers have been elevated to the same
9163 -- depth. If the related entities are the same, then one package is a
9164 -- potential child of the other:
9168 -- X became P_1 P_2 or vica versa
9174 return Is_Child_Unit
(Pack_1
);
9176 else pragma Assert
(P_2_Child
);
9177 return Is_Child_Unit
(Pack_2
);
9180 -- The packages may come from the same package chain or from entirely
9181 -- different hierarcies. To determine this, climb the scope stack until
9182 -- a common root is found.
9184 -- (root) (root 1) (root 2)
9189 while Present
(P_1
) and then Present
(P_2
) loop
9191 -- The two packages may be siblings
9194 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
9203 end Is_Child_Or_Sibling
;
9205 -----------------------------
9206 -- Is_Concurrent_Interface --
9207 -----------------------------
9209 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
9214 (Is_Protected_Interface
(T
)
9215 or else Is_Synchronized_Interface
(T
)
9216 or else Is_Task_Interface
(T
));
9217 end Is_Concurrent_Interface
;
9219 -----------------------
9220 -- Is_Constant_Bound --
9221 -----------------------
9223 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
9225 if Compile_Time_Known_Value
(Exp
) then
9228 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
9229 return Is_Constant_Object
(Entity
(Exp
))
9230 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
9232 elsif Nkind
(Exp
) in N_Binary_Op
then
9233 return Is_Constant_Bound
(Left_Opnd
(Exp
))
9234 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
9235 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
9240 end Is_Constant_Bound
;
9242 --------------------------------------
9243 -- Is_Controlling_Limited_Procedure --
9244 --------------------------------------
9246 function Is_Controlling_Limited_Procedure
9247 (Proc_Nam
: Entity_Id
) return Boolean
9249 Param_Typ
: Entity_Id
:= Empty
;
9252 if Ekind
(Proc_Nam
) = E_Procedure
9253 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
9255 Param_Typ
:= Etype
(Parameter_Type
(First
(
9256 Parameter_Specifications
(Parent
(Proc_Nam
)))));
9258 -- In this case where an Itype was created, the procedure call has been
9261 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
9262 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
9264 Present
(Parameter_Associations
9265 (Associated_Node_For_Itype
(Proc_Nam
)))
9268 Etype
(First
(Parameter_Associations
9269 (Associated_Node_For_Itype
(Proc_Nam
))));
9272 if Present
(Param_Typ
) then
9274 Is_Interface
(Param_Typ
)
9275 and then Is_Limited_Record
(Param_Typ
);
9279 end Is_Controlling_Limited_Procedure
;
9281 -----------------------------
9282 -- Is_CPP_Constructor_Call --
9283 -----------------------------
9285 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
9287 return Nkind
(N
) = N_Function_Call
9288 and then Is_CPP_Class
(Etype
(Etype
(N
)))
9289 and then Is_Constructor
(Entity
(Name
(N
)))
9290 and then Is_Imported
(Entity
(Name
(N
)));
9291 end Is_CPP_Constructor_Call
;
9297 function Is_Delegate
(T
: Entity_Id
) return Boolean is
9298 Desig_Type
: Entity_Id
;
9301 if VM_Target
/= CLI_Target
then
9305 -- Access-to-subprograms are delegates in CIL
9307 if Ekind
(T
) = E_Access_Subprogram_Type
then
9311 if Ekind
(T
) not in Access_Kind
then
9313 -- A delegate is a managed pointer. If no designated type is defined
9314 -- it means that it's not a delegate.
9319 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
9321 if not Is_Tagged_Type
(Desig_Type
) then
9325 -- Test if the type is inherited from [mscorlib]System.Delegate
9327 while Etype
(Desig_Type
) /= Desig_Type
loop
9328 if Chars
(Scope
(Desig_Type
)) /= No_Name
9329 and then Is_Imported
(Scope
(Desig_Type
))
9330 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
9335 Desig_Type
:= Etype
(Desig_Type
);
9341 ----------------------------------------------
9342 -- Is_Dependent_Component_Of_Mutable_Object --
9343 ----------------------------------------------
9345 function Is_Dependent_Component_Of_Mutable_Object
9346 (Object
: Node_Id
) return Boolean
9349 Prefix_Type
: Entity_Id
;
9350 P_Aliased
: Boolean := False;
9353 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
9354 -- Returns True if and only if Comp is declared within a variant part
9356 --------------------------------
9357 -- Is_Declared_Within_Variant --
9358 --------------------------------
9360 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
9361 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
9362 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
9364 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
9365 end Is_Declared_Within_Variant
;
9367 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
9370 if Is_Variable
(Object
) then
9372 if Nkind
(Object
) = N_Selected_Component
then
9373 P
:= Prefix
(Object
);
9374 Prefix_Type
:= Etype
(P
);
9376 if Is_Entity_Name
(P
) then
9378 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
9379 Prefix_Type
:= Base_Type
(Prefix_Type
);
9382 if Is_Aliased
(Entity
(P
)) then
9386 -- A discriminant check on a selected component may be expanded
9387 -- into a dereference when removing side-effects. Recover the
9388 -- original node and its type, which may be unconstrained.
9390 elsif Nkind
(P
) = N_Explicit_Dereference
9391 and then not (Comes_From_Source
(P
))
9393 P
:= Original_Node
(P
);
9394 Prefix_Type
:= Etype
(P
);
9397 -- Check for prefix being an aliased component???
9403 -- A heap object is constrained by its initial value
9405 -- Ada 2005 (AI-363): Always assume the object could be mutable in
9406 -- the dereferenced case, since the access value might denote an
9407 -- unconstrained aliased object, whereas in Ada 95 the designated
9408 -- object is guaranteed to be constrained. A worst-case assumption
9409 -- has to apply in Ada 2005 because we can't tell at compile time
9410 -- whether the object is "constrained by its initial value"
9411 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
9412 -- semantic rules -- these rules are acknowledged to need fixing).
9414 if Ada_Version
< Ada_2005
then
9415 if Is_Access_Type
(Prefix_Type
)
9416 or else Nkind
(P
) = N_Explicit_Dereference
9421 elsif Ada_Version
>= Ada_2005
then
9422 if Is_Access_Type
(Prefix_Type
) then
9424 -- If the access type is pool-specific, and there is no
9425 -- constrained partial view of the designated type, then the
9426 -- designated object is known to be constrained.
9428 if Ekind
(Prefix_Type
) = E_Access_Type
9429 and then not Object_Type_Has_Constrained_Partial_View
9430 (Typ
=> Designated_Type
(Prefix_Type
),
9431 Scop
=> Current_Scope
)
9435 -- Otherwise (general access type, or there is a constrained
9436 -- partial view of the designated type), we need to check
9437 -- based on the designated type.
9440 Prefix_Type
:= Designated_Type
(Prefix_Type
);
9446 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
9448 -- As per AI-0017, the renaming is illegal in a generic body, even
9449 -- if the subtype is indefinite.
9451 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
9453 if not Is_Constrained
(Prefix_Type
)
9454 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
9456 (Is_Generic_Type
(Prefix_Type
)
9457 and then Ekind
(Current_Scope
) = E_Generic_Package
9458 and then In_Package_Body
(Current_Scope
)))
9460 and then (Is_Declared_Within_Variant
(Comp
)
9461 or else Has_Discriminant_Dependent_Constraint
(Comp
))
9462 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
9466 -- If the prefix is of an access type at this point, then we want
9467 -- to return False, rather than calling this function recursively
9468 -- on the access object (which itself might be a discriminant-
9469 -- dependent component of some other object, but that isn't
9470 -- relevant to checking the object passed to us). This avoids
9471 -- issuing wrong errors when compiling with -gnatc, where there
9472 -- can be implicit dereferences that have not been expanded.
9474 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
9479 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
9482 elsif Nkind
(Object
) = N_Indexed_Component
9483 or else Nkind
(Object
) = N_Slice
9485 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
9487 -- A type conversion that Is_Variable is a view conversion:
9488 -- go back to the denoted object.
9490 elsif Nkind
(Object
) = N_Type_Conversion
then
9492 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
9497 end Is_Dependent_Component_Of_Mutable_Object
;
9499 ---------------------
9500 -- Is_Dereferenced --
9501 ---------------------
9503 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
9504 P
: constant Node_Id
:= Parent
(N
);
9507 (Nkind
(P
) = N_Selected_Component
9509 Nkind
(P
) = N_Explicit_Dereference
9511 Nkind
(P
) = N_Indexed_Component
9513 Nkind
(P
) = N_Slice
)
9514 and then Prefix
(P
) = N
;
9515 end Is_Dereferenced
;
9517 ----------------------
9518 -- Is_Descendent_Of --
9519 ----------------------
9521 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
9526 pragma Assert
(Nkind
(T1
) in N_Entity
);
9527 pragma Assert
(Nkind
(T2
) in N_Entity
);
9529 T
:= Base_Type
(T1
);
9531 -- Immediate return if the types match
9536 -- Comment needed here ???
9538 elsif Ekind
(T
) = E_Class_Wide_Type
then
9539 return Etype
(T
) = T2
;
9547 -- Done if we found the type we are looking for
9552 -- Done if no more derivations to check
9559 -- Following test catches error cases resulting from prev errors
9561 elsif No
(Etyp
) then
9564 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
9567 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
9571 T
:= Base_Type
(Etyp
);
9574 end Is_Descendent_Of
;
9576 ----------------------------
9577 -- Is_Expression_Function --
9578 ----------------------------
9580 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
9584 if Ekind
(Subp
) /= E_Function
then
9588 Decl
:= Unit_Declaration_Node
(Subp
);
9589 return Nkind
(Decl
) = N_Subprogram_Declaration
9591 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
9593 (Present
(Corresponding_Body
(Decl
))
9595 Nkind
(Original_Node
9596 (Unit_Declaration_Node
9597 (Corresponding_Body
(Decl
)))) =
9598 N_Expression_Function
));
9600 end Is_Expression_Function
;
9606 function Is_False
(U
: Uint
) return Boolean is
9611 ---------------------------
9612 -- Is_Fixed_Model_Number --
9613 ---------------------------
9615 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
9616 S
: constant Ureal
:= Small_Value
(T
);
9617 M
: Urealp
.Save_Mark
;
9621 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
9624 end Is_Fixed_Model_Number
;
9626 -------------------------------
9627 -- Is_Fully_Initialized_Type --
9628 -------------------------------
9630 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
9632 -- In Ada2012, a scalar type with an aspect Default_Value
9633 -- is fully initialized.
9635 if Is_Scalar_Type
(Typ
) then
9636 return Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
);
9638 elsif Is_Access_Type
(Typ
) then
9641 elsif Is_Array_Type
(Typ
) then
9642 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
9643 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
9648 -- An interesting case, if we have a constrained type one of whose
9649 -- bounds is known to be null, then there are no elements to be
9650 -- initialized, so all the elements are initialized.
9652 if Is_Constrained
(Typ
) then
9655 Indx_Typ
: Entity_Id
;
9659 Indx
:= First_Index
(Typ
);
9660 while Present
(Indx
) loop
9661 if Etype
(Indx
) = Any_Type
then
9664 -- If index is a range, use directly
9666 elsif Nkind
(Indx
) = N_Range
then
9667 Lbd
:= Low_Bound
(Indx
);
9668 Hbd
:= High_Bound
(Indx
);
9671 Indx_Typ
:= Etype
(Indx
);
9673 if Is_Private_Type
(Indx_Typ
) then
9674 Indx_Typ
:= Full_View
(Indx_Typ
);
9677 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
9680 Lbd
:= Type_Low_Bound
(Indx_Typ
);
9681 Hbd
:= Type_High_Bound
(Indx_Typ
);
9685 if Compile_Time_Known_Value
(Lbd
)
9686 and then Compile_Time_Known_Value
(Hbd
)
9688 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
9698 -- If no null indexes, then type is not fully initialized
9704 elsif Is_Record_Type
(Typ
) then
9705 if Has_Discriminants
(Typ
)
9707 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
9708 and then Is_Fully_Initialized_Variant
(Typ
)
9713 -- We consider bounded string types to be fully initialized, because
9714 -- otherwise we get false alarms when the Data component is not
9715 -- default-initialized.
9717 if Is_Bounded_String
(Typ
) then
9721 -- Controlled records are considered to be fully initialized if
9722 -- there is a user defined Initialize routine. This may not be
9723 -- entirely correct, but as the spec notes, we are guessing here
9724 -- what is best from the point of view of issuing warnings.
9726 if Is_Controlled
(Typ
) then
9728 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
9731 if Present
(Utyp
) then
9733 Init
: constant Entity_Id
:=
9735 (Underlying_Type
(Typ
), Name_Initialize
));
9739 and then Comes_From_Source
(Init
)
9741 Is_Predefined_File_Name
9742 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
9746 elsif Has_Null_Extension
(Typ
)
9748 Is_Fully_Initialized_Type
9749 (Etype
(Base_Type
(Typ
)))
9758 -- Otherwise see if all record components are initialized
9764 Ent
:= First_Entity
(Typ
);
9765 while Present
(Ent
) loop
9766 if Ekind
(Ent
) = E_Component
9767 and then (No
(Parent
(Ent
))
9768 or else No
(Expression
(Parent
(Ent
))))
9769 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
9771 -- Special VM case for tag components, which need to be
9772 -- defined in this case, but are never initialized as VMs
9773 -- are using other dispatching mechanisms. Ignore this
9774 -- uninitialized case. Note that this applies both to the
9775 -- uTag entry and the main vtable pointer (CPP_Class case).
9777 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
9786 -- No uninitialized components, so type is fully initialized.
9787 -- Note that this catches the case of no components as well.
9791 elsif Is_Concurrent_Type
(Typ
) then
9794 elsif Is_Private_Type
(Typ
) then
9796 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
9802 return Is_Fully_Initialized_Type
(U
);
9809 end Is_Fully_Initialized_Type
;
9811 ----------------------------------
9812 -- Is_Fully_Initialized_Variant --
9813 ----------------------------------
9815 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
9816 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
9817 Constraints
: constant List_Id
:= New_List
;
9818 Components
: constant Elist_Id
:= New_Elmt_List
;
9819 Comp_Elmt
: Elmt_Id
;
9821 Comp_List
: Node_Id
;
9823 Discr_Val
: Node_Id
;
9825 Report_Errors
: Boolean;
9826 pragma Warnings
(Off
, Report_Errors
);
9829 if Serious_Errors_Detected
> 0 then
9833 if Is_Record_Type
(Typ
)
9834 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
9835 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
9837 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
9839 Discr
:= First_Discriminant
(Typ
);
9840 while Present
(Discr
) loop
9841 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
9842 Discr_Val
:= Expression
(Parent
(Discr
));
9844 if Present
(Discr_Val
)
9845 and then Is_OK_Static_Expression
(Discr_Val
)
9847 Append_To
(Constraints
,
9848 Make_Component_Association
(Loc
,
9849 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
9850 Expression
=> New_Copy
(Discr_Val
)));
9858 Next_Discriminant
(Discr
);
9863 Comp_List
=> Comp_List
,
9864 Governed_By
=> Constraints
,
9866 Report_Errors
=> Report_Errors
);
9868 -- Check that each component present is fully initialized
9870 Comp_Elmt
:= First_Elmt
(Components
);
9871 while Present
(Comp_Elmt
) loop
9872 Comp_Id
:= Node
(Comp_Elmt
);
9874 if Ekind
(Comp_Id
) = E_Component
9875 and then (No
(Parent
(Comp_Id
))
9876 or else No
(Expression
(Parent
(Comp_Id
))))
9877 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
9882 Next_Elmt
(Comp_Elmt
);
9887 elsif Is_Private_Type
(Typ
) then
9889 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
9895 return Is_Fully_Initialized_Variant
(U
);
9902 end Is_Fully_Initialized_Variant
;
9904 ----------------------------
9905 -- Is_Inherited_Operation --
9906 ----------------------------
9908 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
9909 pragma Assert
(Is_Overloadable
(E
));
9910 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
9912 return Kind
= N_Full_Type_Declaration
9913 or else Kind
= N_Private_Extension_Declaration
9914 or else Kind
= N_Subtype_Declaration
9915 or else (Ekind
(E
) = E_Enumeration_Literal
9916 and then Is_Derived_Type
(Etype
(E
)));
9917 end Is_Inherited_Operation
;
9919 -------------------------------------
9920 -- Is_Inherited_Operation_For_Type --
9921 -------------------------------------
9923 function Is_Inherited_Operation_For_Type
9925 Typ
: Entity_Id
) return Boolean
9928 -- Check that the operation has been created by the type declaration
9930 return Is_Inherited_Operation
(E
)
9931 and then Defining_Identifier
(Parent
(E
)) = Typ
;
9932 end Is_Inherited_Operation_For_Type
;
9938 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
9939 Ifaces_List
: Elist_Id
;
9940 Iface_Elmt
: Elmt_Id
;
9944 if Is_Class_Wide_Type
(Typ
)
9946 Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
9947 Name_Reversible_Iterator
)
9949 Is_Predefined_File_Name
9950 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
9954 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
9958 Collect_Interfaces
(Typ
, Ifaces_List
);
9960 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
9961 while Present
(Iface_Elmt
) loop
9962 Iface
:= Node
(Iface_Elmt
);
9963 if Chars
(Iface
) = Name_Forward_Iterator
9965 Is_Predefined_File_Name
9966 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
9971 Next_Elmt
(Iface_Elmt
);
9982 -- We seem to have a lot of overlapping functions that do similar things
9983 -- (testing for left hand sides or lvalues???).
9985 function Is_LHS
(N
: Node_Id
) return Boolean is
9986 P
: constant Node_Id
:= Parent
(N
);
9989 -- Return True if we are the left hand side of an assignment statement
9991 if Nkind
(P
) = N_Assignment_Statement
then
9992 return Name
(P
) = N
;
9994 -- Case of prefix of indexed or selected component or slice
9996 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
9997 and then N
= Prefix
(P
)
9999 -- Here we have the case where the parent P is N.Q or N(Q .. R).
10000 -- If P is an LHS, then N is also effectively an LHS, but there
10001 -- is an important exception. If N is of an access type, then
10002 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
10003 -- case this makes N.all a left hand side but not N itself.
10005 -- Here follows a worrisome kludge. If Etype (N) is not set, which
10006 -- for sure happens in the call from Find_Direct_Name, that means we
10007 -- don't know if N is of an access type, so we can't give an accurate
10008 -- answer. For now, we assume we do not have an access type, which
10009 -- means for example that P.Q.R := X will look like a modification
10010 -- of P, even if P.Q eventually turns out to be an access type. The
10011 -- consequence is at least that in some cases we incorrectly identify
10012 -- a reference as a modification. It is not clear if there are any
10013 -- other bad consequences. ???
10015 if No
(Etype
(N
)) then
10018 -- We have an Etype set, so we can check it
10020 elsif Is_Access_Type
(Etype
(N
)) then
10023 -- OK, not access type case, so just test whole expression
10029 -- All other cases are not left hand sides
10036 -----------------------------
10037 -- Is_Library_Level_Entity --
10038 -----------------------------
10040 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
10042 -- The following is a small optimization, and it also properly handles
10043 -- discriminals, which in task bodies might appear in expressions before
10044 -- the corresponding procedure has been created, and which therefore do
10045 -- not have an assigned scope.
10047 if Is_Formal
(E
) then
10051 -- Normal test is simply that the enclosing dynamic scope is Standard
10053 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
10054 end Is_Library_Level_Entity
;
10056 --------------------------------
10057 -- Is_Limited_Class_Wide_Type --
10058 --------------------------------
10060 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
10063 Is_Class_Wide_Type
(Typ
)
10064 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
10065 end Is_Limited_Class_Wide_Type
;
10067 ---------------------------------
10068 -- Is_Local_Variable_Reference --
10069 ---------------------------------
10071 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
10073 if not Is_Entity_Name
(Expr
) then
10078 Ent
: constant Entity_Id
:= Entity
(Expr
);
10079 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
10081 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
10084 return Present
(Sub
) and then Sub
= Current_Subprogram
;
10088 end Is_Local_Variable_Reference
;
10090 -------------------------
10091 -- Is_Object_Reference --
10092 -------------------------
10094 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
10096 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
10097 -- Determine whether N is the name of an internally-generated renaming
10099 --------------------------------------
10100 -- Is_Internally_Generated_Renaming --
10101 --------------------------------------
10103 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
10108 while Present
(P
) loop
10109 if Nkind
(P
) = N_Object_Renaming_Declaration
then
10110 return not Comes_From_Source
(P
);
10111 elsif Is_List_Member
(P
) then
10119 end Is_Internally_Generated_Renaming
;
10121 -- Start of processing for Is_Object_Reference
10124 if Is_Entity_Name
(N
) then
10125 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
10129 when N_Indexed_Component | N_Slice
=>
10131 Is_Object_Reference
(Prefix
(N
))
10132 or else Is_Access_Type
(Etype
(Prefix
(N
)));
10134 -- In Ada 95, a function call is a constant object; a procedure
10137 when N_Function_Call
=>
10138 return Etype
(N
) /= Standard_Void_Type
;
10140 -- Attributes 'Input, 'Old and 'Result produce objects
10142 when N_Attribute_Reference
=>
10145 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
10147 when N_Selected_Component
=>
10149 Is_Object_Reference
(Selector_Name
(N
))
10151 (Is_Object_Reference
(Prefix
(N
))
10152 or else Is_Access_Type
(Etype
(Prefix
(N
))));
10154 when N_Explicit_Dereference
=>
10157 -- A view conversion of a tagged object is an object reference
10159 when N_Type_Conversion
=>
10160 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
10161 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
10162 and then Is_Object_Reference
(Expression
(N
));
10164 -- An unchecked type conversion is considered to be an object if
10165 -- the operand is an object (this construction arises only as a
10166 -- result of expansion activities).
10168 when N_Unchecked_Type_Conversion
=>
10171 -- Allow string literals to act as objects as long as they appear
10172 -- in internally-generated renamings. The expansion of iterators
10173 -- may generate such renamings when the range involves a string
10176 when N_String_Literal
=>
10177 return Is_Internally_Generated_Renaming
(Parent
(N
));
10179 -- AI05-0003: In Ada 2012 a qualified expression is a name.
10180 -- This allows disambiguation of function calls and the use
10181 -- of aggregates in more contexts.
10183 when N_Qualified_Expression
=>
10184 if Ada_Version
< Ada_2012
then
10187 return Is_Object_Reference
(Expression
(N
))
10188 or else Nkind
(Expression
(N
)) = N_Aggregate
;
10195 end Is_Object_Reference
;
10197 -----------------------------------
10198 -- Is_OK_Variable_For_Out_Formal --
10199 -----------------------------------
10201 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
10203 Note_Possible_Modification
(AV
, Sure
=> True);
10205 -- We must reject parenthesized variable names. Comes_From_Source is
10206 -- checked because there are currently cases where the compiler violates
10207 -- this rule (e.g. passing a task object to its controlled Initialize
10208 -- routine). This should be properly documented in sinfo???
10210 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
10213 -- A variable is always allowed
10215 elsif Is_Variable
(AV
) then
10218 -- Unchecked conversions are allowed only if they come from the
10219 -- generated code, which sometimes uses unchecked conversions for out
10220 -- parameters in cases where code generation is unaffected. We tell
10221 -- source unchecked conversions by seeing if they are rewrites of
10222 -- an original Unchecked_Conversion function call, or of an explicit
10223 -- conversion of a function call or an aggregate (as may happen in the
10224 -- expansion of a packed array aggregate).
10226 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
10227 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
10230 elsif Comes_From_Source
(AV
)
10231 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
10235 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
10236 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
10242 -- Normal type conversions are allowed if argument is a variable
10244 elsif Nkind
(AV
) = N_Type_Conversion
then
10245 if Is_Variable
(Expression
(AV
))
10246 and then Paren_Count
(Expression
(AV
)) = 0
10248 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
10251 -- We also allow a non-parenthesized expression that raises
10252 -- constraint error if it rewrites what used to be a variable
10254 elsif Raises_Constraint_Error
(Expression
(AV
))
10255 and then Paren_Count
(Expression
(AV
)) = 0
10256 and then Is_Variable
(Original_Node
(Expression
(AV
)))
10260 -- Type conversion of something other than a variable
10266 -- If this node is rewritten, then test the original form, if that is
10267 -- OK, then we consider the rewritten node OK (for example, if the
10268 -- original node is a conversion, then Is_Variable will not be true
10269 -- but we still want to allow the conversion if it converts a variable).
10271 elsif Original_Node
(AV
) /= AV
then
10273 -- In Ada 2012, the explicit dereference may be a rewritten call to a
10274 -- Reference function.
10276 if Ada_Version
>= Ada_2012
10277 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
10279 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
10284 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
10287 -- All other non-variables are rejected
10292 end Is_OK_Variable_For_Out_Formal
;
10294 -----------------------------------
10295 -- Is_Partially_Initialized_Type --
10296 -----------------------------------
10298 function Is_Partially_Initialized_Type
10300 Include_Implicit
: Boolean := True) return Boolean
10303 if Is_Scalar_Type
(Typ
) then
10306 elsif Is_Access_Type
(Typ
) then
10307 return Include_Implicit
;
10309 elsif Is_Array_Type
(Typ
) then
10311 -- If component type is partially initialized, so is array type
10313 if Is_Partially_Initialized_Type
10314 (Component_Type
(Typ
), Include_Implicit
)
10318 -- Otherwise we are only partially initialized if we are fully
10319 -- initialized (this is the empty array case, no point in us
10320 -- duplicating that code here).
10323 return Is_Fully_Initialized_Type
(Typ
);
10326 elsif Is_Record_Type
(Typ
) then
10328 -- A discriminated type is always partially initialized if in
10331 if Has_Discriminants
(Typ
) and then Include_Implicit
then
10334 -- A tagged type is always partially initialized
10336 elsif Is_Tagged_Type
(Typ
) then
10339 -- Case of non-discriminated record
10345 Component_Present
: Boolean := False;
10346 -- Set True if at least one component is present. If no
10347 -- components are present, then record type is fully
10348 -- initialized (another odd case, like the null array).
10351 -- Loop through components
10353 Ent
:= First_Entity
(Typ
);
10354 while Present
(Ent
) loop
10355 if Ekind
(Ent
) = E_Component
then
10356 Component_Present
:= True;
10358 -- If a component has an initialization expression then
10359 -- the enclosing record type is partially initialized
10361 if Present
(Parent
(Ent
))
10362 and then Present
(Expression
(Parent
(Ent
)))
10366 -- If a component is of a type which is itself partially
10367 -- initialized, then the enclosing record type is also.
10369 elsif Is_Partially_Initialized_Type
10370 (Etype
(Ent
), Include_Implicit
)
10379 -- No initialized components found. If we found any components
10380 -- they were all uninitialized so the result is false.
10382 if Component_Present
then
10385 -- But if we found no components, then all the components are
10386 -- initialized so we consider the type to be initialized.
10394 -- Concurrent types are always fully initialized
10396 elsif Is_Concurrent_Type
(Typ
) then
10399 -- For a private type, go to underlying type. If there is no underlying
10400 -- type then just assume this partially initialized. Not clear if this
10401 -- can happen in a non-error case, but no harm in testing for this.
10403 elsif Is_Private_Type
(Typ
) then
10405 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10410 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
10414 -- For any other type (are there any?) assume partially initialized
10419 end Is_Partially_Initialized_Type
;
10421 ------------------------------------
10422 -- Is_Potentially_Persistent_Type --
10423 ------------------------------------
10425 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
10430 -- For private type, test corresponding full type
10432 if Is_Private_Type
(T
) then
10433 return Is_Potentially_Persistent_Type
(Full_View
(T
));
10435 -- Scalar types are potentially persistent
10437 elsif Is_Scalar_Type
(T
) then
10440 -- Record type is potentially persistent if not tagged and the types of
10441 -- all it components are potentially persistent, and no component has
10442 -- an initialization expression.
10444 elsif Is_Record_Type
(T
)
10445 and then not Is_Tagged_Type
(T
)
10446 and then not Is_Partially_Initialized_Type
(T
)
10448 Comp
:= First_Component
(T
);
10449 while Present
(Comp
) loop
10450 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
10453 Next_Entity
(Comp
);
10459 -- Array type is potentially persistent if its component type is
10460 -- potentially persistent and if all its constraints are static.
10462 elsif Is_Array_Type
(T
) then
10463 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
10467 Indx
:= First_Index
(T
);
10468 while Present
(Indx
) loop
10469 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
10478 -- All other types are not potentially persistent
10483 end Is_Potentially_Persistent_Type
;
10485 --------------------------------
10486 -- Is_Potentially_Unevaluated --
10487 --------------------------------
10489 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
10496 while not Nkind_In
(Par
, N_If_Expression
,
10504 Par
:= Parent
(Par
);
10506 -- If the context is not an expression, or if is the result of
10507 -- expansion of an enclosing construct (such as another attribute)
10508 -- the predicate does not apply.
10510 if Nkind
(Par
) not in N_Subexpr
10511 or else not Comes_From_Source
(Par
)
10517 if Nkind
(Par
) = N_If_Expression
then
10518 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
10520 elsif Nkind
(Par
) = N_Case_Expression
then
10521 return Expr
/= Expression
(Par
);
10523 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
10524 return Expr
= Right_Opnd
(Par
);
10526 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
10527 return Expr
/= Left_Opnd
(Par
);
10532 end Is_Potentially_Unevaluated
;
10534 ---------------------------------
10535 -- Is_Protected_Self_Reference --
10536 ---------------------------------
10538 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
10540 function In_Access_Definition
(N
: Node_Id
) return Boolean;
10541 -- Returns true if N belongs to an access definition
10543 --------------------------
10544 -- In_Access_Definition --
10545 --------------------------
10547 function In_Access_Definition
(N
: Node_Id
) return Boolean is
10552 while Present
(P
) loop
10553 if Nkind
(P
) = N_Access_Definition
then
10561 end In_Access_Definition
;
10563 -- Start of processing for Is_Protected_Self_Reference
10566 -- Verify that prefix is analyzed and has the proper form. Note that
10567 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
10568 -- which also produce the address of an entity, do not analyze their
10569 -- prefix because they denote entities that are not necessarily visible.
10570 -- Neither of them can apply to a protected type.
10572 return Ada_Version
>= Ada_2005
10573 and then Is_Entity_Name
(N
)
10574 and then Present
(Entity
(N
))
10575 and then Is_Protected_Type
(Entity
(N
))
10576 and then In_Open_Scopes
(Entity
(N
))
10577 and then not In_Access_Definition
(N
);
10578 end Is_Protected_Self_Reference
;
10580 -----------------------------
10581 -- Is_RCI_Pkg_Spec_Or_Body --
10582 -----------------------------
10584 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
10586 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
10587 -- Return True if the unit of Cunit is an RCI package declaration
10589 ---------------------------
10590 -- Is_RCI_Pkg_Decl_Cunit --
10591 ---------------------------
10593 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
10594 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
10597 if Nkind
(The_Unit
) /= N_Package_Declaration
then
10601 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
10602 end Is_RCI_Pkg_Decl_Cunit
;
10604 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
10607 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
10609 (Nkind
(Unit
(Cunit
)) = N_Package_Body
10610 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
10611 end Is_RCI_Pkg_Spec_Or_Body
;
10613 -----------------------------------------
10614 -- Is_Remote_Access_To_Class_Wide_Type --
10615 -----------------------------------------
10617 function Is_Remote_Access_To_Class_Wide_Type
10618 (E
: Entity_Id
) return Boolean
10621 -- A remote access to class-wide type is a general access to object type
10622 -- declared in the visible part of a Remote_Types or Remote_Call_
10625 return Ekind
(E
) = E_General_Access_Type
10626 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
10627 end Is_Remote_Access_To_Class_Wide_Type
;
10629 -----------------------------------------
10630 -- Is_Remote_Access_To_Subprogram_Type --
10631 -----------------------------------------
10633 function Is_Remote_Access_To_Subprogram_Type
10634 (E
: Entity_Id
) return Boolean
10637 return (Ekind
(E
) = E_Access_Subprogram_Type
10638 or else (Ekind
(E
) = E_Record_Type
10639 and then Present
(Corresponding_Remote_Type
(E
))))
10640 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
10641 end Is_Remote_Access_To_Subprogram_Type
;
10643 --------------------
10644 -- Is_Remote_Call --
10645 --------------------
10647 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
10649 if Nkind
(N
) not in N_Subprogram_Call
then
10651 -- An entry call cannot be remote
10655 elsif Nkind
(Name
(N
)) in N_Has_Entity
10656 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
10658 -- A subprogram declared in the spec of a RCI package is remote
10662 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
10663 and then Is_Remote_Access_To_Subprogram_Type
10664 (Etype
(Prefix
(Name
(N
))))
10666 -- The dereference of a RAS is a remote call
10670 elsif Present
(Controlling_Argument
(N
))
10671 and then Is_Remote_Access_To_Class_Wide_Type
10672 (Etype
(Controlling_Argument
(N
)))
10674 -- Any primitive operation call with a controlling argument of
10675 -- a RACW type is a remote call.
10680 -- All other calls are local calls
10683 end Is_Remote_Call
;
10685 ----------------------
10686 -- Is_Renamed_Entry --
10687 ----------------------
10689 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
10690 Orig_Node
: Node_Id
:= Empty
;
10691 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
10693 function Is_Entry
(Nam
: Node_Id
) return Boolean;
10694 -- Determine whether Nam is an entry. Traverse selectors if there are
10695 -- nested selected components.
10701 function Is_Entry
(Nam
: Node_Id
) return Boolean is
10703 if Nkind
(Nam
) = N_Selected_Component
then
10704 return Is_Entry
(Selector_Name
(Nam
));
10707 return Ekind
(Entity
(Nam
)) = E_Entry
;
10710 -- Start of processing for Is_Renamed_Entry
10713 if Present
(Alias
(Proc_Nam
)) then
10714 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
10717 -- Look for a rewritten subprogram renaming declaration
10719 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
10720 and then Present
(Original_Node
(Subp_Decl
))
10722 Orig_Node
:= Original_Node
(Subp_Decl
);
10725 -- The rewritten subprogram is actually an entry
10727 if Present
(Orig_Node
)
10728 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
10729 and then Is_Entry
(Name
(Orig_Node
))
10735 end Is_Renamed_Entry
;
10737 ----------------------------
10738 -- Is_Reversible_Iterator --
10739 ----------------------------
10741 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
10742 Ifaces_List
: Elist_Id
;
10743 Iface_Elmt
: Elmt_Id
;
10747 if Is_Class_Wide_Type
(Typ
)
10748 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
10750 Is_Predefined_File_Name
10751 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
10755 elsif not Is_Tagged_Type
(Typ
)
10756 or else not Is_Derived_Type
(Typ
)
10761 Collect_Interfaces
(Typ
, Ifaces_List
);
10763 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
10764 while Present
(Iface_Elmt
) loop
10765 Iface
:= Node
(Iface_Elmt
);
10766 if Chars
(Iface
) = Name_Reversible_Iterator
10768 Is_Predefined_File_Name
10769 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
10774 Next_Elmt
(Iface_Elmt
);
10779 end Is_Reversible_Iterator
;
10781 ----------------------
10782 -- Is_Selector_Name --
10783 ----------------------
10785 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
10787 if not Is_List_Member
(N
) then
10789 P
: constant Node_Id
:= Parent
(N
);
10790 K
: constant Node_Kind
:= Nkind
(P
);
10793 (K
= N_Expanded_Name
or else
10794 K
= N_Generic_Association
or else
10795 K
= N_Parameter_Association
or else
10796 K
= N_Selected_Component
)
10797 and then Selector_Name
(P
) = N
;
10802 L
: constant List_Id
:= List_Containing
(N
);
10803 P
: constant Node_Id
:= Parent
(L
);
10805 return (Nkind
(P
) = N_Discriminant_Association
10806 and then Selector_Names
(P
) = L
)
10808 (Nkind
(P
) = N_Component_Association
10809 and then Choices
(P
) = L
);
10812 end Is_Selector_Name
;
10814 ----------------------------------
10815 -- Is_SPARK_Initialization_Expr --
10816 ----------------------------------
10818 function Is_SPARK_Initialization_Expr
(N
: Node_Id
) return Boolean is
10821 Comp_Assn
: Node_Id
;
10822 Orig_N
: constant Node_Id
:= Original_Node
(N
);
10827 if not Comes_From_Source
(Orig_N
) then
10831 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
10833 case Nkind
(Orig_N
) is
10834 when N_Character_Literal |
10835 N_Integer_Literal |
10837 N_String_Literal
=>
10840 when N_Identifier |
10842 if Is_Entity_Name
(Orig_N
)
10843 and then Present
(Entity
(Orig_N
)) -- needed in some cases
10845 case Ekind
(Entity
(Orig_N
)) is
10847 E_Enumeration_Literal |
10852 if Is_Type
(Entity
(Orig_N
)) then
10860 when N_Qualified_Expression |
10861 N_Type_Conversion
=>
10862 Is_Ok
:= Is_SPARK_Initialization_Expr
(Expression
(Orig_N
));
10865 Is_Ok
:= Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
10869 N_Membership_Test
=>
10870 Is_Ok
:= Is_SPARK_Initialization_Expr
(Left_Opnd
(Orig_N
))
10871 and then Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
10874 N_Extension_Aggregate
=>
10875 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
10876 Is_Ok
:= Is_SPARK_Initialization_Expr
(Ancestor_Part
(Orig_N
));
10879 Expr
:= First
(Expressions
(Orig_N
));
10880 while Present
(Expr
) loop
10881 if not Is_SPARK_Initialization_Expr
(Expr
) then
10889 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
10890 while Present
(Comp_Assn
) loop
10891 Expr
:= Expression
(Comp_Assn
);
10892 if Present
(Expr
) -- needed for box association
10893 and then not Is_SPARK_Initialization_Expr
(Expr
)
10902 when N_Attribute_Reference
=>
10903 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
10904 Is_Ok
:= Is_SPARK_Initialization_Expr
(Prefix
(Orig_N
));
10907 Expr
:= First
(Expressions
(Orig_N
));
10908 while Present
(Expr
) loop
10909 if not Is_SPARK_Initialization_Expr
(Expr
) then
10917 -- Selected components might be expanded named not yet resolved, so
10918 -- default on the safe side. (Eg on sparklex.ads)
10920 when N_Selected_Component
=>
10929 end Is_SPARK_Initialization_Expr
;
10931 -------------------------------
10932 -- Is_SPARK_Object_Reference --
10933 -------------------------------
10935 function Is_SPARK_Object_Reference
(N
: Node_Id
) return Boolean is
10937 if Is_Entity_Name
(N
) then
10938 return Present
(Entity
(N
))
10940 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
10941 or else Ekind
(Entity
(N
)) in Formal_Kind
);
10945 when N_Selected_Component
=>
10946 return Is_SPARK_Object_Reference
(Prefix
(N
));
10952 end Is_SPARK_Object_Reference
;
10954 ------------------------------
10955 -- Is_SPARK_Volatile_Object --
10956 ------------------------------
10958 function Is_SPARK_Volatile_Object
(N
: Node_Id
) return Boolean is
10960 if Nkind
(N
) = N_Defining_Identifier
then
10961 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
10963 elsif Is_Entity_Name
(N
) then
10965 Is_SPARK_Volatile_Object
(Entity
(N
))
10966 or else Is_Volatile
(Etype
(N
));
10968 elsif Nkind
(N
) = N_Expanded_Name
then
10969 return Is_SPARK_Volatile_Object
(Entity
(N
));
10971 elsif Nkind
(N
) = N_Indexed_Component
then
10972 return Is_SPARK_Volatile_Object
(Prefix
(N
));
10974 elsif Nkind
(N
) = N_Selected_Component
then
10976 Is_SPARK_Volatile_Object
(Prefix
(N
))
10978 Is_SPARK_Volatile_Object
(Selector_Name
(N
));
10983 end Is_SPARK_Volatile_Object
;
10989 function Is_Statement
(N
: Node_Id
) return Boolean is
10992 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
10993 or else Nkind
(N
) = N_Procedure_Call_Statement
;
10996 --------------------------------------------------
10997 -- Is_Subprogram_Stub_Without_Prior_Declaration --
10998 --------------------------------------------------
11000 function Is_Subprogram_Stub_Without_Prior_Declaration
11001 (N
: Node_Id
) return Boolean
11004 -- A subprogram stub without prior declaration serves as declaration for
11005 -- the actual subprogram body. As such, it has an attached defining
11006 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
11008 return Nkind
(N
) = N_Subprogram_Body_Stub
11009 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
11010 end Is_Subprogram_Stub_Without_Prior_Declaration
;
11012 ---------------------------------
11013 -- Is_Synchronized_Tagged_Type --
11014 ---------------------------------
11016 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
11017 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
11020 -- A task or protected type derived from an interface is a tagged type.
11021 -- Such a tagged type is called a synchronized tagged type, as are
11022 -- synchronized interfaces and private extensions whose declaration
11023 -- includes the reserved word synchronized.
11025 return (Is_Tagged_Type
(E
)
11026 and then (Kind
= E_Task_Type
11027 or else Kind
= E_Protected_Type
))
11030 and then Is_Synchronized_Interface
(E
))
11032 (Ekind
(E
) = E_Record_Type_With_Private
11033 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
11034 and then (Synchronized_Present
(Parent
(E
))
11035 or else Is_Synchronized_Interface
(Etype
(E
))));
11036 end Is_Synchronized_Tagged_Type
;
11042 function Is_Transfer
(N
: Node_Id
) return Boolean is
11043 Kind
: constant Node_Kind
:= Nkind
(N
);
11046 if Kind
= N_Simple_Return_Statement
11048 Kind
= N_Extended_Return_Statement
11050 Kind
= N_Goto_Statement
11052 Kind
= N_Raise_Statement
11054 Kind
= N_Requeue_Statement
11058 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
11059 and then No
(Condition
(N
))
11063 elsif Kind
= N_Procedure_Call_Statement
11064 and then Is_Entity_Name
(Name
(N
))
11065 and then Present
(Entity
(Name
(N
)))
11066 and then No_Return
(Entity
(Name
(N
)))
11070 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
11082 function Is_True
(U
: Uint
) return Boolean is
11087 --------------------------------------
11088 -- Is_Unchecked_Conversion_Instance --
11089 --------------------------------------
11091 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
11092 Gen_Par
: Entity_Id
;
11095 -- Look for a function whose generic parent is the predefined intrinsic
11096 -- function Unchecked_Conversion.
11098 if Ekind
(Id
) = E_Function
then
11099 Gen_Par
:= Generic_Parent
(Parent
(Id
));
11103 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
11104 and then Is_Intrinsic_Subprogram
(Gen_Par
)
11105 and then Is_Predefined_File_Name
11106 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
11110 end Is_Unchecked_Conversion_Instance
;
11112 -------------------------------
11113 -- Is_Universal_Numeric_Type --
11114 -------------------------------
11116 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
11118 return T
= Universal_Integer
or else T
= Universal_Real
;
11119 end Is_Universal_Numeric_Type
;
11121 -------------------
11122 -- Is_Value_Type --
11123 -------------------
11125 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
11127 return VM_Target
= CLI_Target
11128 and then Nkind
(T
) in N_Has_Chars
11129 and then Chars
(T
) /= No_Name
11130 and then Get_Name_String
(Chars
(T
)) = "valuetype";
11133 ----------------------------
11134 -- Is_Variable_Size_Array --
11135 ----------------------------
11137 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
11141 pragma Assert
(Is_Array_Type
(E
));
11143 -- Check if some index is initialized with a non-constant value
11145 Idx
:= First_Index
(E
);
11146 while Present
(Idx
) loop
11147 if Nkind
(Idx
) = N_Range
then
11148 if not Is_Constant_Bound
(Low_Bound
(Idx
))
11149 or else not Is_Constant_Bound
(High_Bound
(Idx
))
11155 Idx
:= Next_Index
(Idx
);
11159 end Is_Variable_Size_Array
;
11161 -----------------------------
11162 -- Is_Variable_Size_Record --
11163 -----------------------------
11165 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
11167 Comp_Typ
: Entity_Id
;
11170 pragma Assert
(Is_Record_Type
(E
));
11172 Comp
:= First_Entity
(E
);
11173 while Present
(Comp
) loop
11174 Comp_Typ
:= Etype
(Comp
);
11176 -- Recursive call if the record type has discriminants
11178 if Is_Record_Type
(Comp_Typ
)
11179 and then Has_Discriminants
(Comp_Typ
)
11180 and then Is_Variable_Size_Record
(Comp_Typ
)
11184 elsif Is_Array_Type
(Comp_Typ
)
11185 and then Is_Variable_Size_Array
(Comp_Typ
)
11190 Next_Entity
(Comp
);
11194 end Is_Variable_Size_Record
;
11196 ---------------------
11197 -- Is_VMS_Operator --
11198 ---------------------
11200 function Is_VMS_Operator
(Op
: Entity_Id
) return Boolean is
11202 -- The VMS operators are declared in a child of System that is loaded
11203 -- through pragma Extend_System. In some rare cases a program is run
11204 -- with this extension but without indicating that the target is VMS.
11206 return Ekind
(Op
) = E_Function
11207 and then Is_Intrinsic_Subprogram
(Op
)
11209 ((Present_System_Aux
and then Scope
(Op
) = System_Aux_Id
)
11212 and then Scope
(Scope
(Op
)) = RTU_Entity
(System
)));
11213 end Is_VMS_Operator
;
11219 function Is_Variable
11221 Use_Original_Node
: Boolean := True) return Boolean
11223 Orig_Node
: Node_Id
;
11225 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
11226 -- Within a protected function, the private components of the enclosing
11227 -- protected type are constants. A function nested within a (protected)
11228 -- procedure is not itself protected. Within the body of a protected
11229 -- function the current instance of the protected type is a constant.
11231 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
11232 -- Prefixes can involve implicit dereferences, in which case we must
11233 -- test for the case of a reference of a constant access type, which can
11234 -- can never be a variable.
11236 ---------------------------
11237 -- In_Protected_Function --
11238 ---------------------------
11240 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
11245 -- E is the current instance of a type
11247 if Is_Type
(E
) then
11256 if not Is_Protected_Type
(Prot
) then
11260 S
:= Current_Scope
;
11261 while Present
(S
) and then S
/= Prot
loop
11262 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
11271 end In_Protected_Function
;
11273 ------------------------
11274 -- Is_Variable_Prefix --
11275 ------------------------
11277 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
11279 if Is_Access_Type
(Etype
(P
)) then
11280 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
11282 -- For the case of an indexed component whose prefix has a packed
11283 -- array type, the prefix has been rewritten into a type conversion.
11284 -- Determine variable-ness from the converted expression.
11286 elsif Nkind
(P
) = N_Type_Conversion
11287 and then not Comes_From_Source
(P
)
11288 and then Is_Array_Type
(Etype
(P
))
11289 and then Is_Packed
(Etype
(P
))
11291 return Is_Variable
(Expression
(P
));
11294 return Is_Variable
(P
);
11296 end Is_Variable_Prefix
;
11298 -- Start of processing for Is_Variable
11301 -- Check if we perform the test on the original node since this may be a
11302 -- test of syntactic categories which must not be disturbed by whatever
11303 -- rewriting might have occurred. For example, an aggregate, which is
11304 -- certainly NOT a variable, could be turned into a variable by
11307 if Use_Original_Node
then
11308 Orig_Node
:= Original_Node
(N
);
11313 -- Definitely OK if Assignment_OK is set. Since this is something that
11314 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
11316 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
11319 -- Normally we go to the original node, but there is one exception where
11320 -- we use the rewritten node, namely when it is an explicit dereference.
11321 -- The generated code may rewrite a prefix which is an access type with
11322 -- an explicit dereference. The dereference is a variable, even though
11323 -- the original node may not be (since it could be a constant of the
11326 -- In Ada 2005 we have a further case to consider: the prefix may be a
11327 -- function call given in prefix notation. The original node appears to
11328 -- be a selected component, but we need to examine the call.
11330 elsif Nkind
(N
) = N_Explicit_Dereference
11331 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
11332 and then Present
(Etype
(Orig_Node
))
11333 and then Is_Access_Type
(Etype
(Orig_Node
))
11335 -- Note that if the prefix is an explicit dereference that does not
11336 -- come from source, we must check for a rewritten function call in
11337 -- prefixed notation before other forms of rewriting, to prevent a
11341 (Nkind
(Orig_Node
) = N_Function_Call
11342 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
11344 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
11346 -- in Ada 2012, the dereference may have been added for a type with
11347 -- a declared implicit dereference aspect.
11349 elsif Nkind
(N
) = N_Explicit_Dereference
11350 and then Present
(Etype
(Orig_Node
))
11351 and then Ada_Version
>= Ada_2012
11352 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
11356 -- A function call is never a variable
11358 elsif Nkind
(N
) = N_Function_Call
then
11361 -- All remaining checks use the original node
11363 elsif Is_Entity_Name
(Orig_Node
)
11364 and then Present
(Entity
(Orig_Node
))
11367 E
: constant Entity_Id
:= Entity
(Orig_Node
);
11368 K
: constant Entity_Kind
:= Ekind
(E
);
11371 return (K
= E_Variable
11372 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
11373 or else (K
= E_Component
11374 and then not In_Protected_Function
(E
))
11375 or else K
= E_Out_Parameter
11376 or else K
= E_In_Out_Parameter
11377 or else K
= E_Generic_In_Out_Parameter
11379 -- Current instance of type. If this is a protected type, check
11380 -- we are not within the body of one of its protected functions.
11382 or else (Is_Type
(E
)
11383 and then In_Open_Scopes
(E
)
11384 and then not In_Protected_Function
(E
))
11386 or else (Is_Incomplete_Or_Private_Type
(E
)
11387 and then In_Open_Scopes
(Full_View
(E
)));
11391 case Nkind
(Orig_Node
) is
11392 when N_Indexed_Component | N_Slice
=>
11393 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
11395 when N_Selected_Component
=>
11396 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
11397 and then Is_Variable
(Selector_Name
(Orig_Node
));
11399 -- For an explicit dereference, the type of the prefix cannot
11400 -- be an access to constant or an access to subprogram.
11402 when N_Explicit_Dereference
=>
11404 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
11406 return Is_Access_Type
(Typ
)
11407 and then not Is_Access_Constant
(Root_Type
(Typ
))
11408 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
11411 -- The type conversion is the case where we do not deal with the
11412 -- context dependent special case of an actual parameter. Thus
11413 -- the type conversion is only considered a variable for the
11414 -- purposes of this routine if the target type is tagged. However,
11415 -- a type conversion is considered to be a variable if it does not
11416 -- come from source (this deals for example with the conversions
11417 -- of expressions to their actual subtypes).
11419 when N_Type_Conversion
=>
11420 return Is_Variable
(Expression
(Orig_Node
))
11422 (not Comes_From_Source
(Orig_Node
)
11424 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
11426 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
11428 -- GNAT allows an unchecked type conversion as a variable. This
11429 -- only affects the generation of internal expanded code, since
11430 -- calls to instantiations of Unchecked_Conversion are never
11431 -- considered variables (since they are function calls).
11433 when N_Unchecked_Type_Conversion
=>
11434 return Is_Variable
(Expression
(Orig_Node
));
11442 ---------------------------
11443 -- Is_Visibly_Controlled --
11444 ---------------------------
11446 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
11447 Root
: constant Entity_Id
:= Root_Type
(T
);
11449 return Chars
(Scope
(Root
)) = Name_Finalization
11450 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
11451 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
11452 end Is_Visibly_Controlled
;
11454 ------------------------
11455 -- Is_Volatile_Object --
11456 ------------------------
11458 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
11460 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
11461 -- If prefix is an implicit dereference, examine designated type
11463 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
11464 -- Determines if given object has volatile components
11466 ------------------------
11467 -- Is_Volatile_Prefix --
11468 ------------------------
11470 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
11471 Typ
: constant Entity_Id
:= Etype
(N
);
11474 if Is_Access_Type
(Typ
) then
11476 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
11479 return Is_Volatile
(Dtyp
)
11480 or else Has_Volatile_Components
(Dtyp
);
11484 return Object_Has_Volatile_Components
(N
);
11486 end Is_Volatile_Prefix
;
11488 ------------------------------------
11489 -- Object_Has_Volatile_Components --
11490 ------------------------------------
11492 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
11493 Typ
: constant Entity_Id
:= Etype
(N
);
11496 if Is_Volatile
(Typ
)
11497 or else Has_Volatile_Components
(Typ
)
11501 elsif Is_Entity_Name
(N
)
11502 and then (Has_Volatile_Components
(Entity
(N
))
11503 or else Is_Volatile
(Entity
(N
)))
11507 elsif Nkind
(N
) = N_Indexed_Component
11508 or else Nkind
(N
) = N_Selected_Component
11510 return Is_Volatile_Prefix
(Prefix
(N
));
11515 end Object_Has_Volatile_Components
;
11517 -- Start of processing for Is_Volatile_Object
11520 if Nkind
(N
) = N_Defining_Identifier
then
11521 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
11523 elsif Nkind
(N
) = N_Expanded_Name
then
11524 return Is_Volatile_Object
(Entity
(N
));
11526 elsif Is_Volatile
(Etype
(N
))
11527 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
11531 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
11532 and then Is_Volatile_Prefix
(Prefix
(N
))
11536 elsif Nkind
(N
) = N_Selected_Component
11537 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
11544 end Is_Volatile_Object
;
11546 ---------------------------
11547 -- Itype_Has_Declaration --
11548 ---------------------------
11550 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
11552 pragma Assert
(Is_Itype
(Id
));
11553 return Present
(Parent
(Id
))
11554 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
11555 N_Subtype_Declaration
)
11556 and then Defining_Entity
(Parent
(Id
)) = Id
;
11557 end Itype_Has_Declaration
;
11559 -------------------------
11560 -- Kill_Current_Values --
11561 -------------------------
11563 procedure Kill_Current_Values
11565 Last_Assignment_Only
: Boolean := False)
11568 -- ??? do we have to worry about clearing cached checks?
11570 if Is_Assignable
(Ent
) then
11571 Set_Last_Assignment
(Ent
, Empty
);
11574 if Is_Object
(Ent
) then
11575 if not Last_Assignment_Only
then
11577 Set_Current_Value
(Ent
, Empty
);
11579 if not Can_Never_Be_Null
(Ent
) then
11580 Set_Is_Known_Non_Null
(Ent
, False);
11583 Set_Is_Known_Null
(Ent
, False);
11585 -- Reset Is_Known_Valid unless type is always valid, or if we have
11586 -- a loop parameter (loop parameters are always valid, since their
11587 -- bounds are defined by the bounds given in the loop header).
11589 if not Is_Known_Valid
(Etype
(Ent
))
11590 and then Ekind
(Ent
) /= E_Loop_Parameter
11592 Set_Is_Known_Valid
(Ent
, False);
11596 end Kill_Current_Values
;
11598 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
11601 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
11602 -- Clear current value for entity E and all entities chained to E
11604 ------------------------------------------
11605 -- Kill_Current_Values_For_Entity_Chain --
11606 ------------------------------------------
11608 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
11612 while Present
(Ent
) loop
11613 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
11616 end Kill_Current_Values_For_Entity_Chain
;
11618 -- Start of processing for Kill_Current_Values
11621 -- Kill all saved checks, a special case of killing saved values
11623 if not Last_Assignment_Only
then
11627 -- Loop through relevant scopes, which includes the current scope and
11628 -- any parent scopes if the current scope is a block or a package.
11630 S
:= Current_Scope
;
11633 -- Clear current values of all entities in current scope
11635 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
11637 -- If scope is a package, also clear current values of all private
11638 -- entities in the scope.
11640 if Is_Package_Or_Generic_Package
(S
)
11641 or else Is_Concurrent_Type
(S
)
11643 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
11646 -- If this is a not a subprogram, deal with parents
11648 if not Is_Subprogram
(S
) then
11650 exit Scope_Loop
when S
= Standard_Standard
;
11654 end loop Scope_Loop
;
11655 end Kill_Current_Values
;
11657 --------------------------
11658 -- Kill_Size_Check_Code --
11659 --------------------------
11661 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
11663 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
11664 and then Present
(Size_Check_Code
(E
))
11666 Remove
(Size_Check_Code
(E
));
11667 Set_Size_Check_Code
(E
, Empty
);
11669 end Kill_Size_Check_Code
;
11671 --------------------------
11672 -- Known_To_Be_Assigned --
11673 --------------------------
11675 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
11676 P
: constant Node_Id
:= Parent
(N
);
11681 -- Test left side of assignment
11683 when N_Assignment_Statement
=>
11684 return N
= Name
(P
);
11686 -- Function call arguments are never lvalues
11688 when N_Function_Call
=>
11691 -- Positional parameter for procedure or accept call
11693 when N_Procedure_Call_Statement |
11702 Proc
:= Get_Subprogram_Entity
(P
);
11708 -- If we are not a list member, something is strange, so
11709 -- be conservative and return False.
11711 if not Is_List_Member
(N
) then
11715 -- We are going to find the right formal by stepping forward
11716 -- through the formals, as we step backwards in the actuals.
11718 Form
:= First_Formal
(Proc
);
11721 -- If no formal, something is weird, so be conservative
11722 -- and return False.
11729 exit when No
(Act
);
11730 Next_Formal
(Form
);
11733 return Ekind
(Form
) /= E_In_Parameter
;
11736 -- Named parameter for procedure or accept call
11738 when N_Parameter_Association
=>
11744 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
11750 -- Loop through formals to find the one that matches
11752 Form
:= First_Formal
(Proc
);
11754 -- If no matching formal, that's peculiar, some kind of
11755 -- previous error, so return False to be conservative.
11756 -- Actually this also happens in legal code in the case
11757 -- where P is a parameter association for an Extra_Formal???
11763 -- Else test for match
11765 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
11766 return Ekind
(Form
) /= E_In_Parameter
;
11769 Next_Formal
(Form
);
11773 -- Test for appearing in a conversion that itself appears
11774 -- in an lvalue context, since this should be an lvalue.
11776 when N_Type_Conversion
=>
11777 return Known_To_Be_Assigned
(P
);
11779 -- All other references are definitely not known to be modifications
11785 end Known_To_Be_Assigned
;
11787 ---------------------------
11788 -- Last_Source_Statement --
11789 ---------------------------
11791 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
11795 N
:= Last
(Statements
(HSS
));
11796 while Present
(N
) loop
11797 exit when Comes_From_Source
(N
);
11802 end Last_Source_Statement
;
11804 ----------------------------------
11805 -- Matching_Static_Array_Bounds --
11806 ----------------------------------
11808 function Matching_Static_Array_Bounds
11810 R_Typ
: Node_Id
) return Boolean
11812 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
11813 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
11825 if L_Ndims
/= R_Ndims
then
11829 -- Unconstrained types do not have static bounds
11831 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
11835 -- First treat specially the first dimension, as the lower bound and
11836 -- length of string literals are not stored like those of arrays.
11838 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
11839 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
11840 L_Len
:= String_Literal_Length
(L_Typ
);
11842 L_Index
:= First_Index
(L_Typ
);
11843 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
11845 if Is_OK_Static_Expression
(L_Low
)
11846 and then Is_OK_Static_Expression
(L_High
)
11848 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
11851 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
11858 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
11859 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
11860 R_Len
:= String_Literal_Length
(R_Typ
);
11862 R_Index
:= First_Index
(R_Typ
);
11863 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
11865 if Is_OK_Static_Expression
(R_Low
)
11866 and then Is_OK_Static_Expression
(R_High
)
11868 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
11871 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
11878 if Is_OK_Static_Expression
(L_Low
)
11879 and then Is_OK_Static_Expression
(R_Low
)
11880 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
11881 and then L_Len
= R_Len
11888 -- Then treat all other dimensions
11890 for Indx
in 2 .. L_Ndims
loop
11894 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
11895 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
11897 if Is_OK_Static_Expression
(L_Low
)
11898 and then Is_OK_Static_Expression
(L_High
)
11899 and then Is_OK_Static_Expression
(R_Low
)
11900 and then Is_OK_Static_Expression
(R_High
)
11901 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
11902 and then Expr_Value
(L_High
) = Expr_Value
(R_High
)
11910 -- If we fall through the loop, all indexes matched
11913 end Matching_Static_Array_Bounds
;
11915 -------------------
11916 -- May_Be_Lvalue --
11917 -------------------
11919 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
11920 P
: constant Node_Id
:= Parent
(N
);
11925 -- Test left side of assignment
11927 when N_Assignment_Statement
=>
11928 return N
= Name
(P
);
11930 -- Test prefix of component or attribute. Note that the prefix of an
11931 -- explicit or implicit dereference cannot be an l-value.
11933 when N_Attribute_Reference
=>
11934 return N
= Prefix
(P
)
11935 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
11937 -- For an expanded name, the name is an lvalue if the expanded name
11938 -- is an lvalue, but the prefix is never an lvalue, since it is just
11939 -- the scope where the name is found.
11941 when N_Expanded_Name
=>
11942 if N
= Prefix
(P
) then
11943 return May_Be_Lvalue
(P
);
11948 -- For a selected component A.B, A is certainly an lvalue if A.B is.
11949 -- B is a little interesting, if we have A.B := 3, there is some
11950 -- discussion as to whether B is an lvalue or not, we choose to say
11951 -- it is. Note however that A is not an lvalue if it is of an access
11952 -- type since this is an implicit dereference.
11954 when N_Selected_Component
=>
11956 and then Present
(Etype
(N
))
11957 and then Is_Access_Type
(Etype
(N
))
11961 return May_Be_Lvalue
(P
);
11964 -- For an indexed component or slice, the index or slice bounds is
11965 -- never an lvalue. The prefix is an lvalue if the indexed component
11966 -- or slice is an lvalue, except if it is an access type, where we
11967 -- have an implicit dereference.
11969 when N_Indexed_Component | N_Slice
=>
11971 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
11975 return May_Be_Lvalue
(P
);
11978 -- Prefix of a reference is an lvalue if the reference is an lvalue
11980 when N_Reference
=>
11981 return May_Be_Lvalue
(P
);
11983 -- Prefix of explicit dereference is never an lvalue
11985 when N_Explicit_Dereference
=>
11988 -- Positional parameter for subprogram, entry, or accept call.
11989 -- In older versions of Ada function call arguments are never
11990 -- lvalues. In Ada 2012 functions can have in-out parameters.
11992 when N_Subprogram_Call |
11993 N_Entry_Call_Statement |
11996 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
12000 -- The following mechanism is clumsy and fragile. A single flag
12001 -- set in Resolve_Actuals would be preferable ???
12009 Proc
:= Get_Subprogram_Entity
(P
);
12015 -- If we are not a list member, something is strange, so be
12016 -- conservative and return True.
12018 if not Is_List_Member
(N
) then
12022 -- We are going to find the right formal by stepping forward
12023 -- through the formals, as we step backwards in the actuals.
12025 Form
:= First_Formal
(Proc
);
12028 -- If no formal, something is weird, so be conservative and
12036 exit when No
(Act
);
12037 Next_Formal
(Form
);
12040 return Ekind
(Form
) /= E_In_Parameter
;
12043 -- Named parameter for procedure or accept call
12045 when N_Parameter_Association
=>
12051 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
12057 -- Loop through formals to find the one that matches
12059 Form
:= First_Formal
(Proc
);
12061 -- If no matching formal, that's peculiar, some kind of
12062 -- previous error, so return True to be conservative.
12063 -- Actually happens with legal code for an unresolved call
12064 -- where we may get the wrong homonym???
12070 -- Else test for match
12072 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
12073 return Ekind
(Form
) /= E_In_Parameter
;
12076 Next_Formal
(Form
);
12080 -- Test for appearing in a conversion that itself appears in an
12081 -- lvalue context, since this should be an lvalue.
12083 when N_Type_Conversion
=>
12084 return May_Be_Lvalue
(P
);
12086 -- Test for appearance in object renaming declaration
12088 when N_Object_Renaming_Declaration
=>
12091 -- All other references are definitely not lvalues
12099 -----------------------
12100 -- Mark_Coextensions --
12101 -----------------------
12103 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
12104 Is_Dynamic
: Boolean;
12105 -- Indicates whether the context causes nested coextensions to be
12106 -- dynamic or static
12108 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
12109 -- Recognize an allocator node and label it as a dynamic coextension
12111 --------------------
12112 -- Mark_Allocator --
12113 --------------------
12115 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
12117 if Nkind
(N
) = N_Allocator
then
12119 Set_Is_Dynamic_Coextension
(N
);
12121 -- If the allocator expression is potentially dynamic, it may
12122 -- be expanded out of order and require dynamic allocation
12123 -- anyway, so we treat the coextension itself as dynamic.
12124 -- Potential optimization ???
12126 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
12127 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
12129 Set_Is_Dynamic_Coextension
(N
);
12131 Set_Is_Static_Coextension
(N
);
12136 end Mark_Allocator
;
12138 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
12140 -- Start of processing Mark_Coextensions
12143 case Nkind
(Context_Nod
) is
12145 -- Comment here ???
12147 when N_Assignment_Statement
=>
12148 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
12150 -- An allocator that is a component of a returned aggregate
12151 -- must be dynamic.
12153 when N_Simple_Return_Statement
=>
12155 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
12158 Nkind
(Expr
) = N_Allocator
12160 (Nkind
(Expr
) = N_Qualified_Expression
12161 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
12164 -- An alloctor within an object declaration in an extended return
12165 -- statement is of necessity dynamic.
12167 when N_Object_Declaration
=>
12168 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
12170 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
12172 -- This routine should not be called for constructs which may not
12173 -- contain coextensions.
12176 raise Program_Error
;
12179 Mark_Allocators
(Root_Nod
);
12180 end Mark_Coextensions
;
12186 function Must_Inline
(Subp
: Entity_Id
) return Boolean is
12189 (Optimization_Level
= 0
12191 -- AAMP and VM targets have no support for inlining in the backend.
12192 -- Hence we do as much inlining as possible in the front end.
12194 or else AAMP_On_Target
12195 or else VM_Target
/= No_VM
)
12196 and then Has_Pragma_Inline
(Subp
)
12197 and then (Has_Pragma_Inline_Always
(Subp
) or else Front_End_Inlining
);
12200 ----------------------
12201 -- Needs_One_Actual --
12202 ----------------------
12204 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
12205 Formal
: Entity_Id
;
12208 -- Ada 2005 or later, and formals present
12210 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
12211 Formal
:= Next_Formal
(First_Formal
(E
));
12212 while Present
(Formal
) loop
12213 if No
(Default_Value
(Formal
)) then
12217 Next_Formal
(Formal
);
12222 -- Ada 83/95 or no formals
12227 end Needs_One_Actual
;
12229 ------------------------
12230 -- New_Copy_List_Tree --
12231 ------------------------
12233 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
12238 if List
= No_List
then
12245 while Present
(E
) loop
12246 Append
(New_Copy_Tree
(E
), NL
);
12252 end New_Copy_List_Tree
;
12254 -------------------
12255 -- New_Copy_Tree --
12256 -------------------
12258 use Atree
.Unchecked_Access
;
12259 use Atree_Private_Part
;
12261 -- Our approach here requires a two pass traversal of the tree. The
12262 -- first pass visits all nodes that eventually will be copied looking
12263 -- for defining Itypes. If any defining Itypes are found, then they are
12264 -- copied, and an entry is added to the replacement map. In the second
12265 -- phase, the tree is copied, using the replacement map to replace any
12266 -- Itype references within the copied tree.
12268 -- The following hash tables are used if the Map supplied has more
12269 -- than hash threshold entries to speed up access to the map. If
12270 -- there are fewer entries, then the map is searched sequentially
12271 -- (because setting up a hash table for only a few entries takes
12272 -- more time than it saves.
12274 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
12275 -- Hash function used for hash operations
12277 -------------------
12278 -- New_Copy_Hash --
12279 -------------------
12281 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
12283 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
12290 -- The hash table NCT_Assoc associates old entities in the table
12291 -- with their corresponding new entities (i.e. the pairs of entries
12292 -- presented in the original Map argument are Key-Element pairs).
12294 package NCT_Assoc
is new Simple_HTable
(
12295 Header_Num
=> NCT_Header_Num
,
12296 Element
=> Entity_Id
,
12297 No_Element
=> Empty
,
12299 Hash
=> New_Copy_Hash
,
12300 Equal
=> Types
."=");
12302 ---------------------
12303 -- NCT_Itype_Assoc --
12304 ---------------------
12306 -- The hash table NCT_Itype_Assoc contains entries only for those
12307 -- old nodes which have a non-empty Associated_Node_For_Itype set.
12308 -- The key is the associated node, and the element is the new node
12309 -- itself (NOT the associated node for the new node).
12311 package NCT_Itype_Assoc
is new Simple_HTable
(
12312 Header_Num
=> NCT_Header_Num
,
12313 Element
=> Entity_Id
,
12314 No_Element
=> Empty
,
12316 Hash
=> New_Copy_Hash
,
12317 Equal
=> Types
."=");
12319 -- Start of processing for New_Copy_Tree function
12321 function New_Copy_Tree
12323 Map
: Elist_Id
:= No_Elist
;
12324 New_Sloc
: Source_Ptr
:= No_Location
;
12325 New_Scope
: Entity_Id
:= Empty
) return Node_Id
12327 Actual_Map
: Elist_Id
:= Map
;
12328 -- This is the actual map for the copy. It is initialized with the
12329 -- given elements, and then enlarged as required for Itypes that are
12330 -- copied during the first phase of the copy operation. The visit
12331 -- procedures add elements to this map as Itypes are encountered.
12332 -- The reason we cannot use Map directly, is that it may well be
12333 -- (and normally is) initialized to No_Elist, and if we have mapped
12334 -- entities, we have to reset it to point to a real Elist.
12336 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
12337 -- Called during second phase to map entities into their corresponding
12338 -- copies using Actual_Map. If the argument is not an entity, or is not
12339 -- in Actual_Map, then it is returned unchanged.
12341 procedure Build_NCT_Hash_Tables
;
12342 -- Builds hash tables (number of elements >= threshold value)
12344 function Copy_Elist_With_Replacement
12345 (Old_Elist
: Elist_Id
) return Elist_Id
;
12346 -- Called during second phase to copy element list doing replacements
12348 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
12349 -- Called during the second phase to process a copied Itype. The actual
12350 -- copy happened during the first phase (so that we could make the entry
12351 -- in the mapping), but we still have to deal with the descendents of
12352 -- the copied Itype and copy them where necessary.
12354 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
12355 -- Called during second phase to copy list doing replacements
12357 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
12358 -- Called during second phase to copy node doing replacements
12360 procedure Visit_Elist
(E
: Elist_Id
);
12361 -- Called during first phase to visit all elements of an Elist
12363 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
12364 -- Visit a single field, recursing to call Visit_Node or Visit_List
12365 -- if the field is a syntactic descendent of the current node (i.e.
12366 -- its parent is Node N).
12368 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
12369 -- Called during first phase to visit subsidiary fields of a defining
12370 -- Itype, and also create a copy and make an entry in the replacement
12371 -- map for the new copy.
12373 procedure Visit_List
(L
: List_Id
);
12374 -- Called during first phase to visit all elements of a List
12376 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
12377 -- Called during first phase to visit a node and all its subtrees
12383 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
12388 if not Has_Extension
(N
) or else No
(Actual_Map
) then
12391 elsif NCT_Hash_Tables_Used
then
12392 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
12394 if Present
(Ent
) then
12400 -- No hash table used, do serial search
12403 E
:= First_Elmt
(Actual_Map
);
12404 while Present
(E
) loop
12405 if Node
(E
) = N
then
12406 return Node
(Next_Elmt
(E
));
12408 E
:= Next_Elmt
(Next_Elmt
(E
));
12416 ---------------------------
12417 -- Build_NCT_Hash_Tables --
12418 ---------------------------
12420 procedure Build_NCT_Hash_Tables
is
12424 if NCT_Hash_Table_Setup
then
12426 NCT_Itype_Assoc
.Reset
;
12429 Elmt
:= First_Elmt
(Actual_Map
);
12430 while Present
(Elmt
) loop
12431 Ent
:= Node
(Elmt
);
12433 -- Get new entity, and associate old and new
12436 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
12438 if Is_Type
(Ent
) then
12440 Anode
: constant Entity_Id
:=
12441 Associated_Node_For_Itype
(Ent
);
12444 if Present
(Anode
) then
12446 -- Enter a link between the associated node of the
12447 -- old Itype and the new Itype, for updating later
12448 -- when node is copied.
12450 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
12458 NCT_Hash_Tables_Used
:= True;
12459 NCT_Hash_Table_Setup
:= True;
12460 end Build_NCT_Hash_Tables
;
12462 ---------------------------------
12463 -- Copy_Elist_With_Replacement --
12464 ---------------------------------
12466 function Copy_Elist_With_Replacement
12467 (Old_Elist
: Elist_Id
) return Elist_Id
12470 New_Elist
: Elist_Id
;
12473 if No
(Old_Elist
) then
12477 New_Elist
:= New_Elmt_List
;
12479 M
:= First_Elmt
(Old_Elist
);
12480 while Present
(M
) loop
12481 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
12487 end Copy_Elist_With_Replacement
;
12489 ---------------------------------
12490 -- Copy_Itype_With_Replacement --
12491 ---------------------------------
12493 -- This routine exactly parallels its phase one analog Visit_Itype,
12495 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
12497 -- Translate Next_Entity, Scope and Etype fields, in case they
12498 -- reference entities that have been mapped into copies.
12500 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
12501 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
12503 if Present
(New_Scope
) then
12504 Set_Scope
(New_Itype
, New_Scope
);
12506 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
12509 -- Copy referenced fields
12511 if Is_Discrete_Type
(New_Itype
) then
12512 Set_Scalar_Range
(New_Itype
,
12513 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
12515 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
12516 Set_Discriminant_Constraint
(New_Itype
,
12517 Copy_Elist_With_Replacement
12518 (Discriminant_Constraint
(New_Itype
)));
12520 elsif Is_Array_Type
(New_Itype
) then
12521 if Present
(First_Index
(New_Itype
)) then
12522 Set_First_Index
(New_Itype
,
12523 First
(Copy_List_With_Replacement
12524 (List_Containing
(First_Index
(New_Itype
)))));
12527 if Is_Packed
(New_Itype
) then
12528 Set_Packed_Array_Type
(New_Itype
,
12529 Copy_Node_With_Replacement
12530 (Packed_Array_Type
(New_Itype
)));
12533 end Copy_Itype_With_Replacement
;
12535 --------------------------------
12536 -- Copy_List_With_Replacement --
12537 --------------------------------
12539 function Copy_List_With_Replacement
12540 (Old_List
: List_Id
) return List_Id
12542 New_List
: List_Id
;
12546 if Old_List
= No_List
then
12550 New_List
:= Empty_List
;
12552 E
:= First
(Old_List
);
12553 while Present
(E
) loop
12554 Append
(Copy_Node_With_Replacement
(E
), New_List
);
12560 end Copy_List_With_Replacement
;
12562 --------------------------------
12563 -- Copy_Node_With_Replacement --
12564 --------------------------------
12566 function Copy_Node_With_Replacement
12567 (Old_Node
: Node_Id
) return Node_Id
12569 New_Node
: Node_Id
;
12571 procedure Adjust_Named_Associations
12572 (Old_Node
: Node_Id
;
12573 New_Node
: Node_Id
);
12574 -- If a call node has named associations, these are chained through
12575 -- the First_Named_Actual, Next_Named_Actual links. These must be
12576 -- propagated separately to the new parameter list, because these
12577 -- are not syntactic fields.
12579 function Copy_Field_With_Replacement
12580 (Field
: Union_Id
) return Union_Id
;
12581 -- Given Field, which is a field of Old_Node, return a copy of it
12582 -- if it is a syntactic field (i.e. its parent is Node), setting
12583 -- the parent of the copy to poit to New_Node. Otherwise returns
12584 -- the field (possibly mapped if it is an entity).
12586 -------------------------------
12587 -- Adjust_Named_Associations --
12588 -------------------------------
12590 procedure Adjust_Named_Associations
12591 (Old_Node
: Node_Id
;
12592 New_Node
: Node_Id
)
12597 Old_Next
: Node_Id
;
12598 New_Next
: Node_Id
;
12601 Old_E
:= First
(Parameter_Associations
(Old_Node
));
12602 New_E
:= First
(Parameter_Associations
(New_Node
));
12603 while Present
(Old_E
) loop
12604 if Nkind
(Old_E
) = N_Parameter_Association
12605 and then Present
(Next_Named_Actual
(Old_E
))
12607 if First_Named_Actual
(Old_Node
)
12608 = Explicit_Actual_Parameter
(Old_E
)
12610 Set_First_Named_Actual
12611 (New_Node
, Explicit_Actual_Parameter
(New_E
));
12614 -- Now scan parameter list from the beginning,to locate
12615 -- next named actual, which can be out of order.
12617 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
12618 New_Next
:= First
(Parameter_Associations
(New_Node
));
12620 while Nkind
(Old_Next
) /= N_Parameter_Association
12621 or else Explicit_Actual_Parameter
(Old_Next
)
12622 /= Next_Named_Actual
(Old_E
)
12628 Set_Next_Named_Actual
12629 (New_E
, Explicit_Actual_Parameter
(New_Next
));
12635 end Adjust_Named_Associations
;
12637 ---------------------------------
12638 -- Copy_Field_With_Replacement --
12639 ---------------------------------
12641 function Copy_Field_With_Replacement
12642 (Field
: Union_Id
) return Union_Id
12645 if Field
= Union_Id
(Empty
) then
12648 elsif Field
in Node_Range
then
12650 Old_N
: constant Node_Id
:= Node_Id
(Field
);
12654 -- If syntactic field, as indicated by the parent pointer
12655 -- being set, then copy the referenced node recursively.
12657 if Parent
(Old_N
) = Old_Node
then
12658 New_N
:= Copy_Node_With_Replacement
(Old_N
);
12660 if New_N
/= Old_N
then
12661 Set_Parent
(New_N
, New_Node
);
12664 -- For semantic fields, update possible entity reference
12665 -- from the replacement map.
12668 New_N
:= Assoc
(Old_N
);
12671 return Union_Id
(New_N
);
12674 elsif Field
in List_Range
then
12676 Old_L
: constant List_Id
:= List_Id
(Field
);
12680 -- If syntactic field, as indicated by the parent pointer,
12681 -- then recursively copy the entire referenced list.
12683 if Parent
(Old_L
) = Old_Node
then
12684 New_L
:= Copy_List_With_Replacement
(Old_L
);
12685 Set_Parent
(New_L
, New_Node
);
12687 -- For semantic list, just returned unchanged
12693 return Union_Id
(New_L
);
12696 -- Anything other than a list or a node is returned unchanged
12701 end Copy_Field_With_Replacement
;
12703 -- Start of processing for Copy_Node_With_Replacement
12706 if Old_Node
<= Empty_Or_Error
then
12709 elsif Has_Extension
(Old_Node
) then
12710 return Assoc
(Old_Node
);
12713 New_Node
:= New_Copy
(Old_Node
);
12715 -- If the node we are copying is the associated node of a
12716 -- previously copied Itype, then adjust the associated node
12717 -- of the copy of that Itype accordingly.
12719 if Present
(Actual_Map
) then
12725 -- Case of hash table used
12727 if NCT_Hash_Tables_Used
then
12728 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
12730 if Present
(Ent
) then
12731 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
12734 -- Case of no hash table used
12737 E
:= First_Elmt
(Actual_Map
);
12738 while Present
(E
) loop
12739 if Is_Itype
(Node
(E
))
12741 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
12743 Set_Associated_Node_For_Itype
12744 (Node
(Next_Elmt
(E
)), New_Node
);
12747 E
:= Next_Elmt
(Next_Elmt
(E
));
12753 -- Recursively copy descendents
12756 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
12758 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
12760 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
12762 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
12764 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
12766 -- Adjust Sloc of new node if necessary
12768 if New_Sloc
/= No_Location
then
12769 Set_Sloc
(New_Node
, New_Sloc
);
12771 -- If we adjust the Sloc, then we are essentially making
12772 -- a completely new node, so the Comes_From_Source flag
12773 -- should be reset to the proper default value.
12775 Nodes
.Table
(New_Node
).Comes_From_Source
:=
12776 Default_Node
.Comes_From_Source
;
12779 -- If the node is call and has named associations,
12780 -- set the corresponding links in the copy.
12782 if (Nkind
(Old_Node
) = N_Function_Call
12783 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
12785 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
12786 and then Present
(First_Named_Actual
(Old_Node
))
12788 Adjust_Named_Associations
(Old_Node
, New_Node
);
12791 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
12792 -- The replacement mechanism applies to entities, and is not used
12793 -- here. Eventually we may need a more general graph-copying
12794 -- routine. For now, do a sequential search to find desired node.
12796 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
12797 and then Present
(First_Real_Statement
(Old_Node
))
12800 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
12804 N1
:= First
(Statements
(Old_Node
));
12805 N2
:= First
(Statements
(New_Node
));
12807 while N1
/= Old_F
loop
12812 Set_First_Real_Statement
(New_Node
, N2
);
12817 -- All done, return copied node
12820 end Copy_Node_With_Replacement
;
12826 procedure Visit_Elist
(E
: Elist_Id
) is
12829 if Present
(E
) then
12830 Elmt
:= First_Elmt
(E
);
12832 while Elmt
/= No_Elmt
loop
12833 Visit_Node
(Node
(Elmt
));
12843 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
12845 if F
= Union_Id
(Empty
) then
12848 elsif F
in Node_Range
then
12850 -- Copy node if it is syntactic, i.e. its parent pointer is
12851 -- set to point to the field that referenced it (certain
12852 -- Itypes will also meet this criterion, which is fine, since
12853 -- these are clearly Itypes that do need to be copied, since
12854 -- we are copying their parent.)
12856 if Parent
(Node_Id
(F
)) = N
then
12857 Visit_Node
(Node_Id
(F
));
12860 -- Another case, if we are pointing to an Itype, then we want
12861 -- to copy it if its associated node is somewhere in the tree
12864 -- Note: the exclusion of self-referential copies is just an
12865 -- optimization, since the search of the already copied list
12866 -- would catch it, but it is a common case (Etype pointing
12867 -- to itself for an Itype that is a base type).
12869 elsif Has_Extension
(Node_Id
(F
))
12870 and then Is_Itype
(Entity_Id
(F
))
12871 and then Node_Id
(F
) /= N
12877 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
12878 while Present
(P
) loop
12880 Visit_Node
(Node_Id
(F
));
12887 -- An Itype whose parent is not being copied definitely
12888 -- should NOT be copied, since it does not belong in any
12889 -- sense to the copied subtree.
12895 elsif F
in List_Range
12896 and then Parent
(List_Id
(F
)) = N
12898 Visit_List
(List_Id
(F
));
12907 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
12908 New_Itype
: Entity_Id
;
12913 -- Itypes that describe the designated type of access to subprograms
12914 -- have the structure of subprogram declarations, with signatures,
12915 -- etc. Either we duplicate the signatures completely, or choose to
12916 -- share such itypes, which is fine because their elaboration will
12917 -- have no side effects.
12919 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
12923 New_Itype
:= New_Copy
(Old_Itype
);
12925 -- The new Itype has all the attributes of the old one, and
12926 -- we just copy the contents of the entity. However, the back-end
12927 -- needs different names for debugging purposes, so we create a
12928 -- new internal name for it in all cases.
12930 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
12932 -- If our associated node is an entity that has already been copied,
12933 -- then set the associated node of the copy to point to the right
12934 -- copy. If we have copied an Itype that is itself the associated
12935 -- node of some previously copied Itype, then we set the right
12936 -- pointer in the other direction.
12938 if Present
(Actual_Map
) then
12940 -- Case of hash tables used
12942 if NCT_Hash_Tables_Used
then
12944 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
12946 if Present
(Ent
) then
12947 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
12950 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
12951 if Present
(Ent
) then
12952 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
12954 -- If the hash table has no association for this Itype and
12955 -- its associated node, enter one now.
12958 NCT_Itype_Assoc
.Set
12959 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
12962 -- Case of hash tables not used
12965 E
:= First_Elmt
(Actual_Map
);
12966 while Present
(E
) loop
12967 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
12968 Set_Associated_Node_For_Itype
12969 (New_Itype
, Node
(Next_Elmt
(E
)));
12972 if Is_Type
(Node
(E
))
12974 Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
12976 Set_Associated_Node_For_Itype
12977 (Node
(Next_Elmt
(E
)), New_Itype
);
12980 E
:= Next_Elmt
(Next_Elmt
(E
));
12985 if Present
(Freeze_Node
(New_Itype
)) then
12986 Set_Is_Frozen
(New_Itype
, False);
12987 Set_Freeze_Node
(New_Itype
, Empty
);
12990 -- Add new association to map
12992 if No
(Actual_Map
) then
12993 Actual_Map
:= New_Elmt_List
;
12996 Append_Elmt
(Old_Itype
, Actual_Map
);
12997 Append_Elmt
(New_Itype
, Actual_Map
);
12999 if NCT_Hash_Tables_Used
then
13000 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
13003 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13005 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13006 Build_NCT_Hash_Tables
;
13010 -- If a record subtype is simply copied, the entity list will be
13011 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
13013 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
13014 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
13017 -- Visit descendents that eventually get copied
13019 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
13021 if Is_Discrete_Type
(Old_Itype
) then
13022 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
13024 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
13025 -- ??? This should involve call to Visit_Field
13026 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
13028 elsif Is_Array_Type
(Old_Itype
) then
13029 if Present
(First_Index
(Old_Itype
)) then
13030 Visit_Field
(Union_Id
(List_Containing
13031 (First_Index
(Old_Itype
))),
13035 if Is_Packed
(Old_Itype
) then
13036 Visit_Field
(Union_Id
(Packed_Array_Type
(Old_Itype
)),
13046 procedure Visit_List
(L
: List_Id
) is
13049 if L
/= No_List
then
13052 while Present
(N
) loop
13063 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
13065 -- Start of processing for Visit_Node
13068 -- Handle case of an Itype, which must be copied
13070 if Has_Extension
(N
)
13071 and then Is_Itype
(N
)
13073 -- Nothing to do if already in the list. This can happen with an
13074 -- Itype entity that appears more than once in the tree.
13075 -- Note that we do not want to visit descendents in this case.
13077 -- Test for already in list when hash table is used
13079 if NCT_Hash_Tables_Used
then
13080 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
13084 -- Test for already in list when hash table not used
13090 if Present
(Actual_Map
) then
13091 E
:= First_Elmt
(Actual_Map
);
13092 while Present
(E
) loop
13093 if Node
(E
) = N
then
13096 E
:= Next_Elmt
(Next_Elmt
(E
));
13106 -- Visit descendents
13108 Visit_Field
(Field1
(N
), N
);
13109 Visit_Field
(Field2
(N
), N
);
13110 Visit_Field
(Field3
(N
), N
);
13111 Visit_Field
(Field4
(N
), N
);
13112 Visit_Field
(Field5
(N
), N
);
13115 -- Start of processing for New_Copy_Tree
13120 -- See if we should use hash table
13122 if No
(Actual_Map
) then
13123 NCT_Hash_Tables_Used
:= False;
13130 NCT_Table_Entries
:= 0;
13132 Elmt
:= First_Elmt
(Actual_Map
);
13133 while Present
(Elmt
) loop
13134 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13139 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13140 Build_NCT_Hash_Tables
;
13142 NCT_Hash_Tables_Used
:= False;
13147 -- Hash table set up if required, now start phase one by visiting
13148 -- top node (we will recursively visit the descendents).
13150 Visit_Node
(Source
);
13152 -- Now the second phase of the copy can start. First we process
13153 -- all the mapped entities, copying their descendents.
13155 if Present
(Actual_Map
) then
13158 New_Itype
: Entity_Id
;
13160 Elmt
:= First_Elmt
(Actual_Map
);
13161 while Present
(Elmt
) loop
13163 New_Itype
:= Node
(Elmt
);
13164 Copy_Itype_With_Replacement
(New_Itype
);
13170 -- Now we can copy the actual tree
13172 return Copy_Node_With_Replacement
(Source
);
13175 -------------------------
13176 -- New_External_Entity --
13177 -------------------------
13179 function New_External_Entity
13180 (Kind
: Entity_Kind
;
13181 Scope_Id
: Entity_Id
;
13182 Sloc_Value
: Source_Ptr
;
13183 Related_Id
: Entity_Id
;
13184 Suffix
: Character;
13185 Suffix_Index
: Nat
:= 0;
13186 Prefix
: Character := ' ') return Entity_Id
13188 N
: constant Entity_Id
:=
13189 Make_Defining_Identifier
(Sloc_Value
,
13191 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
13194 Set_Ekind
(N
, Kind
);
13195 Set_Is_Internal
(N
, True);
13196 Append_Entity
(N
, Scope_Id
);
13197 Set_Public_Status
(N
);
13199 if Kind
in Type_Kind
then
13200 Init_Size_Align
(N
);
13204 end New_External_Entity
;
13206 -------------------------
13207 -- New_Internal_Entity --
13208 -------------------------
13210 function New_Internal_Entity
13211 (Kind
: Entity_Kind
;
13212 Scope_Id
: Entity_Id
;
13213 Sloc_Value
: Source_Ptr
;
13214 Id_Char
: Character) return Entity_Id
13216 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
13219 Set_Ekind
(N
, Kind
);
13220 Set_Is_Internal
(N
, True);
13221 Append_Entity
(N
, Scope_Id
);
13223 if Kind
in Type_Kind
then
13224 Init_Size_Align
(N
);
13228 end New_Internal_Entity
;
13234 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
13238 -- If we are pointing at a positional parameter, it is a member of a
13239 -- node list (the list of parameters), and the next parameter is the
13240 -- next node on the list, unless we hit a parameter association, then
13241 -- we shift to using the chain whose head is the First_Named_Actual in
13242 -- the parent, and then is threaded using the Next_Named_Actual of the
13243 -- Parameter_Association. All this fiddling is because the original node
13244 -- list is in the textual call order, and what we need is the
13245 -- declaration order.
13247 if Is_List_Member
(Actual_Id
) then
13248 N
:= Next
(Actual_Id
);
13250 if Nkind
(N
) = N_Parameter_Association
then
13251 return First_Named_Actual
(Parent
(Actual_Id
));
13257 return Next_Named_Actual
(Parent
(Actual_Id
));
13261 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
13263 Actual_Id
:= Next_Actual
(Actual_Id
);
13266 ---------------------
13267 -- No_Scalar_Parts --
13268 ---------------------
13270 function No_Scalar_Parts
(T
: Entity_Id
) return Boolean is
13274 if Is_Scalar_Type
(T
) then
13277 elsif Is_Array_Type
(T
) then
13278 return No_Scalar_Parts
(Component_Type
(T
));
13280 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
13281 C
:= First_Component_Or_Discriminant
(T
);
13282 while Present
(C
) loop
13283 if not No_Scalar_Parts
(Etype
(C
)) then
13286 Next_Component_Or_Discriminant
(C
);
13292 end No_Scalar_Parts
;
13294 -----------------------
13295 -- Normalize_Actuals --
13296 -----------------------
13298 -- Chain actuals according to formals of subprogram. If there are no named
13299 -- associations, the chain is simply the list of Parameter Associations,
13300 -- since the order is the same as the declaration order. If there are named
13301 -- associations, then the First_Named_Actual field in the N_Function_Call
13302 -- or N_Procedure_Call_Statement node points to the Parameter_Association
13303 -- node for the parameter that comes first in declaration order. The
13304 -- remaining named parameters are then chained in declaration order using
13305 -- Next_Named_Actual.
13307 -- This routine also verifies that the number of actuals is compatible with
13308 -- the number and default values of formals, but performs no type checking
13309 -- (type checking is done by the caller).
13311 -- If the matching succeeds, Success is set to True and the caller proceeds
13312 -- with type-checking. If the match is unsuccessful, then Success is set to
13313 -- False, and the caller attempts a different interpretation, if there is
13316 -- If the flag Report is on, the call is not overloaded, and a failure to
13317 -- match can be reported here, rather than in the caller.
13319 procedure Normalize_Actuals
13323 Success
: out Boolean)
13325 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
13326 Actual
: Node_Id
:= Empty
;
13327 Formal
: Entity_Id
;
13328 Last
: Node_Id
:= Empty
;
13329 First_Named
: Node_Id
:= Empty
;
13332 Formals_To_Match
: Integer := 0;
13333 Actuals_To_Match
: Integer := 0;
13335 procedure Chain
(A
: Node_Id
);
13336 -- Add named actual at the proper place in the list, using the
13337 -- Next_Named_Actual link.
13339 function Reporting
return Boolean;
13340 -- Determines if an error is to be reported. To report an error, we
13341 -- need Report to be True, and also we do not report errors caused
13342 -- by calls to init procs that occur within other init procs. Such
13343 -- errors must always be cascaded errors, since if all the types are
13344 -- declared correctly, the compiler will certainly build decent calls.
13350 procedure Chain
(A
: Node_Id
) is
13354 -- Call node points to first actual in list
13356 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
13359 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
13363 Set_Next_Named_Actual
(Last
, Empty
);
13370 function Reporting
return Boolean is
13375 elsif not Within_Init_Proc
then
13378 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
13386 -- Start of processing for Normalize_Actuals
13389 if Is_Access_Type
(S
) then
13391 -- The name in the call is a function call that returns an access
13392 -- to subprogram. The designated type has the list of formals.
13394 Formal
:= First_Formal
(Designated_Type
(S
));
13396 Formal
:= First_Formal
(S
);
13399 while Present
(Formal
) loop
13400 Formals_To_Match
:= Formals_To_Match
+ 1;
13401 Next_Formal
(Formal
);
13404 -- Find if there is a named association, and verify that no positional
13405 -- associations appear after named ones.
13407 if Present
(Actuals
) then
13408 Actual
:= First
(Actuals
);
13411 while Present
(Actual
)
13412 and then Nkind
(Actual
) /= N_Parameter_Association
13414 Actuals_To_Match
:= Actuals_To_Match
+ 1;
13418 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
13420 -- Most common case: positional notation, no defaults
13425 elsif Actuals_To_Match
> Formals_To_Match
then
13427 -- Too many actuals: will not work
13430 if Is_Entity_Name
(Name
(N
)) then
13431 Error_Msg_N
("too many arguments in call to&", Name
(N
));
13433 Error_Msg_N
("too many arguments in call", N
);
13441 First_Named
:= Actual
;
13443 while Present
(Actual
) loop
13444 if Nkind
(Actual
) /= N_Parameter_Association
then
13446 ("positional parameters not allowed after named ones", Actual
);
13451 Actuals_To_Match
:= Actuals_To_Match
+ 1;
13457 if Present
(Actuals
) then
13458 Actual
:= First
(Actuals
);
13461 Formal
:= First_Formal
(S
);
13462 while Present
(Formal
) loop
13464 -- Match the formals in order. If the corresponding actual is
13465 -- positional, nothing to do. Else scan the list of named actuals
13466 -- to find the one with the right name.
13468 if Present
(Actual
)
13469 and then Nkind
(Actual
) /= N_Parameter_Association
13472 Actuals_To_Match
:= Actuals_To_Match
- 1;
13473 Formals_To_Match
:= Formals_To_Match
- 1;
13476 -- For named parameters, search the list of actuals to find
13477 -- one that matches the next formal name.
13479 Actual
:= First_Named
;
13481 while Present
(Actual
) loop
13482 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
13485 Actuals_To_Match
:= Actuals_To_Match
- 1;
13486 Formals_To_Match
:= Formals_To_Match
- 1;
13494 if Ekind
(Formal
) /= E_In_Parameter
13495 or else No
(Default_Value
(Formal
))
13498 if (Comes_From_Source
(S
)
13499 or else Sloc
(S
) = Standard_Location
)
13500 and then Is_Overloadable
(S
)
13504 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
13506 (Nkind
(Parent
(N
)) = N_Function_Call
13508 Nkind
(Parent
(N
)) = N_Parameter_Association
))
13509 and then Ekind
(S
) /= E_Function
13511 Set_Etype
(N
, Etype
(S
));
13513 Error_Msg_Name_1
:= Chars
(S
);
13514 Error_Msg_Sloc
:= Sloc
(S
);
13516 ("missing argument for parameter & " &
13517 "in call to % declared #", N
, Formal
);
13520 elsif Is_Overloadable
(S
) then
13521 Error_Msg_Name_1
:= Chars
(S
);
13523 -- Point to type derivation that generated the
13526 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
13529 ("missing argument for parameter & " &
13530 "in call to % (inherited) #", N
, Formal
);
13534 ("missing argument for parameter &", N
, Formal
);
13542 Formals_To_Match
:= Formals_To_Match
- 1;
13547 Next_Formal
(Formal
);
13550 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
13557 -- Find some superfluous named actual that did not get
13558 -- attached to the list of associations.
13560 Actual
:= First
(Actuals
);
13561 while Present
(Actual
) loop
13562 if Nkind
(Actual
) = N_Parameter_Association
13563 and then Actual
/= Last
13564 and then No
(Next_Named_Actual
(Actual
))
13566 Error_Msg_N
("unmatched actual & in call",
13567 Selector_Name
(Actual
));
13578 end Normalize_Actuals
;
13580 --------------------------------
13581 -- Note_Possible_Modification --
13582 --------------------------------
13584 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
13585 Modification_Comes_From_Source
: constant Boolean :=
13586 Comes_From_Source
(Parent
(N
));
13592 -- Loop to find referenced entity, if there is one
13598 if Is_Entity_Name
(Exp
) then
13599 Ent
:= Entity
(Exp
);
13601 -- If the entity is missing, it is an undeclared identifier,
13602 -- and there is nothing to annotate.
13608 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
13610 P
: constant Node_Id
:= Prefix
(Exp
);
13613 -- In formal verification mode, keep track of all reads and
13614 -- writes through explicit dereferences.
13616 if GNATprove_Mode
then
13617 SPARK_Specific
.Generate_Dereference
(N
, 'm');
13620 if Nkind
(P
) = N_Selected_Component
13621 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
13623 -- Case of a reference to an entry formal
13625 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
13627 elsif Nkind
(P
) = N_Identifier
13628 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
13629 and then Present
(Expression
(Parent
(Entity
(P
))))
13630 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
13633 -- Case of a reference to a value on which side effects have
13636 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
13644 elsif Nkind_In
(Exp
, N_Type_Conversion
,
13645 N_Unchecked_Type_Conversion
)
13647 Exp
:= Expression
(Exp
);
13650 elsif Nkind_In
(Exp
, N_Slice
,
13651 N_Indexed_Component
,
13652 N_Selected_Component
)
13654 -- Special check, if the prefix is an access type, then return
13655 -- since we are modifying the thing pointed to, not the prefix.
13656 -- When we are expanding, most usually the prefix is replaced
13657 -- by an explicit dereference, and this test is not needed, but
13658 -- in some cases (notably -gnatc mode and generics) when we do
13659 -- not do full expansion, we need this special test.
13661 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
13664 -- Otherwise go to prefix and keep going
13667 Exp
:= Prefix
(Exp
);
13671 -- All other cases, not a modification
13677 -- Now look for entity being referenced
13679 if Present
(Ent
) then
13680 if Is_Object
(Ent
) then
13681 if Comes_From_Source
(Exp
)
13682 or else Modification_Comes_From_Source
13684 -- Give warning if pragma unmodified given and we are
13685 -- sure this is a modification.
13687 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
13689 ("??pragma Unmodified given for &!", N
, Ent
);
13692 Set_Never_Set_In_Source
(Ent
, False);
13695 Set_Is_True_Constant
(Ent
, False);
13696 Set_Current_Value
(Ent
, Empty
);
13697 Set_Is_Known_Null
(Ent
, False);
13699 if not Can_Never_Be_Null
(Ent
) then
13700 Set_Is_Known_Non_Null
(Ent
, False);
13703 -- Follow renaming chain
13705 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
13706 and then Present
(Renamed_Object
(Ent
))
13708 Exp
:= Renamed_Object
(Ent
);
13710 -- If the entity is the loop variable in an iteration over
13711 -- a container, retrieve container expression to indicate
13712 -- possible modificastion.
13714 if Present
(Related_Expression
(Ent
))
13715 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
13716 N_Iterator_Specification
13718 Exp
:= Original_Node
(Related_Expression
(Ent
));
13723 -- The expression may be the renaming of a subcomponent of an
13724 -- array or container. The assignment to the subcomponent is
13725 -- a modification of the container.
13727 elsif Comes_From_Source
(Original_Node
(Exp
))
13728 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
13729 N_Indexed_Component
)
13731 Exp
:= Prefix
(Original_Node
(Exp
));
13735 -- Generate a reference only if the assignment comes from
13736 -- source. This excludes, for example, calls to a dispatching
13737 -- assignment operation when the left-hand side is tagged. In
13738 -- GNATprove mode, we need those references also on generated
13739 -- code, as these are used to compute the local effects of
13742 if Modification_Comes_From_Source
or GNATprove_Mode
then
13743 Generate_Reference
(Ent
, Exp
, 'm');
13745 -- If the target of the assignment is the bound variable
13746 -- in an iterator, indicate that the corresponding array
13747 -- or container is also modified.
13749 if Ada_Version
>= Ada_2012
13751 Nkind
(Parent
(Ent
)) = N_Iterator_Specification
13754 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
13757 -- TBD : in the full version of the construct, the
13758 -- domain of iteration can be given by an expression.
13760 if Is_Entity_Name
(Domain
) then
13761 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
13762 Set_Is_True_Constant
(Entity
(Domain
), False);
13763 Set_Never_Set_In_Source
(Entity
(Domain
), False);
13769 Check_Nested_Access
(Ent
);
13774 -- If we are sure this is a modification from source, and we know
13775 -- this modifies a constant, then give an appropriate warning.
13777 if Overlays_Constant
(Ent
)
13778 and then Modification_Comes_From_Source
13782 A
: constant Node_Id
:= Address_Clause
(Ent
);
13784 if Present
(A
) then
13786 Exp
: constant Node_Id
:= Expression
(A
);
13788 if Nkind
(Exp
) = N_Attribute_Reference
13789 and then Attribute_Name
(Exp
) = Name_Address
13790 and then Is_Entity_Name
(Prefix
(Exp
))
13792 Error_Msg_Sloc
:= Sloc
(A
);
13794 ("constant& may be modified via address "
13795 & "clause#??", N
, Entity
(Prefix
(Exp
)));
13808 end Note_Possible_Modification
;
13810 -------------------------
13811 -- Object_Access_Level --
13812 -------------------------
13814 -- Returns the static accessibility level of the view denoted by Obj. Note
13815 -- that the value returned is the result of a call to Scope_Depth. Only
13816 -- scope depths associated with dynamic scopes can actually be returned.
13817 -- Since only relative levels matter for accessibility checking, the fact
13818 -- that the distance between successive levels of accessibility is not
13819 -- always one is immaterial (invariant: if level(E2) is deeper than
13820 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
13822 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
13823 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
13824 -- Determine whether N is a construct of the form
13825 -- Some_Type (Operand._tag'Address)
13826 -- This construct appears in the context of dispatching calls.
13828 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
13829 -- An explicit dereference is created when removing side-effects from
13830 -- expressions for constraint checking purposes. In this case a local
13831 -- access type is created for it. The correct access level is that of
13832 -- the original source node. We detect this case by noting that the
13833 -- prefix of the dereference is created by an object declaration whose
13834 -- initial expression is a reference.
13836 -----------------------------
13837 -- Is_Interface_Conversion --
13838 -----------------------------
13840 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
13843 Nkind
(N
) = N_Unchecked_Type_Conversion
13844 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
13845 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
13846 end Is_Interface_Conversion
;
13852 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
13853 Pref
: constant Node_Id
:= Prefix
(Obj
);
13855 if Is_Entity_Name
(Pref
)
13856 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
13857 and then Present
(Expression
(Parent
(Entity
(Pref
))))
13858 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
13860 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
13870 -- Start of processing for Object_Access_Level
13873 if Nkind
(Obj
) = N_Defining_Identifier
13874 or else Is_Entity_Name
(Obj
)
13876 if Nkind
(Obj
) = N_Defining_Identifier
then
13882 if Is_Prival
(E
) then
13883 E
:= Prival_Link
(E
);
13886 -- If E is a type then it denotes a current instance. For this case
13887 -- we add one to the normal accessibility level of the type to ensure
13888 -- that current instances are treated as always being deeper than
13889 -- than the level of any visible named access type (see 3.10.2(21)).
13891 if Is_Type
(E
) then
13892 return Type_Access_Level
(E
) + 1;
13894 elsif Present
(Renamed_Object
(E
)) then
13895 return Object_Access_Level
(Renamed_Object
(E
));
13897 -- Similarly, if E is a component of the current instance of a
13898 -- protected type, any instance of it is assumed to be at a deeper
13899 -- level than the type. For a protected object (whose type is an
13900 -- anonymous protected type) its components are at the same level
13901 -- as the type itself.
13903 elsif not Is_Overloadable
(E
)
13904 and then Ekind
(Scope
(E
)) = E_Protected_Type
13905 and then Comes_From_Source
(Scope
(E
))
13907 return Type_Access_Level
(Scope
(E
)) + 1;
13910 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
13913 elsif Nkind
(Obj
) = N_Selected_Component
then
13914 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
13915 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13917 return Object_Access_Level
(Prefix
(Obj
));
13920 elsif Nkind
(Obj
) = N_Indexed_Component
then
13921 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
13922 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13924 return Object_Access_Level
(Prefix
(Obj
));
13927 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
13929 -- If the prefix is a selected access discriminant then we make a
13930 -- recursive call on the prefix, which will in turn check the level
13931 -- of the prefix object of the selected discriminant.
13933 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
13934 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
13936 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
13938 return Object_Access_Level
(Prefix
(Obj
));
13940 -- Detect an interface conversion in the context of a dispatching
13941 -- call. Use the original form of the conversion to find the access
13942 -- level of the operand.
13944 elsif Is_Interface
(Etype
(Obj
))
13945 and then Is_Interface_Conversion
(Prefix
(Obj
))
13946 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
13948 return Object_Access_Level
(Original_Node
(Obj
));
13950 elsif not Comes_From_Source
(Obj
) then
13952 Ref
: constant Node_Id
:= Reference_To
(Obj
);
13954 if Present
(Ref
) then
13955 return Object_Access_Level
(Ref
);
13957 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13962 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
13965 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
13966 return Object_Access_Level
(Expression
(Obj
));
13968 elsif Nkind
(Obj
) = N_Function_Call
then
13970 -- Function results are objects, so we get either the access level of
13971 -- the function or, in the case of an indirect call, the level of the
13972 -- access-to-subprogram type. (This code is used for Ada 95, but it
13973 -- looks wrong, because it seems that we should be checking the level
13974 -- of the call itself, even for Ada 95. However, using the Ada 2005
13975 -- version of the code causes regressions in several tests that are
13976 -- compiled with -gnat95. ???)
13978 if Ada_Version
< Ada_2005
then
13979 if Is_Entity_Name
(Name
(Obj
)) then
13980 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
13982 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
13985 -- For Ada 2005, the level of the result object of a function call is
13986 -- defined to be the level of the call's innermost enclosing master.
13987 -- We determine that by querying the depth of the innermost enclosing
13991 Return_Master_Scope_Depth_Of_Call
: declare
13993 function Innermost_Master_Scope_Depth
13994 (N
: Node_Id
) return Uint
;
13995 -- Returns the scope depth of the given node's innermost
13996 -- enclosing dynamic scope (effectively the accessibility
13997 -- level of the innermost enclosing master).
13999 ----------------------------------
14000 -- Innermost_Master_Scope_Depth --
14001 ----------------------------------
14003 function Innermost_Master_Scope_Depth
14004 (N
: Node_Id
) return Uint
14006 Node_Par
: Node_Id
:= Parent
(N
);
14009 -- Locate the nearest enclosing node (by traversing Parents)
14010 -- that Defining_Entity can be applied to, and return the
14011 -- depth of that entity's nearest enclosing dynamic scope.
14013 while Present
(Node_Par
) loop
14014 case Nkind
(Node_Par
) is
14015 when N_Component_Declaration |
14016 N_Entry_Declaration |
14017 N_Formal_Object_Declaration |
14018 N_Formal_Type_Declaration |
14019 N_Full_Type_Declaration |
14020 N_Incomplete_Type_Declaration |
14021 N_Loop_Parameter_Specification |
14022 N_Object_Declaration |
14023 N_Protected_Type_Declaration |
14024 N_Private_Extension_Declaration |
14025 N_Private_Type_Declaration |
14026 N_Subtype_Declaration |
14027 N_Function_Specification |
14028 N_Procedure_Specification |
14029 N_Task_Type_Declaration |
14031 N_Generic_Instantiation |
14033 N_Implicit_Label_Declaration |
14034 N_Package_Declaration |
14035 N_Single_Task_Declaration |
14036 N_Subprogram_Declaration |
14037 N_Generic_Declaration |
14038 N_Renaming_Declaration |
14039 N_Block_Statement |
14040 N_Formal_Subprogram_Declaration |
14041 N_Abstract_Subprogram_Declaration |
14043 N_Exception_Declaration |
14044 N_Formal_Package_Declaration |
14045 N_Number_Declaration |
14046 N_Package_Specification |
14047 N_Parameter_Specification |
14048 N_Single_Protected_Declaration |
14052 (Nearest_Dynamic_Scope
14053 (Defining_Entity
(Node_Par
)));
14059 Node_Par
:= Parent
(Node_Par
);
14062 pragma Assert
(False);
14064 -- Should never reach the following return
14066 return Scope_Depth
(Current_Scope
) + 1;
14067 end Innermost_Master_Scope_Depth
;
14069 -- Start of processing for Return_Master_Scope_Depth_Of_Call
14072 return Innermost_Master_Scope_Depth
(Obj
);
14073 end Return_Master_Scope_Depth_Of_Call
;
14076 -- For convenience we handle qualified expressions, even though they
14077 -- aren't technically object names.
14079 elsif Nkind
(Obj
) = N_Qualified_Expression
then
14080 return Object_Access_Level
(Expression
(Obj
));
14082 -- Otherwise return the scope level of Standard. (If there are cases
14083 -- that fall through to this point they will be treated as having
14084 -- global accessibility for now. ???)
14087 return Scope_Depth
(Standard_Standard
);
14089 end Object_Access_Level
;
14091 --------------------------
14092 -- Original_Aspect_Name --
14093 --------------------------
14095 function Original_Aspect_Name
(N
: Node_Id
) return Name_Id
is
14100 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
14103 if Is_Rewrite_Substitution
(Pras
)
14104 and then Nkind
(Original_Node
(Pras
)) = N_Pragma
14106 Pras
:= Original_Node
(Pras
);
14109 -- Case where we came from aspect specication
14111 if Nkind
(Pras
) = N_Pragma
and then From_Aspect_Specification
(Pras
) then
14112 Pras
:= Corresponding_Aspect
(Pras
);
14115 -- Get name from aspect or pragma
14117 if Nkind
(Pras
) = N_Pragma
then
14118 Name
:= Pragma_Name
(Pras
);
14120 Name
:= Chars
(Identifier
(Pras
));
14123 -- Deal with 'Class
14125 if Class_Present
(Pras
) then
14128 -- Names that need converting to special _xxx form
14136 Name
:= Name_uPost
;
14138 when Name_Invariant
=>
14139 Name
:= Name_uInvariant
;
14141 when Name_Type_Invariant |
14142 Name_Type_Invariant_Class
=>
14143 Name
:= Name_uType_Invariant
;
14145 -- Nothing to do for other cases (e.g. a Check that derived
14146 -- from Pre_Class and has the flag set). Also we do nothing
14147 -- if the name is already in special _xxx form.
14155 end Original_Aspect_Name
;
14156 --------------------------------------
14157 -- Original_Corresponding_Operation --
14158 --------------------------------------
14160 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
14162 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
14165 -- If S is an inherited primitive S2 the original corresponding
14166 -- operation of S is the original corresponding operation of S2
14168 if Present
(Alias
(S
))
14169 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
14171 return Original_Corresponding_Operation
(Alias
(S
));
14173 -- If S overrides an inherited subprogram S2 the original corresponding
14174 -- operation of S is the original corresponding operation of S2
14176 elsif Present
(Overridden_Operation
(S
)) then
14177 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
14179 -- otherwise it is S itself
14184 end Original_Corresponding_Operation
;
14186 -----------------------
14187 -- Private_Component --
14188 -----------------------
14190 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
14191 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
14193 function Trace_Components
14195 Check
: Boolean) return Entity_Id
;
14196 -- Recursive function that does the work, and checks against circular
14197 -- definition for each subcomponent type.
14199 ----------------------
14200 -- Trace_Components --
14201 ----------------------
14203 function Trace_Components
14205 Check
: Boolean) return Entity_Id
14207 Btype
: constant Entity_Id
:= Base_Type
(T
);
14208 Component
: Entity_Id
;
14210 Candidate
: Entity_Id
:= Empty
;
14213 if Check
and then Btype
= Ancestor
then
14214 Error_Msg_N
("circular type definition", Type_Id
);
14218 if Is_Private_Type
(Btype
)
14219 and then not Is_Generic_Type
(Btype
)
14221 if Present
(Full_View
(Btype
))
14222 and then Is_Record_Type
(Full_View
(Btype
))
14223 and then not Is_Frozen
(Btype
)
14225 -- To indicate that the ancestor depends on a private type, the
14226 -- current Btype is sufficient. However, to check for circular
14227 -- definition we must recurse on the full view.
14229 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
14231 if Candidate
= Any_Type
then
14241 elsif Is_Array_Type
(Btype
) then
14242 return Trace_Components
(Component_Type
(Btype
), True);
14244 elsif Is_Record_Type
(Btype
) then
14245 Component
:= First_Entity
(Btype
);
14246 while Present
(Component
)
14247 and then Comes_From_Source
(Component
)
14249 -- Skip anonymous types generated by constrained components
14251 if not Is_Type
(Component
) then
14252 P
:= Trace_Components
(Etype
(Component
), True);
14254 if Present
(P
) then
14255 if P
= Any_Type
then
14263 Next_Entity
(Component
);
14271 end Trace_Components
;
14273 -- Start of processing for Private_Component
14276 return Trace_Components
(Type_Id
, False);
14277 end Private_Component
;
14279 ---------------------------
14280 -- Primitive_Names_Match --
14281 ---------------------------
14283 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
14285 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
14286 -- Given an internal name, returns the corresponding non-internal name
14288 ------------------------
14289 -- Non_Internal_Name --
14290 ------------------------
14292 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
14294 Get_Name_String
(Chars
(E
));
14295 Name_Len
:= Name_Len
- 1;
14297 end Non_Internal_Name
;
14299 -- Start of processing for Primitive_Names_Match
14302 pragma Assert
(Present
(E1
) and then Present
(E2
));
14304 return Chars
(E1
) = Chars
(E2
)
14306 (not Is_Internal_Name
(Chars
(E1
))
14307 and then Is_Internal_Name
(Chars
(E2
))
14308 and then Non_Internal_Name
(E2
) = Chars
(E1
))
14310 (not Is_Internal_Name
(Chars
(E2
))
14311 and then Is_Internal_Name
(Chars
(E1
))
14312 and then Non_Internal_Name
(E1
) = Chars
(E2
))
14314 (Is_Predefined_Dispatching_Operation
(E1
)
14315 and then Is_Predefined_Dispatching_Operation
(E2
)
14316 and then Same_TSS
(E1
, E2
))
14318 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
14319 end Primitive_Names_Match
;
14321 -----------------------
14322 -- Process_End_Label --
14323 -----------------------
14325 procedure Process_End_Label
14334 Label_Ref
: Boolean;
14335 -- Set True if reference to end label itself is required
14338 -- Gets set to the operator symbol or identifier that references the
14339 -- entity Ent. For the child unit case, this is the identifier from the
14340 -- designator. For other cases, this is simply Endl.
14342 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
14343 -- N is an identifier node that appears as a parent unit reference in
14344 -- the case where Ent is a child unit. This procedure generates an
14345 -- appropriate cross-reference entry. E is the corresponding entity.
14347 -------------------------
14348 -- Generate_Parent_Ref --
14349 -------------------------
14351 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
14353 -- If names do not match, something weird, skip reference
14355 if Chars
(E
) = Chars
(N
) then
14357 -- Generate the reference. We do NOT consider this as a reference
14358 -- for unreferenced symbol purposes.
14360 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
14362 if Style_Check
then
14363 Style
.Check_Identifier
(N
, E
);
14366 end Generate_Parent_Ref
;
14368 -- Start of processing for Process_End_Label
14371 -- If no node, ignore. This happens in some error situations, and
14372 -- also for some internally generated structures where no end label
14373 -- references are required in any case.
14379 -- Nothing to do if no End_Label, happens for internally generated
14380 -- constructs where we don't want an end label reference anyway. Also
14381 -- nothing to do if Endl is a string literal, which means there was
14382 -- some prior error (bad operator symbol)
14384 Endl
:= End_Label
(N
);
14386 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
14390 -- Reference node is not in extended main source unit
14392 if not In_Extended_Main_Source_Unit
(N
) then
14394 -- Generally we do not collect references except for the extended
14395 -- main source unit. The one exception is the 'e' entry for a
14396 -- package spec, where it is useful for a client to have the
14397 -- ending information to define scopes.
14403 Label_Ref
:= False;
14405 -- For this case, we can ignore any parent references, but we
14406 -- need the package name itself for the 'e' entry.
14408 if Nkind
(Endl
) = N_Designator
then
14409 Endl
:= Identifier
(Endl
);
14413 -- Reference is in extended main source unit
14418 -- For designator, generate references for the parent entries
14420 if Nkind
(Endl
) = N_Designator
then
14422 -- Generate references for the prefix if the END line comes from
14423 -- source (otherwise we do not need these references) We climb the
14424 -- scope stack to find the expected entities.
14426 if Comes_From_Source
(Endl
) then
14427 Nam
:= Name
(Endl
);
14428 Scop
:= Current_Scope
;
14429 while Nkind
(Nam
) = N_Selected_Component
loop
14430 Scop
:= Scope
(Scop
);
14431 exit when No
(Scop
);
14432 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
14433 Nam
:= Prefix
(Nam
);
14436 if Present
(Scop
) then
14437 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
14441 Endl
:= Identifier
(Endl
);
14445 -- If the end label is not for the given entity, then either we have
14446 -- some previous error, or this is a generic instantiation for which
14447 -- we do not need to make a cross-reference in this case anyway. In
14448 -- either case we simply ignore the call.
14450 if Chars
(Ent
) /= Chars
(Endl
) then
14454 -- If label was really there, then generate a normal reference and then
14455 -- adjust the location in the end label to point past the name (which
14456 -- should almost always be the semicolon).
14458 Loc
:= Sloc
(Endl
);
14460 if Comes_From_Source
(Endl
) then
14462 -- If a label reference is required, then do the style check and
14463 -- generate an l-type cross-reference entry for the label
14466 if Style_Check
then
14467 Style
.Check_Identifier
(Endl
, Ent
);
14470 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
14473 -- Set the location to point past the label (normally this will
14474 -- mean the semicolon immediately following the label). This is
14475 -- done for the sake of the 'e' or 't' entry generated below.
14477 Get_Decoded_Name_String
(Chars
(Endl
));
14478 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
14481 -- In SPARK mode, no missing label is allowed for packages and
14482 -- subprogram bodies. Detect those cases by testing whether
14483 -- Process_End_Label was called for a body (Typ = 't') or a package.
14485 if Restriction_Check_Required
(SPARK_05
)
14486 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
14488 Error_Msg_Node_1
:= Endl
;
14489 Check_SPARK_Restriction
("`END &` required", Endl
, Force
=> True);
14493 -- Now generate the e/t reference
14495 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
14497 -- Restore Sloc, in case modified above, since we have an identifier
14498 -- and the normal Sloc should be left set in the tree.
14500 Set_Sloc
(Endl
, Loc
);
14501 end Process_End_Label
;
14507 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
14508 Seen
: Boolean := False;
14510 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
14511 -- Determine whether node N denotes a reference to Id. If this is the
14512 -- case, set global flag Seen to True and stop the traversal.
14518 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
14520 if Is_Entity_Name
(N
)
14521 and then Present
(Entity
(N
))
14522 and then Entity
(N
) = Id
14531 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
14533 -- Start of processing for Referenced
14536 Inspect_Expression
(Expr
);
14540 ------------------------------------
14541 -- References_Generic_Formal_Type --
14542 ------------------------------------
14544 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
14546 function Process
(N
: Node_Id
) return Traverse_Result
;
14547 -- Process one node in search for generic formal type
14553 function Process
(N
: Node_Id
) return Traverse_Result
is
14555 if Nkind
(N
) in N_Has_Entity
then
14557 E
: constant Entity_Id
:= Entity
(N
);
14559 if Present
(E
) then
14560 if Is_Generic_Type
(E
) then
14562 elsif Present
(Etype
(E
))
14563 and then Is_Generic_Type
(Etype
(E
))
14574 function Traverse
is new Traverse_Func
(Process
);
14575 -- Traverse tree to look for generic type
14578 if Inside_A_Generic
then
14579 return Traverse
(N
) = Abandon
;
14583 end References_Generic_Formal_Type
;
14585 --------------------
14586 -- Remove_Homonym --
14587 --------------------
14589 procedure Remove_Homonym
(E
: Entity_Id
) is
14590 Prev
: Entity_Id
:= Empty
;
14594 if E
= Current_Entity
(E
) then
14595 if Present
(Homonym
(E
)) then
14596 Set_Current_Entity
(Homonym
(E
));
14598 Set_Name_Entity_Id
(Chars
(E
), Empty
);
14602 H
:= Current_Entity
(E
);
14603 while Present
(H
) and then H
/= E
loop
14608 -- If E is not on the homonym chain, nothing to do
14610 if Present
(H
) then
14611 Set_Homonym
(Prev
, Homonym
(E
));
14614 end Remove_Homonym
;
14616 ---------------------
14617 -- Rep_To_Pos_Flag --
14618 ---------------------
14620 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
14622 return New_Occurrence_Of
14623 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
14624 end Rep_To_Pos_Flag
;
14626 --------------------
14627 -- Require_Entity --
14628 --------------------
14630 procedure Require_Entity
(N
: Node_Id
) is
14632 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
14633 if Total_Errors_Detected
/= 0 then
14634 Set_Entity
(N
, Any_Id
);
14636 raise Program_Error
;
14639 end Require_Entity
;
14641 -------------------------------
14642 -- Requires_State_Refinement --
14643 -------------------------------
14645 function Requires_State_Refinement
14646 (Spec_Id
: Entity_Id
;
14647 Body_Id
: Entity_Id
) return Boolean
14649 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
14650 -- Given pragma SPARK_Mode, determine whether the mode is Off
14656 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
14660 -- The default SPARK mode is On
14666 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
14668 -- Then the pragma lacks an argument, the default mode is On
14673 return Chars
(Mode
) = Name_Off
;
14677 -- Start of processing for Requires_State_Refinement
14680 -- A package that does not define at least one abstract state cannot
14681 -- possibly require refinement.
14683 if No
(Abstract_States
(Spec_Id
)) then
14686 -- The package instroduces a single null state which does not merit
14689 elsif Has_Null_Abstract_State
(Spec_Id
) then
14692 -- Check whether the package body is subject to pragma SPARK_Mode. If
14693 -- it is and the mode is Off, the package body is considered to be in
14694 -- regular Ada and does not require refinement.
14696 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
14699 -- The body's SPARK_Mode may be inherited from a similar pragma that
14700 -- appears in the private declarations of the spec. The pragma we are
14701 -- interested appears as the second entry in SPARK_Pragma.
14703 elsif Present
(SPARK_Pragma
(Spec_Id
))
14704 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
14708 -- The spec defines at least one abstract state and the body has no way
14709 -- of circumventing the refinement.
14714 end Requires_State_Refinement
;
14716 ------------------------------
14717 -- Requires_Transient_Scope --
14718 ------------------------------
14720 -- A transient scope is required when variable-sized temporaries are
14721 -- allocated in the primary or secondary stack, or when finalization
14722 -- actions must be generated before the next instruction.
14724 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
14725 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
14727 -- Start of processing for Requires_Transient_Scope
14730 -- This is a private type which is not completed yet. This can only
14731 -- happen in a default expression (of a formal parameter or of a
14732 -- record component). Do not expand transient scope in this case
14737 -- Do not expand transient scope for non-existent procedure return
14739 elsif Typ
= Standard_Void_Type
then
14742 -- Elementary types do not require a transient scope
14744 elsif Is_Elementary_Type
(Typ
) then
14747 -- Generally, indefinite subtypes require a transient scope, since the
14748 -- back end cannot generate temporaries, since this is not a valid type
14749 -- for declaring an object. It might be possible to relax this in the
14750 -- future, e.g. by declaring the maximum possible space for the type.
14752 elsif Is_Indefinite_Subtype
(Typ
) then
14755 -- Functions returning tagged types may dispatch on result so their
14756 -- returned value is allocated on the secondary stack. Controlled
14757 -- type temporaries need finalization.
14759 elsif Is_Tagged_Type
(Typ
)
14760 or else Has_Controlled_Component
(Typ
)
14762 return not Is_Value_Type
(Typ
);
14766 elsif Is_Record_Type
(Typ
) then
14770 Comp
:= First_Entity
(Typ
);
14771 while Present
(Comp
) loop
14772 if Ekind
(Comp
) = E_Component
14773 and then Requires_Transient_Scope
(Etype
(Comp
))
14777 Next_Entity
(Comp
);
14784 -- String literal types never require transient scope
14786 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
14789 -- Array type. Note that we already know that this is a constrained
14790 -- array, since unconstrained arrays will fail the indefinite test.
14792 elsif Is_Array_Type
(Typ
) then
14794 -- If component type requires a transient scope, the array does too
14796 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
14799 -- Otherwise, we only need a transient scope if the size depends on
14800 -- the value of one or more discriminants.
14803 return Size_Depends_On_Discriminant
(Typ
);
14806 -- All other cases do not require a transient scope
14811 end Requires_Transient_Scope
;
14813 --------------------------
14814 -- Reset_Analyzed_Flags --
14815 --------------------------
14817 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
14819 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
14820 -- Function used to reset Analyzed flags in tree. Note that we do
14821 -- not reset Analyzed flags in entities, since there is no need to
14822 -- reanalyze entities, and indeed, it is wrong to do so, since it
14823 -- can result in generating auxiliary stuff more than once.
14825 --------------------
14826 -- Clear_Analyzed --
14827 --------------------
14829 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
14831 if not Has_Extension
(N
) then
14832 Set_Analyzed
(N
, False);
14836 end Clear_Analyzed
;
14838 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
14840 -- Start of processing for Reset_Analyzed_Flags
14843 Reset_Analyzed
(N
);
14844 end Reset_Analyzed_Flags
;
14846 --------------------------------
14847 -- Returns_Unconstrained_Type --
14848 --------------------------------
14850 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
14852 return Ekind
(Subp
) = E_Function
14853 and then not Is_Scalar_Type
(Etype
(Subp
))
14854 and then not Is_Access_Type
(Etype
(Subp
))
14855 and then not Is_Constrained
(Etype
(Subp
));
14856 end Returns_Unconstrained_Type
;
14858 ---------------------------
14859 -- Safe_To_Capture_Value --
14860 ---------------------------
14862 function Safe_To_Capture_Value
14865 Cond
: Boolean := False) return Boolean
14868 -- The only entities for which we track constant values are variables
14869 -- which are not renamings, constants, out parameters, and in out
14870 -- parameters, so check if we have this case.
14872 -- Note: it may seem odd to track constant values for constants, but in
14873 -- fact this routine is used for other purposes than simply capturing
14874 -- the value. In particular, the setting of Known[_Non]_Null.
14876 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
14878 Ekind
(Ent
) = E_Constant
14880 Ekind
(Ent
) = E_Out_Parameter
14882 Ekind
(Ent
) = E_In_Out_Parameter
14886 -- For conditionals, we also allow loop parameters and all formals,
14887 -- including in parameters.
14891 (Ekind
(Ent
) = E_Loop_Parameter
14893 Ekind
(Ent
) = E_In_Parameter
)
14897 -- For all other cases, not just unsafe, but impossible to capture
14898 -- Current_Value, since the above are the only entities which have
14899 -- Current_Value fields.
14905 -- Skip if volatile or aliased, since funny things might be going on in
14906 -- these cases which we cannot necessarily track. Also skip any variable
14907 -- for which an address clause is given, or whose address is taken. Also
14908 -- never capture value of library level variables (an attempt to do so
14909 -- can occur in the case of package elaboration code).
14911 if Treat_As_Volatile
(Ent
)
14912 or else Is_Aliased
(Ent
)
14913 or else Present
(Address_Clause
(Ent
))
14914 or else Address_Taken
(Ent
)
14915 or else (Is_Library_Level_Entity
(Ent
)
14916 and then Ekind
(Ent
) = E_Variable
)
14921 -- OK, all above conditions are met. We also require that the scope of
14922 -- the reference be the same as the scope of the entity, not counting
14923 -- packages and blocks and loops.
14926 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
14927 R_Scope
: Entity_Id
;
14930 R_Scope
:= Current_Scope
;
14931 while R_Scope
/= Standard_Standard
loop
14932 exit when R_Scope
= E_Scope
;
14934 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
14937 R_Scope
:= Scope
(R_Scope
);
14942 -- We also require that the reference does not appear in a context
14943 -- where it is not sure to be executed (i.e. a conditional context
14944 -- or an exception handler). We skip this if Cond is True, since the
14945 -- capturing of values from conditional tests handles this ok.
14958 -- Seems dubious that case expressions are not handled here ???
14961 while Present
(P
) loop
14962 if Nkind
(P
) = N_If_Statement
14963 or else Nkind
(P
) = N_Case_Statement
14964 or else (Nkind
(P
) in N_Short_Circuit
14965 and then Desc
= Right_Opnd
(P
))
14966 or else (Nkind
(P
) = N_If_Expression
14967 and then Desc
/= First
(Expressions
(P
)))
14968 or else Nkind
(P
) = N_Exception_Handler
14969 or else Nkind
(P
) = N_Selective_Accept
14970 or else Nkind
(P
) = N_Conditional_Entry_Call
14971 or else Nkind
(P
) = N_Timed_Entry_Call
14972 or else Nkind
(P
) = N_Asynchronous_Select
14979 -- A special Ada 2012 case: the original node may be part
14980 -- of the else_actions of a conditional expression, in which
14981 -- case it might not have been expanded yet, and appears in
14982 -- a non-syntactic list of actions. In that case it is clearly
14983 -- not safe to save a value.
14986 and then Is_List_Member
(Desc
)
14987 and then No
(Parent
(List_Containing
(Desc
)))
14995 -- OK, looks safe to set value
14998 end Safe_To_Capture_Value
;
15004 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
15005 K1
: constant Node_Kind
:= Nkind
(N1
);
15006 K2
: constant Node_Kind
:= Nkind
(N2
);
15009 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
15010 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
15012 return Chars
(N1
) = Chars
(N2
);
15014 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
15015 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
15017 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
15018 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
15029 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
15030 N1
: constant Node_Id
:= Original_Node
(Node1
);
15031 N2
: constant Node_Id
:= Original_Node
(Node2
);
15032 -- We do the tests on original nodes, since we are most interested
15033 -- in the original source, not any expansion that got in the way.
15035 K1
: constant Node_Kind
:= Nkind
(N1
);
15036 K2
: constant Node_Kind
:= Nkind
(N2
);
15039 -- First case, both are entities with same entity
15041 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
15043 EN1
: constant Entity_Id
:= Entity
(N1
);
15044 EN2
: constant Entity_Id
:= Entity
(N2
);
15046 if Present
(EN1
) and then Present
(EN2
)
15047 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
15048 or else Is_Formal
(EN1
))
15056 -- Second case, selected component with same selector, same record
15058 if K1
= N_Selected_Component
15059 and then K2
= N_Selected_Component
15060 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
15062 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
15064 -- Third case, indexed component with same subscripts, same array
15066 elsif K1
= N_Indexed_Component
15067 and then K2
= N_Indexed_Component
15068 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
15073 E1
:= First
(Expressions
(N1
));
15074 E2
:= First
(Expressions
(N2
));
15075 while Present
(E1
) loop
15076 if not Same_Value
(E1
, E2
) then
15087 -- Fourth case, slice of same array with same bounds
15090 and then K2
= N_Slice
15091 and then Nkind
(Discrete_Range
(N1
)) = N_Range
15092 and then Nkind
(Discrete_Range
(N2
)) = N_Range
15093 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
15094 Low_Bound
(Discrete_Range
(N2
)))
15095 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
15096 High_Bound
(Discrete_Range
(N2
)))
15098 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
15100 -- All other cases, not clearly the same object
15111 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
15116 elsif not Is_Constrained
(T1
)
15117 and then not Is_Constrained
(T2
)
15118 and then Base_Type
(T1
) = Base_Type
(T2
)
15122 -- For now don't bother with case of identical constraints, to be
15123 -- fiddled with later on perhaps (this is only used for optimization
15124 -- purposes, so it is not critical to do a best possible job)
15135 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
15137 if Compile_Time_Known_Value
(Node1
)
15138 and then Compile_Time_Known_Value
(Node2
)
15139 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
15142 elsif Same_Object
(Node1
, Node2
) then
15149 ------------------------
15150 -- Scope_Is_Transient --
15151 ------------------------
15153 function Scope_Is_Transient
return Boolean is
15155 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
15156 end Scope_Is_Transient
;
15162 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
15167 while Scop
/= Standard_Standard
loop
15168 Scop
:= Scope
(Scop
);
15170 if Scop
= Scope2
then
15178 --------------------------
15179 -- Scope_Within_Or_Same --
15180 --------------------------
15182 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
15187 while Scop
/= Standard_Standard
loop
15188 if Scop
= Scope2
then
15191 Scop
:= Scope
(Scop
);
15196 end Scope_Within_Or_Same
;
15198 --------------------
15199 -- Set_Convention --
15200 --------------------
15202 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
15204 Basic_Set_Convention
(E
, Val
);
15207 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
15208 and then Has_Foreign_Convention
(E
)
15210 Set_Can_Use_Internal_Rep
(E
, False);
15212 end Set_Convention
;
15214 ------------------------
15215 -- Set_Current_Entity --
15216 ------------------------
15218 -- The given entity is to be set as the currently visible definition of its
15219 -- associated name (i.e. the Node_Id associated with its name). All we have
15220 -- to do is to get the name from the identifier, and then set the
15221 -- associated Node_Id to point to the given entity.
15223 procedure Set_Current_Entity
(E
: Entity_Id
) is
15225 Set_Name_Entity_Id
(Chars
(E
), E
);
15226 end Set_Current_Entity
;
15228 ---------------------------
15229 -- Set_Debug_Info_Needed --
15230 ---------------------------
15232 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
15234 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
15235 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
15236 -- Used to set debug info in a related node if not set already
15238 --------------------------------------
15239 -- Set_Debug_Info_Needed_If_Not_Set --
15240 --------------------------------------
15242 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
15245 and then not Needs_Debug_Info
(E
)
15247 Set_Debug_Info_Needed
(E
);
15249 -- For a private type, indicate that the full view also needs
15250 -- debug information.
15253 and then Is_Private_Type
(E
)
15254 and then Present
(Full_View
(E
))
15256 Set_Debug_Info_Needed
(Full_View
(E
));
15259 end Set_Debug_Info_Needed_If_Not_Set
;
15261 -- Start of processing for Set_Debug_Info_Needed
15264 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
15265 -- indicates that Debug_Info_Needed is never required for the entity.
15268 or else Debug_Info_Off
(T
)
15273 -- Set flag in entity itself. Note that we will go through the following
15274 -- circuitry even if the flag is already set on T. That's intentional,
15275 -- it makes sure that the flag will be set in subsidiary entities.
15277 Set_Needs_Debug_Info
(T
);
15279 -- Set flag on subsidiary entities if not set already
15281 if Is_Object
(T
) then
15282 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
15284 elsif Is_Type
(T
) then
15285 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
15287 if Is_Record_Type
(T
) then
15289 Ent
: Entity_Id
:= First_Entity
(T
);
15291 while Present
(Ent
) loop
15292 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
15297 -- For a class wide subtype, we also need debug information
15298 -- for the equivalent type.
15300 if Ekind
(T
) = E_Class_Wide_Subtype
then
15301 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
15304 elsif Is_Array_Type
(T
) then
15305 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
15308 Indx
: Node_Id
:= First_Index
(T
);
15310 while Present
(Indx
) loop
15311 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
15312 Indx
:= Next_Index
(Indx
);
15316 -- For a packed array type, we also need debug information for
15317 -- the type used to represent the packed array. Conversely, we
15318 -- also need it for the former if we need it for the latter.
15320 if Is_Packed
(T
) then
15321 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
15324 if Is_Packed_Array_Type
(T
) then
15325 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
15328 elsif Is_Access_Type
(T
) then
15329 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
15331 elsif Is_Private_Type
(T
) then
15332 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
15334 elsif Is_Protected_Type
(T
) then
15335 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
15338 end Set_Debug_Info_Needed
;
15340 ---------------------------------
15341 -- Set_Entity_With_Style_Check --
15342 ---------------------------------
15344 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
15345 Val_Actual
: Entity_Id
;
15349 -- Unconditionally set the entity
15351 Set_Entity
(N
, Val
);
15353 -- Check for No_Implementation_Identifiers
15355 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
15357 -- We have an implementation defined entity if it is marked as
15358 -- implementation defined, or is defined in a package marked as
15359 -- implementation defined. However, library packages themselves
15360 -- are excluded (we don't want to flag Interfaces itself, just
15361 -- the entities within it).
15363 if (Is_Implementation_Defined
(Val
)
15365 Is_Implementation_Defined
(Scope
(Val
)))
15366 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
15367 and then Is_Library_Level_Entity
(Val
))
15369 Check_Restriction
(No_Implementation_Identifiers
, N
);
15373 -- Do the style check
15376 and then not Suppress_Style_Checks
(Val
)
15377 and then not In_Instance
15379 if Nkind
(N
) = N_Identifier
then
15381 elsif Nkind
(N
) = N_Expanded_Name
then
15382 Nod
:= Selector_Name
(N
);
15387 -- A special situation arises for derived operations, where we want
15388 -- to do the check against the parent (since the Sloc of the derived
15389 -- operation points to the derived type declaration itself).
15392 while not Comes_From_Source
(Val_Actual
)
15393 and then Nkind
(Val_Actual
) in N_Entity
15394 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
15395 or else Is_Subprogram
(Val_Actual
)
15396 or else Is_Generic_Subprogram
(Val_Actual
))
15397 and then Present
(Alias
(Val_Actual
))
15399 Val_Actual
:= Alias
(Val_Actual
);
15402 -- Renaming declarations for generic actuals do not come from source,
15403 -- and have a different name from that of the entity they rename, so
15404 -- there is no style check to perform here.
15406 if Chars
(Nod
) = Chars
(Val_Actual
) then
15407 Style
.Check_Identifier
(Nod
, Val_Actual
);
15411 Set_Entity
(N
, Val
);
15412 end Set_Entity_With_Style_Check
;
15414 ------------------------
15415 -- Set_Name_Entity_Id --
15416 ------------------------
15418 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
15420 Set_Name_Table_Info
(Id
, Int
(Val
));
15421 end Set_Name_Entity_Id
;
15423 ---------------------
15424 -- Set_Next_Actual --
15425 ---------------------
15427 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
15429 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
15430 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
15432 end Set_Next_Actual
;
15434 ----------------------------------
15435 -- Set_Optimize_Alignment_Flags --
15436 ----------------------------------
15438 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
15440 if Optimize_Alignment
= 'S' then
15441 Set_Optimize_Alignment_Space
(E
);
15442 elsif Optimize_Alignment
= 'T' then
15443 Set_Optimize_Alignment_Time
(E
);
15445 end Set_Optimize_Alignment_Flags
;
15447 -----------------------
15448 -- Set_Public_Status --
15449 -----------------------
15451 procedure Set_Public_Status
(Id
: Entity_Id
) is
15452 S
: constant Entity_Id
:= Current_Scope
;
15454 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
15455 -- Determines if E is defined within handled statement sequence or
15456 -- an if statement, returns True if so, False otherwise.
15458 ----------------------
15459 -- Within_HSS_Or_If --
15460 ----------------------
15462 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
15465 N
:= Declaration_Node
(E
);
15472 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
15478 end Within_HSS_Or_If
;
15480 -- Start of processing for Set_Public_Status
15483 -- Everything in the scope of Standard is public
15485 if S
= Standard_Standard
then
15486 Set_Is_Public
(Id
);
15488 -- Entity is definitely not public if enclosing scope is not public
15490 elsif not Is_Public
(S
) then
15493 -- An object or function declaration that occurs in a handled sequence
15494 -- of statements or within an if statement is the declaration for a
15495 -- temporary object or local subprogram generated by the expander. It
15496 -- never needs to be made public and furthermore, making it public can
15497 -- cause back end problems.
15499 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
15500 N_Function_Specification
)
15501 and then Within_HSS_Or_If
(Id
)
15505 -- Entities in public packages or records are public
15507 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
15508 Set_Is_Public
(Id
);
15510 -- The bounds of an entry family declaration can generate object
15511 -- declarations that are visible to the back-end, e.g. in the
15512 -- the declaration of a composite type that contains tasks.
15514 elsif Is_Concurrent_Type
(S
)
15515 and then not Has_Completion
(S
)
15516 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
15518 Set_Is_Public
(Id
);
15520 end Set_Public_Status
;
15522 -----------------------------
15523 -- Set_Referenced_Modified --
15524 -----------------------------
15526 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
15530 -- Deal with indexed or selected component where prefix is modified
15532 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
15533 Pref
:= Prefix
(N
);
15535 -- If prefix is access type, then it is the designated object that is
15536 -- being modified, which means we have no entity to set the flag on.
15538 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
15541 -- Otherwise chase the prefix
15544 Set_Referenced_Modified
(Pref
, Out_Param
);
15547 -- Otherwise see if we have an entity name (only other case to process)
15549 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
15550 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
15551 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
15553 end Set_Referenced_Modified
;
15555 ----------------------------
15556 -- Set_Scope_Is_Transient --
15557 ----------------------------
15559 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
15561 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
15562 end Set_Scope_Is_Transient
;
15564 -------------------
15565 -- Set_Size_Info --
15566 -------------------
15568 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
15570 -- We copy Esize, but not RM_Size, since in general RM_Size is
15571 -- subtype specific and does not get inherited by all subtypes.
15573 Set_Esize
(T1
, Esize
(T2
));
15574 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
15576 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
15578 Is_Discrete_Or_Fixed_Point_Type
(T2
)
15580 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
15583 Set_Alignment
(T1
, Alignment
(T2
));
15586 --------------------
15587 -- Static_Boolean --
15588 --------------------
15590 function Static_Boolean
(N
: Node_Id
) return Uint
is
15592 Analyze_And_Resolve
(N
, Standard_Boolean
);
15595 or else Error_Posted
(N
)
15596 or else Etype
(N
) = Any_Type
15601 if Is_Static_Expression
(N
) then
15602 if not Raises_Constraint_Error
(N
) then
15603 return Expr_Value
(N
);
15608 elsif Etype
(N
) = Any_Type
then
15612 Flag_Non_Static_Expr
15613 ("static boolean expression required here", N
);
15616 end Static_Boolean
;
15618 --------------------
15619 -- Static_Integer --
15620 --------------------
15622 function Static_Integer
(N
: Node_Id
) return Uint
is
15624 Analyze_And_Resolve
(N
, Any_Integer
);
15627 or else Error_Posted
(N
)
15628 or else Etype
(N
) = Any_Type
15633 if Is_Static_Expression
(N
) then
15634 if not Raises_Constraint_Error
(N
) then
15635 return Expr_Value
(N
);
15640 elsif Etype
(N
) = Any_Type
then
15644 Flag_Non_Static_Expr
15645 ("static integer expression required here", N
);
15648 end Static_Integer
;
15650 --------------------------
15651 -- Statically_Different --
15652 --------------------------
15654 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
15655 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
15656 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
15658 return Is_Entity_Name
(R1
)
15659 and then Is_Entity_Name
(R2
)
15660 and then Entity
(R1
) /= Entity
(R2
)
15661 and then not Is_Formal
(Entity
(R1
))
15662 and then not Is_Formal
(Entity
(R2
));
15663 end Statically_Different
;
15665 --------------------------------------
15666 -- Subject_To_Loop_Entry_Attributes --
15667 --------------------------------------
15669 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
15675 -- The expansion mechanism transform a loop subject to at least one
15676 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
15677 -- the conditional part.
15679 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
15680 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
15682 Stmt
:= Original_Node
(N
);
15686 Nkind
(Stmt
) = N_Loop_Statement
15687 and then Present
(Identifier
(Stmt
))
15688 and then Present
(Entity
(Identifier
(Stmt
)))
15689 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
15690 end Subject_To_Loop_Entry_Attributes
;
15692 -----------------------------
15693 -- Subprogram_Access_Level --
15694 -----------------------------
15696 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
15698 if Present
(Alias
(Subp
)) then
15699 return Subprogram_Access_Level
(Alias
(Subp
));
15701 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
15703 end Subprogram_Access_Level
;
15705 -------------------------------
15706 -- Support_Atomic_Primitives --
15707 -------------------------------
15709 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
15713 -- Verify the alignment of Typ is known
15715 if not Known_Alignment
(Typ
) then
15719 if Known_Static_Esize
(Typ
) then
15720 Size
:= UI_To_Int
(Esize
(Typ
));
15722 -- If the Esize (Object_Size) is unknown at compile time, look at the
15723 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
15725 elsif Known_Static_RM_Size
(Typ
) then
15726 Size
:= UI_To_Int
(RM_Size
(Typ
));
15728 -- Otherwise, the size is considered to be unknown.
15734 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
15735 -- Typ is properly aligned.
15738 when 8 |
16 |
32 |
64 =>
15739 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
15743 end Support_Atomic_Primitives
;
15749 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
15751 if Debug_Flag_W
then
15752 for J
in 0 .. Scope_Stack
.Last
loop
15757 Write_Name
(Chars
(E
));
15758 Write_Str
(" from ");
15759 Write_Location
(Sloc
(N
));
15764 -----------------------
15765 -- Transfer_Entities --
15766 -----------------------
15768 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
15769 Ent
: Entity_Id
:= First_Entity
(From
);
15776 if (Last_Entity
(To
)) = Empty
then
15777 Set_First_Entity
(To
, Ent
);
15779 Set_Next_Entity
(Last_Entity
(To
), Ent
);
15782 Set_Last_Entity
(To
, Last_Entity
(From
));
15784 while Present
(Ent
) loop
15785 Set_Scope
(Ent
, To
);
15787 if not Is_Public
(Ent
) then
15788 Set_Public_Status
(Ent
);
15791 and then Ekind
(Ent
) = E_Record_Subtype
15794 -- The components of the propagated Itype must be public
15800 Comp
:= First_Entity
(Ent
);
15801 while Present
(Comp
) loop
15802 Set_Is_Public
(Comp
);
15803 Next_Entity
(Comp
);
15812 Set_First_Entity
(From
, Empty
);
15813 Set_Last_Entity
(From
, Empty
);
15814 end Transfer_Entities
;
15816 -----------------------
15817 -- Type_Access_Level --
15818 -----------------------
15820 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
15824 Btyp
:= Base_Type
(Typ
);
15826 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
15827 -- simply use the level where the type is declared. This is true for
15828 -- stand-alone object declarations, and for anonymous access types
15829 -- associated with components the level is the same as that of the
15830 -- enclosing composite type. However, special treatment is needed for
15831 -- the cases of access parameters, return objects of an anonymous access
15832 -- type, and, in Ada 95, access discriminants of limited types.
15834 if Ekind
(Btyp
) in Access_Kind
then
15835 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
15837 -- If the type is a nonlocal anonymous access type (such as for
15838 -- an access parameter) we treat it as being declared at the
15839 -- library level to ensure that names such as X.all'access don't
15840 -- fail static accessibility checks.
15842 if not Is_Local_Anonymous_Access
(Typ
) then
15843 return Scope_Depth
(Standard_Standard
);
15845 -- If this is a return object, the accessibility level is that of
15846 -- the result subtype of the enclosing function. The test here is
15847 -- little complicated, because we have to account for extended
15848 -- return statements that have been rewritten as blocks, in which
15849 -- case we have to find and the Is_Return_Object attribute of the
15850 -- itype's associated object. It would be nice to find a way to
15851 -- simplify this test, but it doesn't seem worthwhile to add a new
15852 -- flag just for purposes of this test. ???
15854 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
15857 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
15858 N_Object_Declaration
15859 and then Is_Return_Object
15860 (Defining_Identifier
15861 (Associated_Node_For_Itype
(Btyp
))))
15867 Scop
:= Scope
(Scope
(Btyp
));
15868 while Present
(Scop
) loop
15869 exit when Ekind
(Scop
) = E_Function
;
15870 Scop
:= Scope
(Scop
);
15873 -- Treat the return object's type as having the level of the
15874 -- function's result subtype (as per RM05-6.5(5.3/2)).
15876 return Type_Access_Level
(Etype
(Scop
));
15881 Btyp
:= Root_Type
(Btyp
);
15883 -- The accessibility level of anonymous access types associated with
15884 -- discriminants is that of the current instance of the type, and
15885 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
15887 -- AI-402: access discriminants have accessibility based on the
15888 -- object rather than the type in Ada 2005, so the above paragraph
15891 -- ??? Needs completion with rules from AI-416
15893 if Ada_Version
<= Ada_95
15894 and then Ekind
(Typ
) = E_Anonymous_Access_Type
15895 and then Present
(Associated_Node_For_Itype
(Typ
))
15896 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
15897 N_Discriminant_Specification
15899 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
15903 -- Return library level for a generic formal type. This is done because
15904 -- RM(10.3.2) says that "The statically deeper relationship does not
15905 -- apply to ... a descendant of a generic formal type". Rather than
15906 -- checking at each point where a static accessibility check is
15907 -- performed to see if we are dealing with a formal type, this rule is
15908 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
15909 -- return extreme values for a formal type; Deepest_Type_Access_Level
15910 -- returns Int'Last. By calling the appropriate function from among the
15911 -- two, we ensure that the static accessibility check will pass if we
15912 -- happen to run into a formal type. More specifically, we should call
15913 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
15914 -- call occurs as part of a static accessibility check and the error
15915 -- case is the case where the type's level is too shallow (as opposed
15918 if Is_Generic_Type
(Root_Type
(Btyp
)) then
15919 return Scope_Depth
(Standard_Standard
);
15922 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
15923 end Type_Access_Level
;
15925 ------------------------------------
15926 -- Type_Without_Stream_Operation --
15927 ------------------------------------
15929 function Type_Without_Stream_Operation
15931 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
15933 BT
: constant Entity_Id
:= Base_Type
(T
);
15934 Op_Missing
: Boolean;
15937 if not Restriction_Active
(No_Default_Stream_Attributes
) then
15941 if Is_Elementary_Type
(T
) then
15942 if Op
= TSS_Null
then
15944 No
(TSS
(BT
, TSS_Stream_Read
))
15945 or else No
(TSS
(BT
, TSS_Stream_Write
));
15948 Op_Missing
:= No
(TSS
(BT
, Op
));
15957 elsif Is_Array_Type
(T
) then
15958 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
15960 elsif Is_Record_Type
(T
) then
15966 Comp
:= First_Component
(T
);
15967 while Present
(Comp
) loop
15968 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
15970 if Present
(C_Typ
) then
15974 Next_Component
(Comp
);
15980 elsif Is_Private_Type
(T
)
15981 and then Present
(Full_View
(T
))
15983 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
15987 end Type_Without_Stream_Operation
;
15989 ----------------------------
15990 -- Unique_Defining_Entity --
15991 ----------------------------
15993 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
15995 return Unique_Entity
(Defining_Entity
(N
));
15996 end Unique_Defining_Entity
;
15998 -------------------
15999 -- Unique_Entity --
16000 -------------------
16002 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
16003 U
: Entity_Id
:= E
;
16009 if Present
(Full_View
(E
)) then
16010 U
:= Full_View
(E
);
16014 if Present
(Full_View
(E
)) then
16015 U
:= Full_View
(E
);
16018 when E_Package_Body
=>
16021 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
16025 U
:= Corresponding_Spec
(P
);
16027 when E_Subprogram_Body
=>
16030 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
16036 if Nkind
(P
) = N_Subprogram_Body_Stub
then
16037 if Present
(Library_Unit
(P
)) then
16039 -- Get to the function or procedure (generic) entity through
16040 -- the body entity.
16043 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
16046 U
:= Corresponding_Spec
(P
);
16049 when Formal_Kind
=>
16050 if Present
(Spec_Entity
(E
)) then
16051 U
:= Spec_Entity
(E
);
16065 function Unique_Name
(E
: Entity_Id
) return String is
16067 -- Names of E_Subprogram_Body or E_Package_Body entities are not
16068 -- reliable, as they may not include the overloading suffix. Instead,
16069 -- when looking for the name of E or one of its enclosing scope, we get
16070 -- the name of the corresponding Unique_Entity.
16072 function Get_Scoped_Name
(E
: Entity_Id
) return String;
16073 -- Return the name of E prefixed by all the names of the scopes to which
16074 -- E belongs, except for Standard.
16076 ---------------------
16077 -- Get_Scoped_Name --
16078 ---------------------
16080 function Get_Scoped_Name
(E
: Entity_Id
) return String is
16081 Name
: constant String := Get_Name_String
(Chars
(E
));
16083 if Has_Fully_Qualified_Name
(E
)
16084 or else Scope
(E
) = Standard_Standard
16088 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
16090 end Get_Scoped_Name
;
16092 -- Start of processing for Unique_Name
16095 if E
= Standard_Standard
then
16096 return Get_Name_String
(Name_Standard
);
16098 elsif Scope
(E
) = Standard_Standard
16099 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
16101 return Get_Name_String
(Name_Standard
) & "__" &
16102 Get_Name_String
(Chars
(E
));
16104 elsif Ekind
(E
) = E_Enumeration_Literal
then
16105 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
16108 return Get_Scoped_Name
(Unique_Entity
(E
));
16112 ---------------------
16113 -- Unit_Is_Visible --
16114 ---------------------
16116 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
16117 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
16118 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
16120 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
16121 -- For a child unit, check whether unit appears in a with_clause
16124 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
16125 -- Scan the context clause of one compilation unit looking for a
16126 -- with_clause for the unit in question.
16128 ----------------------------
16129 -- Unit_In_Parent_Context --
16130 ----------------------------
16132 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
16134 if Unit_In_Context
(Par_Unit
) then
16137 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
16138 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
16143 end Unit_In_Parent_Context
;
16145 ---------------------
16146 -- Unit_In_Context --
16147 ---------------------
16149 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
16153 Clause
:= First
(Context_Items
(Comp_Unit
));
16154 while Present
(Clause
) loop
16155 if Nkind
(Clause
) = N_With_Clause
then
16156 if Library_Unit
(Clause
) = U
then
16159 -- The with_clause may denote a renaming of the unit we are
16160 -- looking for, eg. Text_IO which renames Ada.Text_IO.
16163 Renamed_Entity
(Entity
(Name
(Clause
))) =
16164 Defining_Entity
(Unit
(U
))
16174 end Unit_In_Context
;
16176 -- Start of processing for Unit_Is_Visible
16179 -- The currrent unit is directly visible
16184 elsif Unit_In_Context
(Curr
) then
16187 -- If the current unit is a body, check the context of the spec
16189 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
16191 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
16192 and then not Acts_As_Spec
(Unit
(Curr
)))
16194 if Unit_In_Context
(Library_Unit
(Curr
)) then
16199 -- If the spec is a child unit, examine the parents
16201 if Is_Child_Unit
(Curr_Entity
) then
16202 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
16204 Unit_In_Parent_Context
16205 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
16207 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
16213 end Unit_Is_Visible
;
16215 ------------------------------
16216 -- Universal_Interpretation --
16217 ------------------------------
16219 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
16220 Index
: Interp_Index
;
16224 -- The argument may be a formal parameter of an operator or subprogram
16225 -- with multiple interpretations, or else an expression for an actual.
16227 if Nkind
(Opnd
) = N_Defining_Identifier
16228 or else not Is_Overloaded
(Opnd
)
16230 if Etype
(Opnd
) = Universal_Integer
16231 or else Etype
(Opnd
) = Universal_Real
16233 return Etype
(Opnd
);
16239 Get_First_Interp
(Opnd
, Index
, It
);
16240 while Present
(It
.Typ
) loop
16241 if It
.Typ
= Universal_Integer
16242 or else It
.Typ
= Universal_Real
16247 Get_Next_Interp
(Index
, It
);
16252 end Universal_Interpretation
;
16258 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
16260 -- Recurse to handle unlikely case of multiple levels of qualification
16262 if Nkind
(Expr
) = N_Qualified_Expression
then
16263 return Unqualify
(Expression
(Expr
));
16265 -- Normal case, not a qualified expression
16272 -----------------------
16273 -- Visible_Ancestors --
16274 -----------------------
16276 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
16282 pragma Assert
(Is_Record_Type
(Typ
)
16283 and then Is_Tagged_Type
(Typ
));
16285 -- Collect all the parents and progenitors of Typ. If the full-view of
16286 -- private parents and progenitors is available then it is used to
16287 -- generate the list of visible ancestors; otherwise their partial
16288 -- view is added to the resulting list.
16293 Use_Full_View
=> True);
16297 Ifaces_List
=> List_2
,
16298 Exclude_Parents
=> True,
16299 Use_Full_View
=> True);
16301 -- Join the two lists. Avoid duplications because an interface may
16302 -- simultaneously be parent and progenitor of a type.
16304 Elmt
:= First_Elmt
(List_2
);
16305 while Present
(Elmt
) loop
16306 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
16311 end Visible_Ancestors
;
16313 ----------------------
16314 -- Within_Init_Proc --
16315 ----------------------
16317 function Within_Init_Proc
return Boolean is
16321 S
:= Current_Scope
;
16322 while not Is_Overloadable
(S
) loop
16323 if S
= Standard_Standard
then
16330 return Is_Init_Proc
(S
);
16331 end Within_Init_Proc
;
16337 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
16344 elsif SE
= Standard_Standard
then
16356 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
16357 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
16358 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
16360 Matching_Field
: Entity_Id
;
16361 -- Entity to give a more precise suggestion on how to write a one-
16362 -- element positional aggregate.
16364 function Has_One_Matching_Field
return Boolean;
16365 -- Determines if Expec_Type is a record type with a single component or
16366 -- discriminant whose type matches the found type or is one dimensional
16367 -- array whose component type matches the found type. In the case of
16368 -- one discriminant, we ignore the variant parts. That's not accurate,
16369 -- but good enough for the warning.
16371 ----------------------------
16372 -- Has_One_Matching_Field --
16373 ----------------------------
16375 function Has_One_Matching_Field
return Boolean is
16379 Matching_Field
:= Empty
;
16381 if Is_Array_Type
(Expec_Type
)
16382 and then Number_Dimensions
(Expec_Type
) = 1
16384 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
16386 -- Use type name if available. This excludes multidimensional
16387 -- arrays and anonymous arrays.
16389 if Comes_From_Source
(Expec_Type
) then
16390 Matching_Field
:= Expec_Type
;
16392 -- For an assignment, use name of target
16394 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
16395 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
16397 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
16402 elsif not Is_Record_Type
(Expec_Type
) then
16406 E
:= First_Entity
(Expec_Type
);
16411 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
16412 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
16421 if not Covers
(Etype
(E
), Found_Type
) then
16424 elsif Present
(Next_Entity
(E
))
16425 and then (Ekind
(E
) = E_Component
16426 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
16431 Matching_Field
:= E
;
16435 end Has_One_Matching_Field
;
16437 -- Start of processing for Wrong_Type
16440 -- Don't output message if either type is Any_Type, or if a message
16441 -- has already been posted for this node. We need to do the latter
16442 -- check explicitly (it is ordinarily done in Errout), because we
16443 -- are using ! to force the output of the error messages.
16445 if Expec_Type
= Any_Type
16446 or else Found_Type
= Any_Type
16447 or else Error_Posted
(Expr
)
16451 -- If one of the types is a Taft-Amendment type and the other it its
16452 -- completion, it must be an illegal use of a TAT in the spec, for
16453 -- which an error was already emitted. Avoid cascaded errors.
16455 elsif Is_Incomplete_Type
(Expec_Type
)
16456 and then Has_Completion_In_Body
(Expec_Type
)
16457 and then Full_View
(Expec_Type
) = Etype
(Expr
)
16461 elsif Is_Incomplete_Type
(Etype
(Expr
))
16462 and then Has_Completion_In_Body
(Etype
(Expr
))
16463 and then Full_View
(Etype
(Expr
)) = Expec_Type
16467 -- In an instance, there is an ongoing problem with completion of
16468 -- type derived from private types. Their structure is what Gigi
16469 -- expects, but the Etype is the parent type rather than the
16470 -- derived private type itself. Do not flag error in this case. The
16471 -- private completion is an entity without a parent, like an Itype.
16472 -- Similarly, full and partial views may be incorrect in the instance.
16473 -- There is no simple way to insure that it is consistent ???
16475 elsif In_Instance
then
16476 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
16478 (Has_Private_Declaration
(Expected_Type
)
16479 or else Has_Private_Declaration
(Etype
(Expr
)))
16480 and then No
(Parent
(Expected_Type
))
16486 -- An interesting special check. If the expression is parenthesized
16487 -- and its type corresponds to the type of the sole component of the
16488 -- expected record type, or to the component type of the expected one
16489 -- dimensional array type, then assume we have a bad aggregate attempt.
16491 if Nkind
(Expr
) in N_Subexpr
16492 and then Paren_Count
(Expr
) /= 0
16493 and then Has_One_Matching_Field
16495 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
16496 if Present
(Matching_Field
) then
16497 if Is_Array_Type
(Expec_Type
) then
16499 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
16503 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
16507 -- Another special check, if we are looking for a pool-specific access
16508 -- type and we found an E_Access_Attribute_Type, then we have the case
16509 -- of an Access attribute being used in a context which needs a pool-
16510 -- specific type, which is never allowed. The one extra check we make
16511 -- is that the expected designated type covers the Found_Type.
16513 elsif Is_Access_Type
(Expec_Type
)
16514 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
16515 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
16516 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
16518 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
16520 Error_Msg_N
-- CODEFIX
16521 ("result must be general access type!", Expr
);
16522 Error_Msg_NE
-- CODEFIX
16523 ("add ALL to }!", Expr
, Expec_Type
);
16525 -- Another special check, if the expected type is an integer type,
16526 -- but the expression is of type System.Address, and the parent is
16527 -- an addition or subtraction operation whose left operand is the
16528 -- expression in question and whose right operand is of an integral
16529 -- type, then this is an attempt at address arithmetic, so give
16530 -- appropriate message.
16532 elsif Is_Integer_Type
(Expec_Type
)
16533 and then Is_RTE
(Found_Type
, RE_Address
)
16534 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
16536 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
16537 and then Expr
= Left_Opnd
(Parent
(Expr
))
16538 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
16541 ("address arithmetic not predefined in package System",
16544 ("\possible missing with/use of System.Storage_Elements",
16548 -- If the expected type is an anonymous access type, as for access
16549 -- parameters and discriminants, the error is on the designated types.
16551 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
16552 if Comes_From_Source
(Expec_Type
) then
16553 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
16556 ("expected an access type with designated}",
16557 Expr
, Designated_Type
(Expec_Type
));
16560 if Is_Access_Type
(Found_Type
)
16561 and then not Comes_From_Source
(Found_Type
)
16564 ("\\found an access type with designated}!",
16565 Expr
, Designated_Type
(Found_Type
));
16567 if From_Limited_With
(Found_Type
) then
16568 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
16569 Error_Msg_Qual_Level
:= 99;
16570 Error_Msg_NE
-- CODEFIX
16571 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
16572 Error_Msg_Qual_Level
:= 0;
16574 Error_Msg_NE
("found}!", Expr
, Found_Type
);
16578 -- Normal case of one type found, some other type expected
16581 -- If the names of the two types are the same, see if some number
16582 -- of levels of qualification will help. Don't try more than three
16583 -- levels, and if we get to standard, it's no use (and probably
16584 -- represents an error in the compiler) Also do not bother with
16585 -- internal scope names.
16588 Expec_Scope
: Entity_Id
;
16589 Found_Scope
: Entity_Id
;
16592 Expec_Scope
:= Expec_Type
;
16593 Found_Scope
:= Found_Type
;
16595 for Levels
in Int
range 0 .. 3 loop
16596 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
16597 Error_Msg_Qual_Level
:= Levels
;
16601 Expec_Scope
:= Scope
(Expec_Scope
);
16602 Found_Scope
:= Scope
(Found_Scope
);
16604 exit when Expec_Scope
= Standard_Standard
16605 or else Found_Scope
= Standard_Standard
16606 or else not Comes_From_Source
(Expec_Scope
)
16607 or else not Comes_From_Source
(Found_Scope
);
16611 if Is_Record_Type
(Expec_Type
)
16612 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
16614 Error_Msg_NE
("expected}!", Expr
,
16615 Corresponding_Remote_Type
(Expec_Type
));
16617 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
16620 if Is_Entity_Name
(Expr
)
16621 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
16623 Error_Msg_N
("\\found package name!", Expr
);
16625 elsif Is_Entity_Name
(Expr
)
16627 (Ekind
(Entity
(Expr
)) = E_Procedure
16629 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
16631 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
16633 ("found procedure name, possibly missing Access attribute!",
16637 ("\\found procedure name instead of function!", Expr
);
16640 elsif Nkind
(Expr
) = N_Function_Call
16641 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
16642 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
16643 and then No
(Parameter_Associations
(Expr
))
16646 ("found function name, possibly missing Access attribute!",
16649 -- Catch common error: a prefix or infix operator which is not
16650 -- directly visible because the type isn't.
16652 elsif Nkind
(Expr
) in N_Op
16653 and then Is_Overloaded
(Expr
)
16654 and then not Is_Immediately_Visible
(Expec_Type
)
16655 and then not Is_Potentially_Use_Visible
(Expec_Type
)
16656 and then not In_Use
(Expec_Type
)
16657 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
16660 ("operator of the type is not directly visible!", Expr
);
16662 elsif Ekind
(Found_Type
) = E_Void
16663 and then Present
(Parent
(Found_Type
))
16664 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
16666 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
16669 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
16672 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
16673 -- of the same modular type, and (M1 and M2) = 0 was intended.
16675 if Expec_Type
= Standard_Boolean
16676 and then Is_Modular_Integer_Type
(Found_Type
)
16677 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
16678 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
16681 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
16682 L
: constant Node_Id
:= Left_Opnd
(Op
);
16683 R
: constant Node_Id
:= Right_Opnd
(Op
);
16685 -- The case for the message is when the left operand of the
16686 -- comparison is the same modular type, or when it is an
16687 -- integer literal (or other universal integer expression),
16688 -- which would have been typed as the modular type if the
16689 -- parens had been there.
16691 if (Etype
(L
) = Found_Type
16693 Etype
(L
) = Universal_Integer
)
16694 and then Is_Integer_Type
(Etype
(R
))
16697 ("\\possible missing parens for modular operation", Expr
);
16702 -- Reset error message qualification indication
16704 Error_Msg_Qual_Level
:= 0;