1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Casing
; use Casing
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Errout
; use Errout
;
31 with Elists
; use Elists
;
32 with Exp_Ch11
; use Exp_Ch11
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Util
; use Exp_Util
;
35 with Fname
; use Fname
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
.Sp
; use Namet
.Sp
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
42 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Attr
; use Sem_Attr
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Disp
; use Sem_Disp
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Type
; use Sem_Type
;
55 with Sinfo
; use Sinfo
;
56 with Sinput
; use Sinput
;
57 with Stand
; use Stand
;
59 with Stringt
; use Stringt
;
60 with Targparm
; use Targparm
;
61 with Tbuild
; use Tbuild
;
62 with Ttypes
; use Ttypes
;
63 with Uname
; use Uname
;
65 with GNAT
.HTable
; use GNAT
.HTable
;
67 package body Sem_Util
is
69 ----------------------------------------
70 -- Global_Variables for New_Copy_Tree --
71 ----------------------------------------
73 -- These global variables are used by New_Copy_Tree. See description
74 -- of the body of this subprogram for details. Global variables can be
75 -- safely used by New_Copy_Tree, since there is no case of a recursive
76 -- call from the processing inside New_Copy_Tree.
78 NCT_Hash_Threshold
: constant := 20;
79 -- If there are more than this number of pairs of entries in the
80 -- map, then Hash_Tables_Used will be set, and the hash tables will
81 -- be initialized and used for the searches.
83 NCT_Hash_Tables_Used
: Boolean := False;
84 -- Set to True if hash tables are in use
86 NCT_Table_Entries
: Nat
;
87 -- Count entries in table to see if threshold is reached
89 NCT_Hash_Table_Setup
: Boolean := False;
90 -- Set to True if hash table contains data. We set this True if we
91 -- setup the hash table with data, and leave it set permanently
92 -- from then on, this is a signal that second and subsequent users
93 -- of the hash table must clear the old entries before reuse.
95 subtype NCT_Header_Num
is Int
range 0 .. 511;
96 -- Defines range of headers in hash tables (512 headers)
98 -----------------------
99 -- Local Subprograms --
100 -----------------------
102 function Build_Component_Subtype
105 T
: Entity_Id
) return Node_Id
;
106 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
107 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
108 -- Loc is the source location, T is the original subtype.
110 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
111 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
112 -- with discriminants whose default values are static, examine only the
113 -- components in the selected variant to determine whether all of them
116 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
117 -- T is a derived tagged type. Check whether the type extension is null.
118 -- If the parent type is fully initialized, T can be treated as such.
120 ------------------------------
121 -- Abstract_Interface_List --
122 ------------------------------
124 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
128 if Is_Concurrent_Type
(Typ
) then
130 -- If we are dealing with a synchronized subtype, go to the base
131 -- type, whose declaration has the interface list.
133 -- Shouldn't this be Declaration_Node???
135 Nod
:= Parent
(Base_Type
(Typ
));
137 if Nkind
(Nod
) = N_Full_Type_Declaration
then
141 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
142 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
143 Nod
:= Type_Definition
(Parent
(Typ
));
145 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
146 if Present
(Full_View
(Typ
))
147 and then Nkind
(Parent
(Full_View
(Typ
)))
148 = N_Full_Type_Declaration
150 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
152 -- If the full-view is not available we cannot do anything else
153 -- here (the source has errors).
159 -- Support for generic formals with interfaces is still missing ???
161 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
166 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
170 elsif Ekind
(Typ
) = E_Record_Subtype
then
171 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
173 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
175 -- Recurse, because parent may still be a private extension. Also
176 -- note that the full view of the subtype or the full view of its
177 -- base type may (both) be unavailable.
179 return Abstract_Interface_List
(Etype
(Typ
));
181 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
182 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
183 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
185 Nod
:= Type_Definition
(Parent
(Typ
));
189 return Interface_List
(Nod
);
190 end Abstract_Interface_List
;
192 --------------------------------
193 -- Add_Access_Type_To_Process --
194 --------------------------------
196 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
200 Ensure_Freeze_Node
(E
);
201 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
205 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
209 end Add_Access_Type_To_Process
;
211 ----------------------------
212 -- Add_Global_Declaration --
213 ----------------------------
215 procedure Add_Global_Declaration
(N
: Node_Id
) is
216 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
219 if No
(Declarations
(Aux_Node
)) then
220 Set_Declarations
(Aux_Node
, New_List
);
223 Append_To
(Declarations
(Aux_Node
), N
);
225 end Add_Global_Declaration
;
231 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
233 function Addressable
(V
: Uint
) return Boolean is
235 return V
= Uint_8
or else
241 function Addressable
(V
: Int
) return Boolean is
249 -----------------------
250 -- Alignment_In_Bits --
251 -----------------------
253 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
255 return Alignment
(E
) * System_Storage_Unit
;
256 end Alignment_In_Bits
;
258 ---------------------------------
259 -- Append_Inherited_Subprogram --
260 ---------------------------------
262 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
263 Par
: constant Entity_Id
:= Alias
(S
);
264 -- The parent subprogram
266 Scop
: constant Entity_Id
:= Scope
(Par
);
267 -- The scope of definition of the parent subprogram
269 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
270 -- The derived type of which S is a primitive operation
276 if Ekind
(Current_Scope
) = E_Package
277 and then In_Private_Part
(Current_Scope
)
278 and then Has_Private_Declaration
(Typ
)
279 and then Is_Tagged_Type
(Typ
)
280 and then Scop
= Current_Scope
282 -- The inherited operation is available at the earliest place after
283 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
284 -- relevant for type extensions. If the parent operation appears
285 -- after the type extension, the operation is not visible.
288 (Visible_Declarations
289 (Specification
(Unit_Declaration_Node
(Current_Scope
))));
290 while Present
(Decl
) loop
291 if Nkind
(Decl
) = N_Private_Extension_Declaration
292 and then Defining_Entity
(Decl
) = Typ
294 if Sloc
(Decl
) > Sloc
(Par
) then
295 Next_E
:= Next_Entity
(Par
);
296 Set_Next_Entity
(Par
, S
);
297 Set_Next_Entity
(S
, Next_E
);
309 -- If partial view is not a type extension, or it appears before the
310 -- subprogram declaration, insert normally at end of entity list.
312 Append_Entity
(S
, Current_Scope
);
313 end Append_Inherited_Subprogram
;
315 -----------------------------------------
316 -- Apply_Compile_Time_Constraint_Error --
317 -----------------------------------------
319 procedure Apply_Compile_Time_Constraint_Error
322 Reason
: RT_Exception_Code
;
323 Ent
: Entity_Id
:= Empty
;
324 Typ
: Entity_Id
:= Empty
;
325 Loc
: Source_Ptr
:= No_Location
;
326 Rep
: Boolean := True;
327 Warn
: Boolean := False)
329 Stat
: constant Boolean := Is_Static_Expression
(N
);
330 R_Stat
: constant Node_Id
:=
331 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
342 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
348 -- Now we replace the node by an N_Raise_Constraint_Error node
349 -- This does not need reanalyzing, so set it as analyzed now.
352 Set_Analyzed
(N
, True);
355 Set_Raises_Constraint_Error
(N
);
357 -- Now deal with possible local raise handling
359 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
361 -- If the original expression was marked as static, the result is
362 -- still marked as static, but the Raises_Constraint_Error flag is
363 -- always set so that further static evaluation is not attempted.
366 Set_Is_Static_Expression
(N
);
368 end Apply_Compile_Time_Constraint_Error
;
370 --------------------------------------
371 -- Available_Full_View_Of_Component --
372 --------------------------------------
374 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
375 ST
: constant Entity_Id
:= Scope
(T
);
376 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
378 return In_Open_Scopes
(ST
)
379 and then In_Open_Scopes
(SCT
)
380 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
381 end Available_Full_View_Of_Component
;
387 procedure Bad_Attribute
390 Warn
: Boolean := False)
393 Error_Msg_Warn
:= Warn
;
394 Error_Msg_N
("unrecognized attribute&<", N
);
396 -- Check for possible misspelling
398 Error_Msg_Name_1
:= First_Attribute_Name
;
399 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
400 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
401 Error_Msg_N
-- CODEFIX
402 ("\possible misspelling of %<", N
);
406 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
410 --------------------------------
411 -- Bad_Predicated_Subtype_Use --
412 --------------------------------
414 procedure Bad_Predicated_Subtype_Use
420 if Has_Predicates
(Typ
) then
421 if Is_Generic_Actual_Type
(Typ
) then
422 Error_Msg_FE
(Msg
& "??", N
, Typ
);
423 Error_Msg_F
("\Program_Error will be raised at run time??", N
);
425 Make_Raise_Program_Error
(Sloc
(N
),
426 Reason
=> PE_Bad_Predicated_Generic_Type
));
429 Error_Msg_FE
(Msg
, N
, Typ
);
432 end Bad_Predicated_Subtype_Use
;
434 --------------------------
435 -- Build_Actual_Subtype --
436 --------------------------
438 function Build_Actual_Subtype
440 N
: Node_Or_Entity_Id
) return Node_Id
443 -- Normally Sloc (N), but may point to corresponding body in some cases
445 Constraints
: List_Id
;
451 Disc_Type
: Entity_Id
;
457 if Nkind
(N
) = N_Defining_Identifier
then
458 Obj
:= New_Reference_To
(N
, Loc
);
460 -- If this is a formal parameter of a subprogram declaration, and
461 -- we are compiling the body, we want the declaration for the
462 -- actual subtype to carry the source position of the body, to
463 -- prevent anomalies in gdb when stepping through the code.
465 if Is_Formal
(N
) then
467 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
469 if Nkind
(Decl
) = N_Subprogram_Declaration
470 and then Present
(Corresponding_Body
(Decl
))
472 Loc
:= Sloc
(Corresponding_Body
(Decl
));
481 if Is_Array_Type
(T
) then
482 Constraints
:= New_List
;
483 for J
in 1 .. Number_Dimensions
(T
) loop
485 -- Build an array subtype declaration with the nominal subtype and
486 -- the bounds of the actual. Add the declaration in front of the
487 -- local declarations for the subprogram, for analysis before any
488 -- reference to the formal in the body.
491 Make_Attribute_Reference
(Loc
,
493 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
494 Attribute_Name
=> Name_First
,
495 Expressions
=> New_List
(
496 Make_Integer_Literal
(Loc
, J
)));
499 Make_Attribute_Reference
(Loc
,
501 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
502 Attribute_Name
=> Name_Last
,
503 Expressions
=> New_List
(
504 Make_Integer_Literal
(Loc
, J
)));
506 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
509 -- If the type has unknown discriminants there is no constrained
510 -- subtype to build. This is never called for a formal or for a
511 -- lhs, so returning the type is ok ???
513 elsif Has_Unknown_Discriminants
(T
) then
517 Constraints
:= New_List
;
519 -- Type T is a generic derived type, inherit the discriminants from
522 if Is_Private_Type
(T
)
523 and then No
(Full_View
(T
))
525 -- T was flagged as an error if it was declared as a formal
526 -- derived type with known discriminants. In this case there
527 -- is no need to look at the parent type since T already carries
528 -- its own discriminants.
530 and then not Error_Posted
(T
)
532 Disc_Type
:= Etype
(Base_Type
(T
));
537 Discr
:= First_Discriminant
(Disc_Type
);
538 while Present
(Discr
) loop
539 Append_To
(Constraints
,
540 Make_Selected_Component
(Loc
,
542 Duplicate_Subexpr_No_Checks
(Obj
),
543 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
544 Next_Discriminant
(Discr
);
548 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
549 Set_Is_Internal
(Subt
);
552 Make_Subtype_Declaration
(Loc
,
553 Defining_Identifier
=> Subt
,
554 Subtype_Indication
=>
555 Make_Subtype_Indication
(Loc
,
556 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
558 Make_Index_Or_Discriminant_Constraint
(Loc
,
559 Constraints
=> Constraints
)));
561 Mark_Rewrite_Insertion
(Decl
);
563 end Build_Actual_Subtype
;
565 ---------------------------------------
566 -- Build_Actual_Subtype_Of_Component --
567 ---------------------------------------
569 function Build_Actual_Subtype_Of_Component
571 N
: Node_Id
) return Node_Id
573 Loc
: constant Source_Ptr
:= Sloc
(N
);
574 P
: constant Node_Id
:= Prefix
(N
);
577 Index_Typ
: Entity_Id
;
579 Desig_Typ
: Entity_Id
;
580 -- This is either a copy of T, or if T is an access type, then it is
581 -- the directly designated type of this access type.
583 function Build_Actual_Array_Constraint
return List_Id
;
584 -- If one or more of the bounds of the component depends on
585 -- discriminants, build actual constraint using the discriminants
588 function Build_Actual_Record_Constraint
return List_Id
;
589 -- Similar to previous one, for discriminated components constrained
590 -- by the discriminant of the enclosing object.
592 -----------------------------------
593 -- Build_Actual_Array_Constraint --
594 -----------------------------------
596 function Build_Actual_Array_Constraint
return List_Id
is
597 Constraints
: constant List_Id
:= New_List
;
605 Indx
:= First_Index
(Desig_Typ
);
606 while Present
(Indx
) loop
607 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
608 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
610 if Denotes_Discriminant
(Old_Lo
) then
612 Make_Selected_Component
(Loc
,
613 Prefix
=> New_Copy_Tree
(P
),
614 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
617 Lo
:= New_Copy_Tree
(Old_Lo
);
619 -- The new bound will be reanalyzed in the enclosing
620 -- declaration. For literal bounds that come from a type
621 -- declaration, the type of the context must be imposed, so
622 -- insure that analysis will take place. For non-universal
623 -- types this is not strictly necessary.
625 Set_Analyzed
(Lo
, False);
628 if Denotes_Discriminant
(Old_Hi
) then
630 Make_Selected_Component
(Loc
,
631 Prefix
=> New_Copy_Tree
(P
),
632 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
635 Hi
:= New_Copy_Tree
(Old_Hi
);
636 Set_Analyzed
(Hi
, False);
639 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
644 end Build_Actual_Array_Constraint
;
646 ------------------------------------
647 -- Build_Actual_Record_Constraint --
648 ------------------------------------
650 function Build_Actual_Record_Constraint
return List_Id
is
651 Constraints
: constant List_Id
:= New_List
;
656 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
657 while Present
(D
) loop
658 if Denotes_Discriminant
(Node
(D
)) then
659 D_Val
:= Make_Selected_Component
(Loc
,
660 Prefix
=> New_Copy_Tree
(P
),
661 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
664 D_Val
:= New_Copy_Tree
(Node
(D
));
667 Append
(D_Val
, Constraints
);
672 end Build_Actual_Record_Constraint
;
674 -- Start of processing for Build_Actual_Subtype_Of_Component
677 -- Why the test for Spec_Expression mode here???
679 if In_Spec_Expression
then
682 -- More comments for the rest of this body would be good ???
684 elsif Nkind
(N
) = N_Explicit_Dereference
then
685 if Is_Composite_Type
(T
)
686 and then not Is_Constrained
(T
)
687 and then not (Is_Class_Wide_Type
(T
)
688 and then Is_Constrained
(Root_Type
(T
)))
689 and then not Has_Unknown_Discriminants
(T
)
691 -- If the type of the dereference is already constrained, it is an
694 if Is_Array_Type
(Etype
(N
))
695 and then Is_Constrained
(Etype
(N
))
699 Remove_Side_Effects
(P
);
700 return Build_Actual_Subtype
(T
, N
);
707 if Ekind
(T
) = E_Access_Subtype
then
708 Desig_Typ
:= Designated_Type
(T
);
713 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
714 Id
:= First_Index
(Desig_Typ
);
715 while Present
(Id
) loop
716 Index_Typ
:= Underlying_Type
(Etype
(Id
));
718 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
720 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
722 Remove_Side_Effects
(P
);
724 Build_Component_Subtype
725 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
731 elsif Is_Composite_Type
(Desig_Typ
)
732 and then Has_Discriminants
(Desig_Typ
)
733 and then not Has_Unknown_Discriminants
(Desig_Typ
)
735 if Is_Private_Type
(Desig_Typ
)
736 and then No
(Discriminant_Constraint
(Desig_Typ
))
738 Desig_Typ
:= Full_View
(Desig_Typ
);
741 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
742 while Present
(D
) loop
743 if Denotes_Discriminant
(Node
(D
)) then
744 Remove_Side_Effects
(P
);
746 Build_Component_Subtype
(
747 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
754 -- If none of the above, the actual and nominal subtypes are the same
757 end Build_Actual_Subtype_Of_Component
;
759 -----------------------------
760 -- Build_Component_Subtype --
761 -----------------------------
763 function Build_Component_Subtype
766 T
: Entity_Id
) return Node_Id
772 -- Unchecked_Union components do not require component subtypes
774 if Is_Unchecked_Union
(T
) then
778 Subt
:= Make_Temporary
(Loc
, 'S');
779 Set_Is_Internal
(Subt
);
782 Make_Subtype_Declaration
(Loc
,
783 Defining_Identifier
=> Subt
,
784 Subtype_Indication
=>
785 Make_Subtype_Indication
(Loc
,
786 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
788 Make_Index_Or_Discriminant_Constraint
(Loc
,
791 Mark_Rewrite_Insertion
(Decl
);
793 end Build_Component_Subtype
;
795 ---------------------------
796 -- Build_Default_Subtype --
797 ---------------------------
799 function Build_Default_Subtype
801 N
: Node_Id
) return Entity_Id
803 Loc
: constant Source_Ptr
:= Sloc
(N
);
807 -- The base type that is to be constrained by the defaults
810 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
814 Bas
:= Base_Type
(T
);
816 -- If T is non-private but its base type is private, this is the
817 -- completion of a subtype declaration whose parent type is private
818 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
819 -- are to be found in the full view of the base.
821 if Is_Private_Type
(Bas
) and then Present
(Full_View
(Bas
)) then
822 Bas
:= Full_View
(Bas
);
825 Disc
:= First_Discriminant
(T
);
827 if No
(Discriminant_Default_Value
(Disc
)) then
832 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
833 Constraints
: constant List_Id
:= New_List
;
837 while Present
(Disc
) loop
838 Append_To
(Constraints
,
839 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
840 Next_Discriminant
(Disc
);
844 Make_Subtype_Declaration
(Loc
,
845 Defining_Identifier
=> Act
,
846 Subtype_Indication
=>
847 Make_Subtype_Indication
(Loc
,
848 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
850 Make_Index_Or_Discriminant_Constraint
(Loc
,
851 Constraints
=> Constraints
)));
853 Insert_Action
(N
, Decl
);
857 end Build_Default_Subtype
;
859 --------------------------------------------
860 -- Build_Discriminal_Subtype_Of_Component --
861 --------------------------------------------
863 function Build_Discriminal_Subtype_Of_Component
864 (T
: Entity_Id
) return Node_Id
866 Loc
: constant Source_Ptr
:= Sloc
(T
);
870 function Build_Discriminal_Array_Constraint
return List_Id
;
871 -- If one or more of the bounds of the component depends on
872 -- discriminants, build actual constraint using the discriminants
875 function Build_Discriminal_Record_Constraint
return List_Id
;
876 -- Similar to previous one, for discriminated components constrained by
877 -- the discriminant of the enclosing object.
879 ----------------------------------------
880 -- Build_Discriminal_Array_Constraint --
881 ----------------------------------------
883 function Build_Discriminal_Array_Constraint
return List_Id
is
884 Constraints
: constant List_Id
:= New_List
;
892 Indx
:= First_Index
(T
);
893 while Present
(Indx
) loop
894 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
895 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
897 if Denotes_Discriminant
(Old_Lo
) then
898 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
901 Lo
:= New_Copy_Tree
(Old_Lo
);
904 if Denotes_Discriminant
(Old_Hi
) then
905 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
908 Hi
:= New_Copy_Tree
(Old_Hi
);
911 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
916 end Build_Discriminal_Array_Constraint
;
918 -----------------------------------------
919 -- Build_Discriminal_Record_Constraint --
920 -----------------------------------------
922 function Build_Discriminal_Record_Constraint
return List_Id
is
923 Constraints
: constant List_Id
:= New_List
;
928 D
:= First_Elmt
(Discriminant_Constraint
(T
));
929 while Present
(D
) loop
930 if Denotes_Discriminant
(Node
(D
)) then
932 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
935 D_Val
:= New_Copy_Tree
(Node
(D
));
938 Append
(D_Val
, Constraints
);
943 end Build_Discriminal_Record_Constraint
;
945 -- Start of processing for Build_Discriminal_Subtype_Of_Component
948 if Ekind
(T
) = E_Array_Subtype
then
949 Id
:= First_Index
(T
);
950 while Present
(Id
) loop
951 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
952 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
954 return Build_Component_Subtype
955 (Build_Discriminal_Array_Constraint
, Loc
, T
);
961 elsif Ekind
(T
) = E_Record_Subtype
962 and then Has_Discriminants
(T
)
963 and then not Has_Unknown_Discriminants
(T
)
965 D
:= First_Elmt
(Discriminant_Constraint
(T
));
966 while Present
(D
) loop
967 if Denotes_Discriminant
(Node
(D
)) then
968 return Build_Component_Subtype
969 (Build_Discriminal_Record_Constraint
, Loc
, T
);
976 -- If none of the above, the actual and nominal subtypes are the same
979 end Build_Discriminal_Subtype_Of_Component
;
981 ------------------------------
982 -- Build_Elaboration_Entity --
983 ------------------------------
985 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
986 Loc
: constant Source_Ptr
:= Sloc
(N
);
988 Elab_Ent
: Entity_Id
;
990 procedure Set_Package_Name
(Ent
: Entity_Id
);
991 -- Given an entity, sets the fully qualified name of the entity in
992 -- Name_Buffer, with components separated by double underscores. This
993 -- is a recursive routine that climbs the scope chain to Standard.
995 ----------------------
996 -- Set_Package_Name --
997 ----------------------
999 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1001 if Scope
(Ent
) /= Standard_Standard
then
1002 Set_Package_Name
(Scope
(Ent
));
1005 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1007 Name_Buffer
(Name_Len
+ 1) := '_';
1008 Name_Buffer
(Name_Len
+ 2) := '_';
1009 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1010 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1014 Get_Name_String
(Chars
(Ent
));
1016 end Set_Package_Name
;
1018 -- Start of processing for Build_Elaboration_Entity
1021 -- Ignore if already constructed
1023 if Present
(Elaboration_Entity
(Spec_Id
)) then
1027 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1028 -- name with dots replaced by double underscore. We have to manually
1029 -- construct this name, since it will be elaborated in the outer scope,
1030 -- and thus will not have the unit name automatically prepended.
1032 Set_Package_Name
(Spec_Id
);
1033 Add_Str_To_Name_Buffer
("_E");
1035 -- Create elaboration counter
1037 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1038 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1041 Make_Object_Declaration
(Loc
,
1042 Defining_Identifier
=> Elab_Ent
,
1043 Object_Definition
=>
1044 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1045 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1047 Push_Scope
(Standard_Standard
);
1048 Add_Global_Declaration
(Decl
);
1051 -- Reset True_Constant indication, since we will indeed assign a value
1052 -- to the variable in the binder main. We also kill the Current_Value
1053 -- and Last_Assignment fields for the same reason.
1055 Set_Is_True_Constant
(Elab_Ent
, False);
1056 Set_Current_Value
(Elab_Ent
, Empty
);
1057 Set_Last_Assignment
(Elab_Ent
, Empty
);
1059 -- We do not want any further qualification of the name (if we did not
1060 -- do this, we would pick up the name of the generic package in the case
1061 -- of a library level generic instantiation).
1063 Set_Has_Qualified_Name
(Elab_Ent
);
1064 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1065 end Build_Elaboration_Entity
;
1067 --------------------------------
1068 -- Build_Explicit_Dereference --
1069 --------------------------------
1071 procedure Build_Explicit_Dereference
1075 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1078 -- An entity of a type with a reference aspect is overloaded with
1079 -- both interpretations: with and without the dereference. Now that
1080 -- the dereference is made explicit, set the type of the node properly,
1081 -- to prevent anomalies in the backend. Same if the expression is an
1082 -- overloaded function call whose return type has a reference aspect.
1084 if Is_Entity_Name
(Expr
) then
1085 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1087 elsif Nkind
(Expr
) = N_Function_Call
then
1088 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1091 Set_Is_Overloaded
(Expr
, False);
1093 Make_Explicit_Dereference
(Loc
,
1095 Make_Selected_Component
(Loc
,
1096 Prefix
=> Relocate_Node
(Expr
),
1097 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1098 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1099 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1100 end Build_Explicit_Dereference
;
1102 -----------------------------------
1103 -- Cannot_Raise_Constraint_Error --
1104 -----------------------------------
1106 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1108 if Compile_Time_Known_Value
(Expr
) then
1111 elsif Do_Range_Check
(Expr
) then
1114 elsif Raises_Constraint_Error
(Expr
) then
1118 case Nkind
(Expr
) is
1119 when N_Identifier
=>
1122 when N_Expanded_Name
=>
1125 when N_Selected_Component
=>
1126 return not Do_Discriminant_Check
(Expr
);
1128 when N_Attribute_Reference
=>
1129 if Do_Overflow_Check
(Expr
) then
1132 elsif No
(Expressions
(Expr
)) then
1140 N
:= First
(Expressions
(Expr
));
1141 while Present
(N
) loop
1142 if Cannot_Raise_Constraint_Error
(N
) then
1153 when N_Type_Conversion
=>
1154 if Do_Overflow_Check
(Expr
)
1155 or else Do_Length_Check
(Expr
)
1156 or else Do_Tag_Check
(Expr
)
1160 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1163 when N_Unchecked_Type_Conversion
=>
1164 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1167 if Do_Overflow_Check
(Expr
) then
1170 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1177 if Do_Division_Check
(Expr
)
1178 or else Do_Overflow_Check
(Expr
)
1183 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1185 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1204 N_Op_Shift_Right_Arithmetic |
1208 if Do_Overflow_Check
(Expr
) then
1212 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1214 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1221 end Cannot_Raise_Constraint_Error
;
1223 -------------------------------------
1224 -- Check_Function_Writable_Actuals --
1225 -------------------------------------
1227 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
1228 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
1229 Identifiers_List
: Elist_Id
:= No_Elist
;
1230 Error_Node
: Node_Id
:= Empty
;
1232 procedure Collect_Identifiers
(N
: Node_Id
);
1233 -- In a single traversal of subtree N collect in Writable_Actuals_List
1234 -- all the actuals of functions with writable actuals, and in the list
1235 -- Identifiers_List collect all the identifiers that are not actuals of
1236 -- functions with writable actuals. If a writable actual is referenced
1237 -- twice as writable actual then Error_Node is set to reference its
1238 -- second occurrence, the error is reported, and the tree traversal
1241 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
1242 -- Return the entity associated with the function call
1244 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
1245 -- Preanalyze N without reporting errors. Very dubious, you can't just
1246 -- go analyzing things more than once???
1248 -------------------------
1249 -- Collect_Identifiers --
1250 -------------------------
1252 procedure Collect_Identifiers
(N
: Node_Id
) is
1254 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
1255 -- Process a single node during the tree traversal to collect the
1256 -- writable actuals of functions and all the identifiers which are
1257 -- not writable actuals of functions.
1259 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
1260 -- Returns True if List has a node whose Entity is Entity (N)
1262 -------------------------
1263 -- Check_Function_Call --
1264 -------------------------
1266 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
1267 Is_Writable_Actual
: Boolean := False;
1270 if Nkind
(N
) = N_Identifier
then
1272 -- No analysis possible if the entity is not decorated
1274 if No
(Entity
(N
)) then
1277 -- Don't collect identifiers of packages, called functions, etc
1279 elsif Ekind_In
(Entity
(N
), E_Package
,
1286 -- Analyze if N is a writable actual of a function
1288 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
1290 Call
: constant Node_Id
:= Parent
(N
);
1291 Id
: constant Entity_Id
:= Get_Function_Id
(Call
);
1296 Formal
:= First_Formal
(Id
);
1297 Actual
:= First_Actual
(Call
);
1298 while Present
(Actual
) and then Present
(Formal
) loop
1300 if Ekind_In
(Formal
, E_Out_Parameter
,
1303 Is_Writable_Actual
:= True;
1309 Next_Formal
(Formal
);
1310 Next_Actual
(Actual
);
1315 if Is_Writable_Actual
then
1316 if Contains
(Writable_Actuals_List
, N
) then
1318 ("conflict of writable function parameter in "
1319 & "construct with arbitrary order of evaluation", N
);
1324 if Writable_Actuals_List
= No_Elist
then
1325 Writable_Actuals_List
:= New_Elmt_List
;
1328 Append_Elmt
(N
, Writable_Actuals_List
);
1330 if Identifiers_List
= No_Elist
then
1331 Identifiers_List
:= New_Elmt_List
;
1334 Append_Unique_Elmt
(N
, Identifiers_List
);
1347 N
: Node_Id
) return Boolean
1349 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
1354 if List
= No_Elist
then
1358 Elmt
:= First_Elmt
(List
);
1359 while Present
(Elmt
) loop
1360 if Entity
(Node
(Elmt
)) = Entity
(N
) then
1374 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
1375 -- The traversal procedure
1377 -- Start of processing for Collect_Identifiers
1380 if Present
(Error_Node
) then
1384 if Nkind
(N
) in N_Subexpr
1385 and then Is_Static_Expression
(N
)
1391 end Collect_Identifiers
;
1393 ---------------------
1394 -- Get_Function_Id --
1395 ---------------------
1397 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
1398 Nam
: constant Node_Id
:= Name
(Call
);
1402 if Nkind
(Nam
) = N_Explicit_Dereference
then
1404 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
1406 elsif Nkind
(Nam
) = N_Selected_Component
then
1407 Id
:= Entity
(Selector_Name
(Nam
));
1409 elsif Nkind
(Nam
) = N_Indexed_Component
then
1410 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
1417 end Get_Function_Id
;
1419 ---------------------------
1420 -- Preanalyze_Expression --
1421 ---------------------------
1423 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
1424 Status
: constant Boolean := Get_Ignore_Errors
;
1426 Set_Ignore_Errors
(True);
1428 Set_Ignore_Errors
(Status
);
1429 end Preanalyze_Without_Errors
;
1431 -- Start of processing for Check_Function_Writable_Actuals
1434 if Ada_Version
< Ada_2012
1435 or else (not (Nkind
(N
) in N_Op
)
1436 and then not (Nkind
(N
) in N_Membership_Test
)
1437 and then not Nkind_In
(N
, N_Range
,
1439 N_Extension_Aggregate
,
1440 N_Full_Type_Declaration
,
1442 N_Procedure_Call_Statement
,
1443 N_Entry_Call_Statement
))
1444 or else (Nkind
(N
) = N_Full_Type_Declaration
1445 and then not Is_Record_Type
(Defining_Identifier
(N
)))
1450 -- If a construct C has two or more direct constituents that are names
1451 -- or expressions whose evaluation may occur in an arbitrary order, at
1452 -- least one of which contains a function call with an in out or out
1453 -- parameter, then the construct is legal only if: for each name N that
1454 -- is passed as a parameter of mode in out or out to some inner function
1455 -- call C2 (not including the construct C itself), there is no other
1456 -- name anywhere within a direct constituent of the construct C other
1457 -- than the one containing C2, that is known to refer to the same
1458 -- object (RM 6.4.1(6.17/3)).
1462 Collect_Identifiers
(Low_Bound
(N
));
1463 Collect_Identifiers
(High_Bound
(N
));
1465 when N_Op | N_Membership_Test
=>
1469 Collect_Identifiers
(Left_Opnd
(N
));
1471 if Present
(Right_Opnd
(N
)) then
1472 Collect_Identifiers
(Right_Opnd
(N
));
1475 if Nkind_In
(N
, N_In
, N_Not_In
)
1476 and then Present
(Alternatives
(N
))
1478 Expr
:= First
(Alternatives
(N
));
1479 while Present
(Expr
) loop
1480 Collect_Identifiers
(Expr
);
1487 when N_Full_Type_Declaration
=>
1489 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
1490 -- Return the record part of this record type definition
1492 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
1493 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
1495 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
1496 return Record_Extension_Part
(Type_Def
);
1500 end Get_Record_Part
;
1503 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
1504 Rec
: Node_Id
:= Get_Record_Part
(N
);
1507 -- No need to perform any analysis if the record has no
1510 if No
(Rec
) or else No
(Component_List
(Rec
)) then
1514 -- Collect the identifiers starting from the deepest
1515 -- derivation. Done to report the error in the deepest
1519 if Present
(Component_List
(Rec
)) then
1520 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
1521 while Present
(Comp
) loop
1522 if Nkind
(Comp
) = N_Component_Declaration
1523 and then Present
(Expression
(Comp
))
1525 Collect_Identifiers
(Expression
(Comp
));
1532 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
1533 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
1536 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
1537 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
1541 when N_Subprogram_Call |
1542 N_Entry_Call_Statement
=>
1544 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
1549 Formal
:= First_Formal
(Id
);
1550 Actual
:= First_Actual
(N
);
1551 while Present
(Actual
) and then Present
(Formal
) loop
1552 if Ekind_In
(Formal
, E_Out_Parameter
,
1555 Collect_Identifiers
(Actual
);
1558 Next_Formal
(Formal
);
1559 Next_Actual
(Actual
);
1564 N_Extension_Aggregate
=>
1568 Comp_Expr
: Node_Id
;
1571 -- Handle the N_Others_Choice of array aggregates with static
1572 -- bounds. There is no need to perform this analysis in
1573 -- aggregates without static bounds since we cannot evaluate
1574 -- if the N_Others_Choice covers several elements. There is
1575 -- no need to handle the N_Others choice of record aggregates
1576 -- since at this stage it has been already expanded by
1577 -- Resolve_Record_Aggregate.
1579 if Is_Array_Type
(Etype
(N
))
1580 and then Nkind
(N
) = N_Aggregate
1581 and then Present
(Aggregate_Bounds
(N
))
1582 and then Compile_Time_Known_Bounds
(Etype
(N
))
1583 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
1584 > Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
1587 Count_Components
: Uint
:= Uint_0
;
1588 Num_Components
: Uint
;
1589 Others_Assoc
: Node_Id
;
1590 Others_Choice
: Node_Id
:= Empty
;
1591 Others_Box_Present
: Boolean := False;
1594 -- Count positional associations
1596 if Present
(Expressions
(N
)) then
1597 Comp_Expr
:= First
(Expressions
(N
));
1598 while Present
(Comp_Expr
) loop
1599 Count_Components
:= Count_Components
+ 1;
1604 -- Count the rest of elements and locate the N_Others
1607 Assoc
:= First
(Component_Associations
(N
));
1608 while Present
(Assoc
) loop
1609 Choice
:= First
(Choices
(Assoc
));
1610 while Present
(Choice
) loop
1611 if Nkind
(Choice
) = N_Others_Choice
then
1612 Others_Assoc
:= Assoc
;
1613 Others_Choice
:= Choice
;
1614 Others_Box_Present
:= Box_Present
(Assoc
);
1616 -- Count several components
1618 elsif Nkind_In
(Choice
, N_Range
,
1619 N_Subtype_Indication
)
1620 or else (Is_Entity_Name
(Choice
)
1621 and then Is_Type
(Entity
(Choice
)))
1626 Get_Index_Bounds
(Choice
, L
, H
);
1628 (Compile_Time_Known_Value
(L
)
1629 and then Compile_Time_Known_Value
(H
));
1632 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
1635 -- Count single component. No other case available
1636 -- since we are handling an aggregate with static
1640 pragma Assert
(Is_Static_Expression
(Choice
)
1641 or else Nkind
(Choice
) = N_Identifier
1642 or else Nkind
(Choice
) = N_Integer_Literal
);
1644 Count_Components
:= Count_Components
+ 1;
1654 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
1655 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
1657 pragma Assert
(Count_Components
<= Num_Components
);
1659 -- Handle the N_Others choice if it covers several
1662 if Present
(Others_Choice
)
1663 and then (Num_Components
- Count_Components
) > 1
1665 if not Others_Box_Present
then
1667 -- At this stage, if expansion is active, the
1668 -- expression of the others choice has not been
1669 -- analyzed. Hence we generate a duplicate and
1670 -- we analyze it silently to have available the
1671 -- minimum decoration required to collect the
1674 if not Expander_Active
then
1675 Comp_Expr
:= Expression
(Others_Assoc
);
1678 New_Copy_Tree
(Expression
(Others_Assoc
));
1679 Preanalyze_Without_Errors
(Comp_Expr
);
1682 Collect_Identifiers
(Comp_Expr
);
1684 if Writable_Actuals_List
/= No_Elist
then
1686 -- As suggested by Robert, at current stage we
1687 -- report occurrences of this case as warnings.
1690 ("conflict of writable function parameter in "
1691 & "construct with arbitrary order of "
1693 Node
(First_Elmt
(Writable_Actuals_List
)));
1700 -- Handle ancestor part of extension aggregates
1702 if Nkind
(N
) = N_Extension_Aggregate
then
1703 Collect_Identifiers
(Ancestor_Part
(N
));
1706 -- Handle positional associations
1708 if Present
(Expressions
(N
)) then
1709 Comp_Expr
:= First
(Expressions
(N
));
1710 while Present
(Comp_Expr
) loop
1711 if not Is_Static_Expression
(Comp_Expr
) then
1712 Collect_Identifiers
(Comp_Expr
);
1719 -- Handle discrete associations
1721 if Present
(Component_Associations
(N
)) then
1722 Assoc
:= First
(Component_Associations
(N
));
1723 while Present
(Assoc
) loop
1725 if not Box_Present
(Assoc
) then
1726 Choice
:= First
(Choices
(Assoc
));
1727 while Present
(Choice
) loop
1729 -- For now we skip discriminants since it requires
1730 -- performing the analysis in two phases: first one
1731 -- analyzing discriminants and second one analyzing
1732 -- the rest of components since discriminants are
1733 -- evaluated prior to components: too much extra
1734 -- work to detect a corner case???
1736 if Nkind
(Choice
) in N_Has_Entity
1737 and then Present
(Entity
(Choice
))
1738 and then Ekind
(Entity
(Choice
)) = E_Discriminant
1742 elsif Box_Present
(Assoc
) then
1746 if not Analyzed
(Expression
(Assoc
)) then
1748 New_Copy_Tree
(Expression
(Assoc
));
1749 Set_Parent
(Comp_Expr
, Parent
(N
));
1750 Preanalyze_Without_Errors
(Comp_Expr
);
1752 Comp_Expr
:= Expression
(Assoc
);
1755 Collect_Identifiers
(Comp_Expr
);
1771 -- No further action needed if we already reported an error
1773 if Present
(Error_Node
) then
1777 -- Check if some writable argument of a function is referenced
1779 if Writable_Actuals_List
/= No_Elist
1780 and then Identifiers_List
/= No_Elist
1787 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
1788 while Present
(Elmt_1
) loop
1789 Elmt_2
:= First_Elmt
(Identifiers_List
);
1790 while Present
(Elmt_2
) loop
1791 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
1793 ("conflict of writable function parameter in construct "
1794 & "with arbitrary order of evaluation",
1805 end Check_Function_Writable_Actuals
;
1807 --------------------------------
1808 -- Check_Implicit_Dereference --
1809 --------------------------------
1811 procedure Check_Implicit_Dereference
(Nam
: Node_Id
; Typ
: Entity_Id
) is
1816 if Ada_Version
< Ada_2012
1817 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
1821 elsif not Comes_From_Source
(Nam
) then
1824 elsif Is_Entity_Name
(Nam
)
1825 and then Is_Type
(Entity
(Nam
))
1830 Disc
:= First_Discriminant
(Typ
);
1831 while Present
(Disc
) loop
1832 if Has_Implicit_Dereference
(Disc
) then
1833 Desig
:= Designated_Type
(Etype
(Disc
));
1834 Add_One_Interp
(Nam
, Disc
, Desig
);
1838 Next_Discriminant
(Disc
);
1841 end Check_Implicit_Dereference
;
1843 ----------------------------------
1844 -- Check_Internal_Protected_Use --
1845 ----------------------------------
1847 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
1853 while Present
(S
) loop
1854 if S
= Standard_Standard
then
1857 elsif Ekind
(S
) = E_Function
1858 and then Ekind
(Scope
(S
)) = E_Protected_Type
1867 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
1868 if Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
1870 ("within protected function cannot use protected "
1871 & "procedure in renaming or as generic actual", N
);
1873 elsif Nkind
(N
) = N_Attribute_Reference
then
1875 ("within protected function cannot take access of "
1876 & " protected procedure", N
);
1880 ("within protected function, protected object is constant", N
);
1882 ("\cannot call operation that may modify it", N
);
1885 end Check_Internal_Protected_Use
;
1887 ---------------------------------------
1888 -- Check_Later_Vs_Basic_Declarations --
1889 ---------------------------------------
1891 procedure Check_Later_Vs_Basic_Declarations
1893 During_Parsing
: Boolean)
1895 Body_Sloc
: Source_Ptr
;
1898 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
1899 -- Return whether Decl is considered as a declarative item.
1900 -- When During_Parsing is True, the semantics of Ada 83 is followed.
1901 -- When During_Parsing is False, the semantics of SPARK is followed.
1903 -------------------------------
1904 -- Is_Later_Declarative_Item --
1905 -------------------------------
1907 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
1909 if Nkind
(Decl
) in N_Later_Decl_Item
then
1912 elsif Nkind
(Decl
) = N_Pragma
then
1915 elsif During_Parsing
then
1918 -- In SPARK, a package declaration is not considered as a later
1919 -- declarative item.
1921 elsif Nkind
(Decl
) = N_Package_Declaration
then
1924 -- In SPARK, a renaming is considered as a later declarative item
1926 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
1932 end Is_Later_Declarative_Item
;
1934 -- Start of Check_Later_Vs_Basic_Declarations
1937 Decl
:= First
(Decls
);
1939 -- Loop through sequence of basic declarative items
1941 Outer
: while Present
(Decl
) loop
1942 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
1943 and then Nkind
(Decl
) not in N_Body_Stub
1947 -- Once a body is encountered, we only allow later declarative
1948 -- items. The inner loop checks the rest of the list.
1951 Body_Sloc
:= Sloc
(Decl
);
1953 Inner
: while Present
(Decl
) loop
1954 if not Is_Later_Declarative_Item
(Decl
) then
1955 if During_Parsing
then
1956 if Ada_Version
= Ada_83
then
1957 Error_Msg_Sloc
:= Body_Sloc
;
1959 ("(Ada 83) decl cannot appear after body#", Decl
);
1962 Error_Msg_Sloc
:= Body_Sloc
;
1963 Check_SPARK_Restriction
1964 ("decl cannot appear after body#", Decl
);
1972 end Check_Later_Vs_Basic_Declarations
;
1974 -----------------------------------------
1975 -- Check_Dynamically_Tagged_Expression --
1976 -----------------------------------------
1978 procedure Check_Dynamically_Tagged_Expression
1981 Related_Nod
: Node_Id
)
1984 pragma Assert
(Is_Tagged_Type
(Typ
));
1986 -- In order to avoid spurious errors when analyzing the expanded code,
1987 -- this check is done only for nodes that come from source and for
1988 -- actuals of generic instantiations.
1990 if (Comes_From_Source
(Related_Nod
)
1991 or else In_Generic_Actual
(Expr
))
1992 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1993 or else Is_Dynamically_Tagged
(Expr
))
1994 and then Is_Tagged_Type
(Typ
)
1995 and then not Is_Class_Wide_Type
(Typ
)
1997 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1999 end Check_Dynamically_Tagged_Expression
;
2001 --------------------------
2002 -- Check_Fully_Declared --
2003 --------------------------
2005 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
2007 if Ekind
(T
) = E_Incomplete_Type
then
2009 -- Ada 2005 (AI-50217): If the type is available through a limited
2010 -- with_clause, verify that its full view has been analyzed.
2012 if From_With_Type
(T
)
2013 and then Present
(Non_Limited_View
(T
))
2014 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2016 -- The non-limited view is fully declared
2021 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2024 -- Need comments for these tests ???
2026 elsif Has_Private_Component
(T
)
2027 and then not Is_Generic_Type
(Root_Type
(T
))
2028 and then not In_Spec_Expression
2030 -- Special case: if T is the anonymous type created for a single
2031 -- task or protected object, use the name of the source object.
2033 if Is_Concurrent_Type
(T
)
2034 and then not Comes_From_Source
(T
)
2035 and then Nkind
(N
) = N_Object_Declaration
2037 Error_Msg_NE
("type of& has incomplete component", N
,
2038 Defining_Identifier
(N
));
2042 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2045 end Check_Fully_Declared
;
2047 -------------------------
2048 -- Check_Nested_Access --
2049 -------------------------
2051 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2052 Scop
: constant Entity_Id
:= Current_Scope
;
2053 Current_Subp
: Entity_Id
;
2054 Enclosing
: Entity_Id
;
2057 -- Currently only enabled for VM back-ends for efficiency, should we
2058 -- enable it more systematically ???
2060 -- Check for Is_Imported needs commenting below ???
2062 if VM_Target
/= No_VM
2063 and then (Ekind
(Ent
) = E_Variable
2065 Ekind
(Ent
) = E_Constant
2067 Ekind
(Ent
) = E_Loop_Parameter
)
2068 and then Scope
(Ent
) /= Empty
2069 and then not Is_Library_Level_Entity
(Ent
)
2070 and then not Is_Imported
(Ent
)
2072 if Is_Subprogram
(Scop
)
2073 or else Is_Generic_Subprogram
(Scop
)
2074 or else Is_Entry
(Scop
)
2076 Current_Subp
:= Scop
;
2078 Current_Subp
:= Current_Subprogram
;
2081 Enclosing
:= Enclosing_Subprogram
(Ent
);
2083 if Enclosing
/= Empty
2084 and then Enclosing
/= Current_Subp
2086 Set_Has_Up_Level_Access
(Ent
, True);
2089 end Check_Nested_Access
;
2091 ------------------------------------------
2092 -- Check_Potentially_Blocking_Operation --
2093 ------------------------------------------
2095 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2099 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2100 -- When pragma Detect_Blocking is active, the run time will raise
2101 -- Program_Error. Here we only issue a warning, since we generally
2102 -- support the use of potentially blocking operations in the absence
2105 -- Indirect blocking through a subprogram call cannot be diagnosed
2106 -- statically without interprocedural analysis, so we do not attempt
2109 S
:= Scope
(Current_Scope
);
2110 while Present
(S
) and then S
/= Standard_Standard
loop
2111 if Is_Protected_Type
(S
) then
2113 ("potentially blocking operation in protected operation??", N
);
2119 end Check_Potentially_Blocking_Operation
;
2121 ------------------------------
2122 -- Check_Unprotected_Access --
2123 ------------------------------
2125 procedure Check_Unprotected_Access
2129 Cont_Encl_Typ
: Entity_Id
;
2130 Pref_Encl_Typ
: Entity_Id
;
2132 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
2133 -- Check whether Obj is a private component of a protected object.
2134 -- Return the protected type where the component resides, Empty
2137 function Is_Public_Operation
return Boolean;
2138 -- Verify that the enclosing operation is callable from outside the
2139 -- protected object, to minimize false positives.
2141 ------------------------------
2142 -- Enclosing_Protected_Type --
2143 ------------------------------
2145 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
2147 if Is_Entity_Name
(Obj
) then
2149 Ent
: Entity_Id
:= Entity
(Obj
);
2152 -- The object can be a renaming of a private component, use
2153 -- the original record component.
2155 if Is_Prival
(Ent
) then
2156 Ent
:= Prival_Link
(Ent
);
2159 if Is_Protected_Type
(Scope
(Ent
)) then
2165 -- For indexed and selected components, recursively check the prefix
2167 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
2168 return Enclosing_Protected_Type
(Prefix
(Obj
));
2170 -- The object does not denote a protected component
2175 end Enclosing_Protected_Type
;
2177 -------------------------
2178 -- Is_Public_Operation --
2179 -------------------------
2181 function Is_Public_Operation
return Boolean is
2188 and then S
/= Pref_Encl_Typ
2190 if Scope
(S
) = Pref_Encl_Typ
then
2191 E
:= First_Entity
(Pref_Encl_Typ
);
2193 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
2206 end Is_Public_Operation
;
2208 -- Start of processing for Check_Unprotected_Access
2211 if Nkind
(Expr
) = N_Attribute_Reference
2212 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
2214 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
2215 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
2217 -- Check whether we are trying to export a protected component to a
2218 -- context with an equal or lower access level.
2220 if Present
(Pref_Encl_Typ
)
2221 and then No
(Cont_Encl_Typ
)
2222 and then Is_Public_Operation
2223 and then Scope_Depth
(Pref_Encl_Typ
) >=
2224 Object_Access_Level
(Context
)
2227 ("??possible unprotected access to protected data", Expr
);
2230 end Check_Unprotected_Access
;
2236 procedure Check_VMS
(Construct
: Node_Id
) is
2238 if not OpenVMS_On_Target
then
2240 ("this construct is allowed only in Open'V'M'S", Construct
);
2244 ------------------------
2245 -- Collect_Interfaces --
2246 ------------------------
2248 procedure Collect_Interfaces
2250 Ifaces_List
: out Elist_Id
;
2251 Exclude_Parents
: Boolean := False;
2252 Use_Full_View
: Boolean := True)
2254 procedure Collect
(Typ
: Entity_Id
);
2255 -- Subsidiary subprogram used to traverse the whole list
2256 -- of directly and indirectly implemented interfaces
2262 procedure Collect
(Typ
: Entity_Id
) is
2263 Ancestor
: Entity_Id
;
2271 -- Handle private types
2274 and then Is_Private_Type
(Typ
)
2275 and then Present
(Full_View
(Typ
))
2277 Full_T
:= Full_View
(Typ
);
2280 -- Include the ancestor if we are generating the whole list of
2281 -- abstract interfaces.
2283 if Etype
(Full_T
) /= Typ
2285 -- Protect the frontend against wrong sources. For example:
2288 -- type A is tagged null record;
2289 -- type B is new A with private;
2290 -- type C is new A with private;
2292 -- type B is new C with null record;
2293 -- type C is new B with null record;
2296 and then Etype
(Full_T
) /= T
2298 Ancestor
:= Etype
(Full_T
);
2301 if Is_Interface
(Ancestor
)
2302 and then not Exclude_Parents
2304 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
2308 -- Traverse the graph of ancestor interfaces
2310 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
2311 Id
:= First
(Abstract_Interface_List
(Full_T
));
2312 while Present
(Id
) loop
2313 Iface
:= Etype
(Id
);
2315 -- Protect against wrong uses. For example:
2316 -- type I is interface;
2317 -- type O is tagged null record;
2318 -- type Wrong is new I and O with null record; -- ERROR
2320 if Is_Interface
(Iface
) then
2322 and then Etype
(T
) /= T
2323 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
2328 Append_Unique_Elmt
(Iface
, Ifaces_List
);
2337 -- Start of processing for Collect_Interfaces
2340 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
2341 Ifaces_List
:= New_Elmt_List
;
2343 end Collect_Interfaces
;
2345 ----------------------------------
2346 -- Collect_Interface_Components --
2347 ----------------------------------
2349 procedure Collect_Interface_Components
2350 (Tagged_Type
: Entity_Id
;
2351 Components_List
: out Elist_Id
)
2353 procedure Collect
(Typ
: Entity_Id
);
2354 -- Subsidiary subprogram used to climb to the parents
2360 procedure Collect
(Typ
: Entity_Id
) is
2361 Tag_Comp
: Entity_Id
;
2362 Parent_Typ
: Entity_Id
;
2365 -- Handle private types
2367 if Present
(Full_View
(Etype
(Typ
))) then
2368 Parent_Typ
:= Full_View
(Etype
(Typ
));
2370 Parent_Typ
:= Etype
(Typ
);
2373 if Parent_Typ
/= Typ
2375 -- Protect the frontend against wrong sources. For example:
2378 -- type A is tagged null record;
2379 -- type B is new A with private;
2380 -- type C is new A with private;
2382 -- type B is new C with null record;
2383 -- type C is new B with null record;
2386 and then Parent_Typ
/= Tagged_Type
2388 Collect
(Parent_Typ
);
2391 -- Collect the components containing tags of secondary dispatch
2394 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
2395 while Present
(Tag_Comp
) loop
2396 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
2397 Append_Elmt
(Tag_Comp
, Components_List
);
2399 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
2403 -- Start of processing for Collect_Interface_Components
2406 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
2407 and then Is_Tagged_Type
(Tagged_Type
));
2409 Components_List
:= New_Elmt_List
;
2410 Collect
(Tagged_Type
);
2411 end Collect_Interface_Components
;
2413 -----------------------------
2414 -- Collect_Interfaces_Info --
2415 -----------------------------
2417 procedure Collect_Interfaces_Info
2419 Ifaces_List
: out Elist_Id
;
2420 Components_List
: out Elist_Id
;
2421 Tags_List
: out Elist_Id
)
2423 Comps_List
: Elist_Id
;
2424 Comp_Elmt
: Elmt_Id
;
2425 Comp_Iface
: Entity_Id
;
2426 Iface_Elmt
: Elmt_Id
;
2429 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
2430 -- Search for the secondary tag associated with the interface type
2431 -- Iface that is implemented by T.
2437 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
2440 if not Is_CPP_Class
(T
) then
2441 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
2443 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
2447 and then Is_Tag
(Node
(ADT
))
2448 and then Related_Type
(Node
(ADT
)) /= Iface
2450 -- Skip secondary dispatch table referencing thunks to user
2451 -- defined primitives covered by this interface.
2453 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
2456 -- Skip secondary dispatch tables of Ada types
2458 if not Is_CPP_Class
(T
) then
2460 -- Skip secondary dispatch table referencing thunks to
2461 -- predefined primitives.
2463 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
2466 -- Skip secondary dispatch table referencing user-defined
2467 -- primitives covered by this interface.
2469 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
2472 -- Skip secondary dispatch table referencing predefined
2475 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
2480 pragma Assert
(Is_Tag
(Node
(ADT
)));
2484 -- Start of processing for Collect_Interfaces_Info
2487 Collect_Interfaces
(T
, Ifaces_List
);
2488 Collect_Interface_Components
(T
, Comps_List
);
2490 -- Search for the record component and tag associated with each
2491 -- interface type of T.
2493 Components_List
:= New_Elmt_List
;
2494 Tags_List
:= New_Elmt_List
;
2496 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
2497 while Present
(Iface_Elmt
) loop
2498 Iface
:= Node
(Iface_Elmt
);
2500 -- Associate the primary tag component and the primary dispatch table
2501 -- with all the interfaces that are parents of T
2503 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
2504 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
2505 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
2507 -- Otherwise search for the tag component and secondary dispatch
2511 Comp_Elmt
:= First_Elmt
(Comps_List
);
2512 while Present
(Comp_Elmt
) loop
2513 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
2515 if Comp_Iface
= Iface
2516 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
2518 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
2519 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
2523 Next_Elmt
(Comp_Elmt
);
2525 pragma Assert
(Present
(Comp_Elmt
));
2528 Next_Elmt
(Iface_Elmt
);
2530 end Collect_Interfaces_Info
;
2532 ---------------------
2533 -- Collect_Parents --
2534 ---------------------
2536 procedure Collect_Parents
2538 List
: out Elist_Id
;
2539 Use_Full_View
: Boolean := True)
2541 Current_Typ
: Entity_Id
:= T
;
2542 Parent_Typ
: Entity_Id
;
2545 List
:= New_Elmt_List
;
2547 -- No action if the if the type has no parents
2549 if T
= Etype
(T
) then
2554 Parent_Typ
:= Etype
(Current_Typ
);
2556 if Is_Private_Type
(Parent_Typ
)
2557 and then Present
(Full_View
(Parent_Typ
))
2558 and then Use_Full_View
2560 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
2563 Append_Elmt
(Parent_Typ
, List
);
2565 exit when Parent_Typ
= Current_Typ
;
2566 Current_Typ
:= Parent_Typ
;
2568 end Collect_Parents
;
2570 ----------------------------------
2571 -- Collect_Primitive_Operations --
2572 ----------------------------------
2574 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
2575 B_Type
: constant Entity_Id
:= Base_Type
(T
);
2576 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
2577 B_Scope
: Entity_Id
:= Scope
(B_Type
);
2581 Is_Type_In_Pkg
: Boolean;
2582 Formal_Derived
: Boolean := False;
2585 function Match
(E
: Entity_Id
) return Boolean;
2586 -- True if E's base type is B_Type, or E is of an anonymous access type
2587 -- and the base type of its designated type is B_Type.
2593 function Match
(E
: Entity_Id
) return Boolean is
2594 Etyp
: Entity_Id
:= Etype
(E
);
2597 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
2598 Etyp
:= Designated_Type
(Etyp
);
2601 return Base_Type
(Etyp
) = B_Type
;
2604 -- Start of processing for Collect_Primitive_Operations
2607 -- For tagged types, the primitive operations are collected as they
2608 -- are declared, and held in an explicit list which is simply returned.
2610 if Is_Tagged_Type
(B_Type
) then
2611 return Primitive_Operations
(B_Type
);
2613 -- An untagged generic type that is a derived type inherits the
2614 -- primitive operations of its parent type. Other formal types only
2615 -- have predefined operators, which are not explicitly represented.
2617 elsif Is_Generic_Type
(B_Type
) then
2618 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
2619 and then Nkind
(Formal_Type_Definition
(B_Decl
))
2620 = N_Formal_Derived_Type_Definition
2622 Formal_Derived
:= True;
2624 return New_Elmt_List
;
2628 Op_List
:= New_Elmt_List
;
2630 if B_Scope
= Standard_Standard
then
2631 if B_Type
= Standard_String
then
2632 Append_Elmt
(Standard_Op_Concat
, Op_List
);
2634 elsif B_Type
= Standard_Wide_String
then
2635 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
2641 -- Locate the primitive subprograms of the type
2644 -- The primitive operations appear after the base type, except
2645 -- if the derivation happens within the private part of B_Scope
2646 -- and the type is a private type, in which case both the type
2647 -- and some primitive operations may appear before the base
2648 -- type, and the list of candidates starts after the type.
2650 if In_Open_Scopes
(B_Scope
)
2651 and then Scope
(T
) = B_Scope
2652 and then In_Private_Part
(B_Scope
)
2654 Id
:= Next_Entity
(T
);
2656 Id
:= Next_Entity
(B_Type
);
2659 -- Set flag if this is a type in a package spec
2662 Is_Package_Or_Generic_Package
(B_Scope
)
2664 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
2667 while Present
(Id
) loop
2669 -- Test whether the result type or any of the parameter types of
2670 -- each subprogram following the type match that type when the
2671 -- type is declared in a package spec, is a derived type, or the
2672 -- subprogram is marked as primitive. (The Is_Primitive test is
2673 -- needed to find primitives of nonderived types in declarative
2674 -- parts that happen to override the predefined "=" operator.)
2676 -- Note that generic formal subprograms are not considered to be
2677 -- primitive operations and thus are never inherited.
2679 if Is_Overloadable
(Id
)
2680 and then (Is_Type_In_Pkg
2681 or else Is_Derived_Type
(B_Type
)
2682 or else Is_Primitive
(Id
))
2683 and then Nkind
(Parent
(Parent
(Id
)))
2684 not in N_Formal_Subprogram_Declaration
2692 Formal
:= First_Formal
(Id
);
2693 while Present
(Formal
) loop
2694 if Match
(Formal
) then
2699 Next_Formal
(Formal
);
2703 -- For a formal derived type, the only primitives are the ones
2704 -- inherited from the parent type. Operations appearing in the
2705 -- package declaration are not primitive for it.
2708 and then (not Formal_Derived
2709 or else Present
(Alias
(Id
)))
2711 -- In the special case of an equality operator aliased to
2712 -- an overriding dispatching equality belonging to the same
2713 -- type, we don't include it in the list of primitives.
2714 -- This avoids inheriting multiple equality operators when
2715 -- deriving from untagged private types whose full type is
2716 -- tagged, which can otherwise cause ambiguities. Note that
2717 -- this should only happen for this kind of untagged parent
2718 -- type, since normally dispatching operations are inherited
2719 -- using the type's Primitive_Operations list.
2721 if Chars
(Id
) = Name_Op_Eq
2722 and then Is_Dispatching_Operation
(Id
)
2723 and then Present
(Alias
(Id
))
2724 and then Present
(Overridden_Operation
(Alias
(Id
)))
2725 and then Base_Type
(Etype
(First_Entity
(Id
))) =
2726 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
2730 -- Include the subprogram in the list of primitives
2733 Append_Elmt
(Id
, Op_List
);
2740 -- For a type declared in System, some of its operations may
2741 -- appear in the target-specific extension to System.
2744 and then B_Scope
= RTU_Entity
(System
)
2745 and then Present_System_Aux
2747 B_Scope
:= System_Aux_Id
;
2748 Id
:= First_Entity
(System_Aux_Id
);
2754 end Collect_Primitive_Operations
;
2756 -----------------------------------
2757 -- Compile_Time_Constraint_Error --
2758 -----------------------------------
2760 function Compile_Time_Constraint_Error
2763 Ent
: Entity_Id
:= Empty
;
2764 Loc
: Source_Ptr
:= No_Location
;
2765 Warn
: Boolean := False) return Node_Id
2767 Msgc
: String (1 .. Msg
'Length + 3);
2768 -- Copy of message, with room for possible ?? and ! at end
2778 -- A static constraint error in an instance body is not a fatal error.
2779 -- we choose to inhibit the message altogether, because there is no
2780 -- obvious node (for now) on which to post it. On the other hand the
2781 -- offending node must be replaced with a constraint_error in any case.
2783 -- No messages are generated if we already posted an error on this node
2785 if not Error_Posted
(N
) then
2786 if Loc
/= No_Location
then
2792 Msgc
(1 .. Msg
'Length) := Msg
;
2795 -- Message is a warning, even in Ada 95 case
2797 if Msg
(Msg
'Last) = '?' then
2800 -- In Ada 83, all messages are warnings. In the private part and
2801 -- the body of an instance, constraint_checks are only warnings.
2802 -- We also make this a warning if the Warn parameter is set.
2805 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
2813 elsif In_Instance_Not_Visible
then
2820 -- Otherwise we have a real error message (Ada 95 static case)
2821 -- and we make this an unconditional message. Note that in the
2822 -- warning case we do not make the message unconditional, it seems
2823 -- quite reasonable to delete messages like this (about exceptions
2824 -- that will be raised) in dead code.
2832 -- Should we generate a warning? The answer is not quite yes. The
2833 -- very annoying exception occurs in the case of a short circuit
2834 -- operator where the left operand is static and decisive. Climb
2835 -- parents to see if that is the case we have here. Conditional
2836 -- expressions with decisive conditions are a similar situation.
2844 -- And then with False as left operand
2846 if Nkind
(P
) = N_And_Then
2847 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
2848 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
2853 -- OR ELSE with True as left operand
2855 elsif Nkind
(P
) = N_Or_Else
2856 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
2857 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
2864 elsif Nkind
(P
) = N_If_Expression
then
2866 Cond
: constant Node_Id
:= First
(Expressions
(P
));
2867 Texp
: constant Node_Id
:= Next
(Cond
);
2868 Fexp
: constant Node_Id
:= Next
(Texp
);
2871 if Compile_Time_Known_Value
(Cond
) then
2873 -- Condition is True and we are in the right operand
2875 if Is_True
(Expr_Value
(Cond
))
2876 and then OldP
= Fexp
2881 -- Condition is False and we are in the left operand
2883 elsif Is_False
(Expr_Value
(Cond
))
2884 and then OldP
= Texp
2892 -- Special case for component association in aggregates, where
2893 -- we want to keep climbing up to the parent aggregate.
2895 elsif Nkind
(P
) = N_Component_Association
2896 and then Nkind
(Parent
(P
)) = N_Aggregate
2900 -- Keep going if within subexpression
2903 exit when Nkind
(P
) not in N_Subexpr
;
2908 if Present
(Ent
) then
2909 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
2911 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
2916 -- Check whether the context is an Init_Proc
2918 if Inside_Init_Proc
then
2920 Conc_Typ
: constant Entity_Id
:=
2921 Corresponding_Concurrent_Type
2922 (Entity
(Parameter_Type
(First
2923 (Parameter_Specifications
2924 (Parent
(Current_Scope
))))));
2927 -- Don't complain if the corresponding concurrent type
2928 -- doesn't come from source (i.e. a single task/protected
2931 if Present
(Conc_Typ
)
2932 and then not Comes_From_Source
(Conc_Typ
)
2935 ("\??& will be raised at run time",
2936 N
, Standard_Constraint_Error
, Eloc
);
2940 ("\??& will be raised for objects of this type",
2941 N
, Standard_Constraint_Error
, Eloc
);
2947 ("\??& will be raised at run time",
2948 N
, Standard_Constraint_Error
, Eloc
);
2953 ("\static expression fails Constraint_Check", Eloc
);
2954 Set_Error_Posted
(N
);
2960 end Compile_Time_Constraint_Error
;
2962 -----------------------
2963 -- Conditional_Delay --
2964 -----------------------
2966 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
2968 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
2969 Set_Has_Delayed_Freeze
(New_Ent
);
2971 end Conditional_Delay
;
2973 -------------------------
2974 -- Copy_Component_List --
2975 -------------------------
2977 function Copy_Component_List
2979 Loc
: Source_Ptr
) return List_Id
2982 Comps
: constant List_Id
:= New_List
;
2985 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
2986 while Present
(Comp
) loop
2987 if Comes_From_Source
(Comp
) then
2989 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
2992 Make_Component_Declaration
(Loc
,
2993 Defining_Identifier
=>
2994 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
2995 Component_Definition
=>
2997 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
3001 Next_Component
(Comp
);
3005 end Copy_Component_List
;
3007 -------------------------
3008 -- Copy_Parameter_List --
3009 -------------------------
3011 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
3012 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
3017 if No
(First_Formal
(Subp_Id
)) then
3021 Formal
:= First_Formal
(Subp_Id
);
3022 while Present
(Formal
) loop
3024 (Make_Parameter_Specification
(Loc
,
3025 Defining_Identifier
=>
3026 Make_Defining_Identifier
(Sloc
(Formal
),
3027 Chars
=> Chars
(Formal
)),
3028 In_Present
=> In_Present
(Parent
(Formal
)),
3029 Out_Present
=> Out_Present
(Parent
(Formal
)),
3031 New_Reference_To
(Etype
(Formal
), Loc
),
3033 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
3036 Next_Formal
(Formal
);
3041 end Copy_Parameter_List
;
3043 --------------------------------
3044 -- Corresponding_Generic_Type --
3045 --------------------------------
3047 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
3053 if not Is_Generic_Actual_Type
(T
) then
3056 -- If the actual is the actual of an enclosing instance, resolution
3057 -- was correct in the generic.
3059 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
3060 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
3062 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
3069 if Is_Wrapper_Package
(Inst
) then
3070 Inst
:= Related_Instance
(Inst
);
3075 (Specification
(Unit_Declaration_Node
(Inst
)));
3077 -- Generic actual has the same name as the corresponding formal
3079 Typ
:= First_Entity
(Gen
);
3080 while Present
(Typ
) loop
3081 if Chars
(Typ
) = Chars
(T
) then
3090 end Corresponding_Generic_Type
;
3092 --------------------
3093 -- Current_Entity --
3094 --------------------
3096 -- The currently visible definition for a given identifier is the
3097 -- one most chained at the start of the visibility chain, i.e. the
3098 -- one that is referenced by the Node_Id value of the name of the
3099 -- given identifier.
3101 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
3103 return Get_Name_Entity_Id
(Chars
(N
));
3106 -----------------------------
3107 -- Current_Entity_In_Scope --
3108 -----------------------------
3110 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
3112 CS
: constant Entity_Id
:= Current_Scope
;
3114 Transient_Case
: constant Boolean := Scope_Is_Transient
;
3117 E
:= Get_Name_Entity_Id
(Chars
(N
));
3119 and then Scope
(E
) /= CS
3120 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
3126 end Current_Entity_In_Scope
;
3132 function Current_Scope
return Entity_Id
is
3134 if Scope_Stack
.Last
= -1 then
3135 return Standard_Standard
;
3138 C
: constant Entity_Id
:=
3139 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
3144 return Standard_Standard
;
3150 ------------------------
3151 -- Current_Subprogram --
3152 ------------------------
3154 function Current_Subprogram
return Entity_Id
is
3155 Scop
: constant Entity_Id
:= Current_Scope
;
3157 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
3160 return Enclosing_Subprogram
(Scop
);
3162 end Current_Subprogram
;
3164 ----------------------------------
3165 -- Deepest_Type_Access_Level --
3166 ----------------------------------
3168 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
3170 if Ekind
(Typ
) = E_Anonymous_Access_Type
3171 and then not Is_Local_Anonymous_Access
(Typ
)
3172 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
3174 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
3178 Scope_Depth
(Enclosing_Dynamic_Scope
3179 (Defining_Identifier
3180 (Associated_Node_For_Itype
(Typ
))));
3182 -- For generic formal type, return Int'Last (infinite).
3183 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
3185 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
3186 return UI_From_Int
(Int
'Last);
3189 return Type_Access_Level
(Typ
);
3191 end Deepest_Type_Access_Level
;
3193 ---------------------
3194 -- Defining_Entity --
3195 ---------------------
3197 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
3198 K
: constant Node_Kind
:= Nkind
(N
);
3199 Err
: Entity_Id
:= Empty
;
3204 N_Subprogram_Declaration |
3205 N_Abstract_Subprogram_Declaration |
3207 N_Package_Declaration |
3208 N_Subprogram_Renaming_Declaration |
3209 N_Subprogram_Body_Stub |
3210 N_Generic_Subprogram_Declaration |
3211 N_Generic_Package_Declaration |
3212 N_Formal_Subprogram_Declaration |
3213 N_Expression_Function
3215 return Defining_Entity
(Specification
(N
));
3218 N_Component_Declaration |
3219 N_Defining_Program_Unit_Name |
3220 N_Discriminant_Specification |
3222 N_Entry_Declaration |
3223 N_Entry_Index_Specification |
3224 N_Exception_Declaration |
3225 N_Exception_Renaming_Declaration |
3226 N_Formal_Object_Declaration |
3227 N_Formal_Package_Declaration |
3228 N_Formal_Type_Declaration |
3229 N_Full_Type_Declaration |
3230 N_Implicit_Label_Declaration |
3231 N_Incomplete_Type_Declaration |
3232 N_Loop_Parameter_Specification |
3233 N_Number_Declaration |
3234 N_Object_Declaration |
3235 N_Object_Renaming_Declaration |
3236 N_Package_Body_Stub |
3237 N_Parameter_Specification |
3238 N_Private_Extension_Declaration |
3239 N_Private_Type_Declaration |
3241 N_Protected_Body_Stub |
3242 N_Protected_Type_Declaration |
3243 N_Single_Protected_Declaration |
3244 N_Single_Task_Declaration |
3245 N_Subtype_Declaration |
3248 N_Task_Type_Declaration
3250 return Defining_Identifier
(N
);
3253 return Defining_Entity
(Proper_Body
(N
));
3256 N_Function_Instantiation |
3257 N_Function_Specification |
3258 N_Generic_Function_Renaming_Declaration |
3259 N_Generic_Package_Renaming_Declaration |
3260 N_Generic_Procedure_Renaming_Declaration |
3262 N_Package_Instantiation |
3263 N_Package_Renaming_Declaration |
3264 N_Package_Specification |
3265 N_Procedure_Instantiation |
3266 N_Procedure_Specification
3269 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
3272 if Nkind
(Nam
) in N_Entity
then
3275 -- For Error, make up a name and attach to declaration
3276 -- so we can continue semantic analysis
3278 elsif Nam
= Error
then
3279 Err
:= Make_Temporary
(Sloc
(N
), 'T');
3280 Set_Defining_Unit_Name
(N
, Err
);
3283 -- If not an entity, get defining identifier
3286 return Defining_Identifier
(Nam
);
3290 when N_Block_Statement
=>
3291 return Entity
(Identifier
(N
));
3294 raise Program_Error
;
3297 end Defining_Entity
;
3299 --------------------------
3300 -- Denotes_Discriminant --
3301 --------------------------
3303 function Denotes_Discriminant
3305 Check_Concurrent
: Boolean := False) return Boolean
3309 if not Is_Entity_Name
(N
)
3310 or else No
(Entity
(N
))
3317 -- If we are checking for a protected type, the discriminant may have
3318 -- been rewritten as the corresponding discriminal of the original type
3319 -- or of the corresponding concurrent record, depending on whether we
3320 -- are in the spec or body of the protected type.
3322 return Ekind
(E
) = E_Discriminant
3325 and then Ekind
(E
) = E_In_Parameter
3326 and then Present
(Discriminal_Link
(E
))
3328 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
3330 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
3332 end Denotes_Discriminant
;
3334 -------------------------
3335 -- Denotes_Same_Object --
3336 -------------------------
3338 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
3339 Obj1
: Node_Id
:= A1
;
3340 Obj2
: Node_Id
:= A2
;
3342 function Has_Prefix
(N
: Node_Id
) return Boolean;
3343 -- Return True if N has attribute Prefix
3345 function Is_Renaming
(N
: Node_Id
) return Boolean;
3346 -- Return true if N names a renaming entity
3348 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
3349 -- For renamings, return False if the prefix of any dereference within
3350 -- the renamed object_name is a variable, or any expression within the
3351 -- renamed object_name contains references to variables or calls on
3352 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
3358 function Has_Prefix
(N
: Node_Id
) return Boolean is
3362 N_Attribute_Reference
,
3364 N_Explicit_Dereference
,
3365 N_Indexed_Component
,
3367 N_Selected_Component
,
3375 function Is_Renaming
(N
: Node_Id
) return Boolean is
3377 return Is_Entity_Name
(N
)
3378 and then Present
(Renamed_Entity
(Entity
(N
)));
3381 -----------------------
3382 -- Is_Valid_Renaming --
3383 -----------------------
3385 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
3387 function Check_Renaming
(N
: Node_Id
) return Boolean;
3388 -- Recursive function used to traverse all the prefixes of N
3390 function Check_Renaming
(N
: Node_Id
) return Boolean is
3393 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
3398 if Nkind
(N
) = N_Indexed_Component
then
3403 Indx
:= First
(Expressions
(N
));
3404 while Present
(Indx
) loop
3405 if not Is_OK_Static_Expression
(Indx
) then
3414 if Has_Prefix
(N
) then
3416 P
: constant Node_Id
:= Prefix
(N
);
3419 if Nkind
(N
) = N_Explicit_Dereference
3420 and then Is_Variable
(P
)
3424 elsif Is_Entity_Name
(P
)
3425 and then Ekind
(Entity
(P
)) = E_Function
3429 elsif Nkind
(P
) = N_Function_Call
then
3433 -- Recursion to continue traversing the prefix of the
3434 -- renaming expression
3436 return Check_Renaming
(P
);
3443 -- Start of processing for Is_Valid_Renaming
3446 return Check_Renaming
(N
);
3447 end Is_Valid_Renaming
;
3449 -- Start of processing for Denotes_Same_Object
3452 -- Both names statically denote the same stand-alone object or parameter
3453 -- (RM 6.4.1(6.5/3))
3455 if Is_Entity_Name
(Obj1
)
3456 and then Is_Entity_Name
(Obj2
)
3457 and then Entity
(Obj1
) = Entity
(Obj2
)
3462 -- For renamings, the prefix of any dereference within the renamed
3463 -- object_name is not a variable, and any expression within the
3464 -- renamed object_name contains no references to variables nor
3465 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
3467 if Is_Renaming
(Obj1
) then
3468 if Is_Valid_Renaming
(Obj1
) then
3469 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
3475 if Is_Renaming
(Obj2
) then
3476 if Is_Valid_Renaming
(Obj2
) then
3477 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
3483 -- No match if not same node kind (such cases are handled by
3484 -- Denotes_Same_Prefix)
3486 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
3489 -- After handling valid renamings, one of the two names statically
3490 -- denoted a renaming declaration whose renamed object_name is known
3491 -- to denote the same object as the other (RM 6.4.1(6.10/3))
3493 elsif Is_Entity_Name
(Obj1
) then
3494 if Is_Entity_Name
(Obj2
) then
3495 return Entity
(Obj1
) = Entity
(Obj2
);
3500 -- Both names are selected_components, their prefixes are known to
3501 -- denote the same object, and their selector_names denote the same
3502 -- component (RM 6.4.1(6.6/3)
3504 elsif Nkind
(Obj1
) = N_Selected_Component
then
3505 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
3507 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
3509 -- Both names are dereferences and the dereferenced names are known to
3510 -- denote the same object (RM 6.4.1(6.7/3))
3512 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
3513 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
3515 -- Both names are indexed_components, their prefixes are known to denote
3516 -- the same object, and each of the pairs of corresponding index values
3517 -- are either both static expressions with the same static value or both
3518 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
3520 elsif Nkind
(Obj1
) = N_Indexed_Component
then
3521 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
3529 Indx1
:= First
(Expressions
(Obj1
));
3530 Indx2
:= First
(Expressions
(Obj2
));
3531 while Present
(Indx1
) loop
3533 -- Indexes must denote the same static value or same object
3535 if Is_OK_Static_Expression
(Indx1
) then
3536 if not Is_OK_Static_Expression
(Indx2
) then
3539 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
3543 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
3555 -- Both names are slices, their prefixes are known to denote the same
3556 -- object, and the two slices have statically matching index constraints
3557 -- (RM 6.4.1(6.9/3))
3559 elsif Nkind
(Obj1
) = N_Slice
3560 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
3563 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
3566 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
3567 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
3569 -- Check whether bounds are statically identical. There is no
3570 -- attempt to detect partial overlap of slices.
3572 return Denotes_Same_Object
(Lo1
, Lo2
)
3573 and then Denotes_Same_Object
(Hi1
, Hi2
);
3576 -- In the recursion, literals appear as indexes.
3578 elsif Nkind
(Obj1
) = N_Integer_Literal
3579 and then Nkind
(Obj2
) = N_Integer_Literal
3581 return Intval
(Obj1
) = Intval
(Obj2
);
3586 end Denotes_Same_Object
;
3588 -------------------------
3589 -- Denotes_Same_Prefix --
3590 -------------------------
3592 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
3595 if Is_Entity_Name
(A1
) then
3596 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
3597 and then not Is_Access_Type
(Etype
(A1
))
3599 return Denotes_Same_Object
(A1
, Prefix
(A2
))
3600 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
3605 elsif Is_Entity_Name
(A2
) then
3606 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
3608 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
3610 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
3613 Root1
, Root2
: Node_Id
;
3614 Depth1
, Depth2
: Int
:= 0;
3617 Root1
:= Prefix
(A1
);
3618 while not Is_Entity_Name
(Root1
) loop
3620 (Root1
, N_Selected_Component
, N_Indexed_Component
)
3624 Root1
:= Prefix
(Root1
);
3627 Depth1
:= Depth1
+ 1;
3630 Root2
:= Prefix
(A2
);
3631 while not Is_Entity_Name
(Root2
) loop
3633 (Root2
, N_Selected_Component
, N_Indexed_Component
)
3637 Root2
:= Prefix
(Root2
);
3640 Depth2
:= Depth2
+ 1;
3643 -- If both have the same depth and they do not denote the same
3644 -- object, they are disjoint and no warning is needed.
3646 if Depth1
= Depth2
then
3649 elsif Depth1
> Depth2
then
3650 Root1
:= Prefix
(A1
);
3651 for I
in 1 .. Depth1
- Depth2
- 1 loop
3652 Root1
:= Prefix
(Root1
);
3655 return Denotes_Same_Object
(Root1
, A2
);
3658 Root2
:= Prefix
(A2
);
3659 for I
in 1 .. Depth2
- Depth1
- 1 loop
3660 Root2
:= Prefix
(Root2
);
3663 return Denotes_Same_Object
(A1
, Root2
);
3670 end Denotes_Same_Prefix
;
3672 ----------------------
3673 -- Denotes_Variable --
3674 ----------------------
3676 function Denotes_Variable
(N
: Node_Id
) return Boolean is
3678 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
3679 end Denotes_Variable
;
3681 -----------------------------
3682 -- Depends_On_Discriminant --
3683 -----------------------------
3685 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
3690 Get_Index_Bounds
(N
, L
, H
);
3691 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
3692 end Depends_On_Discriminant
;
3694 -------------------------
3695 -- Designate_Same_Unit --
3696 -------------------------
3698 function Designate_Same_Unit
3700 Name2
: Node_Id
) return Boolean
3702 K1
: constant Node_Kind
:= Nkind
(Name1
);
3703 K2
: constant Node_Kind
:= Nkind
(Name2
);
3705 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
3706 -- Returns the parent unit name node of a defining program unit name
3707 -- or the prefix if N is a selected component or an expanded name.
3709 function Select_Node
(N
: Node_Id
) return Node_Id
;
3710 -- Returns the defining identifier node of a defining program unit
3711 -- name or the selector node if N is a selected component or an
3718 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
3720 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
3732 function Select_Node
(N
: Node_Id
) return Node_Id
is
3734 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
3735 return Defining_Identifier
(N
);
3738 return Selector_Name
(N
);
3742 -- Start of processing for Designate_Next_Unit
3745 if (K1
= N_Identifier
or else
3746 K1
= N_Defining_Identifier
)
3748 (K2
= N_Identifier
or else
3749 K2
= N_Defining_Identifier
)
3751 return Chars
(Name1
) = Chars
(Name2
);
3754 (K1
= N_Expanded_Name
or else
3755 K1
= N_Selected_Component
or else
3756 K1
= N_Defining_Program_Unit_Name
)
3758 (K2
= N_Expanded_Name
or else
3759 K2
= N_Selected_Component
or else
3760 K2
= N_Defining_Program_Unit_Name
)
3763 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
3765 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
3770 end Designate_Same_Unit
;
3772 ------------------------------------------
3773 -- function Dynamic_Accessibility_Level --
3774 ------------------------------------------
3776 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
3778 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
3780 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
3781 -- Construct an integer literal representing an accessibility level
3782 -- with its type set to Natural.
3784 ------------------------
3785 -- Make_Level_Literal --
3786 ------------------------
3788 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
3789 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
3791 Set_Etype
(Result
, Standard_Natural
);
3793 end Make_Level_Literal
;
3795 -- Start of processing for Dynamic_Accessibility_Level
3798 if Is_Entity_Name
(Expr
) then
3801 if Present
(Renamed_Object
(E
)) then
3802 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
3805 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
3806 if Present
(Extra_Accessibility
(E
)) then
3807 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
3812 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
3814 case Nkind
(Expr
) is
3816 -- For access discriminant, the level of the enclosing object
3818 when N_Selected_Component
=>
3819 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
3820 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
3821 E_Anonymous_Access_Type
3823 return Make_Level_Literal
(Object_Access_Level
(Expr
));
3826 when N_Attribute_Reference
=>
3827 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
3829 -- For X'Access, the level of the prefix X
3831 when Attribute_Access
=>
3832 return Make_Level_Literal
3833 (Object_Access_Level
(Prefix
(Expr
)));
3835 -- Treat the unchecked attributes as library-level
3837 when Attribute_Unchecked_Access |
3838 Attribute_Unrestricted_Access
=>
3839 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
3841 -- No other access-valued attributes
3844 raise Program_Error
;
3849 -- Unimplemented: depends on context. As an actual parameter where
3850 -- formal type is anonymous, use
3851 -- Scope_Depth (Current_Scope) + 1.
3852 -- For other cases, see 3.10.2(14/3) and following. ???
3856 when N_Type_Conversion
=>
3857 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
3859 -- Handle type conversions introduced for a rename of an
3860 -- Ada 2012 stand-alone object of an anonymous access type.
3862 return Dynamic_Accessibility_Level
(Expression
(Expr
));
3869 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
3870 end Dynamic_Accessibility_Level
;
3872 -----------------------------------
3873 -- Effective_Extra_Accessibility --
3874 -----------------------------------
3876 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
3878 if Present
(Renamed_Object
(Id
))
3879 and then Is_Entity_Name
(Renamed_Object
(Id
))
3881 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
3883 return Extra_Accessibility
(Id
);
3885 end Effective_Extra_Accessibility
;
3887 ------------------------------
3888 -- Enclosing_Comp_Unit_Node --
3889 ------------------------------
3891 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
3892 Current_Node
: Node_Id
;
3896 while Present
(Current_Node
)
3897 and then Nkind
(Current_Node
) /= N_Compilation_Unit
3899 Current_Node
:= Parent
(Current_Node
);
3902 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
3905 return Current_Node
;
3907 end Enclosing_Comp_Unit_Node
;
3909 --------------------------
3910 -- Enclosing_CPP_Parent --
3911 --------------------------
3913 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
3914 Parent_Typ
: Entity_Id
:= Typ
;
3917 while not Is_CPP_Class
(Parent_Typ
)
3918 and then Etype
(Parent_Typ
) /= Parent_Typ
3920 Parent_Typ
:= Etype
(Parent_Typ
);
3922 if Is_Private_Type
(Parent_Typ
) then
3923 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3927 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
3929 end Enclosing_CPP_Parent
;
3931 ----------------------------
3932 -- Enclosing_Generic_Body --
3933 ----------------------------
3935 function Enclosing_Generic_Body
3936 (N
: Node_Id
) return Node_Id
3944 while Present
(P
) loop
3945 if Nkind
(P
) = N_Package_Body
3946 or else Nkind
(P
) = N_Subprogram_Body
3948 Spec
:= Corresponding_Spec
(P
);
3950 if Present
(Spec
) then
3951 Decl
:= Unit_Declaration_Node
(Spec
);
3953 if Nkind
(Decl
) = N_Generic_Package_Declaration
3954 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
3965 end Enclosing_Generic_Body
;
3967 ----------------------------
3968 -- Enclosing_Generic_Unit --
3969 ----------------------------
3971 function Enclosing_Generic_Unit
3972 (N
: Node_Id
) return Node_Id
3980 while Present
(P
) loop
3981 if Nkind
(P
) = N_Generic_Package_Declaration
3982 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
3986 elsif Nkind
(P
) = N_Package_Body
3987 or else Nkind
(P
) = N_Subprogram_Body
3989 Spec
:= Corresponding_Spec
(P
);
3991 if Present
(Spec
) then
3992 Decl
:= Unit_Declaration_Node
(Spec
);
3994 if Nkind
(Decl
) = N_Generic_Package_Declaration
3995 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
4006 end Enclosing_Generic_Unit
;
4008 -------------------------------
4009 -- Enclosing_Lib_Unit_Entity --
4010 -------------------------------
4012 function Enclosing_Lib_Unit_Entity
4013 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
4015 Unit_Entity
: Entity_Id
;
4018 -- Look for enclosing library unit entity by following scope links.
4019 -- Equivalent to, but faster than indexing through the scope stack.
4022 while (Present
(Scope
(Unit_Entity
))
4023 and then Scope
(Unit_Entity
) /= Standard_Standard
)
4024 and not Is_Child_Unit
(Unit_Entity
)
4026 Unit_Entity
:= Scope
(Unit_Entity
);
4030 end Enclosing_Lib_Unit_Entity
;
4032 -----------------------
4033 -- Enclosing_Package --
4034 -----------------------
4036 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
4037 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4040 if Dynamic_Scope
= Standard_Standard
then
4041 return Standard_Standard
;
4043 elsif Dynamic_Scope
= Empty
then
4046 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
4049 return Dynamic_Scope
;
4052 return Enclosing_Package
(Dynamic_Scope
);
4054 end Enclosing_Package
;
4056 --------------------------
4057 -- Enclosing_Subprogram --
4058 --------------------------
4060 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
4061 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
4064 if Dynamic_Scope
= Standard_Standard
then
4067 elsif Dynamic_Scope
= Empty
then
4070 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
4071 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
4073 elsif Ekind
(Dynamic_Scope
) = E_Block
4074 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
4076 return Enclosing_Subprogram
(Dynamic_Scope
);
4078 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
4079 return Get_Task_Body_Procedure
(Dynamic_Scope
);
4081 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
4082 and then Present
(Full_View
(Dynamic_Scope
))
4083 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
4085 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
4087 -- No body is generated if the protected operation is eliminated
4089 elsif Convention
(Dynamic_Scope
) = Convention_Protected
4090 and then not Is_Eliminated
(Dynamic_Scope
)
4091 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
4093 return Protected_Body_Subprogram
(Dynamic_Scope
);
4096 return Dynamic_Scope
;
4098 end Enclosing_Subprogram
;
4100 ------------------------
4101 -- Ensure_Freeze_Node --
4102 ------------------------
4104 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
4108 if No
(Freeze_Node
(E
)) then
4109 FN
:= Make_Freeze_Entity
(Sloc
(E
));
4110 Set_Has_Delayed_Freeze
(E
);
4111 Set_Freeze_Node
(E
, FN
);
4112 Set_Access_Types_To_Process
(FN
, No_Elist
);
4113 Set_TSS_Elist
(FN
, No_Elist
);
4116 end Ensure_Freeze_Node
;
4122 procedure Enter_Name
(Def_Id
: Entity_Id
) is
4123 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
4124 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
4125 S
: constant Entity_Id
:= Current_Scope
;
4128 Generate_Definition
(Def_Id
);
4130 -- Add new name to current scope declarations. Check for duplicate
4131 -- declaration, which may or may not be a genuine error.
4135 -- Case of previous entity entered because of a missing declaration
4136 -- or else a bad subtype indication. Best is to use the new entity,
4137 -- and make the previous one invisible.
4139 if Etype
(E
) = Any_Type
then
4140 Set_Is_Immediately_Visible
(E
, False);
4142 -- Case of renaming declaration constructed for package instances.
4143 -- if there is an explicit declaration with the same identifier,
4144 -- the renaming is not immediately visible any longer, but remains
4145 -- visible through selected component notation.
4147 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
4148 and then not Comes_From_Source
(E
)
4150 Set_Is_Immediately_Visible
(E
, False);
4152 -- The new entity may be the package renaming, which has the same
4153 -- same name as a generic formal which has been seen already.
4155 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
4156 and then not Comes_From_Source
(Def_Id
)
4158 Set_Is_Immediately_Visible
(E
, False);
4160 -- For a fat pointer corresponding to a remote access to subprogram,
4161 -- we use the same identifier as the RAS type, so that the proper
4162 -- name appears in the stub. This type is only retrieved through
4163 -- the RAS type and never by visibility, and is not added to the
4164 -- visibility list (see below).
4166 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
4167 and then Present
(Corresponding_Remote_Type
(Def_Id
))
4171 -- Case of an implicit operation or derived literal. The new entity
4172 -- hides the implicit one, which is removed from all visibility,
4173 -- i.e. the entity list of its scope, and homonym chain of its name.
4175 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
4176 or else Is_Internal
(E
)
4180 Prev_Vis
: Entity_Id
;
4181 Decl
: constant Node_Id
:= Parent
(E
);
4184 -- If E is an implicit declaration, it cannot be the first
4185 -- entity in the scope.
4187 Prev
:= First_Entity
(Current_Scope
);
4188 while Present
(Prev
)
4189 and then Next_Entity
(Prev
) /= E
4196 -- If E is not on the entity chain of the current scope,
4197 -- it is an implicit declaration in the generic formal
4198 -- part of a generic subprogram. When analyzing the body,
4199 -- the generic formals are visible but not on the entity
4200 -- chain of the subprogram. The new entity will become
4201 -- the visible one in the body.
4204 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
4208 Set_Next_Entity
(Prev
, Next_Entity
(E
));
4210 if No
(Next_Entity
(Prev
)) then
4211 Set_Last_Entity
(Current_Scope
, Prev
);
4214 if E
= Current_Entity
(E
) then
4218 Prev_Vis
:= Current_Entity
(E
);
4219 while Homonym
(Prev_Vis
) /= E
loop
4220 Prev_Vis
:= Homonym
(Prev_Vis
);
4224 if Present
(Prev_Vis
) then
4226 -- Skip E in the visibility chain
4228 Set_Homonym
(Prev_Vis
, Homonym
(E
));
4231 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
4236 -- This section of code could use a comment ???
4238 elsif Present
(Etype
(E
))
4239 and then Is_Concurrent_Type
(Etype
(E
))
4244 -- If the homograph is a protected component renaming, it should not
4245 -- be hiding the current entity. Such renamings are treated as weak
4248 elsif Is_Prival
(E
) then
4249 Set_Is_Immediately_Visible
(E
, False);
4251 -- In this case the current entity is a protected component renaming.
4252 -- Perform minimal decoration by setting the scope and return since
4253 -- the prival should not be hiding other visible entities.
4255 elsif Is_Prival
(Def_Id
) then
4256 Set_Scope
(Def_Id
, Current_Scope
);
4259 -- Analogous to privals, the discriminal generated for an entry index
4260 -- parameter acts as a weak declaration. Perform minimal decoration
4261 -- to avoid bogus errors.
4263 elsif Is_Discriminal
(Def_Id
)
4264 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
4266 Set_Scope
(Def_Id
, Current_Scope
);
4269 -- In the body or private part of an instance, a type extension may
4270 -- introduce a component with the same name as that of an actual. The
4271 -- legality rule is not enforced, but the semantics of the full type
4272 -- with two components of same name are not clear at this point???
4274 elsif In_Instance_Not_Visible
then
4277 -- When compiling a package body, some child units may have become
4278 -- visible. They cannot conflict with local entities that hide them.
4280 elsif Is_Child_Unit
(E
)
4281 and then In_Open_Scopes
(Scope
(E
))
4282 and then not Is_Immediately_Visible
(E
)
4286 -- Conversely, with front-end inlining we may compile the parent body
4287 -- first, and a child unit subsequently. The context is now the
4288 -- parent spec, and body entities are not visible.
4290 elsif Is_Child_Unit
(Def_Id
)
4291 and then Is_Package_Body_Entity
(E
)
4292 and then not In_Package_Body
(Current_Scope
)
4296 -- Case of genuine duplicate declaration
4299 Error_Msg_Sloc
:= Sloc
(E
);
4301 -- If the previous declaration is an incomplete type declaration
4302 -- this may be an attempt to complete it with a private type. The
4303 -- following avoids confusing cascaded errors.
4305 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
4306 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
4309 ("incomplete type cannot be completed with a private " &
4310 "declaration", Parent
(Def_Id
));
4311 Set_Is_Immediately_Visible
(E
, False);
4312 Set_Full_View
(E
, Def_Id
);
4314 -- An inherited component of a record conflicts with a new
4315 -- discriminant. The discriminant is inserted first in the scope,
4316 -- but the error should be posted on it, not on the component.
4318 elsif Ekind
(E
) = E_Discriminant
4319 and then Present
(Scope
(Def_Id
))
4320 and then Scope
(Def_Id
) /= Current_Scope
4322 Error_Msg_Sloc
:= Sloc
(Def_Id
);
4323 Error_Msg_N
("& conflicts with declaration#", E
);
4326 -- If the name of the unit appears in its own context clause, a
4327 -- dummy package with the name has already been created, and the
4328 -- error emitted. Try to continue quietly.
4330 elsif Error_Posted
(E
)
4331 and then Sloc
(E
) = No_Location
4332 and then Nkind
(Parent
(E
)) = N_Package_Specification
4333 and then Current_Scope
= Standard_Standard
4335 Set_Scope
(Def_Id
, Current_Scope
);
4339 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
4341 -- Avoid cascaded messages with duplicate components in
4344 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
4349 if Nkind
(Parent
(Parent
(Def_Id
))) =
4350 N_Generic_Subprogram_Declaration
4352 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
4354 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
4357 -- If entity is in standard, then we are in trouble, because it
4358 -- means that we have a library package with a duplicated name.
4359 -- That's hard to recover from, so abort!
4361 if S
= Standard_Standard
then
4362 raise Unrecoverable_Error
;
4364 -- Otherwise we continue with the declaration. Having two
4365 -- identical declarations should not cause us too much trouble!
4373 -- If we fall through, declaration is OK, at least OK enough to continue
4375 -- If Def_Id is a discriminant or a record component we are in the midst
4376 -- of inheriting components in a derived record definition. Preserve
4377 -- their Ekind and Etype.
4379 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
4382 -- If a type is already set, leave it alone (happens when a type
4383 -- declaration is reanalyzed following a call to the optimizer).
4385 elsif Present
(Etype
(Def_Id
)) then
4388 -- Otherwise, the kind E_Void insures that premature uses of the entity
4389 -- will be detected. Any_Type insures that no cascaded errors will occur
4392 Set_Ekind
(Def_Id
, E_Void
);
4393 Set_Etype
(Def_Id
, Any_Type
);
4396 -- Inherited discriminants and components in derived record types are
4397 -- immediately visible. Itypes are not.
4399 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
4400 or else (No
(Corresponding_Remote_Type
(Def_Id
))
4401 and then not Is_Itype
(Def_Id
))
4403 Set_Is_Immediately_Visible
(Def_Id
);
4404 Set_Current_Entity
(Def_Id
);
4407 Set_Homonym
(Def_Id
, C
);
4408 Append_Entity
(Def_Id
, S
);
4409 Set_Public_Status
(Def_Id
);
4411 -- Declaring a homonym is not allowed in SPARK ...
4414 and then Restriction_Check_Required
(SPARK
)
4417 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
4418 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
4419 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
4422 -- ... unless the new declaration is in a subprogram, and the
4423 -- visible declaration is a variable declaration or a parameter
4424 -- specification outside that subprogram.
4426 if Present
(Enclosing_Subp
)
4427 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
4428 N_Parameter_Specification
)
4429 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
4433 -- ... or the new declaration is in a package, and the visible
4434 -- declaration occurs outside that package.
4436 elsif Present
(Enclosing_Pack
)
4437 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
4441 -- ... or the new declaration is a component declaration in a
4442 -- record type definition.
4444 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
4447 -- Don't issue error for non-source entities
4449 elsif Comes_From_Source
(Def_Id
)
4450 and then Comes_From_Source
(C
)
4452 Error_Msg_Sloc
:= Sloc
(C
);
4453 Check_SPARK_Restriction
4454 ("redeclaration of identifier &#", Def_Id
);
4459 -- Warn if new entity hides an old one
4461 if Warn_On_Hiding
and then Present
(C
)
4463 -- Don't warn for record components since they always have a well
4464 -- defined scope which does not confuse other uses. Note that in
4465 -- some cases, Ekind has not been set yet.
4467 and then Ekind
(C
) /= E_Component
4468 and then Ekind
(C
) /= E_Discriminant
4469 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
4470 and then Ekind
(Def_Id
) /= E_Component
4471 and then Ekind
(Def_Id
) /= E_Discriminant
4472 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
4474 -- Don't warn for one character variables. It is too common to use
4475 -- such variables as locals and will just cause too many false hits.
4477 and then Length_Of_Name
(Chars
(C
)) /= 1
4479 -- Don't warn for non-source entities
4481 and then Comes_From_Source
(C
)
4482 and then Comes_From_Source
(Def_Id
)
4484 -- Don't warn unless entity in question is in extended main source
4486 and then In_Extended_Main_Source_Unit
(Def_Id
)
4488 -- Finally, the hidden entity must be either immediately visible or
4489 -- use visible (i.e. from a used package).
4492 (Is_Immediately_Visible
(C
)
4494 Is_Potentially_Use_Visible
(C
))
4496 Error_Msg_Sloc
:= Sloc
(C
);
4497 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
4501 --------------------------
4502 -- Explain_Limited_Type --
4503 --------------------------
4505 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
4509 -- For array, component type must be limited
4511 if Is_Array_Type
(T
) then
4512 Error_Msg_Node_2
:= T
;
4514 ("\component type& of type& is limited", N
, Component_Type
(T
));
4515 Explain_Limited_Type
(Component_Type
(T
), N
);
4517 elsif Is_Record_Type
(T
) then
4519 -- No need for extra messages if explicit limited record
4521 if Is_Limited_Record
(Base_Type
(T
)) then
4525 -- Otherwise find a limited component. Check only components that
4526 -- come from source, or inherited components that appear in the
4527 -- source of the ancestor.
4529 C
:= First_Component
(T
);
4530 while Present
(C
) loop
4531 if Is_Limited_Type
(Etype
(C
))
4533 (Comes_From_Source
(C
)
4535 (Present
(Original_Record_Component
(C
))
4537 Comes_From_Source
(Original_Record_Component
(C
))))
4539 Error_Msg_Node_2
:= T
;
4540 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
4541 Explain_Limited_Type
(Etype
(C
), N
);
4548 -- The type may be declared explicitly limited, even if no component
4549 -- of it is limited, in which case we fall out of the loop.
4552 end Explain_Limited_Type
;
4558 procedure Find_Actual
4560 Formal
: out Entity_Id
;
4563 Parnt
: constant Node_Id
:= Parent
(N
);
4567 if (Nkind
(Parnt
) = N_Indexed_Component
4569 Nkind
(Parnt
) = N_Selected_Component
)
4570 and then N
= Prefix
(Parnt
)
4572 Find_Actual
(Parnt
, Formal
, Call
);
4575 elsif Nkind
(Parnt
) = N_Parameter_Association
4576 and then N
= Explicit_Actual_Parameter
(Parnt
)
4578 Call
:= Parent
(Parnt
);
4580 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
4589 -- If we have a call to a subprogram look for the parameter. Note that
4590 -- we exclude overloaded calls, since we don't know enough to be sure
4591 -- of giving the right answer in this case.
4593 if Is_Entity_Name
(Name
(Call
))
4594 and then Present
(Entity
(Name
(Call
)))
4595 and then Is_Overloadable
(Entity
(Name
(Call
)))
4596 and then not Is_Overloaded
(Name
(Call
))
4598 -- Fall here if we are definitely a parameter
4600 Actual
:= First_Actual
(Call
);
4601 Formal
:= First_Formal
(Entity
(Name
(Call
)));
4602 while Present
(Formal
) and then Present
(Actual
) loop
4606 Actual
:= Next_Actual
(Actual
);
4607 Formal
:= Next_Formal
(Formal
);
4612 -- Fall through here if we did not find matching actual
4618 ---------------------------
4619 -- Find_Body_Discriminal --
4620 ---------------------------
4622 function Find_Body_Discriminal
4623 (Spec_Discriminant
: Entity_Id
) return Entity_Id
4629 -- If expansion is suppressed, then the scope can be the concurrent type
4630 -- itself rather than a corresponding concurrent record type.
4632 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
4633 Tsk
:= Scope
(Spec_Discriminant
);
4636 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
4638 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
4641 -- Find discriminant of original concurrent type, and use its current
4642 -- discriminal, which is the renaming within the task/protected body.
4644 Disc
:= First_Discriminant
(Tsk
);
4645 while Present
(Disc
) loop
4646 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
4647 return Discriminal
(Disc
);
4650 Next_Discriminant
(Disc
);
4653 -- That loop should always succeed in finding a matching entry and
4654 -- returning. Fatal error if not.
4656 raise Program_Error
;
4657 end Find_Body_Discriminal
;
4659 -------------------------------------
4660 -- Find_Corresponding_Discriminant --
4661 -------------------------------------
4663 function Find_Corresponding_Discriminant
4665 Typ
: Entity_Id
) return Entity_Id
4667 Par_Disc
: Entity_Id
;
4668 Old_Disc
: Entity_Id
;
4669 New_Disc
: Entity_Id
;
4672 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
4674 -- The original type may currently be private, and the discriminant
4675 -- only appear on its full view.
4677 if Is_Private_Type
(Scope
(Par_Disc
))
4678 and then not Has_Discriminants
(Scope
(Par_Disc
))
4679 and then Present
(Full_View
(Scope
(Par_Disc
)))
4681 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
4683 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
4686 if Is_Class_Wide_Type
(Typ
) then
4687 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
4689 New_Disc
:= First_Discriminant
(Typ
);
4692 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
4693 if Old_Disc
= Par_Disc
then
4696 Next_Discriminant
(Old_Disc
);
4697 Next_Discriminant
(New_Disc
);
4701 -- Should always find it
4703 raise Program_Error
;
4704 end Find_Corresponding_Discriminant
;
4706 --------------------------
4707 -- Find_Overlaid_Entity --
4708 --------------------------
4710 procedure Find_Overlaid_Entity
4712 Ent
: out Entity_Id
;
4718 -- We are looking for one of the two following forms:
4720 -- for X'Address use Y'Address
4724 -- Const : constant Address := expr;
4726 -- for X'Address use Const;
4728 -- In the second case, the expr is either Y'Address, or recursively a
4729 -- constant that eventually references Y'Address.
4734 if Nkind
(N
) = N_Attribute_Definition_Clause
4735 and then Chars
(N
) = Name_Address
4737 Expr
:= Expression
(N
);
4739 -- This loop checks the form of the expression for Y'Address,
4740 -- using recursion to deal with intermediate constants.
4743 -- Check for Y'Address
4745 if Nkind
(Expr
) = N_Attribute_Reference
4746 and then Attribute_Name
(Expr
) = Name_Address
4748 Expr
:= Prefix
(Expr
);
4751 -- Check for Const where Const is a constant entity
4753 elsif Is_Entity_Name
(Expr
)
4754 and then Ekind
(Entity
(Expr
)) = E_Constant
4756 Expr
:= Constant_Value
(Entity
(Expr
));
4758 -- Anything else does not need checking
4765 -- This loop checks the form of the prefix for an entity, using
4766 -- recursion to deal with intermediate components.
4769 -- Check for Y where Y is an entity
4771 if Is_Entity_Name
(Expr
) then
4772 Ent
:= Entity
(Expr
);
4775 -- Check for components
4778 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
4780 Expr
:= Prefix
(Expr
);
4783 -- Anything else does not need checking
4790 end Find_Overlaid_Entity
;
4792 -------------------------
4793 -- Find_Parameter_Type --
4794 -------------------------
4796 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
4798 if Nkind
(Param
) /= N_Parameter_Specification
then
4801 -- For an access parameter, obtain the type from the formal entity
4802 -- itself, because access to subprogram nodes do not carry a type.
4803 -- Shouldn't we always use the formal entity ???
4805 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
4806 return Etype
(Defining_Identifier
(Param
));
4809 return Etype
(Parameter_Type
(Param
));
4811 end Find_Parameter_Type
;
4813 -----------------------------
4814 -- Find_Static_Alternative --
4815 -----------------------------
4817 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
4818 Expr
: constant Node_Id
:= Expression
(N
);
4819 Val
: constant Uint
:= Expr_Value
(Expr
);
4824 Alt
:= First
(Alternatives
(N
));
4827 if Nkind
(Alt
) /= N_Pragma
then
4828 Choice
:= First
(Discrete_Choices
(Alt
));
4829 while Present
(Choice
) loop
4831 -- Others choice, always matches
4833 if Nkind
(Choice
) = N_Others_Choice
then
4836 -- Range, check if value is in the range
4838 elsif Nkind
(Choice
) = N_Range
then
4840 Val
>= Expr_Value
(Low_Bound
(Choice
))
4842 Val
<= Expr_Value
(High_Bound
(Choice
));
4844 -- Choice is a subtype name. Note that we know it must
4845 -- be a static subtype, since otherwise it would have
4846 -- been diagnosed as illegal.
4848 elsif Is_Entity_Name
(Choice
)
4849 and then Is_Type
(Entity
(Choice
))
4851 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
4852 Assume_Valid
=> False);
4854 -- Choice is a subtype indication
4856 elsif Nkind
(Choice
) = N_Subtype_Indication
then
4858 C
: constant Node_Id
:= Constraint
(Choice
);
4859 R
: constant Node_Id
:= Range_Expression
(C
);
4863 Val
>= Expr_Value
(Low_Bound
(R
))
4865 Val
<= Expr_Value
(High_Bound
(R
));
4868 -- Choice is a simple expression
4871 exit Search
when Val
= Expr_Value
(Choice
);
4879 pragma Assert
(Present
(Alt
));
4882 -- The above loop *must* terminate by finding a match, since
4883 -- we know the case statement is valid, and the value of the
4884 -- expression is known at compile time. When we fall out of
4885 -- the loop, Alt points to the alternative that we know will
4886 -- be selected at run time.
4889 end Find_Static_Alternative
;
4895 function First_Actual
(Node
: Node_Id
) return Node_Id
is
4899 if No
(Parameter_Associations
(Node
)) then
4903 N
:= First
(Parameter_Associations
(Node
));
4905 if Nkind
(N
) = N_Parameter_Association
then
4906 return First_Named_Actual
(Node
);
4912 -----------------------
4913 -- Gather_Components --
4914 -----------------------
4916 procedure Gather_Components
4918 Comp_List
: Node_Id
;
4919 Governed_By
: List_Id
;
4921 Report_Errors
: out Boolean)
4925 Discrete_Choice
: Node_Id
;
4926 Comp_Item
: Node_Id
;
4928 Discrim
: Entity_Id
;
4929 Discrim_Name
: Node_Id
;
4930 Discrim_Value
: Node_Id
;
4933 Report_Errors
:= False;
4935 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
4938 elsif Present
(Component_Items
(Comp_List
)) then
4939 Comp_Item
:= First
(Component_Items
(Comp_List
));
4945 while Present
(Comp_Item
) loop
4947 -- Skip the tag of a tagged record, the interface tags, as well
4948 -- as all items that are not user components (anonymous types,
4949 -- rep clauses, Parent field, controller field).
4951 if Nkind
(Comp_Item
) = N_Component_Declaration
then
4953 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
4955 if not Is_Tag
(Comp
)
4956 and then Chars
(Comp
) /= Name_uParent
4958 Append_Elmt
(Comp
, Into
);
4966 if No
(Variant_Part
(Comp_List
)) then
4969 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
4970 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
4973 -- Look for the discriminant that governs this variant part.
4974 -- The discriminant *must* be in the Governed_By List
4976 Assoc
:= First
(Governed_By
);
4977 Find_Constraint
: loop
4978 Discrim
:= First
(Choices
(Assoc
));
4979 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
4980 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
4982 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
4983 = Chars
(Discrim_Name
))
4984 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
4985 = Chars
(Discrim_Name
);
4987 if No
(Next
(Assoc
)) then
4988 if not Is_Constrained
(Typ
)
4989 and then Is_Derived_Type
(Typ
)
4990 and then Present
(Stored_Constraint
(Typ
))
4992 -- If the type is a tagged type with inherited discriminants,
4993 -- use the stored constraint on the parent in order to find
4994 -- the values of discriminants that are otherwise hidden by an
4995 -- explicit constraint. Renamed discriminants are handled in
4998 -- If several parent discriminants are renamed by a single
4999 -- discriminant of the derived type, the call to obtain the
5000 -- Corresponding_Discriminant field only retrieves the last
5001 -- of them. We recover the constraint on the others from the
5002 -- Stored_Constraint as well.
5009 D
:= First_Discriminant
(Etype
(Typ
));
5010 C
:= First_Elmt
(Stored_Constraint
(Typ
));
5011 while Present
(D
) and then Present
(C
) loop
5012 if Chars
(Discrim_Name
) = Chars
(D
) then
5013 if Is_Entity_Name
(Node
(C
))
5014 and then Entity
(Node
(C
)) = Entity
(Discrim
)
5016 -- D is renamed by Discrim, whose value is given in
5023 Make_Component_Association
(Sloc
(Typ
),
5025 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
5026 Duplicate_Subexpr_No_Checks
(Node
(C
)));
5028 exit Find_Constraint
;
5031 Next_Discriminant
(D
);
5038 if No
(Next
(Assoc
)) then
5039 Error_Msg_NE
(" missing value for discriminant&",
5040 First
(Governed_By
), Discrim_Name
);
5041 Report_Errors
:= True;
5046 end loop Find_Constraint
;
5048 Discrim_Value
:= Expression
(Assoc
);
5050 if not Is_OK_Static_Expression
(Discrim_Value
) then
5052 ("value for discriminant & must be static!",
5053 Discrim_Value
, Discrim
);
5054 Why_Not_Static
(Discrim_Value
);
5055 Report_Errors
:= True;
5059 Search_For_Discriminant_Value
: declare
5065 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
5068 Find_Discrete_Value
: while Present
(Variant
) loop
5069 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
5070 while Present
(Discrete_Choice
) loop
5072 exit Find_Discrete_Value
when
5073 Nkind
(Discrete_Choice
) = N_Others_Choice
;
5075 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
5077 UI_Low
:= Expr_Value
(Low
);
5078 UI_High
:= Expr_Value
(High
);
5080 exit Find_Discrete_Value
when
5081 UI_Low
<= UI_Discrim_Value
5083 UI_High
>= UI_Discrim_Value
;
5085 Next
(Discrete_Choice
);
5088 Next_Non_Pragma
(Variant
);
5089 end loop Find_Discrete_Value
;
5090 end Search_For_Discriminant_Value
;
5092 if No
(Variant
) then
5094 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
5095 Report_Errors
:= True;
5099 -- If we have found the corresponding choice, recursively add its
5100 -- components to the Into list.
5102 Gather_Components
(Empty
,
5103 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
5104 end Gather_Components
;
5106 ------------------------
5107 -- Get_Actual_Subtype --
5108 ------------------------
5110 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
5111 Typ
: constant Entity_Id
:= Etype
(N
);
5112 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
5121 -- If what we have is an identifier that references a subprogram
5122 -- formal, or a variable or constant object, then we get the actual
5123 -- subtype from the referenced entity if one has been built.
5125 if Nkind
(N
) = N_Identifier
5127 (Is_Formal
(Entity
(N
))
5128 or else Ekind
(Entity
(N
)) = E_Constant
5129 or else Ekind
(Entity
(N
)) = E_Variable
)
5130 and then Present
(Actual_Subtype
(Entity
(N
)))
5132 return Actual_Subtype
(Entity
(N
));
5134 -- Actual subtype of unchecked union is always itself. We never need
5135 -- the "real" actual subtype. If we did, we couldn't get it anyway
5136 -- because the discriminant is not available. The restrictions on
5137 -- Unchecked_Union are designed to make sure that this is OK.
5139 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
5142 -- Here for the unconstrained case, we must find actual subtype
5143 -- No actual subtype is available, so we must build it on the fly.
5145 -- Checking the type, not the underlying type, for constrainedness
5146 -- seems to be necessary. Maybe all the tests should be on the type???
5148 elsif (not Is_Constrained
(Typ
))
5149 and then (Is_Array_Type
(Utyp
)
5150 or else (Is_Record_Type
(Utyp
)
5151 and then Has_Discriminants
(Utyp
)))
5152 and then not Has_Unknown_Discriminants
(Utyp
)
5153 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
5155 -- Nothing to do if in spec expression (why not???)
5157 if In_Spec_Expression
then
5160 elsif Is_Private_Type
(Typ
)
5161 and then not Has_Discriminants
(Typ
)
5163 -- If the type has no discriminants, there is no subtype to
5164 -- build, even if the underlying type is discriminated.
5168 -- Else build the actual subtype
5171 Decl
:= Build_Actual_Subtype
(Typ
, N
);
5172 Atyp
:= Defining_Identifier
(Decl
);
5174 -- If Build_Actual_Subtype generated a new declaration then use it
5178 -- The actual subtype is an Itype, so analyze the declaration,
5179 -- but do not attach it to the tree, to get the type defined.
5181 Set_Parent
(Decl
, N
);
5182 Set_Is_Itype
(Atyp
);
5183 Analyze
(Decl
, Suppress
=> All_Checks
);
5184 Set_Associated_Node_For_Itype
(Atyp
, N
);
5185 Set_Has_Delayed_Freeze
(Atyp
, False);
5187 -- We need to freeze the actual subtype immediately. This is
5188 -- needed, because otherwise this Itype will not get frozen
5189 -- at all, and it is always safe to freeze on creation because
5190 -- any associated types must be frozen at this point.
5192 Freeze_Itype
(Atyp
, N
);
5195 -- Otherwise we did not build a declaration, so return original
5202 -- For all remaining cases, the actual subtype is the same as
5203 -- the nominal type.
5208 end Get_Actual_Subtype
;
5210 -------------------------------------
5211 -- Get_Actual_Subtype_If_Available --
5212 -------------------------------------
5214 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
5215 Typ
: constant Entity_Id
:= Etype
(N
);
5218 -- If what we have is an identifier that references a subprogram
5219 -- formal, or a variable or constant object, then we get the actual
5220 -- subtype from the referenced entity if one has been built.
5222 if Nkind
(N
) = N_Identifier
5224 (Is_Formal
(Entity
(N
))
5225 or else Ekind
(Entity
(N
)) = E_Constant
5226 or else Ekind
(Entity
(N
)) = E_Variable
)
5227 and then Present
(Actual_Subtype
(Entity
(N
)))
5229 return Actual_Subtype
(Entity
(N
));
5231 -- Otherwise the Etype of N is returned unchanged
5236 end Get_Actual_Subtype_If_Available
;
5238 ------------------------
5239 -- Get_Body_From_Stub --
5240 ------------------------
5242 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
5244 return Proper_Body
(Unit
(Library_Unit
(N
)));
5245 end Get_Body_From_Stub
;
5247 -------------------------------
5248 -- Get_Default_External_Name --
5249 -------------------------------
5251 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
5253 Get_Decoded_Name_String
(Chars
(E
));
5255 if Opt
.External_Name_Imp_Casing
= Uppercase
then
5256 Set_Casing
(All_Upper_Case
);
5258 Set_Casing
(All_Lower_Case
);
5262 Make_String_Literal
(Sloc
(E
),
5263 Strval
=> String_From_Name_Buffer
);
5264 end Get_Default_External_Name
;
5266 --------------------------
5267 -- Get_Enclosing_Object --
5268 --------------------------
5270 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
5272 if Is_Entity_Name
(N
) then
5276 when N_Indexed_Component |
5278 N_Selected_Component
=>
5280 -- If not generating code, a dereference may be left implicit.
5281 -- In thoses cases, return Empty.
5283 if Is_Access_Type
(Etype
(Prefix
(N
))) then
5286 return Get_Enclosing_Object
(Prefix
(N
));
5289 when N_Type_Conversion
=>
5290 return Get_Enclosing_Object
(Expression
(N
));
5296 end Get_Enclosing_Object
;
5298 ---------------------------
5299 -- Get_Enum_Lit_From_Pos --
5300 ---------------------------
5302 function Get_Enum_Lit_From_Pos
5305 Loc
: Source_Ptr
) return Node_Id
5307 Btyp
: Entity_Id
:= Base_Type
(T
);
5311 -- In the case where the literal is of type Character, Wide_Character
5312 -- or Wide_Wide_Character or of a type derived from them, there needs
5313 -- to be some special handling since there is no explicit chain of
5314 -- literals to search. Instead, an N_Character_Literal node is created
5315 -- with the appropriate Char_Code and Chars fields.
5317 if Is_Standard_Character_Type
(T
) then
5318 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
5320 Make_Character_Literal
(Loc
,
5322 Char_Literal_Value
=> Pos
);
5324 -- For all other cases, we have a complete table of literals, and
5325 -- we simply iterate through the chain of literal until the one
5326 -- with the desired position value is found.
5330 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
5331 Btyp
:= Full_View
(Btyp
);
5334 Lit
:= First_Literal
(Btyp
);
5335 for J
in 1 .. UI_To_Int
(Pos
) loop
5339 return New_Occurrence_Of
(Lit
, Loc
);
5341 end Get_Enum_Lit_From_Pos
;
5343 ---------------------------------
5344 -- Get_Ensures_From_CTC_Pragma --
5345 ---------------------------------
5347 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
5348 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
5352 if List_Length
(Args
) = 4 then
5353 Res
:= Pick
(Args
, 4);
5355 elsif List_Length
(Args
) = 3 then
5356 Res
:= Pick
(Args
, 3);
5358 if Chars
(Res
) /= Name_Ensures
then
5367 end Get_Ensures_From_CTC_Pragma
;
5369 ------------------------
5370 -- Get_Generic_Entity --
5371 ------------------------
5373 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
5374 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
5376 if Present
(Renamed_Object
(Ent
)) then
5377 return Renamed_Object
(Ent
);
5381 end Get_Generic_Entity
;
5383 ----------------------
5384 -- Get_Index_Bounds --
5385 ----------------------
5387 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
5388 Kind
: constant Node_Kind
:= Nkind
(N
);
5392 if Kind
= N_Range
then
5394 H
:= High_Bound
(N
);
5396 elsif Kind
= N_Subtype_Indication
then
5397 R
:= Range_Expression
(Constraint
(N
));
5405 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
5406 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
5409 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
5410 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
5414 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
5415 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
5418 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
5419 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
5423 -- N is an expression, indicating a range with one value
5428 end Get_Index_Bounds
;
5430 ----------------------------------
5431 -- Get_Library_Unit_Name_string --
5432 ----------------------------------
5434 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
5435 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
5438 Get_Unit_Name_String
(Unit_Name_Id
);
5440 -- Remove seven last character (" (spec)" or " (body)")
5442 Name_Len
:= Name_Len
- 7;
5443 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
5444 end Get_Library_Unit_Name_String
;
5446 ------------------------
5447 -- Get_Name_Entity_Id --
5448 ------------------------
5450 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
5452 return Entity_Id
(Get_Name_Table_Info
(Id
));
5453 end Get_Name_Entity_Id
;
5455 ------------------------------
5456 -- Get_Name_From_CTC_Pragma --
5457 ------------------------------
5459 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
5460 Arg
: constant Node_Id
:=
5461 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
5463 return Strval
(Expr_Value_S
(Arg
));
5464 end Get_Name_From_CTC_Pragma
;
5470 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
5472 return Get_Pragma_Id
(Pragma_Name
(N
));
5475 ---------------------------
5476 -- Get_Referenced_Object --
5477 ---------------------------
5479 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
5484 while Is_Entity_Name
(R
)
5485 and then Present
(Renamed_Object
(Entity
(R
)))
5487 R
:= Renamed_Object
(Entity
(R
));
5491 end Get_Referenced_Object
;
5493 ------------------------
5494 -- Get_Renamed_Entity --
5495 ------------------------
5497 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
5502 while Present
(Renamed_Entity
(R
)) loop
5503 R
:= Renamed_Entity
(R
);
5507 end Get_Renamed_Entity
;
5509 ----------------------------------
5510 -- Get_Requires_From_CTC_Pragma --
5511 ----------------------------------
5513 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
5514 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
5518 if List_Length
(Args
) >= 3 then
5519 Res
:= Pick
(Args
, 3);
5521 if Chars
(Res
) /= Name_Requires
then
5530 end Get_Requires_From_CTC_Pragma
;
5532 -------------------------
5533 -- Get_Subprogram_Body --
5534 -------------------------
5536 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
5540 Decl
:= Unit_Declaration_Node
(E
);
5542 if Nkind
(Decl
) = N_Subprogram_Body
then
5545 -- The below comment is bad, because it is possible for
5546 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
5548 else -- Nkind (Decl) = N_Subprogram_Declaration
5550 if Present
(Corresponding_Body
(Decl
)) then
5551 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
5553 -- Imported subprogram case
5559 end Get_Subprogram_Body
;
5561 ---------------------------
5562 -- Get_Subprogram_Entity --
5563 ---------------------------
5565 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
5570 if Nkind
(Nod
) = N_Accept_Statement
then
5571 Nam
:= Entry_Direct_Name
(Nod
);
5573 -- For an entry call, the prefix of the call is a selected component.
5574 -- Need additional code for internal calls ???
5576 elsif Nkind
(Nod
) = N_Entry_Call_Statement
then
5577 if Nkind
(Name
(Nod
)) = N_Selected_Component
then
5578 Nam
:= Entity
(Selector_Name
(Name
(Nod
)));
5587 if Nkind
(Nam
) = N_Explicit_Dereference
then
5588 Proc
:= Etype
(Prefix
(Nam
));
5589 elsif Is_Entity_Name
(Nam
) then
5590 Proc
:= Entity
(Nam
);
5595 if Is_Object
(Proc
) then
5596 Proc
:= Etype
(Proc
);
5599 if Ekind
(Proc
) = E_Access_Subprogram_Type
then
5600 Proc
:= Directly_Designated_Type
(Proc
);
5603 if not Is_Subprogram
(Proc
)
5604 and then Ekind
(Proc
) /= E_Subprogram_Type
5610 end Get_Subprogram_Entity
;
5612 -----------------------------
5613 -- Get_Task_Body_Procedure --
5614 -----------------------------
5616 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
5618 -- Note: A task type may be the completion of a private type with
5619 -- discriminants. When performing elaboration checks on a task
5620 -- declaration, the current view of the type may be the private one,
5621 -- and the procedure that holds the body of the task is held in its
5624 -- This is an odd function, why not have Task_Body_Procedure do
5625 -- the following digging???
5627 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
5628 end Get_Task_Body_Procedure
;
5630 -----------------------
5631 -- Has_Access_Values --
5632 -----------------------
5634 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
5635 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
5638 -- Case of a private type which is not completed yet. This can only
5639 -- happen in the case of a generic format type appearing directly, or
5640 -- as a component of the type to which this function is being applied
5641 -- at the top level. Return False in this case, since we certainly do
5642 -- not know that the type contains access types.
5647 elsif Is_Access_Type
(Typ
) then
5650 elsif Is_Array_Type
(Typ
) then
5651 return Has_Access_Values
(Component_Type
(Typ
));
5653 elsif Is_Record_Type
(Typ
) then
5658 -- Loop to Check components
5660 Comp
:= First_Component_Or_Discriminant
(Typ
);
5661 while Present
(Comp
) loop
5663 -- Check for access component, tag field does not count, even
5664 -- though it is implemented internally using an access type.
5666 if Has_Access_Values
(Etype
(Comp
))
5667 and then Chars
(Comp
) /= Name_uTag
5672 Next_Component_Or_Discriminant
(Comp
);
5681 end Has_Access_Values
;
5683 ------------------------------
5684 -- Has_Compatible_Alignment --
5685 ------------------------------
5687 function Has_Compatible_Alignment
5689 Expr
: Node_Id
) return Alignment_Result
5691 function Has_Compatible_Alignment_Internal
5694 Default
: Alignment_Result
) return Alignment_Result
;
5695 -- This is the internal recursive function that actually does the work.
5696 -- There is one additional parameter, which says what the result should
5697 -- be if no alignment information is found, and there is no definite
5698 -- indication of compatible alignments. At the outer level, this is set
5699 -- to Unknown, but for internal recursive calls in the case where types
5700 -- are known to be correct, it is set to Known_Compatible.
5702 ---------------------------------------
5703 -- Has_Compatible_Alignment_Internal --
5704 ---------------------------------------
5706 function Has_Compatible_Alignment_Internal
5709 Default
: Alignment_Result
) return Alignment_Result
5711 Result
: Alignment_Result
:= Known_Compatible
;
5712 -- Holds the current status of the result. Note that once a value of
5713 -- Known_Incompatible is set, it is sticky and does not get changed
5714 -- to Unknown (the value in Result only gets worse as we go along,
5717 Offs
: Uint
:= No_Uint
;
5718 -- Set to a factor of the offset from the base object when Expr is a
5719 -- selected or indexed component, based on Component_Bit_Offset and
5720 -- Component_Size respectively. A negative value is used to represent
5721 -- a value which is not known at compile time.
5723 procedure Check_Prefix
;
5724 -- Checks the prefix recursively in the case where the expression
5725 -- is an indexed or selected component.
5727 procedure Set_Result
(R
: Alignment_Result
);
5728 -- If R represents a worse outcome (unknown instead of known
5729 -- compatible, or known incompatible), then set Result to R.
5735 procedure Check_Prefix
is
5737 -- The subtlety here is that in doing a recursive call to check
5738 -- the prefix, we have to decide what to do in the case where we
5739 -- don't find any specific indication of an alignment problem.
5741 -- At the outer level, we normally set Unknown as the result in
5742 -- this case, since we can only set Known_Compatible if we really
5743 -- know that the alignment value is OK, but for the recursive
5744 -- call, in the case where the types match, and we have not
5745 -- specified a peculiar alignment for the object, we are only
5746 -- concerned about suspicious rep clauses, the default case does
5747 -- not affect us, since the compiler will, in the absence of such
5748 -- rep clauses, ensure that the alignment is correct.
5750 if Default
= Known_Compatible
5752 (Etype
(Obj
) = Etype
(Expr
)
5753 and then (Unknown_Alignment
(Obj
)
5755 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
5758 (Has_Compatible_Alignment_Internal
5759 (Obj
, Prefix
(Expr
), Known_Compatible
));
5761 -- In all other cases, we need a full check on the prefix
5765 (Has_Compatible_Alignment_Internal
5766 (Obj
, Prefix
(Expr
), Unknown
));
5774 procedure Set_Result
(R
: Alignment_Result
) is
5781 -- Start of processing for Has_Compatible_Alignment_Internal
5784 -- If Expr is a selected component, we must make sure there is no
5785 -- potentially troublesome component clause, and that the record is
5788 if Nkind
(Expr
) = N_Selected_Component
then
5790 -- Packed record always generate unknown alignment
5792 if Is_Packed
(Etype
(Prefix
(Expr
))) then
5793 Set_Result
(Unknown
);
5796 -- Check prefix and component offset
5799 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
5801 -- If Expr is an indexed component, we must make sure there is no
5802 -- potentially troublesome Component_Size clause and that the array
5803 -- is not bit-packed.
5805 elsif Nkind
(Expr
) = N_Indexed_Component
then
5807 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
5808 Ind
: constant Node_Id
:= First_Index
(Typ
);
5811 -- Bit packed array always generates unknown alignment
5813 if Is_Bit_Packed_Array
(Typ
) then
5814 Set_Result
(Unknown
);
5817 -- Check prefix and component offset
5820 Offs
:= Component_Size
(Typ
);
5822 -- Small optimization: compute the full offset when possible
5825 and then Offs
> Uint_0
5826 and then Present
(Ind
)
5827 and then Nkind
(Ind
) = N_Range
5828 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
5829 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
5831 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
5832 - Expr_Value
(Low_Bound
((Ind
))));
5837 -- If we have a null offset, the result is entirely determined by
5838 -- the base object and has already been computed recursively.
5840 if Offs
= Uint_0
then
5843 -- Case where we know the alignment of the object
5845 elsif Known_Alignment
(Obj
) then
5847 ObjA
: constant Uint
:= Alignment
(Obj
);
5848 ExpA
: Uint
:= No_Uint
;
5849 SizA
: Uint
:= No_Uint
;
5852 -- If alignment of Obj is 1, then we are always OK
5855 Set_Result
(Known_Compatible
);
5857 -- Alignment of Obj is greater than 1, so we need to check
5860 -- If we have an offset, see if it is compatible
5862 if Offs
/= No_Uint
and Offs
> Uint_0
then
5863 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
5864 Set_Result
(Known_Incompatible
);
5867 -- See if Expr is an object with known alignment
5869 elsif Is_Entity_Name
(Expr
)
5870 and then Known_Alignment
(Entity
(Expr
))
5872 ExpA
:= Alignment
(Entity
(Expr
));
5874 -- Otherwise, we can use the alignment of the type of
5875 -- Expr given that we already checked for
5876 -- discombobulating rep clauses for the cases of indexed
5877 -- and selected components above.
5879 elsif Known_Alignment
(Etype
(Expr
)) then
5880 ExpA
:= Alignment
(Etype
(Expr
));
5882 -- Otherwise the alignment is unknown
5885 Set_Result
(Default
);
5888 -- If we got an alignment, see if it is acceptable
5890 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
5891 Set_Result
(Known_Incompatible
);
5894 -- If Expr is not a piece of a larger object, see if size
5895 -- is given. If so, check that it is not too small for the
5896 -- required alignment.
5898 if Offs
/= No_Uint
then
5901 -- See if Expr is an object with known size
5903 elsif Is_Entity_Name
(Expr
)
5904 and then Known_Static_Esize
(Entity
(Expr
))
5906 SizA
:= Esize
(Entity
(Expr
));
5908 -- Otherwise, we check the object size of the Expr type
5910 elsif Known_Static_Esize
(Etype
(Expr
)) then
5911 SizA
:= Esize
(Etype
(Expr
));
5914 -- If we got a size, see if it is a multiple of the Obj
5915 -- alignment, if not, then the alignment cannot be
5916 -- acceptable, since the size is always a multiple of the
5919 if SizA
/= No_Uint
then
5920 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
5921 Set_Result
(Known_Incompatible
);
5927 -- If we do not know required alignment, any non-zero offset is a
5928 -- potential problem (but certainly may be OK, so result is unknown).
5930 elsif Offs
/= No_Uint
then
5931 Set_Result
(Unknown
);
5933 -- If we can't find the result by direct comparison of alignment
5934 -- values, then there is still one case that we can determine known
5935 -- result, and that is when we can determine that the types are the
5936 -- same, and no alignments are specified. Then we known that the
5937 -- alignments are compatible, even if we don't know the alignment
5938 -- value in the front end.
5940 elsif Etype
(Obj
) = Etype
(Expr
) then
5942 -- Types are the same, but we have to check for possible size
5943 -- and alignments on the Expr object that may make the alignment
5944 -- different, even though the types are the same.
5946 if Is_Entity_Name
(Expr
) then
5948 -- First check alignment of the Expr object. Any alignment less
5949 -- than Maximum_Alignment is worrisome since this is the case
5950 -- where we do not know the alignment of Obj.
5952 if Known_Alignment
(Entity
(Expr
))
5954 UI_To_Int
(Alignment
(Entity
(Expr
))) <
5955 Ttypes
.Maximum_Alignment
5957 Set_Result
(Unknown
);
5959 -- Now check size of Expr object. Any size that is not an
5960 -- even multiple of Maximum_Alignment is also worrisome
5961 -- since it may cause the alignment of the object to be less
5962 -- than the alignment of the type.
5964 elsif Known_Static_Esize
(Entity
(Expr
))
5966 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
5967 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
5970 Set_Result
(Unknown
);
5972 -- Otherwise same type is decisive
5975 Set_Result
(Known_Compatible
);
5979 -- Another case to deal with is when there is an explicit size or
5980 -- alignment clause when the types are not the same. If so, then the
5981 -- result is Unknown. We don't need to do this test if the Default is
5982 -- Unknown, since that result will be set in any case.
5984 elsif Default
/= Unknown
5985 and then (Has_Size_Clause
(Etype
(Expr
))
5987 Has_Alignment_Clause
(Etype
(Expr
)))
5989 Set_Result
(Unknown
);
5991 -- If no indication found, set default
5994 Set_Result
(Default
);
5997 -- Return worst result found
6000 end Has_Compatible_Alignment_Internal
;
6002 -- Start of processing for Has_Compatible_Alignment
6005 -- If Obj has no specified alignment, then set alignment from the type
6006 -- alignment. Perhaps we should always do this, but for sure we should
6007 -- do it when there is an address clause since we can do more if the
6008 -- alignment is known.
6010 if Unknown_Alignment
(Obj
) then
6011 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
6014 -- Now do the internal call that does all the work
6016 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
6017 end Has_Compatible_Alignment
;
6019 ----------------------
6020 -- Has_Declarations --
6021 ----------------------
6023 function Has_Declarations
(N
: Node_Id
) return Boolean is
6025 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
6027 N_Compilation_Unit_Aux
,
6033 N_Package_Specification
);
6034 end Has_Declarations
;
6040 function Has_Denormals
(E
: Entity_Id
) return Boolean is
6042 return Is_Floating_Point_Type
(E
)
6043 and then Denorm_On_Target
6044 and then not Vax_Float
(E
);
6047 -------------------------------------------
6048 -- Has_Discriminant_Dependent_Constraint --
6049 -------------------------------------------
6051 function Has_Discriminant_Dependent_Constraint
6052 (Comp
: Entity_Id
) return Boolean
6054 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
6055 Subt_Indic
: constant Node_Id
:=
6056 Subtype_Indication
(Component_Definition
(Comp_Decl
));
6061 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
6062 Constr
:= Constraint
(Subt_Indic
);
6064 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
6065 Assn
:= First
(Constraints
(Constr
));
6066 while Present
(Assn
) loop
6067 case Nkind
(Assn
) is
6068 when N_Subtype_Indication |
6072 if Depends_On_Discriminant
(Assn
) then
6076 when N_Discriminant_Association
=>
6077 if Depends_On_Discriminant
(Expression
(Assn
)) then
6092 end Has_Discriminant_Dependent_Constraint
;
6094 --------------------
6095 -- Has_Infinities --
6096 --------------------
6098 function Has_Infinities
(E
: Entity_Id
) return Boolean is
6101 Is_Floating_Point_Type
(E
)
6102 and then Nkind
(Scalar_Range
(E
)) = N_Range
6103 and then Includes_Infinities
(Scalar_Range
(E
));
6106 --------------------
6107 -- Has_Interfaces --
6108 --------------------
6110 function Has_Interfaces
6112 Use_Full_View
: Boolean := True) return Boolean
6114 Typ
: Entity_Id
:= Base_Type
(T
);
6117 -- Handle concurrent types
6119 if Is_Concurrent_Type
(Typ
) then
6120 Typ
:= Corresponding_Record_Type
(Typ
);
6123 if not Present
(Typ
)
6124 or else not Is_Record_Type
(Typ
)
6125 or else not Is_Tagged_Type
(Typ
)
6130 -- Handle private types
6133 and then Present
(Full_View
(Typ
))
6135 Typ
:= Full_View
(Typ
);
6138 -- Handle concurrent record types
6140 if Is_Concurrent_Record_Type
(Typ
)
6141 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
6147 if Is_Interface
(Typ
)
6149 (Is_Record_Type
(Typ
)
6150 and then Present
(Interfaces
(Typ
))
6151 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
6156 exit when Etype
(Typ
) = Typ
6158 -- Handle private types
6160 or else (Present
(Full_View
(Etype
(Typ
)))
6161 and then Full_View
(Etype
(Typ
)) = Typ
)
6163 -- Protect the frontend against wrong source with cyclic
6166 or else Etype
(Typ
) = T
;
6168 -- Climb to the ancestor type handling private types
6170 if Present
(Full_View
(Etype
(Typ
))) then
6171 Typ
:= Full_View
(Etype
(Typ
));
6180 ------------------------
6181 -- Has_Null_Exclusion --
6182 ------------------------
6184 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
6187 when N_Access_Definition |
6188 N_Access_Function_Definition |
6189 N_Access_Procedure_Definition |
6190 N_Access_To_Object_Definition |
6192 N_Derived_Type_Definition |
6193 N_Function_Specification |
6194 N_Subtype_Declaration
=>
6195 return Null_Exclusion_Present
(N
);
6197 when N_Component_Definition |
6198 N_Formal_Object_Declaration |
6199 N_Object_Renaming_Declaration
=>
6200 if Present
(Subtype_Mark
(N
)) then
6201 return Null_Exclusion_Present
(N
);
6202 else pragma Assert
(Present
(Access_Definition
(N
)));
6203 return Null_Exclusion_Present
(Access_Definition
(N
));
6206 when N_Discriminant_Specification
=>
6207 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
6208 return Null_Exclusion_Present
(Discriminant_Type
(N
));
6210 return Null_Exclusion_Present
(N
);
6213 when N_Object_Declaration
=>
6214 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
6215 return Null_Exclusion_Present
(Object_Definition
(N
));
6217 return Null_Exclusion_Present
(N
);
6220 when N_Parameter_Specification
=>
6221 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
6222 return Null_Exclusion_Present
(Parameter_Type
(N
));
6224 return Null_Exclusion_Present
(N
);
6231 end Has_Null_Exclusion
;
6233 ------------------------
6234 -- Has_Null_Extension --
6235 ------------------------
6237 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
6238 B
: constant Entity_Id
:= Base_Type
(T
);
6243 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
6244 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
6246 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
6248 if Present
(Ext
) then
6249 if Null_Present
(Ext
) then
6252 Comps
:= Component_List
(Ext
);
6254 -- The null component list is rewritten during analysis to
6255 -- include the parent component. Any other component indicates
6256 -- that the extension was not originally null.
6258 return Null_Present
(Comps
)
6259 or else No
(Next
(First
(Component_Items
(Comps
))));
6268 end Has_Null_Extension
;
6270 -------------------------------
6271 -- Has_Overriding_Initialize --
6272 -------------------------------
6274 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
6275 BT
: constant Entity_Id
:= Base_Type
(T
);
6279 if Is_Controlled
(BT
) then
6280 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
6283 elsif Present
(Primitive_Operations
(BT
)) then
6284 P
:= First_Elmt
(Primitive_Operations
(BT
));
6285 while Present
(P
) loop
6287 Init
: constant Entity_Id
:= Node
(P
);
6288 Formal
: constant Entity_Id
:= First_Formal
(Init
);
6290 if Ekind
(Init
) = E_Procedure
6291 and then Chars
(Init
) = Name_Initialize
6292 and then Comes_From_Source
(Init
)
6293 and then Present
(Formal
)
6294 and then Etype
(Formal
) = BT
6295 and then No
(Next_Formal
(Formal
))
6296 and then (Ada_Version
< Ada_2012
6297 or else not Null_Present
(Parent
(Init
)))
6307 -- Here if type itself does not have a non-null Initialize operation:
6308 -- check immediate ancestor.
6310 if Is_Derived_Type
(BT
)
6311 and then Has_Overriding_Initialize
(Etype
(BT
))
6318 end Has_Overriding_Initialize
;
6320 --------------------------------------
6321 -- Has_Preelaborable_Initialization --
6322 --------------------------------------
6324 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
6327 procedure Check_Components
(E
: Entity_Id
);
6328 -- Check component/discriminant chain, sets Has_PE False if a component
6329 -- or discriminant does not meet the preelaborable initialization rules.
6331 ----------------------
6332 -- Check_Components --
6333 ----------------------
6335 procedure Check_Components
(E
: Entity_Id
) is
6339 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
6340 -- Returns True if and only if the expression denoted by N does not
6341 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
6343 ---------------------------------
6344 -- Is_Preelaborable_Expression --
6345 ---------------------------------
6347 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
6351 Comp_Type
: Entity_Id
;
6352 Is_Array_Aggr
: Boolean;
6355 if Is_Static_Expression
(N
) then
6358 elsif Nkind
(N
) = N_Null
then
6361 -- Attributes are allowed in general, even if their prefix is a
6362 -- formal type. (It seems that certain attributes known not to be
6363 -- static might not be allowed, but there are no rules to prevent
6366 elsif Nkind
(N
) = N_Attribute_Reference
then
6369 -- The name of a discriminant evaluated within its parent type is
6370 -- defined to be preelaborable (10.2.1(8)). Note that we test for
6371 -- names that denote discriminals as well as discriminants to
6372 -- catch references occurring within init procs.
6374 elsif Is_Entity_Name
(N
)
6376 (Ekind
(Entity
(N
)) = E_Discriminant
6378 ((Ekind
(Entity
(N
)) = E_Constant
6379 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
6380 and then Present
(Discriminal_Link
(Entity
(N
)))))
6384 elsif Nkind
(N
) = N_Qualified_Expression
then
6385 return Is_Preelaborable_Expression
(Expression
(N
));
6387 -- For aggregates we have to check that each of the associations
6388 -- is preelaborable.
6390 elsif Nkind
(N
) = N_Aggregate
6391 or else Nkind
(N
) = N_Extension_Aggregate
6393 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
6395 if Is_Array_Aggr
then
6396 Comp_Type
:= Component_Type
(Etype
(N
));
6399 -- Check the ancestor part of extension aggregates, which must
6400 -- be either the name of a type that has preelaborable init or
6401 -- an expression that is preelaborable.
6403 if Nkind
(N
) = N_Extension_Aggregate
then
6405 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
6408 if Is_Entity_Name
(Anc_Part
)
6409 and then Is_Type
(Entity
(Anc_Part
))
6411 if not Has_Preelaborable_Initialization
6417 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
6423 -- Check positional associations
6425 Exp
:= First
(Expressions
(N
));
6426 while Present
(Exp
) loop
6427 if not Is_Preelaborable_Expression
(Exp
) then
6434 -- Check named associations
6436 Assn
:= First
(Component_Associations
(N
));
6437 while Present
(Assn
) loop
6438 Choice
:= First
(Choices
(Assn
));
6439 while Present
(Choice
) loop
6440 if Is_Array_Aggr
then
6441 if Nkind
(Choice
) = N_Others_Choice
then
6444 elsif Nkind
(Choice
) = N_Range
then
6445 if not Is_Static_Range
(Choice
) then
6449 elsif not Is_Static_Expression
(Choice
) then
6454 Comp_Type
:= Etype
(Choice
);
6460 -- If the association has a <> at this point, then we have
6461 -- to check whether the component's type has preelaborable
6462 -- initialization. Note that this only occurs when the
6463 -- association's corresponding component does not have a
6464 -- default expression, the latter case having already been
6465 -- expanded as an expression for the association.
6467 if Box_Present
(Assn
) then
6468 if not Has_Preelaborable_Initialization
(Comp_Type
) then
6472 -- In the expression case we check whether the expression
6473 -- is preelaborable.
6476 not Is_Preelaborable_Expression
(Expression
(Assn
))
6484 -- If we get here then aggregate as a whole is preelaborable
6488 -- All other cases are not preelaborable
6493 end Is_Preelaborable_Expression
;
6495 -- Start of processing for Check_Components
6498 -- Loop through entities of record or protected type
6501 while Present
(Ent
) loop
6503 -- We are interested only in components and discriminants
6510 -- Get default expression if any. If there is no declaration
6511 -- node, it means we have an internal entity. The parent and
6512 -- tag fields are examples of such entities. For such cases,
6513 -- we just test the type of the entity.
6515 if Present
(Declaration_Node
(Ent
)) then
6516 Exp
:= Expression
(Declaration_Node
(Ent
));
6519 when E_Discriminant
=>
6521 -- Note: for a renamed discriminant, the Declaration_Node
6522 -- may point to the one from the ancestor, and have a
6523 -- different expression, so use the proper attribute to
6524 -- retrieve the expression from the derived constraint.
6526 Exp
:= Discriminant_Default_Value
(Ent
);
6529 goto Check_Next_Entity
;
6532 -- A component has PI if it has no default expression and the
6533 -- component type has PI.
6536 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
6541 -- Require the default expression to be preelaborable
6543 elsif not Is_Preelaborable_Expression
(Exp
) then
6548 <<Check_Next_Entity
>>
6551 end Check_Components
;
6553 -- Start of processing for Has_Preelaborable_Initialization
6556 -- Immediate return if already marked as known preelaborable init. This
6557 -- covers types for which this function has already been called once
6558 -- and returned True (in which case the result is cached), and also
6559 -- types to which a pragma Preelaborable_Initialization applies.
6561 if Known_To_Have_Preelab_Init
(E
) then
6565 -- If the type is a subtype representing a generic actual type, then
6566 -- test whether its base type has preelaborable initialization since
6567 -- the subtype representing the actual does not inherit this attribute
6568 -- from the actual or formal. (but maybe it should???)
6570 if Is_Generic_Actual_Type
(E
) then
6571 return Has_Preelaborable_Initialization
(Base_Type
(E
));
6574 -- All elementary types have preelaborable initialization
6576 if Is_Elementary_Type
(E
) then
6579 -- Array types have PI if the component type has PI
6581 elsif Is_Array_Type
(E
) then
6582 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
6584 -- A derived type has preelaborable initialization if its parent type
6585 -- has preelaborable initialization and (in the case of a derived record
6586 -- extension) if the non-inherited components all have preelaborable
6587 -- initialization. However, a user-defined controlled type with an
6588 -- overriding Initialize procedure does not have preelaborable
6591 elsif Is_Derived_Type
(E
) then
6593 -- If the derived type is a private extension then it doesn't have
6594 -- preelaborable initialization.
6596 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
6600 -- First check whether ancestor type has preelaborable initialization
6602 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
6604 -- If OK, check extension components (if any)
6606 if Has_PE
and then Is_Record_Type
(E
) then
6607 Check_Components
(First_Entity
(E
));
6610 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
6611 -- with a user defined Initialize procedure does not have PI.
6614 and then Is_Controlled
(E
)
6615 and then Has_Overriding_Initialize
(E
)
6620 -- Private types not derived from a type having preelaborable init and
6621 -- that are not marked with pragma Preelaborable_Initialization do not
6622 -- have preelaborable initialization.
6624 elsif Is_Private_Type
(E
) then
6627 -- Record type has PI if it is non private and all components have PI
6629 elsif Is_Record_Type
(E
) then
6631 Check_Components
(First_Entity
(E
));
6633 -- Protected types must not have entries, and components must meet
6634 -- same set of rules as for record components.
6636 elsif Is_Protected_Type
(E
) then
6637 if Has_Entries
(E
) then
6641 Check_Components
(First_Entity
(E
));
6642 Check_Components
(First_Private_Entity
(E
));
6645 -- Type System.Address always has preelaborable initialization
6647 elsif Is_RTE
(E
, RE_Address
) then
6650 -- In all other cases, type does not have preelaborable initialization
6656 -- If type has preelaborable initialization, cache result
6659 Set_Known_To_Have_Preelab_Init
(E
);
6663 end Has_Preelaborable_Initialization
;
6665 ---------------------------
6666 -- Has_Private_Component --
6667 ---------------------------
6669 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
6670 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
6671 Component
: Entity_Id
;
6674 if Error_Posted
(Type_Id
)
6675 or else Error_Posted
(Btype
)
6680 if Is_Class_Wide_Type
(Btype
) then
6681 Btype
:= Root_Type
(Btype
);
6684 if Is_Private_Type
(Btype
) then
6686 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
6689 if No
(Full_View
(Btype
)) then
6690 return not Is_Generic_Type
(Btype
)
6691 and then not Is_Generic_Type
(Root_Type
(Btype
));
6693 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
6696 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
6700 elsif Is_Array_Type
(Btype
) then
6701 return Has_Private_Component
(Component_Type
(Btype
));
6703 elsif Is_Record_Type
(Btype
) then
6704 Component
:= First_Component
(Btype
);
6705 while Present
(Component
) loop
6706 if Has_Private_Component
(Etype
(Component
)) then
6710 Next_Component
(Component
);
6715 elsif Is_Protected_Type
(Btype
)
6716 and then Present
(Corresponding_Record_Type
(Btype
))
6718 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
6723 end Has_Private_Component
;
6725 ----------------------
6726 -- Has_Signed_Zeros --
6727 ----------------------
6729 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
6731 return Is_Floating_Point_Type
(E
)
6732 and then Signed_Zeros_On_Target
6733 and then not Vax_Float
(E
);
6734 end Has_Signed_Zeros
;
6736 -----------------------------
6737 -- Has_Static_Array_Bounds --
6738 -----------------------------
6740 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
6741 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
6748 -- Unconstrained types do not have static bounds
6750 if not Is_Constrained
(Typ
) then
6754 -- First treat string literals specially, as the lower bound and length
6755 -- of string literals are not stored like those of arrays.
6757 -- A string literal always has static bounds
6759 if Ekind
(Typ
) = E_String_Literal_Subtype
then
6763 -- Treat all dimensions in turn
6765 Index
:= First_Index
(Typ
);
6766 for Indx
in 1 .. Ndims
loop
6768 -- In case of an erroneous index which is not a discrete type, return
6769 -- that the type is not static.
6771 if not Is_Discrete_Type
(Etype
(Index
))
6772 or else Etype
(Index
) = Any_Type
6777 Get_Index_Bounds
(Index
, Low
, High
);
6779 if Error_Posted
(Low
) or else Error_Posted
(High
) then
6783 if Is_OK_Static_Expression
(Low
)
6785 Is_OK_Static_Expression
(High
)
6795 -- If we fall through the loop, all indexes matched
6798 end Has_Static_Array_Bounds
;
6804 function Has_Stream
(T
: Entity_Id
) return Boolean is
6811 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
6814 elsif Is_Array_Type
(T
) then
6815 return Has_Stream
(Component_Type
(T
));
6817 elsif Is_Record_Type
(T
) then
6818 E
:= First_Component
(T
);
6819 while Present
(E
) loop
6820 if Has_Stream
(Etype
(E
)) then
6829 elsif Is_Private_Type
(T
) then
6830 return Has_Stream
(Underlying_Type
(T
));
6841 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
6843 Get_Name_String
(Chars
(E
));
6844 return Name_Buffer
(Name_Len
) = Suffix
;
6851 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
6853 Get_Name_String
(Chars
(E
));
6854 Add_Char_To_Name_Buffer
(Suffix
);
6862 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
6864 pragma Assert
(Has_Suffix
(E
, Suffix
));
6865 Get_Name_String
(Chars
(E
));
6866 Name_Len
:= Name_Len
- 1;
6870 --------------------------
6871 -- Has_Tagged_Component --
6872 --------------------------
6874 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
6878 if Is_Private_Type
(Typ
)
6879 and then Present
(Underlying_Type
(Typ
))
6881 return Has_Tagged_Component
(Underlying_Type
(Typ
));
6883 elsif Is_Array_Type
(Typ
) then
6884 return Has_Tagged_Component
(Component_Type
(Typ
));
6886 elsif Is_Tagged_Type
(Typ
) then
6889 elsif Is_Record_Type
(Typ
) then
6890 Comp
:= First_Component
(Typ
);
6891 while Present
(Comp
) loop
6892 if Has_Tagged_Component
(Etype
(Comp
)) then
6896 Next_Component
(Comp
);
6904 end Has_Tagged_Component
;
6906 -------------------------
6907 -- Implementation_Kind --
6908 -------------------------
6910 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
6911 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
6914 pragma Assert
(Present
(Impl_Prag
));
6915 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
6916 return Chars
(Get_Pragma_Arg
(Arg
));
6917 end Implementation_Kind
;
6919 --------------------------
6920 -- Implements_Interface --
6921 --------------------------
6923 function Implements_Interface
6924 (Typ_Ent
: Entity_Id
;
6925 Iface_Ent
: Entity_Id
;
6926 Exclude_Parents
: Boolean := False) return Boolean
6928 Ifaces_List
: Elist_Id
;
6930 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
6931 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
6934 if Is_Class_Wide_Type
(Typ
) then
6935 Typ
:= Root_Type
(Typ
);
6938 if not Has_Interfaces
(Typ
) then
6942 if Is_Class_Wide_Type
(Iface
) then
6943 Iface
:= Root_Type
(Iface
);
6946 Collect_Interfaces
(Typ
, Ifaces_List
);
6948 Elmt
:= First_Elmt
(Ifaces_List
);
6949 while Present
(Elmt
) loop
6950 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
6951 and then Exclude_Parents
6955 elsif Node
(Elmt
) = Iface
then
6963 end Implements_Interface
;
6969 function In_Instance
return Boolean is
6970 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
6976 and then S
/= Standard_Standard
6978 if (Ekind
(S
) = E_Function
6979 or else Ekind
(S
) = E_Package
6980 or else Ekind
(S
) = E_Procedure
)
6981 and then Is_Generic_Instance
(S
)
6983 -- A child instance is always compiled in the context of a parent
6984 -- instance. Nevertheless, the actuals are not analyzed in an
6985 -- instance context. We detect this case by examining the current
6986 -- compilation unit, which must be a child instance, and checking
6987 -- that it is not currently on the scope stack.
6989 if Is_Child_Unit
(Curr_Unit
)
6991 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
6992 = N_Package_Instantiation
6993 and then not In_Open_Scopes
(Curr_Unit
)
7007 ----------------------
7008 -- In_Instance_Body --
7009 ----------------------
7011 function In_Instance_Body
return Boolean is
7017 and then S
/= Standard_Standard
7019 if (Ekind
(S
) = E_Function
7020 or else Ekind
(S
) = E_Procedure
)
7021 and then Is_Generic_Instance
(S
)
7025 elsif Ekind
(S
) = E_Package
7026 and then In_Package_Body
(S
)
7027 and then Is_Generic_Instance
(S
)
7036 end In_Instance_Body
;
7038 -----------------------------
7039 -- In_Instance_Not_Visible --
7040 -----------------------------
7042 function In_Instance_Not_Visible
return Boolean is
7048 and then S
/= Standard_Standard
7050 if (Ekind
(S
) = E_Function
7051 or else Ekind
(S
) = E_Procedure
)
7052 and then Is_Generic_Instance
(S
)
7056 elsif Ekind
(S
) = E_Package
7057 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
7058 and then Is_Generic_Instance
(S
)
7067 end In_Instance_Not_Visible
;
7069 ------------------------------
7070 -- In_Instance_Visible_Part --
7071 ------------------------------
7073 function In_Instance_Visible_Part
return Boolean is
7079 and then S
/= Standard_Standard
7081 if Ekind
(S
) = E_Package
7082 and then Is_Generic_Instance
(S
)
7083 and then not In_Package_Body
(S
)
7084 and then not In_Private_Part
(S
)
7093 end In_Instance_Visible_Part
;
7095 ---------------------
7096 -- In_Package_Body --
7097 ---------------------
7099 function In_Package_Body
return Boolean is
7105 and then S
/= Standard_Standard
7107 if Ekind
(S
) = E_Package
7108 and then In_Package_Body
(S
)
7117 end In_Package_Body
;
7119 --------------------------------
7120 -- In_Parameter_Specification --
7121 --------------------------------
7123 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
7128 while Present
(PN
) loop
7129 if Nkind
(PN
) = N_Parameter_Specification
then
7137 end In_Parameter_Specification
;
7139 -------------------------------------
7140 -- In_Reverse_Storage_Order_Object --
7141 -------------------------------------
7143 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
7145 Btyp
: Entity_Id
:= Empty
;
7148 -- Climb up indexed components
7152 case Nkind
(Pref
) is
7153 when N_Selected_Component
=>
7154 Pref
:= Prefix
(Pref
);
7157 when N_Indexed_Component
=>
7158 Pref
:= Prefix
(Pref
);
7166 if Present
(Pref
) then
7167 Btyp
:= Base_Type
(Etype
(Pref
));
7172 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
7173 and then Reverse_Storage_Order
(Btyp
);
7174 end In_Reverse_Storage_Order_Object
;
7176 --------------------------------------
7177 -- In_Subprogram_Or_Concurrent_Unit --
7178 --------------------------------------
7180 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
7185 -- Use scope chain to check successively outer scopes
7191 if K
in Subprogram_Kind
7192 or else K
in Concurrent_Kind
7193 or else K
in Generic_Subprogram_Kind
7197 elsif E
= Standard_Standard
then
7203 end In_Subprogram_Or_Concurrent_Unit
;
7205 ---------------------
7206 -- In_Visible_Part --
7207 ---------------------
7209 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
7212 Is_Package_Or_Generic_Package
(Scope_Id
)
7213 and then In_Open_Scopes
(Scope_Id
)
7214 and then not In_Package_Body
(Scope_Id
)
7215 and then not In_Private_Part
(Scope_Id
);
7216 end In_Visible_Part
;
7218 --------------------------------
7219 -- Incomplete_Or_Private_View --
7220 --------------------------------
7222 function Incomplete_Or_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
7223 function Inspect_Decls
7225 Taft
: Boolean := False) return Entity_Id
;
7226 -- Check whether a declarative region contains the incomplete or private
7233 function Inspect_Decls
7235 Taft
: Boolean := False) return Entity_Id
7241 Decl
:= First
(Decls
);
7242 while Present
(Decl
) loop
7246 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
7247 Match
:= Defining_Identifier
(Decl
);
7251 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
7252 N_Private_Type_Declaration
)
7254 Match
:= Defining_Identifier
(Decl
);
7259 and then Present
(Full_View
(Match
))
7260 and then Full_View
(Match
) = Typ
7275 -- Start of processing for Incomplete_Or_Partial_View
7278 -- Incomplete type case
7280 Prev
:= Current_Entity_In_Scope
(Typ
);
7283 and then Is_Incomplete_Type
(Prev
)
7284 and then Present
(Full_View
(Prev
))
7285 and then Full_View
(Prev
) = Typ
7290 -- Private or Taft amendment type case
7293 Pkg
: constant Entity_Id
:= Scope
(Typ
);
7294 Pkg_Decl
: Node_Id
:= Pkg
;
7297 if Ekind
(Pkg
) = E_Package
then
7298 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
7299 Pkg_Decl
:= Parent
(Pkg_Decl
);
7302 -- It is knows that Typ has a private view, look for it in the
7303 -- visible declarations of the enclosing scope. A special case
7304 -- of this is when the two views have been exchanged - the full
7305 -- appears earlier than the private.
7307 if Has_Private_Declaration
(Typ
) then
7308 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
7310 -- Exchanged view case, look in the private declarations
7313 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
7318 -- Otherwise if this is the package body, then Typ is a potential
7319 -- Taft amendment type. The incomplete view should be located in
7320 -- the private declarations of the enclosing scope.
7322 elsif In_Package_Body
(Pkg
) then
7323 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
7328 -- The type has no incomplete or private view
7331 end Incomplete_Or_Private_View
;
7333 ---------------------------------
7334 -- Insert_Explicit_Dereference --
7335 ---------------------------------
7337 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
7338 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
7339 Ent
: Entity_Id
:= Empty
;
7346 Save_Interps
(N
, New_Prefix
);
7349 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
7350 Prefix
=> New_Prefix
));
7352 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
7354 if Is_Overloaded
(New_Prefix
) then
7356 -- The dereference is also overloaded, and its interpretations are
7357 -- the designated types of the interpretations of the original node.
7359 Set_Etype
(N
, Any_Type
);
7361 Get_First_Interp
(New_Prefix
, I
, It
);
7362 while Present
(It
.Nam
) loop
7365 if Is_Access_Type
(T
) then
7366 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
7369 Get_Next_Interp
(I
, It
);
7375 -- Prefix is unambiguous: mark the original prefix (which might
7376 -- Come_From_Source) as a reference, since the new (relocated) one
7377 -- won't be taken into account.
7379 if Is_Entity_Name
(New_Prefix
) then
7380 Ent
:= Entity
(New_Prefix
);
7383 -- For a retrieval of a subcomponent of some composite object,
7384 -- retrieve the ultimate entity if there is one.
7386 elsif Nkind
(New_Prefix
) = N_Selected_Component
7387 or else Nkind
(New_Prefix
) = N_Indexed_Component
7389 Pref
:= Prefix
(New_Prefix
);
7390 while Present
(Pref
)
7392 (Nkind
(Pref
) = N_Selected_Component
7393 or else Nkind
(Pref
) = N_Indexed_Component
)
7395 Pref
:= Prefix
(Pref
);
7398 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
7399 Ent
:= Entity
(Pref
);
7403 -- Place the reference on the entity node
7405 if Present
(Ent
) then
7406 Generate_Reference
(Ent
, Pref
);
7409 end Insert_Explicit_Dereference
;
7411 ------------------------------------------
7412 -- Inspect_Deferred_Constant_Completion --
7413 ------------------------------------------
7415 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
7419 Decl
:= First
(Decls
);
7420 while Present
(Decl
) loop
7422 -- Deferred constant signature
7424 if Nkind
(Decl
) = N_Object_Declaration
7425 and then Constant_Present
(Decl
)
7426 and then No
(Expression
(Decl
))
7428 -- No need to check internally generated constants
7430 and then Comes_From_Source
(Decl
)
7432 -- The constant is not completed. A full object declaration or a
7433 -- pragma Import complete a deferred constant.
7435 and then not Has_Completion
(Defining_Identifier
(Decl
))
7438 ("constant declaration requires initialization expression",
7439 Defining_Identifier
(Decl
));
7442 Decl
:= Next
(Decl
);
7444 end Inspect_Deferred_Constant_Completion
;
7446 -----------------------------
7447 -- Is_Actual_Out_Parameter --
7448 -----------------------------
7450 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
7454 Find_Actual
(N
, Formal
, Call
);
7455 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
7456 end Is_Actual_Out_Parameter
;
7458 -------------------------
7459 -- Is_Actual_Parameter --
7460 -------------------------
7462 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
7463 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
7467 when N_Parameter_Association
=>
7468 return N
= Explicit_Actual_Parameter
(Parent
(N
));
7470 when N_Subprogram_Call
=>
7471 return Is_List_Member
(N
)
7473 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
7478 end Is_Actual_Parameter
;
7480 --------------------------------
7481 -- Is_Actual_Tagged_Parameter --
7482 --------------------------------
7484 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
7488 Find_Actual
(N
, Formal
, Call
);
7489 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
7490 end Is_Actual_Tagged_Parameter
;
7492 ---------------------
7493 -- Is_Aliased_View --
7494 ---------------------
7496 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
7500 if Is_Entity_Name
(Obj
) then
7507 or else (Present
(Renamed_Object
(E
))
7508 and then Is_Aliased_View
(Renamed_Object
(E
)))))
7510 or else ((Is_Formal
(E
)
7511 or else Ekind
(E
) = E_Generic_In_Out_Parameter
7512 or else Ekind
(E
) = E_Generic_In_Parameter
)
7513 and then Is_Tagged_Type
(Etype
(E
)))
7515 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
7517 -- Current instance of type, either directly or as rewritten
7518 -- reference to the current object.
7520 or else (Is_Entity_Name
(Original_Node
(Obj
))
7521 and then Present
(Entity
(Original_Node
(Obj
)))
7522 and then Is_Type
(Entity
(Original_Node
(Obj
))))
7524 or else (Is_Type
(E
) and then E
= Current_Scope
)
7526 or else (Is_Incomplete_Or_Private_Type
(E
)
7527 and then Full_View
(E
) = Current_Scope
)
7529 -- Ada 2012 AI05-0053: the return object of an extended return
7530 -- statement is aliased if its type is immutably limited.
7532 or else (Is_Return_Object
(E
)
7533 and then Is_Immutably_Limited_Type
(Etype
(E
)));
7535 elsif Nkind
(Obj
) = N_Selected_Component
then
7536 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
7538 elsif Nkind
(Obj
) = N_Indexed_Component
then
7539 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
7541 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
7542 and then Has_Aliased_Components
7543 (Designated_Type
(Etype
(Prefix
(Obj
)))));
7545 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
7546 return Is_Tagged_Type
(Etype
(Obj
))
7547 and then Is_Aliased_View
(Expression
(Obj
));
7549 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
7550 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
7555 end Is_Aliased_View
;
7557 -------------------------
7558 -- Is_Ancestor_Package --
7559 -------------------------
7561 function Is_Ancestor_Package
7563 E2
: Entity_Id
) return Boolean
7570 and then Par
/= Standard_Standard
7580 end Is_Ancestor_Package
;
7582 ----------------------
7583 -- Is_Atomic_Object --
7584 ----------------------
7586 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
7588 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
7589 -- Determines if given object has atomic components
7591 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
7592 -- If prefix is an implicit dereference, examine designated type
7594 ----------------------
7595 -- Is_Atomic_Prefix --
7596 ----------------------
7598 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
7600 if Is_Access_Type
(Etype
(N
)) then
7602 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
7604 return Object_Has_Atomic_Components
(N
);
7606 end Is_Atomic_Prefix
;
7608 ----------------------------------
7609 -- Object_Has_Atomic_Components --
7610 ----------------------------------
7612 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
7614 if Has_Atomic_Components
(Etype
(N
))
7615 or else Is_Atomic
(Etype
(N
))
7619 elsif Is_Entity_Name
(N
)
7620 and then (Has_Atomic_Components
(Entity
(N
))
7621 or else Is_Atomic
(Entity
(N
)))
7625 elsif Nkind
(N
) = N_Selected_Component
7626 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
7630 elsif Nkind
(N
) = N_Indexed_Component
7631 or else Nkind
(N
) = N_Selected_Component
7633 return Is_Atomic_Prefix
(Prefix
(N
));
7638 end Object_Has_Atomic_Components
;
7640 -- Start of processing for Is_Atomic_Object
7643 -- Predicate is not relevant to subprograms
7645 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
7648 elsif Is_Atomic
(Etype
(N
))
7649 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
7653 elsif Nkind
(N
) = N_Selected_Component
7654 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
7658 elsif Nkind
(N
) = N_Indexed_Component
7659 or else Nkind
(N
) = N_Selected_Component
7661 return Is_Atomic_Prefix
(Prefix
(N
));
7666 end Is_Atomic_Object
;
7668 -----------------------
7669 -- Is_Bounded_String --
7670 -----------------------
7672 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
7673 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
7676 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
7677 -- Super_String, or one of the [Wide_]Wide_ versions. This will
7678 -- be True for all the Bounded_String types in instances of the
7679 -- Generic_Bounded_Length generics, and for types derived from those.
7681 return Present
(Under
)
7682 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
7683 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
7684 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
7685 end Is_Bounded_String
;
7687 -----------------------------
7688 -- Is_Concurrent_Interface --
7689 -----------------------------
7691 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
7696 (Is_Protected_Interface
(T
)
7697 or else Is_Synchronized_Interface
(T
)
7698 or else Is_Task_Interface
(T
));
7699 end Is_Concurrent_Interface
;
7701 --------------------------------------
7702 -- Is_Controlling_Limited_Procedure --
7703 --------------------------------------
7705 function Is_Controlling_Limited_Procedure
7706 (Proc_Nam
: Entity_Id
) return Boolean
7708 Param_Typ
: Entity_Id
:= Empty
;
7711 if Ekind
(Proc_Nam
) = E_Procedure
7712 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
7714 Param_Typ
:= Etype
(Parameter_Type
(First
(
7715 Parameter_Specifications
(Parent
(Proc_Nam
)))));
7717 -- In this case where an Itype was created, the procedure call has been
7720 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
7721 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
7723 Present
(Parameter_Associations
7724 (Associated_Node_For_Itype
(Proc_Nam
)))
7727 Etype
(First
(Parameter_Associations
7728 (Associated_Node_For_Itype
(Proc_Nam
))));
7731 if Present
(Param_Typ
) then
7733 Is_Interface
(Param_Typ
)
7734 and then Is_Limited_Record
(Param_Typ
);
7738 end Is_Controlling_Limited_Procedure
;
7740 -----------------------------
7741 -- Is_CPP_Constructor_Call --
7742 -----------------------------
7744 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
7746 return Nkind
(N
) = N_Function_Call
7747 and then Is_CPP_Class
(Etype
(Etype
(N
)))
7748 and then Is_Constructor
(Entity
(Name
(N
)))
7749 and then Is_Imported
(Entity
(Name
(N
)));
7750 end Is_CPP_Constructor_Call
;
7756 function Is_Delegate
(T
: Entity_Id
) return Boolean is
7757 Desig_Type
: Entity_Id
;
7760 if VM_Target
/= CLI_Target
then
7764 -- Access-to-subprograms are delegates in CIL
7766 if Ekind
(T
) = E_Access_Subprogram_Type
then
7770 if Ekind
(T
) not in Access_Kind
then
7772 -- A delegate is a managed pointer. If no designated type is defined
7773 -- it means that it's not a delegate.
7778 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
7780 if not Is_Tagged_Type
(Desig_Type
) then
7784 -- Test if the type is inherited from [mscorlib]System.Delegate
7786 while Etype
(Desig_Type
) /= Desig_Type
loop
7787 if Chars
(Scope
(Desig_Type
)) /= No_Name
7788 and then Is_Imported
(Scope
(Desig_Type
))
7789 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
7794 Desig_Type
:= Etype
(Desig_Type
);
7800 ----------------------------------------------
7801 -- Is_Dependent_Component_Of_Mutable_Object --
7802 ----------------------------------------------
7804 function Is_Dependent_Component_Of_Mutable_Object
7805 (Object
: Node_Id
) return Boolean
7808 Prefix_Type
: Entity_Id
;
7809 P_Aliased
: Boolean := False;
7812 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
7813 -- Returns True if and only if Comp is declared within a variant part
7815 --------------------------------
7816 -- Is_Declared_Within_Variant --
7817 --------------------------------
7819 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
7820 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7821 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
7823 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
7824 end Is_Declared_Within_Variant
;
7826 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
7829 if Is_Variable
(Object
) then
7831 if Nkind
(Object
) = N_Selected_Component
then
7832 P
:= Prefix
(Object
);
7833 Prefix_Type
:= Etype
(P
);
7835 if Is_Entity_Name
(P
) then
7837 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
7838 Prefix_Type
:= Base_Type
(Prefix_Type
);
7841 if Is_Aliased
(Entity
(P
)) then
7845 -- A discriminant check on a selected component may be expanded
7846 -- into a dereference when removing side-effects. Recover the
7847 -- original node and its type, which may be unconstrained.
7849 elsif Nkind
(P
) = N_Explicit_Dereference
7850 and then not (Comes_From_Source
(P
))
7852 P
:= Original_Node
(P
);
7853 Prefix_Type
:= Etype
(P
);
7856 -- Check for prefix being an aliased component???
7862 -- A heap object is constrained by its initial value
7864 -- Ada 2005 (AI-363): Always assume the object could be mutable in
7865 -- the dereferenced case, since the access value might denote an
7866 -- unconstrained aliased object, whereas in Ada 95 the designated
7867 -- object is guaranteed to be constrained. A worst-case assumption
7868 -- has to apply in Ada 2005 because we can't tell at compile time
7869 -- whether the object is "constrained by its initial value"
7870 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
7871 -- semantic rules -- these rules are acknowledged to need fixing).
7873 if Ada_Version
< Ada_2005
then
7874 if Is_Access_Type
(Prefix_Type
)
7875 or else Nkind
(P
) = N_Explicit_Dereference
7880 elsif Ada_Version
>= Ada_2005
then
7881 if Is_Access_Type
(Prefix_Type
) then
7883 -- If the access type is pool-specific, and there is no
7884 -- constrained partial view of the designated type, then the
7885 -- designated object is known to be constrained.
7887 if Ekind
(Prefix_Type
) = E_Access_Type
7888 and then not Effectively_Has_Constrained_Partial_View
7889 (Typ
=> Designated_Type
(Prefix_Type
),
7890 Scop
=> Current_Scope
)
7894 -- Otherwise (general access type, or there is a constrained
7895 -- partial view of the designated type), we need to check
7896 -- based on the designated type.
7899 Prefix_Type
:= Designated_Type
(Prefix_Type
);
7905 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
7907 -- As per AI-0017, the renaming is illegal in a generic body, even
7908 -- if the subtype is indefinite.
7910 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
7912 if not Is_Constrained
(Prefix_Type
)
7913 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
7915 (Is_Generic_Type
(Prefix_Type
)
7916 and then Ekind
(Current_Scope
) = E_Generic_Package
7917 and then In_Package_Body
(Current_Scope
)))
7919 and then (Is_Declared_Within_Variant
(Comp
)
7920 or else Has_Discriminant_Dependent_Constraint
(Comp
))
7921 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
7927 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
7931 elsif Nkind
(Object
) = N_Indexed_Component
7932 or else Nkind
(Object
) = N_Slice
7934 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
7936 -- A type conversion that Is_Variable is a view conversion:
7937 -- go back to the denoted object.
7939 elsif Nkind
(Object
) = N_Type_Conversion
then
7941 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
7946 end Is_Dependent_Component_Of_Mutable_Object
;
7948 ---------------------
7949 -- Is_Dereferenced --
7950 ---------------------
7952 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
7953 P
: constant Node_Id
:= Parent
(N
);
7956 (Nkind
(P
) = N_Selected_Component
7958 Nkind
(P
) = N_Explicit_Dereference
7960 Nkind
(P
) = N_Indexed_Component
7962 Nkind
(P
) = N_Slice
)
7963 and then Prefix
(P
) = N
;
7964 end Is_Dereferenced
;
7966 ----------------------
7967 -- Is_Descendent_Of --
7968 ----------------------
7970 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
7975 pragma Assert
(Nkind
(T1
) in N_Entity
);
7976 pragma Assert
(Nkind
(T2
) in N_Entity
);
7978 T
:= Base_Type
(T1
);
7980 -- Immediate return if the types match
7985 -- Comment needed here ???
7987 elsif Ekind
(T
) = E_Class_Wide_Type
then
7988 return Etype
(T
) = T2
;
7996 -- Done if we found the type we are looking for
8001 -- Done if no more derivations to check
8008 -- Following test catches error cases resulting from prev errors
8010 elsif No
(Etyp
) then
8013 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
8016 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
8020 T
:= Base_Type
(Etyp
);
8023 end Is_Descendent_Of
;
8025 ----------------------------
8026 -- Is_Expression_Function --
8027 ----------------------------
8029 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
8030 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
8033 return Ekind
(Subp
) = E_Function
8034 and then Nkind
(Decl
) = N_Subprogram_Declaration
8036 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
8038 (Present
(Corresponding_Body
(Decl
))
8040 Nkind
(Original_Node
8041 (Unit_Declaration_Node
(Corresponding_Body
(Decl
))))
8042 = N_Expression_Function
));
8043 end Is_Expression_Function
;
8049 function Is_False
(U
: Uint
) return Boolean is
8054 ---------------------------
8055 -- Is_Fixed_Model_Number --
8056 ---------------------------
8058 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
8059 S
: constant Ureal
:= Small_Value
(T
);
8060 M
: Urealp
.Save_Mark
;
8064 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
8067 end Is_Fixed_Model_Number
;
8069 -------------------------------
8070 -- Is_Fully_Initialized_Type --
8071 -------------------------------
8073 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
8075 -- In Ada2012, a scalar type with an aspect Default_Value
8076 -- is fully initialized.
8078 if Is_Scalar_Type
(Typ
) then
8079 return Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
);
8081 elsif Is_Access_Type
(Typ
) then
8084 elsif Is_Array_Type
(Typ
) then
8085 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
8086 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
8091 -- An interesting case, if we have a constrained type one of whose
8092 -- bounds is known to be null, then there are no elements to be
8093 -- initialized, so all the elements are initialized!
8095 if Is_Constrained
(Typ
) then
8098 Indx_Typ
: Entity_Id
;
8102 Indx
:= First_Index
(Typ
);
8103 while Present
(Indx
) loop
8104 if Etype
(Indx
) = Any_Type
then
8107 -- If index is a range, use directly
8109 elsif Nkind
(Indx
) = N_Range
then
8110 Lbd
:= Low_Bound
(Indx
);
8111 Hbd
:= High_Bound
(Indx
);
8114 Indx_Typ
:= Etype
(Indx
);
8116 if Is_Private_Type
(Indx_Typ
) then
8117 Indx_Typ
:= Full_View
(Indx_Typ
);
8120 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
8123 Lbd
:= Type_Low_Bound
(Indx_Typ
);
8124 Hbd
:= Type_High_Bound
(Indx_Typ
);
8128 if Compile_Time_Known_Value
(Lbd
)
8129 and then Compile_Time_Known_Value
(Hbd
)
8131 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
8141 -- If no null indexes, then type is not fully initialized
8147 elsif Is_Record_Type
(Typ
) then
8148 if Has_Discriminants
(Typ
)
8150 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
8151 and then Is_Fully_Initialized_Variant
(Typ
)
8156 -- We consider bounded string types to be fully initialized, because
8157 -- otherwise we get false alarms when the Data component is not
8158 -- default-initialized.
8160 if Is_Bounded_String
(Typ
) then
8164 -- Controlled records are considered to be fully initialized if
8165 -- there is a user defined Initialize routine. This may not be
8166 -- entirely correct, but as the spec notes, we are guessing here
8167 -- what is best from the point of view of issuing warnings.
8169 if Is_Controlled
(Typ
) then
8171 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
8174 if Present
(Utyp
) then
8176 Init
: constant Entity_Id
:=
8178 (Underlying_Type
(Typ
), Name_Initialize
));
8182 and then Comes_From_Source
(Init
)
8184 Is_Predefined_File_Name
8185 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
8189 elsif Has_Null_Extension
(Typ
)
8191 Is_Fully_Initialized_Type
8192 (Etype
(Base_Type
(Typ
)))
8201 -- Otherwise see if all record components are initialized
8207 Ent
:= First_Entity
(Typ
);
8208 while Present
(Ent
) loop
8209 if Ekind
(Ent
) = E_Component
8210 and then (No
(Parent
(Ent
))
8211 or else No
(Expression
(Parent
(Ent
))))
8212 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
8214 -- Special VM case for tag components, which need to be
8215 -- defined in this case, but are never initialized as VMs
8216 -- are using other dispatching mechanisms. Ignore this
8217 -- uninitialized case. Note that this applies both to the
8218 -- uTag entry and the main vtable pointer (CPP_Class case).
8220 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
8229 -- No uninitialized components, so type is fully initialized.
8230 -- Note that this catches the case of no components as well.
8234 elsif Is_Concurrent_Type
(Typ
) then
8237 elsif Is_Private_Type
(Typ
) then
8239 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
8245 return Is_Fully_Initialized_Type
(U
);
8252 end Is_Fully_Initialized_Type
;
8254 ----------------------------------
8255 -- Is_Fully_Initialized_Variant --
8256 ----------------------------------
8258 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
8259 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
8260 Constraints
: constant List_Id
:= New_List
;
8261 Components
: constant Elist_Id
:= New_Elmt_List
;
8262 Comp_Elmt
: Elmt_Id
;
8264 Comp_List
: Node_Id
;
8266 Discr_Val
: Node_Id
;
8268 Report_Errors
: Boolean;
8269 pragma Warnings
(Off
, Report_Errors
);
8272 if Serious_Errors_Detected
> 0 then
8276 if Is_Record_Type
(Typ
)
8277 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
8278 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
8280 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
8282 Discr
:= First_Discriminant
(Typ
);
8283 while Present
(Discr
) loop
8284 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
8285 Discr_Val
:= Expression
(Parent
(Discr
));
8287 if Present
(Discr_Val
)
8288 and then Is_OK_Static_Expression
(Discr_Val
)
8290 Append_To
(Constraints
,
8291 Make_Component_Association
(Loc
,
8292 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
8293 Expression
=> New_Copy
(Discr_Val
)));
8301 Next_Discriminant
(Discr
);
8306 Comp_List
=> Comp_List
,
8307 Governed_By
=> Constraints
,
8309 Report_Errors
=> Report_Errors
);
8311 -- Check that each component present is fully initialized
8313 Comp_Elmt
:= First_Elmt
(Components
);
8314 while Present
(Comp_Elmt
) loop
8315 Comp_Id
:= Node
(Comp_Elmt
);
8317 if Ekind
(Comp_Id
) = E_Component
8318 and then (No
(Parent
(Comp_Id
))
8319 or else No
(Expression
(Parent
(Comp_Id
))))
8320 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
8325 Next_Elmt
(Comp_Elmt
);
8330 elsif Is_Private_Type
(Typ
) then
8332 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
8338 return Is_Fully_Initialized_Variant
(U
);
8344 end Is_Fully_Initialized_Variant
;
8346 ----------------------------
8347 -- Is_Inherited_Operation --
8348 ----------------------------
8350 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
8351 pragma Assert
(Is_Overloadable
(E
));
8352 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
8354 return Kind
= N_Full_Type_Declaration
8355 or else Kind
= N_Private_Extension_Declaration
8356 or else Kind
= N_Subtype_Declaration
8357 or else (Ekind
(E
) = E_Enumeration_Literal
8358 and then Is_Derived_Type
(Etype
(E
)));
8359 end Is_Inherited_Operation
;
8361 -------------------------------------
8362 -- Is_Inherited_Operation_For_Type --
8363 -------------------------------------
8365 function Is_Inherited_Operation_For_Type
8367 Typ
: Entity_Id
) return Boolean
8370 return Is_Inherited_Operation
(E
)
8371 and then Etype
(Parent
(E
)) = Typ
;
8372 end Is_Inherited_Operation_For_Type
;
8378 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
8379 Ifaces_List
: Elist_Id
;
8380 Iface_Elmt
: Elmt_Id
;
8384 if Is_Class_Wide_Type
(Typ
)
8386 (Chars
(Etype
(Typ
)) = Name_Forward_Iterator
8388 Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
)
8390 Is_Predefined_File_Name
8391 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
8395 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
8399 Collect_Interfaces
(Typ
, Ifaces_List
);
8401 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
8402 while Present
(Iface_Elmt
) loop
8403 Iface
:= Node
(Iface_Elmt
);
8404 if Chars
(Iface
) = Name_Forward_Iterator
8406 Is_Predefined_File_Name
8407 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
8412 Next_Elmt
(Iface_Elmt
);
8423 -- We seem to have a lot of overlapping functions that do similar things
8424 -- (testing for left hand sides or lvalues???). Anyway, since this one is
8425 -- purely syntactic, it should be in Sem_Aux I would think???
8427 function Is_LHS
(N
: Node_Id
) return Boolean is
8428 P
: constant Node_Id
:= Parent
(N
);
8431 if Nkind
(P
) = N_Assignment_Statement
then
8432 return Name
(P
) = N
;
8435 Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
8437 return N
= Prefix
(P
) and then Is_LHS
(P
);
8444 -----------------------------
8445 -- Is_Library_Level_Entity --
8446 -----------------------------
8448 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
8450 -- The following is a small optimization, and it also properly handles
8451 -- discriminals, which in task bodies might appear in expressions before
8452 -- the corresponding procedure has been created, and which therefore do
8453 -- not have an assigned scope.
8455 if Is_Formal
(E
) then
8459 -- Normal test is simply that the enclosing dynamic scope is Standard
8461 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
8462 end Is_Library_Level_Entity
;
8464 --------------------------------
8465 -- Is_Limited_Class_Wide_Type --
8466 --------------------------------
8468 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
8471 Is_Class_Wide_Type
(Typ
)
8472 and then Is_Limited_Type
(Typ
);
8473 end Is_Limited_Class_Wide_Type
;
8475 ---------------------------------
8476 -- Is_Local_Variable_Reference --
8477 ---------------------------------
8479 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
8481 if not Is_Entity_Name
(Expr
) then
8486 Ent
: constant Entity_Id
:= Entity
(Expr
);
8487 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
8489 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
8492 return Present
(Sub
) and then Sub
= Current_Subprogram
;
8496 end Is_Local_Variable_Reference
;
8498 -------------------------
8499 -- Is_Object_Reference --
8500 -------------------------
8502 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
8504 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
8505 -- Determine whether N is the name of an internally-generated renaming
8507 --------------------------------------
8508 -- Is_Internally_Generated_Renaming --
8509 --------------------------------------
8511 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
8516 while Present
(P
) loop
8517 if Nkind
(P
) = N_Object_Renaming_Declaration
then
8518 return not Comes_From_Source
(P
);
8519 elsif Is_List_Member
(P
) then
8527 end Is_Internally_Generated_Renaming
;
8529 -- Start of processing for Is_Object_Reference
8532 if Is_Entity_Name
(N
) then
8533 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
8537 when N_Indexed_Component | N_Slice
=>
8539 Is_Object_Reference
(Prefix
(N
))
8540 or else Is_Access_Type
(Etype
(Prefix
(N
)));
8542 -- In Ada 95, a function call is a constant object; a procedure
8545 when N_Function_Call
=>
8546 return Etype
(N
) /= Standard_Void_Type
;
8548 -- Attributes 'Input and 'Result produce objects
8550 when N_Attribute_Reference
=>
8551 return Attribute_Name
(N
) = Name_Input
8553 Attribute_Name
(N
) = Name_Result
;
8555 when N_Selected_Component
=>
8557 Is_Object_Reference
(Selector_Name
(N
))
8559 (Is_Object_Reference
(Prefix
(N
))
8560 or else Is_Access_Type
(Etype
(Prefix
(N
))));
8562 when N_Explicit_Dereference
=>
8565 -- A view conversion of a tagged object is an object reference
8567 when N_Type_Conversion
=>
8568 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
8569 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
8570 and then Is_Object_Reference
(Expression
(N
));
8572 -- An unchecked type conversion is considered to be an object if
8573 -- the operand is an object (this construction arises only as a
8574 -- result of expansion activities).
8576 when N_Unchecked_Type_Conversion
=>
8579 -- Allow string literals to act as objects as long as they appear
8580 -- in internally-generated renamings. The expansion of iterators
8581 -- may generate such renamings when the range involves a string
8584 when N_String_Literal
=>
8585 return Is_Internally_Generated_Renaming
(Parent
(N
));
8587 -- AI05-0003: In Ada 2012 a qualified expression is a name.
8588 -- This allows disambiguation of function calls and the use
8589 -- of aggregates in more contexts.
8591 when N_Qualified_Expression
=>
8592 if Ada_Version
< Ada_2012
then
8595 return Is_Object_Reference
(Expression
(N
))
8596 or else Nkind
(Expression
(N
)) = N_Aggregate
;
8603 end Is_Object_Reference
;
8605 -----------------------------------
8606 -- Is_OK_Variable_For_Out_Formal --
8607 -----------------------------------
8609 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
8611 Note_Possible_Modification
(AV
, Sure
=> True);
8613 -- We must reject parenthesized variable names. The check for
8614 -- Comes_From_Source is present because there are currently
8615 -- cases where the compiler violates this rule (e.g. passing
8616 -- a task object to its controlled Initialize routine).
8618 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
8621 -- A variable is always allowed
8623 elsif Is_Variable
(AV
) then
8626 -- Unchecked conversions are allowed only if they come from the
8627 -- generated code, which sometimes uses unchecked conversions for out
8628 -- parameters in cases where code generation is unaffected. We tell
8629 -- source unchecked conversions by seeing if they are rewrites of an
8630 -- original Unchecked_Conversion function call, or of an explicit
8631 -- conversion of a function call.
8633 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
8634 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
8637 elsif Comes_From_Source
(AV
)
8638 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
8642 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
8643 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
8649 -- Normal type conversions are allowed if argument is a variable
8651 elsif Nkind
(AV
) = N_Type_Conversion
then
8652 if Is_Variable
(Expression
(AV
))
8653 and then Paren_Count
(Expression
(AV
)) = 0
8655 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
8658 -- We also allow a non-parenthesized expression that raises
8659 -- constraint error if it rewrites what used to be a variable
8661 elsif Raises_Constraint_Error
(Expression
(AV
))
8662 and then Paren_Count
(Expression
(AV
)) = 0
8663 and then Is_Variable
(Original_Node
(Expression
(AV
)))
8667 -- Type conversion of something other than a variable
8673 -- If this node is rewritten, then test the original form, if that is
8674 -- OK, then we consider the rewritten node OK (for example, if the
8675 -- original node is a conversion, then Is_Variable will not be true
8676 -- but we still want to allow the conversion if it converts a variable).
8678 elsif Original_Node
(AV
) /= AV
then
8680 -- In Ada 2012, the explicit dereference may be a rewritten call to a
8681 -- Reference function.
8683 if Ada_Version
>= Ada_2012
8684 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
8686 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
8691 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
8694 -- All other non-variables are rejected
8699 end Is_OK_Variable_For_Out_Formal
;
8701 -----------------------------------
8702 -- Is_Partially_Initialized_Type --
8703 -----------------------------------
8705 function Is_Partially_Initialized_Type
8707 Include_Implicit
: Boolean := True) return Boolean
8710 if Is_Scalar_Type
(Typ
) then
8713 elsif Is_Access_Type
(Typ
) then
8714 return Include_Implicit
;
8716 elsif Is_Array_Type
(Typ
) then
8718 -- If component type is partially initialized, so is array type
8720 if Is_Partially_Initialized_Type
8721 (Component_Type
(Typ
), Include_Implicit
)
8725 -- Otherwise we are only partially initialized if we are fully
8726 -- initialized (this is the empty array case, no point in us
8727 -- duplicating that code here).
8730 return Is_Fully_Initialized_Type
(Typ
);
8733 elsif Is_Record_Type
(Typ
) then
8735 -- A discriminated type is always partially initialized if in
8738 if Has_Discriminants
(Typ
) and then Include_Implicit
then
8741 -- A tagged type is always partially initialized
8743 elsif Is_Tagged_Type
(Typ
) then
8746 -- Case of non-discriminated record
8752 Component_Present
: Boolean := False;
8753 -- Set True if at least one component is present. If no
8754 -- components are present, then record type is fully
8755 -- initialized (another odd case, like the null array).
8758 -- Loop through components
8760 Ent
:= First_Entity
(Typ
);
8761 while Present
(Ent
) loop
8762 if Ekind
(Ent
) = E_Component
then
8763 Component_Present
:= True;
8765 -- If a component has an initialization expression then
8766 -- the enclosing record type is partially initialized
8768 if Present
(Parent
(Ent
))
8769 and then Present
(Expression
(Parent
(Ent
)))
8773 -- If a component is of a type which is itself partially
8774 -- initialized, then the enclosing record type is also.
8776 elsif Is_Partially_Initialized_Type
8777 (Etype
(Ent
), Include_Implicit
)
8786 -- No initialized components found. If we found any components
8787 -- they were all uninitialized so the result is false.
8789 if Component_Present
then
8792 -- But if we found no components, then all the components are
8793 -- initialized so we consider the type to be initialized.
8801 -- Concurrent types are always fully initialized
8803 elsif Is_Concurrent_Type
(Typ
) then
8806 -- For a private type, go to underlying type. If there is no underlying
8807 -- type then just assume this partially initialized. Not clear if this
8808 -- can happen in a non-error case, but no harm in testing for this.
8810 elsif Is_Private_Type
(Typ
) then
8812 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
8817 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
8821 -- For any other type (are there any?) assume partially initialized
8826 end Is_Partially_Initialized_Type
;
8828 ------------------------------------
8829 -- Is_Potentially_Persistent_Type --
8830 ------------------------------------
8832 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
8837 -- For private type, test corresponding full type
8839 if Is_Private_Type
(T
) then
8840 return Is_Potentially_Persistent_Type
(Full_View
(T
));
8842 -- Scalar types are potentially persistent
8844 elsif Is_Scalar_Type
(T
) then
8847 -- Record type is potentially persistent if not tagged and the types of
8848 -- all it components are potentially persistent, and no component has
8849 -- an initialization expression.
8851 elsif Is_Record_Type
(T
)
8852 and then not Is_Tagged_Type
(T
)
8853 and then not Is_Partially_Initialized_Type
(T
)
8855 Comp
:= First_Component
(T
);
8856 while Present
(Comp
) loop
8857 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
8866 -- Array type is potentially persistent if its component type is
8867 -- potentially persistent and if all its constraints are static.
8869 elsif Is_Array_Type
(T
) then
8870 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
8874 Indx
:= First_Index
(T
);
8875 while Present
(Indx
) loop
8876 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
8885 -- All other types are not potentially persistent
8890 end Is_Potentially_Persistent_Type
;
8892 ---------------------------------
8893 -- Is_Protected_Self_Reference --
8894 ---------------------------------
8896 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
8898 function In_Access_Definition
(N
: Node_Id
) return Boolean;
8899 -- Returns true if N belongs to an access definition
8901 --------------------------
8902 -- In_Access_Definition --
8903 --------------------------
8905 function In_Access_Definition
(N
: Node_Id
) return Boolean is
8910 while Present
(P
) loop
8911 if Nkind
(P
) = N_Access_Definition
then
8919 end In_Access_Definition
;
8921 -- Start of processing for Is_Protected_Self_Reference
8924 -- Verify that prefix is analyzed and has the proper form. Note that
8925 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
8926 -- which also produce the address of an entity, do not analyze their
8927 -- prefix because they denote entities that are not necessarily visible.
8928 -- Neither of them can apply to a protected type.
8930 return Ada_Version
>= Ada_2005
8931 and then Is_Entity_Name
(N
)
8932 and then Present
(Entity
(N
))
8933 and then Is_Protected_Type
(Entity
(N
))
8934 and then In_Open_Scopes
(Entity
(N
))
8935 and then not In_Access_Definition
(N
);
8936 end Is_Protected_Self_Reference
;
8938 -----------------------------
8939 -- Is_RCI_Pkg_Spec_Or_Body --
8940 -----------------------------
8942 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
8944 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
8945 -- Return True if the unit of Cunit is an RCI package declaration
8947 ---------------------------
8948 -- Is_RCI_Pkg_Decl_Cunit --
8949 ---------------------------
8951 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
8952 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
8955 if Nkind
(The_Unit
) /= N_Package_Declaration
then
8959 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
8960 end Is_RCI_Pkg_Decl_Cunit
;
8962 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
8965 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
8967 (Nkind
(Unit
(Cunit
)) = N_Package_Body
8968 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
8969 end Is_RCI_Pkg_Spec_Or_Body
;
8971 -----------------------------------------
8972 -- Is_Remote_Access_To_Class_Wide_Type --
8973 -----------------------------------------
8975 function Is_Remote_Access_To_Class_Wide_Type
8976 (E
: Entity_Id
) return Boolean
8979 -- A remote access to class-wide type is a general access to object type
8980 -- declared in the visible part of a Remote_Types or Remote_Call_
8983 return Ekind
(E
) = E_General_Access_Type
8984 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
8985 end Is_Remote_Access_To_Class_Wide_Type
;
8987 -----------------------------------------
8988 -- Is_Remote_Access_To_Subprogram_Type --
8989 -----------------------------------------
8991 function Is_Remote_Access_To_Subprogram_Type
8992 (E
: Entity_Id
) return Boolean
8995 return (Ekind
(E
) = E_Access_Subprogram_Type
8996 or else (Ekind
(E
) = E_Record_Type
8997 and then Present
(Corresponding_Remote_Type
(E
))))
8998 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
8999 end Is_Remote_Access_To_Subprogram_Type
;
9001 --------------------
9002 -- Is_Remote_Call --
9003 --------------------
9005 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
9007 if Nkind
(N
) not in N_Subprogram_Call
then
9009 -- An entry call cannot be remote
9013 elsif Nkind
(Name
(N
)) in N_Has_Entity
9014 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
9016 -- A subprogram declared in the spec of a RCI package is remote
9020 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
9021 and then Is_Remote_Access_To_Subprogram_Type
9022 (Etype
(Prefix
(Name
(N
))))
9024 -- The dereference of a RAS is a remote call
9028 elsif Present
(Controlling_Argument
(N
))
9029 and then Is_Remote_Access_To_Class_Wide_Type
9030 (Etype
(Controlling_Argument
(N
)))
9032 -- Any primitive operation call with a controlling argument of
9033 -- a RACW type is a remote call.
9038 -- All other calls are local calls
9043 ----------------------
9044 -- Is_Renamed_Entry --
9045 ----------------------
9047 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
9048 Orig_Node
: Node_Id
:= Empty
;
9049 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
9051 function Is_Entry
(Nam
: Node_Id
) return Boolean;
9052 -- Determine whether Nam is an entry. Traverse selectors if there are
9053 -- nested selected components.
9059 function Is_Entry
(Nam
: Node_Id
) return Boolean is
9061 if Nkind
(Nam
) = N_Selected_Component
then
9062 return Is_Entry
(Selector_Name
(Nam
));
9065 return Ekind
(Entity
(Nam
)) = E_Entry
;
9068 -- Start of processing for Is_Renamed_Entry
9071 if Present
(Alias
(Proc_Nam
)) then
9072 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
9075 -- Look for a rewritten subprogram renaming declaration
9077 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
9078 and then Present
(Original_Node
(Subp_Decl
))
9080 Orig_Node
:= Original_Node
(Subp_Decl
);
9083 -- The rewritten subprogram is actually an entry
9085 if Present
(Orig_Node
)
9086 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
9087 and then Is_Entry
(Name
(Orig_Node
))
9093 end Is_Renamed_Entry
;
9095 ----------------------------
9096 -- Is_Reversible_Iterator --
9097 ----------------------------
9099 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
9100 Ifaces_List
: Elist_Id
;
9101 Iface_Elmt
: Elmt_Id
;
9105 if Is_Class_Wide_Type
(Typ
)
9106 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
9108 Is_Predefined_File_Name
9109 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
9113 elsif not Is_Tagged_Type
(Typ
)
9114 or else not Is_Derived_Type
(Typ
)
9119 Collect_Interfaces
(Typ
, Ifaces_List
);
9121 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
9122 while Present
(Iface_Elmt
) loop
9123 Iface
:= Node
(Iface_Elmt
);
9124 if Chars
(Iface
) = Name_Reversible_Iterator
9126 Is_Predefined_File_Name
9127 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
9132 Next_Elmt
(Iface_Elmt
);
9137 end Is_Reversible_Iterator
;
9139 ----------------------
9140 -- Is_Selector_Name --
9141 ----------------------
9143 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
9145 if not Is_List_Member
(N
) then
9147 P
: constant Node_Id
:= Parent
(N
);
9148 K
: constant Node_Kind
:= Nkind
(P
);
9151 (K
= N_Expanded_Name
or else
9152 K
= N_Generic_Association
or else
9153 K
= N_Parameter_Association
or else
9154 K
= N_Selected_Component
)
9155 and then Selector_Name
(P
) = N
;
9160 L
: constant List_Id
:= List_Containing
(N
);
9161 P
: constant Node_Id
:= Parent
(L
);
9163 return (Nkind
(P
) = N_Discriminant_Association
9164 and then Selector_Names
(P
) = L
)
9166 (Nkind
(P
) = N_Component_Association
9167 and then Choices
(P
) = L
);
9170 end Is_Selector_Name
;
9172 ----------------------------------
9173 -- Is_SPARK_Initialization_Expr --
9174 ----------------------------------
9176 function Is_SPARK_Initialization_Expr
(N
: Node_Id
) return Boolean is
9179 Comp_Assn
: Node_Id
;
9180 Orig_N
: constant Node_Id
:= Original_Node
(N
);
9185 if not Comes_From_Source
(Orig_N
) then
9189 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
9191 case Nkind
(Orig_N
) is
9192 when N_Character_Literal |
9200 if Is_Entity_Name
(Orig_N
)
9201 and then Present
(Entity
(Orig_N
)) -- needed in some cases
9203 case Ekind
(Entity
(Orig_N
)) is
9205 E_Enumeration_Literal |
9210 if Is_Type
(Entity
(Orig_N
)) then
9218 when N_Qualified_Expression |
9219 N_Type_Conversion
=>
9220 Is_Ok
:= Is_SPARK_Initialization_Expr
(Expression
(Orig_N
));
9223 Is_Ok
:= Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
9227 N_Membership_Test
=>
9228 Is_Ok
:= Is_SPARK_Initialization_Expr
(Left_Opnd
(Orig_N
))
9229 and then Is_SPARK_Initialization_Expr
(Right_Opnd
(Orig_N
));
9232 N_Extension_Aggregate
=>
9233 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
9234 Is_Ok
:= Is_SPARK_Initialization_Expr
(Ancestor_Part
(Orig_N
));
9237 Expr
:= First
(Expressions
(Orig_N
));
9238 while Present
(Expr
) loop
9239 if not Is_SPARK_Initialization_Expr
(Expr
) then
9247 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
9248 while Present
(Comp_Assn
) loop
9249 Expr
:= Expression
(Comp_Assn
);
9250 if Present
(Expr
) -- needed for box association
9251 and then not Is_SPARK_Initialization_Expr
(Expr
)
9260 when N_Attribute_Reference
=>
9261 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
9262 Is_Ok
:= Is_SPARK_Initialization_Expr
(Prefix
(Orig_N
));
9265 Expr
:= First
(Expressions
(Orig_N
));
9266 while Present
(Expr
) loop
9267 if not Is_SPARK_Initialization_Expr
(Expr
) then
9275 -- Selected components might be expanded named not yet resolved, so
9276 -- default on the safe side. (Eg on sparklex.ads)
9278 when N_Selected_Component
=>
9287 end Is_SPARK_Initialization_Expr
;
9289 -------------------------------
9290 -- Is_SPARK_Object_Reference --
9291 -------------------------------
9293 function Is_SPARK_Object_Reference
(N
: Node_Id
) return Boolean is
9295 if Is_Entity_Name
(N
) then
9296 return Present
(Entity
(N
))
9298 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
9299 or else Ekind
(Entity
(N
)) in Formal_Kind
);
9303 when N_Selected_Component
=>
9304 return Is_SPARK_Object_Reference
(Prefix
(N
));
9310 end Is_SPARK_Object_Reference
;
9316 function Is_Statement
(N
: Node_Id
) return Boolean is
9319 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
9320 or else Nkind
(N
) = N_Procedure_Call_Statement
;
9323 --------------------------------------------------
9324 -- Is_Subprogram_Stub_Without_Prior_Declaration --
9325 --------------------------------------------------
9327 function Is_Subprogram_Stub_Without_Prior_Declaration
9328 (N
: Node_Id
) return Boolean
9331 -- A subprogram stub without prior declaration serves as declaration for
9332 -- the actual subprogram body. As such, it has an attached defining
9333 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
9335 return Nkind
(N
) = N_Subprogram_Body_Stub
9336 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
9337 end Is_Subprogram_Stub_Without_Prior_Declaration
;
9339 ---------------------------------
9340 -- Is_Synchronized_Tagged_Type --
9341 ---------------------------------
9343 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
9344 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
9347 -- A task or protected type derived from an interface is a tagged type.
9348 -- Such a tagged type is called a synchronized tagged type, as are
9349 -- synchronized interfaces and private extensions whose declaration
9350 -- includes the reserved word synchronized.
9352 return (Is_Tagged_Type
(E
)
9353 and then (Kind
= E_Task_Type
9354 or else Kind
= E_Protected_Type
))
9357 and then Is_Synchronized_Interface
(E
))
9359 (Ekind
(E
) = E_Record_Type_With_Private
9360 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
9361 and then (Synchronized_Present
(Parent
(E
))
9362 or else Is_Synchronized_Interface
(Etype
(E
))));
9363 end Is_Synchronized_Tagged_Type
;
9369 function Is_Transfer
(N
: Node_Id
) return Boolean is
9370 Kind
: constant Node_Kind
:= Nkind
(N
);
9373 if Kind
= N_Simple_Return_Statement
9375 Kind
= N_Extended_Return_Statement
9377 Kind
= N_Goto_Statement
9379 Kind
= N_Raise_Statement
9381 Kind
= N_Requeue_Statement
9385 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
9386 and then No
(Condition
(N
))
9390 elsif Kind
= N_Procedure_Call_Statement
9391 and then Is_Entity_Name
(Name
(N
))
9392 and then Present
(Entity
(Name
(N
)))
9393 and then No_Return
(Entity
(Name
(N
)))
9397 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
9409 function Is_True
(U
: Uint
) return Boolean is
9414 -------------------------------
9415 -- Is_Universal_Numeric_Type --
9416 -------------------------------
9418 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
9420 return T
= Universal_Integer
or else T
= Universal_Real
;
9421 end Is_Universal_Numeric_Type
;
9427 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
9429 return VM_Target
= CLI_Target
9430 and then Nkind
(T
) in N_Has_Chars
9431 and then Chars
(T
) /= No_Name
9432 and then Get_Name_String
(Chars
(T
)) = "valuetype";
9435 ---------------------
9436 -- Is_VMS_Operator --
9437 ---------------------
9439 function Is_VMS_Operator
(Op
: Entity_Id
) return Boolean is
9441 -- The VMS operators are declared in a child of System that is loaded
9442 -- through pragma Extend_System. In some rare cases a program is run
9443 -- with this extension but without indicating that the target is VMS.
9445 return Ekind
(Op
) = E_Function
9446 and then Is_Intrinsic_Subprogram
(Op
)
9448 ((Present_System_Aux
9449 and then Scope
(Op
) = System_Aux_Id
)
9452 and then Scope
(Scope
(Op
)) = RTU_Entity
(System
)));
9453 end Is_VMS_Operator
;
9459 function Is_Variable
9461 Use_Original_Node
: Boolean := True) return Boolean
9463 Orig_Node
: Node_Id
;
9465 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
9466 -- Within a protected function, the private components of the enclosing
9467 -- protected type are constants. A function nested within a (protected)
9468 -- procedure is not itself protected.
9470 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
9471 -- Prefixes can involve implicit dereferences, in which case we must
9472 -- test for the case of a reference of a constant access type, which can
9473 -- can never be a variable.
9475 ---------------------------
9476 -- In_Protected_Function --
9477 ---------------------------
9479 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
9480 Prot
: constant Entity_Id
:= Scope
(E
);
9484 if not Is_Protected_Type
(Prot
) then
9488 while Present
(S
) and then S
/= Prot
loop
9489 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
9498 end In_Protected_Function
;
9500 ------------------------
9501 -- Is_Variable_Prefix --
9502 ------------------------
9504 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
9506 if Is_Access_Type
(Etype
(P
)) then
9507 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
9509 -- For the case of an indexed component whose prefix has a packed
9510 -- array type, the prefix has been rewritten into a type conversion.
9511 -- Determine variable-ness from the converted expression.
9513 elsif Nkind
(P
) = N_Type_Conversion
9514 and then not Comes_From_Source
(P
)
9515 and then Is_Array_Type
(Etype
(P
))
9516 and then Is_Packed
(Etype
(P
))
9518 return Is_Variable
(Expression
(P
));
9521 return Is_Variable
(P
);
9523 end Is_Variable_Prefix
;
9525 -- Start of processing for Is_Variable
9528 -- Check if we perform the test on the original node since this may be a
9529 -- test of syntactic categories which must not be disturbed by whatever
9530 -- rewriting might have occurred. For example, an aggregate, which is
9531 -- certainly NOT a variable, could be turned into a variable by
9534 if Use_Original_Node
then
9535 Orig_Node
:= Original_Node
(N
);
9540 -- Definitely OK if Assignment_OK is set. Since this is something that
9541 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
9543 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
9546 -- Normally we go to the original node, but there is one exception where
9547 -- we use the rewritten node, namely when it is an explicit dereference.
9548 -- The generated code may rewrite a prefix which is an access type with
9549 -- an explicit dereference. The dereference is a variable, even though
9550 -- the original node may not be (since it could be a constant of the
9553 -- In Ada 2005 we have a further case to consider: the prefix may be a
9554 -- function call given in prefix notation. The original node appears to
9555 -- be a selected component, but we need to examine the call.
9557 elsif Nkind
(N
) = N_Explicit_Dereference
9558 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
9559 and then Present
(Etype
(Orig_Node
))
9560 and then Is_Access_Type
(Etype
(Orig_Node
))
9562 -- Note that if the prefix is an explicit dereference that does not
9563 -- come from source, we must check for a rewritten function call in
9564 -- prefixed notation before other forms of rewriting, to prevent a
9568 (Nkind
(Orig_Node
) = N_Function_Call
9569 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
9571 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
9573 -- in Ada 2012, the dereference may have been added for a type with
9574 -- a declared implicit dereference aspect.
9576 elsif Nkind
(N
) = N_Explicit_Dereference
9577 and then Present
(Etype
(Orig_Node
))
9578 and then Ada_Version
>= Ada_2012
9579 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
9583 -- A function call is never a variable
9585 elsif Nkind
(N
) = N_Function_Call
then
9588 -- All remaining checks use the original node
9590 elsif Is_Entity_Name
(Orig_Node
)
9591 and then Present
(Entity
(Orig_Node
))
9594 E
: constant Entity_Id
:= Entity
(Orig_Node
);
9595 K
: constant Entity_Kind
:= Ekind
(E
);
9598 return (K
= E_Variable
9599 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
9600 or else (K
= E_Component
9601 and then not In_Protected_Function
(E
))
9602 or else K
= E_Out_Parameter
9603 or else K
= E_In_Out_Parameter
9604 or else K
= E_Generic_In_Out_Parameter
9606 -- Current instance of type
9608 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
9609 or else (Is_Incomplete_Or_Private_Type
(E
)
9610 and then In_Open_Scopes
(Full_View
(E
)));
9614 case Nkind
(Orig_Node
) is
9615 when N_Indexed_Component | N_Slice
=>
9616 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
9618 when N_Selected_Component
=>
9619 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
9620 and then Is_Variable
(Selector_Name
(Orig_Node
));
9622 -- For an explicit dereference, the type of the prefix cannot
9623 -- be an access to constant or an access to subprogram.
9625 when N_Explicit_Dereference
=>
9627 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
9629 return Is_Access_Type
(Typ
)
9630 and then not Is_Access_Constant
(Root_Type
(Typ
))
9631 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
9634 -- The type conversion is the case where we do not deal with the
9635 -- context dependent special case of an actual parameter. Thus
9636 -- the type conversion is only considered a variable for the
9637 -- purposes of this routine if the target type is tagged. However,
9638 -- a type conversion is considered to be a variable if it does not
9639 -- come from source (this deals for example with the conversions
9640 -- of expressions to their actual subtypes).
9642 when N_Type_Conversion
=>
9643 return Is_Variable
(Expression
(Orig_Node
))
9645 (not Comes_From_Source
(Orig_Node
)
9647 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
9649 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
9651 -- GNAT allows an unchecked type conversion as a variable. This
9652 -- only affects the generation of internal expanded code, since
9653 -- calls to instantiations of Unchecked_Conversion are never
9654 -- considered variables (since they are function calls).
9656 when N_Unchecked_Type_Conversion
=>
9657 return Is_Variable
(Expression
(Orig_Node
));
9665 ---------------------------
9666 -- Is_Visibly_Controlled --
9667 ---------------------------
9669 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
9670 Root
: constant Entity_Id
:= Root_Type
(T
);
9672 return Chars
(Scope
(Root
)) = Name_Finalization
9673 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
9674 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
9675 end Is_Visibly_Controlled
;
9677 ------------------------
9678 -- Is_Volatile_Object --
9679 ------------------------
9681 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
9683 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
9684 -- Determines if given object has volatile components
9686 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
9687 -- If prefix is an implicit dereference, examine designated type
9689 ------------------------
9690 -- Is_Volatile_Prefix --
9691 ------------------------
9693 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
9694 Typ
: constant Entity_Id
:= Etype
(N
);
9697 if Is_Access_Type
(Typ
) then
9699 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
9702 return Is_Volatile
(Dtyp
)
9703 or else Has_Volatile_Components
(Dtyp
);
9707 return Object_Has_Volatile_Components
(N
);
9709 end Is_Volatile_Prefix
;
9711 ------------------------------------
9712 -- Object_Has_Volatile_Components --
9713 ------------------------------------
9715 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
9716 Typ
: constant Entity_Id
:= Etype
(N
);
9719 if Is_Volatile
(Typ
)
9720 or else Has_Volatile_Components
(Typ
)
9724 elsif Is_Entity_Name
(N
)
9725 and then (Has_Volatile_Components
(Entity
(N
))
9726 or else Is_Volatile
(Entity
(N
)))
9730 elsif Nkind
(N
) = N_Indexed_Component
9731 or else Nkind
(N
) = N_Selected_Component
9733 return Is_Volatile_Prefix
(Prefix
(N
));
9738 end Object_Has_Volatile_Components
;
9740 -- Start of processing for Is_Volatile_Object
9743 if Is_Volatile
(Etype
(N
))
9744 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
9748 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
9749 and then Is_Volatile_Prefix
(Prefix
(N
))
9753 elsif Nkind
(N
) = N_Selected_Component
9754 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
9761 end Is_Volatile_Object
;
9763 ---------------------------
9764 -- Itype_Has_Declaration --
9765 ---------------------------
9767 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
9769 pragma Assert
(Is_Itype
(Id
));
9770 return Present
(Parent
(Id
))
9771 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
9772 N_Subtype_Declaration
)
9773 and then Defining_Entity
(Parent
(Id
)) = Id
;
9774 end Itype_Has_Declaration
;
9776 -------------------------
9777 -- Kill_Current_Values --
9778 -------------------------
9780 procedure Kill_Current_Values
9782 Last_Assignment_Only
: Boolean := False)
9785 -- ??? do we have to worry about clearing cached checks?
9787 if Is_Assignable
(Ent
) then
9788 Set_Last_Assignment
(Ent
, Empty
);
9791 if Is_Object
(Ent
) then
9792 if not Last_Assignment_Only
then
9794 Set_Current_Value
(Ent
, Empty
);
9796 if not Can_Never_Be_Null
(Ent
) then
9797 Set_Is_Known_Non_Null
(Ent
, False);
9800 Set_Is_Known_Null
(Ent
, False);
9802 -- Reset Is_Known_Valid unless type is always valid, or if we have
9803 -- a loop parameter (loop parameters are always valid, since their
9804 -- bounds are defined by the bounds given in the loop header).
9806 if not Is_Known_Valid
(Etype
(Ent
))
9807 and then Ekind
(Ent
) /= E_Loop_Parameter
9809 Set_Is_Known_Valid
(Ent
, False);
9813 end Kill_Current_Values
;
9815 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
9818 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
9819 -- Clear current value for entity E and all entities chained to E
9821 ------------------------------------------
9822 -- Kill_Current_Values_For_Entity_Chain --
9823 ------------------------------------------
9825 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
9829 while Present
(Ent
) loop
9830 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
9833 end Kill_Current_Values_For_Entity_Chain
;
9835 -- Start of processing for Kill_Current_Values
9838 -- Kill all saved checks, a special case of killing saved values
9840 if not Last_Assignment_Only
then
9844 -- Loop through relevant scopes, which includes the current scope and
9845 -- any parent scopes if the current scope is a block or a package.
9850 -- Clear current values of all entities in current scope
9852 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
9854 -- If scope is a package, also clear current values of all private
9855 -- entities in the scope.
9857 if Is_Package_Or_Generic_Package
(S
)
9858 or else Is_Concurrent_Type
(S
)
9860 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
9863 -- If this is a not a subprogram, deal with parents
9865 if not Is_Subprogram
(S
) then
9867 exit Scope_Loop
when S
= Standard_Standard
;
9871 end loop Scope_Loop
;
9872 end Kill_Current_Values
;
9874 --------------------------
9875 -- Kill_Size_Check_Code --
9876 --------------------------
9878 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
9880 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
9881 and then Present
(Size_Check_Code
(E
))
9883 Remove
(Size_Check_Code
(E
));
9884 Set_Size_Check_Code
(E
, Empty
);
9886 end Kill_Size_Check_Code
;
9888 --------------------------
9889 -- Known_To_Be_Assigned --
9890 --------------------------
9892 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
9893 P
: constant Node_Id
:= Parent
(N
);
9898 -- Test left side of assignment
9900 when N_Assignment_Statement
=>
9901 return N
= Name
(P
);
9903 -- Function call arguments are never lvalues
9905 when N_Function_Call
=>
9908 -- Positional parameter for procedure or accept call
9910 when N_Procedure_Call_Statement |
9919 Proc
:= Get_Subprogram_Entity
(P
);
9925 -- If we are not a list member, something is strange, so
9926 -- be conservative and return False.
9928 if not Is_List_Member
(N
) then
9932 -- We are going to find the right formal by stepping forward
9933 -- through the formals, as we step backwards in the actuals.
9935 Form
:= First_Formal
(Proc
);
9938 -- If no formal, something is weird, so be conservative
9939 -- and return False.
9950 return Ekind
(Form
) /= E_In_Parameter
;
9953 -- Named parameter for procedure or accept call
9955 when N_Parameter_Association
=>
9961 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
9967 -- Loop through formals to find the one that matches
9969 Form
:= First_Formal
(Proc
);
9971 -- If no matching formal, that's peculiar, some kind of
9972 -- previous error, so return False to be conservative.
9973 -- Actually this also happens in legal code in the case
9974 -- where P is a parameter association for an Extra_Formal???
9980 -- Else test for match
9982 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
9983 return Ekind
(Form
) /= E_In_Parameter
;
9990 -- Test for appearing in a conversion that itself appears
9991 -- in an lvalue context, since this should be an lvalue.
9993 when N_Type_Conversion
=>
9994 return Known_To_Be_Assigned
(P
);
9996 -- All other references are definitely not known to be modifications
10002 end Known_To_Be_Assigned
;
10004 ---------------------------
10005 -- Last_Source_Statement --
10006 ---------------------------
10008 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
10012 N
:= Last
(Statements
(HSS
));
10013 while Present
(N
) loop
10014 exit when Comes_From_Source
(N
);
10019 end Last_Source_Statement
;
10021 ----------------------------------
10022 -- Matching_Static_Array_Bounds --
10023 ----------------------------------
10025 function Matching_Static_Array_Bounds
10027 R_Typ
: Node_Id
) return Boolean
10029 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
10030 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
10042 if L_Ndims
/= R_Ndims
then
10046 -- Unconstrained types do not have static bounds
10048 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
10052 -- First treat specially the first dimension, as the lower bound and
10053 -- length of string literals are not stored like those of arrays.
10055 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
10056 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
10057 L_Len
:= String_Literal_Length
(L_Typ
);
10059 L_Index
:= First_Index
(L_Typ
);
10060 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
10062 if Is_OK_Static_Expression
(L_Low
)
10063 and then Is_OK_Static_Expression
(L_High
)
10065 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
10068 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
10075 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
10076 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
10077 R_Len
:= String_Literal_Length
(R_Typ
);
10079 R_Index
:= First_Index
(R_Typ
);
10080 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
10082 if Is_OK_Static_Expression
(R_Low
)
10083 and then Is_OK_Static_Expression
(R_High
)
10085 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
10088 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
10095 if Is_OK_Static_Expression
(L_Low
)
10096 and then Is_OK_Static_Expression
(R_Low
)
10097 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
10098 and then L_Len
= R_Len
10105 -- Then treat all other dimensions
10107 for Indx
in 2 .. L_Ndims
loop
10111 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
10112 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
10114 if Is_OK_Static_Expression
(L_Low
)
10115 and then Is_OK_Static_Expression
(L_High
)
10116 and then Is_OK_Static_Expression
(R_Low
)
10117 and then Is_OK_Static_Expression
(R_High
)
10118 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
10119 and then Expr_Value
(L_High
) = Expr_Value
(R_High
)
10127 -- If we fall through the loop, all indexes matched
10130 end Matching_Static_Array_Bounds
;
10132 -------------------
10133 -- May_Be_Lvalue --
10134 -------------------
10136 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
10137 P
: constant Node_Id
:= Parent
(N
);
10142 -- Test left side of assignment
10144 when N_Assignment_Statement
=>
10145 return N
= Name
(P
);
10147 -- Test prefix of component or attribute. Note that the prefix of an
10148 -- explicit or implicit dereference cannot be an l-value.
10150 when N_Attribute_Reference
=>
10151 return N
= Prefix
(P
)
10152 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
10154 -- For an expanded name, the name is an lvalue if the expanded name
10155 -- is an lvalue, but the prefix is never an lvalue, since it is just
10156 -- the scope where the name is found.
10158 when N_Expanded_Name
=>
10159 if N
= Prefix
(P
) then
10160 return May_Be_Lvalue
(P
);
10165 -- For a selected component A.B, A is certainly an lvalue if A.B is.
10166 -- B is a little interesting, if we have A.B := 3, there is some
10167 -- discussion as to whether B is an lvalue or not, we choose to say
10168 -- it is. Note however that A is not an lvalue if it is of an access
10169 -- type since this is an implicit dereference.
10171 when N_Selected_Component
=>
10173 and then Present
(Etype
(N
))
10174 and then Is_Access_Type
(Etype
(N
))
10178 return May_Be_Lvalue
(P
);
10181 -- For an indexed component or slice, the index or slice bounds is
10182 -- never an lvalue. The prefix is an lvalue if the indexed component
10183 -- or slice is an lvalue, except if it is an access type, where we
10184 -- have an implicit dereference.
10186 when N_Indexed_Component | N_Slice
=>
10188 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
10192 return May_Be_Lvalue
(P
);
10195 -- Prefix of a reference is an lvalue if the reference is an lvalue
10197 when N_Reference
=>
10198 return May_Be_Lvalue
(P
);
10200 -- Prefix of explicit dereference is never an lvalue
10202 when N_Explicit_Dereference
=>
10205 -- Positional parameter for subprogram, entry, or accept call.
10206 -- In older versions of Ada function call arguments are never
10207 -- lvalues. In Ada 2012 functions can have in-out parameters.
10209 when N_Subprogram_Call |
10210 N_Entry_Call_Statement |
10213 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
10217 -- The following mechanism is clumsy and fragile. A single flag
10218 -- set in Resolve_Actuals would be preferable ???
10226 Proc
:= Get_Subprogram_Entity
(P
);
10232 -- If we are not a list member, something is strange, so be
10233 -- conservative and return True.
10235 if not Is_List_Member
(N
) then
10239 -- We are going to find the right formal by stepping forward
10240 -- through the formals, as we step backwards in the actuals.
10242 Form
:= First_Formal
(Proc
);
10245 -- If no formal, something is weird, so be conservative and
10253 exit when No
(Act
);
10254 Next_Formal
(Form
);
10257 return Ekind
(Form
) /= E_In_Parameter
;
10260 -- Named parameter for procedure or accept call
10262 when N_Parameter_Association
=>
10268 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
10274 -- Loop through formals to find the one that matches
10276 Form
:= First_Formal
(Proc
);
10278 -- If no matching formal, that's peculiar, some kind of
10279 -- previous error, so return True to be conservative.
10280 -- Actually happens with legal code for an unresolved call
10281 -- where we may get the wrong homonym???
10287 -- Else test for match
10289 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
10290 return Ekind
(Form
) /= E_In_Parameter
;
10293 Next_Formal
(Form
);
10297 -- Test for appearing in a conversion that itself appears in an
10298 -- lvalue context, since this should be an lvalue.
10300 when N_Type_Conversion
=>
10301 return May_Be_Lvalue
(P
);
10303 -- Test for appearance in object renaming declaration
10305 when N_Object_Renaming_Declaration
=>
10308 -- All other references are definitely not lvalues
10316 -----------------------
10317 -- Mark_Coextensions --
10318 -----------------------
10320 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
10321 Is_Dynamic
: Boolean;
10322 -- Indicates whether the context causes nested coextensions to be
10323 -- dynamic or static
10325 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
10326 -- Recognize an allocator node and label it as a dynamic coextension
10328 --------------------
10329 -- Mark_Allocator --
10330 --------------------
10332 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
10334 if Nkind
(N
) = N_Allocator
then
10336 Set_Is_Dynamic_Coextension
(N
);
10338 -- If the allocator expression is potentially dynamic, it may
10339 -- be expanded out of order and require dynamic allocation
10340 -- anyway, so we treat the coextension itself as dynamic.
10341 -- Potential optimization ???
10343 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
10344 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
10346 Set_Is_Dynamic_Coextension
(N
);
10348 Set_Is_Static_Coextension
(N
);
10353 end Mark_Allocator
;
10355 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
10357 -- Start of processing Mark_Coextensions
10360 case Nkind
(Context_Nod
) is
10362 -- Comment here ???
10364 when N_Assignment_Statement
=>
10365 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
10367 -- An allocator that is a component of a returned aggregate
10368 -- must be dynamic.
10370 when N_Simple_Return_Statement
=>
10372 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
10375 Nkind
(Expr
) = N_Allocator
10377 (Nkind
(Expr
) = N_Qualified_Expression
10378 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
10381 -- An alloctor within an object declaration in an extended return
10382 -- statement is of necessity dynamic.
10384 when N_Object_Declaration
=>
10385 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
10387 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
10389 -- This routine should not be called for constructs which may not
10390 -- contain coextensions.
10393 raise Program_Error
;
10396 Mark_Allocators
(Root_Nod
);
10397 end Mark_Coextensions
;
10403 function Must_Inline
(Subp
: Entity_Id
) return Boolean is
10406 (Optimization_Level
= 0
10408 -- AAMP and VM targets have no support for inlining in the backend.
10409 -- Hence we do as much inlining as possible in the front end.
10411 or else AAMP_On_Target
10412 or else VM_Target
/= No_VM
)
10413 and then Has_Pragma_Inline
(Subp
)
10414 and then (Has_Pragma_Inline_Always
(Subp
) or else Front_End_Inlining
);
10417 ----------------------
10418 -- Needs_One_Actual --
10419 ----------------------
10421 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
10422 Formal
: Entity_Id
;
10425 -- Ada 2005 or later, and formals present
10427 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
10428 Formal
:= Next_Formal
(First_Formal
(E
));
10429 while Present
(Formal
) loop
10430 if No
(Default_Value
(Formal
)) then
10434 Next_Formal
(Formal
);
10439 -- Ada 83/95 or no formals
10444 end Needs_One_Actual
;
10446 ------------------------
10447 -- New_Copy_List_Tree --
10448 ------------------------
10450 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
10455 if List
= No_List
then
10462 while Present
(E
) loop
10463 Append
(New_Copy_Tree
(E
), NL
);
10469 end New_Copy_List_Tree
;
10471 -------------------
10472 -- New_Copy_Tree --
10473 -------------------
10475 use Atree
.Unchecked_Access
;
10476 use Atree_Private_Part
;
10478 -- Our approach here requires a two pass traversal of the tree. The
10479 -- first pass visits all nodes that eventually will be copied looking
10480 -- for defining Itypes. If any defining Itypes are found, then they are
10481 -- copied, and an entry is added to the replacement map. In the second
10482 -- phase, the tree is copied, using the replacement map to replace any
10483 -- Itype references within the copied tree.
10485 -- The following hash tables are used if the Map supplied has more
10486 -- than hash threshold entries to speed up access to the map. If
10487 -- there are fewer entries, then the map is searched sequentially
10488 -- (because setting up a hash table for only a few entries takes
10489 -- more time than it saves.
10491 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
10492 -- Hash function used for hash operations
10494 -------------------
10495 -- New_Copy_Hash --
10496 -------------------
10498 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
10500 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
10507 -- The hash table NCT_Assoc associates old entities in the table
10508 -- with their corresponding new entities (i.e. the pairs of entries
10509 -- presented in the original Map argument are Key-Element pairs).
10511 package NCT_Assoc
is new Simple_HTable
(
10512 Header_Num
=> NCT_Header_Num
,
10513 Element
=> Entity_Id
,
10514 No_Element
=> Empty
,
10516 Hash
=> New_Copy_Hash
,
10517 Equal
=> Types
."=");
10519 ---------------------
10520 -- NCT_Itype_Assoc --
10521 ---------------------
10523 -- The hash table NCT_Itype_Assoc contains entries only for those
10524 -- old nodes which have a non-empty Associated_Node_For_Itype set.
10525 -- The key is the associated node, and the element is the new node
10526 -- itself (NOT the associated node for the new node).
10528 package NCT_Itype_Assoc
is new Simple_HTable
(
10529 Header_Num
=> NCT_Header_Num
,
10530 Element
=> Entity_Id
,
10531 No_Element
=> Empty
,
10533 Hash
=> New_Copy_Hash
,
10534 Equal
=> Types
."=");
10536 -- Start of processing for New_Copy_Tree function
10538 function New_Copy_Tree
10540 Map
: Elist_Id
:= No_Elist
;
10541 New_Sloc
: Source_Ptr
:= No_Location
;
10542 New_Scope
: Entity_Id
:= Empty
) return Node_Id
10544 Actual_Map
: Elist_Id
:= Map
;
10545 -- This is the actual map for the copy. It is initialized with the
10546 -- given elements, and then enlarged as required for Itypes that are
10547 -- copied during the first phase of the copy operation. The visit
10548 -- procedures add elements to this map as Itypes are encountered.
10549 -- The reason we cannot use Map directly, is that it may well be
10550 -- (and normally is) initialized to No_Elist, and if we have mapped
10551 -- entities, we have to reset it to point to a real Elist.
10553 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
10554 -- Called during second phase to map entities into their corresponding
10555 -- copies using Actual_Map. If the argument is not an entity, or is not
10556 -- in Actual_Map, then it is returned unchanged.
10558 procedure Build_NCT_Hash_Tables
;
10559 -- Builds hash tables (number of elements >= threshold value)
10561 function Copy_Elist_With_Replacement
10562 (Old_Elist
: Elist_Id
) return Elist_Id
;
10563 -- Called during second phase to copy element list doing replacements
10565 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
10566 -- Called during the second phase to process a copied Itype. The actual
10567 -- copy happened during the first phase (so that we could make the entry
10568 -- in the mapping), but we still have to deal with the descendents of
10569 -- the copied Itype and copy them where necessary.
10571 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
10572 -- Called during second phase to copy list doing replacements
10574 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
10575 -- Called during second phase to copy node doing replacements
10577 procedure Visit_Elist
(E
: Elist_Id
);
10578 -- Called during first phase to visit all elements of an Elist
10580 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
10581 -- Visit a single field, recursing to call Visit_Node or Visit_List
10582 -- if the field is a syntactic descendent of the current node (i.e.
10583 -- its parent is Node N).
10585 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
10586 -- Called during first phase to visit subsidiary fields of a defining
10587 -- Itype, and also create a copy and make an entry in the replacement
10588 -- map for the new copy.
10590 procedure Visit_List
(L
: List_Id
);
10591 -- Called during first phase to visit all elements of a List
10593 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
10594 -- Called during first phase to visit a node and all its subtrees
10600 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
10605 if not Has_Extension
(N
) or else No
(Actual_Map
) then
10608 elsif NCT_Hash_Tables_Used
then
10609 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
10611 if Present
(Ent
) then
10617 -- No hash table used, do serial search
10620 E
:= First_Elmt
(Actual_Map
);
10621 while Present
(E
) loop
10622 if Node
(E
) = N
then
10623 return Node
(Next_Elmt
(E
));
10625 E
:= Next_Elmt
(Next_Elmt
(E
));
10633 ---------------------------
10634 -- Build_NCT_Hash_Tables --
10635 ---------------------------
10637 procedure Build_NCT_Hash_Tables
is
10641 if NCT_Hash_Table_Setup
then
10643 NCT_Itype_Assoc
.Reset
;
10646 Elmt
:= First_Elmt
(Actual_Map
);
10647 while Present
(Elmt
) loop
10648 Ent
:= Node
(Elmt
);
10650 -- Get new entity, and associate old and new
10653 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
10655 if Is_Type
(Ent
) then
10657 Anode
: constant Entity_Id
:=
10658 Associated_Node_For_Itype
(Ent
);
10661 if Present
(Anode
) then
10663 -- Enter a link between the associated node of the
10664 -- old Itype and the new Itype, for updating later
10665 -- when node is copied.
10667 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
10675 NCT_Hash_Tables_Used
:= True;
10676 NCT_Hash_Table_Setup
:= True;
10677 end Build_NCT_Hash_Tables
;
10679 ---------------------------------
10680 -- Copy_Elist_With_Replacement --
10681 ---------------------------------
10683 function Copy_Elist_With_Replacement
10684 (Old_Elist
: Elist_Id
) return Elist_Id
10687 New_Elist
: Elist_Id
;
10690 if No
(Old_Elist
) then
10694 New_Elist
:= New_Elmt_List
;
10696 M
:= First_Elmt
(Old_Elist
);
10697 while Present
(M
) loop
10698 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
10704 end Copy_Elist_With_Replacement
;
10706 ---------------------------------
10707 -- Copy_Itype_With_Replacement --
10708 ---------------------------------
10710 -- This routine exactly parallels its phase one analog Visit_Itype,
10712 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
10714 -- Translate Next_Entity, Scope and Etype fields, in case they
10715 -- reference entities that have been mapped into copies.
10717 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
10718 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
10720 if Present
(New_Scope
) then
10721 Set_Scope
(New_Itype
, New_Scope
);
10723 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
10726 -- Copy referenced fields
10728 if Is_Discrete_Type
(New_Itype
) then
10729 Set_Scalar_Range
(New_Itype
,
10730 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
10732 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
10733 Set_Discriminant_Constraint
(New_Itype
,
10734 Copy_Elist_With_Replacement
10735 (Discriminant_Constraint
(New_Itype
)));
10737 elsif Is_Array_Type
(New_Itype
) then
10738 if Present
(First_Index
(New_Itype
)) then
10739 Set_First_Index
(New_Itype
,
10740 First
(Copy_List_With_Replacement
10741 (List_Containing
(First_Index
(New_Itype
)))));
10744 if Is_Packed
(New_Itype
) then
10745 Set_Packed_Array_Type
(New_Itype
,
10746 Copy_Node_With_Replacement
10747 (Packed_Array_Type
(New_Itype
)));
10750 end Copy_Itype_With_Replacement
;
10752 --------------------------------
10753 -- Copy_List_With_Replacement --
10754 --------------------------------
10756 function Copy_List_With_Replacement
10757 (Old_List
: List_Id
) return List_Id
10759 New_List
: List_Id
;
10763 if Old_List
= No_List
then
10767 New_List
:= Empty_List
;
10769 E
:= First
(Old_List
);
10770 while Present
(E
) loop
10771 Append
(Copy_Node_With_Replacement
(E
), New_List
);
10777 end Copy_List_With_Replacement
;
10779 --------------------------------
10780 -- Copy_Node_With_Replacement --
10781 --------------------------------
10783 function Copy_Node_With_Replacement
10784 (Old_Node
: Node_Id
) return Node_Id
10786 New_Node
: Node_Id
;
10788 procedure Adjust_Named_Associations
10789 (Old_Node
: Node_Id
;
10790 New_Node
: Node_Id
);
10791 -- If a call node has named associations, these are chained through
10792 -- the First_Named_Actual, Next_Named_Actual links. These must be
10793 -- propagated separately to the new parameter list, because these
10794 -- are not syntactic fields.
10796 function Copy_Field_With_Replacement
10797 (Field
: Union_Id
) return Union_Id
;
10798 -- Given Field, which is a field of Old_Node, return a copy of it
10799 -- if it is a syntactic field (i.e. its parent is Node), setting
10800 -- the parent of the copy to poit to New_Node. Otherwise returns
10801 -- the field (possibly mapped if it is an entity).
10803 -------------------------------
10804 -- Adjust_Named_Associations --
10805 -------------------------------
10807 procedure Adjust_Named_Associations
10808 (Old_Node
: Node_Id
;
10809 New_Node
: Node_Id
)
10814 Old_Next
: Node_Id
;
10815 New_Next
: Node_Id
;
10818 Old_E
:= First
(Parameter_Associations
(Old_Node
));
10819 New_E
:= First
(Parameter_Associations
(New_Node
));
10820 while Present
(Old_E
) loop
10821 if Nkind
(Old_E
) = N_Parameter_Association
10822 and then Present
(Next_Named_Actual
(Old_E
))
10824 if First_Named_Actual
(Old_Node
)
10825 = Explicit_Actual_Parameter
(Old_E
)
10827 Set_First_Named_Actual
10828 (New_Node
, Explicit_Actual_Parameter
(New_E
));
10831 -- Now scan parameter list from the beginning,to locate
10832 -- next named actual, which can be out of order.
10834 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
10835 New_Next
:= First
(Parameter_Associations
(New_Node
));
10837 while Nkind
(Old_Next
) /= N_Parameter_Association
10838 or else Explicit_Actual_Parameter
(Old_Next
)
10839 /= Next_Named_Actual
(Old_E
)
10845 Set_Next_Named_Actual
10846 (New_E
, Explicit_Actual_Parameter
(New_Next
));
10852 end Adjust_Named_Associations
;
10854 ---------------------------------
10855 -- Copy_Field_With_Replacement --
10856 ---------------------------------
10858 function Copy_Field_With_Replacement
10859 (Field
: Union_Id
) return Union_Id
10862 if Field
= Union_Id
(Empty
) then
10865 elsif Field
in Node_Range
then
10867 Old_N
: constant Node_Id
:= Node_Id
(Field
);
10871 -- If syntactic field, as indicated by the parent pointer
10872 -- being set, then copy the referenced node recursively.
10874 if Parent
(Old_N
) = Old_Node
then
10875 New_N
:= Copy_Node_With_Replacement
(Old_N
);
10877 if New_N
/= Old_N
then
10878 Set_Parent
(New_N
, New_Node
);
10881 -- For semantic fields, update possible entity reference
10882 -- from the replacement map.
10885 New_N
:= Assoc
(Old_N
);
10888 return Union_Id
(New_N
);
10891 elsif Field
in List_Range
then
10893 Old_L
: constant List_Id
:= List_Id
(Field
);
10897 -- If syntactic field, as indicated by the parent pointer,
10898 -- then recursively copy the entire referenced list.
10900 if Parent
(Old_L
) = Old_Node
then
10901 New_L
:= Copy_List_With_Replacement
(Old_L
);
10902 Set_Parent
(New_L
, New_Node
);
10904 -- For semantic list, just returned unchanged
10910 return Union_Id
(New_L
);
10913 -- Anything other than a list or a node is returned unchanged
10918 end Copy_Field_With_Replacement
;
10920 -- Start of processing for Copy_Node_With_Replacement
10923 if Old_Node
<= Empty_Or_Error
then
10926 elsif Has_Extension
(Old_Node
) then
10927 return Assoc
(Old_Node
);
10930 New_Node
:= New_Copy
(Old_Node
);
10932 -- If the node we are copying is the associated node of a
10933 -- previously copied Itype, then adjust the associated node
10934 -- of the copy of that Itype accordingly.
10936 if Present
(Actual_Map
) then
10942 -- Case of hash table used
10944 if NCT_Hash_Tables_Used
then
10945 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
10947 if Present
(Ent
) then
10948 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
10951 -- Case of no hash table used
10954 E
:= First_Elmt
(Actual_Map
);
10955 while Present
(E
) loop
10956 if Is_Itype
(Node
(E
))
10958 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
10960 Set_Associated_Node_For_Itype
10961 (Node
(Next_Elmt
(E
)), New_Node
);
10964 E
:= Next_Elmt
(Next_Elmt
(E
));
10970 -- Recursively copy descendents
10973 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
10975 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
10977 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
10979 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
10981 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
10983 -- Adjust Sloc of new node if necessary
10985 if New_Sloc
/= No_Location
then
10986 Set_Sloc
(New_Node
, New_Sloc
);
10988 -- If we adjust the Sloc, then we are essentially making
10989 -- a completely new node, so the Comes_From_Source flag
10990 -- should be reset to the proper default value.
10992 Nodes
.Table
(New_Node
).Comes_From_Source
:=
10993 Default_Node
.Comes_From_Source
;
10996 -- If the node is call and has named associations,
10997 -- set the corresponding links in the copy.
10999 if (Nkind
(Old_Node
) = N_Function_Call
11000 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
11002 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
11003 and then Present
(First_Named_Actual
(Old_Node
))
11005 Adjust_Named_Associations
(Old_Node
, New_Node
);
11008 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
11009 -- The replacement mechanism applies to entities, and is not used
11010 -- here. Eventually we may need a more general graph-copying
11011 -- routine. For now, do a sequential search to find desired node.
11013 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
11014 and then Present
(First_Real_Statement
(Old_Node
))
11017 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
11021 N1
:= First
(Statements
(Old_Node
));
11022 N2
:= First
(Statements
(New_Node
));
11024 while N1
/= Old_F
loop
11029 Set_First_Real_Statement
(New_Node
, N2
);
11034 -- All done, return copied node
11037 end Copy_Node_With_Replacement
;
11043 procedure Visit_Elist
(E
: Elist_Id
) is
11046 if Present
(E
) then
11047 Elmt
:= First_Elmt
(E
);
11049 while Elmt
/= No_Elmt
loop
11050 Visit_Node
(Node
(Elmt
));
11060 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
11062 if F
= Union_Id
(Empty
) then
11065 elsif F
in Node_Range
then
11067 -- Copy node if it is syntactic, i.e. its parent pointer is
11068 -- set to point to the field that referenced it (certain
11069 -- Itypes will also meet this criterion, which is fine, since
11070 -- these are clearly Itypes that do need to be copied, since
11071 -- we are copying their parent.)
11073 if Parent
(Node_Id
(F
)) = N
then
11074 Visit_Node
(Node_Id
(F
));
11077 -- Another case, if we are pointing to an Itype, then we want
11078 -- to copy it if its associated node is somewhere in the tree
11081 -- Note: the exclusion of self-referential copies is just an
11082 -- optimization, since the search of the already copied list
11083 -- would catch it, but it is a common case (Etype pointing
11084 -- to itself for an Itype that is a base type).
11086 elsif Has_Extension
(Node_Id
(F
))
11087 and then Is_Itype
(Entity_Id
(F
))
11088 and then Node_Id
(F
) /= N
11094 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
11095 while Present
(P
) loop
11097 Visit_Node
(Node_Id
(F
));
11104 -- An Itype whose parent is not being copied definitely
11105 -- should NOT be copied, since it does not belong in any
11106 -- sense to the copied subtree.
11112 elsif F
in List_Range
11113 and then Parent
(List_Id
(F
)) = N
11115 Visit_List
(List_Id
(F
));
11124 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
11125 New_Itype
: Entity_Id
;
11130 -- Itypes that describe the designated type of access to subprograms
11131 -- have the structure of subprogram declarations, with signatures,
11132 -- etc. Either we duplicate the signatures completely, or choose to
11133 -- share such itypes, which is fine because their elaboration will
11134 -- have no side effects.
11136 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
11140 New_Itype
:= New_Copy
(Old_Itype
);
11142 -- The new Itype has all the attributes of the old one, and
11143 -- we just copy the contents of the entity. However, the back-end
11144 -- needs different names for debugging purposes, so we create a
11145 -- new internal name for it in all cases.
11147 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
11149 -- If our associated node is an entity that has already been copied,
11150 -- then set the associated node of the copy to point to the right
11151 -- copy. If we have copied an Itype that is itself the associated
11152 -- node of some previously copied Itype, then we set the right
11153 -- pointer in the other direction.
11155 if Present
(Actual_Map
) then
11157 -- Case of hash tables used
11159 if NCT_Hash_Tables_Used
then
11161 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
11163 if Present
(Ent
) then
11164 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
11167 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
11168 if Present
(Ent
) then
11169 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
11171 -- If the hash table has no association for this Itype and
11172 -- its associated node, enter one now.
11175 NCT_Itype_Assoc
.Set
11176 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
11179 -- Case of hash tables not used
11182 E
:= First_Elmt
(Actual_Map
);
11183 while Present
(E
) loop
11184 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
11185 Set_Associated_Node_For_Itype
11186 (New_Itype
, Node
(Next_Elmt
(E
)));
11189 if Is_Type
(Node
(E
))
11191 Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
11193 Set_Associated_Node_For_Itype
11194 (Node
(Next_Elmt
(E
)), New_Itype
);
11197 E
:= Next_Elmt
(Next_Elmt
(E
));
11202 if Present
(Freeze_Node
(New_Itype
)) then
11203 Set_Is_Frozen
(New_Itype
, False);
11204 Set_Freeze_Node
(New_Itype
, Empty
);
11207 -- Add new association to map
11209 if No
(Actual_Map
) then
11210 Actual_Map
:= New_Elmt_List
;
11213 Append_Elmt
(Old_Itype
, Actual_Map
);
11214 Append_Elmt
(New_Itype
, Actual_Map
);
11216 if NCT_Hash_Tables_Used
then
11217 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
11220 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
11222 if NCT_Table_Entries
> NCT_Hash_Threshold
then
11223 Build_NCT_Hash_Tables
;
11227 -- If a record subtype is simply copied, the entity list will be
11228 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
11230 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
11231 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
11234 -- Visit descendents that eventually get copied
11236 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
11238 if Is_Discrete_Type
(Old_Itype
) then
11239 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
11241 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
11242 -- ??? This should involve call to Visit_Field
11243 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
11245 elsif Is_Array_Type
(Old_Itype
) then
11246 if Present
(First_Index
(Old_Itype
)) then
11247 Visit_Field
(Union_Id
(List_Containing
11248 (First_Index
(Old_Itype
))),
11252 if Is_Packed
(Old_Itype
) then
11253 Visit_Field
(Union_Id
(Packed_Array_Type
(Old_Itype
)),
11263 procedure Visit_List
(L
: List_Id
) is
11266 if L
/= No_List
then
11269 while Present
(N
) loop
11280 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
11282 -- Start of processing for Visit_Node
11285 -- Handle case of an Itype, which must be copied
11287 if Has_Extension
(N
)
11288 and then Is_Itype
(N
)
11290 -- Nothing to do if already in the list. This can happen with an
11291 -- Itype entity that appears more than once in the tree.
11292 -- Note that we do not want to visit descendents in this case.
11294 -- Test for already in list when hash table is used
11296 if NCT_Hash_Tables_Used
then
11297 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
11301 -- Test for already in list when hash table not used
11307 if Present
(Actual_Map
) then
11308 E
:= First_Elmt
(Actual_Map
);
11309 while Present
(E
) loop
11310 if Node
(E
) = N
then
11313 E
:= Next_Elmt
(Next_Elmt
(E
));
11323 -- Visit descendents
11325 Visit_Field
(Field1
(N
), N
);
11326 Visit_Field
(Field2
(N
), N
);
11327 Visit_Field
(Field3
(N
), N
);
11328 Visit_Field
(Field4
(N
), N
);
11329 Visit_Field
(Field5
(N
), N
);
11332 -- Start of processing for New_Copy_Tree
11337 -- See if we should use hash table
11339 if No
(Actual_Map
) then
11340 NCT_Hash_Tables_Used
:= False;
11347 NCT_Table_Entries
:= 0;
11349 Elmt
:= First_Elmt
(Actual_Map
);
11350 while Present
(Elmt
) loop
11351 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
11356 if NCT_Table_Entries
> NCT_Hash_Threshold
then
11357 Build_NCT_Hash_Tables
;
11359 NCT_Hash_Tables_Used
:= False;
11364 -- Hash table set up if required, now start phase one by visiting
11365 -- top node (we will recursively visit the descendents).
11367 Visit_Node
(Source
);
11369 -- Now the second phase of the copy can start. First we process
11370 -- all the mapped entities, copying their descendents.
11372 if Present
(Actual_Map
) then
11375 New_Itype
: Entity_Id
;
11377 Elmt
:= First_Elmt
(Actual_Map
);
11378 while Present
(Elmt
) loop
11380 New_Itype
:= Node
(Elmt
);
11381 Copy_Itype_With_Replacement
(New_Itype
);
11387 -- Now we can copy the actual tree
11389 return Copy_Node_With_Replacement
(Source
);
11392 -------------------------
11393 -- New_External_Entity --
11394 -------------------------
11396 function New_External_Entity
11397 (Kind
: Entity_Kind
;
11398 Scope_Id
: Entity_Id
;
11399 Sloc_Value
: Source_Ptr
;
11400 Related_Id
: Entity_Id
;
11401 Suffix
: Character;
11402 Suffix_Index
: Nat
:= 0;
11403 Prefix
: Character := ' ') return Entity_Id
11405 N
: constant Entity_Id
:=
11406 Make_Defining_Identifier
(Sloc_Value
,
11408 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
11411 Set_Ekind
(N
, Kind
);
11412 Set_Is_Internal
(N
, True);
11413 Append_Entity
(N
, Scope_Id
);
11414 Set_Public_Status
(N
);
11416 if Kind
in Type_Kind
then
11417 Init_Size_Align
(N
);
11421 end New_External_Entity
;
11423 -------------------------
11424 -- New_Internal_Entity --
11425 -------------------------
11427 function New_Internal_Entity
11428 (Kind
: Entity_Kind
;
11429 Scope_Id
: Entity_Id
;
11430 Sloc_Value
: Source_Ptr
;
11431 Id_Char
: Character) return Entity_Id
11433 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
11436 Set_Ekind
(N
, Kind
);
11437 Set_Is_Internal
(N
, True);
11438 Append_Entity
(N
, Scope_Id
);
11440 if Kind
in Type_Kind
then
11441 Init_Size_Align
(N
);
11445 end New_Internal_Entity
;
11451 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
11455 -- If we are pointing at a positional parameter, it is a member of a
11456 -- node list (the list of parameters), and the next parameter is the
11457 -- next node on the list, unless we hit a parameter association, then
11458 -- we shift to using the chain whose head is the First_Named_Actual in
11459 -- the parent, and then is threaded using the Next_Named_Actual of the
11460 -- Parameter_Association. All this fiddling is because the original node
11461 -- list is in the textual call order, and what we need is the
11462 -- declaration order.
11464 if Is_List_Member
(Actual_Id
) then
11465 N
:= Next
(Actual_Id
);
11467 if Nkind
(N
) = N_Parameter_Association
then
11468 return First_Named_Actual
(Parent
(Actual_Id
));
11474 return Next_Named_Actual
(Parent
(Actual_Id
));
11478 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
11480 Actual_Id
:= Next_Actual
(Actual_Id
);
11483 ---------------------
11484 -- No_Scalar_Parts --
11485 ---------------------
11487 function No_Scalar_Parts
(T
: Entity_Id
) return Boolean is
11491 if Is_Scalar_Type
(T
) then
11494 elsif Is_Array_Type
(T
) then
11495 return No_Scalar_Parts
(Component_Type
(T
));
11497 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
11498 C
:= First_Component_Or_Discriminant
(T
);
11499 while Present
(C
) loop
11500 if not No_Scalar_Parts
(Etype
(C
)) then
11503 Next_Component_Or_Discriminant
(C
);
11509 end No_Scalar_Parts
;
11511 -----------------------
11512 -- Normalize_Actuals --
11513 -----------------------
11515 -- Chain actuals according to formals of subprogram. If there are no named
11516 -- associations, the chain is simply the list of Parameter Associations,
11517 -- since the order is the same as the declaration order. If there are named
11518 -- associations, then the First_Named_Actual field in the N_Function_Call
11519 -- or N_Procedure_Call_Statement node points to the Parameter_Association
11520 -- node for the parameter that comes first in declaration order. The
11521 -- remaining named parameters are then chained in declaration order using
11522 -- Next_Named_Actual.
11524 -- This routine also verifies that the number of actuals is compatible with
11525 -- the number and default values of formals, but performs no type checking
11526 -- (type checking is done by the caller).
11528 -- If the matching succeeds, Success is set to True and the caller proceeds
11529 -- with type-checking. If the match is unsuccessful, then Success is set to
11530 -- False, and the caller attempts a different interpretation, if there is
11533 -- If the flag Report is on, the call is not overloaded, and a failure to
11534 -- match can be reported here, rather than in the caller.
11536 procedure Normalize_Actuals
11540 Success
: out Boolean)
11542 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
11543 Actual
: Node_Id
:= Empty
;
11544 Formal
: Entity_Id
;
11545 Last
: Node_Id
:= Empty
;
11546 First_Named
: Node_Id
:= Empty
;
11549 Formals_To_Match
: Integer := 0;
11550 Actuals_To_Match
: Integer := 0;
11552 procedure Chain
(A
: Node_Id
);
11553 -- Add named actual at the proper place in the list, using the
11554 -- Next_Named_Actual link.
11556 function Reporting
return Boolean;
11557 -- Determines if an error is to be reported. To report an error, we
11558 -- need Report to be True, and also we do not report errors caused
11559 -- by calls to init procs that occur within other init procs. Such
11560 -- errors must always be cascaded errors, since if all the types are
11561 -- declared correctly, the compiler will certainly build decent calls!
11567 procedure Chain
(A
: Node_Id
) is
11571 -- Call node points to first actual in list
11573 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
11576 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
11580 Set_Next_Named_Actual
(Last
, Empty
);
11587 function Reporting
return Boolean is
11592 elsif not Within_Init_Proc
then
11595 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
11603 -- Start of processing for Normalize_Actuals
11606 if Is_Access_Type
(S
) then
11608 -- The name in the call is a function call that returns an access
11609 -- to subprogram. The designated type has the list of formals.
11611 Formal
:= First_Formal
(Designated_Type
(S
));
11613 Formal
:= First_Formal
(S
);
11616 while Present
(Formal
) loop
11617 Formals_To_Match
:= Formals_To_Match
+ 1;
11618 Next_Formal
(Formal
);
11621 -- Find if there is a named association, and verify that no positional
11622 -- associations appear after named ones.
11624 if Present
(Actuals
) then
11625 Actual
:= First
(Actuals
);
11628 while Present
(Actual
)
11629 and then Nkind
(Actual
) /= N_Parameter_Association
11631 Actuals_To_Match
:= Actuals_To_Match
+ 1;
11635 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
11637 -- Most common case: positional notation, no defaults
11642 elsif Actuals_To_Match
> Formals_To_Match
then
11644 -- Too many actuals: will not work
11647 if Is_Entity_Name
(Name
(N
)) then
11648 Error_Msg_N
("too many arguments in call to&", Name
(N
));
11650 Error_Msg_N
("too many arguments in call", N
);
11658 First_Named
:= Actual
;
11660 while Present
(Actual
) loop
11661 if Nkind
(Actual
) /= N_Parameter_Association
then
11663 ("positional parameters not allowed after named ones", Actual
);
11668 Actuals_To_Match
:= Actuals_To_Match
+ 1;
11674 if Present
(Actuals
) then
11675 Actual
:= First
(Actuals
);
11678 Formal
:= First_Formal
(S
);
11679 while Present
(Formal
) loop
11681 -- Match the formals in order. If the corresponding actual is
11682 -- positional, nothing to do. Else scan the list of named actuals
11683 -- to find the one with the right name.
11685 if Present
(Actual
)
11686 and then Nkind
(Actual
) /= N_Parameter_Association
11689 Actuals_To_Match
:= Actuals_To_Match
- 1;
11690 Formals_To_Match
:= Formals_To_Match
- 1;
11693 -- For named parameters, search the list of actuals to find
11694 -- one that matches the next formal name.
11696 Actual
:= First_Named
;
11698 while Present
(Actual
) loop
11699 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
11702 Actuals_To_Match
:= Actuals_To_Match
- 1;
11703 Formals_To_Match
:= Formals_To_Match
- 1;
11711 if Ekind
(Formal
) /= E_In_Parameter
11712 or else No
(Default_Value
(Formal
))
11715 if (Comes_From_Source
(S
)
11716 or else Sloc
(S
) = Standard_Location
)
11717 and then Is_Overloadable
(S
)
11721 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
11723 (Nkind
(Parent
(N
)) = N_Function_Call
11725 Nkind
(Parent
(N
)) = N_Parameter_Association
))
11726 and then Ekind
(S
) /= E_Function
11728 Set_Etype
(N
, Etype
(S
));
11730 Error_Msg_Name_1
:= Chars
(S
);
11731 Error_Msg_Sloc
:= Sloc
(S
);
11733 ("missing argument for parameter & " &
11734 "in call to % declared #", N
, Formal
);
11737 elsif Is_Overloadable
(S
) then
11738 Error_Msg_Name_1
:= Chars
(S
);
11740 -- Point to type derivation that generated the
11743 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
11746 ("missing argument for parameter & " &
11747 "in call to % (inherited) #", N
, Formal
);
11751 ("missing argument for parameter &", N
, Formal
);
11759 Formals_To_Match
:= Formals_To_Match
- 1;
11764 Next_Formal
(Formal
);
11767 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
11774 -- Find some superfluous named actual that did not get
11775 -- attached to the list of associations.
11777 Actual
:= First
(Actuals
);
11778 while Present
(Actual
) loop
11779 if Nkind
(Actual
) = N_Parameter_Association
11780 and then Actual
/= Last
11781 and then No
(Next_Named_Actual
(Actual
))
11783 Error_Msg_N
("unmatched actual & in call",
11784 Selector_Name
(Actual
));
11795 end Normalize_Actuals
;
11797 --------------------------------
11798 -- Note_Possible_Modification --
11799 --------------------------------
11801 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
11802 Modification_Comes_From_Source
: constant Boolean :=
11803 Comes_From_Source
(Parent
(N
));
11809 -- Loop to find referenced entity, if there is one
11816 if Is_Entity_Name
(Exp
) then
11817 Ent
:= Entity
(Exp
);
11819 -- If the entity is missing, it is an undeclared identifier,
11820 -- and there is nothing to annotate.
11826 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
11828 P
: constant Node_Id
:= Prefix
(Exp
);
11831 -- In formal verification mode, keep track of all reads and
11832 -- writes through explicit dereferences.
11835 Alfa
.Generate_Dereference
(N
, 'm');
11838 if Nkind
(P
) = N_Selected_Component
11840 Entry_Formal
(Entity
(Selector_Name
(P
))))
11842 -- Case of a reference to an entry formal
11844 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
11846 elsif Nkind
(P
) = N_Identifier
11847 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
11848 and then Present
(Expression
(Parent
(Entity
(P
))))
11849 and then Nkind
(Expression
(Parent
(Entity
(P
))))
11852 -- Case of a reference to a value on which side effects have
11855 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
11864 elsif Nkind
(Exp
) = N_Type_Conversion
11865 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
11867 Exp
:= Expression
(Exp
);
11870 elsif Nkind
(Exp
) = N_Slice
11871 or else Nkind
(Exp
) = N_Indexed_Component
11872 or else Nkind
(Exp
) = N_Selected_Component
11874 Exp
:= Prefix
(Exp
);
11881 -- Now look for entity being referenced
11883 if Present
(Ent
) then
11884 if Is_Object
(Ent
) then
11885 if Comes_From_Source
(Exp
)
11886 or else Modification_Comes_From_Source
11888 -- Give warning if pragma unmodified given and we are
11889 -- sure this is a modification.
11891 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
11893 ("??pragma Unmodified given for &!", N
, Ent
);
11896 Set_Never_Set_In_Source
(Ent
, False);
11899 Set_Is_True_Constant
(Ent
, False);
11900 Set_Current_Value
(Ent
, Empty
);
11901 Set_Is_Known_Null
(Ent
, False);
11903 if not Can_Never_Be_Null
(Ent
) then
11904 Set_Is_Known_Non_Null
(Ent
, False);
11907 -- Follow renaming chain
11909 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
11910 and then Present
(Renamed_Object
(Ent
))
11912 Exp
:= Renamed_Object
(Ent
);
11915 -- The expression may be the renaming of a subcomponent of an
11916 -- array or container. The assignment to the subcomponent is
11917 -- a modification of the container.
11919 elsif Comes_From_Source
(Original_Node
(Exp
))
11920 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
11921 N_Indexed_Component
)
11923 Exp
:= Prefix
(Original_Node
(Exp
));
11927 -- Generate a reference only if the assignment comes from
11928 -- source. This excludes, for example, calls to a dispatching
11929 -- assignment operation when the left-hand side is tagged.
11931 if Modification_Comes_From_Source
or else Alfa_Mode
then
11932 Generate_Reference
(Ent
, Exp
, 'm');
11934 -- If the target of the assignment is the bound variable
11935 -- in an iterator, indicate that the corresponding array
11936 -- or container is also modified.
11938 if Ada_Version
>= Ada_2012
11940 Nkind
(Parent
(Ent
)) = N_Iterator_Specification
11943 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
11946 -- TBD : in the full version of the construct, the
11947 -- domain of iteration can be given by an expression.
11949 if Is_Entity_Name
(Domain
) then
11950 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
11951 Set_Is_True_Constant
(Entity
(Domain
), False);
11952 Set_Never_Set_In_Source
(Entity
(Domain
), False);
11958 Check_Nested_Access
(Ent
);
11963 -- If we are sure this is a modification from source, and we know
11964 -- this modifies a constant, then give an appropriate warning.
11966 if Overlays_Constant
(Ent
)
11967 and then Modification_Comes_From_Source
11971 A
: constant Node_Id
:= Address_Clause
(Ent
);
11973 if Present
(A
) then
11975 Exp
: constant Node_Id
:= Expression
(A
);
11977 if Nkind
(Exp
) = N_Attribute_Reference
11978 and then Attribute_Name
(Exp
) = Name_Address
11979 and then Is_Entity_Name
(Prefix
(Exp
))
11981 Error_Msg_Sloc
:= Sloc
(A
);
11983 ("constant& may be modified via address "
11984 & "clause#??", N
, Entity
(Prefix
(Exp
)));
11994 end Note_Possible_Modification
;
11996 -------------------------
11997 -- Object_Access_Level --
11998 -------------------------
12000 -- Returns the static accessibility level of the view denoted by Obj. Note
12001 -- that the value returned is the result of a call to Scope_Depth. Only
12002 -- scope depths associated with dynamic scopes can actually be returned.
12003 -- Since only relative levels matter for accessibility checking, the fact
12004 -- that the distance between successive levels of accessibility is not
12005 -- always one is immaterial (invariant: if level(E2) is deeper than
12006 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
12008 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
12009 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
12010 -- Determine whether N is a construct of the form
12011 -- Some_Type (Operand._tag'Address)
12012 -- This construct appears in the context of dispatching calls.
12014 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
12015 -- An explicit dereference is created when removing side-effects from
12016 -- expressions for constraint checking purposes. In this case a local
12017 -- access type is created for it. The correct access level is that of
12018 -- the original source node. We detect this case by noting that the
12019 -- prefix of the dereference is created by an object declaration whose
12020 -- initial expression is a reference.
12022 -----------------------------
12023 -- Is_Interface_Conversion --
12024 -----------------------------
12026 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
12029 Nkind
(N
) = N_Unchecked_Type_Conversion
12030 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
12031 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
12032 end Is_Interface_Conversion
;
12038 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
12039 Pref
: constant Node_Id
:= Prefix
(Obj
);
12041 if Is_Entity_Name
(Pref
)
12042 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
12043 and then Present
(Expression
(Parent
(Entity
(Pref
))))
12044 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
12046 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
12056 -- Start of processing for Object_Access_Level
12059 if Nkind
(Obj
) = N_Defining_Identifier
12060 or else Is_Entity_Name
(Obj
)
12062 if Nkind
(Obj
) = N_Defining_Identifier
then
12068 if Is_Prival
(E
) then
12069 E
:= Prival_Link
(E
);
12072 -- If E is a type then it denotes a current instance. For this case
12073 -- we add one to the normal accessibility level of the type to ensure
12074 -- that current instances are treated as always being deeper than
12075 -- than the level of any visible named access type (see 3.10.2(21)).
12077 if Is_Type
(E
) then
12078 return Type_Access_Level
(E
) + 1;
12080 elsif Present
(Renamed_Object
(E
)) then
12081 return Object_Access_Level
(Renamed_Object
(E
));
12083 -- Similarly, if E is a component of the current instance of a
12084 -- protected type, any instance of it is assumed to be at a deeper
12085 -- level than the type. For a protected object (whose type is an
12086 -- anonymous protected type) its components are at the same level
12087 -- as the type itself.
12089 elsif not Is_Overloadable
(E
)
12090 and then Ekind
(Scope
(E
)) = E_Protected_Type
12091 and then Comes_From_Source
(Scope
(E
))
12093 return Type_Access_Level
(Scope
(E
)) + 1;
12096 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
12099 elsif Nkind
(Obj
) = N_Selected_Component
then
12100 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
12101 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12103 return Object_Access_Level
(Prefix
(Obj
));
12106 elsif Nkind
(Obj
) = N_Indexed_Component
then
12107 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
12108 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12110 return Object_Access_Level
(Prefix
(Obj
));
12113 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
12115 -- If the prefix is a selected access discriminant then we make a
12116 -- recursive call on the prefix, which will in turn check the level
12117 -- of the prefix object of the selected discriminant.
12119 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
12120 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
12122 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
12124 return Object_Access_Level
(Prefix
(Obj
));
12126 -- Detect an interface conversion in the context of a dispatching
12127 -- call. Use the original form of the conversion to find the access
12128 -- level of the operand.
12130 elsif Is_Interface
(Etype
(Obj
))
12131 and then Is_Interface_Conversion
(Prefix
(Obj
))
12132 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
12134 return Object_Access_Level
(Original_Node
(Obj
));
12136 elsif not Comes_From_Source
(Obj
) then
12138 Ref
: constant Node_Id
:= Reference_To
(Obj
);
12140 if Present
(Ref
) then
12141 return Object_Access_Level
(Ref
);
12143 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12148 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
12151 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
12152 return Object_Access_Level
(Expression
(Obj
));
12154 elsif Nkind
(Obj
) = N_Function_Call
then
12156 -- Function results are objects, so we get either the access level of
12157 -- the function or, in the case of an indirect call, the level of the
12158 -- access-to-subprogram type. (This code is used for Ada 95, but it
12159 -- looks wrong, because it seems that we should be checking the level
12160 -- of the call itself, even for Ada 95. However, using the Ada 2005
12161 -- version of the code causes regressions in several tests that are
12162 -- compiled with -gnat95. ???)
12164 if Ada_Version
< Ada_2005
then
12165 if Is_Entity_Name
(Name
(Obj
)) then
12166 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
12168 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
12171 -- For Ada 2005, the level of the result object of a function call is
12172 -- defined to be the level of the call's innermost enclosing master.
12173 -- We determine that by querying the depth of the innermost enclosing
12177 Return_Master_Scope_Depth_Of_Call
: declare
12179 function Innermost_Master_Scope_Depth
12180 (N
: Node_Id
) return Uint
;
12181 -- Returns the scope depth of the given node's innermost
12182 -- enclosing dynamic scope (effectively the accessibility
12183 -- level of the innermost enclosing master).
12185 ----------------------------------
12186 -- Innermost_Master_Scope_Depth --
12187 ----------------------------------
12189 function Innermost_Master_Scope_Depth
12190 (N
: Node_Id
) return Uint
12192 Node_Par
: Node_Id
:= Parent
(N
);
12195 -- Locate the nearest enclosing node (by traversing Parents)
12196 -- that Defining_Entity can be applied to, and return the
12197 -- depth of that entity's nearest enclosing dynamic scope.
12199 while Present
(Node_Par
) loop
12200 case Nkind
(Node_Par
) is
12201 when N_Component_Declaration |
12202 N_Entry_Declaration |
12203 N_Formal_Object_Declaration |
12204 N_Formal_Type_Declaration |
12205 N_Full_Type_Declaration |
12206 N_Incomplete_Type_Declaration |
12207 N_Loop_Parameter_Specification |
12208 N_Object_Declaration |
12209 N_Protected_Type_Declaration |
12210 N_Private_Extension_Declaration |
12211 N_Private_Type_Declaration |
12212 N_Subtype_Declaration |
12213 N_Function_Specification |
12214 N_Procedure_Specification |
12215 N_Task_Type_Declaration |
12217 N_Generic_Instantiation |
12219 N_Implicit_Label_Declaration |
12220 N_Package_Declaration |
12221 N_Single_Task_Declaration |
12222 N_Subprogram_Declaration |
12223 N_Generic_Declaration |
12224 N_Renaming_Declaration |
12225 N_Block_Statement |
12226 N_Formal_Subprogram_Declaration |
12227 N_Abstract_Subprogram_Declaration |
12229 N_Exception_Declaration |
12230 N_Formal_Package_Declaration |
12231 N_Number_Declaration |
12232 N_Package_Specification |
12233 N_Parameter_Specification |
12234 N_Single_Protected_Declaration |
12238 (Nearest_Dynamic_Scope
12239 (Defining_Entity
(Node_Par
)));
12245 Node_Par
:= Parent
(Node_Par
);
12248 pragma Assert
(False);
12250 -- Should never reach the following return
12252 return Scope_Depth
(Current_Scope
) + 1;
12253 end Innermost_Master_Scope_Depth
;
12255 -- Start of processing for Return_Master_Scope_Depth_Of_Call
12258 return Innermost_Master_Scope_Depth
(Obj
);
12259 end Return_Master_Scope_Depth_Of_Call
;
12262 -- For convenience we handle qualified expressions, even though they
12263 -- aren't technically object names.
12265 elsif Nkind
(Obj
) = N_Qualified_Expression
then
12266 return Object_Access_Level
(Expression
(Obj
));
12268 -- Otherwise return the scope level of Standard. (If there are cases
12269 -- that fall through to this point they will be treated as having
12270 -- global accessibility for now. ???)
12273 return Scope_Depth
(Standard_Standard
);
12275 end Object_Access_Level
;
12277 --------------------------------------
12278 -- Original_Corresponding_Operation --
12279 --------------------------------------
12281 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
12283 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
12286 -- If S is an inherited primitive S2 the original corresponding
12287 -- operation of S is the original corresponding operation of S2
12289 if Present
(Alias
(S
))
12290 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
12292 return Original_Corresponding_Operation
(Alias
(S
));
12294 -- If S overrides an inherited subprogram S2 the original corresponding
12295 -- operation of S is the original corresponding operation of S2
12297 elsif Present
(Overridden_Operation
(S
)) then
12298 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
12300 -- otherwise it is S itself
12305 end Original_Corresponding_Operation
;
12307 -----------------------
12308 -- Private_Component --
12309 -----------------------
12311 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
12312 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
12314 function Trace_Components
12316 Check
: Boolean) return Entity_Id
;
12317 -- Recursive function that does the work, and checks against circular
12318 -- definition for each subcomponent type.
12320 ----------------------
12321 -- Trace_Components --
12322 ----------------------
12324 function Trace_Components
12326 Check
: Boolean) return Entity_Id
12328 Btype
: constant Entity_Id
:= Base_Type
(T
);
12329 Component
: Entity_Id
;
12331 Candidate
: Entity_Id
:= Empty
;
12334 if Check
and then Btype
= Ancestor
then
12335 Error_Msg_N
("circular type definition", Type_Id
);
12339 if Is_Private_Type
(Btype
)
12340 and then not Is_Generic_Type
(Btype
)
12342 if Present
(Full_View
(Btype
))
12343 and then Is_Record_Type
(Full_View
(Btype
))
12344 and then not Is_Frozen
(Btype
)
12346 -- To indicate that the ancestor depends on a private type, the
12347 -- current Btype is sufficient. However, to check for circular
12348 -- definition we must recurse on the full view.
12350 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
12352 if Candidate
= Any_Type
then
12362 elsif Is_Array_Type
(Btype
) then
12363 return Trace_Components
(Component_Type
(Btype
), True);
12365 elsif Is_Record_Type
(Btype
) then
12366 Component
:= First_Entity
(Btype
);
12367 while Present
(Component
)
12368 and then Comes_From_Source
(Component
)
12370 -- Skip anonymous types generated by constrained components
12372 if not Is_Type
(Component
) then
12373 P
:= Trace_Components
(Etype
(Component
), True);
12375 if Present
(P
) then
12376 if P
= Any_Type
then
12384 Next_Entity
(Component
);
12392 end Trace_Components
;
12394 -- Start of processing for Private_Component
12397 return Trace_Components
(Type_Id
, False);
12398 end Private_Component
;
12400 ---------------------------
12401 -- Primitive_Names_Match --
12402 ---------------------------
12404 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
12406 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
12407 -- Given an internal name, returns the corresponding non-internal name
12409 ------------------------
12410 -- Non_Internal_Name --
12411 ------------------------
12413 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
12415 Get_Name_String
(Chars
(E
));
12416 Name_Len
:= Name_Len
- 1;
12418 end Non_Internal_Name
;
12420 -- Start of processing for Primitive_Names_Match
12423 pragma Assert
(Present
(E1
) and then Present
(E2
));
12425 return Chars
(E1
) = Chars
(E2
)
12427 (not Is_Internal_Name
(Chars
(E1
))
12428 and then Is_Internal_Name
(Chars
(E2
))
12429 and then Non_Internal_Name
(E2
) = Chars
(E1
))
12431 (not Is_Internal_Name
(Chars
(E2
))
12432 and then Is_Internal_Name
(Chars
(E1
))
12433 and then Non_Internal_Name
(E1
) = Chars
(E2
))
12435 (Is_Predefined_Dispatching_Operation
(E1
)
12436 and then Is_Predefined_Dispatching_Operation
(E2
)
12437 and then Same_TSS
(E1
, E2
))
12439 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
12440 end Primitive_Names_Match
;
12442 -----------------------
12443 -- Process_End_Label --
12444 -----------------------
12446 procedure Process_End_Label
12455 Label_Ref
: Boolean;
12456 -- Set True if reference to end label itself is required
12459 -- Gets set to the operator symbol or identifier that references the
12460 -- entity Ent. For the child unit case, this is the identifier from the
12461 -- designator. For other cases, this is simply Endl.
12463 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
12464 -- N is an identifier node that appears as a parent unit reference in
12465 -- the case where Ent is a child unit. This procedure generates an
12466 -- appropriate cross-reference entry. E is the corresponding entity.
12468 -------------------------
12469 -- Generate_Parent_Ref --
12470 -------------------------
12472 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
12474 -- If names do not match, something weird, skip reference
12476 if Chars
(E
) = Chars
(N
) then
12478 -- Generate the reference. We do NOT consider this as a reference
12479 -- for unreferenced symbol purposes.
12481 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
12483 if Style_Check
then
12484 Style
.Check_Identifier
(N
, E
);
12487 end Generate_Parent_Ref
;
12489 -- Start of processing for Process_End_Label
12492 -- If no node, ignore. This happens in some error situations, and
12493 -- also for some internally generated structures where no end label
12494 -- references are required in any case.
12500 -- Nothing to do if no End_Label, happens for internally generated
12501 -- constructs where we don't want an end label reference anyway. Also
12502 -- nothing to do if Endl is a string literal, which means there was
12503 -- some prior error (bad operator symbol)
12505 Endl
:= End_Label
(N
);
12507 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
12511 -- Reference node is not in extended main source unit
12513 if not In_Extended_Main_Source_Unit
(N
) then
12515 -- Generally we do not collect references except for the extended
12516 -- main source unit. The one exception is the 'e' entry for a
12517 -- package spec, where it is useful for a client to have the
12518 -- ending information to define scopes.
12524 Label_Ref
:= False;
12526 -- For this case, we can ignore any parent references, but we
12527 -- need the package name itself for the 'e' entry.
12529 if Nkind
(Endl
) = N_Designator
then
12530 Endl
:= Identifier
(Endl
);
12534 -- Reference is in extended main source unit
12539 -- For designator, generate references for the parent entries
12541 if Nkind
(Endl
) = N_Designator
then
12543 -- Generate references for the prefix if the END line comes from
12544 -- source (otherwise we do not need these references) We climb the
12545 -- scope stack to find the expected entities.
12547 if Comes_From_Source
(Endl
) then
12548 Nam
:= Name
(Endl
);
12549 Scop
:= Current_Scope
;
12550 while Nkind
(Nam
) = N_Selected_Component
loop
12551 Scop
:= Scope
(Scop
);
12552 exit when No
(Scop
);
12553 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
12554 Nam
:= Prefix
(Nam
);
12557 if Present
(Scop
) then
12558 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
12562 Endl
:= Identifier
(Endl
);
12566 -- If the end label is not for the given entity, then either we have
12567 -- some previous error, or this is a generic instantiation for which
12568 -- we do not need to make a cross-reference in this case anyway. In
12569 -- either case we simply ignore the call.
12571 if Chars
(Ent
) /= Chars
(Endl
) then
12575 -- If label was really there, then generate a normal reference and then
12576 -- adjust the location in the end label to point past the name (which
12577 -- should almost always be the semicolon).
12579 Loc
:= Sloc
(Endl
);
12581 if Comes_From_Source
(Endl
) then
12583 -- If a label reference is required, then do the style check and
12584 -- generate an l-type cross-reference entry for the label
12587 if Style_Check
then
12588 Style
.Check_Identifier
(Endl
, Ent
);
12591 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
12594 -- Set the location to point past the label (normally this will
12595 -- mean the semicolon immediately following the label). This is
12596 -- done for the sake of the 'e' or 't' entry generated below.
12598 Get_Decoded_Name_String
(Chars
(Endl
));
12599 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
12602 -- In SPARK mode, no missing label is allowed for packages and
12603 -- subprogram bodies. Detect those cases by testing whether
12604 -- Process_End_Label was called for a body (Typ = 't') or a package.
12606 if Restriction_Check_Required
(SPARK
)
12607 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
12609 Error_Msg_Node_1
:= Endl
;
12610 Check_SPARK_Restriction
("`END &` required", Endl
, Force
=> True);
12614 -- Now generate the e/t reference
12616 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
12618 -- Restore Sloc, in case modified above, since we have an identifier
12619 -- and the normal Sloc should be left set in the tree.
12621 Set_Sloc
(Endl
, Loc
);
12622 end Process_End_Label
;
12624 ------------------------------------
12625 -- References_Generic_Formal_Type --
12626 ------------------------------------
12628 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
12630 function Process
(N
: Node_Id
) return Traverse_Result
;
12631 -- Process one node in search for generic formal type
12637 function Process
(N
: Node_Id
) return Traverse_Result
is
12639 if Nkind
(N
) in N_Has_Entity
then
12641 E
: constant Entity_Id
:= Entity
(N
);
12643 if Present
(E
) then
12644 if Is_Generic_Type
(E
) then
12646 elsif Present
(Etype
(E
))
12647 and then Is_Generic_Type
(Etype
(E
))
12658 function Traverse
is new Traverse_Func
(Process
);
12659 -- Traverse tree to look for generic type
12662 if Inside_A_Generic
then
12663 return Traverse
(N
) = Abandon
;
12667 end References_Generic_Formal_Type
;
12669 --------------------
12670 -- Remove_Homonym --
12671 --------------------
12673 procedure Remove_Homonym
(E
: Entity_Id
) is
12674 Prev
: Entity_Id
:= Empty
;
12678 if E
= Current_Entity
(E
) then
12679 if Present
(Homonym
(E
)) then
12680 Set_Current_Entity
(Homonym
(E
));
12682 Set_Name_Entity_Id
(Chars
(E
), Empty
);
12686 H
:= Current_Entity
(E
);
12687 while Present
(H
) and then H
/= E
loop
12692 -- If E is not on the homonym chain, nothing to do
12694 if Present
(H
) then
12695 Set_Homonym
(Prev
, Homonym
(E
));
12698 end Remove_Homonym
;
12700 ---------------------
12701 -- Rep_To_Pos_Flag --
12702 ---------------------
12704 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
12706 return New_Occurrence_Of
12707 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
12708 end Rep_To_Pos_Flag
;
12710 --------------------
12711 -- Require_Entity --
12712 --------------------
12714 procedure Require_Entity
(N
: Node_Id
) is
12716 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
12717 if Total_Errors_Detected
/= 0 then
12718 Set_Entity
(N
, Any_Id
);
12720 raise Program_Error
;
12723 end Require_Entity
;
12725 ------------------------------
12726 -- Requires_Transient_Scope --
12727 ------------------------------
12729 -- A transient scope is required when variable-sized temporaries are
12730 -- allocated in the primary or secondary stack, or when finalization
12731 -- actions must be generated before the next instruction.
12733 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
12734 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
12736 -- Start of processing for Requires_Transient_Scope
12739 -- This is a private type which is not completed yet. This can only
12740 -- happen in a default expression (of a formal parameter or of a
12741 -- record component). Do not expand transient scope in this case
12746 -- Do not expand transient scope for non-existent procedure return
12748 elsif Typ
= Standard_Void_Type
then
12751 -- Elementary types do not require a transient scope
12753 elsif Is_Elementary_Type
(Typ
) then
12756 -- Generally, indefinite subtypes require a transient scope, since the
12757 -- back end cannot generate temporaries, since this is not a valid type
12758 -- for declaring an object. It might be possible to relax this in the
12759 -- future, e.g. by declaring the maximum possible space for the type.
12761 elsif Is_Indefinite_Subtype
(Typ
) then
12764 -- Functions returning tagged types may dispatch on result so their
12765 -- returned value is allocated on the secondary stack. Controlled
12766 -- type temporaries need finalization.
12768 elsif Is_Tagged_Type
(Typ
)
12769 or else Has_Controlled_Component
(Typ
)
12771 return not Is_Value_Type
(Typ
);
12775 elsif Is_Record_Type
(Typ
) then
12779 Comp
:= First_Entity
(Typ
);
12780 while Present
(Comp
) loop
12781 if Ekind
(Comp
) = E_Component
12782 and then Requires_Transient_Scope
(Etype
(Comp
))
12786 Next_Entity
(Comp
);
12793 -- String literal types never require transient scope
12795 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
12798 -- Array type. Note that we already know that this is a constrained
12799 -- array, since unconstrained arrays will fail the indefinite test.
12801 elsif Is_Array_Type
(Typ
) then
12803 -- If component type requires a transient scope, the array does too
12805 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
12808 -- Otherwise, we only need a transient scope if the size depends on
12809 -- the value of one or more discriminants.
12812 return Size_Depends_On_Discriminant
(Typ
);
12815 -- All other cases do not require a transient scope
12820 end Requires_Transient_Scope
;
12822 --------------------------
12823 -- Reset_Analyzed_Flags --
12824 --------------------------
12826 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
12828 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
12829 -- Function used to reset Analyzed flags in tree. Note that we do
12830 -- not reset Analyzed flags in entities, since there is no need to
12831 -- reanalyze entities, and indeed, it is wrong to do so, since it
12832 -- can result in generating auxiliary stuff more than once.
12834 --------------------
12835 -- Clear_Analyzed --
12836 --------------------
12838 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
12840 if not Has_Extension
(N
) then
12841 Set_Analyzed
(N
, False);
12845 end Clear_Analyzed
;
12847 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
12849 -- Start of processing for Reset_Analyzed_Flags
12852 Reset_Analyzed
(N
);
12853 end Reset_Analyzed_Flags
;
12855 --------------------------------
12856 -- Returns_Unconstrained_Type --
12857 --------------------------------
12859 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
12861 return Ekind
(Subp
) = E_Function
12862 and then not Is_Scalar_Type
(Etype
(Subp
))
12863 and then not Is_Access_Type
(Etype
(Subp
))
12864 and then not Is_Constrained
(Etype
(Subp
));
12865 end Returns_Unconstrained_Type
;
12867 ---------------------------
12868 -- Safe_To_Capture_Value --
12869 ---------------------------
12871 function Safe_To_Capture_Value
12874 Cond
: Boolean := False) return Boolean
12877 -- The only entities for which we track constant values are variables
12878 -- which are not renamings, constants, out parameters, and in out
12879 -- parameters, so check if we have this case.
12881 -- Note: it may seem odd to track constant values for constants, but in
12882 -- fact this routine is used for other purposes than simply capturing
12883 -- the value. In particular, the setting of Known[_Non]_Null.
12885 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
12887 Ekind
(Ent
) = E_Constant
12889 Ekind
(Ent
) = E_Out_Parameter
12891 Ekind
(Ent
) = E_In_Out_Parameter
12895 -- For conditionals, we also allow loop parameters and all formals,
12896 -- including in parameters.
12900 (Ekind
(Ent
) = E_Loop_Parameter
12902 Ekind
(Ent
) = E_In_Parameter
)
12906 -- For all other cases, not just unsafe, but impossible to capture
12907 -- Current_Value, since the above are the only entities which have
12908 -- Current_Value fields.
12914 -- Skip if volatile or aliased, since funny things might be going on in
12915 -- these cases which we cannot necessarily track. Also skip any variable
12916 -- for which an address clause is given, or whose address is taken. Also
12917 -- never capture value of library level variables (an attempt to do so
12918 -- can occur in the case of package elaboration code).
12920 if Treat_As_Volatile
(Ent
)
12921 or else Is_Aliased
(Ent
)
12922 or else Present
(Address_Clause
(Ent
))
12923 or else Address_Taken
(Ent
)
12924 or else (Is_Library_Level_Entity
(Ent
)
12925 and then Ekind
(Ent
) = E_Variable
)
12930 -- OK, all above conditions are met. We also require that the scope of
12931 -- the reference be the same as the scope of the entity, not counting
12932 -- packages and blocks and loops.
12935 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
12936 R_Scope
: Entity_Id
;
12939 R_Scope
:= Current_Scope
;
12940 while R_Scope
/= Standard_Standard
loop
12941 exit when R_Scope
= E_Scope
;
12943 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
12946 R_Scope
:= Scope
(R_Scope
);
12951 -- We also require that the reference does not appear in a context
12952 -- where it is not sure to be executed (i.e. a conditional context
12953 -- or an exception handler). We skip this if Cond is True, since the
12954 -- capturing of values from conditional tests handles this ok.
12967 -- Seems dubious that case expressions are not handled here ???
12970 while Present
(P
) loop
12971 if Nkind
(P
) = N_If_Statement
12972 or else Nkind
(P
) = N_Case_Statement
12973 or else (Nkind
(P
) in N_Short_Circuit
12974 and then Desc
= Right_Opnd
(P
))
12975 or else (Nkind
(P
) = N_If_Expression
12976 and then Desc
/= First
(Expressions
(P
)))
12977 or else Nkind
(P
) = N_Exception_Handler
12978 or else Nkind
(P
) = N_Selective_Accept
12979 or else Nkind
(P
) = N_Conditional_Entry_Call
12980 or else Nkind
(P
) = N_Timed_Entry_Call
12981 or else Nkind
(P
) = N_Asynchronous_Select
12991 -- OK, looks safe to set value
12994 end Safe_To_Capture_Value
;
13000 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
13001 K1
: constant Node_Kind
:= Nkind
(N1
);
13002 K2
: constant Node_Kind
:= Nkind
(N2
);
13005 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
13006 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
13008 return Chars
(N1
) = Chars
(N2
);
13010 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
13011 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
13013 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
13014 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
13025 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
13026 N1
: constant Node_Id
:= Original_Node
(Node1
);
13027 N2
: constant Node_Id
:= Original_Node
(Node2
);
13028 -- We do the tests on original nodes, since we are most interested
13029 -- in the original source, not any expansion that got in the way.
13031 K1
: constant Node_Kind
:= Nkind
(N1
);
13032 K2
: constant Node_Kind
:= Nkind
(N2
);
13035 -- First case, both are entities with same entity
13037 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
13039 EN1
: constant Entity_Id
:= Entity
(N1
);
13040 EN2
: constant Entity_Id
:= Entity
(N2
);
13042 if Present
(EN1
) and then Present
(EN2
)
13043 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
13044 or else Is_Formal
(EN1
))
13052 -- Second case, selected component with same selector, same record
13054 if K1
= N_Selected_Component
13055 and then K2
= N_Selected_Component
13056 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
13058 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
13060 -- Third case, indexed component with same subscripts, same array
13062 elsif K1
= N_Indexed_Component
13063 and then K2
= N_Indexed_Component
13064 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
13069 E1
:= First
(Expressions
(N1
));
13070 E2
:= First
(Expressions
(N2
));
13071 while Present
(E1
) loop
13072 if not Same_Value
(E1
, E2
) then
13083 -- Fourth case, slice of same array with same bounds
13086 and then K2
= N_Slice
13087 and then Nkind
(Discrete_Range
(N1
)) = N_Range
13088 and then Nkind
(Discrete_Range
(N2
)) = N_Range
13089 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
13090 Low_Bound
(Discrete_Range
(N2
)))
13091 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
13092 High_Bound
(Discrete_Range
(N2
)))
13094 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
13096 -- All other cases, not clearly the same object
13107 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
13112 elsif not Is_Constrained
(T1
)
13113 and then not Is_Constrained
(T2
)
13114 and then Base_Type
(T1
) = Base_Type
(T2
)
13118 -- For now don't bother with case of identical constraints, to be
13119 -- fiddled with later on perhaps (this is only used for optimization
13120 -- purposes, so it is not critical to do a best possible job)
13131 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
13133 if Compile_Time_Known_Value
(Node1
)
13134 and then Compile_Time_Known_Value
(Node2
)
13135 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
13138 elsif Same_Object
(Node1
, Node2
) then
13145 ------------------------
13146 -- Scope_Is_Transient --
13147 ------------------------
13149 function Scope_Is_Transient
return Boolean is
13151 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
13152 end Scope_Is_Transient
;
13158 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
13163 while Scop
/= Standard_Standard
loop
13164 Scop
:= Scope
(Scop
);
13166 if Scop
= Scope2
then
13174 --------------------------
13175 -- Scope_Within_Or_Same --
13176 --------------------------
13178 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
13183 while Scop
/= Standard_Standard
loop
13184 if Scop
= Scope2
then
13187 Scop
:= Scope
(Scop
);
13192 end Scope_Within_Or_Same
;
13194 --------------------
13195 -- Set_Convention --
13196 --------------------
13198 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
13200 Basic_Set_Convention
(E
, Val
);
13203 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
13204 and then Has_Foreign_Convention
(E
)
13206 Set_Can_Use_Internal_Rep
(E
, False);
13208 end Set_Convention
;
13210 ------------------------
13211 -- Set_Current_Entity --
13212 ------------------------
13214 -- The given entity is to be set as the currently visible definition of its
13215 -- associated name (i.e. the Node_Id associated with its name). All we have
13216 -- to do is to get the name from the identifier, and then set the
13217 -- associated Node_Id to point to the given entity.
13219 procedure Set_Current_Entity
(E
: Entity_Id
) is
13221 Set_Name_Entity_Id
(Chars
(E
), E
);
13222 end Set_Current_Entity
;
13224 ---------------------------
13225 -- Set_Debug_Info_Needed --
13226 ---------------------------
13228 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
13230 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
13231 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
13232 -- Used to set debug info in a related node if not set already
13234 --------------------------------------
13235 -- Set_Debug_Info_Needed_If_Not_Set --
13236 --------------------------------------
13238 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
13241 and then not Needs_Debug_Info
(E
)
13243 Set_Debug_Info_Needed
(E
);
13245 -- For a private type, indicate that the full view also needs
13246 -- debug information.
13249 and then Is_Private_Type
(E
)
13250 and then Present
(Full_View
(E
))
13252 Set_Debug_Info_Needed
(Full_View
(E
));
13255 end Set_Debug_Info_Needed_If_Not_Set
;
13257 -- Start of processing for Set_Debug_Info_Needed
13260 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
13261 -- indicates that Debug_Info_Needed is never required for the entity.
13264 or else Debug_Info_Off
(T
)
13269 -- Set flag in entity itself. Note that we will go through the following
13270 -- circuitry even if the flag is already set on T. That's intentional,
13271 -- it makes sure that the flag will be set in subsidiary entities.
13273 Set_Needs_Debug_Info
(T
);
13275 -- Set flag on subsidiary entities if not set already
13277 if Is_Object
(T
) then
13278 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
13280 elsif Is_Type
(T
) then
13281 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
13283 if Is_Record_Type
(T
) then
13285 Ent
: Entity_Id
:= First_Entity
(T
);
13287 while Present
(Ent
) loop
13288 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
13293 -- For a class wide subtype, we also need debug information
13294 -- for the equivalent type.
13296 if Ekind
(T
) = E_Class_Wide_Subtype
then
13297 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
13300 elsif Is_Array_Type
(T
) then
13301 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
13304 Indx
: Node_Id
:= First_Index
(T
);
13306 while Present
(Indx
) loop
13307 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
13308 Indx
:= Next_Index
(Indx
);
13312 -- For a packed array type, we also need debug information for
13313 -- the type used to represent the packed array. Conversely, we
13314 -- also need it for the former if we need it for the latter.
13316 if Is_Packed
(T
) then
13317 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Type
(T
));
13320 if Is_Packed_Array_Type
(T
) then
13321 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
13324 elsif Is_Access_Type
(T
) then
13325 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
13327 elsif Is_Private_Type
(T
) then
13328 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
13330 elsif Is_Protected_Type
(T
) then
13331 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
13334 end Set_Debug_Info_Needed
;
13336 ---------------------------------
13337 -- Set_Entity_With_Style_Check --
13338 ---------------------------------
13340 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
13341 Val_Actual
: Entity_Id
;
13345 -- Unconditionally set the entity
13347 Set_Entity
(N
, Val
);
13349 -- Check for No_Implementation_Identifiers
13351 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
13353 -- We have an implementation defined entity if it is marked as
13354 -- implementation defined, or is defined in a package marked as
13355 -- implementation defined. However, library packages themselves
13356 -- are excluded (we don't want to flag Interfaces itself, just
13357 -- the entities within it).
13359 if (Is_Implementation_Defined
(Val
)
13360 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
13361 and then Is_Library_Level_Entity
(Val
)))
13362 or else Is_Implementation_Defined
(Scope
(Val
))
13364 Check_Restriction
(No_Implementation_Identifiers
, N
);
13368 -- Do the style check
13371 and then not Suppress_Style_Checks
(Val
)
13372 and then not In_Instance
13374 if Nkind
(N
) = N_Identifier
then
13376 elsif Nkind
(N
) = N_Expanded_Name
then
13377 Nod
:= Selector_Name
(N
);
13382 -- A special situation arises for derived operations, where we want
13383 -- to do the check against the parent (since the Sloc of the derived
13384 -- operation points to the derived type declaration itself).
13387 while not Comes_From_Source
(Val_Actual
)
13388 and then Nkind
(Val_Actual
) in N_Entity
13389 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
13390 or else Is_Subprogram
(Val_Actual
)
13391 or else Is_Generic_Subprogram
(Val_Actual
))
13392 and then Present
(Alias
(Val_Actual
))
13394 Val_Actual
:= Alias
(Val_Actual
);
13397 -- Renaming declarations for generic actuals do not come from source,
13398 -- and have a different name from that of the entity they rename, so
13399 -- there is no style check to perform here.
13401 if Chars
(Nod
) = Chars
(Val_Actual
) then
13402 Style
.Check_Identifier
(Nod
, Val_Actual
);
13406 Set_Entity
(N
, Val
);
13407 end Set_Entity_With_Style_Check
;
13409 ------------------------
13410 -- Set_Name_Entity_Id --
13411 ------------------------
13413 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
13415 Set_Name_Table_Info
(Id
, Int
(Val
));
13416 end Set_Name_Entity_Id
;
13418 ---------------------
13419 -- Set_Next_Actual --
13420 ---------------------
13422 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
13424 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
13425 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
13427 end Set_Next_Actual
;
13429 ----------------------------------
13430 -- Set_Optimize_Alignment_Flags --
13431 ----------------------------------
13433 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
13435 if Optimize_Alignment
= 'S' then
13436 Set_Optimize_Alignment_Space
(E
);
13437 elsif Optimize_Alignment
= 'T' then
13438 Set_Optimize_Alignment_Time
(E
);
13440 end Set_Optimize_Alignment_Flags
;
13442 -----------------------
13443 -- Set_Public_Status --
13444 -----------------------
13446 procedure Set_Public_Status
(Id
: Entity_Id
) is
13447 S
: constant Entity_Id
:= Current_Scope
;
13449 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
13450 -- Determines if E is defined within handled statement sequence or
13451 -- an if statement, returns True if so, False otherwise.
13453 ----------------------
13454 -- Within_HSS_Or_If --
13455 ----------------------
13457 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
13460 N
:= Declaration_Node
(E
);
13467 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
13473 end Within_HSS_Or_If
;
13475 -- Start of processing for Set_Public_Status
13478 -- Everything in the scope of Standard is public
13480 if S
= Standard_Standard
then
13481 Set_Is_Public
(Id
);
13483 -- Entity is definitely not public if enclosing scope is not public
13485 elsif not Is_Public
(S
) then
13488 -- An object or function declaration that occurs in a handled sequence
13489 -- of statements or within an if statement is the declaration for a
13490 -- temporary object or local subprogram generated by the expander. It
13491 -- never needs to be made public and furthermore, making it public can
13492 -- cause back end problems.
13494 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
13495 N_Function_Specification
)
13496 and then Within_HSS_Or_If
(Id
)
13500 -- Entities in public packages or records are public
13502 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
13503 Set_Is_Public
(Id
);
13505 -- The bounds of an entry family declaration can generate object
13506 -- declarations that are visible to the back-end, e.g. in the
13507 -- the declaration of a composite type that contains tasks.
13509 elsif Is_Concurrent_Type
(S
)
13510 and then not Has_Completion
(S
)
13511 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
13513 Set_Is_Public
(Id
);
13515 end Set_Public_Status
;
13517 -----------------------------
13518 -- Set_Referenced_Modified --
13519 -----------------------------
13521 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
13525 -- Deal with indexed or selected component where prefix is modified
13527 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
13528 Pref
:= Prefix
(N
);
13530 -- If prefix is access type, then it is the designated object that is
13531 -- being modified, which means we have no entity to set the flag on.
13533 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
13536 -- Otherwise chase the prefix
13539 Set_Referenced_Modified
(Pref
, Out_Param
);
13542 -- Otherwise see if we have an entity name (only other case to process)
13544 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
13545 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
13546 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
13548 end Set_Referenced_Modified
;
13550 ----------------------------
13551 -- Set_Scope_Is_Transient --
13552 ----------------------------
13554 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
13556 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
13557 end Set_Scope_Is_Transient
;
13559 -------------------
13560 -- Set_Size_Info --
13561 -------------------
13563 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
13565 -- We copy Esize, but not RM_Size, since in general RM_Size is
13566 -- subtype specific and does not get inherited by all subtypes.
13568 Set_Esize
(T1
, Esize
(T2
));
13569 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
13571 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
13573 Is_Discrete_Or_Fixed_Point_Type
(T2
)
13575 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
13578 Set_Alignment
(T1
, Alignment
(T2
));
13581 --------------------
13582 -- Static_Boolean --
13583 --------------------
13585 function Static_Boolean
(N
: Node_Id
) return Uint
is
13587 Analyze_And_Resolve
(N
, Standard_Boolean
);
13590 or else Error_Posted
(N
)
13591 or else Etype
(N
) = Any_Type
13596 if Is_Static_Expression
(N
) then
13597 if not Raises_Constraint_Error
(N
) then
13598 return Expr_Value
(N
);
13603 elsif Etype
(N
) = Any_Type
then
13607 Flag_Non_Static_Expr
13608 ("static boolean expression required here", N
);
13611 end Static_Boolean
;
13613 --------------------
13614 -- Static_Integer --
13615 --------------------
13617 function Static_Integer
(N
: Node_Id
) return Uint
is
13619 Analyze_And_Resolve
(N
, Any_Integer
);
13622 or else Error_Posted
(N
)
13623 or else Etype
(N
) = Any_Type
13628 if Is_Static_Expression
(N
) then
13629 if not Raises_Constraint_Error
(N
) then
13630 return Expr_Value
(N
);
13635 elsif Etype
(N
) = Any_Type
then
13639 Flag_Non_Static_Expr
13640 ("static integer expression required here", N
);
13643 end Static_Integer
;
13645 --------------------------
13646 -- Statically_Different --
13647 --------------------------
13649 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
13650 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
13651 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
13653 return Is_Entity_Name
(R1
)
13654 and then Is_Entity_Name
(R2
)
13655 and then Entity
(R1
) /= Entity
(R2
)
13656 and then not Is_Formal
(Entity
(R1
))
13657 and then not Is_Formal
(Entity
(R2
));
13658 end Statically_Different
;
13660 -----------------------------
13661 -- Subprogram_Access_Level --
13662 -----------------------------
13664 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
13666 if Present
(Alias
(Subp
)) then
13667 return Subprogram_Access_Level
(Alias
(Subp
));
13669 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
13671 end Subprogram_Access_Level
;
13673 -------------------------------
13674 -- Support_Atomic_Primitives --
13675 -------------------------------
13677 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
13681 -- Verify the alignment of Typ is known
13683 if not Known_Alignment
(Typ
) then
13687 if Known_Static_Esize
(Typ
) then
13688 Size
:= UI_To_Int
(Esize
(Typ
));
13690 -- If the Esize (Object_Size) is unknown at compile-time, look at the
13691 -- RM_Size (Value_Size) since it may have been set by an explicit rep
13694 elsif Known_Static_RM_Size
(Typ
) then
13695 Size
:= UI_To_Int
(RM_Size
(Typ
));
13697 -- Otherwise, the size is considered to be unknown.
13703 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
13704 -- Typ is properly aligned.
13707 when 8 |
16 |
32 |
64 =>
13708 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
13712 end Support_Atomic_Primitives
;
13718 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
13720 if Debug_Flag_W
then
13721 for J
in 0 .. Scope_Stack
.Last
loop
13726 Write_Name
(Chars
(E
));
13727 Write_Str
(" from ");
13728 Write_Location
(Sloc
(N
));
13733 -----------------------
13734 -- Transfer_Entities --
13735 -----------------------
13737 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
13738 Ent
: Entity_Id
:= First_Entity
(From
);
13745 if (Last_Entity
(To
)) = Empty
then
13746 Set_First_Entity
(To
, Ent
);
13748 Set_Next_Entity
(Last_Entity
(To
), Ent
);
13751 Set_Last_Entity
(To
, Last_Entity
(From
));
13753 while Present
(Ent
) loop
13754 Set_Scope
(Ent
, To
);
13756 if not Is_Public
(Ent
) then
13757 Set_Public_Status
(Ent
);
13760 and then Ekind
(Ent
) = E_Record_Subtype
13763 -- The components of the propagated Itype must be public
13769 Comp
:= First_Entity
(Ent
);
13770 while Present
(Comp
) loop
13771 Set_Is_Public
(Comp
);
13772 Next_Entity
(Comp
);
13781 Set_First_Entity
(From
, Empty
);
13782 Set_Last_Entity
(From
, Empty
);
13783 end Transfer_Entities
;
13785 -----------------------
13786 -- Type_Access_Level --
13787 -----------------------
13789 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
13793 Btyp
:= Base_Type
(Typ
);
13795 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
13796 -- simply use the level where the type is declared. This is true for
13797 -- stand-alone object declarations, and for anonymous access types
13798 -- associated with components the level is the same as that of the
13799 -- enclosing composite type. However, special treatment is needed for
13800 -- the cases of access parameters, return objects of an anonymous access
13801 -- type, and, in Ada 95, access discriminants of limited types.
13803 if Ekind
(Btyp
) in Access_Kind
then
13804 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
13806 -- If the type is a nonlocal anonymous access type (such as for
13807 -- an access parameter) we treat it as being declared at the
13808 -- library level to ensure that names such as X.all'access don't
13809 -- fail static accessibility checks.
13811 if not Is_Local_Anonymous_Access
(Typ
) then
13812 return Scope_Depth
(Standard_Standard
);
13814 -- If this is a return object, the accessibility level is that of
13815 -- the result subtype of the enclosing function. The test here is
13816 -- little complicated, because we have to account for extended
13817 -- return statements that have been rewritten as blocks, in which
13818 -- case we have to find and the Is_Return_Object attribute of the
13819 -- itype's associated object. It would be nice to find a way to
13820 -- simplify this test, but it doesn't seem worthwhile to add a new
13821 -- flag just for purposes of this test. ???
13823 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
13826 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
13827 N_Object_Declaration
13828 and then Is_Return_Object
13829 (Defining_Identifier
13830 (Associated_Node_For_Itype
(Btyp
))))
13836 Scop
:= Scope
(Scope
(Btyp
));
13837 while Present
(Scop
) loop
13838 exit when Ekind
(Scop
) = E_Function
;
13839 Scop
:= Scope
(Scop
);
13842 -- Treat the return object's type as having the level of the
13843 -- function's result subtype (as per RM05-6.5(5.3/2)).
13845 return Type_Access_Level
(Etype
(Scop
));
13850 Btyp
:= Root_Type
(Btyp
);
13852 -- The accessibility level of anonymous access types associated with
13853 -- discriminants is that of the current instance of the type, and
13854 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
13856 -- AI-402: access discriminants have accessibility based on the
13857 -- object rather than the type in Ada 2005, so the above paragraph
13860 -- ??? Needs completion with rules from AI-416
13862 if Ada_Version
<= Ada_95
13863 and then Ekind
(Typ
) = E_Anonymous_Access_Type
13864 and then Present
(Associated_Node_For_Itype
(Typ
))
13865 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
13866 N_Discriminant_Specification
13868 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
13872 -- Return library level for a generic formal type. This is done because
13873 -- RM(10.3.2) says that "The statically deeper relationship does not
13874 -- apply to ... a descendant of a generic formal type". Rather than
13875 -- checking at each point where a static accessibility check is
13876 -- performed to see if we are dealing with a formal type, this rule is
13877 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
13878 -- return extreme values for a formal type; Deepest_Type_Access_Level
13879 -- returns Int'Last. By calling the appropriate function from among the
13880 -- two, we ensure that the static accessibility check will pass if we
13881 -- happen to run into a formal type. More specifically, we should call
13882 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
13883 -- call occurs as part of a static accessibility check and the error
13884 -- case is the case where the type's level is too shallow (as opposed
13887 if Is_Generic_Type
(Root_Type
(Btyp
)) then
13888 return Scope_Depth
(Standard_Standard
);
13891 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
13892 end Type_Access_Level
;
13894 ------------------------------------
13895 -- Type_Without_Stream_Operation --
13896 ------------------------------------
13898 function Type_Without_Stream_Operation
13900 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
13902 BT
: constant Entity_Id
:= Base_Type
(T
);
13903 Op_Missing
: Boolean;
13906 if not Restriction_Active
(No_Default_Stream_Attributes
) then
13910 if Is_Elementary_Type
(T
) then
13911 if Op
= TSS_Null
then
13913 No
(TSS
(BT
, TSS_Stream_Read
))
13914 or else No
(TSS
(BT
, TSS_Stream_Write
));
13917 Op_Missing
:= No
(TSS
(BT
, Op
));
13926 elsif Is_Array_Type
(T
) then
13927 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
13929 elsif Is_Record_Type
(T
) then
13935 Comp
:= First_Component
(T
);
13936 while Present
(Comp
) loop
13937 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
13939 if Present
(C_Typ
) then
13943 Next_Component
(Comp
);
13949 elsif Is_Private_Type
(T
)
13950 and then Present
(Full_View
(T
))
13952 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
13956 end Type_Without_Stream_Operation
;
13958 ----------------------------
13959 -- Unique_Defining_Entity --
13960 ----------------------------
13962 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
13964 return Unique_Entity
(Defining_Entity
(N
));
13965 end Unique_Defining_Entity
;
13967 -------------------
13968 -- Unique_Entity --
13969 -------------------
13971 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
13972 U
: Entity_Id
:= E
;
13978 if Present
(Full_View
(E
)) then
13979 U
:= Full_View
(E
);
13983 if Present
(Full_View
(E
)) then
13984 U
:= Full_View
(E
);
13987 when E_Package_Body
=>
13990 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
13994 U
:= Corresponding_Spec
(P
);
13996 when E_Subprogram_Body
=>
13999 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
14005 if Nkind
(P
) = N_Subprogram_Body_Stub
then
14006 if Present
(Library_Unit
(P
)) then
14008 -- Get to the function or procedure (generic) entity through
14009 -- the body entity.
14012 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
14015 U
:= Corresponding_Spec
(P
);
14018 when Formal_Kind
=>
14019 if Present
(Spec_Entity
(E
)) then
14020 U
:= Spec_Entity
(E
);
14034 function Unique_Name
(E
: Entity_Id
) return String is
14036 -- Names of E_Subprogram_Body or E_Package_Body entities are not
14037 -- reliable, as they may not include the overloading suffix. Instead,
14038 -- when looking for the name of E or one of its enclosing scope, we get
14039 -- the name of the corresponding Unique_Entity.
14041 function Get_Scoped_Name
(E
: Entity_Id
) return String;
14042 -- Return the name of E prefixed by all the names of the scopes to which
14043 -- E belongs, except for Standard.
14045 ---------------------
14046 -- Get_Scoped_Name --
14047 ---------------------
14049 function Get_Scoped_Name
(E
: Entity_Id
) return String is
14050 Name
: constant String := Get_Name_String
(Chars
(E
));
14052 if Has_Fully_Qualified_Name
(E
)
14053 or else Scope
(E
) = Standard_Standard
14057 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
14059 end Get_Scoped_Name
;
14061 -- Start of processing for Unique_Name
14064 if E
= Standard_Standard
then
14065 return Get_Name_String
(Name_Standard
);
14067 elsif Scope
(E
) = Standard_Standard
14068 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
14070 return Get_Name_String
(Name_Standard
) & "__" &
14071 Get_Name_String
(Chars
(E
));
14073 elsif Ekind
(E
) = E_Enumeration_Literal
then
14074 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
14077 return Get_Scoped_Name
(Unique_Entity
(E
));
14081 ---------------------
14082 -- Unit_Is_Visible --
14083 ---------------------
14085 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
14086 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
14087 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
14089 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
14090 -- For a child unit, check whether unit appears in a with_clause
14093 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
14094 -- Scan the context clause of one compilation unit looking for a
14095 -- with_clause for the unit in question.
14097 ----------------------------
14098 -- Unit_In_Parent_Context --
14099 ----------------------------
14101 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
14103 if Unit_In_Context
(Par_Unit
) then
14106 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
14107 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
14112 end Unit_In_Parent_Context
;
14114 ---------------------
14115 -- Unit_In_Context --
14116 ---------------------
14118 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
14122 Clause
:= First
(Context_Items
(Comp_Unit
));
14123 while Present
(Clause
) loop
14124 if Nkind
(Clause
) = N_With_Clause
then
14125 if Library_Unit
(Clause
) = U
then
14128 -- The with_clause may denote a renaming of the unit we are
14129 -- looking for, eg. Text_IO which renames Ada.Text_IO.
14132 Renamed_Entity
(Entity
(Name
(Clause
))) =
14133 Defining_Entity
(Unit
(U
))
14143 end Unit_In_Context
;
14145 -- Start of processing for Unit_Is_Visible
14148 -- The currrent unit is directly visible
14153 elsif Unit_In_Context
(Curr
) then
14156 -- If the current unit is a body, check the context of the spec
14158 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
14160 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
14161 and then not Acts_As_Spec
(Unit
(Curr
)))
14163 if Unit_In_Context
(Library_Unit
(Curr
)) then
14168 -- If the spec is a child unit, examine the parents
14170 if Is_Child_Unit
(Curr_Entity
) then
14171 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
14173 Unit_In_Parent_Context
14174 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
14176 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
14182 end Unit_Is_Visible
;
14184 ------------------------------
14185 -- Universal_Interpretation --
14186 ------------------------------
14188 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
14189 Index
: Interp_Index
;
14193 -- The argument may be a formal parameter of an operator or subprogram
14194 -- with multiple interpretations, or else an expression for an actual.
14196 if Nkind
(Opnd
) = N_Defining_Identifier
14197 or else not Is_Overloaded
(Opnd
)
14199 if Etype
(Opnd
) = Universal_Integer
14200 or else Etype
(Opnd
) = Universal_Real
14202 return Etype
(Opnd
);
14208 Get_First_Interp
(Opnd
, Index
, It
);
14209 while Present
(It
.Typ
) loop
14210 if It
.Typ
= Universal_Integer
14211 or else It
.Typ
= Universal_Real
14216 Get_Next_Interp
(Index
, It
);
14221 end Universal_Interpretation
;
14227 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
14229 -- Recurse to handle unlikely case of multiple levels of qualification
14231 if Nkind
(Expr
) = N_Qualified_Expression
then
14232 return Unqualify
(Expression
(Expr
));
14234 -- Normal case, not a qualified expression
14241 -----------------------
14242 -- Visible_Ancestors --
14243 -----------------------
14245 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
14251 pragma Assert
(Is_Record_Type
(Typ
)
14252 and then Is_Tagged_Type
(Typ
));
14254 -- Collect all the parents and progenitors of Typ. If the full-view of
14255 -- private parents and progenitors is available then it is used to
14256 -- generate the list of visible ancestors; otherwise their partial
14257 -- view is added to the resulting list.
14262 Use_Full_View
=> True);
14266 Ifaces_List
=> List_2
,
14267 Exclude_Parents
=> True,
14268 Use_Full_View
=> True);
14270 -- Join the two lists. Avoid duplications because an interface may
14271 -- simultaneously be parent and progenitor of a type.
14273 Elmt
:= First_Elmt
(List_2
);
14274 while Present
(Elmt
) loop
14275 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
14280 end Visible_Ancestors
;
14282 ----------------------
14283 -- Within_Init_Proc --
14284 ----------------------
14286 function Within_Init_Proc
return Boolean is
14290 S
:= Current_Scope
;
14291 while not Is_Overloadable
(S
) loop
14292 if S
= Standard_Standard
then
14299 return Is_Init_Proc
(S
);
14300 end Within_Init_Proc
;
14306 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
14307 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
14308 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
14310 Matching_Field
: Entity_Id
;
14311 -- Entity to give a more precise suggestion on how to write a one-
14312 -- element positional aggregate.
14314 function Has_One_Matching_Field
return Boolean;
14315 -- Determines if Expec_Type is a record type with a single component or
14316 -- discriminant whose type matches the found type or is one dimensional
14317 -- array whose component type matches the found type. In the case of
14318 -- one discriminant, we ignore the variant parts. That's not accurate,
14319 -- but good enough for the warning.
14321 ----------------------------
14322 -- Has_One_Matching_Field --
14323 ----------------------------
14325 function Has_One_Matching_Field
return Boolean is
14329 Matching_Field
:= Empty
;
14331 if Is_Array_Type
(Expec_Type
)
14332 and then Number_Dimensions
(Expec_Type
) = 1
14334 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
14336 -- Use type name if available. This excludes multidimensional
14337 -- arrays and anonymous arrays.
14339 if Comes_From_Source
(Expec_Type
) then
14340 Matching_Field
:= Expec_Type
;
14342 -- For an assignment, use name of target
14344 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
14345 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
14347 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
14352 elsif not Is_Record_Type
(Expec_Type
) then
14356 E
:= First_Entity
(Expec_Type
);
14361 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
14362 or else (Chars
(E
) = Name_uTag
14364 Chars
(E
) = Name_uParent
)
14373 if not Covers
(Etype
(E
), Found_Type
) then
14376 elsif Present
(Next_Entity
(E
))
14377 and then (Ekind
(E
) = E_Component
14378 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
14383 Matching_Field
:= E
;
14387 end Has_One_Matching_Field
;
14389 -- Start of processing for Wrong_Type
14392 -- Don't output message if either type is Any_Type, or if a message
14393 -- has already been posted for this node. We need to do the latter
14394 -- check explicitly (it is ordinarily done in Errout), because we
14395 -- are using ! to force the output of the error messages.
14397 if Expec_Type
= Any_Type
14398 or else Found_Type
= Any_Type
14399 or else Error_Posted
(Expr
)
14403 -- If one of the types is a Taft-Amendment type and the other it its
14404 -- completion, it must be an illegal use of a TAT in the spec, for
14405 -- which an error was already emitted. Avoid cascaded errors.
14407 elsif Is_Incomplete_Type
(Expec_Type
)
14408 and then Has_Completion_In_Body
(Expec_Type
)
14409 and then Full_View
(Expec_Type
) = Etype
(Expr
)
14413 elsif Is_Incomplete_Type
(Etype
(Expr
))
14414 and then Has_Completion_In_Body
(Etype
(Expr
))
14415 and then Full_View
(Etype
(Expr
)) = Expec_Type
14419 -- In an instance, there is an ongoing problem with completion of
14420 -- type derived from private types. Their structure is what Gigi
14421 -- expects, but the Etype is the parent type rather than the
14422 -- derived private type itself. Do not flag error in this case. The
14423 -- private completion is an entity without a parent, like an Itype.
14424 -- Similarly, full and partial views may be incorrect in the instance.
14425 -- There is no simple way to insure that it is consistent ???
14427 elsif In_Instance
then
14428 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
14430 (Has_Private_Declaration
(Expected_Type
)
14431 or else Has_Private_Declaration
(Etype
(Expr
)))
14432 and then No
(Parent
(Expected_Type
))
14438 -- An interesting special check. If the expression is parenthesized
14439 -- and its type corresponds to the type of the sole component of the
14440 -- expected record type, or to the component type of the expected one
14441 -- dimensional array type, then assume we have a bad aggregate attempt.
14443 if Nkind
(Expr
) in N_Subexpr
14444 and then Paren_Count
(Expr
) /= 0
14445 and then Has_One_Matching_Field
14447 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
14448 if Present
(Matching_Field
) then
14449 if Is_Array_Type
(Expec_Type
) then
14451 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
14455 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
14459 -- Another special check, if we are looking for a pool-specific access
14460 -- type and we found an E_Access_Attribute_Type, then we have the case
14461 -- of an Access attribute being used in a context which needs a pool-
14462 -- specific type, which is never allowed. The one extra check we make
14463 -- is that the expected designated type covers the Found_Type.
14465 elsif Is_Access_Type
(Expec_Type
)
14466 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
14467 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
14468 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
14470 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
14472 Error_Msg_N
-- CODEFIX
14473 ("result must be general access type!", Expr
);
14474 Error_Msg_NE
-- CODEFIX
14475 ("add ALL to }!", Expr
, Expec_Type
);
14477 -- Another special check, if the expected type is an integer type,
14478 -- but the expression is of type System.Address, and the parent is
14479 -- an addition or subtraction operation whose left operand is the
14480 -- expression in question and whose right operand is of an integral
14481 -- type, then this is an attempt at address arithmetic, so give
14482 -- appropriate message.
14484 elsif Is_Integer_Type
(Expec_Type
)
14485 and then Is_RTE
(Found_Type
, RE_Address
)
14486 and then (Nkind
(Parent
(Expr
)) = N_Op_Add
14488 Nkind
(Parent
(Expr
)) = N_Op_Subtract
)
14489 and then Expr
= Left_Opnd
(Parent
(Expr
))
14490 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
14493 ("address arithmetic not predefined in package System",
14496 ("\possible missing with/use of System.Storage_Elements",
14500 -- If the expected type is an anonymous access type, as for access
14501 -- parameters and discriminants, the error is on the designated types.
14503 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
14504 if Comes_From_Source
(Expec_Type
) then
14505 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
14508 ("expected an access type with designated}",
14509 Expr
, Designated_Type
(Expec_Type
));
14512 if Is_Access_Type
(Found_Type
)
14513 and then not Comes_From_Source
(Found_Type
)
14516 ("\\found an access type with designated}!",
14517 Expr
, Designated_Type
(Found_Type
));
14519 if From_With_Type
(Found_Type
) then
14520 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
14521 Error_Msg_Qual_Level
:= 99;
14522 Error_Msg_NE
-- CODEFIX
14523 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
14524 Error_Msg_Qual_Level
:= 0;
14526 Error_Msg_NE
("found}!", Expr
, Found_Type
);
14530 -- Normal case of one type found, some other type expected
14533 -- If the names of the two types are the same, see if some number
14534 -- of levels of qualification will help. Don't try more than three
14535 -- levels, and if we get to standard, it's no use (and probably
14536 -- represents an error in the compiler) Also do not bother with
14537 -- internal scope names.
14540 Expec_Scope
: Entity_Id
;
14541 Found_Scope
: Entity_Id
;
14544 Expec_Scope
:= Expec_Type
;
14545 Found_Scope
:= Found_Type
;
14547 for Levels
in Int
range 0 .. 3 loop
14548 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
14549 Error_Msg_Qual_Level
:= Levels
;
14553 Expec_Scope
:= Scope
(Expec_Scope
);
14554 Found_Scope
:= Scope
(Found_Scope
);
14556 exit when Expec_Scope
= Standard_Standard
14557 or else Found_Scope
= Standard_Standard
14558 or else not Comes_From_Source
(Expec_Scope
)
14559 or else not Comes_From_Source
(Found_Scope
);
14563 if Is_Record_Type
(Expec_Type
)
14564 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
14566 Error_Msg_NE
("expected}!", Expr
,
14567 Corresponding_Remote_Type
(Expec_Type
));
14569 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
14572 if Is_Entity_Name
(Expr
)
14573 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
14575 Error_Msg_N
("\\found package name!", Expr
);
14577 elsif Is_Entity_Name
(Expr
)
14579 (Ekind
(Entity
(Expr
)) = E_Procedure
14581 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
14583 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
14585 ("found procedure name, possibly missing Access attribute!",
14589 ("\\found procedure name instead of function!", Expr
);
14592 elsif Nkind
(Expr
) = N_Function_Call
14593 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
14594 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
14595 and then No
(Parameter_Associations
(Expr
))
14598 ("found function name, possibly missing Access attribute!",
14601 -- Catch common error: a prefix or infix operator which is not
14602 -- directly visible because the type isn't.
14604 elsif Nkind
(Expr
) in N_Op
14605 and then Is_Overloaded
(Expr
)
14606 and then not Is_Immediately_Visible
(Expec_Type
)
14607 and then not Is_Potentially_Use_Visible
(Expec_Type
)
14608 and then not In_Use
(Expec_Type
)
14609 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
14612 ("operator of the type is not directly visible!", Expr
);
14614 elsif Ekind
(Found_Type
) = E_Void
14615 and then Present
(Parent
(Found_Type
))
14616 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
14618 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
14621 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
14624 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
14625 -- of the same modular type, and (M1 and M2) = 0 was intended.
14627 if Expec_Type
= Standard_Boolean
14628 and then Is_Modular_Integer_Type
(Found_Type
)
14629 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
14630 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
14633 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
14634 L
: constant Node_Id
:= Left_Opnd
(Op
);
14635 R
: constant Node_Id
:= Right_Opnd
(Op
);
14637 -- The case for the message is when the left operand of the
14638 -- comparison is the same modular type, or when it is an
14639 -- integer literal (or other universal integer expression),
14640 -- which would have been typed as the modular type if the
14641 -- parens had been there.
14643 if (Etype
(L
) = Found_Type
14645 Etype
(L
) = Universal_Integer
)
14646 and then Is_Integer_Type
(Etype
(R
))
14649 ("\\possible missing parens for modular operation", Expr
);
14654 -- Reset error message qualification indication
14656 Error_Msg_Qual_Level
:= 0;