1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Util
; use Exp_Util
;
36 with Fname
; use Fname
;
37 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
.Sp
; use Namet
.Sp
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
43 with Output
; use Output
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Attr
; use Sem_Attr
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Disp
; use Sem_Disp
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Prag
; use Sem_Prag
;
55 with Sem_Res
; use Sem_Res
;
56 with Sem_Type
; use Sem_Type
;
57 with Sinfo
; use Sinfo
;
58 with Sinput
; use Sinput
;
59 with Stand
; use Stand
;
61 with Stringt
; use Stringt
;
62 with Targparm
; use Targparm
;
63 with Tbuild
; use Tbuild
;
64 with Ttypes
; use Ttypes
;
65 with Uname
; use Uname
;
67 with GNAT
.HTable
; use GNAT
.HTable
;
69 package body Sem_Util
is
71 ----------------------------------------
72 -- Global_Variables for New_Copy_Tree --
73 ----------------------------------------
75 -- These global variables are used by New_Copy_Tree. See description
76 -- of the body of this subprogram for details. Global variables can be
77 -- safely used by New_Copy_Tree, since there is no case of a recursive
78 -- call from the processing inside New_Copy_Tree.
80 NCT_Hash_Threshold
: constant := 20;
81 -- If there are more than this number of pairs of entries in the
82 -- map, then Hash_Tables_Used will be set, and the hash tables will
83 -- be initialized and used for the searches.
85 NCT_Hash_Tables_Used
: Boolean := False;
86 -- Set to True if hash tables are in use
88 NCT_Table_Entries
: Nat
:= 0;
89 -- Count entries in table to see if threshold is reached
91 NCT_Hash_Table_Setup
: Boolean := False;
92 -- Set to True if hash table contains data. We set this True if we
93 -- setup the hash table with data, and leave it set permanently
94 -- from then on, this is a signal that second and subsequent users
95 -- of the hash table must clear the old entries before reuse.
97 subtype NCT_Header_Num
is Int
range 0 .. 511;
98 -- Defines range of headers in hash tables (512 headers)
100 -----------------------
101 -- Local Subprograms --
102 -----------------------
104 function Build_Component_Subtype
107 T
: Entity_Id
) return Node_Id
;
108 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
109 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
110 -- Loc is the source location, T is the original subtype.
112 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
113 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
114 -- with discriminants whose default values are static, examine only the
115 -- components in the selected variant to determine whether all of them
118 function Has_Enabled_Property
119 (Item_Id
: Entity_Id
;
120 Property
: Name_Id
) return Boolean;
121 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
122 -- Determine whether an abstract state or a variable denoted by entity
123 -- Item_Id has enabled property Property.
125 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
126 -- T is a derived tagged type. Check whether the type extension is null.
127 -- If the parent type is fully initialized, T can be treated as such.
129 ------------------------------
130 -- Abstract_Interface_List --
131 ------------------------------
133 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
137 if Is_Concurrent_Type
(Typ
) then
139 -- If we are dealing with a synchronized subtype, go to the base
140 -- type, whose declaration has the interface list.
142 -- Shouldn't this be Declaration_Node???
144 Nod
:= Parent
(Base_Type
(Typ
));
146 if Nkind
(Nod
) = N_Full_Type_Declaration
then
150 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
151 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
152 Nod
:= Type_Definition
(Parent
(Typ
));
154 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
155 if Present
(Full_View
(Typ
))
156 and then Nkind
(Parent
(Full_View
(Typ
)))
157 = N_Full_Type_Declaration
159 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
161 -- If the full-view is not available we cannot do anything else
162 -- here (the source has errors).
168 -- Support for generic formals with interfaces is still missing ???
170 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
175 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
179 elsif Ekind
(Typ
) = E_Record_Subtype
then
180 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
182 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
184 -- Recurse, because parent may still be a private extension. Also
185 -- note that the full view of the subtype or the full view of its
186 -- base type may (both) be unavailable.
188 return Abstract_Interface_List
(Etype
(Typ
));
190 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
191 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
192 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
194 Nod
:= Type_Definition
(Parent
(Typ
));
198 return Interface_List
(Nod
);
199 end Abstract_Interface_List
;
201 --------------------------------
202 -- Add_Access_Type_To_Process --
203 --------------------------------
205 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
209 Ensure_Freeze_Node
(E
);
210 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
214 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
218 end Add_Access_Type_To_Process
;
220 --------------------------
221 -- Add_Block_Identifier --
222 --------------------------
224 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
225 Loc
: constant Source_Ptr
:= Sloc
(N
);
228 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
230 -- The block already has a label, return its entity
232 if Present
(Identifier
(N
)) then
233 Id
:= Entity
(Identifier
(N
));
235 -- Create a new block label and set its attributes
238 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
239 Set_Etype
(Id
, Standard_Void_Type
);
242 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
243 Set_Block_Node
(Id
, Identifier
(N
));
245 end Add_Block_Identifier
;
247 -----------------------
248 -- Add_Contract_Item --
249 -----------------------
251 procedure Add_Contract_Item
(Prag
: Node_Id
; Id
: Entity_Id
) is
252 Items
: constant Node_Id
:= Contract
(Id
);
257 -- The related context must have a contract and the item to be added
260 pragma Assert
(Present
(Items
));
261 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
263 Nam
:= Original_Aspect_Name
(Prag
);
265 -- Contract items related to [generic] packages or instantiations. The
266 -- applicable pragmas are:
270 -- Part_Of (instantiation only)
272 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
273 if Nam_In
(Nam
, Name_Abstract_State
,
274 Name_Initial_Condition
,
277 Set_Next_Pragma
(Prag
, Classifications
(Items
));
278 Set_Classifications
(Items
, Prag
);
280 -- Indicator Part_Of must be associated with a package instantiation
282 elsif Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) then
283 Set_Next_Pragma
(Prag
, Classifications
(Items
));
284 Set_Classifications
(Items
, Prag
);
286 -- The pragma is not a proper contract item
292 -- Contract items related to package bodies. The applicable pragmas are:
295 elsif Ekind
(Id
) = E_Package_Body
then
296 if Nam
= Name_Refined_State
then
297 Set_Next_Pragma
(Prag
, Classifications
(Items
));
298 Set_Classifications
(Items
, Prag
);
300 -- The pragma is not a proper contract item
306 -- Contract items related to subprogram or entry declarations. The
307 -- applicable pragmas are:
317 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
318 or else Is_Generic_Subprogram
(Id
)
319 or else Is_Subprogram
(Id
)
321 if Nam_In
(Nam
, Name_Precondition
,
328 -- Before we add a precondition or postcondition to the list,
329 -- make sure we do not have a disallowed duplicate, which can
330 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
331 -- instead of the corresponding aspect.
333 if not From_Aspect_Specification
(Prag
)
334 and then Nam_In
(Nam
, Name_Pre_Class
,
341 N
:= Pre_Post_Conditions
(Items
);
342 while Present
(N
) loop
344 and then Original_Aspect_Name
(N
) = Nam
346 Error_Msg_Sloc
:= Sloc
(N
);
348 ("duplication of aspect for & given#", Prag
, Id
);
351 N
:= Next_Pragma
(N
);
356 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
357 Set_Pre_Post_Conditions
(Items
, Prag
);
359 elsif Nam_In
(Nam
, Name_Contract_Cases
, Name_Test_Case
) then
360 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
361 Set_Contract_Test_Cases
(Items
, Prag
);
363 elsif Nam_In
(Nam
, Name_Depends
, Name_Global
) then
364 Set_Next_Pragma
(Prag
, Classifications
(Items
));
365 Set_Classifications
(Items
, Prag
);
367 -- The pragma is not a proper contract item
373 -- Contract items related to subprogram bodies. The applicable pragmas
379 elsif Ekind
(Id
) = E_Subprogram_Body
then
380 if Nam
= Name_Refined_Post
then
381 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
382 Set_Pre_Post_Conditions
(Items
, Prag
);
384 elsif Nam_In
(Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
385 Set_Next_Pragma
(Prag
, Classifications
(Items
));
386 Set_Classifications
(Items
, Prag
);
388 -- The pragma is not a proper contract item
394 -- Contract items related to variables. The applicable pragmas are:
401 elsif Ekind
(Id
) = E_Variable
then
402 if Nam_In
(Nam
, Name_Async_Readers
,
404 Name_Effective_Reads
,
405 Name_Effective_Writes
,
408 Set_Next_Pragma
(Prag
, Classifications
(Items
));
409 Set_Classifications
(Items
, Prag
);
411 -- The pragma is not a proper contract item
417 end Add_Contract_Item
;
419 ----------------------------
420 -- Add_Global_Declaration --
421 ----------------------------
423 procedure Add_Global_Declaration
(N
: Node_Id
) is
424 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
427 if No
(Declarations
(Aux_Node
)) then
428 Set_Declarations
(Aux_Node
, New_List
);
431 Append_To
(Declarations
(Aux_Node
), N
);
433 end Add_Global_Declaration
;
435 --------------------------------
436 -- Address_Integer_Convert_OK --
437 --------------------------------
439 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
441 if Allow_Integer_Address
442 and then ((Is_Descendent_Of_Address
(T1
)
443 and then Is_Private_Type
(T1
)
444 and then Is_Integer_Type
(T2
))
446 (Is_Descendent_Of_Address
(T2
)
447 and then Is_Private_Type
(T2
)
448 and then Is_Integer_Type
(T1
)))
454 end Address_Integer_Convert_OK
;
460 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
462 function Addressable
(V
: Uint
) return Boolean is
464 return V
= Uint_8
or else
470 function Addressable
(V
: Int
) return Boolean is
478 -----------------------
479 -- Alignment_In_Bits --
480 -----------------------
482 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
484 return Alignment
(E
) * System_Storage_Unit
;
485 end Alignment_In_Bits
;
487 ---------------------------------
488 -- Append_Inherited_Subprogram --
489 ---------------------------------
491 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
492 Par
: constant Entity_Id
:= Alias
(S
);
493 -- The parent subprogram
495 Scop
: constant Entity_Id
:= Scope
(Par
);
496 -- The scope of definition of the parent subprogram
498 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
499 -- The derived type of which S is a primitive operation
505 if Ekind
(Current_Scope
) = E_Package
506 and then In_Private_Part
(Current_Scope
)
507 and then Has_Private_Declaration
(Typ
)
508 and then Is_Tagged_Type
(Typ
)
509 and then Scop
= Current_Scope
511 -- The inherited operation is available at the earliest place after
512 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
513 -- relevant for type extensions. If the parent operation appears
514 -- after the type extension, the operation is not visible.
517 (Visible_Declarations
518 (Package_Specification
(Current_Scope
)));
519 while Present
(Decl
) loop
520 if Nkind
(Decl
) = N_Private_Extension_Declaration
521 and then Defining_Entity
(Decl
) = Typ
523 if Sloc
(Decl
) > Sloc
(Par
) then
524 Next_E
:= Next_Entity
(Par
);
525 Set_Next_Entity
(Par
, S
);
526 Set_Next_Entity
(S
, Next_E
);
538 -- If partial view is not a type extension, or it appears before the
539 -- subprogram declaration, insert normally at end of entity list.
541 Append_Entity
(S
, Current_Scope
);
542 end Append_Inherited_Subprogram
;
544 -----------------------------------------
545 -- Apply_Compile_Time_Constraint_Error --
546 -----------------------------------------
548 procedure Apply_Compile_Time_Constraint_Error
551 Reason
: RT_Exception_Code
;
552 Ent
: Entity_Id
:= Empty
;
553 Typ
: Entity_Id
:= Empty
;
554 Loc
: Source_Ptr
:= No_Location
;
555 Rep
: Boolean := True;
556 Warn
: Boolean := False)
558 Stat
: constant Boolean := Is_Static_Expression
(N
);
559 R_Stat
: constant Node_Id
:=
560 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
571 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
577 -- Now we replace the node by an N_Raise_Constraint_Error node
578 -- This does not need reanalyzing, so set it as analyzed now.
581 Set_Analyzed
(N
, True);
584 Set_Raises_Constraint_Error
(N
);
586 -- Now deal with possible local raise handling
588 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
590 -- If the original expression was marked as static, the result is
591 -- still marked as static, but the Raises_Constraint_Error flag is
592 -- always set so that further static evaluation is not attempted.
595 Set_Is_Static_Expression
(N
);
597 end Apply_Compile_Time_Constraint_Error
;
599 ---------------------------
600 -- Async_Readers_Enabled --
601 ---------------------------
603 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
605 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
606 end Async_Readers_Enabled
;
608 ---------------------------
609 -- Async_Writers_Enabled --
610 ---------------------------
612 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
614 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
615 end Async_Writers_Enabled
;
617 --------------------------------------
618 -- Available_Full_View_Of_Component --
619 --------------------------------------
621 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
622 ST
: constant Entity_Id
:= Scope
(T
);
623 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
625 return In_Open_Scopes
(ST
)
626 and then In_Open_Scopes
(SCT
)
627 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
628 end Available_Full_View_Of_Component
;
634 procedure Bad_Attribute
637 Warn
: Boolean := False)
640 Error_Msg_Warn
:= Warn
;
641 Error_Msg_N
("unrecognized attribute&<", N
);
643 -- Check for possible misspelling
645 Error_Msg_Name_1
:= First_Attribute_Name
;
646 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
647 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
648 Error_Msg_N
-- CODEFIX
649 ("\possible misspelling of %<", N
);
653 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
657 --------------------------------
658 -- Bad_Predicated_Subtype_Use --
659 --------------------------------
661 procedure Bad_Predicated_Subtype_Use
665 Suggest_Static
: Boolean := False)
668 if Has_Predicates
(Typ
) then
669 if Is_Generic_Actual_Type
(Typ
) then
670 Error_Msg_Warn
:= SPARK_Mode
/= On
;
671 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
672 Error_Msg_F
("\Program_Error [<<", N
);
674 Make_Raise_Program_Error
(Sloc
(N
),
675 Reason
=> PE_Bad_Predicated_Generic_Type
));
678 Error_Msg_FE
(Msg
, N
, Typ
);
681 -- Emit an optional suggestion on how to remedy the error if the
682 -- context warrants it.
684 if Suggest_Static
and then Present
(Static_Predicate
(Typ
)) then
685 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
688 end Bad_Predicated_Subtype_Use
;
690 ----------------------------------------
691 -- Bad_Unordered_Enumeration_Reference --
692 ----------------------------------------
694 function Bad_Unordered_Enumeration_Reference
696 T
: Entity_Id
) return Boolean
699 return Is_Enumeration_Type
(T
)
700 and then Comes_From_Source
(N
)
701 and then Warn_On_Unordered_Enumeration_Type
702 and then not Has_Pragma_Ordered
(T
)
703 and then not In_Same_Extended_Unit
(N
, T
);
704 end Bad_Unordered_Enumeration_Reference
;
706 --------------------------
707 -- Build_Actual_Subtype --
708 --------------------------
710 function Build_Actual_Subtype
712 N
: Node_Or_Entity_Id
) return Node_Id
715 -- Normally Sloc (N), but may point to corresponding body in some cases
717 Constraints
: List_Id
;
723 Disc_Type
: Entity_Id
;
729 if Nkind
(N
) = N_Defining_Identifier
then
730 Obj
:= New_Occurrence_Of
(N
, Loc
);
732 -- If this is a formal parameter of a subprogram declaration, and
733 -- we are compiling the body, we want the declaration for the
734 -- actual subtype to carry the source position of the body, to
735 -- prevent anomalies in gdb when stepping through the code.
737 if Is_Formal
(N
) then
739 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
741 if Nkind
(Decl
) = N_Subprogram_Declaration
742 and then Present
(Corresponding_Body
(Decl
))
744 Loc
:= Sloc
(Corresponding_Body
(Decl
));
753 if Is_Array_Type
(T
) then
754 Constraints
:= New_List
;
755 for J
in 1 .. Number_Dimensions
(T
) loop
757 -- Build an array subtype declaration with the nominal subtype and
758 -- the bounds of the actual. Add the declaration in front of the
759 -- local declarations for the subprogram, for analysis before any
760 -- reference to the formal in the body.
763 Make_Attribute_Reference
(Loc
,
765 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
766 Attribute_Name
=> Name_First
,
767 Expressions
=> New_List
(
768 Make_Integer_Literal
(Loc
, J
)));
771 Make_Attribute_Reference
(Loc
,
773 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
774 Attribute_Name
=> Name_Last
,
775 Expressions
=> New_List
(
776 Make_Integer_Literal
(Loc
, J
)));
778 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
781 -- If the type has unknown discriminants there is no constrained
782 -- subtype to build. This is never called for a formal or for a
783 -- lhs, so returning the type is ok ???
785 elsif Has_Unknown_Discriminants
(T
) then
789 Constraints
:= New_List
;
791 -- Type T is a generic derived type, inherit the discriminants from
794 if Is_Private_Type
(T
)
795 and then No
(Full_View
(T
))
797 -- T was flagged as an error if it was declared as a formal
798 -- derived type with known discriminants. In this case there
799 -- is no need to look at the parent type since T already carries
800 -- its own discriminants.
802 and then not Error_Posted
(T
)
804 Disc_Type
:= Etype
(Base_Type
(T
));
809 Discr
:= First_Discriminant
(Disc_Type
);
810 while Present
(Discr
) loop
811 Append_To
(Constraints
,
812 Make_Selected_Component
(Loc
,
814 Duplicate_Subexpr_No_Checks
(Obj
),
815 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
816 Next_Discriminant
(Discr
);
820 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
821 Set_Is_Internal
(Subt
);
824 Make_Subtype_Declaration
(Loc
,
825 Defining_Identifier
=> Subt
,
826 Subtype_Indication
=>
827 Make_Subtype_Indication
(Loc
,
828 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
830 Make_Index_Or_Discriminant_Constraint
(Loc
,
831 Constraints
=> Constraints
)));
833 Mark_Rewrite_Insertion
(Decl
);
835 end Build_Actual_Subtype
;
837 ---------------------------------------
838 -- Build_Actual_Subtype_Of_Component --
839 ---------------------------------------
841 function Build_Actual_Subtype_Of_Component
843 N
: Node_Id
) return Node_Id
845 Loc
: constant Source_Ptr
:= Sloc
(N
);
846 P
: constant Node_Id
:= Prefix
(N
);
849 Index_Typ
: Entity_Id
;
851 Desig_Typ
: Entity_Id
;
852 -- This is either a copy of T, or if T is an access type, then it is
853 -- the directly designated type of this access type.
855 function Build_Actual_Array_Constraint
return List_Id
;
856 -- If one or more of the bounds of the component depends on
857 -- discriminants, build actual constraint using the discriminants
860 function Build_Actual_Record_Constraint
return List_Id
;
861 -- Similar to previous one, for discriminated components constrained
862 -- by the discriminant of the enclosing object.
864 -----------------------------------
865 -- Build_Actual_Array_Constraint --
866 -----------------------------------
868 function Build_Actual_Array_Constraint
return List_Id
is
869 Constraints
: constant List_Id
:= New_List
;
877 Indx
:= First_Index
(Desig_Typ
);
878 while Present
(Indx
) loop
879 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
880 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
882 if Denotes_Discriminant
(Old_Lo
) then
884 Make_Selected_Component
(Loc
,
885 Prefix
=> New_Copy_Tree
(P
),
886 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
889 Lo
:= New_Copy_Tree
(Old_Lo
);
891 -- The new bound will be reanalyzed in the enclosing
892 -- declaration. For literal bounds that come from a type
893 -- declaration, the type of the context must be imposed, so
894 -- insure that analysis will take place. For non-universal
895 -- types this is not strictly necessary.
897 Set_Analyzed
(Lo
, False);
900 if Denotes_Discriminant
(Old_Hi
) then
902 Make_Selected_Component
(Loc
,
903 Prefix
=> New_Copy_Tree
(P
),
904 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
907 Hi
:= New_Copy_Tree
(Old_Hi
);
908 Set_Analyzed
(Hi
, False);
911 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
916 end Build_Actual_Array_Constraint
;
918 ------------------------------------
919 -- Build_Actual_Record_Constraint --
920 ------------------------------------
922 function Build_Actual_Record_Constraint
return List_Id
is
923 Constraints
: constant List_Id
:= New_List
;
928 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
929 while Present
(D
) loop
930 if Denotes_Discriminant
(Node
(D
)) then
931 D_Val
:= Make_Selected_Component
(Loc
,
932 Prefix
=> New_Copy_Tree
(P
),
933 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
936 D_Val
:= New_Copy_Tree
(Node
(D
));
939 Append
(D_Val
, Constraints
);
944 end Build_Actual_Record_Constraint
;
946 -- Start of processing for Build_Actual_Subtype_Of_Component
949 -- Why the test for Spec_Expression mode here???
951 if In_Spec_Expression
then
954 -- More comments for the rest of this body would be good ???
956 elsif Nkind
(N
) = N_Explicit_Dereference
then
957 if Is_Composite_Type
(T
)
958 and then not Is_Constrained
(T
)
959 and then not (Is_Class_Wide_Type
(T
)
960 and then Is_Constrained
(Root_Type
(T
)))
961 and then not Has_Unknown_Discriminants
(T
)
963 -- If the type of the dereference is already constrained, it is an
966 if Is_Array_Type
(Etype
(N
))
967 and then Is_Constrained
(Etype
(N
))
971 Remove_Side_Effects
(P
);
972 return Build_Actual_Subtype
(T
, N
);
979 if Ekind
(T
) = E_Access_Subtype
then
980 Desig_Typ
:= Designated_Type
(T
);
985 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
986 Id
:= First_Index
(Desig_Typ
);
987 while Present
(Id
) loop
988 Index_Typ
:= Underlying_Type
(Etype
(Id
));
990 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
992 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
994 Remove_Side_Effects
(P
);
996 Build_Component_Subtype
997 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1003 elsif Is_Composite_Type
(Desig_Typ
)
1004 and then Has_Discriminants
(Desig_Typ
)
1005 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1007 if Is_Private_Type
(Desig_Typ
)
1008 and then No
(Discriminant_Constraint
(Desig_Typ
))
1010 Desig_Typ
:= Full_View
(Desig_Typ
);
1013 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1014 while Present
(D
) loop
1015 if Denotes_Discriminant
(Node
(D
)) then
1016 Remove_Side_Effects
(P
);
1018 Build_Component_Subtype
(
1019 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1026 -- If none of the above, the actual and nominal subtypes are the same
1029 end Build_Actual_Subtype_Of_Component
;
1031 -----------------------------
1032 -- Build_Component_Subtype --
1033 -----------------------------
1035 function Build_Component_Subtype
1038 T
: Entity_Id
) return Node_Id
1044 -- Unchecked_Union components do not require component subtypes
1046 if Is_Unchecked_Union
(T
) then
1050 Subt
:= Make_Temporary
(Loc
, 'S');
1051 Set_Is_Internal
(Subt
);
1054 Make_Subtype_Declaration
(Loc
,
1055 Defining_Identifier
=> Subt
,
1056 Subtype_Indication
=>
1057 Make_Subtype_Indication
(Loc
,
1058 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1060 Make_Index_Or_Discriminant_Constraint
(Loc
,
1061 Constraints
=> C
)));
1063 Mark_Rewrite_Insertion
(Decl
);
1065 end Build_Component_Subtype
;
1067 ---------------------------
1068 -- Build_Default_Subtype --
1069 ---------------------------
1071 function Build_Default_Subtype
1073 N
: Node_Id
) return Entity_Id
1075 Loc
: constant Source_Ptr
:= Sloc
(N
);
1079 -- The base type that is to be constrained by the defaults
1082 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1086 Bas
:= Base_Type
(T
);
1088 -- If T is non-private but its base type is private, this is the
1089 -- completion of a subtype declaration whose parent type is private
1090 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1091 -- are to be found in the full view of the base.
1093 if Is_Private_Type
(Bas
) and then Present
(Full_View
(Bas
)) then
1094 Bas
:= Full_View
(Bas
);
1097 Disc
:= First_Discriminant
(T
);
1099 if No
(Discriminant_Default_Value
(Disc
)) then
1104 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1105 Constraints
: constant List_Id
:= New_List
;
1109 while Present
(Disc
) loop
1110 Append_To
(Constraints
,
1111 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1112 Next_Discriminant
(Disc
);
1116 Make_Subtype_Declaration
(Loc
,
1117 Defining_Identifier
=> Act
,
1118 Subtype_Indication
=>
1119 Make_Subtype_Indication
(Loc
,
1120 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1122 Make_Index_Or_Discriminant_Constraint
(Loc
,
1123 Constraints
=> Constraints
)));
1125 Insert_Action
(N
, Decl
);
1129 end Build_Default_Subtype
;
1131 --------------------------------------------
1132 -- Build_Discriminal_Subtype_Of_Component --
1133 --------------------------------------------
1135 function Build_Discriminal_Subtype_Of_Component
1136 (T
: Entity_Id
) return Node_Id
1138 Loc
: constant Source_Ptr
:= Sloc
(T
);
1142 function Build_Discriminal_Array_Constraint
return List_Id
;
1143 -- If one or more of the bounds of the component depends on
1144 -- discriminants, build actual constraint using the discriminants
1147 function Build_Discriminal_Record_Constraint
return List_Id
;
1148 -- Similar to previous one, for discriminated components constrained by
1149 -- the discriminant of the enclosing object.
1151 ----------------------------------------
1152 -- Build_Discriminal_Array_Constraint --
1153 ----------------------------------------
1155 function Build_Discriminal_Array_Constraint
return List_Id
is
1156 Constraints
: constant List_Id
:= New_List
;
1164 Indx
:= First_Index
(T
);
1165 while Present
(Indx
) loop
1166 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1167 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1169 if Denotes_Discriminant
(Old_Lo
) then
1170 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1173 Lo
:= New_Copy_Tree
(Old_Lo
);
1176 if Denotes_Discriminant
(Old_Hi
) then
1177 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1180 Hi
:= New_Copy_Tree
(Old_Hi
);
1183 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1188 end Build_Discriminal_Array_Constraint
;
1190 -----------------------------------------
1191 -- Build_Discriminal_Record_Constraint --
1192 -----------------------------------------
1194 function Build_Discriminal_Record_Constraint
return List_Id
is
1195 Constraints
: constant List_Id
:= New_List
;
1200 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1201 while Present
(D
) loop
1202 if Denotes_Discriminant
(Node
(D
)) then
1204 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1207 D_Val
:= New_Copy_Tree
(Node
(D
));
1210 Append
(D_Val
, Constraints
);
1215 end Build_Discriminal_Record_Constraint
;
1217 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1220 if Ekind
(T
) = E_Array_Subtype
then
1221 Id
:= First_Index
(T
);
1222 while Present
(Id
) loop
1223 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
1224 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1226 return Build_Component_Subtype
1227 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1233 elsif Ekind
(T
) = E_Record_Subtype
1234 and then Has_Discriminants
(T
)
1235 and then not Has_Unknown_Discriminants
(T
)
1237 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1238 while Present
(D
) loop
1239 if Denotes_Discriminant
(Node
(D
)) then
1240 return Build_Component_Subtype
1241 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1248 -- If none of the above, the actual and nominal subtypes are the same
1251 end Build_Discriminal_Subtype_Of_Component
;
1253 ------------------------------
1254 -- Build_Elaboration_Entity --
1255 ------------------------------
1257 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1258 Loc
: constant Source_Ptr
:= Sloc
(N
);
1260 Elab_Ent
: Entity_Id
;
1262 procedure Set_Package_Name
(Ent
: Entity_Id
);
1263 -- Given an entity, sets the fully qualified name of the entity in
1264 -- Name_Buffer, with components separated by double underscores. This
1265 -- is a recursive routine that climbs the scope chain to Standard.
1267 ----------------------
1268 -- Set_Package_Name --
1269 ----------------------
1271 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1273 if Scope
(Ent
) /= Standard_Standard
then
1274 Set_Package_Name
(Scope
(Ent
));
1277 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1279 Name_Buffer
(Name_Len
+ 1) := '_';
1280 Name_Buffer
(Name_Len
+ 2) := '_';
1281 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1282 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1286 Get_Name_String
(Chars
(Ent
));
1288 end Set_Package_Name
;
1290 -- Start of processing for Build_Elaboration_Entity
1293 -- Ignore if already constructed
1295 if Present
(Elaboration_Entity
(Spec_Id
)) then
1299 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1300 -- no role in analysis.
1306 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1307 -- name with dots replaced by double underscore. We have to manually
1308 -- construct this name, since it will be elaborated in the outer scope,
1309 -- and thus will not have the unit name automatically prepended.
1311 Set_Package_Name
(Spec_Id
);
1312 Add_Str_To_Name_Buffer
("_E");
1314 -- Create elaboration counter
1316 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1317 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1320 Make_Object_Declaration
(Loc
,
1321 Defining_Identifier
=> Elab_Ent
,
1322 Object_Definition
=>
1323 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1324 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1326 Push_Scope
(Standard_Standard
);
1327 Add_Global_Declaration
(Decl
);
1330 -- Reset True_Constant indication, since we will indeed assign a value
1331 -- to the variable in the binder main. We also kill the Current_Value
1332 -- and Last_Assignment fields for the same reason.
1334 Set_Is_True_Constant
(Elab_Ent
, False);
1335 Set_Current_Value
(Elab_Ent
, Empty
);
1336 Set_Last_Assignment
(Elab_Ent
, Empty
);
1338 -- We do not want any further qualification of the name (if we did not
1339 -- do this, we would pick up the name of the generic package in the case
1340 -- of a library level generic instantiation).
1342 Set_Has_Qualified_Name
(Elab_Ent
);
1343 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1344 end Build_Elaboration_Entity
;
1346 --------------------------------
1347 -- Build_Explicit_Dereference --
1348 --------------------------------
1350 procedure Build_Explicit_Dereference
1354 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1357 -- An entity of a type with a reference aspect is overloaded with
1358 -- both interpretations: with and without the dereference. Now that
1359 -- the dereference is made explicit, set the type of the node properly,
1360 -- to prevent anomalies in the backend. Same if the expression is an
1361 -- overloaded function call whose return type has a reference aspect.
1363 if Is_Entity_Name
(Expr
) then
1364 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1366 elsif Nkind
(Expr
) = N_Function_Call
then
1367 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1370 Set_Is_Overloaded
(Expr
, False);
1372 Make_Explicit_Dereference
(Loc
,
1374 Make_Selected_Component
(Loc
,
1375 Prefix
=> Relocate_Node
(Expr
),
1376 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1377 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1378 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1379 end Build_Explicit_Dereference
;
1381 -----------------------------------
1382 -- Cannot_Raise_Constraint_Error --
1383 -----------------------------------
1385 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1387 if Compile_Time_Known_Value
(Expr
) then
1390 elsif Do_Range_Check
(Expr
) then
1393 elsif Raises_Constraint_Error
(Expr
) then
1397 case Nkind
(Expr
) is
1398 when N_Identifier
=>
1401 when N_Expanded_Name
=>
1404 when N_Selected_Component
=>
1405 return not Do_Discriminant_Check
(Expr
);
1407 when N_Attribute_Reference
=>
1408 if Do_Overflow_Check
(Expr
) then
1411 elsif No
(Expressions
(Expr
)) then
1419 N
:= First
(Expressions
(Expr
));
1420 while Present
(N
) loop
1421 if Cannot_Raise_Constraint_Error
(N
) then
1432 when N_Type_Conversion
=>
1433 if Do_Overflow_Check
(Expr
)
1434 or else Do_Length_Check
(Expr
)
1435 or else Do_Tag_Check
(Expr
)
1439 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1442 when N_Unchecked_Type_Conversion
=>
1443 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1446 if Do_Overflow_Check
(Expr
) then
1449 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1456 if Do_Division_Check
(Expr
)
1457 or else Do_Overflow_Check
(Expr
)
1462 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1464 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1483 N_Op_Shift_Right_Arithmetic |
1487 if Do_Overflow_Check
(Expr
) then
1491 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1493 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1500 end Cannot_Raise_Constraint_Error
;
1502 -----------------------------------------
1503 -- Check_Dynamically_Tagged_Expression --
1504 -----------------------------------------
1506 procedure Check_Dynamically_Tagged_Expression
1509 Related_Nod
: Node_Id
)
1512 pragma Assert
(Is_Tagged_Type
(Typ
));
1514 -- In order to avoid spurious errors when analyzing the expanded code,
1515 -- this check is done only for nodes that come from source and for
1516 -- actuals of generic instantiations.
1518 if (Comes_From_Source
(Related_Nod
)
1519 or else In_Generic_Actual
(Expr
))
1520 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1521 or else Is_Dynamically_Tagged
(Expr
))
1522 and then Is_Tagged_Type
(Typ
)
1523 and then not Is_Class_Wide_Type
(Typ
)
1525 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1527 end Check_Dynamically_Tagged_Expression
;
1529 -----------------------------------------------
1530 -- Check_Expression_Against_Static_Predicate --
1531 -----------------------------------------------
1533 procedure Check_Expression_Against_Static_Predicate
1538 -- When the predicate is static and the value of the expression is known
1539 -- at compile time, evaluate the predicate check. A type is non-static
1540 -- when it has aspect Dynamic_Predicate.
1542 if Compile_Time_Known_Value
(Expr
)
1543 and then Has_Predicates
(Typ
)
1544 and then Present
(Static_Predicate
(Typ
))
1545 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
1547 -- Either -gnatc is enabled or the expression is ok
1549 if Operating_Mode
< Generate_Code
1550 or else Eval_Static_Predicate_Check
(Expr
, Typ
)
1554 -- The expression is prohibited by the static predicate
1558 ("?static expression fails static predicate check on &",
1562 end Check_Expression_Against_Static_Predicate
;
1564 --------------------------
1565 -- Check_Fully_Declared --
1566 --------------------------
1568 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1570 if Ekind
(T
) = E_Incomplete_Type
then
1572 -- Ada 2005 (AI-50217): If the type is available through a limited
1573 -- with_clause, verify that its full view has been analyzed.
1575 if From_Limited_With
(T
)
1576 and then Present
(Non_Limited_View
(T
))
1577 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1579 -- The non-limited view is fully declared
1584 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1587 -- Need comments for these tests ???
1589 elsif Has_Private_Component
(T
)
1590 and then not Is_Generic_Type
(Root_Type
(T
))
1591 and then not In_Spec_Expression
1593 -- Special case: if T is the anonymous type created for a single
1594 -- task or protected object, use the name of the source object.
1596 if Is_Concurrent_Type
(T
)
1597 and then not Comes_From_Source
(T
)
1598 and then Nkind
(N
) = N_Object_Declaration
1600 Error_Msg_NE
("type of& has incomplete component", N
,
1601 Defining_Identifier
(N
));
1605 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1608 end Check_Fully_Declared
;
1610 -------------------------------------
1611 -- Check_Function_Writable_Actuals --
1612 -------------------------------------
1614 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
1615 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
1616 Identifiers_List
: Elist_Id
:= No_Elist
;
1617 Error_Node
: Node_Id
:= Empty
;
1619 procedure Collect_Identifiers
(N
: Node_Id
);
1620 -- In a single traversal of subtree N collect in Writable_Actuals_List
1621 -- all the actuals of functions with writable actuals, and in the list
1622 -- Identifiers_List collect all the identifiers that are not actuals of
1623 -- functions with writable actuals. If a writable actual is referenced
1624 -- twice as writable actual then Error_Node is set to reference its
1625 -- second occurrence, the error is reported, and the tree traversal
1628 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
1629 -- Return the entity associated with the function call
1631 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
1632 -- Preanalyze N without reporting errors. Very dubious, you can't just
1633 -- go analyzing things more than once???
1635 -------------------------
1636 -- Collect_Identifiers --
1637 -------------------------
1639 procedure Collect_Identifiers
(N
: Node_Id
) is
1641 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
1642 -- Process a single node during the tree traversal to collect the
1643 -- writable actuals of functions and all the identifiers which are
1644 -- not writable actuals of functions.
1646 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
1647 -- Returns True if List has a node whose Entity is Entity (N)
1649 -------------------------
1650 -- Check_Function_Call --
1651 -------------------------
1653 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
1654 Is_Writable_Actual
: Boolean := False;
1658 if Nkind
(N
) = N_Identifier
then
1660 -- No analysis possible if the entity is not decorated
1662 if No
(Entity
(N
)) then
1665 -- Don't collect identifiers of packages, called functions, etc
1667 elsif Ekind_In
(Entity
(N
), E_Package
,
1674 -- Analyze if N is a writable actual of a function
1676 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
1678 Call
: constant Node_Id
:= Parent
(N
);
1683 Id
:= Get_Function_Id
(Call
);
1685 Formal
:= First_Formal
(Id
);
1686 Actual
:= First_Actual
(Call
);
1687 while Present
(Actual
) and then Present
(Formal
) loop
1689 if Ekind_In
(Formal
, E_Out_Parameter
,
1692 Is_Writable_Actual
:= True;
1698 Next_Formal
(Formal
);
1699 Next_Actual
(Actual
);
1704 if Is_Writable_Actual
then
1705 if Contains
(Writable_Actuals_List
, N
) then
1707 ("value may be affected by call to& "
1708 & "because order of evaluation is arbitrary", N
, Id
);
1713 if Writable_Actuals_List
= No_Elist
then
1714 Writable_Actuals_List
:= New_Elmt_List
;
1717 Append_Elmt
(N
, Writable_Actuals_List
);
1719 if Identifiers_List
= No_Elist
then
1720 Identifiers_List
:= New_Elmt_List
;
1723 Append_Unique_Elmt
(N
, Identifiers_List
);
1736 N
: Node_Id
) return Boolean
1738 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
1743 if List
= No_Elist
then
1747 Elmt
:= First_Elmt
(List
);
1748 while Present
(Elmt
) loop
1749 if Entity
(Node
(Elmt
)) = Entity
(N
) then
1763 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
1764 -- The traversal procedure
1766 -- Start of processing for Collect_Identifiers
1769 if Present
(Error_Node
) then
1773 if Nkind
(N
) in N_Subexpr
1774 and then Is_Static_Expression
(N
)
1780 end Collect_Identifiers
;
1782 ---------------------
1783 -- Get_Function_Id --
1784 ---------------------
1786 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
1787 Nam
: constant Node_Id
:= Name
(Call
);
1791 if Nkind
(Nam
) = N_Explicit_Dereference
then
1793 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
1795 elsif Nkind
(Nam
) = N_Selected_Component
then
1796 Id
:= Entity
(Selector_Name
(Nam
));
1798 elsif Nkind
(Nam
) = N_Indexed_Component
then
1799 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1806 end Get_Function_Id
;
1808 ---------------------------
1809 -- Preanalyze_Expression --
1810 ---------------------------
1812 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
1813 Status
: constant Boolean := Get_Ignore_Errors
;
1815 Set_Ignore_Errors
(True);
1817 Set_Ignore_Errors
(Status
);
1818 end Preanalyze_Without_Errors
;
1820 -- Start of processing for Check_Function_Writable_Actuals
1823 -- The check only applies to Ada 2012 code, and only to constructs that
1824 -- have multiple constituents whose order of evaluation is not specified
1827 if Ada_Version
< Ada_2012
1828 or else (not (Nkind
(N
) in N_Op
)
1829 and then not (Nkind
(N
) in N_Membership_Test
)
1830 and then not Nkind_In
(N
, N_Range
,
1832 N_Extension_Aggregate
,
1833 N_Full_Type_Declaration
,
1835 N_Procedure_Call_Statement
,
1836 N_Entry_Call_Statement
))
1837 or else (Nkind
(N
) = N_Full_Type_Declaration
1838 and then not Is_Record_Type
(Defining_Identifier
(N
)))
1840 -- In addition, this check only applies to source code, not to code
1841 -- generated by constraint checks.
1843 or else not Comes_From_Source
(N
)
1848 -- If a construct C has two or more direct constituents that are names
1849 -- or expressions whose evaluation may occur in an arbitrary order, at
1850 -- least one of which contains a function call with an in out or out
1851 -- parameter, then the construct is legal only if: for each name N that
1852 -- is passed as a parameter of mode in out or out to some inner function
1853 -- call C2 (not including the construct C itself), there is no other
1854 -- name anywhere within a direct constituent of the construct C other
1855 -- than the one containing C2, that is known to refer to the same
1856 -- object (RM 6.4.1(6.17/3)).
1860 Collect_Identifiers
(Low_Bound
(N
));
1861 Collect_Identifiers
(High_Bound
(N
));
1863 when N_Op | N_Membership_Test
=>
1867 Collect_Identifiers
(Left_Opnd
(N
));
1869 if Present
(Right_Opnd
(N
)) then
1870 Collect_Identifiers
(Right_Opnd
(N
));
1873 if Nkind_In
(N
, N_In
, N_Not_In
)
1874 and then Present
(Alternatives
(N
))
1876 Expr
:= First
(Alternatives
(N
));
1877 while Present
(Expr
) loop
1878 Collect_Identifiers
(Expr
);
1885 when N_Full_Type_Declaration
=>
1887 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
1888 -- Return the record part of this record type definition
1890 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
1891 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
1893 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
1894 return Record_Extension_Part
(Type_Def
);
1898 end Get_Record_Part
;
1901 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
1902 Rec
: Node_Id
:= Get_Record_Part
(N
);
1905 -- No need to perform any analysis if the record has no
1908 if No
(Rec
) or else No
(Component_List
(Rec
)) then
1912 -- Collect the identifiers starting from the deepest
1913 -- derivation. Done to report the error in the deepest
1917 if Present
(Component_List
(Rec
)) then
1918 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
1919 while Present
(Comp
) loop
1920 if Nkind
(Comp
) = N_Component_Declaration
1921 and then Present
(Expression
(Comp
))
1923 Collect_Identifiers
(Expression
(Comp
));
1930 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
1931 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
1934 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
1935 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
1939 when N_Subprogram_Call |
1940 N_Entry_Call_Statement
=>
1942 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
1947 Formal
:= First_Formal
(Id
);
1948 Actual
:= First_Actual
(N
);
1949 while Present
(Actual
) and then Present
(Formal
) loop
1950 if Ekind_In
(Formal
, E_Out_Parameter
,
1953 Collect_Identifiers
(Actual
);
1956 Next_Formal
(Formal
);
1957 Next_Actual
(Actual
);
1962 N_Extension_Aggregate
=>
1966 Comp_Expr
: Node_Id
;
1969 -- Handle the N_Others_Choice of array aggregates with static
1970 -- bounds. There is no need to perform this analysis in
1971 -- aggregates without static bounds since we cannot evaluate
1972 -- if the N_Others_Choice covers several elements. There is
1973 -- no need to handle the N_Others choice of record aggregates
1974 -- since at this stage it has been already expanded by
1975 -- Resolve_Record_Aggregate.
1977 if Is_Array_Type
(Etype
(N
))
1978 and then Nkind
(N
) = N_Aggregate
1979 and then Present
(Aggregate_Bounds
(N
))
1980 and then Compile_Time_Known_Bounds
(Etype
(N
))
1981 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
1982 > Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
1985 Count_Components
: Uint
:= Uint_0
;
1986 Num_Components
: Uint
;
1987 Others_Assoc
: Node_Id
;
1988 Others_Choice
: Node_Id
:= Empty
;
1989 Others_Box_Present
: Boolean := False;
1992 -- Count positional associations
1994 if Present
(Expressions
(N
)) then
1995 Comp_Expr
:= First
(Expressions
(N
));
1996 while Present
(Comp_Expr
) loop
1997 Count_Components
:= Count_Components
+ 1;
2002 -- Count the rest of elements and locate the N_Others
2005 Assoc
:= First
(Component_Associations
(N
));
2006 while Present
(Assoc
) loop
2007 Choice
:= First
(Choices
(Assoc
));
2008 while Present
(Choice
) loop
2009 if Nkind
(Choice
) = N_Others_Choice
then
2010 Others_Assoc
:= Assoc
;
2011 Others_Choice
:= Choice
;
2012 Others_Box_Present
:= Box_Present
(Assoc
);
2014 -- Count several components
2016 elsif Nkind_In
(Choice
, N_Range
,
2017 N_Subtype_Indication
)
2018 or else (Is_Entity_Name
(Choice
)
2019 and then Is_Type
(Entity
(Choice
)))
2024 Get_Index_Bounds
(Choice
, L
, H
);
2026 (Compile_Time_Known_Value
(L
)
2027 and then Compile_Time_Known_Value
(H
));
2030 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2033 -- Count single component. No other case available
2034 -- since we are handling an aggregate with static
2038 pragma Assert
(Is_Static_Expression
(Choice
)
2039 or else Nkind
(Choice
) = N_Identifier
2040 or else Nkind
(Choice
) = N_Integer_Literal
);
2042 Count_Components
:= Count_Components
+ 1;
2052 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2053 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2055 pragma Assert
(Count_Components
<= Num_Components
);
2057 -- Handle the N_Others choice if it covers several
2060 if Present
(Others_Choice
)
2061 and then (Num_Components
- Count_Components
) > 1
2063 if not Others_Box_Present
then
2065 -- At this stage, if expansion is active, the
2066 -- expression of the others choice has not been
2067 -- analyzed. Hence we generate a duplicate and
2068 -- we analyze it silently to have available the
2069 -- minimum decoration required to collect the
2072 if not Expander_Active
then
2073 Comp_Expr
:= Expression
(Others_Assoc
);
2076 New_Copy_Tree
(Expression
(Others_Assoc
));
2077 Preanalyze_Without_Errors
(Comp_Expr
);
2080 Collect_Identifiers
(Comp_Expr
);
2082 if Writable_Actuals_List
/= No_Elist
then
2084 -- As suggested by Robert, at current stage we
2085 -- report occurrences of this case as warnings.
2088 ("writable function parameter may affect "
2089 & "value in other component because order "
2090 & "of evaluation is unspecified?",
2091 Node
(First_Elmt
(Writable_Actuals_List
)));
2098 -- Handle ancestor part of extension aggregates
2100 if Nkind
(N
) = N_Extension_Aggregate
then
2101 Collect_Identifiers
(Ancestor_Part
(N
));
2104 -- Handle positional associations
2106 if Present
(Expressions
(N
)) then
2107 Comp_Expr
:= First
(Expressions
(N
));
2108 while Present
(Comp_Expr
) loop
2109 if not Is_Static_Expression
(Comp_Expr
) then
2110 Collect_Identifiers
(Comp_Expr
);
2117 -- Handle discrete associations
2119 if Present
(Component_Associations
(N
)) then
2120 Assoc
:= First
(Component_Associations
(N
));
2121 while Present
(Assoc
) loop
2123 if not Box_Present
(Assoc
) then
2124 Choice
:= First
(Choices
(Assoc
));
2125 while Present
(Choice
) loop
2127 -- For now we skip discriminants since it requires
2128 -- performing the analysis in two phases: first one
2129 -- analyzing discriminants and second one analyzing
2130 -- the rest of components since discriminants are
2131 -- evaluated prior to components: too much extra
2132 -- work to detect a corner case???
2134 if Nkind
(Choice
) in N_Has_Entity
2135 and then Present
(Entity
(Choice
))
2136 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2140 elsif Box_Present
(Assoc
) then
2144 if not Analyzed
(Expression
(Assoc
)) then
2146 New_Copy_Tree
(Expression
(Assoc
));
2147 Set_Parent
(Comp_Expr
, Parent
(N
));
2148 Preanalyze_Without_Errors
(Comp_Expr
);
2150 Comp_Expr
:= Expression
(Assoc
);
2153 Collect_Identifiers
(Comp_Expr
);
2169 -- No further action needed if we already reported an error
2171 if Present
(Error_Node
) then
2175 -- Check if some writable argument of a function is referenced
2177 if Writable_Actuals_List
/= No_Elist
2178 and then Identifiers_List
/= No_Elist
2185 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2186 while Present
(Elmt_1
) loop
2187 Elmt_2
:= First_Elmt
(Identifiers_List
);
2188 while Present
(Elmt_2
) loop
2189 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2190 case Nkind
(Parent
(Node
(Elmt_2
))) is
2192 N_Component_Association |
2193 N_Component_Declaration
=>
2195 ("value may be affected by call in other "
2196 & "component because they are evaluated "
2197 & "in unspecified order",
2200 when N_In | N_Not_In
=>
2202 ("value may be affected by call in other "
2203 & "alternative because they are evaluated "
2204 & "in unspecified order",
2209 ("value of actual may be affected by call in "
2210 & "other actual because they are evaluated "
2211 & "in unspecified order",
2223 end Check_Function_Writable_Actuals
;
2225 --------------------------------
2226 -- Check_Implicit_Dereference --
2227 --------------------------------
2229 procedure Check_Implicit_Dereference
(Nam
: Node_Id
; Typ
: Entity_Id
) is
2234 if Ada_Version
< Ada_2012
2235 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2239 elsif not Comes_From_Source
(Nam
) then
2242 elsif Is_Entity_Name
(Nam
)
2243 and then Is_Type
(Entity
(Nam
))
2248 Disc
:= First_Discriminant
(Typ
);
2249 while Present
(Disc
) loop
2250 if Has_Implicit_Dereference
(Disc
) then
2251 Desig
:= Designated_Type
(Etype
(Disc
));
2252 Add_One_Interp
(Nam
, Disc
, Desig
);
2256 Next_Discriminant
(Disc
);
2259 end Check_Implicit_Dereference
;
2261 ----------------------------------
2262 -- Check_Internal_Protected_Use --
2263 ----------------------------------
2265 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2271 while Present
(S
) loop
2272 if S
= Standard_Standard
then
2275 elsif Ekind
(S
) = E_Function
2276 and then Ekind
(Scope
(S
)) = E_Protected_Type
2285 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2287 -- An indirect function call (e.g. a callback within a protected
2288 -- function body) is not statically illegal. If the access type is
2289 -- anonymous and is the type of an access parameter, the scope of Nam
2290 -- will be the protected type, but it is not a protected operation.
2292 if Ekind
(Nam
) = E_Subprogram_Type
2294 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2298 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2300 ("within protected function cannot use protected "
2301 & "procedure in renaming or as generic actual", N
);
2303 elsif Nkind
(N
) = N_Attribute_Reference
then
2305 ("within protected function cannot take access of "
2306 & " protected procedure", N
);
2310 ("within protected function, protected object is constant", N
);
2312 ("\cannot call operation that may modify it", N
);
2315 end Check_Internal_Protected_Use
;
2317 ---------------------------------------
2318 -- Check_Later_Vs_Basic_Declarations --
2319 ---------------------------------------
2321 procedure Check_Later_Vs_Basic_Declarations
2323 During_Parsing
: Boolean)
2325 Body_Sloc
: Source_Ptr
;
2328 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2329 -- Return whether Decl is considered as a declarative item.
2330 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2331 -- When During_Parsing is False, the semantics of SPARK is followed.
2333 -------------------------------
2334 -- Is_Later_Declarative_Item --
2335 -------------------------------
2337 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2339 if Nkind
(Decl
) in N_Later_Decl_Item
then
2342 elsif Nkind
(Decl
) = N_Pragma
then
2345 elsif During_Parsing
then
2348 -- In SPARK, a package declaration is not considered as a later
2349 -- declarative item.
2351 elsif Nkind
(Decl
) = N_Package_Declaration
then
2354 -- In SPARK, a renaming is considered as a later declarative item
2356 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2362 end Is_Later_Declarative_Item
;
2364 -- Start of Check_Later_Vs_Basic_Declarations
2367 Decl
:= First
(Decls
);
2369 -- Loop through sequence of basic declarative items
2371 Outer
: while Present
(Decl
) loop
2372 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2373 and then Nkind
(Decl
) not in N_Body_Stub
2377 -- Once a body is encountered, we only allow later declarative
2378 -- items. The inner loop checks the rest of the list.
2381 Body_Sloc
:= Sloc
(Decl
);
2383 Inner
: while Present
(Decl
) loop
2384 if not Is_Later_Declarative_Item
(Decl
) then
2385 if During_Parsing
then
2386 if Ada_Version
= Ada_83
then
2387 Error_Msg_Sloc
:= Body_Sloc
;
2389 ("(Ada 83) decl cannot appear after body#", Decl
);
2392 Error_Msg_Sloc
:= Body_Sloc
;
2393 Check_SPARK_Restriction
2394 ("decl cannot appear after body#", Decl
);
2402 end Check_Later_Vs_Basic_Declarations
;
2404 -------------------------
2405 -- Check_Nested_Access --
2406 -------------------------
2408 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2409 Scop
: constant Entity_Id
:= Current_Scope
;
2410 Current_Subp
: Entity_Id
;
2411 Enclosing
: Entity_Id
;
2414 -- Currently only enabled for VM back-ends for efficiency, should we
2415 -- enable it more systematically ???
2417 -- Check for Is_Imported needs commenting below ???
2419 if VM_Target
/= No_VM
2420 and then (Ekind
(Ent
) = E_Variable
2422 Ekind
(Ent
) = E_Constant
2424 Ekind
(Ent
) = E_Loop_Parameter
)
2425 and then Scope
(Ent
) /= Empty
2426 and then not Is_Library_Level_Entity
(Ent
)
2427 and then not Is_Imported
(Ent
)
2429 if Is_Subprogram
(Scop
)
2430 or else Is_Generic_Subprogram
(Scop
)
2431 or else Is_Entry
(Scop
)
2433 Current_Subp
:= Scop
;
2435 Current_Subp
:= Current_Subprogram
;
2438 Enclosing
:= Enclosing_Subprogram
(Ent
);
2440 if Enclosing
/= Empty
2441 and then Enclosing
/= Current_Subp
2443 Set_Has_Up_Level_Access
(Ent
, True);
2446 end Check_Nested_Access
;
2448 ---------------------------
2449 -- Check_No_Hidden_State --
2450 ---------------------------
2452 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2453 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2454 -- Determine whether the entity of a package denoted by Pkg has a null
2457 -----------------------------
2458 -- Has_Null_Abstract_State --
2459 -----------------------------
2461 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2462 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2465 -- Check first available state of related package. A null abstract
2466 -- state always appears as the sole element of the state list.
2470 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2471 end Has_Null_Abstract_State
;
2475 Context
: Entity_Id
:= Empty
;
2476 Not_Visible
: Boolean := False;
2479 -- Start of processing for Check_No_Hidden_State
2482 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2484 -- Find the proper context where the object or state appears
2487 while Present
(Scop
) loop
2490 -- Keep track of the context's visibility
2492 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2494 -- Prevent the search from going too far
2496 if Context
= Standard_Standard
then
2499 -- Objects and states that appear immediately within a subprogram or
2500 -- inside a construct nested within a subprogram do not introduce a
2501 -- hidden state. They behave as local variable declarations.
2503 elsif Is_Subprogram
(Context
) then
2506 -- When examining a package body, use the entity of the spec as it
2507 -- carries the abstract state declarations.
2509 elsif Ekind
(Context
) = E_Package_Body
then
2510 Context
:= Spec_Entity
(Context
);
2513 -- Stop the traversal when a package subject to a null abstract state
2516 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2517 and then Has_Null_Abstract_State
(Context
)
2522 Scop
:= Scope
(Scop
);
2525 -- At this point we know that there is at least one package with a null
2526 -- abstract state in visibility. Emit an error message unconditionally
2527 -- if the entity being processed is a state because the placement of the
2528 -- related package is irrelevant. This is not the case for objects as
2529 -- the intermediate context matters.
2531 if Present
(Context
)
2532 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
2534 Error_Msg_N
("cannot introduce hidden state &", Id
);
2535 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
2537 end Check_No_Hidden_State
;
2539 ------------------------------------------
2540 -- Check_Potentially_Blocking_Operation --
2541 ------------------------------------------
2543 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2547 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2548 -- When pragma Detect_Blocking is active, the run time will raise
2549 -- Program_Error. Here we only issue a warning, since we generally
2550 -- support the use of potentially blocking operations in the absence
2553 -- Indirect blocking through a subprogram call cannot be diagnosed
2554 -- statically without interprocedural analysis, so we do not attempt
2557 S
:= Scope
(Current_Scope
);
2558 while Present
(S
) and then S
/= Standard_Standard
loop
2559 if Is_Protected_Type
(S
) then
2561 ("potentially blocking operation in protected operation??", N
);
2567 end Check_Potentially_Blocking_Operation
;
2569 ---------------------------------
2570 -- Check_Result_And_Post_State --
2571 ---------------------------------
2573 procedure Check_Result_And_Post_State
2575 Result_Seen
: in out Boolean)
2577 procedure Check_Expression
(Expr
: Node_Id
);
2578 -- Perform the 'Result and post-state checks on a given expression
2580 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
2581 -- Attempt to find attribute 'Result in a subtree denoted by N
2583 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
2584 -- Determine whether source node N denotes "True" or "False"
2586 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
2587 -- Determine whether a subtree denoted by N mentions any construct that
2588 -- denotes a post-state.
2590 procedure Check_Function_Result
is
2591 new Traverse_Proc
(Is_Function_Result
);
2593 ----------------------
2594 -- Check_Expression --
2595 ----------------------
2597 procedure Check_Expression
(Expr
: Node_Id
) is
2599 if not Is_Trivial_Boolean
(Expr
) then
2600 Check_Function_Result
(Expr
);
2602 if not Mentions_Post_State
(Expr
) then
2603 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
2605 ("contract case refers only to pre-state?T?", Expr
);
2607 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
2609 ("refined postcondition refers only to pre-state?T?",
2614 ("postcondition refers only to pre-state?T?", Prag
);
2618 end Check_Expression
;
2620 ------------------------
2621 -- Is_Function_Result --
2622 ------------------------
2624 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
2626 if Is_Attribute_Result
(N
) then
2627 Result_Seen
:= True;
2630 -- Continue the traversal
2635 end Is_Function_Result
;
2637 ------------------------
2638 -- Is_Trivial_Boolean --
2639 ------------------------
2641 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
2644 Comes_From_Source
(N
)
2645 and then Is_Entity_Name
(N
)
2646 and then (Entity
(N
) = Standard_True
2647 or else Entity
(N
) = Standard_False
);
2648 end Is_Trivial_Boolean
;
2650 -------------------------
2651 -- Mentions_Post_State --
2652 -------------------------
2654 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
2655 Post_State_Seen
: Boolean := False;
2657 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
2658 -- Attempt to find a construct that denotes a post-state. If this is
2659 -- the case, set flag Post_State_Seen.
2665 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
2669 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
2670 Post_State_Seen
:= True;
2673 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
2676 -- The entity may be modifiable through an implicit dereference
2679 or else Ekind
(Ent
) in Assignable_Kind
2680 or else (Is_Access_Type
(Etype
(Ent
))
2681 and then Nkind
(Parent
(N
)) = N_Selected_Component
)
2683 Post_State_Seen
:= True;
2687 elsif Nkind
(N
) = N_Attribute_Reference
then
2688 if Attribute_Name
(N
) = Name_Old
then
2691 elsif Attribute_Name
(N
) = Name_Result
then
2692 Post_State_Seen
:= True;
2700 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
2702 -- Start of processing for Mentions_Post_State
2705 Find_Post_State
(N
);
2707 return Post_State_Seen
;
2708 end Mentions_Post_State
;
2712 Expr
: constant Node_Id
:=
2713 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
2714 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
2717 -- Start of processing for Check_Result_And_Post_State
2720 -- Examine all consequences
2722 if Nam
= Name_Contract_Cases
then
2723 CCase
:= First
(Component_Associations
(Expr
));
2724 while Present
(CCase
) loop
2725 Check_Expression
(Expression
(CCase
));
2730 -- Examine the expression of a postcondition
2732 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
, Name_Refined_Post
));
2733 Check_Expression
(Expr
);
2735 end Check_Result_And_Post_State
;
2737 ---------------------------------
2738 -- Check_SPARK_Mode_In_Generic --
2739 ---------------------------------
2741 procedure Check_SPARK_Mode_In_Generic
(N
: Node_Id
) is
2745 -- Try to find aspect SPARK_Mode and flag it as illegal
2747 if Has_Aspects
(N
) then
2748 Aspect
:= First
(Aspect_Specifications
(N
));
2749 while Present
(Aspect
) loop
2750 if Get_Aspect_Id
(Aspect
) = Aspect_SPARK_Mode
then
2751 Error_Msg_Name_1
:= Name_SPARK_Mode
;
2753 ("incorrect placement of aspect % on a generic", Aspect
);
2760 end Check_SPARK_Mode_In_Generic
;
2762 ------------------------------
2763 -- Check_Unprotected_Access --
2764 ------------------------------
2766 procedure Check_Unprotected_Access
2770 Cont_Encl_Typ
: Entity_Id
;
2771 Pref_Encl_Typ
: Entity_Id
;
2773 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
2774 -- Check whether Obj is a private component of a protected object.
2775 -- Return the protected type where the component resides, Empty
2778 function Is_Public_Operation
return Boolean;
2779 -- Verify that the enclosing operation is callable from outside the
2780 -- protected object, to minimize false positives.
2782 ------------------------------
2783 -- Enclosing_Protected_Type --
2784 ------------------------------
2786 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
2788 if Is_Entity_Name
(Obj
) then
2790 Ent
: Entity_Id
:= Entity
(Obj
);
2793 -- The object can be a renaming of a private component, use
2794 -- the original record component.
2796 if Is_Prival
(Ent
) then
2797 Ent
:= Prival_Link
(Ent
);
2800 if Is_Protected_Type
(Scope
(Ent
)) then
2806 -- For indexed and selected components, recursively check the prefix
2808 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
2809 return Enclosing_Protected_Type
(Prefix
(Obj
));
2811 -- The object does not denote a protected component
2816 end Enclosing_Protected_Type
;
2818 -------------------------
2819 -- Is_Public_Operation --
2820 -------------------------
2822 function Is_Public_Operation
return Boolean is
2829 and then S
/= Pref_Encl_Typ
2831 if Scope
(S
) = Pref_Encl_Typ
then
2832 E
:= First_Entity
(Pref_Encl_Typ
);
2834 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
2847 end Is_Public_Operation
;
2849 -- Start of processing for Check_Unprotected_Access
2852 if Nkind
(Expr
) = N_Attribute_Reference
2853 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
2855 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
2856 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
2858 -- Check whether we are trying to export a protected component to a
2859 -- context with an equal or lower access level.
2861 if Present
(Pref_Encl_Typ
)
2862 and then No
(Cont_Encl_Typ
)
2863 and then Is_Public_Operation
2864 and then Scope_Depth
(Pref_Encl_Typ
) >=
2865 Object_Access_Level
(Context
)
2868 ("??possible unprotected access to protected data", Expr
);
2871 end Check_Unprotected_Access
;
2877 procedure Check_VMS
(Construct
: Node_Id
) is
2879 if not OpenVMS_On_Target
then
2881 ("this construct is allowed only in Open'V'M'S", Construct
);
2885 ------------------------
2886 -- Collect_Interfaces --
2887 ------------------------
2889 procedure Collect_Interfaces
2891 Ifaces_List
: out Elist_Id
;
2892 Exclude_Parents
: Boolean := False;
2893 Use_Full_View
: Boolean := True)
2895 procedure Collect
(Typ
: Entity_Id
);
2896 -- Subsidiary subprogram used to traverse the whole list
2897 -- of directly and indirectly implemented interfaces
2903 procedure Collect
(Typ
: Entity_Id
) is
2904 Ancestor
: Entity_Id
;
2912 -- Handle private types
2915 and then Is_Private_Type
(Typ
)
2916 and then Present
(Full_View
(Typ
))
2918 Full_T
:= Full_View
(Typ
);
2921 -- Include the ancestor if we are generating the whole list of
2922 -- abstract interfaces.
2924 if Etype
(Full_T
) /= Typ
2926 -- Protect the frontend against wrong sources. For example:
2929 -- type A is tagged null record;
2930 -- type B is new A with private;
2931 -- type C is new A with private;
2933 -- type B is new C with null record;
2934 -- type C is new B with null record;
2937 and then Etype
(Full_T
) /= T
2939 Ancestor
:= Etype
(Full_T
);
2942 if Is_Interface
(Ancestor
)
2943 and then not Exclude_Parents
2945 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
2949 -- Traverse the graph of ancestor interfaces
2951 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
2952 Id
:= First
(Abstract_Interface_List
(Full_T
));
2953 while Present
(Id
) loop
2954 Iface
:= Etype
(Id
);
2956 -- Protect against wrong uses. For example:
2957 -- type I is interface;
2958 -- type O is tagged null record;
2959 -- type Wrong is new I and O with null record; -- ERROR
2961 if Is_Interface
(Iface
) then
2963 and then Etype
(T
) /= T
2964 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
2969 Append_Unique_Elmt
(Iface
, Ifaces_List
);
2978 -- Start of processing for Collect_Interfaces
2981 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
2982 Ifaces_List
:= New_Elmt_List
;
2984 end Collect_Interfaces
;
2986 ----------------------------------
2987 -- Collect_Interface_Components --
2988 ----------------------------------
2990 procedure Collect_Interface_Components
2991 (Tagged_Type
: Entity_Id
;
2992 Components_List
: out Elist_Id
)
2994 procedure Collect
(Typ
: Entity_Id
);
2995 -- Subsidiary subprogram used to climb to the parents
3001 procedure Collect
(Typ
: Entity_Id
) is
3002 Tag_Comp
: Entity_Id
;
3003 Parent_Typ
: Entity_Id
;
3006 -- Handle private types
3008 if Present
(Full_View
(Etype
(Typ
))) then
3009 Parent_Typ
:= Full_View
(Etype
(Typ
));
3011 Parent_Typ
:= Etype
(Typ
);
3014 if Parent_Typ
/= Typ
3016 -- Protect the frontend against wrong sources. For example:
3019 -- type A is tagged null record;
3020 -- type B is new A with private;
3021 -- type C is new A with private;
3023 -- type B is new C with null record;
3024 -- type C is new B with null record;
3027 and then Parent_Typ
/= Tagged_Type
3029 Collect
(Parent_Typ
);
3032 -- Collect the components containing tags of secondary dispatch
3035 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
3036 while Present
(Tag_Comp
) loop
3037 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
3038 Append_Elmt
(Tag_Comp
, Components_List
);
3040 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
3044 -- Start of processing for Collect_Interface_Components
3047 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
3048 and then Is_Tagged_Type
(Tagged_Type
));
3050 Components_List
:= New_Elmt_List
;
3051 Collect
(Tagged_Type
);
3052 end Collect_Interface_Components
;
3054 -----------------------------
3055 -- Collect_Interfaces_Info --
3056 -----------------------------
3058 procedure Collect_Interfaces_Info
3060 Ifaces_List
: out Elist_Id
;
3061 Components_List
: out Elist_Id
;
3062 Tags_List
: out Elist_Id
)
3064 Comps_List
: Elist_Id
;
3065 Comp_Elmt
: Elmt_Id
;
3066 Comp_Iface
: Entity_Id
;
3067 Iface_Elmt
: Elmt_Id
;
3070 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3071 -- Search for the secondary tag associated with the interface type
3072 -- Iface that is implemented by T.
3078 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3081 if not Is_CPP_Class
(T
) then
3082 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3084 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3088 and then Is_Tag
(Node
(ADT
))
3089 and then Related_Type
(Node
(ADT
)) /= Iface
3091 -- Skip secondary dispatch table referencing thunks to user
3092 -- defined primitives covered by this interface.
3094 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3097 -- Skip secondary dispatch tables of Ada types
3099 if not Is_CPP_Class
(T
) then
3101 -- Skip secondary dispatch table referencing thunks to
3102 -- predefined primitives.
3104 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3107 -- Skip secondary dispatch table referencing user-defined
3108 -- primitives covered by this interface.
3110 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3113 -- Skip secondary dispatch table referencing predefined
3116 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3121 pragma Assert
(Is_Tag
(Node
(ADT
)));
3125 -- Start of processing for Collect_Interfaces_Info
3128 Collect_Interfaces
(T
, Ifaces_List
);
3129 Collect_Interface_Components
(T
, Comps_List
);
3131 -- Search for the record component and tag associated with each
3132 -- interface type of T.
3134 Components_List
:= New_Elmt_List
;
3135 Tags_List
:= New_Elmt_List
;
3137 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3138 while Present
(Iface_Elmt
) loop
3139 Iface
:= Node
(Iface_Elmt
);
3141 -- Associate the primary tag component and the primary dispatch table
3142 -- with all the interfaces that are parents of T
3144 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3145 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3146 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3148 -- Otherwise search for the tag component and secondary dispatch
3152 Comp_Elmt
:= First_Elmt
(Comps_List
);
3153 while Present
(Comp_Elmt
) loop
3154 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3156 if Comp_Iface
= Iface
3157 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3159 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3160 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3164 Next_Elmt
(Comp_Elmt
);
3166 pragma Assert
(Present
(Comp_Elmt
));
3169 Next_Elmt
(Iface_Elmt
);
3171 end Collect_Interfaces_Info
;
3173 ---------------------
3174 -- Collect_Parents --
3175 ---------------------
3177 procedure Collect_Parents
3179 List
: out Elist_Id
;
3180 Use_Full_View
: Boolean := True)
3182 Current_Typ
: Entity_Id
:= T
;
3183 Parent_Typ
: Entity_Id
;
3186 List
:= New_Elmt_List
;
3188 -- No action if the if the type has no parents
3190 if T
= Etype
(T
) then
3195 Parent_Typ
:= Etype
(Current_Typ
);
3197 if Is_Private_Type
(Parent_Typ
)
3198 and then Present
(Full_View
(Parent_Typ
))
3199 and then Use_Full_View
3201 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3204 Append_Elmt
(Parent_Typ
, List
);
3206 exit when Parent_Typ
= Current_Typ
;
3207 Current_Typ
:= Parent_Typ
;
3209 end Collect_Parents
;
3211 ----------------------------------
3212 -- Collect_Primitive_Operations --
3213 ----------------------------------
3215 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3216 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3217 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3218 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3222 Is_Type_In_Pkg
: Boolean;
3223 Formal_Derived
: Boolean := False;
3226 function Match
(E
: Entity_Id
) return Boolean;
3227 -- True if E's base type is B_Type, or E is of an anonymous access type
3228 -- and the base type of its designated type is B_Type.
3234 function Match
(E
: Entity_Id
) return Boolean is
3235 Etyp
: Entity_Id
:= Etype
(E
);
3238 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
3239 Etyp
:= Designated_Type
(Etyp
);
3242 return Base_Type
(Etyp
) = B_Type
;
3245 -- Start of processing for Collect_Primitive_Operations
3248 -- For tagged types, the primitive operations are collected as they
3249 -- are declared, and held in an explicit list which is simply returned.
3251 if Is_Tagged_Type
(B_Type
) then
3252 return Primitive_Operations
(B_Type
);
3254 -- An untagged generic type that is a derived type inherits the
3255 -- primitive operations of its parent type. Other formal types only
3256 -- have predefined operators, which are not explicitly represented.
3258 elsif Is_Generic_Type
(B_Type
) then
3259 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
3260 and then Nkind
(Formal_Type_Definition
(B_Decl
))
3261 = N_Formal_Derived_Type_Definition
3263 Formal_Derived
:= True;
3265 return New_Elmt_List
;
3269 Op_List
:= New_Elmt_List
;
3271 if B_Scope
= Standard_Standard
then
3272 if B_Type
= Standard_String
then
3273 Append_Elmt
(Standard_Op_Concat
, Op_List
);
3275 elsif B_Type
= Standard_Wide_String
then
3276 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
3282 -- Locate the primitive subprograms of the type
3285 -- The primitive operations appear after the base type, except
3286 -- if the derivation happens within the private part of B_Scope
3287 -- and the type is a private type, in which case both the type
3288 -- and some primitive operations may appear before the base
3289 -- type, and the list of candidates starts after the type.
3291 if In_Open_Scopes
(B_Scope
)
3292 and then Scope
(T
) = B_Scope
3293 and then In_Private_Part
(B_Scope
)
3295 Id
:= Next_Entity
(T
);
3297 Id
:= Next_Entity
(B_Type
);
3300 -- Set flag if this is a type in a package spec
3303 Is_Package_Or_Generic_Package
(B_Scope
)
3305 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
3308 while Present
(Id
) loop
3310 -- Test whether the result type or any of the parameter types of
3311 -- each subprogram following the type match that type when the
3312 -- type is declared in a package spec, is a derived type, or the
3313 -- subprogram is marked as primitive. (The Is_Primitive test is
3314 -- needed to find primitives of nonderived types in declarative
3315 -- parts that happen to override the predefined "=" operator.)
3317 -- Note that generic formal subprograms are not considered to be
3318 -- primitive operations and thus are never inherited.
3320 if Is_Overloadable
(Id
)
3321 and then (Is_Type_In_Pkg
3322 or else Is_Derived_Type
(B_Type
)
3323 or else Is_Primitive
(Id
))
3324 and then Nkind
(Parent
(Parent
(Id
)))
3325 not in N_Formal_Subprogram_Declaration
3333 Formal
:= First_Formal
(Id
);
3334 while Present
(Formal
) loop
3335 if Match
(Formal
) then
3340 Next_Formal
(Formal
);
3344 -- For a formal derived type, the only primitives are the ones
3345 -- inherited from the parent type. Operations appearing in the
3346 -- package declaration are not primitive for it.
3349 and then (not Formal_Derived
3350 or else Present
(Alias
(Id
)))
3352 -- In the special case of an equality operator aliased to
3353 -- an overriding dispatching equality belonging to the same
3354 -- type, we don't include it in the list of primitives.
3355 -- This avoids inheriting multiple equality operators when
3356 -- deriving from untagged private types whose full type is
3357 -- tagged, which can otherwise cause ambiguities. Note that
3358 -- this should only happen for this kind of untagged parent
3359 -- type, since normally dispatching operations are inherited
3360 -- using the type's Primitive_Operations list.
3362 if Chars
(Id
) = Name_Op_Eq
3363 and then Is_Dispatching_Operation
(Id
)
3364 and then Present
(Alias
(Id
))
3365 and then Present
(Overridden_Operation
(Alias
(Id
)))
3366 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3367 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3371 -- Include the subprogram in the list of primitives
3374 Append_Elmt
(Id
, Op_List
);
3381 -- For a type declared in System, some of its operations may
3382 -- appear in the target-specific extension to System.
3385 and then B_Scope
= RTU_Entity
(System
)
3386 and then Present_System_Aux
3388 B_Scope
:= System_Aux_Id
;
3389 Id
:= First_Entity
(System_Aux_Id
);
3395 end Collect_Primitive_Operations
;
3397 -----------------------------------
3398 -- Compile_Time_Constraint_Error --
3399 -----------------------------------
3401 function Compile_Time_Constraint_Error
3404 Ent
: Entity_Id
:= Empty
;
3405 Loc
: Source_Ptr
:= No_Location
;
3406 Warn
: Boolean := False) return Node_Id
3408 Msgc
: String (1 .. Msg
'Length + 3);
3409 -- Copy of message, with room for possible ?? or << and ! at end
3419 -- If this is a warning, convert it into an error if we are in code
3420 -- subject to SPARK_Mode being set ON.
3422 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3424 -- A static constraint error in an instance body is not a fatal error.
3425 -- we choose to inhibit the message altogether, because there is no
3426 -- obvious node (for now) on which to post it. On the other hand the
3427 -- offending node must be replaced with a constraint_error in any case.
3429 -- No messages are generated if we already posted an error on this node
3431 if not Error_Posted
(N
) then
3432 if Loc
/= No_Location
then
3438 -- Copy message to Msgc, converting any ? in the message into
3439 -- < instead, so that we have an error in GNATprove mode.
3443 for J
in 1 .. Msgl
loop
3444 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
3447 Msgc
(J
) := Msg
(J
);
3451 -- Message is a warning, even in Ada 95 case
3453 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
3456 -- In Ada 83, all messages are warnings. In the private part and
3457 -- the body of an instance, constraint_checks are only warnings.
3458 -- We also make this a warning if the Warn parameter is set.
3461 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
3469 elsif In_Instance_Not_Visible
then
3476 -- Otherwise we have a real error message (Ada 95 static case)
3477 -- and we make this an unconditional message. Note that in the
3478 -- warning case we do not make the message unconditional, it seems
3479 -- quite reasonable to delete messages like this (about exceptions
3480 -- that will be raised) in dead code.
3488 -- Should we generate a warning? The answer is not quite yes. The
3489 -- very annoying exception occurs in the case of a short circuit
3490 -- operator where the left operand is static and decisive. Climb
3491 -- parents to see if that is the case we have here. Conditional
3492 -- expressions with decisive conditions are a similar situation.
3500 -- And then with False as left operand
3502 if Nkind
(P
) = N_And_Then
3503 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3504 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
3509 -- OR ELSE with True as left operand
3511 elsif Nkind
(P
) = N_Or_Else
3512 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
3513 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
3520 elsif Nkind
(P
) = N_If_Expression
then
3522 Cond
: constant Node_Id
:= First
(Expressions
(P
));
3523 Texp
: constant Node_Id
:= Next
(Cond
);
3524 Fexp
: constant Node_Id
:= Next
(Texp
);
3527 if Compile_Time_Known_Value
(Cond
) then
3529 -- Condition is True and we are in the right operand
3531 if Is_True
(Expr_Value
(Cond
))
3532 and then OldP
= Fexp
3537 -- Condition is False and we are in the left operand
3539 elsif Is_False
(Expr_Value
(Cond
))
3540 and then OldP
= Texp
3548 -- Special case for component association in aggregates, where
3549 -- we want to keep climbing up to the parent aggregate.
3551 elsif Nkind
(P
) = N_Component_Association
3552 and then Nkind
(Parent
(P
)) = N_Aggregate
3556 -- Keep going if within subexpression
3559 exit when Nkind
(P
) not in N_Subexpr
;
3564 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3566 if Present
(Ent
) then
3567 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
3569 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
3574 -- Check whether the context is an Init_Proc
3576 if Inside_Init_Proc
then
3578 Conc_Typ
: constant Entity_Id
:=
3579 Corresponding_Concurrent_Type
3580 (Entity
(Parameter_Type
(First
3581 (Parameter_Specifications
3582 (Parent
(Current_Scope
))))));
3585 -- Don't complain if the corresponding concurrent type
3586 -- doesn't come from source (i.e. a single task/protected
3589 if Present
(Conc_Typ
)
3590 and then not Comes_From_Source
(Conc_Typ
)
3593 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3596 if GNATprove_Mode
then
3598 ("\& would have been raised for objects of this "
3599 & "type", N
, Standard_Constraint_Error
, Eloc
);
3602 ("\& will be raised for objects of this type??",
3603 N
, Standard_Constraint_Error
, Eloc
);
3609 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3613 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
3614 Set_Error_Posted
(N
);
3620 end Compile_Time_Constraint_Error
;
3622 -----------------------
3623 -- Conditional_Delay --
3624 -----------------------
3626 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
3628 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
3629 Set_Has_Delayed_Freeze
(New_Ent
);
3631 end Conditional_Delay
;
3633 ----------------------------
3634 -- Contains_Refined_State --
3635 ----------------------------
3637 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
3638 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
3639 -- Determine whether a dependency list mentions a state with a visible
3642 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
3643 -- Determine whether a global list mentions a state with a visible
3646 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
3647 -- Determine whether Item is a reference to an abstract state with a
3648 -- visible refinement.
3650 -----------------------------
3651 -- Has_State_In_Dependency --
3652 -----------------------------
3654 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
3659 -- A null dependency list does not mention any states
3661 if Nkind
(List
) = N_Null
then
3664 -- Dependency clauses appear as component associations of an
3667 elsif Nkind
(List
) = N_Aggregate
3668 and then Present
(Component_Associations
(List
))
3670 Clause
:= First
(Component_Associations
(List
));
3671 while Present
(Clause
) loop
3673 -- Inspect the outputs of a dependency clause
3675 Output
:= First
(Choices
(Clause
));
3676 while Present
(Output
) loop
3677 if Is_Refined_State
(Output
) then
3684 -- Inspect the outputs of a dependency clause
3686 if Is_Refined_State
(Expression
(Clause
)) then
3693 -- If we get here, then none of the dependency clauses mention a
3694 -- state with visible refinement.
3698 -- An illegal pragma managed to sneak in
3701 raise Program_Error
;
3703 end Has_State_In_Dependency
;
3705 -------------------------
3706 -- Has_State_In_Global --
3707 -------------------------
3709 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
3713 -- A null global list does not mention any states
3715 if Nkind
(List
) = N_Null
then
3718 -- Simple global list or moded global list declaration
3720 elsif Nkind
(List
) = N_Aggregate
then
3722 -- The declaration of a simple global list appear as a collection
3725 if Present
(Expressions
(List
)) then
3726 Item
:= First
(Expressions
(List
));
3727 while Present
(Item
) loop
3728 if Is_Refined_State
(Item
) then
3735 -- The declaration of a moded global list appears as a collection
3736 -- of component associations where individual choices denote
3740 Item
:= First
(Component_Associations
(List
));
3741 while Present
(Item
) loop
3742 if Has_State_In_Global
(Expression
(Item
)) then
3750 -- If we get here, then the simple/moded global list did not
3751 -- mention any states with a visible refinement.
3755 -- Single global item declaration
3757 elsif Is_Entity_Name
(List
) then
3758 return Is_Refined_State
(List
);
3760 -- An illegal pragma managed to sneak in
3763 raise Program_Error
;
3765 end Has_State_In_Global
;
3767 ----------------------
3768 -- Is_Refined_State --
3769 ----------------------
3771 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
3773 Item_Id
: Entity_Id
;
3776 if Nkind
(Item
) = N_Null
then
3779 -- States cannot be subject to attribute 'Result. This case arises
3780 -- in dependency relations.
3782 elsif Nkind
(Item
) = N_Attribute_Reference
3783 and then Attribute_Name
(Item
) = Name_Result
3787 -- Multiple items appear as an aggregate. This case arises in
3788 -- dependency relations.
3790 elsif Nkind
(Item
) = N_Aggregate
3791 and then Present
(Expressions
(Item
))
3793 Elmt
:= First
(Expressions
(Item
));
3794 while Present
(Elmt
) loop
3795 if Is_Refined_State
(Elmt
) then
3802 -- If we get here, then none of the inputs or outputs reference a
3803 -- state with visible refinement.
3810 Item_Id
:= Entity_Of
(Item
);
3814 and then Ekind
(Item_Id
) = E_Abstract_State
3815 and then Has_Visible_Refinement
(Item_Id
);
3817 end Is_Refined_State
;
3821 Arg
: constant Node_Id
:=
3822 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
3823 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3825 -- Start of processing for Contains_Refined_State
3828 if Nam
= Name_Depends
then
3829 return Has_State_In_Dependency
(Arg
);
3831 else pragma Assert
(Nam
= Name_Global
);
3832 return Has_State_In_Global
(Arg
);
3834 end Contains_Refined_State
;
3836 -------------------------
3837 -- Copy_Component_List --
3838 -------------------------
3840 function Copy_Component_List
3842 Loc
: Source_Ptr
) return List_Id
3845 Comps
: constant List_Id
:= New_List
;
3848 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
3849 while Present
(Comp
) loop
3850 if Comes_From_Source
(Comp
) then
3852 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
3855 Make_Component_Declaration
(Loc
,
3856 Defining_Identifier
=>
3857 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
3858 Component_Definition
=>
3860 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
3864 Next_Component
(Comp
);
3868 end Copy_Component_List
;
3870 -------------------------
3871 -- Copy_Parameter_List --
3872 -------------------------
3874 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
3875 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
3880 if No
(First_Formal
(Subp_Id
)) then
3884 Formal
:= First_Formal
(Subp_Id
);
3885 while Present
(Formal
) loop
3887 (Make_Parameter_Specification
(Loc
,
3888 Defining_Identifier
=>
3889 Make_Defining_Identifier
(Sloc
(Formal
),
3890 Chars
=> Chars
(Formal
)),
3891 In_Present
=> In_Present
(Parent
(Formal
)),
3892 Out_Present
=> Out_Present
(Parent
(Formal
)),
3894 New_Occurrence_Of
(Etype
(Formal
), Loc
),
3896 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
3899 Next_Formal
(Formal
);
3904 end Copy_Parameter_List
;
3906 --------------------------------
3907 -- Corresponding_Generic_Type --
3908 --------------------------------
3910 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
3916 if not Is_Generic_Actual_Type
(T
) then
3919 -- If the actual is the actual of an enclosing instance, resolution
3920 -- was correct in the generic.
3922 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
3923 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
3925 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
3932 if Is_Wrapper_Package
(Inst
) then
3933 Inst
:= Related_Instance
(Inst
);
3938 (Specification
(Unit_Declaration_Node
(Inst
)));
3940 -- Generic actual has the same name as the corresponding formal
3942 Typ
:= First_Entity
(Gen
);
3943 while Present
(Typ
) loop
3944 if Chars
(Typ
) = Chars
(T
) then
3953 end Corresponding_Generic_Type
;
3955 --------------------
3956 -- Current_Entity --
3957 --------------------
3959 -- The currently visible definition for a given identifier is the
3960 -- one most chained at the start of the visibility chain, i.e. the
3961 -- one that is referenced by the Node_Id value of the name of the
3962 -- given identifier.
3964 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
3966 return Get_Name_Entity_Id
(Chars
(N
));
3969 -----------------------------
3970 -- Current_Entity_In_Scope --
3971 -----------------------------
3973 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
3975 CS
: constant Entity_Id
:= Current_Scope
;
3977 Transient_Case
: constant Boolean := Scope_Is_Transient
;
3980 E
:= Get_Name_Entity_Id
(Chars
(N
));
3982 and then Scope
(E
) /= CS
3983 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
3989 end Current_Entity_In_Scope
;
3995 function Current_Scope
return Entity_Id
is
3997 if Scope_Stack
.Last
= -1 then
3998 return Standard_Standard
;
4001 C
: constant Entity_Id
:=
4002 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
4007 return Standard_Standard
;
4013 ------------------------
4014 -- Current_Subprogram --
4015 ------------------------
4017 function Current_Subprogram
return Entity_Id
is
4018 Scop
: constant Entity_Id
:= Current_Scope
;
4020 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
4023 return Enclosing_Subprogram
(Scop
);
4025 end Current_Subprogram
;
4027 ----------------------------------
4028 -- Deepest_Type_Access_Level --
4029 ----------------------------------
4031 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
4033 if Ekind
(Typ
) = E_Anonymous_Access_Type
4034 and then not Is_Local_Anonymous_Access
(Typ
)
4035 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
4037 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4041 Scope_Depth
(Enclosing_Dynamic_Scope
4042 (Defining_Identifier
4043 (Associated_Node_For_Itype
(Typ
))));
4045 -- For generic formal type, return Int'Last (infinite).
4046 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4048 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
4049 return UI_From_Int
(Int
'Last);
4052 return Type_Access_Level
(Typ
);
4054 end Deepest_Type_Access_Level
;
4056 ---------------------
4057 -- Defining_Entity --
4058 ---------------------
4060 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4061 K
: constant Node_Kind
:= Nkind
(N
);
4062 Err
: Entity_Id
:= Empty
;
4067 N_Subprogram_Declaration |
4068 N_Abstract_Subprogram_Declaration |
4070 N_Package_Declaration |
4071 N_Subprogram_Renaming_Declaration |
4072 N_Subprogram_Body_Stub |
4073 N_Generic_Subprogram_Declaration |
4074 N_Generic_Package_Declaration |
4075 N_Formal_Subprogram_Declaration |
4076 N_Expression_Function
4078 return Defining_Entity
(Specification
(N
));
4081 N_Component_Declaration |
4082 N_Defining_Program_Unit_Name |
4083 N_Discriminant_Specification |
4085 N_Entry_Declaration |
4086 N_Entry_Index_Specification |
4087 N_Exception_Declaration |
4088 N_Exception_Renaming_Declaration |
4089 N_Formal_Object_Declaration |
4090 N_Formal_Package_Declaration |
4091 N_Formal_Type_Declaration |
4092 N_Full_Type_Declaration |
4093 N_Implicit_Label_Declaration |
4094 N_Incomplete_Type_Declaration |
4095 N_Loop_Parameter_Specification |
4096 N_Number_Declaration |
4097 N_Object_Declaration |
4098 N_Object_Renaming_Declaration |
4099 N_Package_Body_Stub |
4100 N_Parameter_Specification |
4101 N_Private_Extension_Declaration |
4102 N_Private_Type_Declaration |
4104 N_Protected_Body_Stub |
4105 N_Protected_Type_Declaration |
4106 N_Single_Protected_Declaration |
4107 N_Single_Task_Declaration |
4108 N_Subtype_Declaration |
4111 N_Task_Type_Declaration
4113 return Defining_Identifier
(N
);
4116 return Defining_Entity
(Proper_Body
(N
));
4119 N_Function_Instantiation |
4120 N_Function_Specification |
4121 N_Generic_Function_Renaming_Declaration |
4122 N_Generic_Package_Renaming_Declaration |
4123 N_Generic_Procedure_Renaming_Declaration |
4125 N_Package_Instantiation |
4126 N_Package_Renaming_Declaration |
4127 N_Package_Specification |
4128 N_Procedure_Instantiation |
4129 N_Procedure_Specification
4132 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
4135 if Nkind
(Nam
) in N_Entity
then
4138 -- For Error, make up a name and attach to declaration
4139 -- so we can continue semantic analysis
4141 elsif Nam
= Error
then
4142 Err
:= Make_Temporary
(Sloc
(N
), 'T');
4143 Set_Defining_Unit_Name
(N
, Err
);
4147 -- If not an entity, get defining identifier
4150 return Defining_Identifier
(Nam
);
4154 when N_Block_Statement
=>
4155 return Entity
(Identifier
(N
));
4158 raise Program_Error
;
4161 end Defining_Entity
;
4163 --------------------------
4164 -- Denotes_Discriminant --
4165 --------------------------
4167 function Denotes_Discriminant
4169 Check_Concurrent
: Boolean := False) return Boolean
4173 if not Is_Entity_Name
(N
)
4174 or else No
(Entity
(N
))
4181 -- If we are checking for a protected type, the discriminant may have
4182 -- been rewritten as the corresponding discriminal of the original type
4183 -- or of the corresponding concurrent record, depending on whether we
4184 -- are in the spec or body of the protected type.
4186 return Ekind
(E
) = E_Discriminant
4189 and then Ekind
(E
) = E_In_Parameter
4190 and then Present
(Discriminal_Link
(E
))
4192 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
4194 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
4196 end Denotes_Discriminant
;
4198 -------------------------
4199 -- Denotes_Same_Object --
4200 -------------------------
4202 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
4203 Obj1
: Node_Id
:= A1
;
4204 Obj2
: Node_Id
:= A2
;
4206 function Has_Prefix
(N
: Node_Id
) return Boolean;
4207 -- Return True if N has attribute Prefix
4209 function Is_Renaming
(N
: Node_Id
) return Boolean;
4210 -- Return true if N names a renaming entity
4212 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
4213 -- For renamings, return False if the prefix of any dereference within
4214 -- the renamed object_name is a variable, or any expression within the
4215 -- renamed object_name contains references to variables or calls on
4216 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4222 function Has_Prefix
(N
: Node_Id
) return Boolean is
4226 N_Attribute_Reference
,
4228 N_Explicit_Dereference
,
4229 N_Indexed_Component
,
4231 N_Selected_Component
,
4239 function Is_Renaming
(N
: Node_Id
) return Boolean is
4241 return Is_Entity_Name
(N
)
4242 and then Present
(Renamed_Entity
(Entity
(N
)));
4245 -----------------------
4246 -- Is_Valid_Renaming --
4247 -----------------------
4249 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
4251 function Check_Renaming
(N
: Node_Id
) return Boolean;
4252 -- Recursive function used to traverse all the prefixes of N
4254 function Check_Renaming
(N
: Node_Id
) return Boolean is
4257 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
4262 if Nkind
(N
) = N_Indexed_Component
then
4267 Indx
:= First
(Expressions
(N
));
4268 while Present
(Indx
) loop
4269 if not Is_OK_Static_Expression
(Indx
) then
4278 if Has_Prefix
(N
) then
4280 P
: constant Node_Id
:= Prefix
(N
);
4283 if Nkind
(N
) = N_Explicit_Dereference
4284 and then Is_Variable
(P
)
4288 elsif Is_Entity_Name
(P
)
4289 and then Ekind
(Entity
(P
)) = E_Function
4293 elsif Nkind
(P
) = N_Function_Call
then
4297 -- Recursion to continue traversing the prefix of the
4298 -- renaming expression
4300 return Check_Renaming
(P
);
4307 -- Start of processing for Is_Valid_Renaming
4310 return Check_Renaming
(N
);
4311 end Is_Valid_Renaming
;
4313 -- Start of processing for Denotes_Same_Object
4316 -- Both names statically denote the same stand-alone object or parameter
4317 -- (RM 6.4.1(6.5/3))
4319 if Is_Entity_Name
(Obj1
)
4320 and then Is_Entity_Name
(Obj2
)
4321 and then Entity
(Obj1
) = Entity
(Obj2
)
4326 -- For renamings, the prefix of any dereference within the renamed
4327 -- object_name is not a variable, and any expression within the
4328 -- renamed object_name contains no references to variables nor
4329 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4331 if Is_Renaming
(Obj1
) then
4332 if Is_Valid_Renaming
(Obj1
) then
4333 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
4339 if Is_Renaming
(Obj2
) then
4340 if Is_Valid_Renaming
(Obj2
) then
4341 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
4347 -- No match if not same node kind (such cases are handled by
4348 -- Denotes_Same_Prefix)
4350 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
4353 -- After handling valid renamings, one of the two names statically
4354 -- denoted a renaming declaration whose renamed object_name is known
4355 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4357 elsif Is_Entity_Name
(Obj1
) then
4358 if Is_Entity_Name
(Obj2
) then
4359 return Entity
(Obj1
) = Entity
(Obj2
);
4364 -- Both names are selected_components, their prefixes are known to
4365 -- denote the same object, and their selector_names denote the same
4366 -- component (RM 6.4.1(6.6/3)
4368 elsif Nkind
(Obj1
) = N_Selected_Component
then
4369 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4371 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
4373 -- Both names are dereferences and the dereferenced names are known to
4374 -- denote the same object (RM 6.4.1(6.7/3))
4376 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
4377 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
4379 -- Both names are indexed_components, their prefixes are known to denote
4380 -- the same object, and each of the pairs of corresponding index values
4381 -- are either both static expressions with the same static value or both
4382 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4384 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4385 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4393 Indx1
:= First
(Expressions
(Obj1
));
4394 Indx2
:= First
(Expressions
(Obj2
));
4395 while Present
(Indx1
) loop
4397 -- Indexes must denote the same static value or same object
4399 if Is_OK_Static_Expression
(Indx1
) then
4400 if not Is_OK_Static_Expression
(Indx2
) then
4403 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4407 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4419 -- Both names are slices, their prefixes are known to denote the same
4420 -- object, and the two slices have statically matching index constraints
4421 -- (RM 6.4.1(6.9/3))
4423 elsif Nkind
(Obj1
) = N_Slice
4424 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4427 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4430 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4431 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4433 -- Check whether bounds are statically identical. There is no
4434 -- attempt to detect partial overlap of slices.
4436 return Denotes_Same_Object
(Lo1
, Lo2
)
4437 and then Denotes_Same_Object
(Hi1
, Hi2
);
4440 -- In the recursion, literals appear as indexes.
4442 elsif Nkind
(Obj1
) = N_Integer_Literal
4443 and then Nkind
(Obj2
) = N_Integer_Literal
4445 return Intval
(Obj1
) = Intval
(Obj2
);
4450 end Denotes_Same_Object
;
4452 -------------------------
4453 -- Denotes_Same_Prefix --
4454 -------------------------
4456 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
4459 if Is_Entity_Name
(A1
) then
4460 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
4461 and then not Is_Access_Type
(Etype
(A1
))
4463 return Denotes_Same_Object
(A1
, Prefix
(A2
))
4464 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
4469 elsif Is_Entity_Name
(A2
) then
4470 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
4472 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4474 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4477 Root1
, Root2
: Node_Id
;
4478 Depth1
, Depth2
: Int
:= 0;
4481 Root1
:= Prefix
(A1
);
4482 while not Is_Entity_Name
(Root1
) loop
4484 (Root1
, N_Selected_Component
, N_Indexed_Component
)
4488 Root1
:= Prefix
(Root1
);
4491 Depth1
:= Depth1
+ 1;
4494 Root2
:= Prefix
(A2
);
4495 while not Is_Entity_Name
(Root2
) loop
4497 (Root2
, N_Selected_Component
, N_Indexed_Component
)
4501 Root2
:= Prefix
(Root2
);
4504 Depth2
:= Depth2
+ 1;
4507 -- If both have the same depth and they do not denote the same
4508 -- object, they are disjoint and no warning is needed.
4510 if Depth1
= Depth2
then
4513 elsif Depth1
> Depth2
then
4514 Root1
:= Prefix
(A1
);
4515 for I
in 1 .. Depth1
- Depth2
- 1 loop
4516 Root1
:= Prefix
(Root1
);
4519 return Denotes_Same_Object
(Root1
, A2
);
4522 Root2
:= Prefix
(A2
);
4523 for I
in 1 .. Depth2
- Depth1
- 1 loop
4524 Root2
:= Prefix
(Root2
);
4527 return Denotes_Same_Object
(A1
, Root2
);
4534 end Denotes_Same_Prefix
;
4536 ----------------------
4537 -- Denotes_Variable --
4538 ----------------------
4540 function Denotes_Variable
(N
: Node_Id
) return Boolean is
4542 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
4543 end Denotes_Variable
;
4545 -----------------------------
4546 -- Depends_On_Discriminant --
4547 -----------------------------
4549 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
4554 Get_Index_Bounds
(N
, L
, H
);
4555 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
4556 end Depends_On_Discriminant
;
4558 -------------------------
4559 -- Designate_Same_Unit --
4560 -------------------------
4562 function Designate_Same_Unit
4564 Name2
: Node_Id
) return Boolean
4566 K1
: constant Node_Kind
:= Nkind
(Name1
);
4567 K2
: constant Node_Kind
:= Nkind
(Name2
);
4569 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
4570 -- Returns the parent unit name node of a defining program unit name
4571 -- or the prefix if N is a selected component or an expanded name.
4573 function Select_Node
(N
: Node_Id
) return Node_Id
;
4574 -- Returns the defining identifier node of a defining program unit
4575 -- name or the selector node if N is a selected component or an
4582 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
4584 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4596 function Select_Node
(N
: Node_Id
) return Node_Id
is
4598 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4599 return Defining_Identifier
(N
);
4602 return Selector_Name
(N
);
4606 -- Start of processing for Designate_Next_Unit
4609 if (K1
= N_Identifier
or else
4610 K1
= N_Defining_Identifier
)
4612 (K2
= N_Identifier
or else
4613 K2
= N_Defining_Identifier
)
4615 return Chars
(Name1
) = Chars
(Name2
);
4618 (K1
= N_Expanded_Name
or else
4619 K1
= N_Selected_Component
or else
4620 K1
= N_Defining_Program_Unit_Name
)
4622 (K2
= N_Expanded_Name
or else
4623 K2
= N_Selected_Component
or else
4624 K2
= N_Defining_Program_Unit_Name
)
4627 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
4629 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
4634 end Designate_Same_Unit
;
4636 ------------------------------------------
4637 -- function Dynamic_Accessibility_Level --
4638 ------------------------------------------
4640 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
4642 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
4644 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
4645 -- Construct an integer literal representing an accessibility level
4646 -- with its type set to Natural.
4648 ------------------------
4649 -- Make_Level_Literal --
4650 ------------------------
4652 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
4653 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
4655 Set_Etype
(Result
, Standard_Natural
);
4657 end Make_Level_Literal
;
4659 -- Start of processing for Dynamic_Accessibility_Level
4662 if Is_Entity_Name
(Expr
) then
4665 if Present
(Renamed_Object
(E
)) then
4666 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
4669 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
4670 if Present
(Extra_Accessibility
(E
)) then
4671 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
4676 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4678 case Nkind
(Expr
) is
4680 -- For access discriminant, the level of the enclosing object
4682 when N_Selected_Component
=>
4683 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
4684 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
4685 E_Anonymous_Access_Type
4687 return Make_Level_Literal
(Object_Access_Level
(Expr
));
4690 when N_Attribute_Reference
=>
4691 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
4693 -- For X'Access, the level of the prefix X
4695 when Attribute_Access
=>
4696 return Make_Level_Literal
4697 (Object_Access_Level
(Prefix
(Expr
)));
4699 -- Treat the unchecked attributes as library-level
4701 when Attribute_Unchecked_Access |
4702 Attribute_Unrestricted_Access
=>
4703 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
4705 -- No other access-valued attributes
4708 raise Program_Error
;
4713 -- Unimplemented: depends on context. As an actual parameter where
4714 -- formal type is anonymous, use
4715 -- Scope_Depth (Current_Scope) + 1.
4716 -- For other cases, see 3.10.2(14/3) and following. ???
4720 when N_Type_Conversion
=>
4721 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
4723 -- Handle type conversions introduced for a rename of an
4724 -- Ada 2012 stand-alone object of an anonymous access type.
4726 return Dynamic_Accessibility_Level
(Expression
(Expr
));
4733 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
4734 end Dynamic_Accessibility_Level
;
4736 -----------------------------------
4737 -- Effective_Extra_Accessibility --
4738 -----------------------------------
4740 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
4742 if Present
(Renamed_Object
(Id
))
4743 and then Is_Entity_Name
(Renamed_Object
(Id
))
4745 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
4747 return Extra_Accessibility
(Id
);
4749 end Effective_Extra_Accessibility
;
4751 -----------------------------
4752 -- Effective_Reads_Enabled --
4753 -----------------------------
4755 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
4757 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
4758 end Effective_Reads_Enabled
;
4760 ------------------------------
4761 -- Effective_Writes_Enabled --
4762 ------------------------------
4764 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
4766 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
4767 end Effective_Writes_Enabled
;
4769 ------------------------------
4770 -- Enclosing_Comp_Unit_Node --
4771 ------------------------------
4773 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
4774 Current_Node
: Node_Id
;
4778 while Present
(Current_Node
)
4779 and then Nkind
(Current_Node
) /= N_Compilation_Unit
4781 Current_Node
:= Parent
(Current_Node
);
4784 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
4787 return Current_Node
;
4789 end Enclosing_Comp_Unit_Node
;
4791 --------------------------
4792 -- Enclosing_CPP_Parent --
4793 --------------------------
4795 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
4796 Parent_Typ
: Entity_Id
:= Typ
;
4799 while not Is_CPP_Class
(Parent_Typ
)
4800 and then Etype
(Parent_Typ
) /= Parent_Typ
4802 Parent_Typ
:= Etype
(Parent_Typ
);
4804 if Is_Private_Type
(Parent_Typ
) then
4805 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4809 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
4811 end Enclosing_CPP_Parent
;
4813 ----------------------------
4814 -- Enclosing_Generic_Body --
4815 ----------------------------
4817 function Enclosing_Generic_Body
4818 (N
: Node_Id
) return Node_Id
4826 while Present
(P
) loop
4827 if Nkind
(P
) = N_Package_Body
4828 or else Nkind
(P
) = N_Subprogram_Body
4830 Spec
:= Corresponding_Spec
(P
);
4832 if Present
(Spec
) then
4833 Decl
:= Unit_Declaration_Node
(Spec
);
4835 if Nkind
(Decl
) = N_Generic_Package_Declaration
4836 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4847 end Enclosing_Generic_Body
;
4849 ----------------------------
4850 -- Enclosing_Generic_Unit --
4851 ----------------------------
4853 function Enclosing_Generic_Unit
4854 (N
: Node_Id
) return Node_Id
4862 while Present
(P
) loop
4863 if Nkind
(P
) = N_Generic_Package_Declaration
4864 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
4868 elsif Nkind
(P
) = N_Package_Body
4869 or else Nkind
(P
) = N_Subprogram_Body
4871 Spec
:= Corresponding_Spec
(P
);
4873 if Present
(Spec
) then
4874 Decl
:= Unit_Declaration_Node
(Spec
);
4876 if Nkind
(Decl
) = N_Generic_Package_Declaration
4877 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4888 end Enclosing_Generic_Unit
;
4890 -------------------------------
4891 -- Enclosing_Lib_Unit_Entity --
4892 -------------------------------
4894 function Enclosing_Lib_Unit_Entity
4895 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
4897 Unit_Entity
: Entity_Id
;
4900 -- Look for enclosing library unit entity by following scope links.
4901 -- Equivalent to, but faster than indexing through the scope stack.
4904 while (Present
(Scope
(Unit_Entity
))
4905 and then Scope
(Unit_Entity
) /= Standard_Standard
)
4906 and not Is_Child_Unit
(Unit_Entity
)
4908 Unit_Entity
:= Scope
(Unit_Entity
);
4912 end Enclosing_Lib_Unit_Entity
;
4914 -----------------------
4915 -- Enclosing_Package --
4916 -----------------------
4918 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
4919 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4922 if Dynamic_Scope
= Standard_Standard
then
4923 return Standard_Standard
;
4925 elsif Dynamic_Scope
= Empty
then
4928 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
4931 return Dynamic_Scope
;
4934 return Enclosing_Package
(Dynamic_Scope
);
4936 end Enclosing_Package
;
4938 --------------------------
4939 -- Enclosing_Subprogram --
4940 --------------------------
4942 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
4943 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4946 if Dynamic_Scope
= Standard_Standard
then
4949 elsif Dynamic_Scope
= Empty
then
4952 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
4953 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
4955 elsif Ekind
(Dynamic_Scope
) = E_Block
4956 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
4958 return Enclosing_Subprogram
(Dynamic_Scope
);
4960 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
4961 return Get_Task_Body_Procedure
(Dynamic_Scope
);
4963 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
4964 and then Present
(Full_View
(Dynamic_Scope
))
4965 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
4967 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
4969 -- No body is generated if the protected operation is eliminated
4971 elsif Convention
(Dynamic_Scope
) = Convention_Protected
4972 and then not Is_Eliminated
(Dynamic_Scope
)
4973 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
4975 return Protected_Body_Subprogram
(Dynamic_Scope
);
4978 return Dynamic_Scope
;
4980 end Enclosing_Subprogram
;
4982 ------------------------
4983 -- Ensure_Freeze_Node --
4984 ------------------------
4986 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
4989 if No
(Freeze_Node
(E
)) then
4990 FN
:= Make_Freeze_Entity
(Sloc
(E
));
4991 Set_Has_Delayed_Freeze
(E
);
4992 Set_Freeze_Node
(E
, FN
);
4993 Set_Access_Types_To_Process
(FN
, No_Elist
);
4994 Set_TSS_Elist
(FN
, No_Elist
);
4997 end Ensure_Freeze_Node
;
5003 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5004 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5005 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5006 S
: constant Entity_Id
:= Current_Scope
;
5009 Generate_Definition
(Def_Id
);
5011 -- Add new name to current scope declarations. Check for duplicate
5012 -- declaration, which may or may not be a genuine error.
5016 -- Case of previous entity entered because of a missing declaration
5017 -- or else a bad subtype indication. Best is to use the new entity,
5018 -- and make the previous one invisible.
5020 if Etype
(E
) = Any_Type
then
5021 Set_Is_Immediately_Visible
(E
, False);
5023 -- Case of renaming declaration constructed for package instances.
5024 -- if there is an explicit declaration with the same identifier,
5025 -- the renaming is not immediately visible any longer, but remains
5026 -- visible through selected component notation.
5028 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
5029 and then not Comes_From_Source
(E
)
5031 Set_Is_Immediately_Visible
(E
, False);
5033 -- The new entity may be the package renaming, which has the same
5034 -- same name as a generic formal which has been seen already.
5036 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
5037 and then not Comes_From_Source
(Def_Id
)
5039 Set_Is_Immediately_Visible
(E
, False);
5041 -- For a fat pointer corresponding to a remote access to subprogram,
5042 -- we use the same identifier as the RAS type, so that the proper
5043 -- name appears in the stub. This type is only retrieved through
5044 -- the RAS type and never by visibility, and is not added to the
5045 -- visibility list (see below).
5047 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
5048 and then Present
(Corresponding_Remote_Type
(Def_Id
))
5052 -- Case of an implicit operation or derived literal. The new entity
5053 -- hides the implicit one, which is removed from all visibility,
5054 -- i.e. the entity list of its scope, and homonym chain of its name.
5056 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
5057 or else Is_Internal
(E
)
5061 Prev_Vis
: Entity_Id
;
5062 Decl
: constant Node_Id
:= Parent
(E
);
5065 -- If E is an implicit declaration, it cannot be the first
5066 -- entity in the scope.
5068 Prev
:= First_Entity
(Current_Scope
);
5069 while Present
(Prev
)
5070 and then Next_Entity
(Prev
) /= E
5077 -- If E is not on the entity chain of the current scope,
5078 -- it is an implicit declaration in the generic formal
5079 -- part of a generic subprogram. When analyzing the body,
5080 -- the generic formals are visible but not on the entity
5081 -- chain of the subprogram. The new entity will become
5082 -- the visible one in the body.
5085 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
5089 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5091 if No
(Next_Entity
(Prev
)) then
5092 Set_Last_Entity
(Current_Scope
, Prev
);
5095 if E
= Current_Entity
(E
) then
5099 Prev_Vis
:= Current_Entity
(E
);
5100 while Homonym
(Prev_Vis
) /= E
loop
5101 Prev_Vis
:= Homonym
(Prev_Vis
);
5105 if Present
(Prev_Vis
) then
5107 -- Skip E in the visibility chain
5109 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5112 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5117 -- This section of code could use a comment ???
5119 elsif Present
(Etype
(E
))
5120 and then Is_Concurrent_Type
(Etype
(E
))
5125 -- If the homograph is a protected component renaming, it should not
5126 -- be hiding the current entity. Such renamings are treated as weak
5129 elsif Is_Prival
(E
) then
5130 Set_Is_Immediately_Visible
(E
, False);
5132 -- In this case the current entity is a protected component renaming.
5133 -- Perform minimal decoration by setting the scope and return since
5134 -- the prival should not be hiding other visible entities.
5136 elsif Is_Prival
(Def_Id
) then
5137 Set_Scope
(Def_Id
, Current_Scope
);
5140 -- Analogous to privals, the discriminal generated for an entry index
5141 -- parameter acts as a weak declaration. Perform minimal decoration
5142 -- to avoid bogus errors.
5144 elsif Is_Discriminal
(Def_Id
)
5145 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
5147 Set_Scope
(Def_Id
, Current_Scope
);
5150 -- In the body or private part of an instance, a type extension may
5151 -- introduce a component with the same name as that of an actual. The
5152 -- legality rule is not enforced, but the semantics of the full type
5153 -- with two components of same name are not clear at this point???
5155 elsif In_Instance_Not_Visible
then
5158 -- When compiling a package body, some child units may have become
5159 -- visible. They cannot conflict with local entities that hide them.
5161 elsif Is_Child_Unit
(E
)
5162 and then In_Open_Scopes
(Scope
(E
))
5163 and then not Is_Immediately_Visible
(E
)
5167 -- Conversely, with front-end inlining we may compile the parent body
5168 -- first, and a child unit subsequently. The context is now the
5169 -- parent spec, and body entities are not visible.
5171 elsif Is_Child_Unit
(Def_Id
)
5172 and then Is_Package_Body_Entity
(E
)
5173 and then not In_Package_Body
(Current_Scope
)
5177 -- Case of genuine duplicate declaration
5180 Error_Msg_Sloc
:= Sloc
(E
);
5182 -- If the previous declaration is an incomplete type declaration
5183 -- this may be an attempt to complete it with a private type. The
5184 -- following avoids confusing cascaded errors.
5186 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
5187 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
5190 ("incomplete type cannot be completed with a private " &
5191 "declaration", Parent
(Def_Id
));
5192 Set_Is_Immediately_Visible
(E
, False);
5193 Set_Full_View
(E
, Def_Id
);
5195 -- An inherited component of a record conflicts with a new
5196 -- discriminant. The discriminant is inserted first in the scope,
5197 -- but the error should be posted on it, not on the component.
5199 elsif Ekind
(E
) = E_Discriminant
5200 and then Present
(Scope
(Def_Id
))
5201 and then Scope
(Def_Id
) /= Current_Scope
5203 Error_Msg_Sloc
:= Sloc
(Def_Id
);
5204 Error_Msg_N
("& conflicts with declaration#", E
);
5207 -- If the name of the unit appears in its own context clause, a
5208 -- dummy package with the name has already been created, and the
5209 -- error emitted. Try to continue quietly.
5211 elsif Error_Posted
(E
)
5212 and then Sloc
(E
) = No_Location
5213 and then Nkind
(Parent
(E
)) = N_Package_Specification
5214 and then Current_Scope
= Standard_Standard
5216 Set_Scope
(Def_Id
, Current_Scope
);
5220 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
5222 -- Avoid cascaded messages with duplicate components in
5225 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
5230 if Nkind
(Parent
(Parent
(Def_Id
))) =
5231 N_Generic_Subprogram_Declaration
5233 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
5235 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
5238 -- If entity is in standard, then we are in trouble, because it
5239 -- means that we have a library package with a duplicated name.
5240 -- That's hard to recover from, so abort.
5242 if S
= Standard_Standard
then
5243 raise Unrecoverable_Error
;
5245 -- Otherwise we continue with the declaration. Having two
5246 -- identical declarations should not cause us too much trouble.
5254 -- If we fall through, declaration is OK, at least OK enough to continue
5256 -- If Def_Id is a discriminant or a record component we are in the midst
5257 -- of inheriting components in a derived record definition. Preserve
5258 -- their Ekind and Etype.
5260 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
5263 -- If a type is already set, leave it alone (happens when a type
5264 -- declaration is reanalyzed following a call to the optimizer).
5266 elsif Present
(Etype
(Def_Id
)) then
5269 -- Otherwise, the kind E_Void insures that premature uses of the entity
5270 -- will be detected. Any_Type insures that no cascaded errors will occur
5273 Set_Ekind
(Def_Id
, E_Void
);
5274 Set_Etype
(Def_Id
, Any_Type
);
5277 -- Inherited discriminants and components in derived record types are
5278 -- immediately visible. Itypes are not.
5280 -- Unless the Itype is for a record type with a corresponding remote
5281 -- type (what is that about, it was not commented ???)
5283 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
5285 ((not Is_Record_Type
(Def_Id
)
5286 or else No
(Corresponding_Remote_Type
(Def_Id
)))
5287 and then not Is_Itype
(Def_Id
))
5289 Set_Is_Immediately_Visible
(Def_Id
);
5290 Set_Current_Entity
(Def_Id
);
5293 Set_Homonym
(Def_Id
, C
);
5294 Append_Entity
(Def_Id
, S
);
5295 Set_Public_Status
(Def_Id
);
5297 -- Declaring a homonym is not allowed in SPARK ...
5300 and then Restriction_Check_Required
(SPARK_05
)
5303 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
5304 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
5305 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
5308 -- ... unless the new declaration is in a subprogram, and the
5309 -- visible declaration is a variable declaration or a parameter
5310 -- specification outside that subprogram.
5312 if Present
(Enclosing_Subp
)
5313 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
5314 N_Parameter_Specification
)
5315 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
5319 -- ... or the new declaration is in a package, and the visible
5320 -- declaration occurs outside that package.
5322 elsif Present
(Enclosing_Pack
)
5323 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
5327 -- ... or the new declaration is a component declaration in a
5328 -- record type definition.
5330 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
5333 -- Don't issue error for non-source entities
5335 elsif Comes_From_Source
(Def_Id
)
5336 and then Comes_From_Source
(C
)
5338 Error_Msg_Sloc
:= Sloc
(C
);
5339 Check_SPARK_Restriction
5340 ("redeclaration of identifier &#", Def_Id
);
5345 -- Warn if new entity hides an old one
5347 if Warn_On_Hiding
and then Present
(C
)
5349 -- Don't warn for record components since they always have a well
5350 -- defined scope which does not confuse other uses. Note that in
5351 -- some cases, Ekind has not been set yet.
5353 and then Ekind
(C
) /= E_Component
5354 and then Ekind
(C
) /= E_Discriminant
5355 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
5356 and then Ekind
(Def_Id
) /= E_Component
5357 and then Ekind
(Def_Id
) /= E_Discriminant
5358 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
5360 -- Don't warn for one character variables. It is too common to use
5361 -- such variables as locals and will just cause too many false hits.
5363 and then Length_Of_Name
(Chars
(C
)) /= 1
5365 -- Don't warn for non-source entities
5367 and then Comes_From_Source
(C
)
5368 and then Comes_From_Source
(Def_Id
)
5370 -- Don't warn unless entity in question is in extended main source
5372 and then In_Extended_Main_Source_Unit
(Def_Id
)
5374 -- Finally, the hidden entity must be either immediately visible or
5375 -- use visible (i.e. from a used package).
5378 (Is_Immediately_Visible
(C
)
5380 Is_Potentially_Use_Visible
(C
))
5382 Error_Msg_Sloc
:= Sloc
(C
);
5383 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
5391 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
5397 if Is_Entity_Name
(N
) then
5400 -- Follow a possible chain of renamings to reach the root renamed
5403 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5404 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5405 Id
:= Entity
(Renamed_Object
(Id
));
5416 --------------------------
5417 -- Explain_Limited_Type --
5418 --------------------------
5420 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5424 -- For array, component type must be limited
5426 if Is_Array_Type
(T
) then
5427 Error_Msg_Node_2
:= T
;
5429 ("\component type& of type& is limited", N
, Component_Type
(T
));
5430 Explain_Limited_Type
(Component_Type
(T
), N
);
5432 elsif Is_Record_Type
(T
) then
5434 -- No need for extra messages if explicit limited record
5436 if Is_Limited_Record
(Base_Type
(T
)) then
5440 -- Otherwise find a limited component. Check only components that
5441 -- come from source, or inherited components that appear in the
5442 -- source of the ancestor.
5444 C
:= First_Component
(T
);
5445 while Present
(C
) loop
5446 if Is_Limited_Type
(Etype
(C
))
5448 (Comes_From_Source
(C
)
5450 (Present
(Original_Record_Component
(C
))
5452 Comes_From_Source
(Original_Record_Component
(C
))))
5454 Error_Msg_Node_2
:= T
;
5455 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
5456 Explain_Limited_Type
(Etype
(C
), N
);
5463 -- The type may be declared explicitly limited, even if no component
5464 -- of it is limited, in which case we fall out of the loop.
5467 end Explain_Limited_Type
;
5473 procedure Find_Actual
5475 Formal
: out Entity_Id
;
5478 Parnt
: constant Node_Id
:= Parent
(N
);
5482 if (Nkind
(Parnt
) = N_Indexed_Component
5484 Nkind
(Parnt
) = N_Selected_Component
)
5485 and then N
= Prefix
(Parnt
)
5487 Find_Actual
(Parnt
, Formal
, Call
);
5490 elsif Nkind
(Parnt
) = N_Parameter_Association
5491 and then N
= Explicit_Actual_Parameter
(Parnt
)
5493 Call
:= Parent
(Parnt
);
5495 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
5504 -- If we have a call to a subprogram look for the parameter. Note that
5505 -- we exclude overloaded calls, since we don't know enough to be sure
5506 -- of giving the right answer in this case.
5508 if Nkind_In
(Call
, N_Function_Call
, N_Procedure_Call_Statement
)
5509 and then Is_Entity_Name
(Name
(Call
))
5510 and then Present
(Entity
(Name
(Call
)))
5511 and then Is_Overloadable
(Entity
(Name
(Call
)))
5512 and then not Is_Overloaded
(Name
(Call
))
5514 -- Fall here if we are definitely a parameter
5516 Actual
:= First_Actual
(Call
);
5517 Formal
:= First_Formal
(Entity
(Name
(Call
)));
5518 while Present
(Formal
) and then Present
(Actual
) loop
5522 Actual
:= Next_Actual
(Actual
);
5523 Formal
:= Next_Formal
(Formal
);
5528 -- Fall through here if we did not find matching actual
5534 ---------------------------
5535 -- Find_Body_Discriminal --
5536 ---------------------------
5538 function Find_Body_Discriminal
5539 (Spec_Discriminant
: Entity_Id
) return Entity_Id
5545 -- If expansion is suppressed, then the scope can be the concurrent type
5546 -- itself rather than a corresponding concurrent record type.
5548 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
5549 Tsk
:= Scope
(Spec_Discriminant
);
5552 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
5554 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
5557 -- Find discriminant of original concurrent type, and use its current
5558 -- discriminal, which is the renaming within the task/protected body.
5560 Disc
:= First_Discriminant
(Tsk
);
5561 while Present
(Disc
) loop
5562 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
5563 return Discriminal
(Disc
);
5566 Next_Discriminant
(Disc
);
5569 -- That loop should always succeed in finding a matching entry and
5570 -- returning. Fatal error if not.
5572 raise Program_Error
;
5573 end Find_Body_Discriminal
;
5575 -------------------------------------
5576 -- Find_Corresponding_Discriminant --
5577 -------------------------------------
5579 function Find_Corresponding_Discriminant
5581 Typ
: Entity_Id
) return Entity_Id
5583 Par_Disc
: Entity_Id
;
5584 Old_Disc
: Entity_Id
;
5585 New_Disc
: Entity_Id
;
5588 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
5590 -- The original type may currently be private, and the discriminant
5591 -- only appear on its full view.
5593 if Is_Private_Type
(Scope
(Par_Disc
))
5594 and then not Has_Discriminants
(Scope
(Par_Disc
))
5595 and then Present
(Full_View
(Scope
(Par_Disc
)))
5597 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
5599 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
5602 if Is_Class_Wide_Type
(Typ
) then
5603 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
5605 New_Disc
:= First_Discriminant
(Typ
);
5608 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
5609 if Old_Disc
= Par_Disc
then
5612 Next_Discriminant
(Old_Disc
);
5613 Next_Discriminant
(New_Disc
);
5617 -- Should always find it
5619 raise Program_Error
;
5620 end Find_Corresponding_Discriminant
;
5622 ----------------------------------
5623 -- Find_Enclosing_Iterator_Loop --
5624 ----------------------------------
5626 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
5631 -- Traverse the scope chain looking for an iterator loop. Such loops are
5632 -- usually transformed into blocks, hence the use of Original_Node.
5635 while Present
(S
) and then S
/= Standard_Standard
loop
5636 if Ekind
(S
) = E_Loop
5637 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
5639 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
5641 if Nkind
(Constr
) = N_Loop_Statement
5642 and then Present
(Iteration_Scheme
(Constr
))
5643 and then Nkind
(Iterator_Specification
5644 (Iteration_Scheme
(Constr
))) =
5645 N_Iterator_Specification
5655 end Find_Enclosing_Iterator_Loop
;
5657 ------------------------------------
5658 -- Find_Loop_In_Conditional_Block --
5659 ------------------------------------
5661 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
5667 if Nkind
(Stmt
) = N_If_Statement
then
5668 Stmt
:= First
(Then_Statements
(Stmt
));
5671 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
5673 -- Inspect the statements of the conditional block. In general the loop
5674 -- should be the first statement in the statement sequence of the block,
5675 -- but the finalization machinery may have introduced extra object
5678 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
5679 while Present
(Stmt
) loop
5680 if Nkind
(Stmt
) = N_Loop_Statement
then
5687 -- The expansion of attribute 'Loop_Entry produced a malformed block
5689 raise Program_Error
;
5690 end Find_Loop_In_Conditional_Block
;
5692 --------------------------
5693 -- Find_Overlaid_Entity --
5694 --------------------------
5696 procedure Find_Overlaid_Entity
5698 Ent
: out Entity_Id
;
5704 -- We are looking for one of the two following forms:
5706 -- for X'Address use Y'Address
5710 -- Const : constant Address := expr;
5712 -- for X'Address use Const;
5714 -- In the second case, the expr is either Y'Address, or recursively a
5715 -- constant that eventually references Y'Address.
5720 if Nkind
(N
) = N_Attribute_Definition_Clause
5721 and then Chars
(N
) = Name_Address
5723 Expr
:= Expression
(N
);
5725 -- This loop checks the form of the expression for Y'Address,
5726 -- using recursion to deal with intermediate constants.
5729 -- Check for Y'Address
5731 if Nkind
(Expr
) = N_Attribute_Reference
5732 and then Attribute_Name
(Expr
) = Name_Address
5734 Expr
:= Prefix
(Expr
);
5737 -- Check for Const where Const is a constant entity
5739 elsif Is_Entity_Name
(Expr
)
5740 and then Ekind
(Entity
(Expr
)) = E_Constant
5742 Expr
:= Constant_Value
(Entity
(Expr
));
5744 -- Anything else does not need checking
5751 -- This loop checks the form of the prefix for an entity, using
5752 -- recursion to deal with intermediate components.
5755 -- Check for Y where Y is an entity
5757 if Is_Entity_Name
(Expr
) then
5758 Ent
:= Entity
(Expr
);
5761 -- Check for components
5764 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
5766 Expr
:= Prefix
(Expr
);
5769 -- Anything else does not need checking
5776 end Find_Overlaid_Entity
;
5778 -------------------------
5779 -- Find_Parameter_Type --
5780 -------------------------
5782 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
5784 if Nkind
(Param
) /= N_Parameter_Specification
then
5787 -- For an access parameter, obtain the type from the formal entity
5788 -- itself, because access to subprogram nodes do not carry a type.
5789 -- Shouldn't we always use the formal entity ???
5791 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
5792 return Etype
(Defining_Identifier
(Param
));
5795 return Etype
(Parameter_Type
(Param
));
5797 end Find_Parameter_Type
;
5799 -----------------------------------
5800 -- Find_Placement_In_State_Space --
5801 -----------------------------------
5803 procedure Find_Placement_In_State_Space
5804 (Item_Id
: Entity_Id
;
5805 Placement
: out State_Space_Kind
;
5806 Pack_Id
: out Entity_Id
)
5808 Context
: Entity_Id
;
5811 -- Assume that the item does not appear in the state space of a package
5813 Placement
:= Not_In_Package
;
5816 -- Climb the scope stack and examine the enclosing context
5818 Context
:= Scope
(Item_Id
);
5819 while Present
(Context
) and then Context
/= Standard_Standard
loop
5820 if Ekind
(Context
) = E_Package
then
5823 -- A package body is a cut off point for the traversal as the item
5824 -- cannot be visible to the outside from this point on. Note that
5825 -- this test must be done first as a body is also classified as a
5828 if In_Package_Body
(Context
) then
5829 Placement
:= Body_State_Space
;
5832 -- The private part of a package is a cut off point for the
5833 -- traversal as the item cannot be visible to the outside from
5836 elsif In_Private_Part
(Context
) then
5837 Placement
:= Private_State_Space
;
5840 -- When the item appears in the visible state space of a package,
5841 -- continue to climb the scope stack as this may not be the final
5845 Placement
:= Visible_State_Space
;
5847 -- The visible state space of a child unit acts as the proper
5848 -- placement of an item.
5850 if Is_Child_Unit
(Context
) then
5855 -- The item or its enclosing package appear in a construct that has
5859 Placement
:= Not_In_Package
;
5863 Context
:= Scope
(Context
);
5865 end Find_Placement_In_State_Space
;
5867 -----------------------------
5868 -- Find_Static_Alternative --
5869 -----------------------------
5871 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
5872 Expr
: constant Node_Id
:= Expression
(N
);
5873 Val
: constant Uint
:= Expr_Value
(Expr
);
5878 Alt
:= First
(Alternatives
(N
));
5881 if Nkind
(Alt
) /= N_Pragma
then
5882 Choice
:= First
(Discrete_Choices
(Alt
));
5883 while Present
(Choice
) loop
5885 -- Others choice, always matches
5887 if Nkind
(Choice
) = N_Others_Choice
then
5890 -- Range, check if value is in the range
5892 elsif Nkind
(Choice
) = N_Range
then
5894 Val
>= Expr_Value
(Low_Bound
(Choice
))
5896 Val
<= Expr_Value
(High_Bound
(Choice
));
5898 -- Choice is a subtype name. Note that we know it must
5899 -- be a static subtype, since otherwise it would have
5900 -- been diagnosed as illegal.
5902 elsif Is_Entity_Name
(Choice
)
5903 and then Is_Type
(Entity
(Choice
))
5905 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
5906 Assume_Valid
=> False);
5908 -- Choice is a subtype indication
5910 elsif Nkind
(Choice
) = N_Subtype_Indication
then
5912 C
: constant Node_Id
:= Constraint
(Choice
);
5913 R
: constant Node_Id
:= Range_Expression
(C
);
5917 Val
>= Expr_Value
(Low_Bound
(R
))
5919 Val
<= Expr_Value
(High_Bound
(R
));
5922 -- Choice is a simple expression
5925 exit Search
when Val
= Expr_Value
(Choice
);
5933 pragma Assert
(Present
(Alt
));
5936 -- The above loop *must* terminate by finding a match, since
5937 -- we know the case statement is valid, and the value of the
5938 -- expression is known at compile time. When we fall out of
5939 -- the loop, Alt points to the alternative that we know will
5940 -- be selected at run time.
5943 end Find_Static_Alternative
;
5949 function First_Actual
(Node
: Node_Id
) return Node_Id
is
5953 if No
(Parameter_Associations
(Node
)) then
5957 N
:= First
(Parameter_Associations
(Node
));
5959 if Nkind
(N
) = N_Parameter_Association
then
5960 return First_Named_Actual
(Node
);
5966 -----------------------
5967 -- Gather_Components --
5968 -----------------------
5970 procedure Gather_Components
5972 Comp_List
: Node_Id
;
5973 Governed_By
: List_Id
;
5975 Report_Errors
: out Boolean)
5979 Discrete_Choice
: Node_Id
;
5980 Comp_Item
: Node_Id
;
5982 Discrim
: Entity_Id
;
5983 Discrim_Name
: Node_Id
;
5984 Discrim_Value
: Node_Id
;
5987 Report_Errors
:= False;
5989 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
5992 elsif Present
(Component_Items
(Comp_List
)) then
5993 Comp_Item
:= First
(Component_Items
(Comp_List
));
5999 while Present
(Comp_Item
) loop
6001 -- Skip the tag of a tagged record, the interface tags, as well
6002 -- as all items that are not user components (anonymous types,
6003 -- rep clauses, Parent field, controller field).
6005 if Nkind
(Comp_Item
) = N_Component_Declaration
then
6007 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
6009 if not Is_Tag
(Comp
)
6010 and then Chars
(Comp
) /= Name_uParent
6012 Append_Elmt
(Comp
, Into
);
6020 if No
(Variant_Part
(Comp_List
)) then
6023 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
6024 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
6027 -- Look for the discriminant that governs this variant part.
6028 -- The discriminant *must* be in the Governed_By List
6030 Assoc
:= First
(Governed_By
);
6031 Find_Constraint
: loop
6032 Discrim
:= First
(Choices
(Assoc
));
6033 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
6034 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
6036 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
6037 Chars
(Discrim_Name
))
6038 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
6039 = Chars
(Discrim_Name
);
6041 if No
(Next
(Assoc
)) then
6042 if not Is_Constrained
(Typ
)
6043 and then Is_Derived_Type
(Typ
)
6044 and then Present
(Stored_Constraint
(Typ
))
6046 -- If the type is a tagged type with inherited discriminants,
6047 -- use the stored constraint on the parent in order to find
6048 -- the values of discriminants that are otherwise hidden by an
6049 -- explicit constraint. Renamed discriminants are handled in
6052 -- If several parent discriminants are renamed by a single
6053 -- discriminant of the derived type, the call to obtain the
6054 -- Corresponding_Discriminant field only retrieves the last
6055 -- of them. We recover the constraint on the others from the
6056 -- Stored_Constraint as well.
6063 D
:= First_Discriminant
(Etype
(Typ
));
6064 C
:= First_Elmt
(Stored_Constraint
(Typ
));
6065 while Present
(D
) and then Present
(C
) loop
6066 if Chars
(Discrim_Name
) = Chars
(D
) then
6067 if Is_Entity_Name
(Node
(C
))
6068 and then Entity
(Node
(C
)) = Entity
(Discrim
)
6070 -- D is renamed by Discrim, whose value is given in
6077 Make_Component_Association
(Sloc
(Typ
),
6079 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
6080 Duplicate_Subexpr_No_Checks
(Node
(C
)));
6082 exit Find_Constraint
;
6085 Next_Discriminant
(D
);
6092 if No
(Next
(Assoc
)) then
6093 Error_Msg_NE
(" missing value for discriminant&",
6094 First
(Governed_By
), Discrim_Name
);
6095 Report_Errors
:= True;
6100 end loop Find_Constraint
;
6102 Discrim_Value
:= Expression
(Assoc
);
6104 if not Is_OK_Static_Expression
(Discrim_Value
) then
6106 ("value for discriminant & must be static!",
6107 Discrim_Value
, Discrim
);
6108 Why_Not_Static
(Discrim_Value
);
6109 Report_Errors
:= True;
6113 Search_For_Discriminant_Value
: declare
6119 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
6122 Find_Discrete_Value
: while Present
(Variant
) loop
6123 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
6124 while Present
(Discrete_Choice
) loop
6125 exit Find_Discrete_Value
when
6126 Nkind
(Discrete_Choice
) = N_Others_Choice
;
6128 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
6130 UI_Low
:= Expr_Value
(Low
);
6131 UI_High
:= Expr_Value
(High
);
6133 exit Find_Discrete_Value
when
6134 UI_Low
<= UI_Discrim_Value
6136 UI_High
>= UI_Discrim_Value
;
6138 Next
(Discrete_Choice
);
6141 Next_Non_Pragma
(Variant
);
6142 end loop Find_Discrete_Value
;
6143 end Search_For_Discriminant_Value
;
6145 if No
(Variant
) then
6147 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
6148 Report_Errors
:= True;
6152 -- If we have found the corresponding choice, recursively add its
6153 -- components to the Into list.
6156 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
6157 end Gather_Components
;
6159 ------------------------
6160 -- Get_Actual_Subtype --
6161 ------------------------
6163 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
6164 Typ
: constant Entity_Id
:= Etype
(N
);
6165 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
6174 -- If what we have is an identifier that references a subprogram
6175 -- formal, or a variable or constant object, then we get the actual
6176 -- subtype from the referenced entity if one has been built.
6178 if Nkind
(N
) = N_Identifier
6180 (Is_Formal
(Entity
(N
))
6181 or else Ekind
(Entity
(N
)) = E_Constant
6182 or else Ekind
(Entity
(N
)) = E_Variable
)
6183 and then Present
(Actual_Subtype
(Entity
(N
)))
6185 return Actual_Subtype
(Entity
(N
));
6187 -- Actual subtype of unchecked union is always itself. We never need
6188 -- the "real" actual subtype. If we did, we couldn't get it anyway
6189 -- because the discriminant is not available. The restrictions on
6190 -- Unchecked_Union are designed to make sure that this is OK.
6192 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
6195 -- Here for the unconstrained case, we must find actual subtype
6196 -- No actual subtype is available, so we must build it on the fly.
6198 -- Checking the type, not the underlying type, for constrainedness
6199 -- seems to be necessary. Maybe all the tests should be on the type???
6201 elsif (not Is_Constrained
(Typ
))
6202 and then (Is_Array_Type
(Utyp
)
6203 or else (Is_Record_Type
(Utyp
)
6204 and then Has_Discriminants
(Utyp
)))
6205 and then not Has_Unknown_Discriminants
(Utyp
)
6206 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
6208 -- Nothing to do if in spec expression (why not???)
6210 if In_Spec_Expression
then
6213 elsif Is_Private_Type
(Typ
)
6214 and then not Has_Discriminants
(Typ
)
6216 -- If the type has no discriminants, there is no subtype to
6217 -- build, even if the underlying type is discriminated.
6221 -- Else build the actual subtype
6224 Decl
:= Build_Actual_Subtype
(Typ
, N
);
6225 Atyp
:= Defining_Identifier
(Decl
);
6227 -- If Build_Actual_Subtype generated a new declaration then use it
6231 -- The actual subtype is an Itype, so analyze the declaration,
6232 -- but do not attach it to the tree, to get the type defined.
6234 Set_Parent
(Decl
, N
);
6235 Set_Is_Itype
(Atyp
);
6236 Analyze
(Decl
, Suppress
=> All_Checks
);
6237 Set_Associated_Node_For_Itype
(Atyp
, N
);
6238 Set_Has_Delayed_Freeze
(Atyp
, False);
6240 -- We need to freeze the actual subtype immediately. This is
6241 -- needed, because otherwise this Itype will not get frozen
6242 -- at all, and it is always safe to freeze on creation because
6243 -- any associated types must be frozen at this point.
6245 Freeze_Itype
(Atyp
, N
);
6248 -- Otherwise we did not build a declaration, so return original
6255 -- For all remaining cases, the actual subtype is the same as
6256 -- the nominal type.
6261 end Get_Actual_Subtype
;
6263 -------------------------------------
6264 -- Get_Actual_Subtype_If_Available --
6265 -------------------------------------
6267 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
6268 Typ
: constant Entity_Id
:= Etype
(N
);
6271 -- If what we have is an identifier that references a subprogram
6272 -- formal, or a variable or constant object, then we get the actual
6273 -- subtype from the referenced entity if one has been built.
6275 if Nkind
(N
) = N_Identifier
6277 (Is_Formal
(Entity
(N
))
6278 or else Ekind
(Entity
(N
)) = E_Constant
6279 or else Ekind
(Entity
(N
)) = E_Variable
)
6280 and then Present
(Actual_Subtype
(Entity
(N
)))
6282 return Actual_Subtype
(Entity
(N
));
6284 -- Otherwise the Etype of N is returned unchanged
6289 end Get_Actual_Subtype_If_Available
;
6291 ------------------------
6292 -- Get_Body_From_Stub --
6293 ------------------------
6295 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
6297 return Proper_Body
(Unit
(Library_Unit
(N
)));
6298 end Get_Body_From_Stub
;
6300 ---------------------
6301 -- Get_Cursor_Type --
6302 ---------------------
6304 function Get_Cursor_Type
6306 Typ
: Entity_Id
) return Entity_Id
6310 First_Op
: Entity_Id
;
6314 -- If error already detected, return
6316 if Error_Posted
(Aspect
) then
6320 -- The cursor type for an Iterable aspect is the return type of a
6321 -- non-overloaded First primitive operation. Locate association for
6324 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
6326 while Present
(Assoc
) loop
6327 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
6328 First_Op
:= Expression
(Assoc
);
6335 if First_Op
= Any_Id
then
6336 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
6342 -- Locate function with desired name and profile in scope of type
6344 Func
:= First_Entity
(Scope
(Typ
));
6345 while Present
(Func
) loop
6346 if Chars
(Func
) = Chars
(First_Op
)
6347 and then Ekind
(Func
) = E_Function
6348 and then Present
(First_Formal
(Func
))
6349 and then Etype
(First_Formal
(Func
)) = Typ
6350 and then No
(Next_Formal
(First_Formal
(Func
)))
6352 if Cursor
/= Any_Type
then
6354 ("Operation First for iterable type must be unique", Aspect
);
6357 Cursor
:= Etype
(Func
);
6364 -- If not found, no way to resolve remaining primitives.
6366 if Cursor
= Any_Type
then
6368 ("No legal primitive operation First for Iterable type", Aspect
);
6372 end Get_Cursor_Type
;
6374 -------------------------------
6375 -- Get_Default_External_Name --
6376 -------------------------------
6378 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
6380 Get_Decoded_Name_String
(Chars
(E
));
6382 if Opt
.External_Name_Imp_Casing
= Uppercase
then
6383 Set_Casing
(All_Upper_Case
);
6385 Set_Casing
(All_Lower_Case
);
6389 Make_String_Literal
(Sloc
(E
),
6390 Strval
=> String_From_Name_Buffer
);
6391 end Get_Default_External_Name
;
6393 --------------------------
6394 -- Get_Enclosing_Object --
6395 --------------------------
6397 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
6399 if Is_Entity_Name
(N
) then
6403 when N_Indexed_Component |
6405 N_Selected_Component
=>
6407 -- If not generating code, a dereference may be left implicit.
6408 -- In thoses cases, return Empty.
6410 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6413 return Get_Enclosing_Object
(Prefix
(N
));
6416 when N_Type_Conversion
=>
6417 return Get_Enclosing_Object
(Expression
(N
));
6423 end Get_Enclosing_Object
;
6425 ---------------------------
6426 -- Get_Enum_Lit_From_Pos --
6427 ---------------------------
6429 function Get_Enum_Lit_From_Pos
6432 Loc
: Source_Ptr
) return Node_Id
6434 Btyp
: Entity_Id
:= Base_Type
(T
);
6438 -- In the case where the literal is of type Character, Wide_Character
6439 -- or Wide_Wide_Character or of a type derived from them, there needs
6440 -- to be some special handling since there is no explicit chain of
6441 -- literals to search. Instead, an N_Character_Literal node is created
6442 -- with the appropriate Char_Code and Chars fields.
6444 if Is_Standard_Character_Type
(T
) then
6445 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
6447 Make_Character_Literal
(Loc
,
6449 Char_Literal_Value
=> Pos
);
6451 -- For all other cases, we have a complete table of literals, and
6452 -- we simply iterate through the chain of literal until the one
6453 -- with the desired position value is found.
6457 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
6458 Btyp
:= Full_View
(Btyp
);
6461 Lit
:= First_Literal
(Btyp
);
6462 for J
in 1 .. UI_To_Int
(Pos
) loop
6466 return New_Occurrence_Of
(Lit
, Loc
);
6468 end Get_Enum_Lit_From_Pos
;
6470 ---------------------------------
6471 -- Get_Ensures_From_CTC_Pragma --
6472 ---------------------------------
6474 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
6475 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
6479 if List_Length
(Args
) = 4 then
6480 Res
:= Pick
(Args
, 4);
6482 elsif List_Length
(Args
) = 3 then
6483 Res
:= Pick
(Args
, 3);
6485 if Chars
(Res
) /= Name_Ensures
then
6494 end Get_Ensures_From_CTC_Pragma
;
6496 ------------------------
6497 -- Get_Generic_Entity --
6498 ------------------------
6500 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
6501 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
6503 if Present
(Renamed_Object
(Ent
)) then
6504 return Renamed_Object
(Ent
);
6508 end Get_Generic_Entity
;
6510 -------------------------------------
6511 -- Get_Incomplete_View_Of_Ancestor --
6512 -------------------------------------
6514 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
6515 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
6516 Par_Scope
: Entity_Id
;
6517 Par_Type
: Entity_Id
;
6520 -- The incomplete view of an ancestor is only relevant for private
6521 -- derived types in child units.
6523 if not Is_Derived_Type
(E
)
6524 or else not Is_Child_Unit
(Cur_Unit
)
6529 Par_Scope
:= Scope
(Cur_Unit
);
6530 if No
(Par_Scope
) then
6534 Par_Type
:= Etype
(Base_Type
(E
));
6536 -- Traverse list of ancestor types until we find one declared in
6537 -- a parent or grandparent unit (two levels seem sufficient).
6539 while Present
(Par_Type
) loop
6540 if Scope
(Par_Type
) = Par_Scope
6541 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
6545 elsif not Is_Derived_Type
(Par_Type
) then
6549 Par_Type
:= Etype
(Base_Type
(Par_Type
));
6553 -- If none found, there is no relevant ancestor type.
6557 end Get_Incomplete_View_Of_Ancestor
;
6559 ----------------------
6560 -- Get_Index_Bounds --
6561 ----------------------
6563 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
6564 Kind
: constant Node_Kind
:= Nkind
(N
);
6568 if Kind
= N_Range
then
6570 H
:= High_Bound
(N
);
6572 elsif Kind
= N_Subtype_Indication
then
6573 R
:= Range_Expression
(Constraint
(N
));
6581 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
6582 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
6585 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
6586 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
6590 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
6591 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
6594 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
6595 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
6599 -- N is an expression, indicating a range with one value
6604 end Get_Index_Bounds
;
6606 ---------------------------------
6607 -- Get_Iterable_Type_Primitive --
6608 ---------------------------------
6610 function Get_Iterable_Type_Primitive
6612 Nam
: Name_Id
) return Entity_Id
6614 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
6622 Assoc
:= First
(Component_Associations
(Funcs
));
6623 while Present
(Assoc
) loop
6624 if Chars
(First
(Choices
(Assoc
))) = Nam
then
6625 return Entity
(Expression
(Assoc
));
6628 Assoc
:= Next
(Assoc
);
6633 end Get_Iterable_Type_Primitive
;
6635 ----------------------------------
6636 -- Get_Library_Unit_Name_string --
6637 ----------------------------------
6639 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
6640 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
6643 Get_Unit_Name_String
(Unit_Name_Id
);
6645 -- Remove seven last character (" (spec)" or " (body)")
6647 Name_Len
:= Name_Len
- 7;
6648 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
6649 end Get_Library_Unit_Name_String
;
6651 ------------------------
6652 -- Get_Name_Entity_Id --
6653 ------------------------
6655 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
6657 return Entity_Id
(Get_Name_Table_Info
(Id
));
6658 end Get_Name_Entity_Id
;
6660 ------------------------------
6661 -- Get_Name_From_CTC_Pragma --
6662 ------------------------------
6664 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
6665 Arg
: constant Node_Id
:=
6666 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
6668 return Strval
(Expr_Value_S
(Arg
));
6669 end Get_Name_From_CTC_Pragma
;
6675 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
6677 return Get_Pragma_Id
(Pragma_Name
(N
));
6680 -----------------------
6681 -- Get_Reason_String --
6682 -----------------------
6684 procedure Get_Reason_String
(N
: Node_Id
) is
6686 if Nkind
(N
) = N_String_Literal
then
6687 Store_String_Chars
(Strval
(N
));
6689 elsif Nkind
(N
) = N_Op_Concat
then
6690 Get_Reason_String
(Left_Opnd
(N
));
6691 Get_Reason_String
(Right_Opnd
(N
));
6693 -- If not of required form, error
6697 ("Reason for pragma Warnings has wrong form", N
);
6699 ("\must be string literal or concatenation of string literals", N
);
6702 end Get_Reason_String
;
6704 ---------------------------
6705 -- Get_Referenced_Object --
6706 ---------------------------
6708 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
6713 while Is_Entity_Name
(R
)
6714 and then Present
(Renamed_Object
(Entity
(R
)))
6716 R
:= Renamed_Object
(Entity
(R
));
6720 end Get_Referenced_Object
;
6722 ------------------------
6723 -- Get_Renamed_Entity --
6724 ------------------------
6726 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
6731 while Present
(Renamed_Entity
(R
)) loop
6732 R
:= Renamed_Entity
(R
);
6736 end Get_Renamed_Entity
;
6738 ----------------------------------
6739 -- Get_Requires_From_CTC_Pragma --
6740 ----------------------------------
6742 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
6743 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
6747 if List_Length
(Args
) >= 3 then
6748 Res
:= Pick
(Args
, 3);
6750 if Chars
(Res
) /= Name_Requires
then
6759 end Get_Requires_From_CTC_Pragma
;
6761 -------------------------
6762 -- Get_Subprogram_Body --
6763 -------------------------
6765 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
6769 Decl
:= Unit_Declaration_Node
(E
);
6771 if Nkind
(Decl
) = N_Subprogram_Body
then
6774 -- The below comment is bad, because it is possible for
6775 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
6777 else -- Nkind (Decl) = N_Subprogram_Declaration
6779 if Present
(Corresponding_Body
(Decl
)) then
6780 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
6782 -- Imported subprogram case
6788 end Get_Subprogram_Body
;
6790 ---------------------------
6791 -- Get_Subprogram_Entity --
6792 ---------------------------
6794 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
6796 Subp_Id
: Entity_Id
;
6799 if Nkind
(Nod
) = N_Accept_Statement
then
6800 Subp
:= Entry_Direct_Name
(Nod
);
6802 elsif Nkind
(Nod
) = N_Slice
then
6803 Subp
:= Prefix
(Nod
);
6809 -- Strip the subprogram call
6812 if Nkind_In
(Subp
, N_Explicit_Dereference
,
6813 N_Indexed_Component
,
6814 N_Selected_Component
)
6816 Subp
:= Prefix
(Subp
);
6818 elsif Nkind_In
(Subp
, N_Type_Conversion
,
6819 N_Unchecked_Type_Conversion
)
6821 Subp
:= Expression
(Subp
);
6828 -- Extract the entity of the subprogram call
6830 if Is_Entity_Name
(Subp
) then
6831 Subp_Id
:= Entity
(Subp
);
6833 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
6834 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
6837 if Is_Subprogram
(Subp_Id
) then
6843 -- The search did not find a construct that denotes a subprogram
6848 end Get_Subprogram_Entity
;
6850 -----------------------------
6851 -- Get_Task_Body_Procedure --
6852 -----------------------------
6854 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
6856 -- Note: A task type may be the completion of a private type with
6857 -- discriminants. When performing elaboration checks on a task
6858 -- declaration, the current view of the type may be the private one,
6859 -- and the procedure that holds the body of the task is held in its
6862 -- This is an odd function, why not have Task_Body_Procedure do
6863 -- the following digging???
6865 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
6866 end Get_Task_Body_Procedure
;
6868 -----------------------
6869 -- Has_Access_Values --
6870 -----------------------
6872 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
6873 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
6876 -- Case of a private type which is not completed yet. This can only
6877 -- happen in the case of a generic format type appearing directly, or
6878 -- as a component of the type to which this function is being applied
6879 -- at the top level. Return False in this case, since we certainly do
6880 -- not know that the type contains access types.
6885 elsif Is_Access_Type
(Typ
) then
6888 elsif Is_Array_Type
(Typ
) then
6889 return Has_Access_Values
(Component_Type
(Typ
));
6891 elsif Is_Record_Type
(Typ
) then
6896 -- Loop to Check components
6898 Comp
:= First_Component_Or_Discriminant
(Typ
);
6899 while Present
(Comp
) loop
6901 -- Check for access component, tag field does not count, even
6902 -- though it is implemented internally using an access type.
6904 if Has_Access_Values
(Etype
(Comp
))
6905 and then Chars
(Comp
) /= Name_uTag
6910 Next_Component_Or_Discriminant
(Comp
);
6919 end Has_Access_Values
;
6921 ------------------------------
6922 -- Has_Compatible_Alignment --
6923 ------------------------------
6925 function Has_Compatible_Alignment
6927 Expr
: Node_Id
) return Alignment_Result
6929 function Has_Compatible_Alignment_Internal
6932 Default
: Alignment_Result
) return Alignment_Result
;
6933 -- This is the internal recursive function that actually does the work.
6934 -- There is one additional parameter, which says what the result should
6935 -- be if no alignment information is found, and there is no definite
6936 -- indication of compatible alignments. At the outer level, this is set
6937 -- to Unknown, but for internal recursive calls in the case where types
6938 -- are known to be correct, it is set to Known_Compatible.
6940 ---------------------------------------
6941 -- Has_Compatible_Alignment_Internal --
6942 ---------------------------------------
6944 function Has_Compatible_Alignment_Internal
6947 Default
: Alignment_Result
) return Alignment_Result
6949 Result
: Alignment_Result
:= Known_Compatible
;
6950 -- Holds the current status of the result. Note that once a value of
6951 -- Known_Incompatible is set, it is sticky and does not get changed
6952 -- to Unknown (the value in Result only gets worse as we go along,
6955 Offs
: Uint
:= No_Uint
;
6956 -- Set to a factor of the offset from the base object when Expr is a
6957 -- selected or indexed component, based on Component_Bit_Offset and
6958 -- Component_Size respectively. A negative value is used to represent
6959 -- a value which is not known at compile time.
6961 procedure Check_Prefix
;
6962 -- Checks the prefix recursively in the case where the expression
6963 -- is an indexed or selected component.
6965 procedure Set_Result
(R
: Alignment_Result
);
6966 -- If R represents a worse outcome (unknown instead of known
6967 -- compatible, or known incompatible), then set Result to R.
6973 procedure Check_Prefix
is
6975 -- The subtlety here is that in doing a recursive call to check
6976 -- the prefix, we have to decide what to do in the case where we
6977 -- don't find any specific indication of an alignment problem.
6979 -- At the outer level, we normally set Unknown as the result in
6980 -- this case, since we can only set Known_Compatible if we really
6981 -- know that the alignment value is OK, but for the recursive
6982 -- call, in the case where the types match, and we have not
6983 -- specified a peculiar alignment for the object, we are only
6984 -- concerned about suspicious rep clauses, the default case does
6985 -- not affect us, since the compiler will, in the absence of such
6986 -- rep clauses, ensure that the alignment is correct.
6988 if Default
= Known_Compatible
6990 (Etype
(Obj
) = Etype
(Expr
)
6991 and then (Unknown_Alignment
(Obj
)
6993 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
6996 (Has_Compatible_Alignment_Internal
6997 (Obj
, Prefix
(Expr
), Known_Compatible
));
6999 -- In all other cases, we need a full check on the prefix
7003 (Has_Compatible_Alignment_Internal
7004 (Obj
, Prefix
(Expr
), Unknown
));
7012 procedure Set_Result
(R
: Alignment_Result
) is
7019 -- Start of processing for Has_Compatible_Alignment_Internal
7022 -- If Expr is a selected component, we must make sure there is no
7023 -- potentially troublesome component clause, and that the record is
7026 if Nkind
(Expr
) = N_Selected_Component
then
7028 -- Packed record always generate unknown alignment
7030 if Is_Packed
(Etype
(Prefix
(Expr
))) then
7031 Set_Result
(Unknown
);
7034 -- Check prefix and component offset
7037 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
7039 -- If Expr is an indexed component, we must make sure there is no
7040 -- potentially troublesome Component_Size clause and that the array
7041 -- is not bit-packed.
7043 elsif Nkind
(Expr
) = N_Indexed_Component
then
7045 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
7046 Ind
: constant Node_Id
:= First_Index
(Typ
);
7049 -- Bit packed array always generates unknown alignment
7051 if Is_Bit_Packed_Array
(Typ
) then
7052 Set_Result
(Unknown
);
7055 -- Check prefix and component offset
7058 Offs
:= Component_Size
(Typ
);
7060 -- Small optimization: compute the full offset when possible
7063 and then Offs
> Uint_0
7064 and then Present
(Ind
)
7065 and then Nkind
(Ind
) = N_Range
7066 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
7067 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
7069 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
7070 - Expr_Value
(Low_Bound
((Ind
))));
7075 -- If we have a null offset, the result is entirely determined by
7076 -- the base object and has already been computed recursively.
7078 if Offs
= Uint_0
then
7081 -- Case where we know the alignment of the object
7083 elsif Known_Alignment
(Obj
) then
7085 ObjA
: constant Uint
:= Alignment
(Obj
);
7086 ExpA
: Uint
:= No_Uint
;
7087 SizA
: Uint
:= No_Uint
;
7090 -- If alignment of Obj is 1, then we are always OK
7093 Set_Result
(Known_Compatible
);
7095 -- Alignment of Obj is greater than 1, so we need to check
7098 -- If we have an offset, see if it is compatible
7100 if Offs
/= No_Uint
and Offs
> Uint_0
then
7101 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
7102 Set_Result
(Known_Incompatible
);
7105 -- See if Expr is an object with known alignment
7107 elsif Is_Entity_Name
(Expr
)
7108 and then Known_Alignment
(Entity
(Expr
))
7110 ExpA
:= Alignment
(Entity
(Expr
));
7112 -- Otherwise, we can use the alignment of the type of
7113 -- Expr given that we already checked for
7114 -- discombobulating rep clauses for the cases of indexed
7115 -- and selected components above.
7117 elsif Known_Alignment
(Etype
(Expr
)) then
7118 ExpA
:= Alignment
(Etype
(Expr
));
7120 -- Otherwise the alignment is unknown
7123 Set_Result
(Default
);
7126 -- If we got an alignment, see if it is acceptable
7128 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
7129 Set_Result
(Known_Incompatible
);
7132 -- If Expr is not a piece of a larger object, see if size
7133 -- is given. If so, check that it is not too small for the
7134 -- required alignment.
7136 if Offs
/= No_Uint
then
7139 -- See if Expr is an object with known size
7141 elsif Is_Entity_Name
(Expr
)
7142 and then Known_Static_Esize
(Entity
(Expr
))
7144 SizA
:= Esize
(Entity
(Expr
));
7146 -- Otherwise, we check the object size of the Expr type
7148 elsif Known_Static_Esize
(Etype
(Expr
)) then
7149 SizA
:= Esize
(Etype
(Expr
));
7152 -- If we got a size, see if it is a multiple of the Obj
7153 -- alignment, if not, then the alignment cannot be
7154 -- acceptable, since the size is always a multiple of the
7157 if SizA
/= No_Uint
then
7158 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
7159 Set_Result
(Known_Incompatible
);
7165 -- If we do not know required alignment, any non-zero offset is a
7166 -- potential problem (but certainly may be OK, so result is unknown).
7168 elsif Offs
/= No_Uint
then
7169 Set_Result
(Unknown
);
7171 -- If we can't find the result by direct comparison of alignment
7172 -- values, then there is still one case that we can determine known
7173 -- result, and that is when we can determine that the types are the
7174 -- same, and no alignments are specified. Then we known that the
7175 -- alignments are compatible, even if we don't know the alignment
7176 -- value in the front end.
7178 elsif Etype
(Obj
) = Etype
(Expr
) then
7180 -- Types are the same, but we have to check for possible size
7181 -- and alignments on the Expr object that may make the alignment
7182 -- different, even though the types are the same.
7184 if Is_Entity_Name
(Expr
) then
7186 -- First check alignment of the Expr object. Any alignment less
7187 -- than Maximum_Alignment is worrisome since this is the case
7188 -- where we do not know the alignment of Obj.
7190 if Known_Alignment
(Entity
(Expr
))
7192 UI_To_Int
(Alignment
(Entity
(Expr
))) <
7193 Ttypes
.Maximum_Alignment
7195 Set_Result
(Unknown
);
7197 -- Now check size of Expr object. Any size that is not an
7198 -- even multiple of Maximum_Alignment is also worrisome
7199 -- since it may cause the alignment of the object to be less
7200 -- than the alignment of the type.
7202 elsif Known_Static_Esize
(Entity
(Expr
))
7204 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
7205 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
7208 Set_Result
(Unknown
);
7210 -- Otherwise same type is decisive
7213 Set_Result
(Known_Compatible
);
7217 -- Another case to deal with is when there is an explicit size or
7218 -- alignment clause when the types are not the same. If so, then the
7219 -- result is Unknown. We don't need to do this test if the Default is
7220 -- Unknown, since that result will be set in any case.
7222 elsif Default
/= Unknown
7223 and then (Has_Size_Clause
(Etype
(Expr
))
7225 Has_Alignment_Clause
(Etype
(Expr
)))
7227 Set_Result
(Unknown
);
7229 -- If no indication found, set default
7232 Set_Result
(Default
);
7235 -- Return worst result found
7238 end Has_Compatible_Alignment_Internal
;
7240 -- Start of processing for Has_Compatible_Alignment
7243 -- If Obj has no specified alignment, then set alignment from the type
7244 -- alignment. Perhaps we should always do this, but for sure we should
7245 -- do it when there is an address clause since we can do more if the
7246 -- alignment is known.
7248 if Unknown_Alignment
(Obj
) then
7249 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
7252 -- Now do the internal call that does all the work
7254 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
7255 end Has_Compatible_Alignment
;
7257 ----------------------
7258 -- Has_Declarations --
7259 ----------------------
7261 function Has_Declarations
(N
: Node_Id
) return Boolean is
7263 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
7265 N_Compilation_Unit_Aux
,
7271 N_Package_Specification
);
7272 end Has_Declarations
;
7278 function Has_Denormals
(E
: Entity_Id
) return Boolean is
7280 return Is_Floating_Point_Type
(E
)
7281 and then Denorm_On_Target
7282 and then not Vax_Float
(E
);
7285 -------------------------------------------
7286 -- Has_Discriminant_Dependent_Constraint --
7287 -------------------------------------------
7289 function Has_Discriminant_Dependent_Constraint
7290 (Comp
: Entity_Id
) return Boolean
7292 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7293 Subt_Indic
: constant Node_Id
:=
7294 Subtype_Indication
(Component_Definition
(Comp_Decl
));
7299 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
7300 Constr
:= Constraint
(Subt_Indic
);
7302 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
7303 Assn
:= First
(Constraints
(Constr
));
7304 while Present
(Assn
) loop
7305 case Nkind
(Assn
) is
7306 when N_Subtype_Indication |
7310 if Depends_On_Discriminant
(Assn
) then
7314 when N_Discriminant_Association
=>
7315 if Depends_On_Discriminant
(Expression
(Assn
)) then
7330 end Has_Discriminant_Dependent_Constraint
;
7332 --------------------------
7333 -- Has_Enabled_Property --
7334 --------------------------
7336 function Has_Enabled_Property
7337 (Item_Id
: Entity_Id
;
7338 Property
: Name_Id
) return Boolean
7340 function State_Has_Enabled_Property
return Boolean;
7341 -- Determine whether a state denoted by Item_Id has the property
7343 function Variable_Has_Enabled_Property
return Boolean;
7344 -- Determine whether a variable denoted by Item_Id has the property
7346 --------------------------------
7347 -- State_Has_Enabled_Property --
7348 --------------------------------
7350 function State_Has_Enabled_Property
return Boolean is
7351 Decl
: constant Node_Id
:= Parent
(Item_Id
);
7359 -- The declaration of an external abstract state appears as an
7360 -- extension aggregate. If this is not the case, properties can never
7363 if Nkind
(Decl
) /= N_Extension_Aggregate
then
7367 -- When External appears as a simple option, it automatically enables
7370 Opt
:= First
(Expressions
(Decl
));
7371 while Present
(Opt
) loop
7372 if Nkind
(Opt
) = N_Identifier
7373 and then Chars
(Opt
) = Name_External
7381 -- When External specifies particular properties, inspect those and
7382 -- find the desired one (if any).
7384 Opt
:= First
(Component_Associations
(Decl
));
7385 while Present
(Opt
) loop
7386 Opt_Nam
:= First
(Choices
(Opt
));
7388 if Nkind
(Opt_Nam
) = N_Identifier
7389 and then Chars
(Opt_Nam
) = Name_External
7391 Props
:= Expression
(Opt
);
7393 -- Multiple properties appear as an aggregate
7395 if Nkind
(Props
) = N_Aggregate
then
7397 -- Simple property form
7399 Prop
:= First
(Expressions
(Props
));
7400 while Present
(Prop
) loop
7401 if Chars
(Prop
) = Property
then
7408 -- Property with expression form
7410 Prop
:= First
(Component_Associations
(Props
));
7411 while Present
(Prop
) loop
7412 Prop_Nam
:= First
(Choices
(Prop
));
7414 if Chars
(Prop_Nam
) = Property
then
7415 return Is_True
(Expr_Value
(Expression
(Prop
)));
7424 return Chars
(Props
) = Property
;
7432 end State_Has_Enabled_Property
;
7434 -----------------------------------
7435 -- Variable_Has_Enabled_Property --
7436 -----------------------------------
7438 function Variable_Has_Enabled_Property
return Boolean is
7439 AR
: constant Node_Id
:=
7440 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
7441 AW
: constant Node_Id
:=
7442 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
7443 ER
: constant Node_Id
:=
7444 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
7445 EW
: constant Node_Id
:=
7446 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
7448 -- A non-volatile object can never possess external properties
7450 if not Is_SPARK_Volatile_Object
(Item_Id
) then
7453 -- External properties related to variables come in two flavors -
7454 -- explicit and implicit. The explicit case is characterized by the
7455 -- presence of a property pragma while the implicit case lacks all
7458 elsif Property
= Name_Async_Readers
7462 (No
(AW
) and then No
(ER
) and then No
(EW
)))
7466 elsif Property
= Name_Async_Writers
7470 (No
(AR
) and then No
(ER
) and then No
(EW
)))
7474 elsif Property
= Name_Effective_Reads
7478 (No
(AR
) and then No
(AW
) and then No
(EW
)))
7482 elsif Property
= Name_Effective_Writes
7486 (No
(AR
) and then No
(AW
) and then No
(ER
)))
7493 end Variable_Has_Enabled_Property
;
7495 -- Start of processing for Has_Enabled_Property
7498 if Ekind
(Item_Id
) = E_Abstract_State
then
7499 return State_Has_Enabled_Property
;
7501 else pragma Assert
(Ekind
(Item_Id
) = E_Variable
);
7502 return Variable_Has_Enabled_Property
;
7504 end Has_Enabled_Property
;
7506 --------------------
7507 -- Has_Infinities --
7508 --------------------
7510 function Has_Infinities
(E
: Entity_Id
) return Boolean is
7513 Is_Floating_Point_Type
(E
)
7514 and then Nkind
(Scalar_Range
(E
)) = N_Range
7515 and then Includes_Infinities
(Scalar_Range
(E
));
7518 --------------------
7519 -- Has_Interfaces --
7520 --------------------
7522 function Has_Interfaces
7524 Use_Full_View
: Boolean := True) return Boolean
7526 Typ
: Entity_Id
:= Base_Type
(T
);
7529 -- Handle concurrent types
7531 if Is_Concurrent_Type
(Typ
) then
7532 Typ
:= Corresponding_Record_Type
(Typ
);
7535 if not Present
(Typ
)
7536 or else not Is_Record_Type
(Typ
)
7537 or else not Is_Tagged_Type
(Typ
)
7542 -- Handle private types
7545 and then Present
(Full_View
(Typ
))
7547 Typ
:= Full_View
(Typ
);
7550 -- Handle concurrent record types
7552 if Is_Concurrent_Record_Type
(Typ
)
7553 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
7559 if Is_Interface
(Typ
)
7561 (Is_Record_Type
(Typ
)
7562 and then Present
(Interfaces
(Typ
))
7563 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
7568 exit when Etype
(Typ
) = Typ
7570 -- Handle private types
7572 or else (Present
(Full_View
(Etype
(Typ
)))
7573 and then Full_View
(Etype
(Typ
)) = Typ
)
7575 -- Protect the frontend against wrong source with cyclic
7578 or else Etype
(Typ
) = T
;
7580 -- Climb to the ancestor type handling private types
7582 if Present
(Full_View
(Etype
(Typ
))) then
7583 Typ
:= Full_View
(Etype
(Typ
));
7592 ---------------------------------
7593 -- Has_No_Obvious_Side_Effects --
7594 ---------------------------------
7596 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
7598 -- For now, just handle literals, constants, and non-volatile
7599 -- variables and expressions combining these with operators or
7600 -- short circuit forms.
7602 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
7605 elsif Nkind
(N
) = N_Character_Literal
then
7608 elsif Nkind
(N
) in N_Unary_Op
then
7609 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
7611 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
7612 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
7614 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
7616 elsif Nkind
(N
) = N_Expression_With_Actions
7618 Is_Empty_List
(Actions
(N
))
7620 return Has_No_Obvious_Side_Effects
(Expression
(N
));
7622 elsif Nkind
(N
) in N_Has_Entity
then
7623 return Present
(Entity
(N
))
7624 and then Ekind_In
(Entity
(N
), E_Variable
,
7626 E_Enumeration_Literal
,
7630 and then not Is_Volatile
(Entity
(N
));
7635 end Has_No_Obvious_Side_Effects
;
7637 ------------------------
7638 -- Has_Null_Exclusion --
7639 ------------------------
7641 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
7644 when N_Access_Definition |
7645 N_Access_Function_Definition |
7646 N_Access_Procedure_Definition |
7647 N_Access_To_Object_Definition |
7649 N_Derived_Type_Definition |
7650 N_Function_Specification |
7651 N_Subtype_Declaration
=>
7652 return Null_Exclusion_Present
(N
);
7654 when N_Component_Definition |
7655 N_Formal_Object_Declaration |
7656 N_Object_Renaming_Declaration
=>
7657 if Present
(Subtype_Mark
(N
)) then
7658 return Null_Exclusion_Present
(N
);
7659 else pragma Assert
(Present
(Access_Definition
(N
)));
7660 return Null_Exclusion_Present
(Access_Definition
(N
));
7663 when N_Discriminant_Specification
=>
7664 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
7665 return Null_Exclusion_Present
(Discriminant_Type
(N
));
7667 return Null_Exclusion_Present
(N
);
7670 when N_Object_Declaration
=>
7671 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
7672 return Null_Exclusion_Present
(Object_Definition
(N
));
7674 return Null_Exclusion_Present
(N
);
7677 when N_Parameter_Specification
=>
7678 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
7679 return Null_Exclusion_Present
(Parameter_Type
(N
));
7681 return Null_Exclusion_Present
(N
);
7688 end Has_Null_Exclusion
;
7690 ------------------------
7691 -- Has_Null_Extension --
7692 ------------------------
7694 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
7695 B
: constant Entity_Id
:= Base_Type
(T
);
7700 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
7701 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
7703 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
7705 if Present
(Ext
) then
7706 if Null_Present
(Ext
) then
7709 Comps
:= Component_List
(Ext
);
7711 -- The null component list is rewritten during analysis to
7712 -- include the parent component. Any other component indicates
7713 -- that the extension was not originally null.
7715 return Null_Present
(Comps
)
7716 or else No
(Next
(First
(Component_Items
(Comps
))));
7725 end Has_Null_Extension
;
7727 -------------------------------
7728 -- Has_Overriding_Initialize --
7729 -------------------------------
7731 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
7732 BT
: constant Entity_Id
:= Base_Type
(T
);
7736 if Is_Controlled
(BT
) then
7737 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
7740 elsif Present
(Primitive_Operations
(BT
)) then
7741 P
:= First_Elmt
(Primitive_Operations
(BT
));
7742 while Present
(P
) loop
7744 Init
: constant Entity_Id
:= Node
(P
);
7745 Formal
: constant Entity_Id
:= First_Formal
(Init
);
7747 if Ekind
(Init
) = E_Procedure
7748 and then Chars
(Init
) = Name_Initialize
7749 and then Comes_From_Source
(Init
)
7750 and then Present
(Formal
)
7751 and then Etype
(Formal
) = BT
7752 and then No
(Next_Formal
(Formal
))
7753 and then (Ada_Version
< Ada_2012
7754 or else not Null_Present
(Parent
(Init
)))
7764 -- Here if type itself does not have a non-null Initialize operation:
7765 -- check immediate ancestor.
7767 if Is_Derived_Type
(BT
)
7768 and then Has_Overriding_Initialize
(Etype
(BT
))
7775 end Has_Overriding_Initialize
;
7777 --------------------------------------
7778 -- Has_Preelaborable_Initialization --
7779 --------------------------------------
7781 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
7784 procedure Check_Components
(E
: Entity_Id
);
7785 -- Check component/discriminant chain, sets Has_PE False if a component
7786 -- or discriminant does not meet the preelaborable initialization rules.
7788 ----------------------
7789 -- Check_Components --
7790 ----------------------
7792 procedure Check_Components
(E
: Entity_Id
) is
7796 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
7797 -- Returns True if and only if the expression denoted by N does not
7798 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
7800 ---------------------------------
7801 -- Is_Preelaborable_Expression --
7802 ---------------------------------
7804 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
7808 Comp_Type
: Entity_Id
;
7809 Is_Array_Aggr
: Boolean;
7812 if Is_Static_Expression
(N
) then
7815 elsif Nkind
(N
) = N_Null
then
7818 -- Attributes are allowed in general, even if their prefix is a
7819 -- formal type. (It seems that certain attributes known not to be
7820 -- static might not be allowed, but there are no rules to prevent
7823 elsif Nkind
(N
) = N_Attribute_Reference
then
7826 -- The name of a discriminant evaluated within its parent type is
7827 -- defined to be preelaborable (10.2.1(8)). Note that we test for
7828 -- names that denote discriminals as well as discriminants to
7829 -- catch references occurring within init procs.
7831 elsif Is_Entity_Name
(N
)
7833 (Ekind
(Entity
(N
)) = E_Discriminant
7835 ((Ekind
(Entity
(N
)) = E_Constant
7836 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
7837 and then Present
(Discriminal_Link
(Entity
(N
)))))
7841 elsif Nkind
(N
) = N_Qualified_Expression
then
7842 return Is_Preelaborable_Expression
(Expression
(N
));
7844 -- For aggregates we have to check that each of the associations
7845 -- is preelaborable.
7847 elsif Nkind
(N
) = N_Aggregate
7848 or else Nkind
(N
) = N_Extension_Aggregate
7850 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
7852 if Is_Array_Aggr
then
7853 Comp_Type
:= Component_Type
(Etype
(N
));
7856 -- Check the ancestor part of extension aggregates, which must
7857 -- be either the name of a type that has preelaborable init or
7858 -- an expression that is preelaborable.
7860 if Nkind
(N
) = N_Extension_Aggregate
then
7862 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
7865 if Is_Entity_Name
(Anc_Part
)
7866 and then Is_Type
(Entity
(Anc_Part
))
7868 if not Has_Preelaborable_Initialization
7874 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
7880 -- Check positional associations
7882 Exp
:= First
(Expressions
(N
));
7883 while Present
(Exp
) loop
7884 if not Is_Preelaborable_Expression
(Exp
) then
7891 -- Check named associations
7893 Assn
:= First
(Component_Associations
(N
));
7894 while Present
(Assn
) loop
7895 Choice
:= First
(Choices
(Assn
));
7896 while Present
(Choice
) loop
7897 if Is_Array_Aggr
then
7898 if Nkind
(Choice
) = N_Others_Choice
then
7901 elsif Nkind
(Choice
) = N_Range
then
7902 if not Is_Static_Range
(Choice
) then
7906 elsif not Is_Static_Expression
(Choice
) then
7911 Comp_Type
:= Etype
(Choice
);
7917 -- If the association has a <> at this point, then we have
7918 -- to check whether the component's type has preelaborable
7919 -- initialization. Note that this only occurs when the
7920 -- association's corresponding component does not have a
7921 -- default expression, the latter case having already been
7922 -- expanded as an expression for the association.
7924 if Box_Present
(Assn
) then
7925 if not Has_Preelaborable_Initialization
(Comp_Type
) then
7929 -- In the expression case we check whether the expression
7930 -- is preelaborable.
7933 not Is_Preelaborable_Expression
(Expression
(Assn
))
7941 -- If we get here then aggregate as a whole is preelaborable
7945 -- All other cases are not preelaborable
7950 end Is_Preelaborable_Expression
;
7952 -- Start of processing for Check_Components
7955 -- Loop through entities of record or protected type
7958 while Present
(Ent
) loop
7960 -- We are interested only in components and discriminants
7967 -- Get default expression if any. If there is no declaration
7968 -- node, it means we have an internal entity. The parent and
7969 -- tag fields are examples of such entities. For such cases,
7970 -- we just test the type of the entity.
7972 if Present
(Declaration_Node
(Ent
)) then
7973 Exp
:= Expression
(Declaration_Node
(Ent
));
7976 when E_Discriminant
=>
7978 -- Note: for a renamed discriminant, the Declaration_Node
7979 -- may point to the one from the ancestor, and have a
7980 -- different expression, so use the proper attribute to
7981 -- retrieve the expression from the derived constraint.
7983 Exp
:= Discriminant_Default_Value
(Ent
);
7986 goto Check_Next_Entity
;
7989 -- A component has PI if it has no default expression and the
7990 -- component type has PI.
7993 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
7998 -- Require the default expression to be preelaborable
8000 elsif not Is_Preelaborable_Expression
(Exp
) then
8005 <<Check_Next_Entity
>>
8008 end Check_Components
;
8010 -- Start of processing for Has_Preelaborable_Initialization
8013 -- Immediate return if already marked as known preelaborable init. This
8014 -- covers types for which this function has already been called once
8015 -- and returned True (in which case the result is cached), and also
8016 -- types to which a pragma Preelaborable_Initialization applies.
8018 if Known_To_Have_Preelab_Init
(E
) then
8022 -- If the type is a subtype representing a generic actual type, then
8023 -- test whether its base type has preelaborable initialization since
8024 -- the subtype representing the actual does not inherit this attribute
8025 -- from the actual or formal. (but maybe it should???)
8027 if Is_Generic_Actual_Type
(E
) then
8028 return Has_Preelaborable_Initialization
(Base_Type
(E
));
8031 -- All elementary types have preelaborable initialization
8033 if Is_Elementary_Type
(E
) then
8036 -- Array types have PI if the component type has PI
8038 elsif Is_Array_Type
(E
) then
8039 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
8041 -- A derived type has preelaborable initialization if its parent type
8042 -- has preelaborable initialization and (in the case of a derived record
8043 -- extension) if the non-inherited components all have preelaborable
8044 -- initialization. However, a user-defined controlled type with an
8045 -- overriding Initialize procedure does not have preelaborable
8048 elsif Is_Derived_Type
(E
) then
8050 -- If the derived type is a private extension then it doesn't have
8051 -- preelaborable initialization.
8053 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
8057 -- First check whether ancestor type has preelaborable initialization
8059 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
8061 -- If OK, check extension components (if any)
8063 if Has_PE
and then Is_Record_Type
(E
) then
8064 Check_Components
(First_Entity
(E
));
8067 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8068 -- with a user defined Initialize procedure does not have PI.
8071 and then Is_Controlled
(E
)
8072 and then Has_Overriding_Initialize
(E
)
8077 -- Private types not derived from a type having preelaborable init and
8078 -- that are not marked with pragma Preelaborable_Initialization do not
8079 -- have preelaborable initialization.
8081 elsif Is_Private_Type
(E
) then
8084 -- Record type has PI if it is non private and all components have PI
8086 elsif Is_Record_Type
(E
) then
8088 Check_Components
(First_Entity
(E
));
8090 -- Protected types must not have entries, and components must meet
8091 -- same set of rules as for record components.
8093 elsif Is_Protected_Type
(E
) then
8094 if Has_Entries
(E
) then
8098 Check_Components
(First_Entity
(E
));
8099 Check_Components
(First_Private_Entity
(E
));
8102 -- Type System.Address always has preelaborable initialization
8104 elsif Is_RTE
(E
, RE_Address
) then
8107 -- In all other cases, type does not have preelaborable initialization
8113 -- If type has preelaborable initialization, cache result
8116 Set_Known_To_Have_Preelab_Init
(E
);
8120 end Has_Preelaborable_Initialization
;
8122 ---------------------------
8123 -- Has_Private_Component --
8124 ---------------------------
8126 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
8127 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
8128 Component
: Entity_Id
;
8131 if Error_Posted
(Type_Id
)
8132 or else Error_Posted
(Btype
)
8137 if Is_Class_Wide_Type
(Btype
) then
8138 Btype
:= Root_Type
(Btype
);
8141 if Is_Private_Type
(Btype
) then
8143 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
8146 if No
(Full_View
(Btype
)) then
8147 return not Is_Generic_Type
(Btype
)
8148 and then not Is_Generic_Type
(Root_Type
(Btype
));
8150 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
8153 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
8157 elsif Is_Array_Type
(Btype
) then
8158 return Has_Private_Component
(Component_Type
(Btype
));
8160 elsif Is_Record_Type
(Btype
) then
8161 Component
:= First_Component
(Btype
);
8162 while Present
(Component
) loop
8163 if Has_Private_Component
(Etype
(Component
)) then
8167 Next_Component
(Component
);
8172 elsif Is_Protected_Type
(Btype
)
8173 and then Present
(Corresponding_Record_Type
(Btype
))
8175 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
8180 end Has_Private_Component
;
8182 ----------------------
8183 -- Has_Signed_Zeros --
8184 ----------------------
8186 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
8188 return Is_Floating_Point_Type
(E
)
8189 and then Signed_Zeros_On_Target
8190 and then not Vax_Float
(E
);
8191 end Has_Signed_Zeros
;
8193 -----------------------------
8194 -- Has_Static_Array_Bounds --
8195 -----------------------------
8197 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
8198 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
8205 -- Unconstrained types do not have static bounds
8207 if not Is_Constrained
(Typ
) then
8211 -- First treat string literals specially, as the lower bound and length
8212 -- of string literals are not stored like those of arrays.
8214 -- A string literal always has static bounds
8216 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8220 -- Treat all dimensions in turn
8222 Index
:= First_Index
(Typ
);
8223 for Indx
in 1 .. Ndims
loop
8225 -- In case of an erroneous index which is not a discrete type, return
8226 -- that the type is not static.
8228 if not Is_Discrete_Type
(Etype
(Index
))
8229 or else Etype
(Index
) = Any_Type
8234 Get_Index_Bounds
(Index
, Low
, High
);
8236 if Error_Posted
(Low
) or else Error_Posted
(High
) then
8240 if Is_OK_Static_Expression
(Low
)
8242 Is_OK_Static_Expression
(High
)
8252 -- If we fall through the loop, all indexes matched
8255 end Has_Static_Array_Bounds
;
8261 function Has_Stream
(T
: Entity_Id
) return Boolean is
8268 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
8271 elsif Is_Array_Type
(T
) then
8272 return Has_Stream
(Component_Type
(T
));
8274 elsif Is_Record_Type
(T
) then
8275 E
:= First_Component
(T
);
8276 while Present
(E
) loop
8277 if Has_Stream
(Etype
(E
)) then
8286 elsif Is_Private_Type
(T
) then
8287 return Has_Stream
(Underlying_Type
(T
));
8298 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
8300 Get_Name_String
(Chars
(E
));
8301 return Name_Buffer
(Name_Len
) = Suffix
;
8308 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8310 Get_Name_String
(Chars
(E
));
8311 Add_Char_To_Name_Buffer
(Suffix
);
8319 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8321 pragma Assert
(Has_Suffix
(E
, Suffix
));
8322 Get_Name_String
(Chars
(E
));
8323 Name_Len
:= Name_Len
- 1;
8327 --------------------------
8328 -- Has_Tagged_Component --
8329 --------------------------
8331 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
8335 if Is_Private_Type
(Typ
)
8336 and then Present
(Underlying_Type
(Typ
))
8338 return Has_Tagged_Component
(Underlying_Type
(Typ
));
8340 elsif Is_Array_Type
(Typ
) then
8341 return Has_Tagged_Component
(Component_Type
(Typ
));
8343 elsif Is_Tagged_Type
(Typ
) then
8346 elsif Is_Record_Type
(Typ
) then
8347 Comp
:= First_Component
(Typ
);
8348 while Present
(Comp
) loop
8349 if Has_Tagged_Component
(Etype
(Comp
)) then
8353 Next_Component
(Comp
);
8361 end Has_Tagged_Component
;
8363 ----------------------------
8364 -- Has_Volatile_Component --
8365 ----------------------------
8367 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
8371 if Has_Volatile_Components
(Typ
) then
8374 elsif Is_Array_Type
(Typ
) then
8375 return Is_Volatile
(Component_Type
(Typ
));
8377 elsif Is_Record_Type
(Typ
) then
8378 Comp
:= First_Component
(Typ
);
8379 while Present
(Comp
) loop
8380 if Is_Volatile_Object
(Comp
) then
8384 Comp
:= Next_Component
(Comp
);
8389 end Has_Volatile_Component
;
8391 -------------------------
8392 -- Implementation_Kind --
8393 -------------------------
8395 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
8396 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
8399 pragma Assert
(Present
(Impl_Prag
));
8400 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
8401 return Chars
(Get_Pragma_Arg
(Arg
));
8402 end Implementation_Kind
;
8404 --------------------------
8405 -- Implements_Interface --
8406 --------------------------
8408 function Implements_Interface
8409 (Typ_Ent
: Entity_Id
;
8410 Iface_Ent
: Entity_Id
;
8411 Exclude_Parents
: Boolean := False) return Boolean
8413 Ifaces_List
: Elist_Id
;
8415 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
8416 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
8419 if Is_Class_Wide_Type
(Typ
) then
8420 Typ
:= Root_Type
(Typ
);
8423 if not Has_Interfaces
(Typ
) then
8427 if Is_Class_Wide_Type
(Iface
) then
8428 Iface
:= Root_Type
(Iface
);
8431 Collect_Interfaces
(Typ
, Ifaces_List
);
8433 Elmt
:= First_Elmt
(Ifaces_List
);
8434 while Present
(Elmt
) loop
8435 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
8436 and then Exclude_Parents
8440 elsif Node
(Elmt
) = Iface
then
8448 end Implements_Interface
;
8450 ------------------------------------
8451 -- In_Assertion_Expression_Pragma --
8452 ------------------------------------
8454 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
8456 Prag
: Node_Id
:= Empty
;
8459 -- Climb the parent chain looking for an enclosing pragma
8462 while Present
(Par
) loop
8463 if Nkind
(Par
) = N_Pragma
then
8467 -- Precondition-like pragmas are expanded into if statements, check
8468 -- the original node instead.
8470 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
8471 Prag
:= Original_Node
(Par
);
8474 -- Prevent the search from going too far
8476 elsif Is_Body_Or_Package_Declaration
(Par
) then
8480 Par
:= Parent
(Par
);
8485 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
8486 end In_Assertion_Expression_Pragma
;
8492 function In_Instance
return Boolean is
8493 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
8499 and then S
/= Standard_Standard
8501 if (Ekind
(S
) = E_Function
8502 or else Ekind
(S
) = E_Package
8503 or else Ekind
(S
) = E_Procedure
)
8504 and then Is_Generic_Instance
(S
)
8506 -- A child instance is always compiled in the context of a parent
8507 -- instance. Nevertheless, the actuals are not analyzed in an
8508 -- instance context. We detect this case by examining the current
8509 -- compilation unit, which must be a child instance, and checking
8510 -- that it is not currently on the scope stack.
8512 if Is_Child_Unit
(Curr_Unit
)
8514 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
8515 = N_Package_Instantiation
8516 and then not In_Open_Scopes
(Curr_Unit
)
8530 ----------------------
8531 -- In_Instance_Body --
8532 ----------------------
8534 function In_Instance_Body
return Boolean is
8540 and then S
/= Standard_Standard
8542 if (Ekind
(S
) = E_Function
8543 or else Ekind
(S
) = E_Procedure
)
8544 and then Is_Generic_Instance
(S
)
8548 elsif Ekind
(S
) = E_Package
8549 and then In_Package_Body
(S
)
8550 and then Is_Generic_Instance
(S
)
8559 end In_Instance_Body
;
8561 -----------------------------
8562 -- In_Instance_Not_Visible --
8563 -----------------------------
8565 function In_Instance_Not_Visible
return Boolean is
8571 and then S
/= Standard_Standard
8573 if (Ekind
(S
) = E_Function
8574 or else Ekind
(S
) = E_Procedure
)
8575 and then Is_Generic_Instance
(S
)
8579 elsif Ekind
(S
) = E_Package
8580 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
8581 and then Is_Generic_Instance
(S
)
8590 end In_Instance_Not_Visible
;
8592 ------------------------------
8593 -- In_Instance_Visible_Part --
8594 ------------------------------
8596 function In_Instance_Visible_Part
return Boolean is
8602 and then S
/= Standard_Standard
8604 if Ekind
(S
) = E_Package
8605 and then Is_Generic_Instance
(S
)
8606 and then not In_Package_Body
(S
)
8607 and then not In_Private_Part
(S
)
8616 end In_Instance_Visible_Part
;
8618 ---------------------
8619 -- In_Package_Body --
8620 ---------------------
8622 function In_Package_Body
return Boolean is
8628 and then S
/= Standard_Standard
8630 if Ekind
(S
) = E_Package
8631 and then In_Package_Body
(S
)
8640 end In_Package_Body
;
8642 --------------------------------
8643 -- In_Parameter_Specification --
8644 --------------------------------
8646 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
8651 while Present
(PN
) loop
8652 if Nkind
(PN
) = N_Parameter_Specification
then
8660 end In_Parameter_Specification
;
8662 --------------------------
8663 -- In_Pragma_Expression --
8664 --------------------------
8666 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
8673 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
8679 end In_Pragma_Expression
;
8681 -------------------------------------
8682 -- In_Reverse_Storage_Order_Object --
8683 -------------------------------------
8685 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
8687 Btyp
: Entity_Id
:= Empty
;
8690 -- Climb up indexed components
8694 case Nkind
(Pref
) is
8695 when N_Selected_Component
=>
8696 Pref
:= Prefix
(Pref
);
8699 when N_Indexed_Component
=>
8700 Pref
:= Prefix
(Pref
);
8708 if Present
(Pref
) then
8709 Btyp
:= Base_Type
(Etype
(Pref
));
8714 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
8715 and then Reverse_Storage_Order
(Btyp
);
8716 end In_Reverse_Storage_Order_Object
;
8718 --------------------------------------
8719 -- In_Subprogram_Or_Concurrent_Unit --
8720 --------------------------------------
8722 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
8727 -- Use scope chain to check successively outer scopes
8733 if K
in Subprogram_Kind
8734 or else K
in Concurrent_Kind
8735 or else K
in Generic_Subprogram_Kind
8739 elsif E
= Standard_Standard
then
8745 end In_Subprogram_Or_Concurrent_Unit
;
8747 ---------------------
8748 -- In_Visible_Part --
8749 ---------------------
8751 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
8754 Is_Package_Or_Generic_Package
(Scope_Id
)
8755 and then In_Open_Scopes
(Scope_Id
)
8756 and then not In_Package_Body
(Scope_Id
)
8757 and then not In_Private_Part
(Scope_Id
);
8758 end In_Visible_Part
;
8760 --------------------------------
8761 -- Incomplete_Or_Private_View --
8762 --------------------------------
8764 function Incomplete_Or_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
8765 function Inspect_Decls
8767 Taft
: Boolean := False) return Entity_Id
;
8768 -- Check whether a declarative region contains the incomplete or private
8775 function Inspect_Decls
8777 Taft
: Boolean := False) return Entity_Id
8783 Decl
:= First
(Decls
);
8784 while Present
(Decl
) loop
8788 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
8789 Match
:= Defining_Identifier
(Decl
);
8793 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
8794 N_Private_Type_Declaration
)
8796 Match
:= Defining_Identifier
(Decl
);
8801 and then Present
(Full_View
(Match
))
8802 and then Full_View
(Match
) = Typ
8817 -- Start of processing for Incomplete_Or_Partial_View
8820 -- Incomplete type case
8822 Prev
:= Current_Entity_In_Scope
(Typ
);
8825 and then Is_Incomplete_Type
(Prev
)
8826 and then Present
(Full_View
(Prev
))
8827 and then Full_View
(Prev
) = Typ
8832 -- Private or Taft amendment type case
8835 Pkg
: constant Entity_Id
:= Scope
(Typ
);
8836 Pkg_Decl
: Node_Id
:= Pkg
;
8839 if Ekind
(Pkg
) = E_Package
then
8840 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
8841 Pkg_Decl
:= Parent
(Pkg_Decl
);
8844 -- It is knows that Typ has a private view, look for it in the
8845 -- visible declarations of the enclosing scope. A special case
8846 -- of this is when the two views have been exchanged - the full
8847 -- appears earlier than the private.
8849 if Has_Private_Declaration
(Typ
) then
8850 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
8852 -- Exchanged view case, look in the private declarations
8855 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
8860 -- Otherwise if this is the package body, then Typ is a potential
8861 -- Taft amendment type. The incomplete view should be located in
8862 -- the private declarations of the enclosing scope.
8864 elsif In_Package_Body
(Pkg
) then
8865 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
8870 -- The type has no incomplete or private view
8873 end Incomplete_Or_Private_View
;
8875 ---------------------------------
8876 -- Insert_Explicit_Dereference --
8877 ---------------------------------
8879 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
8880 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
8881 Ent
: Entity_Id
:= Empty
;
8888 Save_Interps
(N
, New_Prefix
);
8891 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
8892 Prefix
=> New_Prefix
));
8894 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
8896 if Is_Overloaded
(New_Prefix
) then
8898 -- The dereference is also overloaded, and its interpretations are
8899 -- the designated types of the interpretations of the original node.
8901 Set_Etype
(N
, Any_Type
);
8903 Get_First_Interp
(New_Prefix
, I
, It
);
8904 while Present
(It
.Nam
) loop
8907 if Is_Access_Type
(T
) then
8908 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
8911 Get_Next_Interp
(I
, It
);
8917 -- Prefix is unambiguous: mark the original prefix (which might
8918 -- Come_From_Source) as a reference, since the new (relocated) one
8919 -- won't be taken into account.
8921 if Is_Entity_Name
(New_Prefix
) then
8922 Ent
:= Entity
(New_Prefix
);
8925 -- For a retrieval of a subcomponent of some composite object,
8926 -- retrieve the ultimate entity if there is one.
8928 elsif Nkind
(New_Prefix
) = N_Selected_Component
8929 or else Nkind
(New_Prefix
) = N_Indexed_Component
8931 Pref
:= Prefix
(New_Prefix
);
8932 while Present
(Pref
)
8934 (Nkind
(Pref
) = N_Selected_Component
8935 or else Nkind
(Pref
) = N_Indexed_Component
)
8937 Pref
:= Prefix
(Pref
);
8940 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
8941 Ent
:= Entity
(Pref
);
8945 -- Place the reference on the entity node
8947 if Present
(Ent
) then
8948 Generate_Reference
(Ent
, Pref
);
8951 end Insert_Explicit_Dereference
;
8953 ------------------------------------------
8954 -- Inspect_Deferred_Constant_Completion --
8955 ------------------------------------------
8957 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
8961 Decl
:= First
(Decls
);
8962 while Present
(Decl
) loop
8964 -- Deferred constant signature
8966 if Nkind
(Decl
) = N_Object_Declaration
8967 and then Constant_Present
(Decl
)
8968 and then No
(Expression
(Decl
))
8970 -- No need to check internally generated constants
8972 and then Comes_From_Source
(Decl
)
8974 -- The constant is not completed. A full object declaration or a
8975 -- pragma Import complete a deferred constant.
8977 and then not Has_Completion
(Defining_Identifier
(Decl
))
8980 ("constant declaration requires initialization expression",
8981 Defining_Identifier
(Decl
));
8984 Decl
:= Next
(Decl
);
8986 end Inspect_Deferred_Constant_Completion
;
8988 -----------------------------
8989 -- Is_Actual_Out_Parameter --
8990 -----------------------------
8992 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
8996 Find_Actual
(N
, Formal
, Call
);
8997 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
8998 end Is_Actual_Out_Parameter
;
9000 -------------------------
9001 -- Is_Actual_Parameter --
9002 -------------------------
9004 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
9005 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
9009 when N_Parameter_Association
=>
9010 return N
= Explicit_Actual_Parameter
(Parent
(N
));
9012 when N_Subprogram_Call
=>
9013 return Is_List_Member
(N
)
9015 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
9020 end Is_Actual_Parameter
;
9022 --------------------------------
9023 -- Is_Actual_Tagged_Parameter --
9024 --------------------------------
9026 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
9030 Find_Actual
(N
, Formal
, Call
);
9031 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
9032 end Is_Actual_Tagged_Parameter
;
9034 ---------------------
9035 -- Is_Aliased_View --
9036 ---------------------
9038 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
9042 if Is_Entity_Name
(Obj
) then
9049 or else (Present
(Renamed_Object
(E
))
9050 and then Is_Aliased_View
(Renamed_Object
(E
)))))
9052 or else ((Is_Formal
(E
)
9053 or else Ekind
(E
) = E_Generic_In_Out_Parameter
9054 or else Ekind
(E
) = E_Generic_In_Parameter
)
9055 and then Is_Tagged_Type
(Etype
(E
)))
9057 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
9059 -- Current instance of type, either directly or as rewritten
9060 -- reference to the current object.
9062 or else (Is_Entity_Name
(Original_Node
(Obj
))
9063 and then Present
(Entity
(Original_Node
(Obj
)))
9064 and then Is_Type
(Entity
(Original_Node
(Obj
))))
9066 or else (Is_Type
(E
) and then E
= Current_Scope
)
9068 or else (Is_Incomplete_Or_Private_Type
(E
)
9069 and then Full_View
(E
) = Current_Scope
)
9071 -- Ada 2012 AI05-0053: the return object of an extended return
9072 -- statement is aliased if its type is immutably limited.
9074 or else (Is_Return_Object
(E
)
9075 and then Is_Limited_View
(Etype
(E
)));
9077 elsif Nkind
(Obj
) = N_Selected_Component
then
9078 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
9080 elsif Nkind
(Obj
) = N_Indexed_Component
then
9081 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
9083 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
9084 and then Has_Aliased_Components
9085 (Designated_Type
(Etype
(Prefix
(Obj
)))));
9087 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
9088 return Is_Tagged_Type
(Etype
(Obj
))
9089 and then Is_Aliased_View
(Expression
(Obj
));
9091 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
9092 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
9097 end Is_Aliased_View
;
9099 -------------------------
9100 -- Is_Ancestor_Package --
9101 -------------------------
9103 function Is_Ancestor_Package
9105 E2
: Entity_Id
) return Boolean
9112 and then Par
/= Standard_Standard
9122 end Is_Ancestor_Package
;
9124 ----------------------
9125 -- Is_Atomic_Object --
9126 ----------------------
9128 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
9130 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
9131 -- Determines if given object has atomic components
9133 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
9134 -- If prefix is an implicit dereference, examine designated type
9136 ----------------------
9137 -- Is_Atomic_Prefix --
9138 ----------------------
9140 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
9142 if Is_Access_Type
(Etype
(N
)) then
9144 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
9146 return Object_Has_Atomic_Components
(N
);
9148 end Is_Atomic_Prefix
;
9150 ----------------------------------
9151 -- Object_Has_Atomic_Components --
9152 ----------------------------------
9154 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
9156 if Has_Atomic_Components
(Etype
(N
))
9157 or else Is_Atomic
(Etype
(N
))
9161 elsif Is_Entity_Name
(N
)
9162 and then (Has_Atomic_Components
(Entity
(N
))
9163 or else Is_Atomic
(Entity
(N
)))
9167 elsif Nkind
(N
) = N_Selected_Component
9168 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9172 elsif Nkind
(N
) = N_Indexed_Component
9173 or else Nkind
(N
) = N_Selected_Component
9175 return Is_Atomic_Prefix
(Prefix
(N
));
9180 end Object_Has_Atomic_Components
;
9182 -- Start of processing for Is_Atomic_Object
9185 -- Predicate is not relevant to subprograms
9187 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
9190 elsif Is_Atomic
(Etype
(N
))
9191 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
9195 elsif Nkind
(N
) = N_Selected_Component
9196 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9200 elsif Nkind
(N
) = N_Indexed_Component
9201 or else Nkind
(N
) = N_Selected_Component
9203 return Is_Atomic_Prefix
(Prefix
(N
));
9208 end Is_Atomic_Object
;
9210 -------------------------
9211 -- Is_Attribute_Result --
9212 -------------------------
9214 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
9217 Nkind
(N
) = N_Attribute_Reference
9218 and then Attribute_Name
(N
) = Name_Result
;
9219 end Is_Attribute_Result
;
9221 ------------------------------------
9222 -- Is_Body_Or_Package_Declaration --
9223 ------------------------------------
9225 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
9227 return Nkind_In
(N
, N_Entry_Body
,
9229 N_Package_Declaration
,
9233 end Is_Body_Or_Package_Declaration
;
9235 -----------------------
9236 -- Is_Bounded_String --
9237 -----------------------
9239 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
9240 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
9243 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9244 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9245 -- be True for all the Bounded_String types in instances of the
9246 -- Generic_Bounded_Length generics, and for types derived from those.
9248 return Present
(Under
)
9249 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
9250 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
9251 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
9252 end Is_Bounded_String
;
9254 -------------------------
9255 -- Is_Child_Or_Sibling --
9256 -------------------------
9258 function Is_Child_Or_Sibling
9259 (Pack_1
: Entity_Id
;
9260 Pack_2
: Entity_Id
) return Boolean
9262 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
9263 -- Given an arbitrary package, return the number of "climbs" necessary
9264 -- to reach scope Standard_Standard.
9266 procedure Equalize_Depths
9267 (Pack
: in out Entity_Id
;
9269 Depth_To_Reach
: Nat
);
9270 -- Given an arbitrary package, its depth and a target depth to reach,
9271 -- climb the scope chain until the said depth is reached. The pointer
9272 -- to the package and its depth a modified during the climb.
9274 ----------------------------
9275 -- Distance_From_Standard --
9276 ----------------------------
9278 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
9285 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
9287 Scop
:= Scope
(Scop
);
9291 end Distance_From_Standard
;
9293 ---------------------
9294 -- Equalize_Depths --
9295 ---------------------
9297 procedure Equalize_Depths
9298 (Pack
: in out Entity_Id
;
9300 Depth_To_Reach
: Nat
)
9303 -- The package must be at a greater or equal depth
9305 if Depth
< Depth_To_Reach
then
9306 raise Program_Error
;
9309 -- Climb the scope chain until the desired depth is reached
9311 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
9312 Pack
:= Scope
(Pack
);
9315 end Equalize_Depths
;
9319 P_1
: Entity_Id
:= Pack_1
;
9320 P_1_Child
: Boolean := False;
9321 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
9322 P_2
: Entity_Id
:= Pack_2
;
9323 P_2_Child
: Boolean := False;
9324 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
9326 -- Start of processing for Is_Child_Or_Sibling
9330 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
9332 -- Both packages denote the same entity, therefore they cannot be
9333 -- children or siblings.
9338 -- One of the packages is at a deeper level than the other. Note that
9339 -- both may still come from differen hierarchies.
9347 elsif P_1_Depth
> P_2_Depth
then
9351 Depth_To_Reach
=> P_2_Depth
);
9360 elsif P_2_Depth
> P_1_Depth
then
9364 Depth_To_Reach
=> P_1_Depth
);
9368 -- At this stage the package pointers have been elevated to the same
9369 -- depth. If the related entities are the same, then one package is a
9370 -- potential child of the other:
9374 -- X became P_1 P_2 or vica versa
9380 return Is_Child_Unit
(Pack_1
);
9382 else pragma Assert
(P_2_Child
);
9383 return Is_Child_Unit
(Pack_2
);
9386 -- The packages may come from the same package chain or from entirely
9387 -- different hierarcies. To determine this, climb the scope stack until
9388 -- a common root is found.
9390 -- (root) (root 1) (root 2)
9395 while Present
(P_1
) and then Present
(P_2
) loop
9397 -- The two packages may be siblings
9400 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
9409 end Is_Child_Or_Sibling
;
9411 -----------------------------
9412 -- Is_Concurrent_Interface --
9413 -----------------------------
9415 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
9420 (Is_Protected_Interface
(T
)
9421 or else Is_Synchronized_Interface
(T
)
9422 or else Is_Task_Interface
(T
));
9423 end Is_Concurrent_Interface
;
9425 ---------------------------
9426 -- Is_Container_Element --
9427 ---------------------------
9429 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
9430 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
9431 Pref
: constant Node_Id
:= Prefix
(Exp
);
9434 -- Call to an indexing aspect
9436 Cont_Typ
: Entity_Id
;
9437 -- The type of the container being accessed
9439 Elem_Typ
: Entity_Id
;
9442 Indexing
: Entity_Id
;
9444 -- Indicates that constant indexing is used, and the element is thus
9447 Ref_Typ
: Entity_Id
;
9448 -- The reference type returned by the indexing operation
9451 -- If C is a container, in a context that imposes the element type of
9452 -- that container, the indexing notation C (X) is rewritten as:
9454 -- Indexing (C, X).Discr.all
9456 -- where Indexing is one of the indexing aspects of the container.
9457 -- If the context does not require a reference, the construct can be
9462 -- First, verify that the construct has the proper form
9464 if not Expander_Active
then
9467 elsif Nkind
(Pref
) /= N_Selected_Component
then
9470 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
9474 Call
:= Prefix
(Pref
);
9475 Ref_Typ
:= Etype
(Call
);
9478 if not Has_Implicit_Dereference
(Ref_Typ
)
9479 or else No
(First
(Parameter_Associations
(Call
)))
9480 or else not Is_Entity_Name
(Name
(Call
))
9485 -- Retrieve type of container object, and its iterator aspects
9487 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
9488 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
9491 if No
(Indexing
) then
9493 -- Container should have at least one indexing operation
9497 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
9499 -- This may be a variable indexing operation
9501 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
9504 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
9513 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
9515 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
9519 -- Check that the expression is not the target of an assignment, in
9520 -- which case the rewriting is not possible.
9522 if not Is_Const
then
9530 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
9531 and then Par
= Name
(Parent
(Par
))
9535 -- A renaming produces a reference, and the transformation
9538 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
9542 (Nkind
(Parent
(Par
)), N_Function_Call
,
9543 N_Procedure_Call_Statement
,
9544 N_Entry_Call_Statement
)
9546 -- Check that the element is not part of an actual for an
9547 -- in-out parameter.
9554 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
9555 A
:= First
(Parameter_Associations
(Parent
(Par
)));
9556 while Present
(F
) loop
9557 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
9566 -- E_In_Parameter in a call: element is not modified.
9571 Par
:= Parent
(Par
);
9576 -- The expression has the proper form and the context requires the
9577 -- element type. Retrieve the Element function of the container and
9578 -- rewrite the construct as a call to it.
9584 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
9585 while Present
(Op
) loop
9586 exit when Chars
(Node
(Op
)) = Name_Element
;
9595 Make_Function_Call
(Loc
,
9596 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
9597 Parameter_Associations
=> Parameter_Associations
(Call
)));
9598 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
9602 end Is_Container_Element
;
9604 -----------------------
9605 -- Is_Constant_Bound --
9606 -----------------------
9608 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
9610 if Compile_Time_Known_Value
(Exp
) then
9613 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
9614 return Is_Constant_Object
(Entity
(Exp
))
9615 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
9617 elsif Nkind
(Exp
) in N_Binary_Op
then
9618 return Is_Constant_Bound
(Left_Opnd
(Exp
))
9619 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
9620 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
9625 end Is_Constant_Bound
;
9627 --------------------------------------
9628 -- Is_Controlling_Limited_Procedure --
9629 --------------------------------------
9631 function Is_Controlling_Limited_Procedure
9632 (Proc_Nam
: Entity_Id
) return Boolean
9634 Param_Typ
: Entity_Id
:= Empty
;
9637 if Ekind
(Proc_Nam
) = E_Procedure
9638 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
9640 Param_Typ
:= Etype
(Parameter_Type
(First
(
9641 Parameter_Specifications
(Parent
(Proc_Nam
)))));
9643 -- In this case where an Itype was created, the procedure call has been
9646 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
9647 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
9649 Present
(Parameter_Associations
9650 (Associated_Node_For_Itype
(Proc_Nam
)))
9653 Etype
(First
(Parameter_Associations
9654 (Associated_Node_For_Itype
(Proc_Nam
))));
9657 if Present
(Param_Typ
) then
9659 Is_Interface
(Param_Typ
)
9660 and then Is_Limited_Record
(Param_Typ
);
9664 end Is_Controlling_Limited_Procedure
;
9666 -----------------------------
9667 -- Is_CPP_Constructor_Call --
9668 -----------------------------
9670 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
9672 return Nkind
(N
) = N_Function_Call
9673 and then Is_CPP_Class
(Etype
(Etype
(N
)))
9674 and then Is_Constructor
(Entity
(Name
(N
)))
9675 and then Is_Imported
(Entity
(Name
(N
)));
9676 end Is_CPP_Constructor_Call
;
9682 function Is_Delegate
(T
: Entity_Id
) return Boolean is
9683 Desig_Type
: Entity_Id
;
9686 if VM_Target
/= CLI_Target
then
9690 -- Access-to-subprograms are delegates in CIL
9692 if Ekind
(T
) = E_Access_Subprogram_Type
then
9696 if Ekind
(T
) not in Access_Kind
then
9698 -- A delegate is a managed pointer. If no designated type is defined
9699 -- it means that it's not a delegate.
9704 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
9706 if not Is_Tagged_Type
(Desig_Type
) then
9710 -- Test if the type is inherited from [mscorlib]System.Delegate
9712 while Etype
(Desig_Type
) /= Desig_Type
loop
9713 if Chars
(Scope
(Desig_Type
)) /= No_Name
9714 and then Is_Imported
(Scope
(Desig_Type
))
9715 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
9720 Desig_Type
:= Etype
(Desig_Type
);
9726 ----------------------------------------------
9727 -- Is_Dependent_Component_Of_Mutable_Object --
9728 ----------------------------------------------
9730 function Is_Dependent_Component_Of_Mutable_Object
9731 (Object
: Node_Id
) return Boolean
9734 Prefix_Type
: Entity_Id
;
9735 P_Aliased
: Boolean := False;
9738 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
9739 -- Returns True if and only if Comp is declared within a variant part
9741 --------------------------------
9742 -- Is_Declared_Within_Variant --
9743 --------------------------------
9745 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
9746 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
9747 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
9749 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
9750 end Is_Declared_Within_Variant
;
9752 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
9755 if Is_Variable
(Object
) then
9757 if Nkind
(Object
) = N_Selected_Component
then
9758 P
:= Prefix
(Object
);
9759 Prefix_Type
:= Etype
(P
);
9761 if Is_Entity_Name
(P
) then
9763 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
9764 Prefix_Type
:= Base_Type
(Prefix_Type
);
9767 if Is_Aliased
(Entity
(P
)) then
9771 -- A discriminant check on a selected component may be expanded
9772 -- into a dereference when removing side-effects. Recover the
9773 -- original node and its type, which may be unconstrained.
9775 elsif Nkind
(P
) = N_Explicit_Dereference
9776 and then not (Comes_From_Source
(P
))
9778 P
:= Original_Node
(P
);
9779 Prefix_Type
:= Etype
(P
);
9782 -- Check for prefix being an aliased component???
9788 -- A heap object is constrained by its initial value
9790 -- Ada 2005 (AI-363): Always assume the object could be mutable in
9791 -- the dereferenced case, since the access value might denote an
9792 -- unconstrained aliased object, whereas in Ada 95 the designated
9793 -- object is guaranteed to be constrained. A worst-case assumption
9794 -- has to apply in Ada 2005 because we can't tell at compile time
9795 -- whether the object is "constrained by its initial value"
9796 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
9797 -- semantic rules -- these rules are acknowledged to need fixing).
9799 if Ada_Version
< Ada_2005
then
9800 if Is_Access_Type
(Prefix_Type
)
9801 or else Nkind
(P
) = N_Explicit_Dereference
9806 elsif Ada_Version
>= Ada_2005
then
9807 if Is_Access_Type
(Prefix_Type
) then
9809 -- If the access type is pool-specific, and there is no
9810 -- constrained partial view of the designated type, then the
9811 -- designated object is known to be constrained.
9813 if Ekind
(Prefix_Type
) = E_Access_Type
9814 and then not Object_Type_Has_Constrained_Partial_View
9815 (Typ
=> Designated_Type
(Prefix_Type
),
9816 Scop
=> Current_Scope
)
9820 -- Otherwise (general access type, or there is a constrained
9821 -- partial view of the designated type), we need to check
9822 -- based on the designated type.
9825 Prefix_Type
:= Designated_Type
(Prefix_Type
);
9831 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
9833 -- As per AI-0017, the renaming is illegal in a generic body, even
9834 -- if the subtype is indefinite.
9836 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
9838 if not Is_Constrained
(Prefix_Type
)
9839 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
9841 (Is_Generic_Type
(Prefix_Type
)
9842 and then Ekind
(Current_Scope
) = E_Generic_Package
9843 and then In_Package_Body
(Current_Scope
)))
9845 and then (Is_Declared_Within_Variant
(Comp
)
9846 or else Has_Discriminant_Dependent_Constraint
(Comp
))
9847 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
9851 -- If the prefix is of an access type at this point, then we want
9852 -- to return False, rather than calling this function recursively
9853 -- on the access object (which itself might be a discriminant-
9854 -- dependent component of some other object, but that isn't
9855 -- relevant to checking the object passed to us). This avoids
9856 -- issuing wrong errors when compiling with -gnatc, where there
9857 -- can be implicit dereferences that have not been expanded.
9859 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
9864 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
9867 elsif Nkind
(Object
) = N_Indexed_Component
9868 or else Nkind
(Object
) = N_Slice
9870 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
9872 -- A type conversion that Is_Variable is a view conversion:
9873 -- go back to the denoted object.
9875 elsif Nkind
(Object
) = N_Type_Conversion
then
9877 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
9882 end Is_Dependent_Component_Of_Mutable_Object
;
9884 ---------------------
9885 -- Is_Dereferenced --
9886 ---------------------
9888 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
9889 P
: constant Node_Id
:= Parent
(N
);
9892 (Nkind
(P
) = N_Selected_Component
9894 Nkind
(P
) = N_Explicit_Dereference
9896 Nkind
(P
) = N_Indexed_Component
9898 Nkind
(P
) = N_Slice
)
9899 and then Prefix
(P
) = N
;
9900 end Is_Dereferenced
;
9902 ----------------------
9903 -- Is_Descendent_Of --
9904 ----------------------
9906 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
9911 pragma Assert
(Nkind
(T1
) in N_Entity
);
9912 pragma Assert
(Nkind
(T2
) in N_Entity
);
9914 T
:= Base_Type
(T1
);
9916 -- Immediate return if the types match
9921 -- Comment needed here ???
9923 elsif Ekind
(T
) = E_Class_Wide_Type
then
9924 return Etype
(T
) = T2
;
9932 -- Done if we found the type we are looking for
9937 -- Done if no more derivations to check
9944 -- Following test catches error cases resulting from prev errors
9946 elsif No
(Etyp
) then
9949 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
9952 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
9956 T
:= Base_Type
(Etyp
);
9959 end Is_Descendent_Of
;
9961 ----------------------------
9962 -- Is_Expression_Function --
9963 ----------------------------
9965 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
9969 if Ekind
(Subp
) /= E_Function
then
9973 Decl
:= Unit_Declaration_Node
(Subp
);
9974 return Nkind
(Decl
) = N_Subprogram_Declaration
9976 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
9978 (Present
(Corresponding_Body
(Decl
))
9980 Nkind
(Original_Node
9981 (Unit_Declaration_Node
9982 (Corresponding_Body
(Decl
)))) =
9983 N_Expression_Function
));
9985 end Is_Expression_Function
;
9991 function Is_False
(U
: Uint
) return Boolean is
9996 ---------------------------
9997 -- Is_Fixed_Model_Number --
9998 ---------------------------
10000 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
10001 S
: constant Ureal
:= Small_Value
(T
);
10002 M
: Urealp
.Save_Mark
;
10006 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
10007 Urealp
.Release
(M
);
10009 end Is_Fixed_Model_Number
;
10011 -------------------------------
10012 -- Is_Fully_Initialized_Type --
10013 -------------------------------
10015 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
10017 -- In Ada2012, a scalar type with an aspect Default_Value
10018 -- is fully initialized.
10020 if Is_Scalar_Type
(Typ
) then
10021 return Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
);
10023 elsif Is_Access_Type
(Typ
) then
10026 elsif Is_Array_Type
(Typ
) then
10027 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
10028 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
10033 -- An interesting case, if we have a constrained type one of whose
10034 -- bounds is known to be null, then there are no elements to be
10035 -- initialized, so all the elements are initialized.
10037 if Is_Constrained
(Typ
) then
10040 Indx_Typ
: Entity_Id
;
10041 Lbd
, Hbd
: Node_Id
;
10044 Indx
:= First_Index
(Typ
);
10045 while Present
(Indx
) loop
10046 if Etype
(Indx
) = Any_Type
then
10049 -- If index is a range, use directly
10051 elsif Nkind
(Indx
) = N_Range
then
10052 Lbd
:= Low_Bound
(Indx
);
10053 Hbd
:= High_Bound
(Indx
);
10056 Indx_Typ
:= Etype
(Indx
);
10058 if Is_Private_Type
(Indx_Typ
) then
10059 Indx_Typ
:= Full_View
(Indx_Typ
);
10062 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
10065 Lbd
:= Type_Low_Bound
(Indx_Typ
);
10066 Hbd
:= Type_High_Bound
(Indx_Typ
);
10070 if Compile_Time_Known_Value
(Lbd
)
10071 and then Compile_Time_Known_Value
(Hbd
)
10073 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
10083 -- If no null indexes, then type is not fully initialized
10089 elsif Is_Record_Type
(Typ
) then
10090 if Has_Discriminants
(Typ
)
10092 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
10093 and then Is_Fully_Initialized_Variant
(Typ
)
10098 -- We consider bounded string types to be fully initialized, because
10099 -- otherwise we get false alarms when the Data component is not
10100 -- default-initialized.
10102 if Is_Bounded_String
(Typ
) then
10106 -- Controlled records are considered to be fully initialized if
10107 -- there is a user defined Initialize routine. This may not be
10108 -- entirely correct, but as the spec notes, we are guessing here
10109 -- what is best from the point of view of issuing warnings.
10111 if Is_Controlled
(Typ
) then
10113 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
10116 if Present
(Utyp
) then
10118 Init
: constant Entity_Id
:=
10120 (Underlying_Type
(Typ
), Name_Initialize
));
10124 and then Comes_From_Source
(Init
)
10126 Is_Predefined_File_Name
10127 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
10131 elsif Has_Null_Extension
(Typ
)
10133 Is_Fully_Initialized_Type
10134 (Etype
(Base_Type
(Typ
)))
10143 -- Otherwise see if all record components are initialized
10149 Ent
:= First_Entity
(Typ
);
10150 while Present
(Ent
) loop
10151 if Ekind
(Ent
) = E_Component
10152 and then (No
(Parent
(Ent
))
10153 or else No
(Expression
(Parent
(Ent
))))
10154 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
10156 -- Special VM case for tag components, which need to be
10157 -- defined in this case, but are never initialized as VMs
10158 -- are using other dispatching mechanisms. Ignore this
10159 -- uninitialized case. Note that this applies both to the
10160 -- uTag entry and the main vtable pointer (CPP_Class case).
10162 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
10171 -- No uninitialized components, so type is fully initialized.
10172 -- Note that this catches the case of no components as well.
10176 elsif Is_Concurrent_Type
(Typ
) then
10179 elsif Is_Private_Type
(Typ
) then
10181 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10187 return Is_Fully_Initialized_Type
(U
);
10194 end Is_Fully_Initialized_Type
;
10196 ----------------------------------
10197 -- Is_Fully_Initialized_Variant --
10198 ----------------------------------
10200 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
10201 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
10202 Constraints
: constant List_Id
:= New_List
;
10203 Components
: constant Elist_Id
:= New_Elmt_List
;
10204 Comp_Elmt
: Elmt_Id
;
10206 Comp_List
: Node_Id
;
10208 Discr_Val
: Node_Id
;
10210 Report_Errors
: Boolean;
10211 pragma Warnings
(Off
, Report_Errors
);
10214 if Serious_Errors_Detected
> 0 then
10218 if Is_Record_Type
(Typ
)
10219 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
10220 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
10222 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
10224 Discr
:= First_Discriminant
(Typ
);
10225 while Present
(Discr
) loop
10226 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
10227 Discr_Val
:= Expression
(Parent
(Discr
));
10229 if Present
(Discr_Val
)
10230 and then Is_OK_Static_Expression
(Discr_Val
)
10232 Append_To
(Constraints
,
10233 Make_Component_Association
(Loc
,
10234 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
10235 Expression
=> New_Copy
(Discr_Val
)));
10243 Next_Discriminant
(Discr
);
10248 Comp_List
=> Comp_List
,
10249 Governed_By
=> Constraints
,
10250 Into
=> Components
,
10251 Report_Errors
=> Report_Errors
);
10253 -- Check that each component present is fully initialized
10255 Comp_Elmt
:= First_Elmt
(Components
);
10256 while Present
(Comp_Elmt
) loop
10257 Comp_Id
:= Node
(Comp_Elmt
);
10259 if Ekind
(Comp_Id
) = E_Component
10260 and then (No
(Parent
(Comp_Id
))
10261 or else No
(Expression
(Parent
(Comp_Id
))))
10262 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
10267 Next_Elmt
(Comp_Elmt
);
10272 elsif Is_Private_Type
(Typ
) then
10274 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10280 return Is_Fully_Initialized_Variant
(U
);
10287 end Is_Fully_Initialized_Variant
;
10289 ----------------------------
10290 -- Is_Inherited_Operation --
10291 ----------------------------
10293 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
10294 pragma Assert
(Is_Overloadable
(E
));
10295 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
10297 return Kind
= N_Full_Type_Declaration
10298 or else Kind
= N_Private_Extension_Declaration
10299 or else Kind
= N_Subtype_Declaration
10300 or else (Ekind
(E
) = E_Enumeration_Literal
10301 and then Is_Derived_Type
(Etype
(E
)));
10302 end Is_Inherited_Operation
;
10304 -------------------------------------
10305 -- Is_Inherited_Operation_For_Type --
10306 -------------------------------------
10308 function Is_Inherited_Operation_For_Type
10310 Typ
: Entity_Id
) return Boolean
10313 -- Check that the operation has been created by the type declaration
10315 return Is_Inherited_Operation
(E
)
10316 and then Defining_Identifier
(Parent
(E
)) = Typ
;
10317 end Is_Inherited_Operation_For_Type
;
10323 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
10324 Ifaces_List
: Elist_Id
;
10325 Iface_Elmt
: Elmt_Id
;
10329 if Is_Class_Wide_Type
(Typ
)
10331 Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
10332 Name_Reversible_Iterator
)
10334 Is_Predefined_File_Name
10335 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
10339 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
10342 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
10346 Collect_Interfaces
(Typ
, Ifaces_List
);
10348 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
10349 while Present
(Iface_Elmt
) loop
10350 Iface
:= Node
(Iface_Elmt
);
10351 if Chars
(Iface
) = Name_Forward_Iterator
10353 Is_Predefined_File_Name
10354 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
10359 Next_Elmt
(Iface_Elmt
);
10370 function Is_Junk_Name
(N
: Name_Id
) return Boolean is
10371 function Match
(S
: String) return Boolean;
10372 -- Return true if substring S is found in Name_Buffer (1 .. Name_Len)
10378 function Match
(S
: String) return Boolean is
10379 Slen1
: constant Integer := S
'Length - 1;
10382 for J
in 1 .. Name_Len
- S
'Length + 1 loop
10383 if Name_Buffer
(J
.. J
+ Slen1
) = S
then
10391 -- Start of processing for Is_Junk_Name
10394 Get_Unqualified_Decoded_Name_String
(N
);
10395 Set_All_Upper_Case
;
10398 Match
("DISCARD") or else
10399 Match
("DUMMY") or else
10400 Match
("IGNORE") or else
10401 Match
("JUNK") or else
10409 -- We seem to have a lot of overlapping functions that do similar things
10410 -- (testing for left hand sides or lvalues???).
10412 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
10413 P
: constant Node_Id
:= Parent
(N
);
10416 -- Return True if we are the left hand side of an assignment statement
10418 if Nkind
(P
) = N_Assignment_Statement
then
10419 if Name
(P
) = N
then
10425 -- Case of prefix of indexed or selected component or slice
10427 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
10428 and then N
= Prefix
(P
)
10430 -- Here we have the case where the parent P is N.Q or N(Q .. R).
10431 -- If P is an LHS, then N is also effectively an LHS, but there
10432 -- is an important exception. If N is of an access type, then
10433 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
10434 -- case this makes N.all a left hand side but not N itself.
10436 -- If we don't know the type yet, this is the case where we return
10437 -- Unknown, since the answer depends on the type which is unknown.
10439 if No
(Etype
(N
)) then
10442 -- We have an Etype set, so we can check it
10444 elsif Is_Access_Type
(Etype
(N
)) then
10447 -- OK, not access type case, so just test whole expression
10453 -- All other cases are not left hand sides
10460 -----------------------------
10461 -- Is_Library_Level_Entity --
10462 -----------------------------
10464 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
10466 -- The following is a small optimization, and it also properly handles
10467 -- discriminals, which in task bodies might appear in expressions before
10468 -- the corresponding procedure has been created, and which therefore do
10469 -- not have an assigned scope.
10471 if Is_Formal
(E
) then
10475 -- Normal test is simply that the enclosing dynamic scope is Standard
10477 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
10478 end Is_Library_Level_Entity
;
10480 --------------------------------
10481 -- Is_Limited_Class_Wide_Type --
10482 --------------------------------
10484 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
10487 Is_Class_Wide_Type
(Typ
)
10488 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
10489 end Is_Limited_Class_Wide_Type
;
10491 ---------------------------------
10492 -- Is_Local_Variable_Reference --
10493 ---------------------------------
10495 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
10497 if not Is_Entity_Name
(Expr
) then
10502 Ent
: constant Entity_Id
:= Entity
(Expr
);
10503 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
10505 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
10508 return Present
(Sub
) and then Sub
= Current_Subprogram
;
10512 end Is_Local_Variable_Reference
;
10514 -------------------------
10515 -- Is_Object_Reference --
10516 -------------------------
10518 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
10520 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
10521 -- Determine whether N is the name of an internally-generated renaming
10523 --------------------------------------
10524 -- Is_Internally_Generated_Renaming --
10525 --------------------------------------
10527 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
10532 while Present
(P
) loop
10533 if Nkind
(P
) = N_Object_Renaming_Declaration
then
10534 return not Comes_From_Source
(P
);
10535 elsif Is_List_Member
(P
) then
10543 end Is_Internally_Generated_Renaming
;
10545 -- Start of processing for Is_Object_Reference
10548 if Is_Entity_Name
(N
) then
10549 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
10553 when N_Indexed_Component | N_Slice
=>
10555 Is_Object_Reference
(Prefix
(N
))
10556 or else Is_Access_Type
(Etype
(Prefix
(N
)));
10558 -- In Ada 95, a function call is a constant object; a procedure
10561 when N_Function_Call
=>
10562 return Etype
(N
) /= Standard_Void_Type
;
10564 -- Attributes 'Input, 'Old and 'Result produce objects
10566 when N_Attribute_Reference
=>
10569 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
10571 when N_Selected_Component
=>
10573 Is_Object_Reference
(Selector_Name
(N
))
10575 (Is_Object_Reference
(Prefix
(N
))
10576 or else Is_Access_Type
(Etype
(Prefix
(N
))));
10578 when N_Explicit_Dereference
=>
10581 -- A view conversion of a tagged object is an object reference
10583 when N_Type_Conversion
=>
10584 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
10585 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
10586 and then Is_Object_Reference
(Expression
(N
));
10588 -- An unchecked type conversion is considered to be an object if
10589 -- the operand is an object (this construction arises only as a
10590 -- result of expansion activities).
10592 when N_Unchecked_Type_Conversion
=>
10595 -- Allow string literals to act as objects as long as they appear
10596 -- in internally-generated renamings. The expansion of iterators
10597 -- may generate such renamings when the range involves a string
10600 when N_String_Literal
=>
10601 return Is_Internally_Generated_Renaming
(Parent
(N
));
10603 -- AI05-0003: In Ada 2012 a qualified expression is a name.
10604 -- This allows disambiguation of function calls and the use
10605 -- of aggregates in more contexts.
10607 when N_Qualified_Expression
=>
10608 if Ada_Version
< Ada_2012
then
10611 return Is_Object_Reference
(Expression
(N
))
10612 or else Nkind
(Expression
(N
)) = N_Aggregate
;
10619 end Is_Object_Reference
;
10621 -----------------------------------
10622 -- Is_OK_Variable_For_Out_Formal --
10623 -----------------------------------
10625 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
10627 Note_Possible_Modification
(AV
, Sure
=> True);
10629 -- We must reject parenthesized variable names. Comes_From_Source is
10630 -- checked because there are currently cases where the compiler violates
10631 -- this rule (e.g. passing a task object to its controlled Initialize
10632 -- routine). This should be properly documented in sinfo???
10634 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
10637 -- A variable is always allowed
10639 elsif Is_Variable
(AV
) then
10642 -- Unchecked conversions are allowed only if they come from the
10643 -- generated code, which sometimes uses unchecked conversions for out
10644 -- parameters in cases where code generation is unaffected. We tell
10645 -- source unchecked conversions by seeing if they are rewrites of
10646 -- an original Unchecked_Conversion function call, or of an explicit
10647 -- conversion of a function call or an aggregate (as may happen in the
10648 -- expansion of a packed array aggregate).
10650 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
10651 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
10654 elsif Comes_From_Source
(AV
)
10655 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
10659 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
10660 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
10666 -- Normal type conversions are allowed if argument is a variable
10668 elsif Nkind
(AV
) = N_Type_Conversion
then
10669 if Is_Variable
(Expression
(AV
))
10670 and then Paren_Count
(Expression
(AV
)) = 0
10672 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
10675 -- We also allow a non-parenthesized expression that raises
10676 -- constraint error if it rewrites what used to be a variable
10678 elsif Raises_Constraint_Error
(Expression
(AV
))
10679 and then Paren_Count
(Expression
(AV
)) = 0
10680 and then Is_Variable
(Original_Node
(Expression
(AV
)))
10684 -- Type conversion of something other than a variable
10690 -- If this node is rewritten, then test the original form, if that is
10691 -- OK, then we consider the rewritten node OK (for example, if the
10692 -- original node is a conversion, then Is_Variable will not be true
10693 -- but we still want to allow the conversion if it converts a variable).
10695 elsif Original_Node
(AV
) /= AV
then
10697 -- In Ada 2012, the explicit dereference may be a rewritten call to a
10698 -- Reference function.
10700 if Ada_Version
>= Ada_2012
10701 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
10703 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
10708 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
10711 -- All other non-variables are rejected
10716 end Is_OK_Variable_For_Out_Formal
;
10718 -----------------------------------
10719 -- Is_Partially_Initialized_Type --
10720 -----------------------------------
10722 function Is_Partially_Initialized_Type
10724 Include_Implicit
: Boolean := True) return Boolean
10727 if Is_Scalar_Type
(Typ
) then
10730 elsif Is_Access_Type
(Typ
) then
10731 return Include_Implicit
;
10733 elsif Is_Array_Type
(Typ
) then
10735 -- If component type is partially initialized, so is array type
10737 if Is_Partially_Initialized_Type
10738 (Component_Type
(Typ
), Include_Implicit
)
10742 -- Otherwise we are only partially initialized if we are fully
10743 -- initialized (this is the empty array case, no point in us
10744 -- duplicating that code here).
10747 return Is_Fully_Initialized_Type
(Typ
);
10750 elsif Is_Record_Type
(Typ
) then
10752 -- A discriminated type is always partially initialized if in
10755 if Has_Discriminants
(Typ
) and then Include_Implicit
then
10758 -- A tagged type is always partially initialized
10760 elsif Is_Tagged_Type
(Typ
) then
10763 -- Case of non-discriminated record
10769 Component_Present
: Boolean := False;
10770 -- Set True if at least one component is present. If no
10771 -- components are present, then record type is fully
10772 -- initialized (another odd case, like the null array).
10775 -- Loop through components
10777 Ent
:= First_Entity
(Typ
);
10778 while Present
(Ent
) loop
10779 if Ekind
(Ent
) = E_Component
then
10780 Component_Present
:= True;
10782 -- If a component has an initialization expression then
10783 -- the enclosing record type is partially initialized
10785 if Present
(Parent
(Ent
))
10786 and then Present
(Expression
(Parent
(Ent
)))
10790 -- If a component is of a type which is itself partially
10791 -- initialized, then the enclosing record type is also.
10793 elsif Is_Partially_Initialized_Type
10794 (Etype
(Ent
), Include_Implicit
)
10803 -- No initialized components found. If we found any components
10804 -- they were all uninitialized so the result is false.
10806 if Component_Present
then
10809 -- But if we found no components, then all the components are
10810 -- initialized so we consider the type to be initialized.
10818 -- Concurrent types are always fully initialized
10820 elsif Is_Concurrent_Type
(Typ
) then
10823 -- For a private type, go to underlying type. If there is no underlying
10824 -- type then just assume this partially initialized. Not clear if this
10825 -- can happen in a non-error case, but no harm in testing for this.
10827 elsif Is_Private_Type
(Typ
) then
10829 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10834 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
10838 -- For any other type (are there any?) assume partially initialized
10843 end Is_Partially_Initialized_Type
;
10845 ------------------------------------
10846 -- Is_Potentially_Persistent_Type --
10847 ------------------------------------
10849 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
10854 -- For private type, test corresponding full type
10856 if Is_Private_Type
(T
) then
10857 return Is_Potentially_Persistent_Type
(Full_View
(T
));
10859 -- Scalar types are potentially persistent
10861 elsif Is_Scalar_Type
(T
) then
10864 -- Record type is potentially persistent if not tagged and the types of
10865 -- all it components are potentially persistent, and no component has
10866 -- an initialization expression.
10868 elsif Is_Record_Type
(T
)
10869 and then not Is_Tagged_Type
(T
)
10870 and then not Is_Partially_Initialized_Type
(T
)
10872 Comp
:= First_Component
(T
);
10873 while Present
(Comp
) loop
10874 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
10877 Next_Entity
(Comp
);
10883 -- Array type is potentially persistent if its component type is
10884 -- potentially persistent and if all its constraints are static.
10886 elsif Is_Array_Type
(T
) then
10887 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
10891 Indx
:= First_Index
(T
);
10892 while Present
(Indx
) loop
10893 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
10902 -- All other types are not potentially persistent
10907 end Is_Potentially_Persistent_Type
;
10909 --------------------------------
10910 -- Is_Potentially_Unevaluated --
10911 --------------------------------
10913 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
10920 while not Nkind_In
(Par
, N_If_Expression
,
10928 Par
:= Parent
(Par
);
10930 -- If the context is not an expression, or if is the result of
10931 -- expansion of an enclosing construct (such as another attribute)
10932 -- the predicate does not apply.
10934 if Nkind
(Par
) not in N_Subexpr
10935 or else not Comes_From_Source
(Par
)
10941 if Nkind
(Par
) = N_If_Expression
then
10942 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
10944 elsif Nkind
(Par
) = N_Case_Expression
then
10945 return Expr
/= Expression
(Par
);
10947 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
10948 return Expr
= Right_Opnd
(Par
);
10950 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
10951 return Expr
/= Left_Opnd
(Par
);
10956 end Is_Potentially_Unevaluated
;
10958 ---------------------------------
10959 -- Is_Protected_Self_Reference --
10960 ---------------------------------
10962 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
10964 function In_Access_Definition
(N
: Node_Id
) return Boolean;
10965 -- Returns true if N belongs to an access definition
10967 --------------------------
10968 -- In_Access_Definition --
10969 --------------------------
10971 function In_Access_Definition
(N
: Node_Id
) return Boolean is
10976 while Present
(P
) loop
10977 if Nkind
(P
) = N_Access_Definition
then
10985 end In_Access_Definition
;
10987 -- Start of processing for Is_Protected_Self_Reference
10990 -- Verify that prefix is analyzed and has the proper form. Note that
10991 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
10992 -- which also produce the address of an entity, do not analyze their
10993 -- prefix because they denote entities that are not necessarily visible.
10994 -- Neither of them can apply to a protected type.
10996 return Ada_Version
>= Ada_2005
10997 and then Is_Entity_Name
(N
)
10998 and then Present
(Entity
(N
))
10999 and then Is_Protected_Type
(Entity
(N
))
11000 and then In_Open_Scopes
(Entity
(N
))
11001 and then not In_Access_Definition
(N
);
11002 end Is_Protected_Self_Reference
;
11004 -----------------------------
11005 -- Is_RCI_Pkg_Spec_Or_Body --
11006 -----------------------------
11008 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
11010 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
11011 -- Return True if the unit of Cunit is an RCI package declaration
11013 ---------------------------
11014 -- Is_RCI_Pkg_Decl_Cunit --
11015 ---------------------------
11017 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
11018 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
11021 if Nkind
(The_Unit
) /= N_Package_Declaration
then
11025 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
11026 end Is_RCI_Pkg_Decl_Cunit
;
11028 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11031 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
11033 (Nkind
(Unit
(Cunit
)) = N_Package_Body
11034 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
11035 end Is_RCI_Pkg_Spec_Or_Body
;
11037 -----------------------------------------
11038 -- Is_Remote_Access_To_Class_Wide_Type --
11039 -----------------------------------------
11041 function Is_Remote_Access_To_Class_Wide_Type
11042 (E
: Entity_Id
) return Boolean
11045 -- A remote access to class-wide type is a general access to object type
11046 -- declared in the visible part of a Remote_Types or Remote_Call_
11049 return Ekind
(E
) = E_General_Access_Type
11050 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11051 end Is_Remote_Access_To_Class_Wide_Type
;
11053 -----------------------------------------
11054 -- Is_Remote_Access_To_Subprogram_Type --
11055 -----------------------------------------
11057 function Is_Remote_Access_To_Subprogram_Type
11058 (E
: Entity_Id
) return Boolean
11061 return (Ekind
(E
) = E_Access_Subprogram_Type
11062 or else (Ekind
(E
) = E_Record_Type
11063 and then Present
(Corresponding_Remote_Type
(E
))))
11064 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11065 end Is_Remote_Access_To_Subprogram_Type
;
11067 --------------------
11068 -- Is_Remote_Call --
11069 --------------------
11071 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
11073 if Nkind
(N
) not in N_Subprogram_Call
then
11075 -- An entry call cannot be remote
11079 elsif Nkind
(Name
(N
)) in N_Has_Entity
11080 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
11082 -- A subprogram declared in the spec of a RCI package is remote
11086 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
11087 and then Is_Remote_Access_To_Subprogram_Type
11088 (Etype
(Prefix
(Name
(N
))))
11090 -- The dereference of a RAS is a remote call
11094 elsif Present
(Controlling_Argument
(N
))
11095 and then Is_Remote_Access_To_Class_Wide_Type
11096 (Etype
(Controlling_Argument
(N
)))
11098 -- Any primitive operation call with a controlling argument of
11099 -- a RACW type is a remote call.
11104 -- All other calls are local calls
11107 end Is_Remote_Call
;
11109 ----------------------
11110 -- Is_Renamed_Entry --
11111 ----------------------
11113 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
11114 Orig_Node
: Node_Id
:= Empty
;
11115 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
11117 function Is_Entry
(Nam
: Node_Id
) return Boolean;
11118 -- Determine whether Nam is an entry. Traverse selectors if there are
11119 -- nested selected components.
11125 function Is_Entry
(Nam
: Node_Id
) return Boolean is
11127 if Nkind
(Nam
) = N_Selected_Component
then
11128 return Is_Entry
(Selector_Name
(Nam
));
11131 return Ekind
(Entity
(Nam
)) = E_Entry
;
11134 -- Start of processing for Is_Renamed_Entry
11137 if Present
(Alias
(Proc_Nam
)) then
11138 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
11141 -- Look for a rewritten subprogram renaming declaration
11143 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11144 and then Present
(Original_Node
(Subp_Decl
))
11146 Orig_Node
:= Original_Node
(Subp_Decl
);
11149 -- The rewritten subprogram is actually an entry
11151 if Present
(Orig_Node
)
11152 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
11153 and then Is_Entry
(Name
(Orig_Node
))
11159 end Is_Renamed_Entry
;
11161 ----------------------------
11162 -- Is_Reversible_Iterator --
11163 ----------------------------
11165 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
11166 Ifaces_List
: Elist_Id
;
11167 Iface_Elmt
: Elmt_Id
;
11171 if Is_Class_Wide_Type
(Typ
)
11172 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
11174 Is_Predefined_File_Name
11175 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
11179 elsif not Is_Tagged_Type
(Typ
)
11180 or else not Is_Derived_Type
(Typ
)
11185 Collect_Interfaces
(Typ
, Ifaces_List
);
11187 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
11188 while Present
(Iface_Elmt
) loop
11189 Iface
:= Node
(Iface_Elmt
);
11190 if Chars
(Iface
) = Name_Reversible_Iterator
11192 Is_Predefined_File_Name
11193 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
11198 Next_Elmt
(Iface_Elmt
);
11203 end Is_Reversible_Iterator
;
11205 ----------------------
11206 -- Is_Selector_Name --
11207 ----------------------
11209 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
11211 if not Is_List_Member
(N
) then
11213 P
: constant Node_Id
:= Parent
(N
);
11214 K
: constant Node_Kind
:= Nkind
(P
);
11217 (K
= N_Expanded_Name
or else
11218 K
= N_Generic_Association
or else
11219 K
= N_Parameter_Association
or else
11220 K
= N_Selected_Component
)
11221 and then Selector_Name
(P
) = N
;
11226 L
: constant List_Id
:= List_Containing
(N
);
11227 P
: constant Node_Id
:= Parent
(L
);
11229 return (Nkind
(P
) = N_Discriminant_Association
11230 and then Selector_Names
(P
) = L
)
11232 (Nkind
(P
) = N_Component_Association
11233 and then Choices
(P
) = L
);
11236 end Is_Selector_Name
;
11238 ----------------------------------
11239 -- Is_SPARK_Initialization_Expr --
11240 ----------------------------------
11242 function Is_SPARK_Initialization_Expr
(N
: Node_Id
) return Boolean is
11245 Comp_Assn
: Node_Id
;
11246 Orig_N
: constant Node_Id
:= Original_Node
(N
);
11251 if not Comes_From_Source
(Orig_N
) then
11255 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
11257 case Nkind
(Orig_N
) is
11258 when N_Character_Literal |
11259 N_Integer_Literal |
11261 N_String_Literal
=>
11264 when N_Identifier |
11266 if Is_Entity_Name
(Orig_N
)
11267 and then Present
(Entity
(Orig_N
)) -- needed in some cases
11269 case Ekind
(Entity
(Orig_N
)) is
11271 E_Enumeration_Literal |
11276 if Is_Type
(Entity
(Orig_N
)) then
11284 when N_Qualified_Expression |
11285 N_Type_Conversion
=>
11286 Is_Ok
:= Is_SPARK_Initialization_Expr
(Expression
(Orig_N
));
11289 Is_Ok
:= Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
11293 N_Membership_Test
=>
11294 Is_Ok
:= Is_SPARK_Initialization_Expr
(Left_Opnd
(Orig_N
))
11295 and then Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
11298 N_Extension_Aggregate
=>
11299 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
11300 Is_Ok
:= Is_SPARK_Initialization_Expr
(Ancestor_Part
(Orig_N
));
11303 Expr
:= First
(Expressions
(Orig_N
));
11304 while Present
(Expr
) loop
11305 if not Is_SPARK_Initialization_Expr
(Expr
) then
11313 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
11314 while Present
(Comp_Assn
) loop
11315 Expr
:= Expression
(Comp_Assn
);
11316 if Present
(Expr
) -- needed for box association
11317 and then not Is_SPARK_Initialization_Expr
(Expr
)
11326 when N_Attribute_Reference
=>
11327 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
11328 Is_Ok
:= Is_SPARK_Initialization_Expr
(Prefix
(Orig_N
));
11331 Expr
:= First
(Expressions
(Orig_N
));
11332 while Present
(Expr
) loop
11333 if not Is_SPARK_Initialization_Expr
(Expr
) then
11341 -- Selected components might be expanded named not yet resolved, so
11342 -- default on the safe side. (Eg on sparklex.ads)
11344 when N_Selected_Component
=>
11353 end Is_SPARK_Initialization_Expr
;
11355 -------------------------------
11356 -- Is_SPARK_Object_Reference --
11357 -------------------------------
11359 function Is_SPARK_Object_Reference
(N
: Node_Id
) return Boolean is
11361 if Is_Entity_Name
(N
) then
11362 return Present
(Entity
(N
))
11364 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
11365 or else Ekind
(Entity
(N
)) in Formal_Kind
);
11369 when N_Selected_Component
=>
11370 return Is_SPARK_Object_Reference
(Prefix
(N
));
11376 end Is_SPARK_Object_Reference
;
11378 ------------------------------
11379 -- Is_SPARK_Volatile_Object --
11380 ------------------------------
11382 function Is_SPARK_Volatile_Object
(N
: Node_Id
) return Boolean is
11384 if Nkind
(N
) = N_Defining_Identifier
then
11385 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
11387 elsif Is_Entity_Name
(N
) then
11389 Is_SPARK_Volatile_Object
(Entity
(N
))
11390 or else Is_Volatile
(Etype
(N
));
11392 elsif Nkind
(N
) = N_Expanded_Name
then
11393 return Is_SPARK_Volatile_Object
(Entity
(N
));
11395 elsif Nkind
(N
) = N_Indexed_Component
then
11396 return Is_SPARK_Volatile_Object
(Prefix
(N
));
11398 elsif Nkind
(N
) = N_Selected_Component
then
11400 Is_SPARK_Volatile_Object
(Prefix
(N
))
11402 Is_SPARK_Volatile_Object
(Selector_Name
(N
));
11407 end Is_SPARK_Volatile_Object
;
11413 function Is_Statement
(N
: Node_Id
) return Boolean is
11416 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
11417 or else Nkind
(N
) = N_Procedure_Call_Statement
;
11420 --------------------------------------------------
11421 -- Is_Subprogram_Stub_Without_Prior_Declaration --
11422 --------------------------------------------------
11424 function Is_Subprogram_Stub_Without_Prior_Declaration
11425 (N
: Node_Id
) return Boolean
11428 -- A subprogram stub without prior declaration serves as declaration for
11429 -- the actual subprogram body. As such, it has an attached defining
11430 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
11432 return Nkind
(N
) = N_Subprogram_Body_Stub
11433 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
11434 end Is_Subprogram_Stub_Without_Prior_Declaration
;
11436 ---------------------------------
11437 -- Is_Synchronized_Tagged_Type --
11438 ---------------------------------
11440 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
11441 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
11444 -- A task or protected type derived from an interface is a tagged type.
11445 -- Such a tagged type is called a synchronized tagged type, as are
11446 -- synchronized interfaces and private extensions whose declaration
11447 -- includes the reserved word synchronized.
11449 return (Is_Tagged_Type
(E
)
11450 and then (Kind
= E_Task_Type
11451 or else Kind
= E_Protected_Type
))
11454 and then Is_Synchronized_Interface
(E
))
11456 (Ekind
(E
) = E_Record_Type_With_Private
11457 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
11458 and then (Synchronized_Present
(Parent
(E
))
11459 or else Is_Synchronized_Interface
(Etype
(E
))));
11460 end Is_Synchronized_Tagged_Type
;
11466 function Is_Transfer
(N
: Node_Id
) return Boolean is
11467 Kind
: constant Node_Kind
:= Nkind
(N
);
11470 if Kind
= N_Simple_Return_Statement
11472 Kind
= N_Extended_Return_Statement
11474 Kind
= N_Goto_Statement
11476 Kind
= N_Raise_Statement
11478 Kind
= N_Requeue_Statement
11482 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
11483 and then No
(Condition
(N
))
11487 elsif Kind
= N_Procedure_Call_Statement
11488 and then Is_Entity_Name
(Name
(N
))
11489 and then Present
(Entity
(Name
(N
)))
11490 and then No_Return
(Entity
(Name
(N
)))
11494 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
11506 function Is_True
(U
: Uint
) return Boolean is
11511 --------------------------------------
11512 -- Is_Unchecked_Conversion_Instance --
11513 --------------------------------------
11515 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
11516 Gen_Par
: Entity_Id
;
11519 -- Look for a function whose generic parent is the predefined intrinsic
11520 -- function Unchecked_Conversion.
11522 if Ekind
(Id
) = E_Function
then
11523 Gen_Par
:= Generic_Parent
(Parent
(Id
));
11527 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
11528 and then Is_Intrinsic_Subprogram
(Gen_Par
)
11529 and then Is_Predefined_File_Name
11530 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
11534 end Is_Unchecked_Conversion_Instance
;
11536 -------------------------------
11537 -- Is_Universal_Numeric_Type --
11538 -------------------------------
11540 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
11542 return T
= Universal_Integer
or else T
= Universal_Real
;
11543 end Is_Universal_Numeric_Type
;
11545 -------------------
11546 -- Is_Value_Type --
11547 -------------------
11549 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
11551 return VM_Target
= CLI_Target
11552 and then Nkind
(T
) in N_Has_Chars
11553 and then Chars
(T
) /= No_Name
11554 and then Get_Name_String
(Chars
(T
)) = "valuetype";
11557 ----------------------------
11558 -- Is_Variable_Size_Array --
11559 ----------------------------
11561 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
11565 pragma Assert
(Is_Array_Type
(E
));
11567 -- Check if some index is initialized with a non-constant value
11569 Idx
:= First_Index
(E
);
11570 while Present
(Idx
) loop
11571 if Nkind
(Idx
) = N_Range
then
11572 if not Is_Constant_Bound
(Low_Bound
(Idx
))
11573 or else not Is_Constant_Bound
(High_Bound
(Idx
))
11579 Idx
:= Next_Index
(Idx
);
11583 end Is_Variable_Size_Array
;
11585 -----------------------------
11586 -- Is_Variable_Size_Record --
11587 -----------------------------
11589 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
11591 Comp_Typ
: Entity_Id
;
11594 pragma Assert
(Is_Record_Type
(E
));
11596 Comp
:= First_Entity
(E
);
11597 while Present
(Comp
) loop
11598 Comp_Typ
:= Etype
(Comp
);
11600 -- Recursive call if the record type has discriminants
11602 if Is_Record_Type
(Comp_Typ
)
11603 and then Has_Discriminants
(Comp_Typ
)
11604 and then Is_Variable_Size_Record
(Comp_Typ
)
11608 elsif Is_Array_Type
(Comp_Typ
)
11609 and then Is_Variable_Size_Array
(Comp_Typ
)
11614 Next_Entity
(Comp
);
11618 end Is_Variable_Size_Record
;
11620 ---------------------
11621 -- Is_VMS_Operator --
11622 ---------------------
11624 function Is_VMS_Operator
(Op
: Entity_Id
) return Boolean is
11626 -- The VMS operators are declared in a child of System that is loaded
11627 -- through pragma Extend_System. In some rare cases a program is run
11628 -- with this extension but without indicating that the target is VMS.
11630 return Ekind
(Op
) = E_Function
11631 and then Is_Intrinsic_Subprogram
(Op
)
11633 ((Present_System_Aux
and then Scope
(Op
) = System_Aux_Id
)
11636 and then Scope
(Scope
(Op
)) = RTU_Entity
(System
)));
11637 end Is_VMS_Operator
;
11643 function Is_Variable
11645 Use_Original_Node
: Boolean := True) return Boolean
11647 Orig_Node
: Node_Id
;
11649 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
11650 -- Within a protected function, the private components of the enclosing
11651 -- protected type are constants. A function nested within a (protected)
11652 -- procedure is not itself protected. Within the body of a protected
11653 -- function the current instance of the protected type is a constant.
11655 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
11656 -- Prefixes can involve implicit dereferences, in which case we must
11657 -- test for the case of a reference of a constant access type, which can
11658 -- can never be a variable.
11660 ---------------------------
11661 -- In_Protected_Function --
11662 ---------------------------
11664 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
11669 -- E is the current instance of a type
11671 if Is_Type
(E
) then
11680 if not Is_Protected_Type
(Prot
) then
11684 S
:= Current_Scope
;
11685 while Present
(S
) and then S
/= Prot
loop
11686 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
11695 end In_Protected_Function
;
11697 ------------------------
11698 -- Is_Variable_Prefix --
11699 ------------------------
11701 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
11703 if Is_Access_Type
(Etype
(P
)) then
11704 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
11706 -- For the case of an indexed component whose prefix has a packed
11707 -- array type, the prefix has been rewritten into a type conversion.
11708 -- Determine variable-ness from the converted expression.
11710 elsif Nkind
(P
) = N_Type_Conversion
11711 and then not Comes_From_Source
(P
)
11712 and then Is_Array_Type
(Etype
(P
))
11713 and then Is_Packed
(Etype
(P
))
11715 return Is_Variable
(Expression
(P
));
11718 return Is_Variable
(P
);
11720 end Is_Variable_Prefix
;
11722 -- Start of processing for Is_Variable
11725 -- Check if we perform the test on the original node since this may be a
11726 -- test of syntactic categories which must not be disturbed by whatever
11727 -- rewriting might have occurred. For example, an aggregate, which is
11728 -- certainly NOT a variable, could be turned into a variable by
11731 if Use_Original_Node
then
11732 Orig_Node
:= Original_Node
(N
);
11737 -- Definitely OK if Assignment_OK is set. Since this is something that
11738 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
11740 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
11743 -- Normally we go to the original node, but there is one exception where
11744 -- we use the rewritten node, namely when it is an explicit dereference.
11745 -- The generated code may rewrite a prefix which is an access type with
11746 -- an explicit dereference. The dereference is a variable, even though
11747 -- the original node may not be (since it could be a constant of the
11750 -- In Ada 2005 we have a further case to consider: the prefix may be a
11751 -- function call given in prefix notation. The original node appears to
11752 -- be a selected component, but we need to examine the call.
11754 elsif Nkind
(N
) = N_Explicit_Dereference
11755 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
11756 and then Present
(Etype
(Orig_Node
))
11757 and then Is_Access_Type
(Etype
(Orig_Node
))
11759 -- Note that if the prefix is an explicit dereference that does not
11760 -- come from source, we must check for a rewritten function call in
11761 -- prefixed notation before other forms of rewriting, to prevent a
11765 (Nkind
(Orig_Node
) = N_Function_Call
11766 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
11768 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
11770 -- in Ada 2012, the dereference may have been added for a type with
11771 -- a declared implicit dereference aspect.
11773 elsif Nkind
(N
) = N_Explicit_Dereference
11774 and then Present
(Etype
(Orig_Node
))
11775 and then Ada_Version
>= Ada_2012
11776 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
11780 -- A function call is never a variable
11782 elsif Nkind
(N
) = N_Function_Call
then
11785 -- All remaining checks use the original node
11787 elsif Is_Entity_Name
(Orig_Node
)
11788 and then Present
(Entity
(Orig_Node
))
11791 E
: constant Entity_Id
:= Entity
(Orig_Node
);
11792 K
: constant Entity_Kind
:= Ekind
(E
);
11795 return (K
= E_Variable
11796 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
11797 or else (K
= E_Component
11798 and then not In_Protected_Function
(E
))
11799 or else K
= E_Out_Parameter
11800 or else K
= E_In_Out_Parameter
11801 or else K
= E_Generic_In_Out_Parameter
11803 -- Current instance of type. If this is a protected type, check
11804 -- we are not within the body of one of its protected functions.
11806 or else (Is_Type
(E
)
11807 and then In_Open_Scopes
(E
)
11808 and then not In_Protected_Function
(E
))
11810 or else (Is_Incomplete_Or_Private_Type
(E
)
11811 and then In_Open_Scopes
(Full_View
(E
)));
11815 case Nkind
(Orig_Node
) is
11816 when N_Indexed_Component | N_Slice
=>
11817 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
11819 when N_Selected_Component
=>
11820 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
11821 and then Is_Variable
(Selector_Name
(Orig_Node
));
11823 -- For an explicit dereference, the type of the prefix cannot
11824 -- be an access to constant or an access to subprogram.
11826 when N_Explicit_Dereference
=>
11828 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
11830 return Is_Access_Type
(Typ
)
11831 and then not Is_Access_Constant
(Root_Type
(Typ
))
11832 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
11835 -- The type conversion is the case where we do not deal with the
11836 -- context dependent special case of an actual parameter. Thus
11837 -- the type conversion is only considered a variable for the
11838 -- purposes of this routine if the target type is tagged. However,
11839 -- a type conversion is considered to be a variable if it does not
11840 -- come from source (this deals for example with the conversions
11841 -- of expressions to their actual subtypes).
11843 when N_Type_Conversion
=>
11844 return Is_Variable
(Expression
(Orig_Node
))
11846 (not Comes_From_Source
(Orig_Node
)
11848 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
11850 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
11852 -- GNAT allows an unchecked type conversion as a variable. This
11853 -- only affects the generation of internal expanded code, since
11854 -- calls to instantiations of Unchecked_Conversion are never
11855 -- considered variables (since they are function calls).
11857 when N_Unchecked_Type_Conversion
=>
11858 return Is_Variable
(Expression
(Orig_Node
));
11866 ---------------------------
11867 -- Is_Visibly_Controlled --
11868 ---------------------------
11870 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
11871 Root
: constant Entity_Id
:= Root_Type
(T
);
11873 return Chars
(Scope
(Root
)) = Name_Finalization
11874 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
11875 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
11876 end Is_Visibly_Controlled
;
11878 ------------------------
11879 -- Is_Volatile_Object --
11880 ------------------------
11882 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
11884 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
11885 -- If prefix is an implicit dereference, examine designated type
11887 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
11888 -- Determines if given object has volatile components
11890 ------------------------
11891 -- Is_Volatile_Prefix --
11892 ------------------------
11894 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
11895 Typ
: constant Entity_Id
:= Etype
(N
);
11898 if Is_Access_Type
(Typ
) then
11900 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
11903 return Is_Volatile
(Dtyp
)
11904 or else Has_Volatile_Components
(Dtyp
);
11908 return Object_Has_Volatile_Components
(N
);
11910 end Is_Volatile_Prefix
;
11912 ------------------------------------
11913 -- Object_Has_Volatile_Components --
11914 ------------------------------------
11916 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
11917 Typ
: constant Entity_Id
:= Etype
(N
);
11920 if Is_Volatile
(Typ
)
11921 or else Has_Volatile_Components
(Typ
)
11925 elsif Is_Entity_Name
(N
)
11926 and then (Has_Volatile_Components
(Entity
(N
))
11927 or else Is_Volatile
(Entity
(N
)))
11931 elsif Nkind
(N
) = N_Indexed_Component
11932 or else Nkind
(N
) = N_Selected_Component
11934 return Is_Volatile_Prefix
(Prefix
(N
));
11939 end Object_Has_Volatile_Components
;
11941 -- Start of processing for Is_Volatile_Object
11944 if Nkind
(N
) = N_Defining_Identifier
then
11945 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
11947 elsif Nkind
(N
) = N_Expanded_Name
then
11948 return Is_Volatile_Object
(Entity
(N
));
11950 elsif Is_Volatile
(Etype
(N
))
11951 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
11955 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
11956 and then Is_Volatile_Prefix
(Prefix
(N
))
11960 elsif Nkind
(N
) = N_Selected_Component
11961 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
11968 end Is_Volatile_Object
;
11970 ---------------------------
11971 -- Itype_Has_Declaration --
11972 ---------------------------
11974 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
11976 pragma Assert
(Is_Itype
(Id
));
11977 return Present
(Parent
(Id
))
11978 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
11979 N_Subtype_Declaration
)
11980 and then Defining_Entity
(Parent
(Id
)) = Id
;
11981 end Itype_Has_Declaration
;
11983 -------------------------
11984 -- Kill_Current_Values --
11985 -------------------------
11987 procedure Kill_Current_Values
11989 Last_Assignment_Only
: Boolean := False)
11992 if Is_Assignable
(Ent
) then
11993 Set_Last_Assignment
(Ent
, Empty
);
11996 if Is_Object
(Ent
) then
11997 if not Last_Assignment_Only
then
11999 Set_Current_Value
(Ent
, Empty
);
12001 if not Can_Never_Be_Null
(Ent
) then
12002 Set_Is_Known_Non_Null
(Ent
, False);
12005 Set_Is_Known_Null
(Ent
, False);
12007 -- Reset Is_Known_Valid unless type is always valid, or if we have
12008 -- a loop parameter (loop parameters are always valid, since their
12009 -- bounds are defined by the bounds given in the loop header).
12011 if not Is_Known_Valid
(Etype
(Ent
))
12012 and then Ekind
(Ent
) /= E_Loop_Parameter
12014 Set_Is_Known_Valid
(Ent
, False);
12018 end Kill_Current_Values
;
12020 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
12023 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
12024 -- Clear current value for entity E and all entities chained to E
12026 ------------------------------------------
12027 -- Kill_Current_Values_For_Entity_Chain --
12028 ------------------------------------------
12030 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
12034 while Present
(Ent
) loop
12035 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
12038 end Kill_Current_Values_For_Entity_Chain
;
12040 -- Start of processing for Kill_Current_Values
12043 -- Kill all saved checks, a special case of killing saved values
12045 if not Last_Assignment_Only
then
12049 -- Loop through relevant scopes, which includes the current scope and
12050 -- any parent scopes if the current scope is a block or a package.
12052 S
:= Current_Scope
;
12055 -- Clear current values of all entities in current scope
12057 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
12059 -- If scope is a package, also clear current values of all private
12060 -- entities in the scope.
12062 if Is_Package_Or_Generic_Package
(S
)
12063 or else Is_Concurrent_Type
(S
)
12065 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
12068 -- If this is a not a subprogram, deal with parents
12070 if not Is_Subprogram
(S
) then
12072 exit Scope_Loop
when S
= Standard_Standard
;
12076 end loop Scope_Loop
;
12077 end Kill_Current_Values
;
12079 --------------------------
12080 -- Kill_Size_Check_Code --
12081 --------------------------
12083 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
12085 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
12086 and then Present
(Size_Check_Code
(E
))
12088 Remove
(Size_Check_Code
(E
));
12089 Set_Size_Check_Code
(E
, Empty
);
12091 end Kill_Size_Check_Code
;
12093 --------------------------
12094 -- Known_To_Be_Assigned --
12095 --------------------------
12097 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
12098 P
: constant Node_Id
:= Parent
(N
);
12103 -- Test left side of assignment
12105 when N_Assignment_Statement
=>
12106 return N
= Name
(P
);
12108 -- Function call arguments are never lvalues
12110 when N_Function_Call
=>
12113 -- Positional parameter for procedure or accept call
12115 when N_Procedure_Call_Statement |
12124 Proc
:= Get_Subprogram_Entity
(P
);
12130 -- If we are not a list member, something is strange, so
12131 -- be conservative and return False.
12133 if not Is_List_Member
(N
) then
12137 -- We are going to find the right formal by stepping forward
12138 -- through the formals, as we step backwards in the actuals.
12140 Form
:= First_Formal
(Proc
);
12143 -- If no formal, something is weird, so be conservative
12144 -- and return False.
12151 exit when No
(Act
);
12152 Next_Formal
(Form
);
12155 return Ekind
(Form
) /= E_In_Parameter
;
12158 -- Named parameter for procedure or accept call
12160 when N_Parameter_Association
=>
12166 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
12172 -- Loop through formals to find the one that matches
12174 Form
:= First_Formal
(Proc
);
12176 -- If no matching formal, that's peculiar, some kind of
12177 -- previous error, so return False to be conservative.
12178 -- Actually this also happens in legal code in the case
12179 -- where P is a parameter association for an Extra_Formal???
12185 -- Else test for match
12187 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
12188 return Ekind
(Form
) /= E_In_Parameter
;
12191 Next_Formal
(Form
);
12195 -- Test for appearing in a conversion that itself appears
12196 -- in an lvalue context, since this should be an lvalue.
12198 when N_Type_Conversion
=>
12199 return Known_To_Be_Assigned
(P
);
12201 -- All other references are definitely not known to be modifications
12207 end Known_To_Be_Assigned
;
12209 ---------------------------
12210 -- Last_Source_Statement --
12211 ---------------------------
12213 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
12217 N
:= Last
(Statements
(HSS
));
12218 while Present
(N
) loop
12219 exit when Comes_From_Source
(N
);
12224 end Last_Source_Statement
;
12226 ----------------------------------
12227 -- Matching_Static_Array_Bounds --
12228 ----------------------------------
12230 function Matching_Static_Array_Bounds
12232 R_Typ
: Node_Id
) return Boolean
12234 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
12235 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
12247 if L_Ndims
/= R_Ndims
then
12251 -- Unconstrained types do not have static bounds
12253 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
12257 -- First treat specially the first dimension, as the lower bound and
12258 -- length of string literals are not stored like those of arrays.
12260 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
12261 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
12262 L_Len
:= String_Literal_Length
(L_Typ
);
12264 L_Index
:= First_Index
(L_Typ
);
12265 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
12267 if Is_OK_Static_Expression
(L_Low
)
12268 and then Is_OK_Static_Expression
(L_High
)
12270 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
12273 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
12280 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
12281 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
12282 R_Len
:= String_Literal_Length
(R_Typ
);
12284 R_Index
:= First_Index
(R_Typ
);
12285 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
12287 if Is_OK_Static_Expression
(R_Low
)
12288 and then Is_OK_Static_Expression
(R_High
)
12290 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
12293 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
12300 if Is_OK_Static_Expression
(L_Low
)
12301 and then Is_OK_Static_Expression
(R_Low
)
12302 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
12303 and then L_Len
= R_Len
12310 -- Then treat all other dimensions
12312 for Indx
in 2 .. L_Ndims
loop
12316 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
12317 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
12319 if Is_OK_Static_Expression
(L_Low
)
12320 and then Is_OK_Static_Expression
(L_High
)
12321 and then Is_OK_Static_Expression
(R_Low
)
12322 and then Is_OK_Static_Expression
(R_High
)
12323 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
12324 and then Expr_Value
(L_High
) = Expr_Value
(R_High
)
12332 -- If we fall through the loop, all indexes matched
12335 end Matching_Static_Array_Bounds
;
12337 -------------------
12338 -- May_Be_Lvalue --
12339 -------------------
12341 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
12342 P
: constant Node_Id
:= Parent
(N
);
12347 -- Test left side of assignment
12349 when N_Assignment_Statement
=>
12350 return N
= Name
(P
);
12352 -- Test prefix of component or attribute. Note that the prefix of an
12353 -- explicit or implicit dereference cannot be an l-value.
12355 when N_Attribute_Reference
=>
12356 return N
= Prefix
(P
)
12357 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
12359 -- For an expanded name, the name is an lvalue if the expanded name
12360 -- is an lvalue, but the prefix is never an lvalue, since it is just
12361 -- the scope where the name is found.
12363 when N_Expanded_Name
=>
12364 if N
= Prefix
(P
) then
12365 return May_Be_Lvalue
(P
);
12370 -- For a selected component A.B, A is certainly an lvalue if A.B is.
12371 -- B is a little interesting, if we have A.B := 3, there is some
12372 -- discussion as to whether B is an lvalue or not, we choose to say
12373 -- it is. Note however that A is not an lvalue if it is of an access
12374 -- type since this is an implicit dereference.
12376 when N_Selected_Component
=>
12378 and then Present
(Etype
(N
))
12379 and then Is_Access_Type
(Etype
(N
))
12383 return May_Be_Lvalue
(P
);
12386 -- For an indexed component or slice, the index or slice bounds is
12387 -- never an lvalue. The prefix is an lvalue if the indexed component
12388 -- or slice is an lvalue, except if it is an access type, where we
12389 -- have an implicit dereference.
12391 when N_Indexed_Component | N_Slice
=>
12393 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
12397 return May_Be_Lvalue
(P
);
12400 -- Prefix of a reference is an lvalue if the reference is an lvalue
12402 when N_Reference
=>
12403 return May_Be_Lvalue
(P
);
12405 -- Prefix of explicit dereference is never an lvalue
12407 when N_Explicit_Dereference
=>
12410 -- Positional parameter for subprogram, entry, or accept call.
12411 -- In older versions of Ada function call arguments are never
12412 -- lvalues. In Ada 2012 functions can have in-out parameters.
12414 when N_Subprogram_Call |
12415 N_Entry_Call_Statement |
12418 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
12422 -- The following mechanism is clumsy and fragile. A single flag
12423 -- set in Resolve_Actuals would be preferable ???
12431 Proc
:= Get_Subprogram_Entity
(P
);
12437 -- If we are not a list member, something is strange, so be
12438 -- conservative and return True.
12440 if not Is_List_Member
(N
) then
12444 -- We are going to find the right formal by stepping forward
12445 -- through the formals, as we step backwards in the actuals.
12447 Form
:= First_Formal
(Proc
);
12450 -- If no formal, something is weird, so be conservative and
12458 exit when No
(Act
);
12459 Next_Formal
(Form
);
12462 return Ekind
(Form
) /= E_In_Parameter
;
12465 -- Named parameter for procedure or accept call
12467 when N_Parameter_Association
=>
12473 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
12479 -- Loop through formals to find the one that matches
12481 Form
:= First_Formal
(Proc
);
12483 -- If no matching formal, that's peculiar, some kind of
12484 -- previous error, so return True to be conservative.
12485 -- Actually happens with legal code for an unresolved call
12486 -- where we may get the wrong homonym???
12492 -- Else test for match
12494 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
12495 return Ekind
(Form
) /= E_In_Parameter
;
12498 Next_Formal
(Form
);
12502 -- Test for appearing in a conversion that itself appears in an
12503 -- lvalue context, since this should be an lvalue.
12505 when N_Type_Conversion
=>
12506 return May_Be_Lvalue
(P
);
12508 -- Test for appearance in object renaming declaration
12510 when N_Object_Renaming_Declaration
=>
12513 -- All other references are definitely not lvalues
12521 -----------------------
12522 -- Mark_Coextensions --
12523 -----------------------
12525 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
12526 Is_Dynamic
: Boolean;
12527 -- Indicates whether the context causes nested coextensions to be
12528 -- dynamic or static
12530 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
12531 -- Recognize an allocator node and label it as a dynamic coextension
12533 --------------------
12534 -- Mark_Allocator --
12535 --------------------
12537 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
12539 if Nkind
(N
) = N_Allocator
then
12541 Set_Is_Dynamic_Coextension
(N
);
12543 -- If the allocator expression is potentially dynamic, it may
12544 -- be expanded out of order and require dynamic allocation
12545 -- anyway, so we treat the coextension itself as dynamic.
12546 -- Potential optimization ???
12548 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
12549 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
12551 Set_Is_Dynamic_Coextension
(N
);
12553 Set_Is_Static_Coextension
(N
);
12558 end Mark_Allocator
;
12560 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
12562 -- Start of processing Mark_Coextensions
12565 case Nkind
(Context_Nod
) is
12567 -- Comment here ???
12569 when N_Assignment_Statement
=>
12570 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
12572 -- An allocator that is a component of a returned aggregate
12573 -- must be dynamic.
12575 when N_Simple_Return_Statement
=>
12577 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
12580 Nkind
(Expr
) = N_Allocator
12582 (Nkind
(Expr
) = N_Qualified_Expression
12583 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
12586 -- An alloctor within an object declaration in an extended return
12587 -- statement is of necessity dynamic.
12589 when N_Object_Declaration
=>
12590 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
12592 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
12594 -- This routine should not be called for constructs which may not
12595 -- contain coextensions.
12598 raise Program_Error
;
12601 Mark_Allocators
(Root_Nod
);
12602 end Mark_Coextensions
;
12608 function Must_Inline
(Subp
: Entity_Id
) return Boolean is
12611 (Optimization_Level
= 0
12613 -- AAMP and VM targets have no support for inlining in the backend.
12614 -- Hence we do as much inlining as possible in the front end.
12616 or else AAMP_On_Target
12617 or else VM_Target
/= No_VM
)
12618 and then Has_Pragma_Inline
(Subp
)
12619 and then (Has_Pragma_Inline_Always
(Subp
) or else Front_End_Inlining
);
12622 ----------------------
12623 -- Needs_One_Actual --
12624 ----------------------
12626 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
12627 Formal
: Entity_Id
;
12630 -- Ada 2005 or later, and formals present
12632 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
12633 Formal
:= Next_Formal
(First_Formal
(E
));
12634 while Present
(Formal
) loop
12635 if No
(Default_Value
(Formal
)) then
12639 Next_Formal
(Formal
);
12644 -- Ada 83/95 or no formals
12649 end Needs_One_Actual
;
12651 ------------------------
12652 -- New_Copy_List_Tree --
12653 ------------------------
12655 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
12660 if List
= No_List
then
12667 while Present
(E
) loop
12668 Append
(New_Copy_Tree
(E
), NL
);
12674 end New_Copy_List_Tree
;
12676 -------------------
12677 -- New_Copy_Tree --
12678 -------------------
12680 use Atree
.Unchecked_Access
;
12681 use Atree_Private_Part
;
12683 -- Our approach here requires a two pass traversal of the tree. The
12684 -- first pass visits all nodes that eventually will be copied looking
12685 -- for defining Itypes. If any defining Itypes are found, then they are
12686 -- copied, and an entry is added to the replacement map. In the second
12687 -- phase, the tree is copied, using the replacement map to replace any
12688 -- Itype references within the copied tree.
12690 -- The following hash tables are used if the Map supplied has more
12691 -- than hash threshold entries to speed up access to the map. If
12692 -- there are fewer entries, then the map is searched sequentially
12693 -- (because setting up a hash table for only a few entries takes
12694 -- more time than it saves.
12696 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
12697 -- Hash function used for hash operations
12699 -------------------
12700 -- New_Copy_Hash --
12701 -------------------
12703 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
12705 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
12712 -- The hash table NCT_Assoc associates old entities in the table
12713 -- with their corresponding new entities (i.e. the pairs of entries
12714 -- presented in the original Map argument are Key-Element pairs).
12716 package NCT_Assoc
is new Simple_HTable
(
12717 Header_Num
=> NCT_Header_Num
,
12718 Element
=> Entity_Id
,
12719 No_Element
=> Empty
,
12721 Hash
=> New_Copy_Hash
,
12722 Equal
=> Types
."=");
12724 ---------------------
12725 -- NCT_Itype_Assoc --
12726 ---------------------
12728 -- The hash table NCT_Itype_Assoc contains entries only for those
12729 -- old nodes which have a non-empty Associated_Node_For_Itype set.
12730 -- The key is the associated node, and the element is the new node
12731 -- itself (NOT the associated node for the new node).
12733 package NCT_Itype_Assoc
is new Simple_HTable
(
12734 Header_Num
=> NCT_Header_Num
,
12735 Element
=> Entity_Id
,
12736 No_Element
=> Empty
,
12738 Hash
=> New_Copy_Hash
,
12739 Equal
=> Types
."=");
12741 -- Start of processing for New_Copy_Tree function
12743 function New_Copy_Tree
12745 Map
: Elist_Id
:= No_Elist
;
12746 New_Sloc
: Source_Ptr
:= No_Location
;
12747 New_Scope
: Entity_Id
:= Empty
) return Node_Id
12749 Actual_Map
: Elist_Id
:= Map
;
12750 -- This is the actual map for the copy. It is initialized with the
12751 -- given elements, and then enlarged as required for Itypes that are
12752 -- copied during the first phase of the copy operation. The visit
12753 -- procedures add elements to this map as Itypes are encountered.
12754 -- The reason we cannot use Map directly, is that it may well be
12755 -- (and normally is) initialized to No_Elist, and if we have mapped
12756 -- entities, we have to reset it to point to a real Elist.
12758 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
12759 -- Called during second phase to map entities into their corresponding
12760 -- copies using Actual_Map. If the argument is not an entity, or is not
12761 -- in Actual_Map, then it is returned unchanged.
12763 procedure Build_NCT_Hash_Tables
;
12764 -- Builds hash tables (number of elements >= threshold value)
12766 function Copy_Elist_With_Replacement
12767 (Old_Elist
: Elist_Id
) return Elist_Id
;
12768 -- Called during second phase to copy element list doing replacements
12770 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
12771 -- Called during the second phase to process a copied Itype. The actual
12772 -- copy happened during the first phase (so that we could make the entry
12773 -- in the mapping), but we still have to deal with the descendents of
12774 -- the copied Itype and copy them where necessary.
12776 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
12777 -- Called during second phase to copy list doing replacements
12779 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
12780 -- Called during second phase to copy node doing replacements
12782 procedure Visit_Elist
(E
: Elist_Id
);
12783 -- Called during first phase to visit all elements of an Elist
12785 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
12786 -- Visit a single field, recursing to call Visit_Node or Visit_List
12787 -- if the field is a syntactic descendent of the current node (i.e.
12788 -- its parent is Node N).
12790 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
12791 -- Called during first phase to visit subsidiary fields of a defining
12792 -- Itype, and also create a copy and make an entry in the replacement
12793 -- map for the new copy.
12795 procedure Visit_List
(L
: List_Id
);
12796 -- Called during first phase to visit all elements of a List
12798 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
12799 -- Called during first phase to visit a node and all its subtrees
12805 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
12810 if not Has_Extension
(N
) or else No
(Actual_Map
) then
12813 elsif NCT_Hash_Tables_Used
then
12814 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
12816 if Present
(Ent
) then
12822 -- No hash table used, do serial search
12825 E
:= First_Elmt
(Actual_Map
);
12826 while Present
(E
) loop
12827 if Node
(E
) = N
then
12828 return Node
(Next_Elmt
(E
));
12830 E
:= Next_Elmt
(Next_Elmt
(E
));
12838 ---------------------------
12839 -- Build_NCT_Hash_Tables --
12840 ---------------------------
12842 procedure Build_NCT_Hash_Tables
is
12846 if NCT_Hash_Table_Setup
then
12848 NCT_Itype_Assoc
.Reset
;
12851 Elmt
:= First_Elmt
(Actual_Map
);
12852 while Present
(Elmt
) loop
12853 Ent
:= Node
(Elmt
);
12855 -- Get new entity, and associate old and new
12858 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
12860 if Is_Type
(Ent
) then
12862 Anode
: constant Entity_Id
:=
12863 Associated_Node_For_Itype
(Ent
);
12866 if Present
(Anode
) then
12868 -- Enter a link between the associated node of the
12869 -- old Itype and the new Itype, for updating later
12870 -- when node is copied.
12872 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
12880 NCT_Hash_Tables_Used
:= True;
12881 NCT_Hash_Table_Setup
:= True;
12882 end Build_NCT_Hash_Tables
;
12884 ---------------------------------
12885 -- Copy_Elist_With_Replacement --
12886 ---------------------------------
12888 function Copy_Elist_With_Replacement
12889 (Old_Elist
: Elist_Id
) return Elist_Id
12892 New_Elist
: Elist_Id
;
12895 if No
(Old_Elist
) then
12899 New_Elist
:= New_Elmt_List
;
12901 M
:= First_Elmt
(Old_Elist
);
12902 while Present
(M
) loop
12903 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
12909 end Copy_Elist_With_Replacement
;
12911 ---------------------------------
12912 -- Copy_Itype_With_Replacement --
12913 ---------------------------------
12915 -- This routine exactly parallels its phase one analog Visit_Itype,
12917 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
12919 -- Translate Next_Entity, Scope and Etype fields, in case they
12920 -- reference entities that have been mapped into copies.
12922 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
12923 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
12925 if Present
(New_Scope
) then
12926 Set_Scope
(New_Itype
, New_Scope
);
12928 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
12931 -- Copy referenced fields
12933 if Is_Discrete_Type
(New_Itype
) then
12934 Set_Scalar_Range
(New_Itype
,
12935 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
12937 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
12938 Set_Discriminant_Constraint
(New_Itype
,
12939 Copy_Elist_With_Replacement
12940 (Discriminant_Constraint
(New_Itype
)));
12942 elsif Is_Array_Type
(New_Itype
) then
12943 if Present
(First_Index
(New_Itype
)) then
12944 Set_First_Index
(New_Itype
,
12945 First
(Copy_List_With_Replacement
12946 (List_Containing
(First_Index
(New_Itype
)))));
12949 if Is_Packed
(New_Itype
) then
12950 Set_Packed_Array_Type
(New_Itype
,
12951 Copy_Node_With_Replacement
12952 (Packed_Array_Type
(New_Itype
)));
12955 end Copy_Itype_With_Replacement
;
12957 --------------------------------
12958 -- Copy_List_With_Replacement --
12959 --------------------------------
12961 function Copy_List_With_Replacement
12962 (Old_List
: List_Id
) return List_Id
12964 New_List
: List_Id
;
12968 if Old_List
= No_List
then
12972 New_List
:= Empty_List
;
12974 E
:= First
(Old_List
);
12975 while Present
(E
) loop
12976 Append
(Copy_Node_With_Replacement
(E
), New_List
);
12982 end Copy_List_With_Replacement
;
12984 --------------------------------
12985 -- Copy_Node_With_Replacement --
12986 --------------------------------
12988 function Copy_Node_With_Replacement
12989 (Old_Node
: Node_Id
) return Node_Id
12991 New_Node
: Node_Id
;
12993 procedure Adjust_Named_Associations
12994 (Old_Node
: Node_Id
;
12995 New_Node
: Node_Id
);
12996 -- If a call node has named associations, these are chained through
12997 -- the First_Named_Actual, Next_Named_Actual links. These must be
12998 -- propagated separately to the new parameter list, because these
12999 -- are not syntactic fields.
13001 function Copy_Field_With_Replacement
13002 (Field
: Union_Id
) return Union_Id
;
13003 -- Given Field, which is a field of Old_Node, return a copy of it
13004 -- if it is a syntactic field (i.e. its parent is Node), setting
13005 -- the parent of the copy to poit to New_Node. Otherwise returns
13006 -- the field (possibly mapped if it is an entity).
13008 -------------------------------
13009 -- Adjust_Named_Associations --
13010 -------------------------------
13012 procedure Adjust_Named_Associations
13013 (Old_Node
: Node_Id
;
13014 New_Node
: Node_Id
)
13019 Old_Next
: Node_Id
;
13020 New_Next
: Node_Id
;
13023 Old_E
:= First
(Parameter_Associations
(Old_Node
));
13024 New_E
:= First
(Parameter_Associations
(New_Node
));
13025 while Present
(Old_E
) loop
13026 if Nkind
(Old_E
) = N_Parameter_Association
13027 and then Present
(Next_Named_Actual
(Old_E
))
13029 if First_Named_Actual
(Old_Node
)
13030 = Explicit_Actual_Parameter
(Old_E
)
13032 Set_First_Named_Actual
13033 (New_Node
, Explicit_Actual_Parameter
(New_E
));
13036 -- Now scan parameter list from the beginning,to locate
13037 -- next named actual, which can be out of order.
13039 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
13040 New_Next
:= First
(Parameter_Associations
(New_Node
));
13042 while Nkind
(Old_Next
) /= N_Parameter_Association
13043 or else Explicit_Actual_Parameter
(Old_Next
)
13044 /= Next_Named_Actual
(Old_E
)
13050 Set_Next_Named_Actual
13051 (New_E
, Explicit_Actual_Parameter
(New_Next
));
13057 end Adjust_Named_Associations
;
13059 ---------------------------------
13060 -- Copy_Field_With_Replacement --
13061 ---------------------------------
13063 function Copy_Field_With_Replacement
13064 (Field
: Union_Id
) return Union_Id
13067 if Field
= Union_Id
(Empty
) then
13070 elsif Field
in Node_Range
then
13072 Old_N
: constant Node_Id
:= Node_Id
(Field
);
13076 -- If syntactic field, as indicated by the parent pointer
13077 -- being set, then copy the referenced node recursively.
13079 if Parent
(Old_N
) = Old_Node
then
13080 New_N
:= Copy_Node_With_Replacement
(Old_N
);
13082 if New_N
/= Old_N
then
13083 Set_Parent
(New_N
, New_Node
);
13086 -- For semantic fields, update possible entity reference
13087 -- from the replacement map.
13090 New_N
:= Assoc
(Old_N
);
13093 return Union_Id
(New_N
);
13096 elsif Field
in List_Range
then
13098 Old_L
: constant List_Id
:= List_Id
(Field
);
13102 -- If syntactic field, as indicated by the parent pointer,
13103 -- then recursively copy the entire referenced list.
13105 if Parent
(Old_L
) = Old_Node
then
13106 New_L
:= Copy_List_With_Replacement
(Old_L
);
13107 Set_Parent
(New_L
, New_Node
);
13109 -- For semantic list, just returned unchanged
13115 return Union_Id
(New_L
);
13118 -- Anything other than a list or a node is returned unchanged
13123 end Copy_Field_With_Replacement
;
13125 -- Start of processing for Copy_Node_With_Replacement
13128 if Old_Node
<= Empty_Or_Error
then
13131 elsif Has_Extension
(Old_Node
) then
13132 return Assoc
(Old_Node
);
13135 New_Node
:= New_Copy
(Old_Node
);
13137 -- If the node we are copying is the associated node of a
13138 -- previously copied Itype, then adjust the associated node
13139 -- of the copy of that Itype accordingly.
13141 if Present
(Actual_Map
) then
13147 -- Case of hash table used
13149 if NCT_Hash_Tables_Used
then
13150 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
13152 if Present
(Ent
) then
13153 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
13156 -- Case of no hash table used
13159 E
:= First_Elmt
(Actual_Map
);
13160 while Present
(E
) loop
13161 if Is_Itype
(Node
(E
))
13163 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
13165 Set_Associated_Node_For_Itype
13166 (Node
(Next_Elmt
(E
)), New_Node
);
13169 E
:= Next_Elmt
(Next_Elmt
(E
));
13175 -- Recursively copy descendents
13178 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
13180 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
13182 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
13184 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
13186 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
13188 -- Adjust Sloc of new node if necessary
13190 if New_Sloc
/= No_Location
then
13191 Set_Sloc
(New_Node
, New_Sloc
);
13193 -- If we adjust the Sloc, then we are essentially making
13194 -- a completely new node, so the Comes_From_Source flag
13195 -- should be reset to the proper default value.
13197 Nodes
.Table
(New_Node
).Comes_From_Source
:=
13198 Default_Node
.Comes_From_Source
;
13201 -- If the node is call and has named associations,
13202 -- set the corresponding links in the copy.
13204 if (Nkind
(Old_Node
) = N_Function_Call
13205 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
13207 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
13208 and then Present
(First_Named_Actual
(Old_Node
))
13210 Adjust_Named_Associations
(Old_Node
, New_Node
);
13213 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
13214 -- The replacement mechanism applies to entities, and is not used
13215 -- here. Eventually we may need a more general graph-copying
13216 -- routine. For now, do a sequential search to find desired node.
13218 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
13219 and then Present
(First_Real_Statement
(Old_Node
))
13222 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
13226 N1
:= First
(Statements
(Old_Node
));
13227 N2
:= First
(Statements
(New_Node
));
13229 while N1
/= Old_F
loop
13234 Set_First_Real_Statement
(New_Node
, N2
);
13239 -- All done, return copied node
13242 end Copy_Node_With_Replacement
;
13248 procedure Visit_Elist
(E
: Elist_Id
) is
13251 if Present
(E
) then
13252 Elmt
:= First_Elmt
(E
);
13254 while Elmt
/= No_Elmt
loop
13255 Visit_Node
(Node
(Elmt
));
13265 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
13267 if F
= Union_Id
(Empty
) then
13270 elsif F
in Node_Range
then
13272 -- Copy node if it is syntactic, i.e. its parent pointer is
13273 -- set to point to the field that referenced it (certain
13274 -- Itypes will also meet this criterion, which is fine, since
13275 -- these are clearly Itypes that do need to be copied, since
13276 -- we are copying their parent.)
13278 if Parent
(Node_Id
(F
)) = N
then
13279 Visit_Node
(Node_Id
(F
));
13282 -- Another case, if we are pointing to an Itype, then we want
13283 -- to copy it if its associated node is somewhere in the tree
13286 -- Note: the exclusion of self-referential copies is just an
13287 -- optimization, since the search of the already copied list
13288 -- would catch it, but it is a common case (Etype pointing
13289 -- to itself for an Itype that is a base type).
13291 elsif Has_Extension
(Node_Id
(F
))
13292 and then Is_Itype
(Entity_Id
(F
))
13293 and then Node_Id
(F
) /= N
13299 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
13300 while Present
(P
) loop
13302 Visit_Node
(Node_Id
(F
));
13309 -- An Itype whose parent is not being copied definitely
13310 -- should NOT be copied, since it does not belong in any
13311 -- sense to the copied subtree.
13317 elsif F
in List_Range
13318 and then Parent
(List_Id
(F
)) = N
13320 Visit_List
(List_Id
(F
));
13329 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
13330 New_Itype
: Entity_Id
;
13335 -- Itypes that describe the designated type of access to subprograms
13336 -- have the structure of subprogram declarations, with signatures,
13337 -- etc. Either we duplicate the signatures completely, or choose to
13338 -- share such itypes, which is fine because their elaboration will
13339 -- have no side effects.
13341 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
13345 New_Itype
:= New_Copy
(Old_Itype
);
13347 -- The new Itype has all the attributes of the old one, and
13348 -- we just copy the contents of the entity. However, the back-end
13349 -- needs different names for debugging purposes, so we create a
13350 -- new internal name for it in all cases.
13352 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
13354 -- If our associated node is an entity that has already been copied,
13355 -- then set the associated node of the copy to point to the right
13356 -- copy. If we have copied an Itype that is itself the associated
13357 -- node of some previously copied Itype, then we set the right
13358 -- pointer in the other direction.
13360 if Present
(Actual_Map
) then
13362 -- Case of hash tables used
13364 if NCT_Hash_Tables_Used
then
13366 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
13368 if Present
(Ent
) then
13369 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
13372 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
13373 if Present
(Ent
) then
13374 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
13376 -- If the hash table has no association for this Itype and
13377 -- its associated node, enter one now.
13380 NCT_Itype_Assoc
.Set
13381 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
13384 -- Case of hash tables not used
13387 E
:= First_Elmt
(Actual_Map
);
13388 while Present
(E
) loop
13389 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
13390 Set_Associated_Node_For_Itype
13391 (New_Itype
, Node
(Next_Elmt
(E
)));
13394 if Is_Type
(Node
(E
))
13396 Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
13398 Set_Associated_Node_For_Itype
13399 (Node
(Next_Elmt
(E
)), New_Itype
);
13402 E
:= Next_Elmt
(Next_Elmt
(E
));
13407 if Present
(Freeze_Node
(New_Itype
)) then
13408 Set_Is_Frozen
(New_Itype
, False);
13409 Set_Freeze_Node
(New_Itype
, Empty
);
13412 -- Add new association to map
13414 if No
(Actual_Map
) then
13415 Actual_Map
:= New_Elmt_List
;
13418 Append_Elmt
(Old_Itype
, Actual_Map
);
13419 Append_Elmt
(New_Itype
, Actual_Map
);
13421 if NCT_Hash_Tables_Used
then
13422 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
13425 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13427 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13428 Build_NCT_Hash_Tables
;
13432 -- If a record subtype is simply copied, the entity list will be
13433 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
13435 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
13436 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
13439 -- Visit descendents that eventually get copied
13441 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
13443 if Is_Discrete_Type
(Old_Itype
) then
13444 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
13446 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
13447 -- ??? This should involve call to Visit_Field
13448 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
13450 elsif Is_Array_Type
(Old_Itype
) then
13451 if Present
(First_Index
(Old_Itype
)) then
13452 Visit_Field
(Union_Id
(List_Containing
13453 (First_Index
(Old_Itype
))),
13457 if Is_Packed
(Old_Itype
) then
13458 Visit_Field
(Union_Id
(Packed_Array_Type
(Old_Itype
)),
13468 procedure Visit_List
(L
: List_Id
) is
13471 if L
/= No_List
then
13474 while Present
(N
) loop
13485 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
13487 -- Start of processing for Visit_Node
13490 -- Handle case of an Itype, which must be copied
13492 if Has_Extension
(N
)
13493 and then Is_Itype
(N
)
13495 -- Nothing to do if already in the list. This can happen with an
13496 -- Itype entity that appears more than once in the tree.
13497 -- Note that we do not want to visit descendents in this case.
13499 -- Test for already in list when hash table is used
13501 if NCT_Hash_Tables_Used
then
13502 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
13506 -- Test for already in list when hash table not used
13512 if Present
(Actual_Map
) then
13513 E
:= First_Elmt
(Actual_Map
);
13514 while Present
(E
) loop
13515 if Node
(E
) = N
then
13518 E
:= Next_Elmt
(Next_Elmt
(E
));
13528 -- Visit descendents
13530 Visit_Field
(Field1
(N
), N
);
13531 Visit_Field
(Field2
(N
), N
);
13532 Visit_Field
(Field3
(N
), N
);
13533 Visit_Field
(Field4
(N
), N
);
13534 Visit_Field
(Field5
(N
), N
);
13537 -- Start of processing for New_Copy_Tree
13542 -- See if we should use hash table
13544 if No
(Actual_Map
) then
13545 NCT_Hash_Tables_Used
:= False;
13552 NCT_Table_Entries
:= 0;
13554 Elmt
:= First_Elmt
(Actual_Map
);
13555 while Present
(Elmt
) loop
13556 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13561 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13562 Build_NCT_Hash_Tables
;
13564 NCT_Hash_Tables_Used
:= False;
13569 -- Hash table set up if required, now start phase one by visiting
13570 -- top node (we will recursively visit the descendents).
13572 Visit_Node
(Source
);
13574 -- Now the second phase of the copy can start. First we process
13575 -- all the mapped entities, copying their descendents.
13577 if Present
(Actual_Map
) then
13580 New_Itype
: Entity_Id
;
13582 Elmt
:= First_Elmt
(Actual_Map
);
13583 while Present
(Elmt
) loop
13585 New_Itype
:= Node
(Elmt
);
13586 Copy_Itype_With_Replacement
(New_Itype
);
13592 -- Now we can copy the actual tree
13594 return Copy_Node_With_Replacement
(Source
);
13597 -------------------------
13598 -- New_External_Entity --
13599 -------------------------
13601 function New_External_Entity
13602 (Kind
: Entity_Kind
;
13603 Scope_Id
: Entity_Id
;
13604 Sloc_Value
: Source_Ptr
;
13605 Related_Id
: Entity_Id
;
13606 Suffix
: Character;
13607 Suffix_Index
: Nat
:= 0;
13608 Prefix
: Character := ' ') return Entity_Id
13610 N
: constant Entity_Id
:=
13611 Make_Defining_Identifier
(Sloc_Value
,
13613 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
13616 Set_Ekind
(N
, Kind
);
13617 Set_Is_Internal
(N
, True);
13618 Append_Entity
(N
, Scope_Id
);
13619 Set_Public_Status
(N
);
13621 if Kind
in Type_Kind
then
13622 Init_Size_Align
(N
);
13626 end New_External_Entity
;
13628 -------------------------
13629 -- New_Internal_Entity --
13630 -------------------------
13632 function New_Internal_Entity
13633 (Kind
: Entity_Kind
;
13634 Scope_Id
: Entity_Id
;
13635 Sloc_Value
: Source_Ptr
;
13636 Id_Char
: Character) return Entity_Id
13638 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
13641 Set_Ekind
(N
, Kind
);
13642 Set_Is_Internal
(N
, True);
13643 Append_Entity
(N
, Scope_Id
);
13645 if Kind
in Type_Kind
then
13646 Init_Size_Align
(N
);
13650 end New_Internal_Entity
;
13656 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
13660 -- If we are pointing at a positional parameter, it is a member of a
13661 -- node list (the list of parameters), and the next parameter is the
13662 -- next node on the list, unless we hit a parameter association, then
13663 -- we shift to using the chain whose head is the First_Named_Actual in
13664 -- the parent, and then is threaded using the Next_Named_Actual of the
13665 -- Parameter_Association. All this fiddling is because the original node
13666 -- list is in the textual call order, and what we need is the
13667 -- declaration order.
13669 if Is_List_Member
(Actual_Id
) then
13670 N
:= Next
(Actual_Id
);
13672 if Nkind
(N
) = N_Parameter_Association
then
13673 return First_Named_Actual
(Parent
(Actual_Id
));
13679 return Next_Named_Actual
(Parent
(Actual_Id
));
13683 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
13685 Actual_Id
:= Next_Actual
(Actual_Id
);
13688 ---------------------
13689 -- No_Scalar_Parts --
13690 ---------------------
13692 function No_Scalar_Parts
(T
: Entity_Id
) return Boolean is
13696 if Is_Scalar_Type
(T
) then
13699 elsif Is_Array_Type
(T
) then
13700 return No_Scalar_Parts
(Component_Type
(T
));
13702 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
13703 C
:= First_Component_Or_Discriminant
(T
);
13704 while Present
(C
) loop
13705 if not No_Scalar_Parts
(Etype
(C
)) then
13708 Next_Component_Or_Discriminant
(C
);
13714 end No_Scalar_Parts
;
13716 -----------------------
13717 -- Normalize_Actuals --
13718 -----------------------
13720 -- Chain actuals according to formals of subprogram. If there are no named
13721 -- associations, the chain is simply the list of Parameter Associations,
13722 -- since the order is the same as the declaration order. If there are named
13723 -- associations, then the First_Named_Actual field in the N_Function_Call
13724 -- or N_Procedure_Call_Statement node points to the Parameter_Association
13725 -- node for the parameter that comes first in declaration order. The
13726 -- remaining named parameters are then chained in declaration order using
13727 -- Next_Named_Actual.
13729 -- This routine also verifies that the number of actuals is compatible with
13730 -- the number and default values of formals, but performs no type checking
13731 -- (type checking is done by the caller).
13733 -- If the matching succeeds, Success is set to True and the caller proceeds
13734 -- with type-checking. If the match is unsuccessful, then Success is set to
13735 -- False, and the caller attempts a different interpretation, if there is
13738 -- If the flag Report is on, the call is not overloaded, and a failure to
13739 -- match can be reported here, rather than in the caller.
13741 procedure Normalize_Actuals
13745 Success
: out Boolean)
13747 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
13748 Actual
: Node_Id
:= Empty
;
13749 Formal
: Entity_Id
;
13750 Last
: Node_Id
:= Empty
;
13751 First_Named
: Node_Id
:= Empty
;
13754 Formals_To_Match
: Integer := 0;
13755 Actuals_To_Match
: Integer := 0;
13757 procedure Chain
(A
: Node_Id
);
13758 -- Add named actual at the proper place in the list, using the
13759 -- Next_Named_Actual link.
13761 function Reporting
return Boolean;
13762 -- Determines if an error is to be reported. To report an error, we
13763 -- need Report to be True, and also we do not report errors caused
13764 -- by calls to init procs that occur within other init procs. Such
13765 -- errors must always be cascaded errors, since if all the types are
13766 -- declared correctly, the compiler will certainly build decent calls.
13772 procedure Chain
(A
: Node_Id
) is
13776 -- Call node points to first actual in list
13778 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
13781 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
13785 Set_Next_Named_Actual
(Last
, Empty
);
13792 function Reporting
return Boolean is
13797 elsif not Within_Init_Proc
then
13800 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
13808 -- Start of processing for Normalize_Actuals
13811 if Is_Access_Type
(S
) then
13813 -- The name in the call is a function call that returns an access
13814 -- to subprogram. The designated type has the list of formals.
13816 Formal
:= First_Formal
(Designated_Type
(S
));
13818 Formal
:= First_Formal
(S
);
13821 while Present
(Formal
) loop
13822 Formals_To_Match
:= Formals_To_Match
+ 1;
13823 Next_Formal
(Formal
);
13826 -- Find if there is a named association, and verify that no positional
13827 -- associations appear after named ones.
13829 if Present
(Actuals
) then
13830 Actual
:= First
(Actuals
);
13833 while Present
(Actual
)
13834 and then Nkind
(Actual
) /= N_Parameter_Association
13836 Actuals_To_Match
:= Actuals_To_Match
+ 1;
13840 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
13842 -- Most common case: positional notation, no defaults
13847 elsif Actuals_To_Match
> Formals_To_Match
then
13849 -- Too many actuals: will not work
13852 if Is_Entity_Name
(Name
(N
)) then
13853 Error_Msg_N
("too many arguments in call to&", Name
(N
));
13855 Error_Msg_N
("too many arguments in call", N
);
13863 First_Named
:= Actual
;
13865 while Present
(Actual
) loop
13866 if Nkind
(Actual
) /= N_Parameter_Association
then
13868 ("positional parameters not allowed after named ones", Actual
);
13873 Actuals_To_Match
:= Actuals_To_Match
+ 1;
13879 if Present
(Actuals
) then
13880 Actual
:= First
(Actuals
);
13883 Formal
:= First_Formal
(S
);
13884 while Present
(Formal
) loop
13886 -- Match the formals in order. If the corresponding actual is
13887 -- positional, nothing to do. Else scan the list of named actuals
13888 -- to find the one with the right name.
13890 if Present
(Actual
)
13891 and then Nkind
(Actual
) /= N_Parameter_Association
13894 Actuals_To_Match
:= Actuals_To_Match
- 1;
13895 Formals_To_Match
:= Formals_To_Match
- 1;
13898 -- For named parameters, search the list of actuals to find
13899 -- one that matches the next formal name.
13901 Actual
:= First_Named
;
13903 while Present
(Actual
) loop
13904 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
13907 Actuals_To_Match
:= Actuals_To_Match
- 1;
13908 Formals_To_Match
:= Formals_To_Match
- 1;
13916 if Ekind
(Formal
) /= E_In_Parameter
13917 or else No
(Default_Value
(Formal
))
13920 if (Comes_From_Source
(S
)
13921 or else Sloc
(S
) = Standard_Location
)
13922 and then Is_Overloadable
(S
)
13926 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
13928 (Nkind
(Parent
(N
)) = N_Function_Call
13930 Nkind
(Parent
(N
)) = N_Parameter_Association
))
13931 and then Ekind
(S
) /= E_Function
13933 Set_Etype
(N
, Etype
(S
));
13935 Error_Msg_Name_1
:= Chars
(S
);
13936 Error_Msg_Sloc
:= Sloc
(S
);
13938 ("missing argument for parameter & " &
13939 "in call to % declared #", N
, Formal
);
13942 elsif Is_Overloadable
(S
) then
13943 Error_Msg_Name_1
:= Chars
(S
);
13945 -- Point to type derivation that generated the
13948 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
13951 ("missing argument for parameter & " &
13952 "in call to % (inherited) #", N
, Formal
);
13956 ("missing argument for parameter &", N
, Formal
);
13964 Formals_To_Match
:= Formals_To_Match
- 1;
13969 Next_Formal
(Formal
);
13972 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
13979 -- Find some superfluous named actual that did not get
13980 -- attached to the list of associations.
13982 Actual
:= First
(Actuals
);
13983 while Present
(Actual
) loop
13984 if Nkind
(Actual
) = N_Parameter_Association
13985 and then Actual
/= Last
13986 and then No
(Next_Named_Actual
(Actual
))
13988 Error_Msg_N
("unmatched actual & in call",
13989 Selector_Name
(Actual
));
14000 end Normalize_Actuals
;
14002 --------------------------------
14003 -- Note_Possible_Modification --
14004 --------------------------------
14006 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
14007 Modification_Comes_From_Source
: constant Boolean :=
14008 Comes_From_Source
(Parent
(N
));
14014 -- Loop to find referenced entity, if there is one
14020 if Is_Entity_Name
(Exp
) then
14021 Ent
:= Entity
(Exp
);
14023 -- If the entity is missing, it is an undeclared identifier,
14024 -- and there is nothing to annotate.
14030 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
14032 P
: constant Node_Id
:= Prefix
(Exp
);
14035 -- In formal verification mode, keep track of all reads and
14036 -- writes through explicit dereferences.
14038 if GNATprove_Mode
then
14039 SPARK_Specific
.Generate_Dereference
(N
, 'm');
14042 if Nkind
(P
) = N_Selected_Component
14043 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
14045 -- Case of a reference to an entry formal
14047 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
14049 elsif Nkind
(P
) = N_Identifier
14050 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
14051 and then Present
(Expression
(Parent
(Entity
(P
))))
14052 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
14055 -- Case of a reference to a value on which side effects have
14058 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
14066 elsif Nkind_In
(Exp
, N_Type_Conversion
,
14067 N_Unchecked_Type_Conversion
)
14069 Exp
:= Expression
(Exp
);
14072 elsif Nkind_In
(Exp
, N_Slice
,
14073 N_Indexed_Component
,
14074 N_Selected_Component
)
14076 -- Special check, if the prefix is an access type, then return
14077 -- since we are modifying the thing pointed to, not the prefix.
14078 -- When we are expanding, most usually the prefix is replaced
14079 -- by an explicit dereference, and this test is not needed, but
14080 -- in some cases (notably -gnatc mode and generics) when we do
14081 -- not do full expansion, we need this special test.
14083 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
14086 -- Otherwise go to prefix and keep going
14089 Exp
:= Prefix
(Exp
);
14093 -- All other cases, not a modification
14099 -- Now look for entity being referenced
14101 if Present
(Ent
) then
14102 if Is_Object
(Ent
) then
14103 if Comes_From_Source
(Exp
)
14104 or else Modification_Comes_From_Source
14106 -- Give warning if pragma unmodified given and we are
14107 -- sure this is a modification.
14109 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
14111 ("??pragma Unmodified given for &!", N
, Ent
);
14114 Set_Never_Set_In_Source
(Ent
, False);
14117 Set_Is_True_Constant
(Ent
, False);
14118 Set_Current_Value
(Ent
, Empty
);
14119 Set_Is_Known_Null
(Ent
, False);
14121 if not Can_Never_Be_Null
(Ent
) then
14122 Set_Is_Known_Non_Null
(Ent
, False);
14125 -- Follow renaming chain
14127 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
14128 and then Present
(Renamed_Object
(Ent
))
14130 Exp
:= Renamed_Object
(Ent
);
14132 -- If the entity is the loop variable in an iteration over
14133 -- a container, retrieve container expression to indicate
14134 -- possible modificastion.
14136 if Present
(Related_Expression
(Ent
))
14137 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
14138 N_Iterator_Specification
14140 Exp
:= Original_Node
(Related_Expression
(Ent
));
14145 -- The expression may be the renaming of a subcomponent of an
14146 -- array or container. The assignment to the subcomponent is
14147 -- a modification of the container.
14149 elsif Comes_From_Source
(Original_Node
(Exp
))
14150 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
14151 N_Indexed_Component
)
14153 Exp
:= Prefix
(Original_Node
(Exp
));
14157 -- Generate a reference only if the assignment comes from
14158 -- source. This excludes, for example, calls to a dispatching
14159 -- assignment operation when the left-hand side is tagged. In
14160 -- GNATprove mode, we need those references also on generated
14161 -- code, as these are used to compute the local effects of
14164 if Modification_Comes_From_Source
or GNATprove_Mode
then
14165 Generate_Reference
(Ent
, Exp
, 'm');
14167 -- If the target of the assignment is the bound variable
14168 -- in an iterator, indicate that the corresponding array
14169 -- or container is also modified.
14171 if Ada_Version
>= Ada_2012
14173 Nkind
(Parent
(Ent
)) = N_Iterator_Specification
14176 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
14179 -- TBD : in the full version of the construct, the
14180 -- domain of iteration can be given by an expression.
14182 if Is_Entity_Name
(Domain
) then
14183 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
14184 Set_Is_True_Constant
(Entity
(Domain
), False);
14185 Set_Never_Set_In_Source
(Entity
(Domain
), False);
14191 Check_Nested_Access
(Ent
);
14196 -- If we are sure this is a modification from source, and we know
14197 -- this modifies a constant, then give an appropriate warning.
14199 if Overlays_Constant
(Ent
)
14200 and then Modification_Comes_From_Source
14204 A
: constant Node_Id
:= Address_Clause
(Ent
);
14206 if Present
(A
) then
14208 Exp
: constant Node_Id
:= Expression
(A
);
14210 if Nkind
(Exp
) = N_Attribute_Reference
14211 and then Attribute_Name
(Exp
) = Name_Address
14212 and then Is_Entity_Name
(Prefix
(Exp
))
14214 Error_Msg_Sloc
:= Sloc
(A
);
14216 ("constant& may be modified via address "
14217 & "clause#??", N
, Entity
(Prefix
(Exp
)));
14230 end Note_Possible_Modification
;
14232 -------------------------
14233 -- Object_Access_Level --
14234 -------------------------
14236 -- Returns the static accessibility level of the view denoted by Obj. Note
14237 -- that the value returned is the result of a call to Scope_Depth. Only
14238 -- scope depths associated with dynamic scopes can actually be returned.
14239 -- Since only relative levels matter for accessibility checking, the fact
14240 -- that the distance between successive levels of accessibility is not
14241 -- always one is immaterial (invariant: if level(E2) is deeper than
14242 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
14244 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
14245 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
14246 -- Determine whether N is a construct of the form
14247 -- Some_Type (Operand._tag'Address)
14248 -- This construct appears in the context of dispatching calls.
14250 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
14251 -- An explicit dereference is created when removing side-effects from
14252 -- expressions for constraint checking purposes. In this case a local
14253 -- access type is created for it. The correct access level is that of
14254 -- the original source node. We detect this case by noting that the
14255 -- prefix of the dereference is created by an object declaration whose
14256 -- initial expression is a reference.
14258 -----------------------------
14259 -- Is_Interface_Conversion --
14260 -----------------------------
14262 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
14265 Nkind
(N
) = N_Unchecked_Type_Conversion
14266 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
14267 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
14268 end Is_Interface_Conversion
;
14274 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
14275 Pref
: constant Node_Id
:= Prefix
(Obj
);
14277 if Is_Entity_Name
(Pref
)
14278 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
14279 and then Present
(Expression
(Parent
(Entity
(Pref
))))
14280 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
14282 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
14292 -- Start of processing for Object_Access_Level
14295 if Nkind
(Obj
) = N_Defining_Identifier
14296 or else Is_Entity_Name
(Obj
)
14298 if Nkind
(Obj
) = N_Defining_Identifier
then
14304 if Is_Prival
(E
) then
14305 E
:= Prival_Link
(E
);
14308 -- If E is a type then it denotes a current instance. For this case
14309 -- we add one to the normal accessibility level of the type to ensure
14310 -- that current instances are treated as always being deeper than
14311 -- than the level of any visible named access type (see 3.10.2(21)).
14313 if Is_Type
(E
) then
14314 return Type_Access_Level
(E
) + 1;
14316 elsif Present
(Renamed_Object
(E
)) then
14317 return Object_Access_Level
(Renamed_Object
(E
));
14319 -- Similarly, if E is a component of the current instance of a
14320 -- protected type, any instance of it is assumed to be at a deeper
14321 -- level than the type. For a protected object (whose type is an
14322 -- anonymous protected type) its components are at the same level
14323 -- as the type itself.
14325 elsif not Is_Overloadable
(E
)
14326 and then Ekind
(Scope
(E
)) = E_Protected_Type
14327 and then Comes_From_Source
(Scope
(E
))
14329 return Type_Access_Level
(Scope
(E
)) + 1;
14332 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
14335 elsif Nkind
(Obj
) = N_Selected_Component
then
14336 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
14337 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14339 return Object_Access_Level
(Prefix
(Obj
));
14342 elsif Nkind
(Obj
) = N_Indexed_Component
then
14343 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
14344 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14346 return Object_Access_Level
(Prefix
(Obj
));
14349 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
14351 -- If the prefix is a selected access discriminant then we make a
14352 -- recursive call on the prefix, which will in turn check the level
14353 -- of the prefix object of the selected discriminant.
14355 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
14356 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
14358 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
14360 return Object_Access_Level
(Prefix
(Obj
));
14362 -- Detect an interface conversion in the context of a dispatching
14363 -- call. Use the original form of the conversion to find the access
14364 -- level of the operand.
14366 elsif Is_Interface
(Etype
(Obj
))
14367 and then Is_Interface_Conversion
(Prefix
(Obj
))
14368 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
14370 return Object_Access_Level
(Original_Node
(Obj
));
14372 elsif not Comes_From_Source
(Obj
) then
14374 Ref
: constant Node_Id
:= Reference_To
(Obj
);
14376 if Present
(Ref
) then
14377 return Object_Access_Level
(Ref
);
14379 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14384 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14387 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
14388 return Object_Access_Level
(Expression
(Obj
));
14390 elsif Nkind
(Obj
) = N_Function_Call
then
14392 -- Function results are objects, so we get either the access level of
14393 -- the function or, in the case of an indirect call, the level of the
14394 -- access-to-subprogram type. (This code is used for Ada 95, but it
14395 -- looks wrong, because it seems that we should be checking the level
14396 -- of the call itself, even for Ada 95. However, using the Ada 2005
14397 -- version of the code causes regressions in several tests that are
14398 -- compiled with -gnat95. ???)
14400 if Ada_Version
< Ada_2005
then
14401 if Is_Entity_Name
(Name
(Obj
)) then
14402 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
14404 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
14407 -- For Ada 2005, the level of the result object of a function call is
14408 -- defined to be the level of the call's innermost enclosing master.
14409 -- We determine that by querying the depth of the innermost enclosing
14413 Return_Master_Scope_Depth_Of_Call
: declare
14415 function Innermost_Master_Scope_Depth
14416 (N
: Node_Id
) return Uint
;
14417 -- Returns the scope depth of the given node's innermost
14418 -- enclosing dynamic scope (effectively the accessibility
14419 -- level of the innermost enclosing master).
14421 ----------------------------------
14422 -- Innermost_Master_Scope_Depth --
14423 ----------------------------------
14425 function Innermost_Master_Scope_Depth
14426 (N
: Node_Id
) return Uint
14428 Node_Par
: Node_Id
:= Parent
(N
);
14431 -- Locate the nearest enclosing node (by traversing Parents)
14432 -- that Defining_Entity can be applied to, and return the
14433 -- depth of that entity's nearest enclosing dynamic scope.
14435 while Present
(Node_Par
) loop
14436 case Nkind
(Node_Par
) is
14437 when N_Component_Declaration |
14438 N_Entry_Declaration |
14439 N_Formal_Object_Declaration |
14440 N_Formal_Type_Declaration |
14441 N_Full_Type_Declaration |
14442 N_Incomplete_Type_Declaration |
14443 N_Loop_Parameter_Specification |
14444 N_Object_Declaration |
14445 N_Protected_Type_Declaration |
14446 N_Private_Extension_Declaration |
14447 N_Private_Type_Declaration |
14448 N_Subtype_Declaration |
14449 N_Function_Specification |
14450 N_Procedure_Specification |
14451 N_Task_Type_Declaration |
14453 N_Generic_Instantiation |
14455 N_Implicit_Label_Declaration |
14456 N_Package_Declaration |
14457 N_Single_Task_Declaration |
14458 N_Subprogram_Declaration |
14459 N_Generic_Declaration |
14460 N_Renaming_Declaration |
14461 N_Block_Statement |
14462 N_Formal_Subprogram_Declaration |
14463 N_Abstract_Subprogram_Declaration |
14465 N_Exception_Declaration |
14466 N_Formal_Package_Declaration |
14467 N_Number_Declaration |
14468 N_Package_Specification |
14469 N_Parameter_Specification |
14470 N_Single_Protected_Declaration |
14474 (Nearest_Dynamic_Scope
14475 (Defining_Entity
(Node_Par
)));
14481 Node_Par
:= Parent
(Node_Par
);
14484 pragma Assert
(False);
14486 -- Should never reach the following return
14488 return Scope_Depth
(Current_Scope
) + 1;
14489 end Innermost_Master_Scope_Depth
;
14491 -- Start of processing for Return_Master_Scope_Depth_Of_Call
14494 return Innermost_Master_Scope_Depth
(Obj
);
14495 end Return_Master_Scope_Depth_Of_Call
;
14498 -- For convenience we handle qualified expressions, even though they
14499 -- aren't technically object names.
14501 elsif Nkind
(Obj
) = N_Qualified_Expression
then
14502 return Object_Access_Level
(Expression
(Obj
));
14504 -- Otherwise return the scope level of Standard. (If there are cases
14505 -- that fall through to this point they will be treated as having
14506 -- global accessibility for now. ???)
14509 return Scope_Depth
(Standard_Standard
);
14511 end Object_Access_Level
;
14513 --------------------------
14514 -- Original_Aspect_Name --
14515 --------------------------
14517 function Original_Aspect_Name
(N
: Node_Id
) return Name_Id
is
14522 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
14525 if Is_Rewrite_Substitution
(Pras
)
14526 and then Nkind
(Original_Node
(Pras
)) = N_Pragma
14528 Pras
:= Original_Node
(Pras
);
14531 -- Case where we came from aspect specication
14533 if Nkind
(Pras
) = N_Pragma
and then From_Aspect_Specification
(Pras
) then
14534 Pras
:= Corresponding_Aspect
(Pras
);
14537 -- Get name from aspect or pragma
14539 if Nkind
(Pras
) = N_Pragma
then
14540 Name
:= Pragma_Name
(Pras
);
14542 Name
:= Chars
(Identifier
(Pras
));
14545 -- Deal with 'Class
14547 if Class_Present
(Pras
) then
14550 -- Names that need converting to special _xxx form
14558 Name
:= Name_uPost
;
14560 when Name_Invariant
=>
14561 Name
:= Name_uInvariant
;
14563 when Name_Type_Invariant |
14564 Name_Type_Invariant_Class
=>
14565 Name
:= Name_uType_Invariant
;
14567 -- Nothing to do for other cases (e.g. a Check that derived
14568 -- from Pre_Class and has the flag set). Also we do nothing
14569 -- if the name is already in special _xxx form.
14577 end Original_Aspect_Name
;
14578 --------------------------------------
14579 -- Original_Corresponding_Operation --
14580 --------------------------------------
14582 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
14584 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
14587 -- If S is an inherited primitive S2 the original corresponding
14588 -- operation of S is the original corresponding operation of S2
14590 if Present
(Alias
(S
))
14591 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
14593 return Original_Corresponding_Operation
(Alias
(S
));
14595 -- If S overrides an inherited subprogram S2 the original corresponding
14596 -- operation of S is the original corresponding operation of S2
14598 elsif Present
(Overridden_Operation
(S
)) then
14599 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
14601 -- otherwise it is S itself
14606 end Original_Corresponding_Operation
;
14608 -----------------------
14609 -- Private_Component --
14610 -----------------------
14612 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
14613 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
14615 function Trace_Components
14617 Check
: Boolean) return Entity_Id
;
14618 -- Recursive function that does the work, and checks against circular
14619 -- definition for each subcomponent type.
14621 ----------------------
14622 -- Trace_Components --
14623 ----------------------
14625 function Trace_Components
14627 Check
: Boolean) return Entity_Id
14629 Btype
: constant Entity_Id
:= Base_Type
(T
);
14630 Component
: Entity_Id
;
14632 Candidate
: Entity_Id
:= Empty
;
14635 if Check
and then Btype
= Ancestor
then
14636 Error_Msg_N
("circular type definition", Type_Id
);
14640 if Is_Private_Type
(Btype
)
14641 and then not Is_Generic_Type
(Btype
)
14643 if Present
(Full_View
(Btype
))
14644 and then Is_Record_Type
(Full_View
(Btype
))
14645 and then not Is_Frozen
(Btype
)
14647 -- To indicate that the ancestor depends on a private type, the
14648 -- current Btype is sufficient. However, to check for circular
14649 -- definition we must recurse on the full view.
14651 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
14653 if Candidate
= Any_Type
then
14663 elsif Is_Array_Type
(Btype
) then
14664 return Trace_Components
(Component_Type
(Btype
), True);
14666 elsif Is_Record_Type
(Btype
) then
14667 Component
:= First_Entity
(Btype
);
14668 while Present
(Component
)
14669 and then Comes_From_Source
(Component
)
14671 -- Skip anonymous types generated by constrained components
14673 if not Is_Type
(Component
) then
14674 P
:= Trace_Components
(Etype
(Component
), True);
14676 if Present
(P
) then
14677 if P
= Any_Type
then
14685 Next_Entity
(Component
);
14693 end Trace_Components
;
14695 -- Start of processing for Private_Component
14698 return Trace_Components
(Type_Id
, False);
14699 end Private_Component
;
14701 ---------------------------
14702 -- Primitive_Names_Match --
14703 ---------------------------
14705 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
14707 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
14708 -- Given an internal name, returns the corresponding non-internal name
14710 ------------------------
14711 -- Non_Internal_Name --
14712 ------------------------
14714 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
14716 Get_Name_String
(Chars
(E
));
14717 Name_Len
:= Name_Len
- 1;
14719 end Non_Internal_Name
;
14721 -- Start of processing for Primitive_Names_Match
14724 pragma Assert
(Present
(E1
) and then Present
(E2
));
14726 return Chars
(E1
) = Chars
(E2
)
14728 (not Is_Internal_Name
(Chars
(E1
))
14729 and then Is_Internal_Name
(Chars
(E2
))
14730 and then Non_Internal_Name
(E2
) = Chars
(E1
))
14732 (not Is_Internal_Name
(Chars
(E2
))
14733 and then Is_Internal_Name
(Chars
(E1
))
14734 and then Non_Internal_Name
(E1
) = Chars
(E2
))
14736 (Is_Predefined_Dispatching_Operation
(E1
)
14737 and then Is_Predefined_Dispatching_Operation
(E2
)
14738 and then Same_TSS
(E1
, E2
))
14740 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
14741 end Primitive_Names_Match
;
14743 -----------------------
14744 -- Process_End_Label --
14745 -----------------------
14747 procedure Process_End_Label
14756 Label_Ref
: Boolean;
14757 -- Set True if reference to end label itself is required
14760 -- Gets set to the operator symbol or identifier that references the
14761 -- entity Ent. For the child unit case, this is the identifier from the
14762 -- designator. For other cases, this is simply Endl.
14764 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
14765 -- N is an identifier node that appears as a parent unit reference in
14766 -- the case where Ent is a child unit. This procedure generates an
14767 -- appropriate cross-reference entry. E is the corresponding entity.
14769 -------------------------
14770 -- Generate_Parent_Ref --
14771 -------------------------
14773 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
14775 -- If names do not match, something weird, skip reference
14777 if Chars
(E
) = Chars
(N
) then
14779 -- Generate the reference. We do NOT consider this as a reference
14780 -- for unreferenced symbol purposes.
14782 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
14784 if Style_Check
then
14785 Style
.Check_Identifier
(N
, E
);
14788 end Generate_Parent_Ref
;
14790 -- Start of processing for Process_End_Label
14793 -- If no node, ignore. This happens in some error situations, and
14794 -- also for some internally generated structures where no end label
14795 -- references are required in any case.
14801 -- Nothing to do if no End_Label, happens for internally generated
14802 -- constructs where we don't want an end label reference anyway. Also
14803 -- nothing to do if Endl is a string literal, which means there was
14804 -- some prior error (bad operator symbol)
14806 Endl
:= End_Label
(N
);
14808 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
14812 -- Reference node is not in extended main source unit
14814 if not In_Extended_Main_Source_Unit
(N
) then
14816 -- Generally we do not collect references except for the extended
14817 -- main source unit. The one exception is the 'e' entry for a
14818 -- package spec, where it is useful for a client to have the
14819 -- ending information to define scopes.
14825 Label_Ref
:= False;
14827 -- For this case, we can ignore any parent references, but we
14828 -- need the package name itself for the 'e' entry.
14830 if Nkind
(Endl
) = N_Designator
then
14831 Endl
:= Identifier
(Endl
);
14835 -- Reference is in extended main source unit
14840 -- For designator, generate references for the parent entries
14842 if Nkind
(Endl
) = N_Designator
then
14844 -- Generate references for the prefix if the END line comes from
14845 -- source (otherwise we do not need these references) We climb the
14846 -- scope stack to find the expected entities.
14848 if Comes_From_Source
(Endl
) then
14849 Nam
:= Name
(Endl
);
14850 Scop
:= Current_Scope
;
14851 while Nkind
(Nam
) = N_Selected_Component
loop
14852 Scop
:= Scope
(Scop
);
14853 exit when No
(Scop
);
14854 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
14855 Nam
:= Prefix
(Nam
);
14858 if Present
(Scop
) then
14859 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
14863 Endl
:= Identifier
(Endl
);
14867 -- If the end label is not for the given entity, then either we have
14868 -- some previous error, or this is a generic instantiation for which
14869 -- we do not need to make a cross-reference in this case anyway. In
14870 -- either case we simply ignore the call.
14872 if Chars
(Ent
) /= Chars
(Endl
) then
14876 -- If label was really there, then generate a normal reference and then
14877 -- adjust the location in the end label to point past the name (which
14878 -- should almost always be the semicolon).
14880 Loc
:= Sloc
(Endl
);
14882 if Comes_From_Source
(Endl
) then
14884 -- If a label reference is required, then do the style check and
14885 -- generate an l-type cross-reference entry for the label
14888 if Style_Check
then
14889 Style
.Check_Identifier
(Endl
, Ent
);
14892 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
14895 -- Set the location to point past the label (normally this will
14896 -- mean the semicolon immediately following the label). This is
14897 -- done for the sake of the 'e' or 't' entry generated below.
14899 Get_Decoded_Name_String
(Chars
(Endl
));
14900 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
14903 -- In SPARK mode, no missing label is allowed for packages and
14904 -- subprogram bodies. Detect those cases by testing whether
14905 -- Process_End_Label was called for a body (Typ = 't') or a package.
14907 if Restriction_Check_Required
(SPARK_05
)
14908 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
14910 Error_Msg_Node_1
:= Endl
;
14911 Check_SPARK_Restriction
("`END &` required", Endl
, Force
=> True);
14915 -- Now generate the e/t reference
14917 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
14919 -- Restore Sloc, in case modified above, since we have an identifier
14920 -- and the normal Sloc should be left set in the tree.
14922 Set_Sloc
(Endl
, Loc
);
14923 end Process_End_Label
;
14929 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
14930 Seen
: Boolean := False;
14932 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
14933 -- Determine whether node N denotes a reference to Id. If this is the
14934 -- case, set global flag Seen to True and stop the traversal.
14940 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
14942 if Is_Entity_Name
(N
)
14943 and then Present
(Entity
(N
))
14944 and then Entity
(N
) = Id
14953 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
14955 -- Start of processing for Referenced
14958 Inspect_Expression
(Expr
);
14962 ------------------------------------
14963 -- References_Generic_Formal_Type --
14964 ------------------------------------
14966 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
14968 function Process
(N
: Node_Id
) return Traverse_Result
;
14969 -- Process one node in search for generic formal type
14975 function Process
(N
: Node_Id
) return Traverse_Result
is
14977 if Nkind
(N
) in N_Has_Entity
then
14979 E
: constant Entity_Id
:= Entity
(N
);
14981 if Present
(E
) then
14982 if Is_Generic_Type
(E
) then
14984 elsif Present
(Etype
(E
))
14985 and then Is_Generic_Type
(Etype
(E
))
14996 function Traverse
is new Traverse_Func
(Process
);
14997 -- Traverse tree to look for generic type
15000 if Inside_A_Generic
then
15001 return Traverse
(N
) = Abandon
;
15005 end References_Generic_Formal_Type
;
15007 --------------------
15008 -- Remove_Homonym --
15009 --------------------
15011 procedure Remove_Homonym
(E
: Entity_Id
) is
15012 Prev
: Entity_Id
:= Empty
;
15016 if E
= Current_Entity
(E
) then
15017 if Present
(Homonym
(E
)) then
15018 Set_Current_Entity
(Homonym
(E
));
15020 Set_Name_Entity_Id
(Chars
(E
), Empty
);
15024 H
:= Current_Entity
(E
);
15025 while Present
(H
) and then H
/= E
loop
15030 -- If E is not on the homonym chain, nothing to do
15032 if Present
(H
) then
15033 Set_Homonym
(Prev
, Homonym
(E
));
15036 end Remove_Homonym
;
15038 ---------------------
15039 -- Rep_To_Pos_Flag --
15040 ---------------------
15042 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
15044 return New_Occurrence_Of
15045 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
15046 end Rep_To_Pos_Flag
;
15048 --------------------
15049 -- Require_Entity --
15050 --------------------
15052 procedure Require_Entity
(N
: Node_Id
) is
15054 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
15055 if Total_Errors_Detected
/= 0 then
15056 Set_Entity
(N
, Any_Id
);
15058 raise Program_Error
;
15061 end Require_Entity
;
15063 -------------------------------
15064 -- Requires_State_Refinement --
15065 -------------------------------
15067 function Requires_State_Refinement
15068 (Spec_Id
: Entity_Id
;
15069 Body_Id
: Entity_Id
) return Boolean
15071 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
15072 -- Given pragma SPARK_Mode, determine whether the mode is Off
15078 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
15082 -- The default SPARK mode is On
15088 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
15090 -- Then the pragma lacks an argument, the default mode is On
15095 return Chars
(Mode
) = Name_Off
;
15099 -- Start of processing for Requires_State_Refinement
15102 -- A package that does not define at least one abstract state cannot
15103 -- possibly require refinement.
15105 if No
(Abstract_States
(Spec_Id
)) then
15108 -- The package instroduces a single null state which does not merit
15111 elsif Has_Null_Abstract_State
(Spec_Id
) then
15114 -- Check whether the package body is subject to pragma SPARK_Mode. If
15115 -- it is and the mode is Off, the package body is considered to be in
15116 -- regular Ada and does not require refinement.
15118 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
15121 -- The body's SPARK_Mode may be inherited from a similar pragma that
15122 -- appears in the private declarations of the spec. The pragma we are
15123 -- interested appears as the second entry in SPARK_Pragma.
15125 elsif Present
(SPARK_Pragma
(Spec_Id
))
15126 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
15130 -- The spec defines at least one abstract state and the body has no way
15131 -- of circumventing the refinement.
15136 end Requires_State_Refinement
;
15138 ------------------------------
15139 -- Requires_Transient_Scope --
15140 ------------------------------
15142 -- A transient scope is required when variable-sized temporaries are
15143 -- allocated in the primary or secondary stack, or when finalization
15144 -- actions must be generated before the next instruction.
15146 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
15147 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
15149 -- Start of processing for Requires_Transient_Scope
15152 -- This is a private type which is not completed yet. This can only
15153 -- happen in a default expression (of a formal parameter or of a
15154 -- record component). Do not expand transient scope in this case
15159 -- Do not expand transient scope for non-existent procedure return
15161 elsif Typ
= Standard_Void_Type
then
15164 -- Elementary types do not require a transient scope
15166 elsif Is_Elementary_Type
(Typ
) then
15169 -- Generally, indefinite subtypes require a transient scope, since the
15170 -- back end cannot generate temporaries, since this is not a valid type
15171 -- for declaring an object. It might be possible to relax this in the
15172 -- future, e.g. by declaring the maximum possible space for the type.
15174 elsif Is_Indefinite_Subtype
(Typ
) then
15177 -- Functions returning tagged types may dispatch on result so their
15178 -- returned value is allocated on the secondary stack. Controlled
15179 -- type temporaries need finalization.
15181 elsif Is_Tagged_Type
(Typ
)
15182 or else Has_Controlled_Component
(Typ
)
15184 return not Is_Value_Type
(Typ
);
15188 elsif Is_Record_Type
(Typ
) then
15192 Comp
:= First_Entity
(Typ
);
15193 while Present
(Comp
) loop
15194 if Ekind
(Comp
) = E_Component
15195 and then Requires_Transient_Scope
(Etype
(Comp
))
15199 Next_Entity
(Comp
);
15206 -- String literal types never require transient scope
15208 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
15211 -- Array type. Note that we already know that this is a constrained
15212 -- array, since unconstrained arrays will fail the indefinite test.
15214 elsif Is_Array_Type
(Typ
) then
15216 -- If component type requires a transient scope, the array does too
15218 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
15221 -- Otherwise, we only need a transient scope if the size depends on
15222 -- the value of one or more discriminants.
15225 return Size_Depends_On_Discriminant
(Typ
);
15228 -- All other cases do not require a transient scope
15233 end Requires_Transient_Scope
;
15235 --------------------------
15236 -- Reset_Analyzed_Flags --
15237 --------------------------
15239 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
15241 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
15242 -- Function used to reset Analyzed flags in tree. Note that we do
15243 -- not reset Analyzed flags in entities, since there is no need to
15244 -- reanalyze entities, and indeed, it is wrong to do so, since it
15245 -- can result in generating auxiliary stuff more than once.
15247 --------------------
15248 -- Clear_Analyzed --
15249 --------------------
15251 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
15253 if not Has_Extension
(N
) then
15254 Set_Analyzed
(N
, False);
15258 end Clear_Analyzed
;
15260 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
15262 -- Start of processing for Reset_Analyzed_Flags
15265 Reset_Analyzed
(N
);
15266 end Reset_Analyzed_Flags
;
15268 --------------------------------
15269 -- Returns_Unconstrained_Type --
15270 --------------------------------
15272 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
15274 return Ekind
(Subp
) = E_Function
15275 and then not Is_Scalar_Type
(Etype
(Subp
))
15276 and then not Is_Access_Type
(Etype
(Subp
))
15277 and then not Is_Constrained
(Etype
(Subp
));
15278 end Returns_Unconstrained_Type
;
15280 ---------------------------
15281 -- Safe_To_Capture_Value --
15282 ---------------------------
15284 function Safe_To_Capture_Value
15287 Cond
: Boolean := False) return Boolean
15290 -- The only entities for which we track constant values are variables
15291 -- which are not renamings, constants, out parameters, and in out
15292 -- parameters, so check if we have this case.
15294 -- Note: it may seem odd to track constant values for constants, but in
15295 -- fact this routine is used for other purposes than simply capturing
15296 -- the value. In particular, the setting of Known[_Non]_Null.
15298 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
15300 Ekind
(Ent
) = E_Constant
15302 Ekind
(Ent
) = E_Out_Parameter
15304 Ekind
(Ent
) = E_In_Out_Parameter
15308 -- For conditionals, we also allow loop parameters and all formals,
15309 -- including in parameters.
15313 (Ekind
(Ent
) = E_Loop_Parameter
15315 Ekind
(Ent
) = E_In_Parameter
)
15319 -- For all other cases, not just unsafe, but impossible to capture
15320 -- Current_Value, since the above are the only entities which have
15321 -- Current_Value fields.
15327 -- Skip if volatile or aliased, since funny things might be going on in
15328 -- these cases which we cannot necessarily track. Also skip any variable
15329 -- for which an address clause is given, or whose address is taken. Also
15330 -- never capture value of library level variables (an attempt to do so
15331 -- can occur in the case of package elaboration code).
15333 if Treat_As_Volatile
(Ent
)
15334 or else Is_Aliased
(Ent
)
15335 or else Present
(Address_Clause
(Ent
))
15336 or else Address_Taken
(Ent
)
15337 or else (Is_Library_Level_Entity
(Ent
)
15338 and then Ekind
(Ent
) = E_Variable
)
15343 -- OK, all above conditions are met. We also require that the scope of
15344 -- the reference be the same as the scope of the entity, not counting
15345 -- packages and blocks and loops.
15348 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
15349 R_Scope
: Entity_Id
;
15352 R_Scope
:= Current_Scope
;
15353 while R_Scope
/= Standard_Standard
loop
15354 exit when R_Scope
= E_Scope
;
15356 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
15359 R_Scope
:= Scope
(R_Scope
);
15364 -- We also require that the reference does not appear in a context
15365 -- where it is not sure to be executed (i.e. a conditional context
15366 -- or an exception handler). We skip this if Cond is True, since the
15367 -- capturing of values from conditional tests handles this ok.
15380 -- Seems dubious that case expressions are not handled here ???
15383 while Present
(P
) loop
15384 if Nkind
(P
) = N_If_Statement
15385 or else Nkind
(P
) = N_Case_Statement
15386 or else (Nkind
(P
) in N_Short_Circuit
15387 and then Desc
= Right_Opnd
(P
))
15388 or else (Nkind
(P
) = N_If_Expression
15389 and then Desc
/= First
(Expressions
(P
)))
15390 or else Nkind
(P
) = N_Exception_Handler
15391 or else Nkind
(P
) = N_Selective_Accept
15392 or else Nkind
(P
) = N_Conditional_Entry_Call
15393 or else Nkind
(P
) = N_Timed_Entry_Call
15394 or else Nkind
(P
) = N_Asynchronous_Select
15401 -- A special Ada 2012 case: the original node may be part
15402 -- of the else_actions of a conditional expression, in which
15403 -- case it might not have been expanded yet, and appears in
15404 -- a non-syntactic list of actions. In that case it is clearly
15405 -- not safe to save a value.
15408 and then Is_List_Member
(Desc
)
15409 and then No
(Parent
(List_Containing
(Desc
)))
15417 -- OK, looks safe to set value
15420 end Safe_To_Capture_Value
;
15426 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
15427 K1
: constant Node_Kind
:= Nkind
(N1
);
15428 K2
: constant Node_Kind
:= Nkind
(N2
);
15431 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
15432 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
15434 return Chars
(N1
) = Chars
(N2
);
15436 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
15437 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
15439 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
15440 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
15451 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
15452 N1
: constant Node_Id
:= Original_Node
(Node1
);
15453 N2
: constant Node_Id
:= Original_Node
(Node2
);
15454 -- We do the tests on original nodes, since we are most interested
15455 -- in the original source, not any expansion that got in the way.
15457 K1
: constant Node_Kind
:= Nkind
(N1
);
15458 K2
: constant Node_Kind
:= Nkind
(N2
);
15461 -- First case, both are entities with same entity
15463 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
15465 EN1
: constant Entity_Id
:= Entity
(N1
);
15466 EN2
: constant Entity_Id
:= Entity
(N2
);
15468 if Present
(EN1
) and then Present
(EN2
)
15469 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
15470 or else Is_Formal
(EN1
))
15478 -- Second case, selected component with same selector, same record
15480 if K1
= N_Selected_Component
15481 and then K2
= N_Selected_Component
15482 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
15484 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
15486 -- Third case, indexed component with same subscripts, same array
15488 elsif K1
= N_Indexed_Component
15489 and then K2
= N_Indexed_Component
15490 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
15495 E1
:= First
(Expressions
(N1
));
15496 E2
:= First
(Expressions
(N2
));
15497 while Present
(E1
) loop
15498 if not Same_Value
(E1
, E2
) then
15509 -- Fourth case, slice of same array with same bounds
15512 and then K2
= N_Slice
15513 and then Nkind
(Discrete_Range
(N1
)) = N_Range
15514 and then Nkind
(Discrete_Range
(N2
)) = N_Range
15515 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
15516 Low_Bound
(Discrete_Range
(N2
)))
15517 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
15518 High_Bound
(Discrete_Range
(N2
)))
15520 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
15522 -- All other cases, not clearly the same object
15533 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
15538 elsif not Is_Constrained
(T1
)
15539 and then not Is_Constrained
(T2
)
15540 and then Base_Type
(T1
) = Base_Type
(T2
)
15544 -- For now don't bother with case of identical constraints, to be
15545 -- fiddled with later on perhaps (this is only used for optimization
15546 -- purposes, so it is not critical to do a best possible job)
15557 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
15559 if Compile_Time_Known_Value
(Node1
)
15560 and then Compile_Time_Known_Value
(Node2
)
15561 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
15564 elsif Same_Object
(Node1
, Node2
) then
15571 ------------------------
15572 -- Scope_Is_Transient --
15573 ------------------------
15575 function Scope_Is_Transient
return Boolean is
15577 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
15578 end Scope_Is_Transient
;
15584 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
15589 while Scop
/= Standard_Standard
loop
15590 Scop
:= Scope
(Scop
);
15592 if Scop
= Scope2
then
15600 --------------------------
15601 -- Scope_Within_Or_Same --
15602 --------------------------
15604 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
15609 while Scop
/= Standard_Standard
loop
15610 if Scop
= Scope2
then
15613 Scop
:= Scope
(Scop
);
15618 end Scope_Within_Or_Same
;
15620 --------------------
15621 -- Set_Convention --
15622 --------------------
15624 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
15626 Basic_Set_Convention
(E
, Val
);
15629 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
15630 and then Has_Foreign_Convention
(E
)
15632 Set_Can_Use_Internal_Rep
(E
, False);
15635 -- If E is an object or component, and the type of E is an anonymous
15636 -- access type with no convention set, then also set the convention of
15637 -- the anonymous access type. We do not do this for anonymous protected
15638 -- types, since protected types always have the default convention.
15640 if Present
(Etype
(E
))
15641 and then (Is_Object
(E
)
15642 or else Ekind
(E
) = E_Component
15644 -- Allow E_Void (happens for pragma Convention appearing
15645 -- in the middle of a record applying to a component)
15647 or else Ekind
(E
) = E_Void
)
15650 Typ
: constant Entity_Id
:= Etype
(E
);
15653 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
15654 E_Anonymous_Access_Subprogram_Type
)
15655 and then not Has_Convention_Pragma
(Typ
)
15657 Basic_Set_Convention
(Typ
, Val
);
15658 Set_Has_Convention_Pragma
(Typ
);
15660 -- And for the access subprogram type, deal similarly with the
15661 -- designated E_Subprogram_Type if it is also internal (which
15664 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
15666 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
15668 if Ekind
(Dtype
) = E_Subprogram_Type
15669 and then Is_Itype
(Dtype
)
15670 and then not Has_Convention_Pragma
(Dtype
)
15672 Basic_Set_Convention
(Dtype
, Val
);
15673 Set_Has_Convention_Pragma
(Dtype
);
15680 end Set_Convention
;
15682 ------------------------
15683 -- Set_Current_Entity --
15684 ------------------------
15686 -- The given entity is to be set as the currently visible definition of its
15687 -- associated name (i.e. the Node_Id associated with its name). All we have
15688 -- to do is to get the name from the identifier, and then set the
15689 -- associated Node_Id to point to the given entity.
15691 procedure Set_Current_Entity
(E
: Entity_Id
) is
15693 Set_Name_Entity_Id
(Chars
(E
), E
);
15694 end Set_Current_Entity
;
15696 ---------------------------
15697 -- Set_Debug_Info_Needed --
15698 ---------------------------
15700 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
15702 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
15703 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
15704 -- Used to set debug info in a related node if not set already
15706 --------------------------------------
15707 -- Set_Debug_Info_Needed_If_Not_Set --
15708 --------------------------------------
15710 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
15713 and then not Needs_Debug_Info
(E
)
15715 Set_Debug_Info_Needed
(E
);
15717 -- For a private type, indicate that the full view also needs
15718 -- debug information.
15721 and then Is_Private_Type
(E
)
15722 and then Present
(Full_View
(E
))
15724 Set_Debug_Info_Needed
(Full_View
(E
));
15727 end Set_Debug_Info_Needed_If_Not_Set
;
15729 -- Start of processing for Set_Debug_Info_Needed
15732 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
15733 -- indicates that Debug_Info_Needed is never required for the entity.
15736 or else Debug_Info_Off
(T
)
15741 -- Set flag in entity itself. Note that we will go through the following
15742 -- circuitry even if the flag is already set on T. That's intentional,
15743 -- it makes sure that the flag will be set in subsidiary entities.
15745 Set_Needs_Debug_Info
(T
);
15747 -- Set flag on subsidiary entities if not set already
15749 if Is_Object
(T
) then
15750 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
15752 elsif Is_Type
(T
) then
15753 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
15755 if Is_Record_Type
(T
) then
15757 Ent
: Entity_Id
:= First_Entity
(T
);
15759 while Present
(Ent
) loop
15760 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
15765 -- For a class wide subtype, we also need debug information
15766 -- for the equivalent type.
15768 if Ekind
(T
) = E_Class_Wide_Subtype
then
15769 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
15772 elsif Is_Array_Type
(T
) then
15773 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
15776 Indx
: Node_Id
:= First_Index
(T
);
15778 while Present
(Indx
) loop
15779 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
15780 Indx
:= Next_Index
(Indx
);
15784 -- For a packed array type, we also need debug information for
15785 -- the type used to represent the packed array. Conversely, we
15786 -- also need it for the former if we need it for the latter.
15788 if Is_Packed
(T
) then
15789 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
15792 if Is_Packed_Array_Type
(T
) then
15793 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
15796 elsif Is_Access_Type
(T
) then
15797 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
15799 elsif Is_Private_Type
(T
) then
15800 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
15802 elsif Is_Protected_Type
(T
) then
15803 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
15806 end Set_Debug_Info_Needed
;
15808 ----------------------------
15809 -- Set_Entity_With_Checks --
15810 ----------------------------
15812 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
15813 Val_Actual
: Entity_Id
;
15815 Post_Node
: Node_Id
;
15818 -- Unconditionally set the entity
15820 Set_Entity
(N
, Val
);
15822 -- Remaining checks are only done on source nodes
15824 if not Comes_From_Source
(N
) then
15828 -- The node to post on is the selector in the case of an expanded name,
15829 -- and otherwise the node itself.
15831 if Nkind
(N
) = N_Expanded_Name
then
15832 Post_Node
:= Selector_Name
(N
);
15837 -- Check for violation of No_Abort_Statements, which is triggered by
15838 -- call to Ada.Task_Identification.Abort_Task.
15840 if Restriction_Check_Required
(No_Abort_Statements
)
15841 and then (Is_RTE
(Val
, RE_Abort_Task
))
15843 Check_Restriction
(No_Abort_Statements
, Post_Node
);
15846 -- Check for violation of No_Dynamic_Attachment
15848 if Restriction_Check_Required
(No_Dynamic_Attachment
)
15849 and then RTU_Loaded
(Ada_Interrupts
)
15850 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
15851 Is_RTE
(Val
, RE_Is_Attached
) or else
15852 Is_RTE
(Val
, RE_Current_Handler
) or else
15853 Is_RTE
(Val
, RE_Attach_Handler
) or else
15854 Is_RTE
(Val
, RE_Exchange_Handler
) or else
15855 Is_RTE
(Val
, RE_Detach_Handler
) or else
15856 Is_RTE
(Val
, RE_Reference
))
15858 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
15861 -- Check for No_Implementation_Identifiers
15863 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
15865 -- We have an implementation defined entity if it is marked as
15866 -- implementation defined, or is defined in a package marked as
15867 -- implementation defined. However, library packages themselves
15868 -- are excluded (we don't want to flag Interfaces itself, just
15869 -- the entities within it).
15871 if (Is_Implementation_Defined
(Val
)
15873 Is_Implementation_Defined
(Scope
(Val
)))
15874 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
15875 and then Is_Library_Level_Entity
(Val
))
15877 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
15881 -- Do the style check
15884 and then not Suppress_Style_Checks
(Val
)
15885 and then not In_Instance
15887 if Nkind
(N
) = N_Identifier
then
15889 elsif Nkind
(N
) = N_Expanded_Name
then
15890 Nod
:= Selector_Name
(N
);
15895 -- A special situation arises for derived operations, where we want
15896 -- to do the check against the parent (since the Sloc of the derived
15897 -- operation points to the derived type declaration itself).
15900 while not Comes_From_Source
(Val_Actual
)
15901 and then Nkind
(Val_Actual
) in N_Entity
15902 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
15903 or else Is_Subprogram
(Val_Actual
)
15904 or else Is_Generic_Subprogram
(Val_Actual
))
15905 and then Present
(Alias
(Val_Actual
))
15907 Val_Actual
:= Alias
(Val_Actual
);
15910 -- Renaming declarations for generic actuals do not come from source,
15911 -- and have a different name from that of the entity they rename, so
15912 -- there is no style check to perform here.
15914 if Chars
(Nod
) = Chars
(Val_Actual
) then
15915 Style
.Check_Identifier
(Nod
, Val_Actual
);
15919 Set_Entity
(N
, Val
);
15920 end Set_Entity_With_Checks
;
15922 ------------------------
15923 -- Set_Name_Entity_Id --
15924 ------------------------
15926 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
15928 Set_Name_Table_Info
(Id
, Int
(Val
));
15929 end Set_Name_Entity_Id
;
15931 ---------------------
15932 -- Set_Next_Actual --
15933 ---------------------
15935 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
15937 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
15938 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
15940 end Set_Next_Actual
;
15942 ----------------------------------
15943 -- Set_Optimize_Alignment_Flags --
15944 ----------------------------------
15946 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
15948 if Optimize_Alignment
= 'S' then
15949 Set_Optimize_Alignment_Space
(E
);
15950 elsif Optimize_Alignment
= 'T' then
15951 Set_Optimize_Alignment_Time
(E
);
15953 end Set_Optimize_Alignment_Flags
;
15955 -----------------------
15956 -- Set_Public_Status --
15957 -----------------------
15959 procedure Set_Public_Status
(Id
: Entity_Id
) is
15960 S
: constant Entity_Id
:= Current_Scope
;
15962 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
15963 -- Determines if E is defined within handled statement sequence or
15964 -- an if statement, returns True if so, False otherwise.
15966 ----------------------
15967 -- Within_HSS_Or_If --
15968 ----------------------
15970 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
15973 N
:= Declaration_Node
(E
);
15980 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
15986 end Within_HSS_Or_If
;
15988 -- Start of processing for Set_Public_Status
15991 -- Everything in the scope of Standard is public
15993 if S
= Standard_Standard
then
15994 Set_Is_Public
(Id
);
15996 -- Entity is definitely not public if enclosing scope is not public
15998 elsif not Is_Public
(S
) then
16001 -- An object or function declaration that occurs in a handled sequence
16002 -- of statements or within an if statement is the declaration for a
16003 -- temporary object or local subprogram generated by the expander. It
16004 -- never needs to be made public and furthermore, making it public can
16005 -- cause back end problems.
16007 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
16008 N_Function_Specification
)
16009 and then Within_HSS_Or_If
(Id
)
16013 -- Entities in public packages or records are public
16015 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
16016 Set_Is_Public
(Id
);
16018 -- The bounds of an entry family declaration can generate object
16019 -- declarations that are visible to the back-end, e.g. in the
16020 -- the declaration of a composite type that contains tasks.
16022 elsif Is_Concurrent_Type
(S
)
16023 and then not Has_Completion
(S
)
16024 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
16026 Set_Is_Public
(Id
);
16028 end Set_Public_Status
;
16030 -----------------------------
16031 -- Set_Referenced_Modified --
16032 -----------------------------
16034 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
16038 -- Deal with indexed or selected component where prefix is modified
16040 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
16041 Pref
:= Prefix
(N
);
16043 -- If prefix is access type, then it is the designated object that is
16044 -- being modified, which means we have no entity to set the flag on.
16046 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
16049 -- Otherwise chase the prefix
16052 Set_Referenced_Modified
(Pref
, Out_Param
);
16055 -- Otherwise see if we have an entity name (only other case to process)
16057 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
16058 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
16059 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
16061 end Set_Referenced_Modified
;
16063 ----------------------------
16064 -- Set_Scope_Is_Transient --
16065 ----------------------------
16067 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
16069 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
16070 end Set_Scope_Is_Transient
;
16072 -------------------
16073 -- Set_Size_Info --
16074 -------------------
16076 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
16078 -- We copy Esize, but not RM_Size, since in general RM_Size is
16079 -- subtype specific and does not get inherited by all subtypes.
16081 Set_Esize
(T1
, Esize
(T2
));
16082 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
16084 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
16086 Is_Discrete_Or_Fixed_Point_Type
(T2
)
16088 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
16091 Set_Alignment
(T1
, Alignment
(T2
));
16094 --------------------
16095 -- Static_Boolean --
16096 --------------------
16098 function Static_Boolean
(N
: Node_Id
) return Uint
is
16100 Analyze_And_Resolve
(N
, Standard_Boolean
);
16103 or else Error_Posted
(N
)
16104 or else Etype
(N
) = Any_Type
16109 if Is_Static_Expression
(N
) then
16110 if not Raises_Constraint_Error
(N
) then
16111 return Expr_Value
(N
);
16116 elsif Etype
(N
) = Any_Type
then
16120 Flag_Non_Static_Expr
16121 ("static boolean expression required here", N
);
16124 end Static_Boolean
;
16126 --------------------
16127 -- Static_Integer --
16128 --------------------
16130 function Static_Integer
(N
: Node_Id
) return Uint
is
16132 Analyze_And_Resolve
(N
, Any_Integer
);
16135 or else Error_Posted
(N
)
16136 or else Etype
(N
) = Any_Type
16141 if Is_Static_Expression
(N
) then
16142 if not Raises_Constraint_Error
(N
) then
16143 return Expr_Value
(N
);
16148 elsif Etype
(N
) = Any_Type
then
16152 Flag_Non_Static_Expr
16153 ("static integer expression required here", N
);
16156 end Static_Integer
;
16158 --------------------------
16159 -- Statically_Different --
16160 --------------------------
16162 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
16163 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
16164 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
16166 return Is_Entity_Name
(R1
)
16167 and then Is_Entity_Name
(R2
)
16168 and then Entity
(R1
) /= Entity
(R2
)
16169 and then not Is_Formal
(Entity
(R1
))
16170 and then not Is_Formal
(Entity
(R2
));
16171 end Statically_Different
;
16173 --------------------------------------
16174 -- Subject_To_Loop_Entry_Attributes --
16175 --------------------------------------
16177 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
16183 -- The expansion mechanism transform a loop subject to at least one
16184 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
16185 -- the conditional part.
16187 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
16188 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
16190 Stmt
:= Original_Node
(N
);
16194 Nkind
(Stmt
) = N_Loop_Statement
16195 and then Present
(Identifier
(Stmt
))
16196 and then Present
(Entity
(Identifier
(Stmt
)))
16197 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
16198 end Subject_To_Loop_Entry_Attributes
;
16200 -----------------------------
16201 -- Subprogram_Access_Level --
16202 -----------------------------
16204 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
16206 if Present
(Alias
(Subp
)) then
16207 return Subprogram_Access_Level
(Alias
(Subp
));
16209 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
16211 end Subprogram_Access_Level
;
16213 -------------------------------
16214 -- Support_Atomic_Primitives --
16215 -------------------------------
16217 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
16221 -- Verify the alignment of Typ is known
16223 if not Known_Alignment
(Typ
) then
16227 if Known_Static_Esize
(Typ
) then
16228 Size
:= UI_To_Int
(Esize
(Typ
));
16230 -- If the Esize (Object_Size) is unknown at compile time, look at the
16231 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
16233 elsif Known_Static_RM_Size
(Typ
) then
16234 Size
:= UI_To_Int
(RM_Size
(Typ
));
16236 -- Otherwise, the size is considered to be unknown.
16242 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
16243 -- Typ is properly aligned.
16246 when 8 |
16 |
32 |
64 =>
16247 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
16251 end Support_Atomic_Primitives
;
16257 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
16259 if Debug_Flag_W
then
16260 for J
in 0 .. Scope_Stack
.Last
loop
16265 Write_Name
(Chars
(E
));
16266 Write_Str
(" from ");
16267 Write_Location
(Sloc
(N
));
16272 -----------------------
16273 -- Transfer_Entities --
16274 -----------------------
16276 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
16277 Ent
: Entity_Id
:= First_Entity
(From
);
16284 if (Last_Entity
(To
)) = Empty
then
16285 Set_First_Entity
(To
, Ent
);
16287 Set_Next_Entity
(Last_Entity
(To
), Ent
);
16290 Set_Last_Entity
(To
, Last_Entity
(From
));
16292 while Present
(Ent
) loop
16293 Set_Scope
(Ent
, To
);
16295 if not Is_Public
(Ent
) then
16296 Set_Public_Status
(Ent
);
16299 and then Ekind
(Ent
) = E_Record_Subtype
16302 -- The components of the propagated Itype must be public
16308 Comp
:= First_Entity
(Ent
);
16309 while Present
(Comp
) loop
16310 Set_Is_Public
(Comp
);
16311 Next_Entity
(Comp
);
16320 Set_First_Entity
(From
, Empty
);
16321 Set_Last_Entity
(From
, Empty
);
16322 end Transfer_Entities
;
16324 -----------------------
16325 -- Type_Access_Level --
16326 -----------------------
16328 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
16332 Btyp
:= Base_Type
(Typ
);
16334 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
16335 -- simply use the level where the type is declared. This is true for
16336 -- stand-alone object declarations, and for anonymous access types
16337 -- associated with components the level is the same as that of the
16338 -- enclosing composite type. However, special treatment is needed for
16339 -- the cases of access parameters, return objects of an anonymous access
16340 -- type, and, in Ada 95, access discriminants of limited types.
16342 if Ekind
(Btyp
) in Access_Kind
then
16343 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
16345 -- If the type is a nonlocal anonymous access type (such as for
16346 -- an access parameter) we treat it as being declared at the
16347 -- library level to ensure that names such as X.all'access don't
16348 -- fail static accessibility checks.
16350 if not Is_Local_Anonymous_Access
(Typ
) then
16351 return Scope_Depth
(Standard_Standard
);
16353 -- If this is a return object, the accessibility level is that of
16354 -- the result subtype of the enclosing function. The test here is
16355 -- little complicated, because we have to account for extended
16356 -- return statements that have been rewritten as blocks, in which
16357 -- case we have to find and the Is_Return_Object attribute of the
16358 -- itype's associated object. It would be nice to find a way to
16359 -- simplify this test, but it doesn't seem worthwhile to add a new
16360 -- flag just for purposes of this test. ???
16362 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
16365 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
16366 N_Object_Declaration
16367 and then Is_Return_Object
16368 (Defining_Identifier
16369 (Associated_Node_For_Itype
(Btyp
))))
16375 Scop
:= Scope
(Scope
(Btyp
));
16376 while Present
(Scop
) loop
16377 exit when Ekind
(Scop
) = E_Function
;
16378 Scop
:= Scope
(Scop
);
16381 -- Treat the return object's type as having the level of the
16382 -- function's result subtype (as per RM05-6.5(5.3/2)).
16384 return Type_Access_Level
(Etype
(Scop
));
16389 Btyp
:= Root_Type
(Btyp
);
16391 -- The accessibility level of anonymous access types associated with
16392 -- discriminants is that of the current instance of the type, and
16393 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
16395 -- AI-402: access discriminants have accessibility based on the
16396 -- object rather than the type in Ada 2005, so the above paragraph
16399 -- ??? Needs completion with rules from AI-416
16401 if Ada_Version
<= Ada_95
16402 and then Ekind
(Typ
) = E_Anonymous_Access_Type
16403 and then Present
(Associated_Node_For_Itype
(Typ
))
16404 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
16405 N_Discriminant_Specification
16407 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
16411 -- Return library level for a generic formal type. This is done because
16412 -- RM(10.3.2) says that "The statically deeper relationship does not
16413 -- apply to ... a descendant of a generic formal type". Rather than
16414 -- checking at each point where a static accessibility check is
16415 -- performed to see if we are dealing with a formal type, this rule is
16416 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
16417 -- return extreme values for a formal type; Deepest_Type_Access_Level
16418 -- returns Int'Last. By calling the appropriate function from among the
16419 -- two, we ensure that the static accessibility check will pass if we
16420 -- happen to run into a formal type. More specifically, we should call
16421 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
16422 -- call occurs as part of a static accessibility check and the error
16423 -- case is the case where the type's level is too shallow (as opposed
16426 if Is_Generic_Type
(Root_Type
(Btyp
)) then
16427 return Scope_Depth
(Standard_Standard
);
16430 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
16431 end Type_Access_Level
;
16433 ------------------------------------
16434 -- Type_Without_Stream_Operation --
16435 ------------------------------------
16437 function Type_Without_Stream_Operation
16439 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
16441 BT
: constant Entity_Id
:= Base_Type
(T
);
16442 Op_Missing
: Boolean;
16445 if not Restriction_Active
(No_Default_Stream_Attributes
) then
16449 if Is_Elementary_Type
(T
) then
16450 if Op
= TSS_Null
then
16452 No
(TSS
(BT
, TSS_Stream_Read
))
16453 or else No
(TSS
(BT
, TSS_Stream_Write
));
16456 Op_Missing
:= No
(TSS
(BT
, Op
));
16465 elsif Is_Array_Type
(T
) then
16466 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
16468 elsif Is_Record_Type
(T
) then
16474 Comp
:= First_Component
(T
);
16475 while Present
(Comp
) loop
16476 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
16478 if Present
(C_Typ
) then
16482 Next_Component
(Comp
);
16488 elsif Is_Private_Type
(T
)
16489 and then Present
(Full_View
(T
))
16491 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
16495 end Type_Without_Stream_Operation
;
16497 ----------------------------
16498 -- Unique_Defining_Entity --
16499 ----------------------------
16501 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
16503 return Unique_Entity
(Defining_Entity
(N
));
16504 end Unique_Defining_Entity
;
16506 -------------------
16507 -- Unique_Entity --
16508 -------------------
16510 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
16511 U
: Entity_Id
:= E
;
16517 if Present
(Full_View
(E
)) then
16518 U
:= Full_View
(E
);
16522 if Present
(Full_View
(E
)) then
16523 U
:= Full_View
(E
);
16526 when E_Package_Body
=>
16529 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
16533 U
:= Corresponding_Spec
(P
);
16535 when E_Subprogram_Body
=>
16538 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
16544 if Nkind
(P
) = N_Subprogram_Body_Stub
then
16545 if Present
(Library_Unit
(P
)) then
16547 -- Get to the function or procedure (generic) entity through
16548 -- the body entity.
16551 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
16554 U
:= Corresponding_Spec
(P
);
16557 when Formal_Kind
=>
16558 if Present
(Spec_Entity
(E
)) then
16559 U
:= Spec_Entity
(E
);
16573 function Unique_Name
(E
: Entity_Id
) return String is
16575 -- Names of E_Subprogram_Body or E_Package_Body entities are not
16576 -- reliable, as they may not include the overloading suffix. Instead,
16577 -- when looking for the name of E or one of its enclosing scope, we get
16578 -- the name of the corresponding Unique_Entity.
16580 function Get_Scoped_Name
(E
: Entity_Id
) return String;
16581 -- Return the name of E prefixed by all the names of the scopes to which
16582 -- E belongs, except for Standard.
16584 ---------------------
16585 -- Get_Scoped_Name --
16586 ---------------------
16588 function Get_Scoped_Name
(E
: Entity_Id
) return String is
16589 Name
: constant String := Get_Name_String
(Chars
(E
));
16591 if Has_Fully_Qualified_Name
(E
)
16592 or else Scope
(E
) = Standard_Standard
16596 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
16598 end Get_Scoped_Name
;
16600 -- Start of processing for Unique_Name
16603 if E
= Standard_Standard
then
16604 return Get_Name_String
(Name_Standard
);
16606 elsif Scope
(E
) = Standard_Standard
16607 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
16609 return Get_Name_String
(Name_Standard
) & "__" &
16610 Get_Name_String
(Chars
(E
));
16612 elsif Ekind
(E
) = E_Enumeration_Literal
then
16613 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
16616 return Get_Scoped_Name
(Unique_Entity
(E
));
16620 ---------------------
16621 -- Unit_Is_Visible --
16622 ---------------------
16624 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
16625 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
16626 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
16628 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
16629 -- For a child unit, check whether unit appears in a with_clause
16632 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
16633 -- Scan the context clause of one compilation unit looking for a
16634 -- with_clause for the unit in question.
16636 ----------------------------
16637 -- Unit_In_Parent_Context --
16638 ----------------------------
16640 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
16642 if Unit_In_Context
(Par_Unit
) then
16645 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
16646 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
16651 end Unit_In_Parent_Context
;
16653 ---------------------
16654 -- Unit_In_Context --
16655 ---------------------
16657 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
16661 Clause
:= First
(Context_Items
(Comp_Unit
));
16662 while Present
(Clause
) loop
16663 if Nkind
(Clause
) = N_With_Clause
then
16664 if Library_Unit
(Clause
) = U
then
16667 -- The with_clause may denote a renaming of the unit we are
16668 -- looking for, eg. Text_IO which renames Ada.Text_IO.
16671 Renamed_Entity
(Entity
(Name
(Clause
))) =
16672 Defining_Entity
(Unit
(U
))
16682 end Unit_In_Context
;
16684 -- Start of processing for Unit_Is_Visible
16687 -- The currrent unit is directly visible
16692 elsif Unit_In_Context
(Curr
) then
16695 -- If the current unit is a body, check the context of the spec
16697 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
16699 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
16700 and then not Acts_As_Spec
(Unit
(Curr
)))
16702 if Unit_In_Context
(Library_Unit
(Curr
)) then
16707 -- If the spec is a child unit, examine the parents
16709 if Is_Child_Unit
(Curr_Entity
) then
16710 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
16712 Unit_In_Parent_Context
16713 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
16715 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
16721 end Unit_Is_Visible
;
16723 ------------------------------
16724 -- Universal_Interpretation --
16725 ------------------------------
16727 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
16728 Index
: Interp_Index
;
16732 -- The argument may be a formal parameter of an operator or subprogram
16733 -- with multiple interpretations, or else an expression for an actual.
16735 if Nkind
(Opnd
) = N_Defining_Identifier
16736 or else not Is_Overloaded
(Opnd
)
16738 if Etype
(Opnd
) = Universal_Integer
16739 or else Etype
(Opnd
) = Universal_Real
16741 return Etype
(Opnd
);
16747 Get_First_Interp
(Opnd
, Index
, It
);
16748 while Present
(It
.Typ
) loop
16749 if It
.Typ
= Universal_Integer
16750 or else It
.Typ
= Universal_Real
16755 Get_Next_Interp
(Index
, It
);
16760 end Universal_Interpretation
;
16766 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
16768 -- Recurse to handle unlikely case of multiple levels of qualification
16770 if Nkind
(Expr
) = N_Qualified_Expression
then
16771 return Unqualify
(Expression
(Expr
));
16773 -- Normal case, not a qualified expression
16780 -----------------------
16781 -- Visible_Ancestors --
16782 -----------------------
16784 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
16790 pragma Assert
(Is_Record_Type
(Typ
)
16791 and then Is_Tagged_Type
(Typ
));
16793 -- Collect all the parents and progenitors of Typ. If the full-view of
16794 -- private parents and progenitors is available then it is used to
16795 -- generate the list of visible ancestors; otherwise their partial
16796 -- view is added to the resulting list.
16801 Use_Full_View
=> True);
16805 Ifaces_List
=> List_2
,
16806 Exclude_Parents
=> True,
16807 Use_Full_View
=> True);
16809 -- Join the two lists. Avoid duplications because an interface may
16810 -- simultaneously be parent and progenitor of a type.
16812 Elmt
:= First_Elmt
(List_2
);
16813 while Present
(Elmt
) loop
16814 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
16819 end Visible_Ancestors
;
16821 ----------------------
16822 -- Within_Init_Proc --
16823 ----------------------
16825 function Within_Init_Proc
return Boolean is
16829 S
:= Current_Scope
;
16830 while not Is_Overloadable
(S
) loop
16831 if S
= Standard_Standard
then
16838 return Is_Init_Proc
(S
);
16839 end Within_Init_Proc
;
16845 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
16852 elsif SE
= Standard_Standard
then
16864 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
16865 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
16866 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
16868 Matching_Field
: Entity_Id
;
16869 -- Entity to give a more precise suggestion on how to write a one-
16870 -- element positional aggregate.
16872 function Has_One_Matching_Field
return Boolean;
16873 -- Determines if Expec_Type is a record type with a single component or
16874 -- discriminant whose type matches the found type or is one dimensional
16875 -- array whose component type matches the found type. In the case of
16876 -- one discriminant, we ignore the variant parts. That's not accurate,
16877 -- but good enough for the warning.
16879 ----------------------------
16880 -- Has_One_Matching_Field --
16881 ----------------------------
16883 function Has_One_Matching_Field
return Boolean is
16887 Matching_Field
:= Empty
;
16889 if Is_Array_Type
(Expec_Type
)
16890 and then Number_Dimensions
(Expec_Type
) = 1
16892 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
16894 -- Use type name if available. This excludes multidimensional
16895 -- arrays and anonymous arrays.
16897 if Comes_From_Source
(Expec_Type
) then
16898 Matching_Field
:= Expec_Type
;
16900 -- For an assignment, use name of target
16902 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
16903 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
16905 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
16910 elsif not Is_Record_Type
(Expec_Type
) then
16914 E
:= First_Entity
(Expec_Type
);
16919 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
16920 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
16929 if not Covers
(Etype
(E
), Found_Type
) then
16932 elsif Present
(Next_Entity
(E
))
16933 and then (Ekind
(E
) = E_Component
16934 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
16939 Matching_Field
:= E
;
16943 end Has_One_Matching_Field
;
16945 -- Start of processing for Wrong_Type
16948 -- Don't output message if either type is Any_Type, or if a message
16949 -- has already been posted for this node. We need to do the latter
16950 -- check explicitly (it is ordinarily done in Errout), because we
16951 -- are using ! to force the output of the error messages.
16953 if Expec_Type
= Any_Type
16954 or else Found_Type
= Any_Type
16955 or else Error_Posted
(Expr
)
16959 -- If one of the types is a Taft-Amendment type and the other it its
16960 -- completion, it must be an illegal use of a TAT in the spec, for
16961 -- which an error was already emitted. Avoid cascaded errors.
16963 elsif Is_Incomplete_Type
(Expec_Type
)
16964 and then Has_Completion_In_Body
(Expec_Type
)
16965 and then Full_View
(Expec_Type
) = Etype
(Expr
)
16969 elsif Is_Incomplete_Type
(Etype
(Expr
))
16970 and then Has_Completion_In_Body
(Etype
(Expr
))
16971 and then Full_View
(Etype
(Expr
)) = Expec_Type
16975 -- In an instance, there is an ongoing problem with completion of
16976 -- type derived from private types. Their structure is what Gigi
16977 -- expects, but the Etype is the parent type rather than the
16978 -- derived private type itself. Do not flag error in this case. The
16979 -- private completion is an entity without a parent, like an Itype.
16980 -- Similarly, full and partial views may be incorrect in the instance.
16981 -- There is no simple way to insure that it is consistent ???
16983 elsif In_Instance
then
16984 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
16986 (Has_Private_Declaration
(Expected_Type
)
16987 or else Has_Private_Declaration
(Etype
(Expr
)))
16988 and then No
(Parent
(Expected_Type
))
16994 -- An interesting special check. If the expression is parenthesized
16995 -- and its type corresponds to the type of the sole component of the
16996 -- expected record type, or to the component type of the expected one
16997 -- dimensional array type, then assume we have a bad aggregate attempt.
16999 if Nkind
(Expr
) in N_Subexpr
17000 and then Paren_Count
(Expr
) /= 0
17001 and then Has_One_Matching_Field
17003 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
17004 if Present
(Matching_Field
) then
17005 if Is_Array_Type
(Expec_Type
) then
17007 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
17011 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
17015 -- Another special check, if we are looking for a pool-specific access
17016 -- type and we found an E_Access_Attribute_Type, then we have the case
17017 -- of an Access attribute being used in a context which needs a pool-
17018 -- specific type, which is never allowed. The one extra check we make
17019 -- is that the expected designated type covers the Found_Type.
17021 elsif Is_Access_Type
(Expec_Type
)
17022 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
17023 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
17024 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
17026 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
17028 Error_Msg_N
-- CODEFIX
17029 ("result must be general access type!", Expr
);
17030 Error_Msg_NE
-- CODEFIX
17031 ("add ALL to }!", Expr
, Expec_Type
);
17033 -- Another special check, if the expected type is an integer type,
17034 -- but the expression is of type System.Address, and the parent is
17035 -- an addition or subtraction operation whose left operand is the
17036 -- expression in question and whose right operand is of an integral
17037 -- type, then this is an attempt at address arithmetic, so give
17038 -- appropriate message.
17040 elsif Is_Integer_Type
(Expec_Type
)
17041 and then Is_RTE
(Found_Type
, RE_Address
)
17042 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
17044 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
17045 and then Expr
= Left_Opnd
(Parent
(Expr
))
17046 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
17049 ("address arithmetic not predefined in package System",
17052 ("\possible missing with/use of System.Storage_Elements",
17056 -- If the expected type is an anonymous access type, as for access
17057 -- parameters and discriminants, the error is on the designated types.
17059 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
17060 if Comes_From_Source
(Expec_Type
) then
17061 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
17064 ("expected an access type with designated}",
17065 Expr
, Designated_Type
(Expec_Type
));
17068 if Is_Access_Type
(Found_Type
)
17069 and then not Comes_From_Source
(Found_Type
)
17072 ("\\found an access type with designated}!",
17073 Expr
, Designated_Type
(Found_Type
));
17075 if From_Limited_With
(Found_Type
) then
17076 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
17077 Error_Msg_Qual_Level
:= 99;
17078 Error_Msg_NE
-- CODEFIX
17079 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
17080 Error_Msg_Qual_Level
:= 0;
17082 Error_Msg_NE
("found}!", Expr
, Found_Type
);
17086 -- Normal case of one type found, some other type expected
17089 -- If the names of the two types are the same, see if some number
17090 -- of levels of qualification will help. Don't try more than three
17091 -- levels, and if we get to standard, it's no use (and probably
17092 -- represents an error in the compiler) Also do not bother with
17093 -- internal scope names.
17096 Expec_Scope
: Entity_Id
;
17097 Found_Scope
: Entity_Id
;
17100 Expec_Scope
:= Expec_Type
;
17101 Found_Scope
:= Found_Type
;
17103 for Levels
in Int
range 0 .. 3 loop
17104 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
17105 Error_Msg_Qual_Level
:= Levels
;
17109 Expec_Scope
:= Scope
(Expec_Scope
);
17110 Found_Scope
:= Scope
(Found_Scope
);
17112 exit when Expec_Scope
= Standard_Standard
17113 or else Found_Scope
= Standard_Standard
17114 or else not Comes_From_Source
(Expec_Scope
)
17115 or else not Comes_From_Source
(Found_Scope
);
17119 if Is_Record_Type
(Expec_Type
)
17120 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
17122 Error_Msg_NE
("expected}!", Expr
,
17123 Corresponding_Remote_Type
(Expec_Type
));
17125 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
17128 if Is_Entity_Name
(Expr
)
17129 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
17131 Error_Msg_N
("\\found package name!", Expr
);
17133 elsif Is_Entity_Name
(Expr
)
17135 (Ekind
(Entity
(Expr
)) = E_Procedure
17137 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
17139 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
17141 ("found procedure name, possibly missing Access attribute!",
17145 ("\\found procedure name instead of function!", Expr
);
17148 elsif Nkind
(Expr
) = N_Function_Call
17149 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
17150 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
17151 and then No
(Parameter_Associations
(Expr
))
17154 ("found function name, possibly missing Access attribute!",
17157 -- Catch common error: a prefix or infix operator which is not
17158 -- directly visible because the type isn't.
17160 elsif Nkind
(Expr
) in N_Op
17161 and then Is_Overloaded
(Expr
)
17162 and then not Is_Immediately_Visible
(Expec_Type
)
17163 and then not Is_Potentially_Use_Visible
(Expec_Type
)
17164 and then not In_Use
(Expec_Type
)
17165 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
17168 ("operator of the type is not directly visible!", Expr
);
17170 elsif Ekind
(Found_Type
) = E_Void
17171 and then Present
(Parent
(Found_Type
))
17172 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
17174 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
17177 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
17180 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
17181 -- of the same modular type, and (M1 and M2) = 0 was intended.
17183 if Expec_Type
= Standard_Boolean
17184 and then Is_Modular_Integer_Type
(Found_Type
)
17185 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
17186 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
17189 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
17190 L
: constant Node_Id
:= Left_Opnd
(Op
);
17191 R
: constant Node_Id
:= Right_Opnd
(Op
);
17193 -- The case for the message is when the left operand of the
17194 -- comparison is the same modular type, or when it is an
17195 -- integer literal (or other universal integer expression),
17196 -- which would have been typed as the modular type if the
17197 -- parens had been there.
17199 if (Etype
(L
) = Found_Type
17201 Etype
(L
) = Universal_Integer
)
17202 and then Is_Integer_Type
(Etype
(R
))
17205 ("\\possible missing parens for modular operation", Expr
);
17210 -- Reset error message qualification indication
17212 Error_Msg_Qual_Level
:= 0;