1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Errout
; use Errout
;
32 with Elists
; use Elists
;
33 with Exp_Tss
; use Exp_Tss
;
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
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
42 with Output
; use Output
;
44 with Rtsfind
; use Rtsfind
;
45 with Scans
; use Scans
;
48 with Sem_Ch8
; use Sem_Ch8
;
49 with Sem_Eval
; use Sem_Eval
;
50 with Sem_Res
; use Sem_Res
;
51 with Sem_Type
; use Sem_Type
;
52 with Sinfo
; use Sinfo
;
53 with Sinput
; use Sinput
;
54 with Snames
; use Snames
;
55 with Stand
; use Stand
;
57 with Stringt
; use Stringt
;
58 with Targparm
; use Targparm
;
59 with Tbuild
; use Tbuild
;
60 with Ttypes
; use Ttypes
;
61 with Uname
; use Uname
;
63 package body Sem_Util
is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 function Build_Component_Subtype
72 T
: Entity_Id
) return Node_Id
;
73 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
74 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
75 -- Loc is the source location, T is the original subtype.
77 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
78 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
79 -- with discriminants whose default values are static, examine only the
80 -- components in the selected variant to determine whether all of them
83 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
84 -- T is a derived tagged type. Check whether the type extension is null.
85 -- If the parent type is fully initialized, T can be treated as such.
87 --------------------------------
88 -- Add_Access_Type_To_Process --
89 --------------------------------
91 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
95 Ensure_Freeze_Node
(E
);
96 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
100 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
104 end Add_Access_Type_To_Process
;
106 -----------------------
107 -- Alignment_In_Bits --
108 -----------------------
110 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
112 return Alignment
(E
) * System_Storage_Unit
;
113 end Alignment_In_Bits
;
115 -----------------------------------------
116 -- Apply_Compile_Time_Constraint_Error --
117 -----------------------------------------
119 procedure Apply_Compile_Time_Constraint_Error
122 Reason
: RT_Exception_Code
;
123 Ent
: Entity_Id
:= Empty
;
124 Typ
: Entity_Id
:= Empty
;
125 Loc
: Source_Ptr
:= No_Location
;
126 Rep
: Boolean := True;
127 Warn
: Boolean := False)
129 Stat
: constant Boolean := Is_Static_Expression
(N
);
140 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
146 -- Now we replace the node by an N_Raise_Constraint_Error node
147 -- This does not need reanalyzing, so set it as analyzed now.
150 Make_Raise_Constraint_Error
(Sloc
(N
),
152 Set_Analyzed
(N
, True);
154 Set_Raises_Constraint_Error
(N
);
156 -- If the original expression was marked as static, the result is
157 -- still marked as static, but the Raises_Constraint_Error flag is
158 -- always set so that further static evaluation is not attempted.
161 Set_Is_Static_Expression
(N
);
163 end Apply_Compile_Time_Constraint_Error
;
165 --------------------------
166 -- Build_Actual_Subtype --
167 --------------------------
169 function Build_Actual_Subtype
171 N
: Node_Or_Entity_Id
) return Node_Id
173 Loc
: constant Source_Ptr
:= Sloc
(N
);
174 Constraints
: List_Id
;
180 Disc_Type
: Entity_Id
;
184 if Nkind
(N
) = N_Defining_Identifier
then
185 Obj
:= New_Reference_To
(N
, Loc
);
190 if Is_Array_Type
(T
) then
191 Constraints
:= New_List
;
192 for J
in 1 .. Number_Dimensions
(T
) loop
194 -- Build an array subtype declaration with the nominal subtype and
195 -- the bounds of the actual. Add the declaration in front of the
196 -- local declarations for the subprogram, for analysis before any
197 -- reference to the formal in the body.
200 Make_Attribute_Reference
(Loc
,
202 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
203 Attribute_Name
=> Name_First
,
204 Expressions
=> New_List
(
205 Make_Integer_Literal
(Loc
, J
)));
208 Make_Attribute_Reference
(Loc
,
210 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
211 Attribute_Name
=> Name_Last
,
212 Expressions
=> New_List
(
213 Make_Integer_Literal
(Loc
, J
)));
215 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
218 -- If the type has unknown discriminants there is no constrained
219 -- subtype to build. This is never called for a formal or for a
220 -- lhs, so returning the type is ok ???
222 elsif Has_Unknown_Discriminants
(T
) then
226 Constraints
:= New_List
;
228 if Is_Private_Type
(T
) and then No
(Full_View
(T
)) then
230 -- Type is a generic derived type. Inherit discriminants from
233 Disc_Type
:= Etype
(Base_Type
(T
));
238 Discr
:= First_Discriminant
(Disc_Type
);
239 while Present
(Discr
) loop
240 Append_To
(Constraints
,
241 Make_Selected_Component
(Loc
,
243 Duplicate_Subexpr_No_Checks
(Obj
),
244 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
245 Next_Discriminant
(Discr
);
250 Make_Defining_Identifier
(Loc
,
251 Chars
=> New_Internal_Name
('S'));
252 Set_Is_Internal
(Subt
);
255 Make_Subtype_Declaration
(Loc
,
256 Defining_Identifier
=> Subt
,
257 Subtype_Indication
=>
258 Make_Subtype_Indication
(Loc
,
259 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
261 Make_Index_Or_Discriminant_Constraint
(Loc
,
262 Constraints
=> Constraints
)));
264 Mark_Rewrite_Insertion
(Decl
);
266 end Build_Actual_Subtype
;
268 ---------------------------------------
269 -- Build_Actual_Subtype_Of_Component --
270 ---------------------------------------
272 function Build_Actual_Subtype_Of_Component
274 N
: Node_Id
) return Node_Id
276 Loc
: constant Source_Ptr
:= Sloc
(N
);
277 P
: constant Node_Id
:= Prefix
(N
);
280 Indx_Type
: Entity_Id
;
282 Deaccessed_T
: Entity_Id
;
283 -- This is either a copy of T, or if T is an access type, then it is
284 -- the directly designated type of this access type.
286 function Build_Actual_Array_Constraint
return List_Id
;
287 -- If one or more of the bounds of the component depends on
288 -- discriminants, build actual constraint using the discriminants
291 function Build_Actual_Record_Constraint
return List_Id
;
292 -- Similar to previous one, for discriminated components constrained
293 -- by the discriminant of the enclosing object.
295 -----------------------------------
296 -- Build_Actual_Array_Constraint --
297 -----------------------------------
299 function Build_Actual_Array_Constraint
return List_Id
is
300 Constraints
: constant List_Id
:= New_List
;
308 Indx
:= First_Index
(Deaccessed_T
);
309 while Present
(Indx
) loop
310 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
311 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
313 if Denotes_Discriminant
(Old_Lo
) then
315 Make_Selected_Component
(Loc
,
316 Prefix
=> New_Copy_Tree
(P
),
317 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
320 Lo
:= New_Copy_Tree
(Old_Lo
);
322 -- The new bound will be reanalyzed in the enclosing
323 -- declaration. For literal bounds that come from a type
324 -- declaration, the type of the context must be imposed, so
325 -- insure that analysis will take place. For non-universal
326 -- types this is not strictly necessary.
328 Set_Analyzed
(Lo
, False);
331 if Denotes_Discriminant
(Old_Hi
) then
333 Make_Selected_Component
(Loc
,
334 Prefix
=> New_Copy_Tree
(P
),
335 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
338 Hi
:= New_Copy_Tree
(Old_Hi
);
339 Set_Analyzed
(Hi
, False);
342 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
347 end Build_Actual_Array_Constraint
;
349 ------------------------------------
350 -- Build_Actual_Record_Constraint --
351 ------------------------------------
353 function Build_Actual_Record_Constraint
return List_Id
is
354 Constraints
: constant List_Id
:= New_List
;
359 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
360 while Present
(D
) loop
361 if Denotes_Discriminant
(Node
(D
)) then
362 D_Val
:= Make_Selected_Component
(Loc
,
363 Prefix
=> New_Copy_Tree
(P
),
364 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
367 D_Val
:= New_Copy_Tree
(Node
(D
));
370 Append
(D_Val
, Constraints
);
375 end Build_Actual_Record_Constraint
;
377 -- Start of processing for Build_Actual_Subtype_Of_Component
380 if In_Default_Expression
then
383 elsif Nkind
(N
) = N_Explicit_Dereference
then
384 if Is_Composite_Type
(T
)
385 and then not Is_Constrained
(T
)
386 and then not (Is_Class_Wide_Type
(T
)
387 and then Is_Constrained
(Root_Type
(T
)))
388 and then not Has_Unknown_Discriminants
(T
)
390 -- If the type of the dereference is already constrained, it
391 -- is an actual subtype.
393 if Is_Array_Type
(Etype
(N
))
394 and then Is_Constrained
(Etype
(N
))
398 Remove_Side_Effects
(P
);
399 return Build_Actual_Subtype
(T
, N
);
406 if Ekind
(T
) = E_Access_Subtype
then
407 Deaccessed_T
:= Designated_Type
(T
);
412 if Ekind
(Deaccessed_T
) = E_Array_Subtype
then
413 Id
:= First_Index
(Deaccessed_T
);
414 while Present
(Id
) loop
415 Indx_Type
:= Underlying_Type
(Etype
(Id
));
417 if Denotes_Discriminant
(Type_Low_Bound
(Indx_Type
)) or else
418 Denotes_Discriminant
(Type_High_Bound
(Indx_Type
))
420 Remove_Side_Effects
(P
);
422 Build_Component_Subtype
(
423 Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
429 elsif Is_Composite_Type
(Deaccessed_T
)
430 and then Has_Discriminants
(Deaccessed_T
)
431 and then not Has_Unknown_Discriminants
(Deaccessed_T
)
433 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
434 while Present
(D
) loop
435 if Denotes_Discriminant
(Node
(D
)) then
436 Remove_Side_Effects
(P
);
438 Build_Component_Subtype
(
439 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
446 -- If none of the above, the actual and nominal subtypes are the same
449 end Build_Actual_Subtype_Of_Component
;
451 -----------------------------
452 -- Build_Component_Subtype --
453 -----------------------------
455 function Build_Component_Subtype
458 T
: Entity_Id
) return Node_Id
464 -- Unchecked_Union components do not require component subtypes
466 if Is_Unchecked_Union
(T
) then
471 Make_Defining_Identifier
(Loc
,
472 Chars
=> New_Internal_Name
('S'));
473 Set_Is_Internal
(Subt
);
476 Make_Subtype_Declaration
(Loc
,
477 Defining_Identifier
=> Subt
,
478 Subtype_Indication
=>
479 Make_Subtype_Indication
(Loc
,
480 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
482 Make_Index_Or_Discriminant_Constraint
(Loc
,
485 Mark_Rewrite_Insertion
(Decl
);
487 end Build_Component_Subtype
;
489 ---------------------------
490 -- Build_Default_Subtype --
491 ---------------------------
493 function Build_Default_Subtype
495 N
: Node_Id
) return Entity_Id
497 Loc
: constant Source_Ptr
:= Sloc
(N
);
501 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
505 Disc
:= First_Discriminant
(T
);
507 if No
(Discriminant_Default_Value
(Disc
)) then
512 Act
: constant Entity_Id
:=
513 Make_Defining_Identifier
(Loc
,
514 Chars
=> New_Internal_Name
('S'));
516 Constraints
: constant List_Id
:= New_List
;
520 while Present
(Disc
) loop
521 Append_To
(Constraints
,
522 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
523 Next_Discriminant
(Disc
);
527 Make_Subtype_Declaration
(Loc
,
528 Defining_Identifier
=> Act
,
529 Subtype_Indication
=>
530 Make_Subtype_Indication
(Loc
,
531 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
533 Make_Index_Or_Discriminant_Constraint
(Loc
,
534 Constraints
=> Constraints
)));
536 Insert_Action
(N
, Decl
);
540 end Build_Default_Subtype
;
542 --------------------------------------------
543 -- Build_Discriminal_Subtype_Of_Component --
544 --------------------------------------------
546 function Build_Discriminal_Subtype_Of_Component
547 (T
: Entity_Id
) return Node_Id
549 Loc
: constant Source_Ptr
:= Sloc
(T
);
553 function Build_Discriminal_Array_Constraint
return List_Id
;
554 -- If one or more of the bounds of the component depends on
555 -- discriminants, build actual constraint using the discriminants
558 function Build_Discriminal_Record_Constraint
return List_Id
;
559 -- Similar to previous one, for discriminated components constrained
560 -- by the discriminant of the enclosing object.
562 ----------------------------------------
563 -- Build_Discriminal_Array_Constraint --
564 ----------------------------------------
566 function Build_Discriminal_Array_Constraint
return List_Id
is
567 Constraints
: constant List_Id
:= New_List
;
575 Indx
:= First_Index
(T
);
576 while Present
(Indx
) loop
577 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
578 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
580 if Denotes_Discriminant
(Old_Lo
) then
581 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
584 Lo
:= New_Copy_Tree
(Old_Lo
);
587 if Denotes_Discriminant
(Old_Hi
) then
588 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
591 Hi
:= New_Copy_Tree
(Old_Hi
);
594 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
599 end Build_Discriminal_Array_Constraint
;
601 -----------------------------------------
602 -- Build_Discriminal_Record_Constraint --
603 -----------------------------------------
605 function Build_Discriminal_Record_Constraint
return List_Id
is
606 Constraints
: constant List_Id
:= New_List
;
611 D
:= First_Elmt
(Discriminant_Constraint
(T
));
612 while Present
(D
) loop
613 if Denotes_Discriminant
(Node
(D
)) then
615 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
618 D_Val
:= New_Copy_Tree
(Node
(D
));
621 Append
(D_Val
, Constraints
);
626 end Build_Discriminal_Record_Constraint
;
628 -- Start of processing for Build_Discriminal_Subtype_Of_Component
631 if Ekind
(T
) = E_Array_Subtype
then
632 Id
:= First_Index
(T
);
633 while Present
(Id
) loop
634 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
635 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
637 return Build_Component_Subtype
638 (Build_Discriminal_Array_Constraint
, Loc
, T
);
644 elsif Ekind
(T
) = E_Record_Subtype
645 and then Has_Discriminants
(T
)
646 and then not Has_Unknown_Discriminants
(T
)
648 D
:= First_Elmt
(Discriminant_Constraint
(T
));
649 while Present
(D
) loop
650 if Denotes_Discriminant
(Node
(D
)) then
651 return Build_Component_Subtype
652 (Build_Discriminal_Record_Constraint
, Loc
, T
);
659 -- If none of the above, the actual and nominal subtypes are the same
662 end Build_Discriminal_Subtype_Of_Component
;
664 ------------------------------
665 -- Build_Elaboration_Entity --
666 ------------------------------
668 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
669 Loc
: constant Source_Ptr
:= Sloc
(N
);
670 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
673 Elab_Ent
: Entity_Id
;
676 -- Ignore if already constructed
678 if Present
(Elaboration_Entity
(Spec_Id
)) then
682 -- Construct name of elaboration entity as xxx_E, where xxx
683 -- is the unit name with dots replaced by double underscore.
684 -- We have to manually construct this name, since it will
685 -- be elaborated in the outer scope, and thus will not have
686 -- the unit name automatically prepended.
688 Get_Name_String
(Unit_Name
(Unum
));
690 -- Replace the %s by _E
692 Name_Buffer
(Name_Len
- 1 .. Name_Len
) := "_E";
694 -- Replace dots by double underscore
697 while P
< Name_Len
- 2 loop
698 if Name_Buffer
(P
) = '.' then
699 Name_Buffer
(P
+ 2 .. Name_Len
+ 1) :=
700 Name_Buffer
(P
+ 1 .. Name_Len
);
701 Name_Len
:= Name_Len
+ 1;
702 Name_Buffer
(P
) := '_';
703 Name_Buffer
(P
+ 1) := '_';
710 -- Create elaboration flag
713 Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
714 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
716 if No
(Declarations
(Aux_Decls_Node
(N
))) then
717 Set_Declarations
(Aux_Decls_Node
(N
), New_List
);
721 Make_Object_Declaration
(Loc
,
722 Defining_Identifier
=> Elab_Ent
,
724 New_Occurrence_Of
(Standard_Boolean
, Loc
),
726 New_Occurrence_Of
(Standard_False
, Loc
));
728 Append_To
(Declarations
(Aux_Decls_Node
(N
)), Decl
);
731 -- Reset True_Constant indication, since we will indeed assign a value
732 -- to the variable in the binder main. We also kill the Current_Value
733 -- and Last_Assignment fields for the same reason.
735 Set_Is_True_Constant
(Elab_Ent
, False);
736 Set_Current_Value
(Elab_Ent
, Empty
);
737 Set_Last_Assignment
(Elab_Ent
, Empty
);
739 -- We do not want any further qualification of the name (if we did
740 -- not do this, we would pick up the name of the generic package
741 -- in the case of a library level generic instantiation).
743 Set_Has_Qualified_Name
(Elab_Ent
);
744 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
745 end Build_Elaboration_Entity
;
747 -----------------------------------
748 -- Cannot_Raise_Constraint_Error --
749 -----------------------------------
751 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
753 if Compile_Time_Known_Value
(Expr
) then
756 elsif Do_Range_Check
(Expr
) then
759 elsif Raises_Constraint_Error
(Expr
) then
767 when N_Expanded_Name
=>
770 when N_Selected_Component
=>
771 return not Do_Discriminant_Check
(Expr
);
773 when N_Attribute_Reference
=>
774 if Do_Overflow_Check
(Expr
) then
777 elsif No
(Expressions
(Expr
)) then
785 N
:= First
(Expressions
(Expr
));
786 while Present
(N
) loop
787 if Cannot_Raise_Constraint_Error
(N
) then
798 when N_Type_Conversion
=>
799 if Do_Overflow_Check
(Expr
)
800 or else Do_Length_Check
(Expr
)
801 or else Do_Tag_Check
(Expr
)
806 Cannot_Raise_Constraint_Error
(Expression
(Expr
));
809 when N_Unchecked_Type_Conversion
=>
810 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
813 if Do_Overflow_Check
(Expr
) then
817 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
824 if Do_Division_Check
(Expr
)
825 or else Do_Overflow_Check
(Expr
)
830 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
832 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
851 N_Op_Shift_Right_Arithmetic |
855 if Do_Overflow_Check
(Expr
) then
859 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
861 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
868 end Cannot_Raise_Constraint_Error
;
870 --------------------------
871 -- Check_Fully_Declared --
872 --------------------------
874 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
876 if Ekind
(T
) = E_Incomplete_Type
then
878 -- Ada 2005 (AI-50217): If the type is available through a limited
879 -- with_clause, verify that its full view has been analyzed.
881 if From_With_Type
(T
)
882 and then Present
(Non_Limited_View
(T
))
883 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
885 -- The non-limited view is fully declared
890 ("premature usage of incomplete}", N
, First_Subtype
(T
));
893 elsif Has_Private_Component
(T
)
894 and then not Is_Generic_Type
(Root_Type
(T
))
895 and then not In_Default_Expression
898 -- Special case: if T is the anonymous type created for a single
899 -- task or protected object, use the name of the source object.
901 if Is_Concurrent_Type
(T
)
902 and then not Comes_From_Source
(T
)
903 and then Nkind
(N
) = N_Object_Declaration
905 Error_Msg_NE
("type of& has incomplete component", N
,
906 Defining_Identifier
(N
));
910 ("premature usage of incomplete}", N
, First_Subtype
(T
));
913 end Check_Fully_Declared
;
915 ------------------------------------------
916 -- Check_Potentially_Blocking_Operation --
917 ------------------------------------------
919 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
923 -- N is one of the potentially blocking operations listed in 9.5.1(8).
924 -- When pragma Detect_Blocking is active, the run time will raise
925 -- Program_Error. Here we only issue a warning, since we generally
926 -- support the use of potentially blocking operations in the absence
929 -- Indirect blocking through a subprogram call cannot be diagnosed
930 -- statically without interprocedural analysis, so we do not attempt
933 S
:= Scope
(Current_Scope
);
934 while Present
(S
) and then S
/= Standard_Standard
loop
935 if Is_Protected_Type
(S
) then
937 ("potentially blocking operation in protected operation?", N
);
944 end Check_Potentially_Blocking_Operation
;
950 procedure Check_VMS
(Construct
: Node_Id
) is
952 if not OpenVMS_On_Target
then
954 ("this construct is allowed only in Open'V'M'S", Construct
);
958 ---------------------------------
959 -- Collect_Abstract_Interfaces --
960 ---------------------------------
962 procedure Collect_Abstract_Interfaces
964 Ifaces_List
: out Elist_Id
;
965 Exclude_Parent_Interfaces
: Boolean := False)
967 procedure Add_Interface
(Iface
: Entity_Id
);
968 -- Add the interface it if is not already in the list
970 procedure Collect
(Typ
: Entity_Id
);
971 -- Subsidiary subprogram used to traverse the whole list
972 -- of directly and indirectly implemented interfaces
978 procedure Add_Interface
(Iface
: Entity_Id
) is
982 Elmt
:= First_Elmt
(Ifaces_List
);
983 while Present
(Elmt
) and then Node
(Elmt
) /= Iface
loop
988 Append_Elmt
(Iface
, Ifaces_List
);
996 procedure Collect
(Typ
: Entity_Id
) is
997 Ancestor
: Entity_Id
;
1003 if Ekind
(Typ
) = E_Record_Type_With_Private
then
1004 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
1005 Nod
:= Type_Definition
(Parent
(Typ
));
1007 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
1008 if Present
(Full_View
(Typ
)) then
1009 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
1011 -- If the full-view is not available we cannot do anything
1012 -- else here (the source has errors)
1018 -- The support for generic formals with interfaces is still
1021 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
1026 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
1027 Nod
:= Parent
(Typ
);
1030 elsif Ekind
(Typ
) = E_Record_Subtype
then
1031 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
1033 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
1034 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
1035 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
1037 Nod
:= Type_Definition
(Parent
(Typ
));
1041 -- Include the ancestor if we are generating the whole list of
1042 -- abstract interfaces.
1044 if Etype
(Typ
) /= Typ
1046 -- Protect the frontend against wrong sources. For example:
1049 -- type A is tagged null record;
1050 -- type B is new A with private;
1051 -- type C is new A with private;
1053 -- type B is new C with null record;
1054 -- type C is new B with null record;
1057 and then Etype
(Typ
) /= T
1059 Ancestor
:= Etype
(Typ
);
1062 if Is_Interface
(Ancestor
)
1063 and then not Exclude_Parent_Interfaces
1065 Add_Interface
(Ancestor
);
1069 -- Traverse the graph of ancestor interfaces
1071 if Is_Non_Empty_List
(Interface_List
(Nod
)) then
1072 Id
:= First
(Interface_List
(Nod
));
1073 while Present
(Id
) loop
1074 Iface
:= Etype
(Id
);
1076 -- Protect against wrong uses. For example:
1077 -- type I is interface;
1078 -- type O is tagged null record;
1079 -- type Wrong is new I and O with null record; -- ERROR
1081 if Is_Interface
(Iface
) then
1082 if Exclude_Parent_Interfaces
1083 and then Interface_Present_In_Ancestor
(T
, Iface
)
1088 Add_Interface
(Iface
);
1097 -- Start of processing for Collect_Abstract_Interfaces
1100 pragma Assert
(Is_Tagged_Type
(T
));
1101 Ifaces_List
:= New_Elmt_List
;
1103 end Collect_Abstract_Interfaces
;
1105 ----------------------------------
1106 -- Collect_Primitive_Operations --
1107 ----------------------------------
1109 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
1110 B_Type
: constant Entity_Id
:= Base_Type
(T
);
1111 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
1112 B_Scope
: Entity_Id
:= Scope
(B_Type
);
1116 Formal_Derived
: Boolean := False;
1120 -- For tagged types, the primitive operations are collected as they
1121 -- are declared, and held in an explicit list which is simply returned.
1123 if Is_Tagged_Type
(B_Type
) then
1124 return Primitive_Operations
(B_Type
);
1126 -- An untagged generic type that is a derived type inherits the
1127 -- primitive operations of its parent type. Other formal types only
1128 -- have predefined operators, which are not explicitly represented.
1130 elsif Is_Generic_Type
(B_Type
) then
1131 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
1132 and then Nkind
(Formal_Type_Definition
(B_Decl
))
1133 = N_Formal_Derived_Type_Definition
1135 Formal_Derived
:= True;
1137 return New_Elmt_List
;
1141 Op_List
:= New_Elmt_List
;
1143 if B_Scope
= Standard_Standard
then
1144 if B_Type
= Standard_String
then
1145 Append_Elmt
(Standard_Op_Concat
, Op_List
);
1147 elsif B_Type
= Standard_Wide_String
then
1148 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
1154 elsif (Is_Package_Or_Generic_Package
(B_Scope
)
1156 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
1158 or else Is_Derived_Type
(B_Type
)
1160 -- The primitive operations appear after the base type, except
1161 -- if the derivation happens within the private part of B_Scope
1162 -- and the type is a private type, in which case both the type
1163 -- and some primitive operations may appear before the base
1164 -- type, and the list of candidates starts after the type.
1166 if In_Open_Scopes
(B_Scope
)
1167 and then Scope
(T
) = B_Scope
1168 and then In_Private_Part
(B_Scope
)
1170 Id
:= Next_Entity
(T
);
1172 Id
:= Next_Entity
(B_Type
);
1175 while Present
(Id
) loop
1177 -- Note that generic formal subprograms are not
1178 -- considered to be primitive operations and thus
1179 -- are never inherited.
1181 if Is_Overloadable
(Id
)
1182 and then Nkind
(Parent
(Parent
(Id
)))
1183 not in N_Formal_Subprogram_Declaration
1187 if Base_Type
(Etype
(Id
)) = B_Type
then
1190 Formal
:= First_Formal
(Id
);
1191 while Present
(Formal
) loop
1192 if Base_Type
(Etype
(Formal
)) = B_Type
then
1196 elsif Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
1198 (Designated_Type
(Etype
(Formal
))) = B_Type
1204 Next_Formal
(Formal
);
1208 -- For a formal derived type, the only primitives are the
1209 -- ones inherited from the parent type. Operations appearing
1210 -- in the package declaration are not primitive for it.
1213 and then (not Formal_Derived
1214 or else Present
(Alias
(Id
)))
1216 Append_Elmt
(Id
, Op_List
);
1222 -- For a type declared in System, some of its operations
1223 -- may appear in the target-specific extension to System.
1226 and then Chars
(B_Scope
) = Name_System
1227 and then Scope
(B_Scope
) = Standard_Standard
1228 and then Present_System_Aux
1230 B_Scope
:= System_Aux_Id
;
1231 Id
:= First_Entity
(System_Aux_Id
);
1237 end Collect_Primitive_Operations
;
1239 -------------------------------------
1240 -- Collect_Synchronized_Interfaces --
1241 -------------------------------------
1243 procedure Collect_Synchronized_Interfaces
1245 Ifaces_List
: out Elist_Id
)
1249 procedure Collect
(Typ
: Entity_Id
);
1250 -- Gather any parent or progenitor interfaces of type Typ
1256 procedure Collect
(Typ
: Entity_Id
) is
1257 Iface_Elmt
: Elmt_Id
;
1259 procedure Add
(Iface
: Entity_Id
);
1260 -- Add a single interface to list Ifaces if the interface is
1261 -- not already in the list.
1267 procedure Add
(Iface
: Entity_Id
) is
1268 Iface_Elmt
: Elmt_Id
;
1271 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
1272 while Present
(Iface_Elmt
)
1273 and then Node
(Iface_Elmt
) /= Iface
1275 Next_Elmt
(Iface_Elmt
);
1278 if No
(Iface_Elmt
) then
1279 Append_Elmt
(Iface
, Ifaces_List
);
1283 -- Start of processing for Collect
1286 if Is_Interface
(Typ
) then
1288 -- Potential parent interface
1290 if Etype
(Typ
) /= Typ
then
1291 Collect
(Etype
(Typ
));
1296 if Present
(Abstract_Interfaces
(Typ
)) then
1297 Iface_Elmt
:= First_Elmt
(Abstract_Interfaces
(Typ
));
1298 while Present
(Iface_Elmt
) loop
1299 Collect
(Node
(Iface_Elmt
));
1300 Next_Elmt
(Iface_Elmt
);
1308 -- Start of processing for Collect_Synchronized_Interfaces
1311 pragma Assert
(Is_Concurrent_Type
(Typ
));
1313 Ifaces_List
:= New_Elmt_List
;
1315 if Present
(Interface_List
(Parent
(Typ
))) then
1316 Iface
:= First
(Interface_List
(Parent
(Typ
)));
1317 while Present
(Iface
) loop
1318 Collect
(Etype
(Iface
));
1323 end Collect_Synchronized_Interfaces
;
1325 -----------------------------------
1326 -- Compile_Time_Constraint_Error --
1327 -----------------------------------
1329 function Compile_Time_Constraint_Error
1332 Ent
: Entity_Id
:= Empty
;
1333 Loc
: Source_Ptr
:= No_Location
;
1334 Warn
: Boolean := False) return Node_Id
1336 Msgc
: String (1 .. Msg
'Length + 2);
1345 -- A static constraint error in an instance body is not a fatal error.
1346 -- we choose to inhibit the message altogether, because there is no
1347 -- obvious node (for now) on which to post it. On the other hand the
1348 -- offending node must be replaced with a constraint_error in any case.
1350 -- No messages are generated if we already posted an error on this node
1352 if not Error_Posted
(N
) then
1353 if Loc
/= No_Location
then
1359 -- Make all such messages unconditional
1361 Msgc
(1 .. Msg
'Length) := Msg
;
1362 Msgc
(Msg
'Length + 1) := '!';
1363 Msgl
:= Msg
'Length + 1;
1365 -- Message is a warning, even in Ada 95 case
1367 if Msg
(Msg
'Last) = '?' then
1370 -- In Ada 83, all messages are warnings. In the private part and
1371 -- the body of an instance, constraint_checks are only warnings.
1372 -- We also make this a warning if the Warn parameter is set.
1375 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
1381 elsif In_Instance_Not_Visible
then
1386 -- Otherwise we have a real error message (Ada 95 static case)
1392 -- Should we generate a warning? The answer is not quite yes. The
1393 -- very annoying exception occurs in the case of a short circuit
1394 -- operator where the left operand is static and decisive. Climb
1395 -- parents to see if that is the case we have here. Conditional
1396 -- expressions with decisive conditions are a similar situation.
1404 -- And then with False as left operand
1406 if Nkind
(P
) = N_And_Then
1407 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1408 and then Is_False
(Expr_Value
(Left_Opnd
(P
)))
1413 -- OR ELSE with True as left operand
1415 elsif Nkind
(P
) = N_Or_Else
1416 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1417 and then Is_True
(Expr_Value
(Left_Opnd
(P
)))
1422 -- Conditional expression
1424 elsif Nkind
(P
) = N_Conditional_Expression
then
1426 Cond
: constant Node_Id
:= First
(Expressions
(P
));
1427 Texp
: constant Node_Id
:= Next
(Cond
);
1428 Fexp
: constant Node_Id
:= Next
(Texp
);
1431 if Compile_Time_Known_Value
(Cond
) then
1433 -- Condition is True and we are in the right operand
1435 if Is_True
(Expr_Value
(Cond
))
1436 and then OldP
= Fexp
1441 -- Condition is False and we are in the left operand
1443 elsif Is_False
(Expr_Value
(Cond
))
1444 and then OldP
= Texp
1452 -- Special case for component association in aggregates, where
1453 -- we want to keep climbing up to the parent aggregate.
1455 elsif Nkind
(P
) = N_Component_Association
1456 and then Nkind
(Parent
(P
)) = N_Aggregate
1460 -- Keep going if within subexpression
1463 exit when Nkind
(P
) not in N_Subexpr
;
1468 if Present
(Ent
) then
1469 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
1471 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
1475 if Inside_Init_Proc
then
1477 ("\?& will be raised for objects of this type",
1478 N
, Standard_Constraint_Error
, Eloc
);
1481 ("\?& will be raised at run time",
1482 N
, Standard_Constraint_Error
, Eloc
);
1487 ("\static expression fails Constraint_Check", Eloc
);
1488 Set_Error_Posted
(N
);
1494 end Compile_Time_Constraint_Error
;
1496 -----------------------
1497 -- Conditional_Delay --
1498 -----------------------
1500 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
1502 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
1503 Set_Has_Delayed_Freeze
(New_Ent
);
1505 end Conditional_Delay
;
1507 --------------------
1508 -- Current_Entity --
1509 --------------------
1511 -- The currently visible definition for a given identifier is the
1512 -- one most chained at the start of the visibility chain, i.e. the
1513 -- one that is referenced by the Node_Id value of the name of the
1514 -- given identifier.
1516 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
1518 return Get_Name_Entity_Id
(Chars
(N
));
1521 -----------------------------
1522 -- Current_Entity_In_Scope --
1523 -----------------------------
1525 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
1527 CS
: constant Entity_Id
:= Current_Scope
;
1529 Transient_Case
: constant Boolean := Scope_Is_Transient
;
1532 E
:= Get_Name_Entity_Id
(Chars
(N
));
1534 and then Scope
(E
) /= CS
1535 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
1541 end Current_Entity_In_Scope
;
1547 function Current_Scope
return Entity_Id
is
1549 if Scope_Stack
.Last
= -1 then
1550 return Standard_Standard
;
1553 C
: constant Entity_Id
:=
1554 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
1559 return Standard_Standard
;
1565 ------------------------
1566 -- Current_Subprogram --
1567 ------------------------
1569 function Current_Subprogram
return Entity_Id
is
1570 Scop
: constant Entity_Id
:= Current_Scope
;
1573 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
1576 return Enclosing_Subprogram
(Scop
);
1578 end Current_Subprogram
;
1580 ---------------------
1581 -- Defining_Entity --
1582 ---------------------
1584 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
1585 K
: constant Node_Kind
:= Nkind
(N
);
1586 Err
: Entity_Id
:= Empty
;
1591 N_Subprogram_Declaration |
1592 N_Abstract_Subprogram_Declaration |
1594 N_Package_Declaration |
1595 N_Subprogram_Renaming_Declaration |
1596 N_Subprogram_Body_Stub |
1597 N_Generic_Subprogram_Declaration |
1598 N_Generic_Package_Declaration |
1599 N_Formal_Subprogram_Declaration
1601 return Defining_Entity
(Specification
(N
));
1604 N_Component_Declaration |
1605 N_Defining_Program_Unit_Name |
1606 N_Discriminant_Specification |
1608 N_Entry_Declaration |
1609 N_Entry_Index_Specification |
1610 N_Exception_Declaration |
1611 N_Exception_Renaming_Declaration |
1612 N_Formal_Object_Declaration |
1613 N_Formal_Package_Declaration |
1614 N_Formal_Type_Declaration |
1615 N_Full_Type_Declaration |
1616 N_Implicit_Label_Declaration |
1617 N_Incomplete_Type_Declaration |
1618 N_Loop_Parameter_Specification |
1619 N_Number_Declaration |
1620 N_Object_Declaration |
1621 N_Object_Renaming_Declaration |
1622 N_Package_Body_Stub |
1623 N_Parameter_Specification |
1624 N_Private_Extension_Declaration |
1625 N_Private_Type_Declaration |
1627 N_Protected_Body_Stub |
1628 N_Protected_Type_Declaration |
1629 N_Single_Protected_Declaration |
1630 N_Single_Task_Declaration |
1631 N_Subtype_Declaration |
1634 N_Task_Type_Declaration
1636 return Defining_Identifier
(N
);
1639 return Defining_Entity
(Proper_Body
(N
));
1642 N_Function_Instantiation |
1643 N_Function_Specification |
1644 N_Generic_Function_Renaming_Declaration |
1645 N_Generic_Package_Renaming_Declaration |
1646 N_Generic_Procedure_Renaming_Declaration |
1648 N_Package_Instantiation |
1649 N_Package_Renaming_Declaration |
1650 N_Package_Specification |
1651 N_Procedure_Instantiation |
1652 N_Procedure_Specification
1655 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
1658 if Nkind
(Nam
) in N_Entity
then
1661 -- For Error, make up a name and attach to declaration
1662 -- so we can continue semantic analysis
1664 elsif Nam
= Error
then
1666 Make_Defining_Identifier
(Sloc
(N
),
1667 Chars
=> New_Internal_Name
('T'));
1668 Set_Defining_Unit_Name
(N
, Err
);
1671 -- If not an entity, get defining identifier
1674 return Defining_Identifier
(Nam
);
1678 when N_Block_Statement
=>
1679 return Entity
(Identifier
(N
));
1682 raise Program_Error
;
1685 end Defining_Entity
;
1687 --------------------------
1688 -- Denotes_Discriminant --
1689 --------------------------
1691 function Denotes_Discriminant
1693 Check_Concurrent
: Boolean := False) return Boolean
1697 if not Is_Entity_Name
(N
)
1698 or else No
(Entity
(N
))
1705 -- If we are checking for a protected type, the discriminant may have
1706 -- been rewritten as the corresponding discriminal of the original type
1707 -- or of the corresponding concurrent record, depending on whether we
1708 -- are in the spec or body of the protected type.
1710 return Ekind
(E
) = E_Discriminant
1713 and then Ekind
(E
) = E_In_Parameter
1714 and then Present
(Discriminal_Link
(E
))
1716 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
1718 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
1720 end Denotes_Discriminant
;
1722 -----------------------------
1723 -- Depends_On_Discriminant --
1724 -----------------------------
1726 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
1731 Get_Index_Bounds
(N
, L
, H
);
1732 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
1733 end Depends_On_Discriminant
;
1735 -------------------------
1736 -- Designate_Same_Unit --
1737 -------------------------
1739 function Designate_Same_Unit
1741 Name2
: Node_Id
) return Boolean
1743 K1
: constant Node_Kind
:= Nkind
(Name1
);
1744 K2
: constant Node_Kind
:= Nkind
(Name2
);
1746 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
1747 -- Returns the parent unit name node of a defining program unit name
1748 -- or the prefix if N is a selected component or an expanded name.
1750 function Select_Node
(N
: Node_Id
) return Node_Id
;
1751 -- Returns the defining identifier node of a defining program unit
1752 -- name or the selector node if N is a selected component or an
1759 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
1761 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
1773 function Select_Node
(N
: Node_Id
) return Node_Id
is
1775 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
1776 return Defining_Identifier
(N
);
1779 return Selector_Name
(N
);
1783 -- Start of processing for Designate_Next_Unit
1786 if (K1
= N_Identifier
or else
1787 K1
= N_Defining_Identifier
)
1789 (K2
= N_Identifier
or else
1790 K2
= N_Defining_Identifier
)
1792 return Chars
(Name1
) = Chars
(Name2
);
1795 (K1
= N_Expanded_Name
or else
1796 K1
= N_Selected_Component
or else
1797 K1
= N_Defining_Program_Unit_Name
)
1799 (K2
= N_Expanded_Name
or else
1800 K2
= N_Selected_Component
or else
1801 K2
= N_Defining_Program_Unit_Name
)
1804 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
1806 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
1811 end Designate_Same_Unit
;
1813 ----------------------------
1814 -- Enclosing_Generic_Body --
1815 ----------------------------
1817 function Enclosing_Generic_Body
1818 (N
: Node_Id
) return Node_Id
1826 while Present
(P
) loop
1827 if Nkind
(P
) = N_Package_Body
1828 or else Nkind
(P
) = N_Subprogram_Body
1830 Spec
:= Corresponding_Spec
(P
);
1832 if Present
(Spec
) then
1833 Decl
:= Unit_Declaration_Node
(Spec
);
1835 if Nkind
(Decl
) = N_Generic_Package_Declaration
1836 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
1847 end Enclosing_Generic_Body
;
1849 ----------------------------
1850 -- Enclosing_Generic_Unit --
1851 ----------------------------
1853 function Enclosing_Generic_Unit
1854 (N
: Node_Id
) return Node_Id
1862 while Present
(P
) loop
1863 if Nkind
(P
) = N_Generic_Package_Declaration
1864 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
1868 elsif Nkind
(P
) = N_Package_Body
1869 or else Nkind
(P
) = N_Subprogram_Body
1871 Spec
:= Corresponding_Spec
(P
);
1873 if Present
(Spec
) then
1874 Decl
:= Unit_Declaration_Node
(Spec
);
1876 if Nkind
(Decl
) = N_Generic_Package_Declaration
1877 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
1888 end Enclosing_Generic_Unit
;
1890 -------------------------------
1891 -- Enclosing_Lib_Unit_Entity --
1892 -------------------------------
1894 function Enclosing_Lib_Unit_Entity
return Entity_Id
is
1895 Unit_Entity
: Entity_Id
;
1898 -- Look for enclosing library unit entity by following scope links.
1899 -- Equivalent to, but faster than indexing through the scope stack.
1901 Unit_Entity
:= Current_Scope
;
1902 while (Present
(Scope
(Unit_Entity
))
1903 and then Scope
(Unit_Entity
) /= Standard_Standard
)
1904 and not Is_Child_Unit
(Unit_Entity
)
1906 Unit_Entity
:= Scope
(Unit_Entity
);
1910 end Enclosing_Lib_Unit_Entity
;
1912 -----------------------------
1913 -- Enclosing_Lib_Unit_Node --
1914 -----------------------------
1916 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
1917 Current_Node
: Node_Id
;
1921 while Present
(Current_Node
)
1922 and then Nkind
(Current_Node
) /= N_Compilation_Unit
1924 Current_Node
:= Parent
(Current_Node
);
1927 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
1931 return Current_Node
;
1932 end Enclosing_Lib_Unit_Node
;
1934 --------------------------
1935 -- Enclosing_Subprogram --
1936 --------------------------
1938 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
1939 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
1942 if Dynamic_Scope
= Standard_Standard
then
1945 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
1946 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
1948 elsif Ekind
(Dynamic_Scope
) = E_Block
then
1949 return Enclosing_Subprogram
(Dynamic_Scope
);
1951 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
1952 return Get_Task_Body_Procedure
(Dynamic_Scope
);
1954 elsif Convention
(Dynamic_Scope
) = Convention_Protected
then
1955 return Protected_Body_Subprogram
(Dynamic_Scope
);
1958 return Dynamic_Scope
;
1960 end Enclosing_Subprogram
;
1962 ------------------------
1963 -- Ensure_Freeze_Node --
1964 ------------------------
1966 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
1970 if No
(Freeze_Node
(E
)) then
1971 FN
:= Make_Freeze_Entity
(Sloc
(E
));
1972 Set_Has_Delayed_Freeze
(E
);
1973 Set_Freeze_Node
(E
, FN
);
1974 Set_Access_Types_To_Process
(FN
, No_Elist
);
1975 Set_TSS_Elist
(FN
, No_Elist
);
1978 end Ensure_Freeze_Node
;
1984 procedure Enter_Name
(Def_Id
: Entity_Id
) is
1985 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
1986 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
1987 S
: constant Entity_Id
:= Current_Scope
;
1989 function Is_Private_Component_Renaming
(N
: Node_Id
) return Boolean;
1990 -- Recognize a renaming declaration that is introduced for private
1991 -- components of a protected type. We treat these as weak declarations
1992 -- so that they are overridden by entities with the same name that
1993 -- come from source, such as formals or local variables of a given
1994 -- protected declaration.
1996 -----------------------------------
1997 -- Is_Private_Component_Renaming --
1998 -----------------------------------
2000 function Is_Private_Component_Renaming
(N
: Node_Id
) return Boolean is
2002 return not Comes_From_Source
(N
)
2003 and then not Comes_From_Source
(Current_Scope
)
2004 and then Nkind
(N
) = N_Object_Renaming_Declaration
;
2005 end Is_Private_Component_Renaming
;
2007 -- Start of processing for Enter_Name
2010 Generate_Definition
(Def_Id
);
2012 -- Add new name to current scope declarations. Check for duplicate
2013 -- declaration, which may or may not be a genuine error.
2017 -- Case of previous entity entered because of a missing declaration
2018 -- or else a bad subtype indication. Best is to use the new entity,
2019 -- and make the previous one invisible.
2021 if Etype
(E
) = Any_Type
then
2022 Set_Is_Immediately_Visible
(E
, False);
2024 -- Case of renaming declaration constructed for package instances.
2025 -- if there is an explicit declaration with the same identifier,
2026 -- the renaming is not immediately visible any longer, but remains
2027 -- visible through selected component notation.
2029 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
2030 and then not Comes_From_Source
(E
)
2032 Set_Is_Immediately_Visible
(E
, False);
2034 -- The new entity may be the package renaming, which has the same
2035 -- same name as a generic formal which has been seen already.
2037 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
2038 and then not Comes_From_Source
(Def_Id
)
2040 Set_Is_Immediately_Visible
(E
, False);
2042 -- For a fat pointer corresponding to a remote access to subprogram,
2043 -- we use the same identifier as the RAS type, so that the proper
2044 -- name appears in the stub. This type is only retrieved through
2045 -- the RAS type and never by visibility, and is not added to the
2046 -- visibility list (see below).
2048 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
2049 and then Present
(Corresponding_Remote_Type
(Def_Id
))
2053 -- A controller component for a type extension overrides the
2054 -- inherited component.
2056 elsif Chars
(E
) = Name_uController
then
2059 -- Case of an implicit operation or derived literal. The new entity
2060 -- hides the implicit one, which is removed from all visibility,
2061 -- i.e. the entity list of its scope, and homonym chain of its name.
2063 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
2064 or else Is_Internal
(E
)
2068 Prev_Vis
: Entity_Id
;
2069 Decl
: constant Node_Id
:= Parent
(E
);
2072 -- If E is an implicit declaration, it cannot be the first
2073 -- entity in the scope.
2075 Prev
:= First_Entity
(Current_Scope
);
2076 while Present
(Prev
)
2077 and then Next_Entity
(Prev
) /= E
2084 -- If E is not on the entity chain of the current scope,
2085 -- it is an implicit declaration in the generic formal
2086 -- part of a generic subprogram. When analyzing the body,
2087 -- the generic formals are visible but not on the entity
2088 -- chain of the subprogram. The new entity will become
2089 -- the visible one in the body.
2092 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
2096 Set_Next_Entity
(Prev
, Next_Entity
(E
));
2098 if No
(Next_Entity
(Prev
)) then
2099 Set_Last_Entity
(Current_Scope
, Prev
);
2102 if E
= Current_Entity
(E
) then
2106 Prev_Vis
:= Current_Entity
(E
);
2107 while Homonym
(Prev_Vis
) /= E
loop
2108 Prev_Vis
:= Homonym
(Prev_Vis
);
2112 if Present
(Prev_Vis
) then
2114 -- Skip E in the visibility chain
2116 Set_Homonym
(Prev_Vis
, Homonym
(E
));
2119 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
2124 -- This section of code could use a comment ???
2126 elsif Present
(Etype
(E
))
2127 and then Is_Concurrent_Type
(Etype
(E
))
2132 elsif Is_Private_Component_Renaming
(Parent
(Def_Id
)) then
2135 -- In the body or private part of an instance, a type extension
2136 -- may introduce a component with the same name as that of an
2137 -- actual. The legality rule is not enforced, but the semantics
2138 -- of the full type with two components of the same name are not
2139 -- clear at this point ???
2141 elsif In_Instance_Not_Visible
then
2144 -- When compiling a package body, some child units may have become
2145 -- visible. They cannot conflict with local entities that hide them.
2147 elsif Is_Child_Unit
(E
)
2148 and then In_Open_Scopes
(Scope
(E
))
2149 and then not Is_Immediately_Visible
(E
)
2153 -- Conversely, with front-end inlining we may compile the parent
2154 -- body first, and a child unit subsequently. The context is now
2155 -- the parent spec, and body entities are not visible.
2157 elsif Is_Child_Unit
(Def_Id
)
2158 and then Is_Package_Body_Entity
(E
)
2159 and then not In_Package_Body
(Current_Scope
)
2163 -- Case of genuine duplicate declaration
2166 Error_Msg_Sloc
:= Sloc
(E
);
2168 -- If the previous declaration is an incomplete type declaration
2169 -- this may be an attempt to complete it with a private type.
2170 -- The following avoids confusing cascaded errors.
2172 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
2173 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
2176 ("incomplete type cannot be completed" &
2177 " with a private declaration",
2179 Set_Is_Immediately_Visible
(E
, False);
2180 Set_Full_View
(E
, Def_Id
);
2182 elsif Ekind
(E
) = E_Discriminant
2183 and then Present
(Scope
(Def_Id
))
2184 and then Scope
(Def_Id
) /= Current_Scope
2186 -- An inherited component of a record conflicts with
2187 -- a new discriminant. The discriminant is inserted first
2188 -- in the scope, but the error should be posted on it, not
2189 -- on the component.
2191 Error_Msg_Sloc
:= Sloc
(Def_Id
);
2192 Error_Msg_N
("& conflicts with declaration#", E
);
2195 -- If the name of the unit appears in its own context clause,
2196 -- a dummy package with the name has already been created, and
2197 -- the error emitted. Try to continue quietly.
2199 elsif Error_Posted
(E
)
2200 and then Sloc
(E
) = No_Location
2201 and then Nkind
(Parent
(E
)) = N_Package_Specification
2202 and then Current_Scope
= Standard_Standard
2204 Set_Scope
(Def_Id
, Current_Scope
);
2208 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
2210 -- Avoid cascaded messages with duplicate components in
2213 if Ekind
(E
) = E_Component
2214 or else Ekind
(E
) = E_Discriminant
2220 if Nkind
(Parent
(Parent
(Def_Id
)))
2221 = N_Generic_Subprogram_Declaration
2223 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
2225 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
2228 -- If entity is in standard, then we are in trouble, because
2229 -- it means that we have a library package with a duplicated
2230 -- name. That's hard to recover from, so abort!
2232 if S
= Standard_Standard
then
2233 raise Unrecoverable_Error
;
2235 -- Otherwise we continue with the declaration. Having two
2236 -- identical declarations should not cause us too much trouble!
2244 -- If we fall through, declaration is OK , or OK enough to continue
2246 -- If Def_Id is a discriminant or a record component we are in the
2247 -- midst of inheriting components in a derived record definition.
2248 -- Preserve their Ekind and Etype.
2250 if Ekind
(Def_Id
) = E_Discriminant
2251 or else Ekind
(Def_Id
) = E_Component
2255 -- If a type is already set, leave it alone (happens whey a type
2256 -- declaration is reanalyzed following a call to the optimizer)
2258 elsif Present
(Etype
(Def_Id
)) then
2261 -- Otherwise, the kind E_Void insures that premature uses of the entity
2262 -- will be detected. Any_Type insures that no cascaded errors will occur
2265 Set_Ekind
(Def_Id
, E_Void
);
2266 Set_Etype
(Def_Id
, Any_Type
);
2269 -- Inherited discriminants and components in derived record types are
2270 -- immediately visible. Itypes are not.
2272 if Ekind
(Def_Id
) = E_Discriminant
2273 or else Ekind
(Def_Id
) = E_Component
2274 or else (No
(Corresponding_Remote_Type
(Def_Id
))
2275 and then not Is_Itype
(Def_Id
))
2277 Set_Is_Immediately_Visible
(Def_Id
);
2278 Set_Current_Entity
(Def_Id
);
2281 Set_Homonym
(Def_Id
, C
);
2282 Append_Entity
(Def_Id
, S
);
2283 Set_Public_Status
(Def_Id
);
2285 -- Warn if new entity hides an old one
2287 if Warn_On_Hiding
and then Present
(C
)
2289 -- Don't warn for one character variables. It is too common to use
2290 -- such variables as locals and will just cause too many false hits.
2292 and then Length_Of_Name
(Chars
(C
)) /= 1
2294 -- Don't warn for non-source eneities
2296 and then Comes_From_Source
(C
)
2297 and then Comes_From_Source
(Def_Id
)
2299 -- Don't warn unless entity in question is in extended main source
2301 and then In_Extended_Main_Source_Unit
(Def_Id
)
2303 -- Finally, the hidden entity must be either immediately visible
2304 -- or use visible (from a used package)
2307 (Is_Immediately_Visible
(C
)
2309 Is_Potentially_Use_Visible
(C
))
2311 Error_Msg_Sloc
:= Sloc
(C
);
2312 Error_Msg_N
("declaration hides &#?", Def_Id
);
2316 --------------------------
2317 -- Explain_Limited_Type --
2318 --------------------------
2320 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
2324 -- For array, component type must be limited
2326 if Is_Array_Type
(T
) then
2327 Error_Msg_Node_2
:= T
;
2329 ("\component type& of type& is limited", N
, Component_Type
(T
));
2330 Explain_Limited_Type
(Component_Type
(T
), N
);
2332 elsif Is_Record_Type
(T
) then
2334 -- No need for extra messages if explicit limited record
2336 if Is_Limited_Record
(Base_Type
(T
)) then
2340 -- Otherwise find a limited component. Check only components that
2341 -- come from source, or inherited components that appear in the
2342 -- source of the ancestor.
2344 C
:= First_Component
(T
);
2345 while Present
(C
) loop
2346 if Is_Limited_Type
(Etype
(C
))
2348 (Comes_From_Source
(C
)
2350 (Present
(Original_Record_Component
(C
))
2352 Comes_From_Source
(Original_Record_Component
(C
))))
2354 Error_Msg_Node_2
:= T
;
2355 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
2356 Explain_Limited_Type
(Etype
(C
), N
);
2363 -- The type may be declared explicitly limited, even if no component
2364 -- of it is limited, in which case we fall out of the loop.
2367 end Explain_Limited_Type
;
2369 -------------------------------------
2370 -- Find_Corresponding_Discriminant --
2371 -------------------------------------
2373 function Find_Corresponding_Discriminant
2375 Typ
: Entity_Id
) return Entity_Id
2377 Par_Disc
: Entity_Id
;
2378 Old_Disc
: Entity_Id
;
2379 New_Disc
: Entity_Id
;
2382 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
2384 -- The original type may currently be private, and the discriminant
2385 -- only appear on its full view.
2387 if Is_Private_Type
(Scope
(Par_Disc
))
2388 and then not Has_Discriminants
(Scope
(Par_Disc
))
2389 and then Present
(Full_View
(Scope
(Par_Disc
)))
2391 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
2393 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
2396 if Is_Class_Wide_Type
(Typ
) then
2397 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
2399 New_Disc
:= First_Discriminant
(Typ
);
2402 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
2403 if Old_Disc
= Par_Disc
then
2406 Next_Discriminant
(Old_Disc
);
2407 Next_Discriminant
(New_Disc
);
2411 -- Should always find it
2413 raise Program_Error
;
2414 end Find_Corresponding_Discriminant
;
2416 -----------------------------
2417 -- Find_Static_Alternative --
2418 -----------------------------
2420 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
2421 Expr
: constant Node_Id
:= Expression
(N
);
2422 Val
: constant Uint
:= Expr_Value
(Expr
);
2427 Alt
:= First
(Alternatives
(N
));
2430 if Nkind
(Alt
) /= N_Pragma
then
2431 Choice
:= First
(Discrete_Choices
(Alt
));
2432 while Present
(Choice
) loop
2434 -- Others choice, always matches
2436 if Nkind
(Choice
) = N_Others_Choice
then
2439 -- Range, check if value is in the range
2441 elsif Nkind
(Choice
) = N_Range
then
2443 Val
>= Expr_Value
(Low_Bound
(Choice
))
2445 Val
<= Expr_Value
(High_Bound
(Choice
));
2447 -- Choice is a subtype name. Note that we know it must
2448 -- be a static subtype, since otherwise it would have
2449 -- been diagnosed as illegal.
2451 elsif Is_Entity_Name
(Choice
)
2452 and then Is_Type
(Entity
(Choice
))
2454 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
));
2456 -- Choice is a subtype indication
2458 elsif Nkind
(Choice
) = N_Subtype_Indication
then
2460 C
: constant Node_Id
:= Constraint
(Choice
);
2461 R
: constant Node_Id
:= Range_Expression
(C
);
2465 Val
>= Expr_Value
(Low_Bound
(R
))
2467 Val
<= Expr_Value
(High_Bound
(R
));
2470 -- Choice is a simple expression
2473 exit Search
when Val
= Expr_Value
(Choice
);
2481 pragma Assert
(Present
(Alt
));
2484 -- The above loop *must* terminate by finding a match, since
2485 -- we know the case statement is valid, and the value of the
2486 -- expression is known at compile time. When we fall out of
2487 -- the loop, Alt points to the alternative that we know will
2488 -- be selected at run time.
2491 end Find_Static_Alternative
;
2497 function First_Actual
(Node
: Node_Id
) return Node_Id
is
2501 if No
(Parameter_Associations
(Node
)) then
2505 N
:= First
(Parameter_Associations
(Node
));
2507 if Nkind
(N
) = N_Parameter_Association
then
2508 return First_Named_Actual
(Node
);
2514 -------------------------
2515 -- Full_Qualified_Name --
2516 -------------------------
2518 function Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
2520 pragma Warnings
(Off
, Res
);
2522 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
;
2523 -- Compute recursively the qualified name without NUL at the end
2525 ----------------------------------
2526 -- Internal_Full_Qualified_Name --
2527 ----------------------------------
2529 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
2530 Ent
: Entity_Id
:= E
;
2531 Parent_Name
: String_Id
:= No_String
;
2534 -- Deals properly with child units
2536 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
2537 Ent
:= Defining_Identifier
(Ent
);
2540 -- Compute qualification recursively (only "Standard" has no scope)
2542 if Present
(Scope
(Scope
(Ent
))) then
2543 Parent_Name
:= Internal_Full_Qualified_Name
(Scope
(Ent
));
2546 -- Every entity should have a name except some expanded blocks
2547 -- don't bother about those.
2549 if Chars
(Ent
) = No_Name
then
2553 -- Add a period between Name and qualification
2555 if Parent_Name
/= No_String
then
2556 Start_String
(Parent_Name
);
2557 Store_String_Char
(Get_Char_Code
('.'));
2563 -- Generates the entity name in upper case
2565 Get_Decoded_Name_String
(Chars
(Ent
));
2567 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
2569 end Internal_Full_Qualified_Name
;
2571 -- Start of processing for Full_Qualified_Name
2574 Res
:= Internal_Full_Qualified_Name
(E
);
2575 Store_String_Char
(Get_Char_Code
(ASCII
.nul
));
2577 end Full_Qualified_Name
;
2579 -----------------------
2580 -- Gather_Components --
2581 -----------------------
2583 procedure Gather_Components
2585 Comp_List
: Node_Id
;
2586 Governed_By
: List_Id
;
2588 Report_Errors
: out Boolean)
2592 Discrete_Choice
: Node_Id
;
2593 Comp_Item
: Node_Id
;
2595 Discrim
: Entity_Id
;
2596 Discrim_Name
: Node_Id
;
2597 Discrim_Value
: Node_Id
;
2600 Report_Errors
:= False;
2602 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
2605 elsif Present
(Component_Items
(Comp_List
)) then
2606 Comp_Item
:= First
(Component_Items
(Comp_List
));
2612 while Present
(Comp_Item
) loop
2614 -- Skip the tag of a tagged record, the interface tags, as well
2615 -- as all items that are not user components (anonymous types,
2616 -- rep clauses, Parent field, controller field).
2618 if Nkind
(Comp_Item
) = N_Component_Declaration
then
2620 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
2622 if not Is_Tag
(Comp
)
2623 and then Chars
(Comp
) /= Name_uParent
2624 and then Chars
(Comp
) /= Name_uController
2626 Append_Elmt
(Comp
, Into
);
2634 if No
(Variant_Part
(Comp_List
)) then
2637 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
2638 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
2641 -- Look for the discriminant that governs this variant part.
2642 -- The discriminant *must* be in the Governed_By List
2644 Assoc
:= First
(Governed_By
);
2645 Find_Constraint
: loop
2646 Discrim
:= First
(Choices
(Assoc
));
2647 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
2648 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
2650 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
2651 = Chars
(Discrim_Name
))
2652 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
2653 = Chars
(Discrim_Name
);
2655 if No
(Next
(Assoc
)) then
2656 if not Is_Constrained
(Typ
)
2657 and then Is_Derived_Type
(Typ
)
2658 and then Present
(Stored_Constraint
(Typ
))
2660 -- If the type is a tagged type with inherited discriminants,
2661 -- use the stored constraint on the parent in order to find
2662 -- the values of discriminants that are otherwise hidden by an
2663 -- explicit constraint. Renamed discriminants are handled in
2666 -- If several parent discriminants are renamed by a single
2667 -- discriminant of the derived type, the call to obtain the
2668 -- Corresponding_Discriminant field only retrieves the last
2669 -- of them. We recover the constraint on the others from the
2670 -- Stored_Constraint as well.
2677 D
:= First_Discriminant
(Etype
(Typ
));
2678 C
:= First_Elmt
(Stored_Constraint
(Typ
));
2679 while Present
(D
) and then Present
(C
) loop
2680 if Chars
(Discrim_Name
) = Chars
(D
) then
2681 if Is_Entity_Name
(Node
(C
))
2682 and then Entity
(Node
(C
)) = Entity
(Discrim
)
2684 -- D is renamed by Discrim, whose value is given in
2691 Make_Component_Association
(Sloc
(Typ
),
2693 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
2694 Duplicate_Subexpr_No_Checks
(Node
(C
)));
2696 exit Find_Constraint
;
2699 Next_Discriminant
(D
);
2706 if No
(Next
(Assoc
)) then
2707 Error_Msg_NE
(" missing value for discriminant&",
2708 First
(Governed_By
), Discrim_Name
);
2709 Report_Errors
:= True;
2714 end loop Find_Constraint
;
2716 Discrim_Value
:= Expression
(Assoc
);
2718 if not Is_OK_Static_Expression
(Discrim_Value
) then
2720 ("value for discriminant & must be static!",
2721 Discrim_Value
, Discrim
);
2722 Why_Not_Static
(Discrim_Value
);
2723 Report_Errors
:= True;
2727 Search_For_Discriminant_Value
: declare
2733 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
2736 Find_Discrete_Value
: while Present
(Variant
) loop
2737 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
2738 while Present
(Discrete_Choice
) loop
2740 exit Find_Discrete_Value
when
2741 Nkind
(Discrete_Choice
) = N_Others_Choice
;
2743 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
2745 UI_Low
:= Expr_Value
(Low
);
2746 UI_High
:= Expr_Value
(High
);
2748 exit Find_Discrete_Value
when
2749 UI_Low
<= UI_Discrim_Value
2751 UI_High
>= UI_Discrim_Value
;
2753 Next
(Discrete_Choice
);
2756 Next_Non_Pragma
(Variant
);
2757 end loop Find_Discrete_Value
;
2758 end Search_For_Discriminant_Value
;
2760 if No
(Variant
) then
2762 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
2763 Report_Errors
:= True;
2767 -- If we have found the corresponding choice, recursively add its
2768 -- components to the Into list.
2770 Gather_Components
(Empty
,
2771 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
2772 end Gather_Components
;
2774 ------------------------
2775 -- Get_Actual_Subtype --
2776 ------------------------
2778 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
2779 Typ
: constant Entity_Id
:= Etype
(N
);
2780 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
2789 -- If what we have is an identifier that references a subprogram
2790 -- formal, or a variable or constant object, then we get the actual
2791 -- subtype from the referenced entity if one has been built.
2793 if Nkind
(N
) = N_Identifier
2795 (Is_Formal
(Entity
(N
))
2796 or else Ekind
(Entity
(N
)) = E_Constant
2797 or else Ekind
(Entity
(N
)) = E_Variable
)
2798 and then Present
(Actual_Subtype
(Entity
(N
)))
2800 return Actual_Subtype
(Entity
(N
));
2802 -- Actual subtype of unchecked union is always itself. We never need
2803 -- the "real" actual subtype. If we did, we couldn't get it anyway
2804 -- because the discriminant is not available. The restrictions on
2805 -- Unchecked_Union are designed to make sure that this is OK.
2807 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
2810 -- Here for the unconstrained case, we must find actual subtype
2811 -- No actual subtype is available, so we must build it on the fly.
2813 -- Checking the type, not the underlying type, for constrainedness
2814 -- seems to be necessary. Maybe all the tests should be on the type???
2816 elsif (not Is_Constrained
(Typ
))
2817 and then (Is_Array_Type
(Utyp
)
2818 or else (Is_Record_Type
(Utyp
)
2819 and then Has_Discriminants
(Utyp
)))
2820 and then not Has_Unknown_Discriminants
(Utyp
)
2821 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
2823 -- Nothing to do if in default expression
2825 if In_Default_Expression
then
2828 elsif Is_Private_Type
(Typ
)
2829 and then not Has_Discriminants
(Typ
)
2831 -- If the type has no discriminants, there is no subtype to
2832 -- build, even if the underlying type is discriminated.
2836 -- Else build the actual subtype
2839 Decl
:= Build_Actual_Subtype
(Typ
, N
);
2840 Atyp
:= Defining_Identifier
(Decl
);
2842 -- If Build_Actual_Subtype generated a new declaration then use it
2846 -- The actual subtype is an Itype, so analyze the declaration,
2847 -- but do not attach it to the tree, to get the type defined.
2849 Set_Parent
(Decl
, N
);
2850 Set_Is_Itype
(Atyp
);
2851 Analyze
(Decl
, Suppress
=> All_Checks
);
2852 Set_Associated_Node_For_Itype
(Atyp
, N
);
2853 Set_Has_Delayed_Freeze
(Atyp
, False);
2855 -- We need to freeze the actual subtype immediately. This is
2856 -- needed, because otherwise this Itype will not get frozen
2857 -- at all, and it is always safe to freeze on creation because
2858 -- any associated types must be frozen at this point.
2860 Freeze_Itype
(Atyp
, N
);
2863 -- Otherwise we did not build a declaration, so return original
2870 -- For all remaining cases, the actual subtype is the same as
2871 -- the nominal type.
2876 end Get_Actual_Subtype
;
2878 -------------------------------------
2879 -- Get_Actual_Subtype_If_Available --
2880 -------------------------------------
2882 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
2883 Typ
: constant Entity_Id
:= Etype
(N
);
2886 -- If what we have is an identifier that references a subprogram
2887 -- formal, or a variable or constant object, then we get the actual
2888 -- subtype from the referenced entity if one has been built.
2890 if Nkind
(N
) = N_Identifier
2892 (Is_Formal
(Entity
(N
))
2893 or else Ekind
(Entity
(N
)) = E_Constant
2894 or else Ekind
(Entity
(N
)) = E_Variable
)
2895 and then Present
(Actual_Subtype
(Entity
(N
)))
2897 return Actual_Subtype
(Entity
(N
));
2899 -- Otherwise the Etype of N is returned unchanged
2904 end Get_Actual_Subtype_If_Available
;
2906 -------------------------------
2907 -- Get_Default_External_Name --
2908 -------------------------------
2910 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
2912 Get_Decoded_Name_String
(Chars
(E
));
2914 if Opt
.External_Name_Imp_Casing
= Uppercase
then
2915 Set_Casing
(All_Upper_Case
);
2917 Set_Casing
(All_Lower_Case
);
2921 Make_String_Literal
(Sloc
(E
),
2922 Strval
=> String_From_Name_Buffer
);
2923 end Get_Default_External_Name
;
2925 ---------------------------
2926 -- Get_Enum_Lit_From_Pos --
2927 ---------------------------
2929 function Get_Enum_Lit_From_Pos
2932 Loc
: Source_Ptr
) return Node_Id
2937 -- In the case where the literal is of type Character, Wide_Character
2938 -- or Wide_Wide_Character or of a type derived from them, there needs
2939 -- to be some special handling since there is no explicit chain of
2940 -- literals to search. Instead, an N_Character_Literal node is created
2941 -- with the appropriate Char_Code and Chars fields.
2943 if Root_Type
(T
) = Standard_Character
2944 or else Root_Type
(T
) = Standard_Wide_Character
2945 or else Root_Type
(T
) = Standard_Wide_Wide_Character
2947 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
2949 Make_Character_Literal
(Loc
,
2951 Char_Literal_Value
=> Pos
);
2953 -- For all other cases, we have a complete table of literals, and
2954 -- we simply iterate through the chain of literal until the one
2955 -- with the desired position value is found.
2959 Lit
:= First_Literal
(Base_Type
(T
));
2960 for J
in 1 .. UI_To_Int
(Pos
) loop
2964 return New_Occurrence_Of
(Lit
, Loc
);
2966 end Get_Enum_Lit_From_Pos
;
2968 ------------------------
2969 -- Get_Generic_Entity --
2970 ------------------------
2972 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
2973 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
2975 if Present
(Renamed_Object
(Ent
)) then
2976 return Renamed_Object
(Ent
);
2980 end Get_Generic_Entity
;
2982 ----------------------
2983 -- Get_Index_Bounds --
2984 ----------------------
2986 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
2987 Kind
: constant Node_Kind
:= Nkind
(N
);
2991 if Kind
= N_Range
then
2993 H
:= High_Bound
(N
);
2995 elsif Kind
= N_Subtype_Indication
then
2996 R
:= Range_Expression
(Constraint
(N
));
3004 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
3005 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
3008 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
3009 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
3013 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
3014 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
3017 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
3018 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
3022 -- N is an expression, indicating a range with one value
3027 end Get_Index_Bounds
;
3029 ----------------------------------
3030 -- Get_Library_Unit_Name_string --
3031 ----------------------------------
3033 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
3034 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
3037 Get_Unit_Name_String
(Unit_Name_Id
);
3039 -- Remove seven last character (" (spec)" or " (body)")
3041 Name_Len
:= Name_Len
- 7;
3042 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
3043 end Get_Library_Unit_Name_String
;
3045 ------------------------
3046 -- Get_Name_Entity_Id --
3047 ------------------------
3049 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
3051 return Entity_Id
(Get_Name_Table_Info
(Id
));
3052 end Get_Name_Entity_Id
;
3054 ---------------------------
3055 -- Get_Subprogram_Entity --
3056 ---------------------------
3058 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
3063 if Nkind
(Nod
) = N_Accept_Statement
then
3064 Nam
:= Entry_Direct_Name
(Nod
);
3069 if Nkind
(Nam
) = N_Explicit_Dereference
then
3070 Proc
:= Etype
(Prefix
(Nam
));
3071 elsif Is_Entity_Name
(Nam
) then
3072 Proc
:= Entity
(Nam
);
3077 if Is_Object
(Proc
) then
3078 Proc
:= Etype
(Proc
);
3081 if Ekind
(Proc
) = E_Access_Subprogram_Type
then
3082 Proc
:= Directly_Designated_Type
(Proc
);
3085 if not Is_Subprogram
(Proc
)
3086 and then Ekind
(Proc
) /= E_Subprogram_Type
3092 end Get_Subprogram_Entity
;
3094 ---------------------------
3095 -- Get_Referenced_Object --
3096 ---------------------------
3098 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
3103 while Is_Entity_Name
(R
)
3104 and then Present
(Renamed_Object
(Entity
(R
)))
3106 R
:= Renamed_Object
(Entity
(R
));
3110 end Get_Referenced_Object
;
3112 -------------------------
3113 -- Get_Subprogram_Body --
3114 -------------------------
3116 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
3120 Decl
:= Unit_Declaration_Node
(E
);
3122 if Nkind
(Decl
) = N_Subprogram_Body
then
3125 -- The below comment is bad, because it is possible for
3126 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
3128 else -- Nkind (Decl) = N_Subprogram_Declaration
3130 if Present
(Corresponding_Body
(Decl
)) then
3131 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
3133 -- Imported subprogram case
3139 end Get_Subprogram_Body
;
3141 -----------------------------
3142 -- Get_Task_Body_Procedure --
3143 -----------------------------
3145 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
3147 -- Note: A task type may be the completion of a private type with
3148 -- discriminants. when performing elaboration checks on a task
3149 -- declaration, the current view of the type may be the private one,
3150 -- and the procedure that holds the body of the task is held in its
3153 -- This is an odd function, why not have Task_Body_Procedure do
3154 -- the following digging???
3156 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
3157 end Get_Task_Body_Procedure
;
3159 -----------------------------
3160 -- Has_Abstract_Interfaces --
3161 -----------------------------
3163 function Has_Abstract_Interfaces
(Tagged_Type
: Entity_Id
) return Boolean is
3167 pragma Assert
(Is_Record_Type
(Tagged_Type
)
3168 and then Is_Tagged_Type
(Tagged_Type
));
3170 -- Handle private types
3172 if Present
(Full_View
(Tagged_Type
)) then
3173 Typ
:= Full_View
(Tagged_Type
);
3179 if Is_Interface
(Typ
)
3180 or else (Present
(Abstract_Interfaces
(Typ
))
3182 not Is_Empty_Elmt_List
(Abstract_Interfaces
(Typ
)))
3187 exit when Etype
(Typ
) = Typ
3189 -- Handle private types
3191 or else (Present
(Full_View
(Etype
(Typ
)))
3192 and then Full_View
(Etype
(Typ
)) = Typ
)
3194 -- Protect the frontend against wrong source with cyclic
3197 or else Etype
(Typ
) = Tagged_Type
;
3199 -- Climb to the ancestor type handling private types
3201 if Present
(Full_View
(Etype
(Typ
))) then
3202 Typ
:= Full_View
(Etype
(Typ
));
3209 end Has_Abstract_Interfaces
;
3211 -----------------------
3212 -- Has_Access_Values --
3213 -----------------------
3215 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
3216 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
3219 -- Case of a private type which is not completed yet. This can only
3220 -- happen in the case of a generic format type appearing directly, or
3221 -- as a component of the type to which this function is being applied
3222 -- at the top level. Return False in this case, since we certainly do
3223 -- not know that the type contains access types.
3228 elsif Is_Access_Type
(Typ
) then
3231 elsif Is_Array_Type
(Typ
) then
3232 return Has_Access_Values
(Component_Type
(Typ
));
3234 elsif Is_Record_Type
(Typ
) then
3239 Comp
:= First_Entity
(Typ
);
3240 while Present
(Comp
) loop
3241 if (Ekind
(Comp
) = E_Component
3243 Ekind
(Comp
) = E_Discriminant
)
3244 and then Has_Access_Values
(Etype
(Comp
))
3258 end Has_Access_Values
;
3260 ------------------------------
3261 -- Has_Compatible_Alignment --
3262 ------------------------------
3264 function Has_Compatible_Alignment
3266 Expr
: Node_Id
) return Alignment_Result
3268 function Has_Compatible_Alignment_Internal
3271 Default
: Alignment_Result
) return Alignment_Result
;
3272 -- This is the internal recursive function that actually does the work.
3273 -- There is one additional parameter, which says what the result should
3274 -- be if no alignment information is found, and there is no definite
3275 -- indication of compatible alignments. At the outer level, this is set
3276 -- to Unknown, but for internal recursive calls in the case where types
3277 -- are known to be correct, it is set to Known_Compatible.
3279 ---------------------------------------
3280 -- Has_Compatible_Alignment_Internal --
3281 ---------------------------------------
3283 function Has_Compatible_Alignment_Internal
3286 Default
: Alignment_Result
) return Alignment_Result
3288 Result
: Alignment_Result
:= Known_Compatible
;
3289 -- Set to result if Problem_Prefix or Problem_Offset returns True.
3290 -- Note that once a value of Known_Incompatible is set, it is sticky
3291 -- and does not get changed to Unknown (the value in Result only gets
3292 -- worse as we go along, never better).
3294 procedure Check_Offset
(Offs
: Uint
);
3295 -- Called when Expr is a selected or indexed component with Offs set
3296 -- to resp Component_First_Bit or Component_Size. Checks that if the
3297 -- offset is specified it is compatible with the object alignment
3298 -- requirements. The value in Result is modified accordingly.
3300 procedure Check_Prefix
;
3301 -- Checks the prefix recursively in the case where the expression
3302 -- is an indexed or selected component.
3304 procedure Set_Result
(R
: Alignment_Result
);
3305 -- If R represents a worse outcome (unknown instead of known
3306 -- compatible, or known incompatible), then set Result to R.
3312 procedure Check_Offset
(Offs
: Uint
) is
3314 -- Unspecified or zero offset is always OK
3316 if Offs
= No_Uint
or else Offs
= Uint_0
then
3319 -- If we do not know required alignment, any non-zero offset is
3320 -- a potential problem (but certainly may be OK, so result is
3323 elsif Unknown_Alignment
(Obj
) then
3324 Set_Result
(Unknown
);
3326 -- If we know the required alignment, see if offset is compatible
3329 if Offs
mod (System_Storage_Unit
* Alignment
(Obj
)) /= 0 then
3330 Set_Result
(Known_Incompatible
);
3339 procedure Check_Prefix
is
3341 -- The subtlety here is that in doing a recursive call to check
3342 -- the prefix, we have to decide what to do in the case where we
3343 -- don't find any specific indication of an alignment problem.
3345 -- At the outer level, we normally set Unknown as the result in
3346 -- this case, since we can only set Known_Compatible if we really
3347 -- know that the alignment value is OK, but for the recursive
3348 -- call, in the case where the types match, and we have not
3349 -- specified a peculiar alignment for the object, we are only
3350 -- concerned about suspicious rep clauses, the default case does
3351 -- not affect us, since the compiler will, in the absence of such
3352 -- rep clauses, ensure that the alignment is correct.
3354 if Default
= Known_Compatible
3356 (Etype
(Obj
) = Etype
(Expr
)
3357 and then (Unknown_Alignment
(Obj
)
3359 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
3362 (Has_Compatible_Alignment_Internal
3363 (Obj
, Prefix
(Expr
), Known_Compatible
));
3365 -- In all other cases, we need a full check on the prefix
3369 (Has_Compatible_Alignment_Internal
3370 (Obj
, Prefix
(Expr
), Unknown
));
3378 procedure Set_Result
(R
: Alignment_Result
) is
3385 -- Start of processing for Has_Compatible_Alignment_Internal
3388 -- If Expr is a selected component, we must make sure there is no
3389 -- potentially troublesome component clause, and that the record is
3392 if Nkind
(Expr
) = N_Selected_Component
then
3394 -- Packed record always generate unknown alignment
3396 if Is_Packed
(Etype
(Prefix
(Expr
))) then
3397 Set_Result
(Unknown
);
3400 -- Check possible bad component offset and check prefix
3403 (Component_Bit_Offset
(Entity
(Selector_Name
(Expr
))));
3406 -- If Expr is an indexed component, we must make sure there is no
3407 -- potentially troublesome Component_Size clause and that the array
3408 -- is not bit-packed.
3410 elsif Nkind
(Expr
) = N_Indexed_Component
then
3412 -- Bit packed array always generates unknown alignment
3414 if Is_Bit_Packed_Array
(Etype
(Prefix
(Expr
))) then
3415 Set_Result
(Unknown
);
3418 -- Check possible bad component size and check prefix
3420 Check_Offset
(Component_Size
(Etype
(Prefix
(Expr
))));
3424 -- Case where we know the alignment of the object
3426 if Known_Alignment
(Obj
) then
3428 ObjA
: constant Uint
:= Alignment
(Obj
);
3429 ExpA
: Uint
:= No_Uint
;
3430 SizA
: Uint
:= No_Uint
;
3433 -- If alignment of Obj is 1, then we are always OK
3436 Set_Result
(Known_Compatible
);
3438 -- Alignment of Obj is greater than 1, so we need to check
3441 -- See if Expr is an object with known alignment
3443 if Is_Entity_Name
(Expr
)
3444 and then Known_Alignment
(Entity
(Expr
))
3446 ExpA
:= Alignment
(Entity
(Expr
));
3448 -- Otherwise, we can use the alignment of the type of
3449 -- Expr given that we already checked for
3450 -- discombobulating rep clauses for the cases of indexed
3451 -- and selected components above.
3453 elsif Known_Alignment
(Etype
(Expr
)) then
3454 ExpA
:= Alignment
(Etype
(Expr
));
3457 -- If we got an alignment, see if it is acceptable
3459 if ExpA
/= No_Uint
then
3461 Set_Result
(Known_Incompatible
);
3464 -- Case of Expr alignment unknown
3467 Set_Result
(Default
);
3470 -- See if size is given. If so, check that it is not too
3471 -- small for the required alignment.
3472 -- See if Expr is an object with known alignment
3474 if Is_Entity_Name
(Expr
)
3475 and then Known_Static_Esize
(Entity
(Expr
))
3477 SizA
:= Esize
(Entity
(Expr
));
3479 -- Otherwise, we check the object size of the Expr type
3481 elsif Known_Static_Esize
(Etype
(Expr
)) then
3482 SizA
:= Esize
(Etype
(Expr
));
3485 -- If we got a size, see if it is a multiple of the Obj
3486 -- alignment, if not, then the alignment cannot be
3487 -- acceptable, since the size is always a multiple of the
3490 if SizA
/= No_Uint
then
3491 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
3492 Set_Result
(Known_Incompatible
);
3498 -- If we can't find the result by direct comparison of alignment
3499 -- values, then there is still one case that we can determine known
3500 -- result, and that is when we can determine that the types are the
3501 -- same, and no alignments are specified. Then we known that the
3502 -- alignments are compatible, even if we don't know the alignment
3503 -- value in the front end.
3505 elsif Etype
(Obj
) = Etype
(Expr
) then
3507 -- Types are the same, but we have to check for possible size
3508 -- and alignments on the Expr object that may make the alignment
3509 -- different, even though the types are the same.
3511 if Is_Entity_Name
(Expr
) then
3513 -- First check alignment of the Expr object. Any alignment less
3514 -- than Maximum_Alignment is worrisome since this is the case
3515 -- where we do not know the alignment of Obj.
3517 if Known_Alignment
(Entity
(Expr
))
3519 UI_To_Int
(Alignment
(Entity
(Expr
)))
3520 < Ttypes
.Maximum_Alignment
3522 Set_Result
(Unknown
);
3524 -- Now check size of Expr object. Any size that is not an
3525 -- even multiple of Maxiumum_Alignment is also worrisome
3526 -- since it may cause the alignment of the object to be less
3527 -- than the alignment of the type.
3529 elsif Known_Static_Esize
(Entity
(Expr
))
3531 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
3532 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
3535 Set_Result
(Unknown
);
3537 -- Otherwise same type is decisive
3540 Set_Result
(Known_Compatible
);
3544 -- Another case to deal with is when there is an explicit size or
3545 -- alignment clause when the types are not the same. If so, then the
3546 -- result is Unknown. We don't need to do this test if the Default is
3547 -- Unknown, since that result will be set in any case.
3549 elsif Default
/= Unknown
3550 and then (Has_Size_Clause
(Etype
(Expr
))
3552 Has_Alignment_Clause
(Etype
(Expr
)))
3554 Set_Result
(Unknown
);
3556 -- If no indication found, set default
3559 Set_Result
(Default
);
3562 -- Return worst result found
3565 end Has_Compatible_Alignment_Internal
;
3567 -- Start of processing for Has_Compatible_Alignment
3570 -- If Obj has no specified alignment, then set alignment from the type
3571 -- alignment. Perhaps we should always do this, but for sure we should
3572 -- do it when there is an address clause since we can do more if the
3573 -- alignment is known.
3575 if Unknown_Alignment
(Obj
) then
3576 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
3579 -- Now do the internal call that does all the work
3581 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
3582 end Has_Compatible_Alignment
;
3584 ----------------------
3585 -- Has_Declarations --
3586 ----------------------
3588 function Has_Declarations
(N
: Node_Id
) return Boolean is
3589 K
: constant Node_Kind
:= Nkind
(N
);
3591 return K
= N_Accept_Statement
3592 or else K
= N_Block_Statement
3593 or else K
= N_Compilation_Unit_Aux
3594 or else K
= N_Entry_Body
3595 or else K
= N_Package_Body
3596 or else K
= N_Protected_Body
3597 or else K
= N_Subprogram_Body
3598 or else K
= N_Task_Body
3599 or else K
= N_Package_Specification
;
3600 end Has_Declarations
;
3602 -------------------------------------------
3603 -- Has_Discriminant_Dependent_Constraint --
3604 -------------------------------------------
3606 function Has_Discriminant_Dependent_Constraint
3607 (Comp
: Entity_Id
) return Boolean
3609 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
3610 Subt_Indic
: constant Node_Id
:=
3611 Subtype_Indication
(Component_Definition
(Comp_Decl
));
3616 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
3617 Constr
:= Constraint
(Subt_Indic
);
3619 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
3620 Assn
:= First
(Constraints
(Constr
));
3621 while Present
(Assn
) loop
3622 case Nkind
(Assn
) is
3623 when N_Subtype_Indication |
3627 if Depends_On_Discriminant
(Assn
) then
3631 when N_Discriminant_Association
=>
3632 if Depends_On_Discriminant
(Expression
(Assn
)) then
3647 end Has_Discriminant_Dependent_Constraint
;
3649 --------------------
3650 -- Has_Infinities --
3651 --------------------
3653 function Has_Infinities
(E
: Entity_Id
) return Boolean is
3656 Is_Floating_Point_Type
(E
)
3657 and then Nkind
(Scalar_Range
(E
)) = N_Range
3658 and then Includes_Infinities
(Scalar_Range
(E
));
3661 ------------------------
3662 -- Has_Null_Exclusion --
3663 ------------------------
3665 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
3668 when N_Access_Definition |
3669 N_Access_Function_Definition |
3670 N_Access_Procedure_Definition |
3671 N_Access_To_Object_Definition |
3673 N_Derived_Type_Definition |
3674 N_Function_Specification |
3675 N_Subtype_Declaration
=>
3676 return Null_Exclusion_Present
(N
);
3678 when N_Component_Definition |
3679 N_Formal_Object_Declaration |
3680 N_Object_Renaming_Declaration
=>
3681 if Present
(Subtype_Mark
(N
)) then
3682 return Null_Exclusion_Present
(N
);
3683 else pragma Assert
(Present
(Access_Definition
(N
)));
3684 return Null_Exclusion_Present
(Access_Definition
(N
));
3687 when N_Discriminant_Specification
=>
3688 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
3689 return Null_Exclusion_Present
(Discriminant_Type
(N
));
3691 return Null_Exclusion_Present
(N
);
3694 when N_Object_Declaration
=>
3695 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
3696 return Null_Exclusion_Present
(Object_Definition
(N
));
3698 return Null_Exclusion_Present
(N
);
3701 when N_Parameter_Specification
=>
3702 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
3703 return Null_Exclusion_Present
(Parameter_Type
(N
));
3705 return Null_Exclusion_Present
(N
);
3712 end Has_Null_Exclusion
;
3714 ------------------------
3715 -- Has_Null_Extension --
3716 ------------------------
3718 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
3719 B
: constant Entity_Id
:= Base_Type
(T
);
3724 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
3725 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
3727 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
3729 if Present
(Ext
) then
3730 if Null_Present
(Ext
) then
3733 Comps
:= Component_List
(Ext
);
3735 -- The null component list is rewritten during analysis to
3736 -- include the parent component. Any other component indicates
3737 -- that the extension was not originally null.
3739 return Null_Present
(Comps
)
3740 or else No
(Next
(First
(Component_Items
(Comps
))));
3749 end Has_Null_Extension
;
3751 --------------------------------------
3752 -- Has_Preelaborable_Initialization --
3753 --------------------------------------
3755 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
3758 procedure Check_Components
(E
: Entity_Id
);
3759 -- Check component/discriminant chain, sets Has_PE False if a component
3760 -- or discriminant does not meet the preelaborable initialization rules.
3762 ----------------------
3763 -- Check_Components --
3764 ----------------------
3766 procedure Check_Components
(E
: Entity_Id
) is
3771 -- Loop through entities of record or protected type
3774 while Present
(Ent
) loop
3776 -- We are interested only in components and discriminants
3778 if Ekind
(Ent
) = E_Component
3780 Ekind
(Ent
) = E_Discriminant
3782 -- Get default expression if any. If there is no declaration
3783 -- node, it means we have an internal entity. The parent and
3784 -- tag fields are examples of such entitires. For these
3785 -- cases, we just test the type of the entity.
3787 if Present
(Declaration_Node
(Ent
)) then
3788 Exp
:= Expression
(Declaration_Node
(Ent
));
3793 -- A component has PI if it has no default expression and
3794 -- the component type has PI.
3797 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
3802 -- Or if expression obeys rules for preelaboration. For
3803 -- now we approximate this by testing if the default
3804 -- expression is a static expression or if it is an
3805 -- access attribute reference.
3807 -- This is an approximation, it is probably incomplete???
3809 elsif Is_Static_Expression
(Exp
) then
3812 elsif Nkind
(Exp
) = N_Attribute_Reference
3813 and then (Attribute_Name
(Exp
) = Name_Access
3815 Attribute_Name
(Exp
) = Name_Unchecked_Access
3817 Attribute_Name
(Exp
) = Name_Unrestricted_Access
)
3829 end Check_Components
;
3831 -- Start of processing for Has_Preelaborable_Initialization
3834 -- Immediate return if already marked as known preelaborable init
3836 if Known_To_Have_Preelab_Init
(E
) then
3840 -- All elementary types have preelaborable initialization
3842 if Is_Elementary_Type
(E
) then
3845 -- Array types have PI if the component type has PI
3847 elsif Is_Array_Type
(E
) then
3848 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
3850 -- Record types have PI if all components have PI
3852 elsif Is_Record_Type
(E
) then
3854 Check_Components
(First_Entity
(E
));
3856 -- Another check here, if this is a controlled type, see if it has a
3857 -- user defined Initialize procedure. If so, then there is a special
3858 -- rule that means this type does not have PI.
3860 if Is_Controlled
(E
)
3861 and then Present
(Primitive_Operations
(E
))
3867 P
:= First_Elmt
(Primitive_Operations
(E
));
3868 while Present
(P
) loop
3869 if Chars
(Node
(P
)) = Name_Initialize
3870 and then Comes_From_Source
(Node
(P
))
3881 -- Protected types, must not have entries, and components must meet
3882 -- same set of rules as for record components.
3884 elsif Is_Protected_Type
(E
) then
3885 if Has_Entries
(E
) then
3889 Check_Components
(First_Entity
(E
));
3890 Check_Components
(First_Private_Entity
(E
));
3893 -- A derived type has preelaborable initialization if its parent type
3894 -- has preelaborable initialization and (in the case of a derived record
3895 -- extension) if the non-inherited components all have preelaborable
3896 -- initialization. However, a user-defined controlled type with an
3897 -- overriding Initialize procedure does not have preelaborable
3902 -- Type System.Address always has preelaborable initialization
3904 elsif Is_RTE
(E
, RE_Address
) then
3907 -- In all other cases, type does not have preelaborable init
3914 Set_Known_To_Have_Preelab_Init
(E
);
3918 end Has_Preelaborable_Initialization
;
3920 ---------------------------
3921 -- Has_Private_Component --
3922 ---------------------------
3924 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
3925 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
3926 Component
: Entity_Id
;
3929 if Error_Posted
(Type_Id
)
3930 or else Error_Posted
(Btype
)
3935 if Is_Class_Wide_Type
(Btype
) then
3936 Btype
:= Root_Type
(Btype
);
3939 if Is_Private_Type
(Btype
) then
3941 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
3945 if No
(Full_View
(Btype
)) then
3946 return not Is_Generic_Type
(Btype
)
3947 and then not Is_Generic_Type
(Root_Type
(Btype
));
3950 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
3954 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
3957 elsif Is_Array_Type
(Btype
) then
3958 return Has_Private_Component
(Component_Type
(Btype
));
3960 elsif Is_Record_Type
(Btype
) then
3962 Component
:= First_Component
(Btype
);
3963 while Present
(Component
) loop
3964 if Has_Private_Component
(Etype
(Component
)) then
3968 Next_Component
(Component
);
3973 elsif Is_Protected_Type
(Btype
)
3974 and then Present
(Corresponding_Record_Type
(Btype
))
3976 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
3981 end Has_Private_Component
;
3987 function Has_Stream
(T
: Entity_Id
) return Boolean is
3994 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
3997 elsif Is_Array_Type
(T
) then
3998 return Has_Stream
(Component_Type
(T
));
4000 elsif Is_Record_Type
(T
) then
4001 E
:= First_Component
(T
);
4002 while Present
(E
) loop
4003 if Has_Stream
(Etype
(E
)) then
4012 elsif Is_Private_Type
(T
) then
4013 return Has_Stream
(Underlying_Type
(T
));
4020 --------------------------
4021 -- Has_Tagged_Component --
4022 --------------------------
4024 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
4028 if Is_Private_Type
(Typ
)
4029 and then Present
(Underlying_Type
(Typ
))
4031 return Has_Tagged_Component
(Underlying_Type
(Typ
));
4033 elsif Is_Array_Type
(Typ
) then
4034 return Has_Tagged_Component
(Component_Type
(Typ
));
4036 elsif Is_Tagged_Type
(Typ
) then
4039 elsif Is_Record_Type
(Typ
) then
4040 Comp
:= First_Component
(Typ
);
4041 while Present
(Comp
) loop
4042 if Has_Tagged_Component
(Etype
(Comp
)) then
4046 Comp
:= Next_Component
(Typ
);
4054 end Has_Tagged_Component
;
4060 function In_Instance
return Boolean is
4061 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
4067 and then S
/= Standard_Standard
4069 if (Ekind
(S
) = E_Function
4070 or else Ekind
(S
) = E_Package
4071 or else Ekind
(S
) = E_Procedure
)
4072 and then Is_Generic_Instance
(S
)
4075 -- A child instance is always compiled in the context of a parent
4076 -- instance. Nevertheless, the actuals are not analyzed in an
4077 -- instance context. We detect this case by examining the current
4078 -- compilation unit, which must be a child instance, and checking
4079 -- that it is not currently on the scope stack.
4081 if Is_Child_Unit
(Curr_Unit
)
4083 Nkind
(Unit
(Cunit
(Current_Sem_Unit
)))
4084 = N_Package_Instantiation
4085 and then not In_Open_Scopes
(Curr_Unit
)
4099 ----------------------
4100 -- In_Instance_Body --
4101 ----------------------
4103 function In_Instance_Body
return Boolean is
4109 and then S
/= Standard_Standard
4111 if (Ekind
(S
) = E_Function
4112 or else Ekind
(S
) = E_Procedure
)
4113 and then Is_Generic_Instance
(S
)
4117 elsif Ekind
(S
) = E_Package
4118 and then In_Package_Body
(S
)
4119 and then Is_Generic_Instance
(S
)
4128 end In_Instance_Body
;
4130 -----------------------------
4131 -- In_Instance_Not_Visible --
4132 -----------------------------
4134 function In_Instance_Not_Visible
return Boolean is
4140 and then S
/= Standard_Standard
4142 if (Ekind
(S
) = E_Function
4143 or else Ekind
(S
) = E_Procedure
)
4144 and then Is_Generic_Instance
(S
)
4148 elsif Ekind
(S
) = E_Package
4149 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
4150 and then Is_Generic_Instance
(S
)
4159 end In_Instance_Not_Visible
;
4161 ------------------------------
4162 -- In_Instance_Visible_Part --
4163 ------------------------------
4165 function In_Instance_Visible_Part
return Boolean is
4171 and then S
/= Standard_Standard
4173 if Ekind
(S
) = E_Package
4174 and then Is_Generic_Instance
(S
)
4175 and then not In_Package_Body
(S
)
4176 and then not In_Private_Part
(S
)
4185 end In_Instance_Visible_Part
;
4187 ----------------------
4188 -- In_Packiage_Body --
4189 ----------------------
4191 function In_Package_Body
return Boolean is
4197 and then S
/= Standard_Standard
4199 if Ekind
(S
) = E_Package
4200 and then In_Package_Body
(S
)
4209 end In_Package_Body
;
4211 --------------------------------------
4212 -- In_Subprogram_Or_Concurrent_Unit --
4213 --------------------------------------
4215 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
4220 -- Use scope chain to check successively outer scopes
4226 if K
in Subprogram_Kind
4227 or else K
in Concurrent_Kind
4228 or else K
in Generic_Subprogram_Kind
4232 elsif E
= Standard_Standard
then
4238 end In_Subprogram_Or_Concurrent_Unit
;
4240 ---------------------
4241 -- In_Visible_Part --
4242 ---------------------
4244 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
4247 Is_Package_Or_Generic_Package
(Scope_Id
)
4248 and then In_Open_Scopes
(Scope_Id
)
4249 and then not In_Package_Body
(Scope_Id
)
4250 and then not In_Private_Part
(Scope_Id
);
4251 end In_Visible_Part
;
4253 ---------------------------------
4254 -- Insert_Explicit_Dereference --
4255 ---------------------------------
4257 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
4258 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
4259 Ent
: Entity_Id
:= Empty
;
4266 Save_Interps
(N
, New_Prefix
);
4268 Make_Explicit_Dereference
(Sloc
(N
), Prefix
=> New_Prefix
));
4270 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
4272 if Is_Overloaded
(New_Prefix
) then
4274 -- The deference is also overloaded, and its interpretations are the
4275 -- designated types of the interpretations of the original node.
4277 Set_Etype
(N
, Any_Type
);
4279 Get_First_Interp
(New_Prefix
, I
, It
);
4280 while Present
(It
.Nam
) loop
4283 if Is_Access_Type
(T
) then
4284 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
4287 Get_Next_Interp
(I
, It
);
4293 -- Prefix is unambiguous: mark the original prefix (which might
4294 -- Come_From_Source) as a reference, since the new (relocated) one
4295 -- won't be taken into account.
4297 if Is_Entity_Name
(New_Prefix
) then
4298 Ent
:= Entity
(New_Prefix
);
4300 -- For a retrieval of a subcomponent of some composite object,
4301 -- retrieve the ultimate entity if there is one.
4303 elsif Nkind
(New_Prefix
) = N_Selected_Component
4304 or else Nkind
(New_Prefix
) = N_Indexed_Component
4306 Pref
:= Prefix
(New_Prefix
);
4307 while Present
(Pref
)
4309 (Nkind
(Pref
) = N_Selected_Component
4310 or else Nkind
(Pref
) = N_Indexed_Component
)
4312 Pref
:= Prefix
(Pref
);
4315 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
4316 Ent
:= Entity
(Pref
);
4320 if Present
(Ent
) then
4321 Generate_Reference
(Ent
, New_Prefix
);
4324 end Insert_Explicit_Dereference
;
4330 function Is_AAMP_Float
(E
: Entity_Id
) return Boolean is
4332 pragma Assert
(Is_Type
(E
));
4334 return AAMP_On_Target
4335 and then Is_Floating_Point_Type
(E
)
4336 and then E
= Base_Type
(E
);
4339 -------------------------
4340 -- Is_Actual_Parameter --
4341 -------------------------
4343 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
4344 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
4348 when N_Parameter_Association
=>
4349 return N
= Explicit_Actual_Parameter
(Parent
(N
));
4351 when N_Function_Call | N_Procedure_Call_Statement
=>
4352 return Is_List_Member
(N
)
4354 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
4359 end Is_Actual_Parameter
;
4361 ---------------------
4362 -- Is_Aliased_View --
4363 ---------------------
4365 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
4369 if Is_Entity_Name
(Obj
) then
4377 or else (Present
(Renamed_Object
(E
))
4378 and then Is_Aliased_View
(Renamed_Object
(E
)))))
4380 or else ((Is_Formal
(E
)
4381 or else Ekind
(E
) = E_Generic_In_Out_Parameter
4382 or else Ekind
(E
) = E_Generic_In_Parameter
)
4383 and then Is_Tagged_Type
(Etype
(E
)))
4385 or else ((Ekind
(E
) = E_Task_Type
4386 or else Ekind
(E
) = E_Protected_Type
)
4387 and then In_Open_Scopes
(E
))
4389 -- Current instance of type, either directly or as rewritten
4390 -- reference to the current object.
4392 or else (Is_Entity_Name
(Original_Node
(Obj
))
4393 and then Present
(Entity
(Original_Node
(Obj
)))
4394 and then Is_Type
(Entity
(Original_Node
(Obj
))))
4396 or else (Is_Type
(E
) and then E
= Current_Scope
)
4397 or else (Is_Incomplete_Or_Private_Type
(E
)
4398 and then Full_View
(E
) = Current_Scope
);
4400 elsif Nkind
(Obj
) = N_Selected_Component
then
4401 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
4403 elsif Nkind
(Obj
) = N_Indexed_Component
then
4404 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
4406 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
4408 Has_Aliased_Components
4409 (Designated_Type
(Etype
(Prefix
(Obj
)))));
4411 elsif Nkind
(Obj
) = N_Unchecked_Type_Conversion
4412 or else Nkind
(Obj
) = N_Type_Conversion
4414 return Is_Tagged_Type
(Etype
(Obj
))
4415 and then Is_Aliased_View
(Expression
(Obj
));
4417 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
4418 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
4423 end Is_Aliased_View
;
4425 -------------------------
4426 -- Is_Ancestor_Package --
4427 -------------------------
4429 function Is_Ancestor_Package
4431 E2
: Entity_Id
) return Boolean
4438 and then Par
/= Standard_Standard
4448 end Is_Ancestor_Package
;
4450 ----------------------
4451 -- Is_Atomic_Object --
4452 ----------------------
4454 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
4456 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
4457 -- Determines if given object has atomic components
4459 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
4460 -- If prefix is an implicit dereference, examine designated type
4462 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
4464 if Is_Access_Type
(Etype
(N
)) then
4466 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
4468 return Object_Has_Atomic_Components
(N
);
4470 end Is_Atomic_Prefix
;
4472 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
4474 if Has_Atomic_Components
(Etype
(N
))
4475 or else Is_Atomic
(Etype
(N
))
4479 elsif Is_Entity_Name
(N
)
4480 and then (Has_Atomic_Components
(Entity
(N
))
4481 or else Is_Atomic
(Entity
(N
)))
4485 elsif Nkind
(N
) = N_Indexed_Component
4486 or else Nkind
(N
) = N_Selected_Component
4488 return Is_Atomic_Prefix
(Prefix
(N
));
4493 end Object_Has_Atomic_Components
;
4495 -- Start of processing for Is_Atomic_Object
4498 if Is_Atomic
(Etype
(N
))
4499 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
4503 elsif Nkind
(N
) = N_Indexed_Component
4504 or else Nkind
(N
) = N_Selected_Component
4506 return Is_Atomic_Prefix
(Prefix
(N
));
4511 end Is_Atomic_Object
;
4513 --------------------------------------
4514 -- Is_Controlling_Limited_Procedure --
4515 --------------------------------------
4517 function Is_Controlling_Limited_Procedure
4518 (Proc_Nam
: Entity_Id
) return Boolean
4520 Param_Typ
: Entity_Id
:= Empty
;
4523 if Ekind
(Proc_Nam
) = E_Procedure
4524 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
4526 Param_Typ
:= Etype
(Parameter_Type
(First
(
4527 Parameter_Specifications
(Parent
(Proc_Nam
)))));
4529 -- In this case where an Itype was created, the procedure call has been
4532 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
4533 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
4535 Present
(Parameter_Associations
4536 (Associated_Node_For_Itype
(Proc_Nam
)))
4539 Etype
(First
(Parameter_Associations
4540 (Associated_Node_For_Itype
(Proc_Nam
))));
4543 if Present
(Param_Typ
) then
4545 Is_Interface
(Param_Typ
)
4546 and then Is_Limited_Record
(Param_Typ
);
4550 end Is_Controlling_Limited_Procedure
;
4552 ----------------------------------------------
4553 -- Is_Dependent_Component_Of_Mutable_Object --
4554 ----------------------------------------------
4556 function Is_Dependent_Component_Of_Mutable_Object
4557 (Object
: Node_Id
) return Boolean
4560 Prefix_Type
: Entity_Id
;
4561 P_Aliased
: Boolean := False;
4564 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
4565 -- Returns True if and only if Comp is declared within a variant part
4567 --------------------------------
4568 -- Is_Declared_Within_Variant --
4569 --------------------------------
4571 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
4572 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
4573 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
4575 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
4576 end Is_Declared_Within_Variant
;
4578 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
4581 if Is_Variable
(Object
) then
4583 if Nkind
(Object
) = N_Selected_Component
then
4584 P
:= Prefix
(Object
);
4585 Prefix_Type
:= Etype
(P
);
4587 if Is_Entity_Name
(P
) then
4589 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
4590 Prefix_Type
:= Base_Type
(Prefix_Type
);
4593 if Is_Aliased
(Entity
(P
)) then
4597 -- A discriminant check on a selected component may be
4598 -- expanded into a dereference when removing side-effects.
4599 -- Recover the original node and its type, which may be
4602 elsif Nkind
(P
) = N_Explicit_Dereference
4603 and then not (Comes_From_Source
(P
))
4605 P
:= Original_Node
(P
);
4606 Prefix_Type
:= Etype
(P
);
4609 -- Check for prefix being an aliased component ???
4614 -- A heap object is constrained by its initial value
4616 -- Ada 2005 (AI-363): Always assume the object could be mutable in
4617 -- the dereferenced case, since the access value might denote an
4618 -- unconstrained aliased object, whereas in Ada 95 the designated
4619 -- object is guaranteed to be constrained. A worst-case assumption
4620 -- has to apply in Ada 2005 because we can't tell at compile time
4621 -- whether the object is "constrained by its initial value"
4622 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
4623 -- semantic rules -- these rules are acknowledged to need fixing).
4625 if Ada_Version
< Ada_05
then
4626 if Is_Access_Type
(Prefix_Type
)
4627 or else Nkind
(P
) = N_Explicit_Dereference
4632 elsif Ada_Version
>= Ada_05
then
4633 if Is_Access_Type
(Prefix_Type
) then
4634 Prefix_Type
:= Designated_Type
(Prefix_Type
);
4639 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
4641 -- As per AI-0017, the renaming is illegal in a generic body,
4642 -- even if the subtype is indefinite.
4644 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
4646 if not Is_Constrained
(Prefix_Type
)
4647 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
4649 (Is_Generic_Type
(Prefix_Type
)
4650 and then Ekind
(Current_Scope
) = E_Generic_Package
4651 and then In_Package_Body
(Current_Scope
)))
4653 and then (Is_Declared_Within_Variant
(Comp
)
4654 or else Has_Discriminant_Dependent_Constraint
(Comp
))
4655 and then (not P_Aliased
or else Ada_Version
>= Ada_05
)
4661 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
4665 elsif Nkind
(Object
) = N_Indexed_Component
4666 or else Nkind
(Object
) = N_Slice
4668 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
4670 -- A type conversion that Is_Variable is a view conversion:
4671 -- go back to the denoted object.
4673 elsif Nkind
(Object
) = N_Type_Conversion
then
4675 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
4680 end Is_Dependent_Component_Of_Mutable_Object
;
4682 ---------------------
4683 -- Is_Dereferenced --
4684 ---------------------
4686 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
4687 P
: constant Node_Id
:= Parent
(N
);
4690 (Nkind
(P
) = N_Selected_Component
4692 Nkind
(P
) = N_Explicit_Dereference
4694 Nkind
(P
) = N_Indexed_Component
4696 Nkind
(P
) = N_Slice
)
4697 and then Prefix
(P
) = N
;
4698 end Is_Dereferenced
;
4700 ----------------------
4701 -- Is_Descendent_Of --
4702 ----------------------
4704 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
4709 pragma Assert
(Nkind
(T1
) in N_Entity
);
4710 pragma Assert
(Nkind
(T2
) in N_Entity
);
4712 T
:= Base_Type
(T1
);
4714 -- Immediate return if the types match
4719 -- Comment needed here ???
4721 elsif Ekind
(T
) = E_Class_Wide_Type
then
4722 return Etype
(T
) = T2
;
4730 -- Done if we found the type we are looking for
4735 -- Done if no more derivations to check
4742 -- Following test catches error cases resulting from prev errors
4744 elsif No
(Etyp
) then
4747 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
4750 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
4754 T
:= Base_Type
(Etyp
);
4758 raise Program_Error
;
4759 end Is_Descendent_Of
;
4761 ------------------------------
4762 -- Is_Descendent_Of_Address --
4763 ------------------------------
4765 function Is_Descendent_Of_Address
(T1
: Entity_Id
) return Boolean is
4767 -- If Address has not been loaded, answer must be False
4769 if not RTU_Loaded
(System
) then
4772 -- Otherwise we can get the entity we are interested in without
4773 -- causing an unwanted dependency on System, and do the test.
4776 return Is_Descendent_Of
(T1
, Base_Type
(RTE
(RE_Address
)));
4778 end Is_Descendent_Of_Address
;
4784 function Is_False
(U
: Uint
) return Boolean is
4789 ---------------------------
4790 -- Is_Fixed_Model_Number --
4791 ---------------------------
4793 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
4794 S
: constant Ureal
:= Small_Value
(T
);
4795 M
: Urealp
.Save_Mark
;
4799 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
4802 end Is_Fixed_Model_Number
;
4804 -------------------------------
4805 -- Is_Fully_Initialized_Type --
4806 -------------------------------
4808 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
4810 if Is_Scalar_Type
(Typ
) then
4813 elsif Is_Access_Type
(Typ
) then
4816 elsif Is_Array_Type
(Typ
) then
4817 if Is_Fully_Initialized_Type
(Component_Type
(Typ
)) then
4821 -- An interesting case, if we have a constrained type one of whose
4822 -- bounds is known to be null, then there are no elements to be
4823 -- initialized, so all the elements are initialized!
4825 if Is_Constrained
(Typ
) then
4828 Indx_Typ
: Entity_Id
;
4832 Indx
:= First_Index
(Typ
);
4833 while Present
(Indx
) loop
4834 if Etype
(Indx
) = Any_Type
then
4837 -- If index is a range, use directly
4839 elsif Nkind
(Indx
) = N_Range
then
4840 Lbd
:= Low_Bound
(Indx
);
4841 Hbd
:= High_Bound
(Indx
);
4844 Indx_Typ
:= Etype
(Indx
);
4846 if Is_Private_Type
(Indx_Typ
) then
4847 Indx_Typ
:= Full_View
(Indx_Typ
);
4850 if No
(Indx_Typ
) then
4853 Lbd
:= Type_Low_Bound
(Indx_Typ
);
4854 Hbd
:= Type_High_Bound
(Indx_Typ
);
4858 if Compile_Time_Known_Value
(Lbd
)
4859 and then Compile_Time_Known_Value
(Hbd
)
4861 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
4871 -- If no null indexes, then type is not fully initialized
4877 elsif Is_Record_Type
(Typ
) then
4878 if Has_Discriminants
(Typ
)
4880 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
4881 and then Is_Fully_Initialized_Variant
(Typ
)
4886 -- Controlled records are considered to be fully initialized if
4887 -- there is a user defined Initialize routine. This may not be
4888 -- entirely correct, but as the spec notes, we are guessing here
4889 -- what is best from the point of view of issuing warnings.
4891 if Is_Controlled
(Typ
) then
4893 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
4896 if Present
(Utyp
) then
4898 Init
: constant Entity_Id
:=
4900 (Underlying_Type
(Typ
), Name_Initialize
));
4904 and then Comes_From_Source
(Init
)
4906 Is_Predefined_File_Name
4907 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
4911 elsif Has_Null_Extension
(Typ
)
4913 Is_Fully_Initialized_Type
4914 (Etype
(Base_Type
(Typ
)))
4923 -- Otherwise see if all record components are initialized
4929 Ent
:= First_Entity
(Typ
);
4930 while Present
(Ent
) loop
4931 if Chars
(Ent
) = Name_uController
then
4934 elsif Ekind
(Ent
) = E_Component
4935 and then (No
(Parent
(Ent
))
4936 or else No
(Expression
(Parent
(Ent
))))
4937 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
4946 -- No uninitialized components, so type is fully initialized.
4947 -- Note that this catches the case of no components as well.
4951 elsif Is_Concurrent_Type
(Typ
) then
4954 elsif Is_Private_Type
(Typ
) then
4956 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
4962 return Is_Fully_Initialized_Type
(U
);
4969 end Is_Fully_Initialized_Type
;
4971 ----------------------------------
4972 -- Is_Fully_Initialized_Variant --
4973 ----------------------------------
4975 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
4976 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4977 Constraints
: constant List_Id
:= New_List
;
4978 Components
: constant Elist_Id
:= New_Elmt_List
;
4979 Comp_Elmt
: Elmt_Id
;
4981 Comp_List
: Node_Id
;
4983 Discr_Val
: Node_Id
;
4984 Report_Errors
: Boolean;
4987 if Serious_Errors_Detected
> 0 then
4991 if Is_Record_Type
(Typ
)
4992 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
4993 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
4995 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
4997 Discr
:= First_Discriminant
(Typ
);
4998 while Present
(Discr
) loop
4999 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
5000 Discr_Val
:= Expression
(Parent
(Discr
));
5002 if Present
(Discr_Val
)
5003 and then Is_OK_Static_Expression
(Discr_Val
)
5005 Append_To
(Constraints
,
5006 Make_Component_Association
(Loc
,
5007 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
5008 Expression
=> New_Copy
(Discr_Val
)));
5016 Next_Discriminant
(Discr
);
5021 Comp_List
=> Comp_List
,
5022 Governed_By
=> Constraints
,
5024 Report_Errors
=> Report_Errors
);
5026 -- Check that each component present is fully initialized
5028 Comp_Elmt
:= First_Elmt
(Components
);
5029 while Present
(Comp_Elmt
) loop
5030 Comp_Id
:= Node
(Comp_Elmt
);
5032 if Ekind
(Comp_Id
) = E_Component
5033 and then (No
(Parent
(Comp_Id
))
5034 or else No
(Expression
(Parent
(Comp_Id
))))
5035 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
5040 Next_Elmt
(Comp_Elmt
);
5045 elsif Is_Private_Type
(Typ
) then
5047 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5053 return Is_Fully_Initialized_Variant
(U
);
5059 end Is_Fully_Initialized_Variant
;
5061 ----------------------------
5062 -- Is_Inherited_Operation --
5063 ----------------------------
5065 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
5066 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
5068 pragma Assert
(Is_Overloadable
(E
));
5069 return Kind
= N_Full_Type_Declaration
5070 or else Kind
= N_Private_Extension_Declaration
5071 or else Kind
= N_Subtype_Declaration
5072 or else (Ekind
(E
) = E_Enumeration_Literal
5073 and then Is_Derived_Type
(Etype
(E
)));
5074 end Is_Inherited_Operation
;
5076 -----------------------------
5077 -- Is_Library_Level_Entity --
5078 -----------------------------
5080 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
5082 -- The following is a small optimization, and it also handles
5083 -- properly discriminals, which in task bodies might appear in
5084 -- expressions before the corresponding procedure has been
5085 -- created, and which therefore do not have an assigned scope.
5087 if Ekind
(E
) in Formal_Kind
then
5091 -- Normal test is simply that the enclosing dynamic scope is Standard
5093 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
5094 end Is_Library_Level_Entity
;
5096 ---------------------------------
5097 -- Is_Local_Variable_Reference --
5098 ---------------------------------
5100 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
5102 if not Is_Entity_Name
(Expr
) then
5107 Ent
: constant Entity_Id
:= Entity
(Expr
);
5108 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
5110 if Ekind
(Ent
) /= E_Variable
5112 Ekind
(Ent
) /= E_In_Out_Parameter
5116 return Present
(Sub
) and then Sub
= Current_Subprogram
;
5120 end Is_Local_Variable_Reference
;
5122 -------------------------
5123 -- Is_Object_Reference --
5124 -------------------------
5126 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
5128 if Is_Entity_Name
(N
) then
5129 return Is_Object
(Entity
(N
));
5133 when N_Indexed_Component | N_Slice
=>
5135 Is_Object_Reference
(Prefix
(N
))
5136 or else Is_Access_Type
(Etype
(Prefix
(N
)));
5138 -- In Ada95, a function call is a constant object; a procedure
5141 when N_Function_Call
=>
5142 return Etype
(N
) /= Standard_Void_Type
;
5144 -- A reference to the stream attribute Input is a function call
5146 when N_Attribute_Reference
=>
5147 return Attribute_Name
(N
) = Name_Input
;
5149 when N_Selected_Component
=>
5151 Is_Object_Reference
(Selector_Name
(N
))
5153 (Is_Object_Reference
(Prefix
(N
))
5154 or else Is_Access_Type
(Etype
(Prefix
(N
))));
5156 when N_Explicit_Dereference
=>
5159 -- A view conversion of a tagged object is an object reference
5161 when N_Type_Conversion
=>
5162 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
5163 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
5164 and then Is_Object_Reference
(Expression
(N
));
5166 -- An unchecked type conversion is considered to be an object if
5167 -- the operand is an object (this construction arises only as a
5168 -- result of expansion activities).
5170 when N_Unchecked_Type_Conversion
=>
5177 end Is_Object_Reference
;
5179 -----------------------------------
5180 -- Is_OK_Variable_For_Out_Formal --
5181 -----------------------------------
5183 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
5185 Note_Possible_Modification
(AV
);
5187 -- We must reject parenthesized variable names. The check for
5188 -- Comes_From_Source is present because there are currently
5189 -- cases where the compiler violates this rule (e.g. passing
5190 -- a task object to its controlled Initialize routine).
5192 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
5195 -- A variable is always allowed
5197 elsif Is_Variable
(AV
) then
5200 -- Unchecked conversions are allowed only if they come from the
5201 -- generated code, which sometimes uses unchecked conversions for out
5202 -- parameters in cases where code generation is unaffected. We tell
5203 -- source unchecked conversions by seeing if they are rewrites of an
5204 -- original Unchecked_Conversion function call, or of an explicit
5205 -- conversion of a function call.
5207 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
5208 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
5211 elsif Comes_From_Source
(AV
)
5212 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
5216 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
5217 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
5223 -- Normal type conversions are allowed if argument is a variable
5225 elsif Nkind
(AV
) = N_Type_Conversion
then
5226 if Is_Variable
(Expression
(AV
))
5227 and then Paren_Count
(Expression
(AV
)) = 0
5229 Note_Possible_Modification
(Expression
(AV
));
5232 -- We also allow a non-parenthesized expression that raises
5233 -- constraint error if it rewrites what used to be a variable
5235 elsif Raises_Constraint_Error
(Expression
(AV
))
5236 and then Paren_Count
(Expression
(AV
)) = 0
5237 and then Is_Variable
(Original_Node
(Expression
(AV
)))
5241 -- Type conversion of something other than a variable
5247 -- If this node is rewritten, then test the original form, if that is
5248 -- OK, then we consider the rewritten node OK (for example, if the
5249 -- original node is a conversion, then Is_Variable will not be true
5250 -- but we still want to allow the conversion if it converts a variable).
5252 elsif Original_Node
(AV
) /= AV
then
5253 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
5255 -- All other non-variables are rejected
5260 end Is_OK_Variable_For_Out_Formal
;
5262 -----------------------------------
5263 -- Is_Partially_Initialized_Type --
5264 -----------------------------------
5266 function Is_Partially_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
5268 if Is_Scalar_Type
(Typ
) then
5271 elsif Is_Access_Type
(Typ
) then
5274 elsif Is_Array_Type
(Typ
) then
5276 -- If component type is partially initialized, so is array type
5278 if Is_Partially_Initialized_Type
(Component_Type
(Typ
)) then
5281 -- Otherwise we are only partially initialized if we are fully
5282 -- initialized (this is the empty array case, no point in us
5283 -- duplicating that code here).
5286 return Is_Fully_Initialized_Type
(Typ
);
5289 elsif Is_Record_Type
(Typ
) then
5291 -- A discriminated type is always partially initialized
5293 if Has_Discriminants
(Typ
) then
5296 -- A tagged type is always partially initialized
5298 elsif Is_Tagged_Type
(Typ
) then
5301 -- Case of non-discriminated record
5307 Component_Present
: Boolean := False;
5308 -- Set True if at least one component is present. If no
5309 -- components are present, then record type is fully
5310 -- initialized (another odd case, like the null array).
5313 -- Loop through components
5315 Ent
:= First_Entity
(Typ
);
5316 while Present
(Ent
) loop
5317 if Ekind
(Ent
) = E_Component
then
5318 Component_Present
:= True;
5320 -- If a component has an initialization expression then
5321 -- the enclosing record type is partially initialized
5323 if Present
(Parent
(Ent
))
5324 and then Present
(Expression
(Parent
(Ent
)))
5328 -- If a component is of a type which is itself partially
5329 -- initialized, then the enclosing record type is also.
5331 elsif Is_Partially_Initialized_Type
(Etype
(Ent
)) then
5339 -- No initialized components found. If we found any components
5340 -- they were all uninitialized so the result is false.
5342 if Component_Present
then
5345 -- But if we found no components, then all the components are
5346 -- initialized so we consider the type to be initialized.
5354 -- Concurrent types are always fully initialized
5356 elsif Is_Concurrent_Type
(Typ
) then
5359 -- For a private type, go to underlying type. If there is no underlying
5360 -- type then just assume this partially initialized. Not clear if this
5361 -- can happen in a non-error case, but no harm in testing for this.
5363 elsif Is_Private_Type
(Typ
) then
5365 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
5370 return Is_Partially_Initialized_Type
(U
);
5374 -- For any other type (are there any?) assume partially initialized
5379 end Is_Partially_Initialized_Type
;
5381 ------------------------------------
5382 -- Is_Potentially_Persistent_Type --
5383 ------------------------------------
5385 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
5390 -- For private type, test corrresponding full type
5392 if Is_Private_Type
(T
) then
5393 return Is_Potentially_Persistent_Type
(Full_View
(T
));
5395 -- Scalar types are potentially persistent
5397 elsif Is_Scalar_Type
(T
) then
5400 -- Record type is potentially persistent if not tagged and the types of
5401 -- all it components are potentially persistent, and no component has
5402 -- an initialization expression.
5404 elsif Is_Record_Type
(T
)
5405 and then not Is_Tagged_Type
(T
)
5406 and then not Is_Partially_Initialized_Type
(T
)
5408 Comp
:= First_Component
(T
);
5409 while Present
(Comp
) loop
5410 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
5419 -- Array type is potentially persistent if its component type is
5420 -- potentially persistent and if all its constraints are static.
5422 elsif Is_Array_Type
(T
) then
5423 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
5427 Indx
:= First_Index
(T
);
5428 while Present
(Indx
) loop
5429 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
5438 -- All other types are not potentially persistent
5443 end Is_Potentially_Persistent_Type
;
5445 -----------------------------
5446 -- Is_RCI_Pkg_Spec_Or_Body --
5447 -----------------------------
5449 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
5451 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
5452 -- Return True if the unit of Cunit is an RCI package declaration
5454 ---------------------------
5455 -- Is_RCI_Pkg_Decl_Cunit --
5456 ---------------------------
5458 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
5459 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
5462 if Nkind
(The_Unit
) /= N_Package_Declaration
then
5466 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
5467 end Is_RCI_Pkg_Decl_Cunit
;
5469 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
5472 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
5474 (Nkind
(Unit
(Cunit
)) = N_Package_Body
5475 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
5476 end Is_RCI_Pkg_Spec_Or_Body
;
5478 -----------------------------------------
5479 -- Is_Remote_Access_To_Class_Wide_Type --
5480 -----------------------------------------
5482 function Is_Remote_Access_To_Class_Wide_Type
5483 (E
: Entity_Id
) return Boolean
5487 function Comes_From_Limited_Private_Type_Declaration
5488 (E
: Entity_Id
) return Boolean;
5489 -- Check that the type is declared by a limited type declaration,
5490 -- or else is derived from a Remote_Type ancestor through private
5493 -------------------------------------------------
5494 -- Comes_From_Limited_Private_Type_Declaration --
5495 -------------------------------------------------
5497 function Comes_From_Limited_Private_Type_Declaration
5498 (E
: Entity_Id
) return Boolean
5500 N
: constant Node_Id
:= Declaration_Node
(E
);
5503 if Nkind
(N
) = N_Private_Type_Declaration
5504 and then Limited_Present
(N
)
5509 if Nkind
(N
) = N_Private_Extension_Declaration
then
5511 Comes_From_Limited_Private_Type_Declaration
(Etype
(E
))
5513 (Is_Remote_Types
(Etype
(E
))
5514 and then Is_Limited_Record
(Etype
(E
))
5515 and then Has_Private_Declaration
(Etype
(E
)));
5519 end Comes_From_Limited_Private_Type_Declaration
;
5521 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
5524 if not (Is_Remote_Call_Interface
(E
)
5525 or else Is_Remote_Types
(E
))
5526 or else Ekind
(E
) /= E_General_Access_Type
5531 D
:= Designated_Type
(E
);
5533 if Ekind
(D
) /= E_Class_Wide_Type
then
5537 return Comes_From_Limited_Private_Type_Declaration
5538 (Defining_Identifier
(Parent
(D
)));
5539 end Is_Remote_Access_To_Class_Wide_Type
;
5541 -----------------------------------------
5542 -- Is_Remote_Access_To_Subprogram_Type --
5543 -----------------------------------------
5545 function Is_Remote_Access_To_Subprogram_Type
5546 (E
: Entity_Id
) return Boolean
5549 return (Ekind
(E
) = E_Access_Subprogram_Type
5550 or else (Ekind
(E
) = E_Record_Type
5551 and then Present
(Corresponding_Remote_Type
(E
))))
5552 and then (Is_Remote_Call_Interface
(E
)
5553 or else Is_Remote_Types
(E
));
5554 end Is_Remote_Access_To_Subprogram_Type
;
5556 --------------------
5557 -- Is_Remote_Call --
5558 --------------------
5560 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
5562 if Nkind
(N
) /= N_Procedure_Call_Statement
5563 and then Nkind
(N
) /= N_Function_Call
5565 -- An entry call cannot be remote
5569 elsif Nkind
(Name
(N
)) in N_Has_Entity
5570 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
5572 -- A subprogram declared in the spec of a RCI package is remote
5576 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
5577 and then Is_Remote_Access_To_Subprogram_Type
5578 (Etype
(Prefix
(Name
(N
))))
5580 -- The dereference of a RAS is a remote call
5584 elsif Present
(Controlling_Argument
(N
))
5585 and then Is_Remote_Access_To_Class_Wide_Type
5586 (Etype
(Controlling_Argument
(N
)))
5588 -- Any primitive operation call with a controlling argument of
5589 -- a RACW type is a remote call.
5594 -- All other calls are local calls
5599 ----------------------
5600 -- Is_Renamed_Entry --
5601 ----------------------
5603 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
5604 Orig_Node
: Node_Id
:= Empty
;
5605 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
5607 function Is_Entry
(Nam
: Node_Id
) return Boolean;
5608 -- Determine whether Nam is an entry. Traverse selectors
5609 -- if there are nested selected components.
5615 function Is_Entry
(Nam
: Node_Id
) return Boolean is
5617 if Nkind
(Nam
) = N_Selected_Component
then
5618 return Is_Entry
(Selector_Name
(Nam
));
5621 return Ekind
(Entity
(Nam
)) = E_Entry
;
5624 -- Start of processing for Is_Renamed_Entry
5627 if Present
(Alias
(Proc_Nam
)) then
5628 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
5631 -- Look for a rewritten subprogram renaming declaration
5633 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
5634 and then Present
(Original_Node
(Subp_Decl
))
5636 Orig_Node
:= Original_Node
(Subp_Decl
);
5639 -- The rewritten subprogram is actually an entry
5641 if Present
(Orig_Node
)
5642 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
5643 and then Is_Entry
(Name
(Orig_Node
))
5649 end Is_Renamed_Entry
;
5651 ----------------------
5652 -- Is_Selector_Name --
5653 ----------------------
5655 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
5657 if not Is_List_Member
(N
) then
5659 P
: constant Node_Id
:= Parent
(N
);
5660 K
: constant Node_Kind
:= Nkind
(P
);
5663 (K
= N_Expanded_Name
or else
5664 K
= N_Generic_Association
or else
5665 K
= N_Parameter_Association
or else
5666 K
= N_Selected_Component
)
5667 and then Selector_Name
(P
) = N
;
5672 L
: constant List_Id
:= List_Containing
(N
);
5673 P
: constant Node_Id
:= Parent
(L
);
5675 return (Nkind
(P
) = N_Discriminant_Association
5676 and then Selector_Names
(P
) = L
)
5678 (Nkind
(P
) = N_Component_Association
5679 and then Choices
(P
) = L
);
5682 end Is_Selector_Name
;
5688 function Is_Statement
(N
: Node_Id
) return Boolean is
5691 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
5692 or else Nkind
(N
) = N_Procedure_Call_Statement
;
5699 function Is_Transfer
(N
: Node_Id
) return Boolean is
5700 Kind
: constant Node_Kind
:= Nkind
(N
);
5703 if Kind
= N_Return_Statement
5705 Kind
= N_Extended_Return_Statement
5707 Kind
= N_Goto_Statement
5709 Kind
= N_Raise_Statement
5711 Kind
= N_Requeue_Statement
5715 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
5716 and then No
(Condition
(N
))
5720 elsif Kind
= N_Procedure_Call_Statement
5721 and then Is_Entity_Name
(Name
(N
))
5722 and then Present
(Entity
(Name
(N
)))
5723 and then No_Return
(Entity
(Name
(N
)))
5727 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
5739 function Is_True
(U
: Uint
) return Boolean is
5748 function Is_Variable
(N
: Node_Id
) return Boolean is
5750 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
5751 -- We do the test on the original node, since this is basically a
5752 -- test of syntactic categories, so it must not be disturbed by
5753 -- whatever rewriting might have occurred. For example, an aggregate,
5754 -- which is certainly NOT a variable, could be turned into a variable
5757 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
5758 -- Within a protected function, the private components of the
5759 -- enclosing protected type are constants. A function nested within
5760 -- a (protected) procedure is not itself protected.
5762 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
5763 -- Prefixes can involve implicit dereferences, in which case we
5764 -- must test for the case of a reference of a constant access
5765 -- type, which can never be a variable.
5767 ---------------------------
5768 -- In_Protected_Function --
5769 ---------------------------
5771 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
5772 Prot
: constant Entity_Id
:= Scope
(E
);
5776 if not Is_Protected_Type
(Prot
) then
5780 while Present
(S
) and then S
/= Prot
loop
5781 if Ekind
(S
) = E_Function
5782 and then Scope
(S
) = Prot
5792 end In_Protected_Function
;
5794 ------------------------
5795 -- Is_Variable_Prefix --
5796 ------------------------
5798 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
5800 if Is_Access_Type
(Etype
(P
)) then
5801 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
5803 -- For the case of an indexed component whose prefix has a packed
5804 -- array type, the prefix has been rewritten into a type conversion.
5805 -- Determine variable-ness from the converted expression.
5807 elsif Nkind
(P
) = N_Type_Conversion
5808 and then not Comes_From_Source
(P
)
5809 and then Is_Array_Type
(Etype
(P
))
5810 and then Is_Packed
(Etype
(P
))
5812 return Is_Variable
(Expression
(P
));
5815 return Is_Variable
(P
);
5817 end Is_Variable_Prefix
;
5819 -- Start of processing for Is_Variable
5822 -- Definitely OK if Assignment_OK is set. Since this is something that
5823 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
5825 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
5828 -- Normally we go to the original node, but there is one exception
5829 -- where we use the rewritten node, namely when it is an explicit
5830 -- dereference. The generated code may rewrite a prefix which is an
5831 -- access type with an explicit dereference. The dereference is a
5832 -- variable, even though the original node may not be (since it could
5833 -- be a constant of the access type).
5835 elsif Nkind
(N
) = N_Explicit_Dereference
5836 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
5837 and then Is_Access_Type
(Etype
(Orig_Node
))
5839 return Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
5841 -- A function call is never a variable
5843 elsif Nkind
(N
) = N_Function_Call
then
5846 -- All remaining checks use the original node
5848 elsif Is_Entity_Name
(Orig_Node
) then
5850 E
: constant Entity_Id
:= Entity
(Orig_Node
);
5851 K
: constant Entity_Kind
:= Ekind
(E
);
5854 return (K
= E_Variable
5855 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
5856 or else (K
= E_Component
5857 and then not In_Protected_Function
(E
))
5858 or else K
= E_Out_Parameter
5859 or else K
= E_In_Out_Parameter
5860 or else K
= E_Generic_In_Out_Parameter
5862 -- Current instance of type:
5864 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
5865 or else (Is_Incomplete_Or_Private_Type
(E
)
5866 and then In_Open_Scopes
(Full_View
(E
)));
5870 case Nkind
(Orig_Node
) is
5871 when N_Indexed_Component | N_Slice
=>
5872 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
5874 when N_Selected_Component
=>
5875 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
5876 and then Is_Variable
(Selector_Name
(Orig_Node
));
5878 -- For an explicit dereference, the type of the prefix cannot
5879 -- be an access to constant or an access to subprogram.
5881 when N_Explicit_Dereference
=>
5883 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
5885 return Is_Access_Type
(Typ
)
5886 and then not Is_Access_Constant
(Root_Type
(Typ
))
5887 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
5890 -- The type conversion is the case where we do not deal with the
5891 -- context dependent special case of an actual parameter. Thus
5892 -- the type conversion is only considered a variable for the
5893 -- purposes of this routine if the target type is tagged. However,
5894 -- a type conversion is considered to be a variable if it does not
5895 -- come from source (this deals for example with the conversions
5896 -- of expressions to their actual subtypes).
5898 when N_Type_Conversion
=>
5899 return Is_Variable
(Expression
(Orig_Node
))
5901 (not Comes_From_Source
(Orig_Node
)
5903 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
5905 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
5907 -- GNAT allows an unchecked type conversion as a variable. This
5908 -- only affects the generation of internal expanded code, since
5909 -- calls to instantiations of Unchecked_Conversion are never
5910 -- considered variables (since they are function calls).
5911 -- This is also true for expression actions.
5913 when N_Unchecked_Type_Conversion
=>
5914 return Is_Variable
(Expression
(Orig_Node
));
5922 ------------------------
5923 -- Is_Volatile_Object --
5924 ------------------------
5926 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
5928 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
5929 -- Determines if given object has volatile components
5931 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
5932 -- If prefix is an implicit dereference, examine designated type
5934 ------------------------
5935 -- Is_Volatile_Prefix --
5936 ------------------------
5938 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
5939 Typ
: constant Entity_Id
:= Etype
(N
);
5942 if Is_Access_Type
(Typ
) then
5944 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
5947 return Is_Volatile
(Dtyp
)
5948 or else Has_Volatile_Components
(Dtyp
);
5952 return Object_Has_Volatile_Components
(N
);
5954 end Is_Volatile_Prefix
;
5956 ------------------------------------
5957 -- Object_Has_Volatile_Components --
5958 ------------------------------------
5960 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
5961 Typ
: constant Entity_Id
:= Etype
(N
);
5964 if Is_Volatile
(Typ
)
5965 or else Has_Volatile_Components
(Typ
)
5969 elsif Is_Entity_Name
(N
)
5970 and then (Has_Volatile_Components
(Entity
(N
))
5971 or else Is_Volatile
(Entity
(N
)))
5975 elsif Nkind
(N
) = N_Indexed_Component
5976 or else Nkind
(N
) = N_Selected_Component
5978 return Is_Volatile_Prefix
(Prefix
(N
));
5983 end Object_Has_Volatile_Components
;
5985 -- Start of processing for Is_Volatile_Object
5988 if Is_Volatile
(Etype
(N
))
5989 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
5993 elsif Nkind
(N
) = N_Indexed_Component
5994 or else Nkind
(N
) = N_Selected_Component
5996 return Is_Volatile_Prefix
(Prefix
(N
));
6001 end Is_Volatile_Object
;
6003 -------------------------
6004 -- Kill_Current_Values --
6005 -------------------------
6007 procedure Kill_Current_Values
(Ent
: Entity_Id
) is
6009 if Is_Object
(Ent
) then
6011 Set_Current_Value
(Ent
, Empty
);
6013 if Ekind
(Ent
) = E_Variable
then
6014 Set_Last_Assignment
(Ent
, Empty
);
6017 if not Can_Never_Be_Null
(Ent
) then
6018 Set_Is_Known_Non_Null
(Ent
, False);
6021 Set_Is_Known_Null
(Ent
, False);
6023 end Kill_Current_Values
;
6025 procedure Kill_Current_Values
is
6028 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
6029 -- Clear current value for entity E and all entities chained to E
6031 ------------------------------------------
6032 -- Kill_Current_Values_For_Entity_Chain --
6033 ------------------------------------------
6035 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
6039 while Present
(Ent
) loop
6040 Kill_Current_Values
(Ent
);
6043 end Kill_Current_Values_For_Entity_Chain
;
6045 -- Start of processing for Kill_Current_Values
6048 -- Kill all saved checks, a special case of killing saved values
6052 -- Loop through relevant scopes, which includes the current scope and
6053 -- any parent scopes if the current scope is a block or a package.
6058 -- Clear current values of all entities in current scope
6060 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
6062 -- If scope is a package, also clear current values of all
6063 -- private entities in the scope.
6065 if Ekind
(S
) = E_Package
6067 Ekind
(S
) = E_Generic_Package
6069 Is_Concurrent_Type
(S
)
6071 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
6074 -- If this is a not a subprogram, deal with parents
6076 if not Is_Subprogram
(S
) then
6078 exit Scope_Loop
when S
= Standard_Standard
;
6082 end loop Scope_Loop
;
6083 end Kill_Current_Values
;
6085 --------------------------
6086 -- Kill_Size_Check_Code --
6087 --------------------------
6089 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
6091 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
6092 and then Present
(Size_Check_Code
(E
))
6094 Remove
(Size_Check_Code
(E
));
6095 Set_Size_Check_Code
(E
, Empty
);
6097 end Kill_Size_Check_Code
;
6099 --------------------------
6100 -- Known_To_Be_Assigned --
6101 --------------------------
6103 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
6104 P
: constant Node_Id
:= Parent
(N
);
6109 -- Test left side of assignment
6111 when N_Assignment_Statement
=>
6112 return N
= Name
(P
);
6114 -- Function call arguments are never lvalues
6116 when N_Function_Call
=>
6119 -- Positional parameter for procedure or accept call
6121 when N_Procedure_Call_Statement |
6130 Proc
:= Get_Subprogram_Entity
(P
);
6136 -- If we are not a list member, something is strange, so
6137 -- be conservative and return False.
6139 if not Is_List_Member
(N
) then
6143 -- We are going to find the right formal by stepping forward
6144 -- through the formals, as we step backwards in the actuals.
6146 Form
:= First_Formal
(Proc
);
6149 -- If no formal, something is weird, so be conservative
6150 -- and return False.
6161 return Ekind
(Form
) /= E_In_Parameter
;
6164 -- Named parameter for procedure or accept call
6166 when N_Parameter_Association
=>
6172 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
6178 -- Loop through formals to find the one that matches
6180 Form
:= First_Formal
(Proc
);
6182 -- If no matching formal, that's peculiar, some kind of
6183 -- previous error, so return False to be conservative.
6189 -- Else test for match
6191 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
6192 return Ekind
(Form
) /= E_In_Parameter
;
6199 -- Test for appearing in a conversion that itself appears
6200 -- in an lvalue context, since this should be an lvalue.
6202 when N_Type_Conversion
=>
6203 return Known_To_Be_Assigned
(P
);
6205 -- All other references are definitely not knwon to be modifications
6211 end Known_To_Be_Assigned
;
6217 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
6218 P
: constant Node_Id
:= Parent
(N
);
6223 -- Test left side of assignment
6225 when N_Assignment_Statement
=>
6226 return N
= Name
(P
);
6228 -- Test prefix of component or attribute
6230 when N_Attribute_Reference |
6232 N_Explicit_Dereference |
6233 N_Indexed_Component |
6235 N_Selected_Component |
6237 return N
= Prefix
(P
);
6239 -- Function call arguments are never lvalues
6241 when N_Function_Call
=>
6244 -- Positional parameter for procedure or accept call
6246 when N_Procedure_Call_Statement |
6255 Proc
:= Get_Subprogram_Entity
(P
);
6261 -- If we are not a list member, something is strange, so
6262 -- be conservative and return True.
6264 if not Is_List_Member
(N
) then
6268 -- We are going to find the right formal by stepping forward
6269 -- through the formals, as we step backwards in the actuals.
6271 Form
:= First_Formal
(Proc
);
6274 -- If no formal, something is weird, so be conservative
6286 return Ekind
(Form
) /= E_In_Parameter
;
6289 -- Named parameter for procedure or accept call
6291 when N_Parameter_Association
=>
6297 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
6303 -- Loop through formals to find the one that matches
6305 Form
:= First_Formal
(Proc
);
6307 -- If no matching formal, that's peculiar, some kind of
6308 -- previous error, so return True to be conservative.
6314 -- Else test for match
6316 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
6317 return Ekind
(Form
) /= E_In_Parameter
;
6324 -- Test for appearing in a conversion that itself appears
6325 -- in an lvalue context, since this should be an lvalue.
6327 when N_Type_Conversion
=>
6328 return May_Be_Lvalue
(P
);
6330 -- Test for appearence in object renaming declaration
6332 when N_Object_Renaming_Declaration
=>
6335 -- All other references are definitely not Lvalues
6343 -------------------------
6344 -- New_External_Entity --
6345 -------------------------
6347 function New_External_Entity
6348 (Kind
: Entity_Kind
;
6349 Scope_Id
: Entity_Id
;
6350 Sloc_Value
: Source_Ptr
;
6351 Related_Id
: Entity_Id
;
6353 Suffix_Index
: Nat
:= 0;
6354 Prefix
: Character := ' ') return Entity_Id
6356 N
: constant Entity_Id
:=
6357 Make_Defining_Identifier
(Sloc_Value
,
6359 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
6362 Set_Ekind
(N
, Kind
);
6363 Set_Is_Internal
(N
, True);
6364 Append_Entity
(N
, Scope_Id
);
6365 Set_Public_Status
(N
);
6367 if Kind
in Type_Kind
then
6368 Init_Size_Align
(N
);
6372 end New_External_Entity
;
6374 -------------------------
6375 -- New_Internal_Entity --
6376 -------------------------
6378 function New_Internal_Entity
6379 (Kind
: Entity_Kind
;
6380 Scope_Id
: Entity_Id
;
6381 Sloc_Value
: Source_Ptr
;
6382 Id_Char
: Character) return Entity_Id
6384 N
: constant Entity_Id
:=
6385 Make_Defining_Identifier
(Sloc_Value
, New_Internal_Name
(Id_Char
));
6388 Set_Ekind
(N
, Kind
);
6389 Set_Is_Internal
(N
, True);
6390 Append_Entity
(N
, Scope_Id
);
6392 if Kind
in Type_Kind
then
6393 Init_Size_Align
(N
);
6397 end New_Internal_Entity
;
6403 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
6407 -- If we are pointing at a positional parameter, it is a member of
6408 -- a node list (the list of parameters), and the next parameter
6409 -- is the next node on the list, unless we hit a parameter
6410 -- association, in which case we shift to using the chain whose
6411 -- head is the First_Named_Actual in the parent, and then is
6412 -- threaded using the Next_Named_Actual of the Parameter_Association.
6413 -- All this fiddling is because the original node list is in the
6414 -- textual call order, and what we need is the declaration order.
6416 if Is_List_Member
(Actual_Id
) then
6417 N
:= Next
(Actual_Id
);
6419 if Nkind
(N
) = N_Parameter_Association
then
6420 return First_Named_Actual
(Parent
(Actual_Id
));
6426 return Next_Named_Actual
(Parent
(Actual_Id
));
6430 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
6432 Actual_Id
:= Next_Actual
(Actual_Id
);
6435 -----------------------
6436 -- Normalize_Actuals --
6437 -----------------------
6439 -- Chain actuals according to formals of subprogram. If there are no named
6440 -- associations, the chain is simply the list of Parameter Associations,
6441 -- since the order is the same as the declaration order. If there are named
6442 -- associations, then the First_Named_Actual field in the N_Function_Call
6443 -- or N_Procedure_Call_Statement node points to the Parameter_Association
6444 -- node for the parameter that comes first in declaration order. The
6445 -- remaining named parameters are then chained in declaration order using
6446 -- Next_Named_Actual.
6448 -- This routine also verifies that the number of actuals is compatible with
6449 -- the number and default values of formals, but performs no type checking
6450 -- (type checking is done by the caller).
6452 -- If the matching succeeds, Success is set to True and the caller proceeds
6453 -- with type-checking. If the match is unsuccessful, then Success is set to
6454 -- False, and the caller attempts a different interpretation, if there is
6457 -- If the flag Report is on, the call is not overloaded, and a failure to
6458 -- match can be reported here, rather than in the caller.
6460 procedure Normalize_Actuals
6464 Success
: out Boolean)
6466 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
6467 Actual
: Node_Id
:= Empty
;
6469 Last
: Node_Id
:= Empty
;
6470 First_Named
: Node_Id
:= Empty
;
6473 Formals_To_Match
: Integer := 0;
6474 Actuals_To_Match
: Integer := 0;
6476 procedure Chain
(A
: Node_Id
);
6477 -- Add named actual at the proper place in the list, using the
6478 -- Next_Named_Actual link.
6480 function Reporting
return Boolean;
6481 -- Determines if an error is to be reported. To report an error, we
6482 -- need Report to be True, and also we do not report errors caused
6483 -- by calls to init procs that occur within other init procs. Such
6484 -- errors must always be cascaded errors, since if all the types are
6485 -- declared correctly, the compiler will certainly build decent calls!
6491 procedure Chain
(A
: Node_Id
) is
6495 -- Call node points to first actual in list
6497 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
6500 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
6504 Set_Next_Named_Actual
(Last
, Empty
);
6511 function Reporting
return Boolean is
6516 elsif not Within_Init_Proc
then
6519 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
6527 -- Start of processing for Normalize_Actuals
6530 if Is_Access_Type
(S
) then
6532 -- The name in the call is a function call that returns an access
6533 -- to subprogram. The designated type has the list of formals.
6535 Formal
:= First_Formal
(Designated_Type
(S
));
6537 Formal
:= First_Formal
(S
);
6540 while Present
(Formal
) loop
6541 Formals_To_Match
:= Formals_To_Match
+ 1;
6542 Next_Formal
(Formal
);
6545 -- Find if there is a named association, and verify that no positional
6546 -- associations appear after named ones.
6548 if Present
(Actuals
) then
6549 Actual
:= First
(Actuals
);
6552 while Present
(Actual
)
6553 and then Nkind
(Actual
) /= N_Parameter_Association
6555 Actuals_To_Match
:= Actuals_To_Match
+ 1;
6559 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
6561 -- Most common case: positional notation, no defaults
6566 elsif Actuals_To_Match
> Formals_To_Match
then
6568 -- Too many actuals: will not work
6571 if Is_Entity_Name
(Name
(N
)) then
6572 Error_Msg_N
("too many arguments in call to&", Name
(N
));
6574 Error_Msg_N
("too many arguments in call", N
);
6582 First_Named
:= Actual
;
6584 while Present
(Actual
) loop
6585 if Nkind
(Actual
) /= N_Parameter_Association
then
6587 ("positional parameters not allowed after named ones", Actual
);
6592 Actuals_To_Match
:= Actuals_To_Match
+ 1;
6598 if Present
(Actuals
) then
6599 Actual
:= First
(Actuals
);
6602 Formal
:= First_Formal
(S
);
6603 while Present
(Formal
) loop
6605 -- Match the formals in order. If the corresponding actual
6606 -- is positional, nothing to do. Else scan the list of named
6607 -- actuals to find the one with the right name.
6610 and then Nkind
(Actual
) /= N_Parameter_Association
6613 Actuals_To_Match
:= Actuals_To_Match
- 1;
6614 Formals_To_Match
:= Formals_To_Match
- 1;
6617 -- For named parameters, search the list of actuals to find
6618 -- one that matches the next formal name.
6620 Actual
:= First_Named
;
6622 while Present
(Actual
) loop
6623 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
6626 Actuals_To_Match
:= Actuals_To_Match
- 1;
6627 Formals_To_Match
:= Formals_To_Match
- 1;
6635 if Ekind
(Formal
) /= E_In_Parameter
6636 or else No
(Default_Value
(Formal
))
6639 if (Comes_From_Source
(S
)
6640 or else Sloc
(S
) = Standard_Location
)
6641 and then Is_Overloadable
(S
)
6645 (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
6647 (Nkind
(Parent
(N
)) = N_Function_Call
6649 Nkind
(Parent
(N
)) = N_Parameter_Association
))
6650 and then Ekind
(S
) /= E_Function
6652 Set_Etype
(N
, Etype
(S
));
6654 Error_Msg_Name_1
:= Chars
(S
);
6655 Error_Msg_Sloc
:= Sloc
(S
);
6657 ("missing argument for parameter & " &
6658 "in call to % declared #", N
, Formal
);
6661 elsif Is_Overloadable
(S
) then
6662 Error_Msg_Name_1
:= Chars
(S
);
6664 -- Point to type derivation that generated the
6667 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
6670 ("missing argument for parameter & " &
6671 "in call to % (inherited) #", N
, Formal
);
6675 ("missing argument for parameter &", N
, Formal
);
6683 Formals_To_Match
:= Formals_To_Match
- 1;
6688 Next_Formal
(Formal
);
6691 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
6698 -- Find some superfluous named actual that did not get
6699 -- attached to the list of associations.
6701 Actual
:= First
(Actuals
);
6702 while Present
(Actual
) loop
6703 if Nkind
(Actual
) = N_Parameter_Association
6704 and then Actual
/= Last
6705 and then No
(Next_Named_Actual
(Actual
))
6707 Error_Msg_N
("unmatched actual & in call",
6708 Selector_Name
(Actual
));
6719 end Normalize_Actuals
;
6721 --------------------------------
6722 -- Note_Possible_Modification --
6723 --------------------------------
6725 procedure Note_Possible_Modification
(N
: Node_Id
) is
6726 Modification_Comes_From_Source
: constant Boolean :=
6727 Comes_From_Source
(Parent
(N
));
6733 -- Loop to find referenced entity, if there is one
6740 if Is_Entity_Name
(Exp
) then
6741 Ent
:= Entity
(Exp
);
6743 -- If the entity is missing, it is an undeclared identifier,
6744 -- and there is nothing to annotate.
6750 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
6752 P
: constant Node_Id
:= Prefix
(Exp
);
6755 if Nkind
(P
) = N_Selected_Component
6757 Entry_Formal
(Entity
(Selector_Name
(P
))))
6759 -- Case of a reference to an entry formal
6761 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
6763 elsif Nkind
(P
) = N_Identifier
6764 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
6765 and then Present
(Expression
(Parent
(Entity
(P
))))
6766 and then Nkind
(Expression
(Parent
(Entity
(P
))))
6769 -- Case of a reference to a value on which
6770 -- side effects have been removed.
6772 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
6781 elsif Nkind
(Exp
) = N_Type_Conversion
6782 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
6784 Exp
:= Expression
(Exp
);
6787 elsif Nkind
(Exp
) = N_Slice
6788 or else Nkind
(Exp
) = N_Indexed_Component
6789 or else Nkind
(Exp
) = N_Selected_Component
6791 Exp
:= Prefix
(Exp
);
6798 -- Now look for entity being referenced
6800 if Present
(Ent
) then
6801 if Is_Object
(Ent
) then
6802 if Comes_From_Source
(Exp
)
6803 or else Modification_Comes_From_Source
6805 Set_Never_Set_In_Source
(Ent
, False);
6808 Set_Is_True_Constant
(Ent
, False);
6809 Set_Current_Value
(Ent
, Empty
);
6810 Set_Is_Known_Null
(Ent
, False);
6812 if not Can_Never_Be_Null
(Ent
) then
6813 Set_Is_Known_Non_Null
(Ent
, False);
6816 -- Follow renaming chain
6818 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
6819 and then Present
(Renamed_Object
(Ent
))
6821 Exp
:= Renamed_Object
(Ent
);
6825 -- Generate a reference only if the assignment comes from
6826 -- source. This excludes, for example, calls to a dispatching
6827 -- assignment operation when the left-hand side is tagged.
6829 if Modification_Comes_From_Source
then
6830 Generate_Reference
(Ent
, Exp
, 'm');
6838 end Note_Possible_Modification
;
6840 -------------------------
6841 -- Object_Access_Level --
6842 -------------------------
6844 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
6847 -- Returns the static accessibility level of the view denoted
6848 -- by Obj. Note that the value returned is the result of a
6849 -- call to Scope_Depth. Only scope depths associated with
6850 -- dynamic scopes can actually be returned. Since only
6851 -- relative levels matter for accessibility checking, the fact
6852 -- that the distance between successive levels of accessibility
6853 -- is not always one is immaterial (invariant: if level(E2) is
6854 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
6857 if Is_Entity_Name
(Obj
) then
6860 -- If E is a type then it denotes a current instance.
6861 -- For this case we add one to the normal accessibility
6862 -- level of the type to ensure that current instances
6863 -- are treated as always being deeper than than the level
6864 -- of any visible named access type (see 3.10.2(21)).
6867 return Type_Access_Level
(E
) + 1;
6869 elsif Present
(Renamed_Object
(E
)) then
6870 return Object_Access_Level
(Renamed_Object
(E
));
6872 -- Similarly, if E is a component of the current instance of a
6873 -- protected type, any instance of it is assumed to be at a deeper
6874 -- level than the type. For a protected object (whose type is an
6875 -- anonymous protected type) its components are at the same level
6876 -- as the type itself.
6878 elsif not Is_Overloadable
(E
)
6879 and then Ekind
(Scope
(E
)) = E_Protected_Type
6880 and then Comes_From_Source
(Scope
(E
))
6882 return Type_Access_Level
(Scope
(E
)) + 1;
6885 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
6888 elsif Nkind
(Obj
) = N_Selected_Component
then
6889 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
6890 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
6892 return Object_Access_Level
(Prefix
(Obj
));
6895 elsif Nkind
(Obj
) = N_Indexed_Component
then
6896 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
6897 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
6899 return Object_Access_Level
(Prefix
(Obj
));
6902 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
6904 -- If the prefix is a selected access discriminant then
6905 -- we make a recursive call on the prefix, which will
6906 -- in turn check the level of the prefix object of
6907 -- the selected discriminant.
6909 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
6910 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
6912 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
6914 return Object_Access_Level
(Prefix
(Obj
));
6916 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
6919 elsif Nkind
(Obj
) = N_Type_Conversion
6920 or else Nkind
(Obj
) = N_Unchecked_Type_Conversion
6922 return Object_Access_Level
(Expression
(Obj
));
6924 -- Function results are objects, so we get either the access level
6925 -- of the function or, in the case of an indirect call, the level of
6926 -- of the access-to-subprogram type.
6928 elsif Nkind
(Obj
) = N_Function_Call
then
6929 if Is_Entity_Name
(Name
(Obj
)) then
6930 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
6932 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
6935 -- For convenience we handle qualified expressions, even though
6936 -- they aren't technically object names.
6938 elsif Nkind
(Obj
) = N_Qualified_Expression
then
6939 return Object_Access_Level
(Expression
(Obj
));
6941 -- Otherwise return the scope level of Standard.
6942 -- (If there are cases that fall through
6943 -- to this point they will be treated as
6944 -- having global accessibility for now. ???)
6947 return Scope_Depth
(Standard_Standard
);
6949 end Object_Access_Level
;
6951 --------------------------------------
6952 -- Overrides_Synchronized_Primitive --
6953 --------------------------------------
6955 function Overrides_Synchronized_Primitive
6956 (Def_Id
: Entity_Id
;
6957 First_Hom
: Entity_Id
;
6958 Ifaces_List
: Elist_Id
;
6959 In_Scope
: Boolean := True) return Entity_Id
6961 Candidate
: Entity_Id
;
6964 function Matches_Prefixed_View_Profile
6965 (Subp_Params
: List_Id
;
6966 Over_Params
: List_Id
) return Boolean;
6967 -- Determine if a subprogram parameter profile (Subp_Params)
6968 -- matches that of a potentially overriden subprogram (Over_Params).
6969 -- Determine if the type of first parameter in the list Over_Params
6970 -- is an implemented interface, that is to say, the interface is in
6973 -----------------------------------
6974 -- Matches_Prefixed_View_Profile --
6975 -----------------------------------
6977 function Matches_Prefixed_View_Profile
6978 (Subp_Params
: List_Id
;
6979 Over_Params
: List_Id
) return Boolean
6981 Subp_Param
: Node_Id
;
6982 Over_Param
: Node_Id
;
6983 Over_Param_Typ
: Entity_Id
;
6985 function Is_Implemented
(Iface
: Entity_Id
) return Boolean;
6986 -- Determine if Iface is implemented by the current task or
6989 --------------------
6990 -- Is_Implemented --
6991 --------------------
6993 function Is_Implemented
(Iface
: Entity_Id
) return Boolean is
6994 Iface_Elmt
: Elmt_Id
;
6997 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
6998 while Present
(Iface_Elmt
) loop
6999 if Node
(Iface_Elmt
) = Iface
then
7003 Next_Elmt
(Iface_Elmt
);
7009 -- Start of processing for Matches_Prefixed_View_Profile
7012 Subp_Param
:= First
(Subp_Params
);
7013 Over_Param
:= First
(Over_Params
);
7015 if Nkind
(Parameter_Type
(Over_Param
)) = N_Access_Definition
then
7017 Etype
(Subtype_Mark
(Parameter_Type
(Over_Param
)));
7019 Over_Param_Typ
:= Etype
(Parameter_Type
(Over_Param
));
7022 -- The first parameter of the potentially overriden subprogram
7023 -- must be an interface implemented by Def_Id.
7025 if not Is_Interface
(Over_Param_Typ
)
7026 or else not Is_Implemented
(Over_Param_Typ
)
7031 -- This may be a primitive declared after a task or protected type.
7032 -- We need to skip the first parameter since it is irrelevant.
7034 if not In_Scope
then
7035 Subp_Param
:= Next
(Subp_Param
);
7037 Over_Param
:= Next
(Over_Param
);
7039 while Present
(Subp_Param
) and then Present
(Over_Param
) loop
7041 -- The two parameters must be mode conformant and both types
7042 -- must be the same.
7044 if Ekind
(Defining_Identifier
(Subp_Param
)) /=
7045 Ekind
(Defining_Identifier
(Over_Param
))
7047 Etype
(Parameter_Type
(Subp_Param
)) /=
7048 Etype
(Parameter_Type
(Over_Param
))
7057 -- One of the two lists contains more parameters than the other
7059 if Present
(Subp_Param
) or else Present
(Over_Param
) then
7064 end Matches_Prefixed_View_Profile
;
7066 -- Start of processing for Overrides_Synchronized_Primitive
7069 -- At this point the caller should have collected the interfaces
7070 -- implemented by the synchronized type.
7072 pragma Assert
(Present
(Ifaces_List
));
7074 -- Traverse the homonym chain, looking at a potentially overriden
7075 -- subprogram that belongs to an implemented interface.
7078 while Present
(Hom
) loop
7081 -- Entries can override abstract or null interface procedures
7083 if Ekind
(Def_Id
) = E_Entry
7084 and then Ekind
(Candidate
) = E_Procedure
7085 and then Nkind
(Parent
(Candidate
)) = N_Procedure_Specification
7086 and then (Is_Abstract
(Candidate
)
7087 or else Null_Present
(Parent
(Candidate
)))
7089 while Present
(Alias
(Candidate
)) loop
7090 Candidate
:= Alias
(Candidate
);
7093 if Matches_Prefixed_View_Profile
7094 (Parameter_Specifications
(Parent
(Def_Id
)),
7095 Parameter_Specifications
(Parent
(Candidate
)))
7100 -- Procedure can override abstract or null interface procedures
7102 elsif Ekind
(Def_Id
) = E_Procedure
7103 and then Ekind
(Candidate
) = E_Procedure
7104 and then Nkind
(Parent
(Candidate
)) = N_Procedure_Specification
7105 and then (Is_Abstract
(Candidate
)
7106 or else Null_Present
(Parent
(Candidate
)))
7107 and then Matches_Prefixed_View_Profile
7108 (Parameter_Specifications
(Parent
(Def_Id
)),
7109 Parameter_Specifications
(Parent
(Candidate
)))
7113 -- Function can override abstract interface functions
7115 elsif Ekind
(Def_Id
) = E_Function
7116 and then Ekind
(Candidate
) = E_Function
7117 and then Nkind
(Parent
(Candidate
)) = N_Function_Specification
7118 and then Is_Abstract
(Candidate
)
7119 and then Matches_Prefixed_View_Profile
7120 (Parameter_Specifications
(Parent
(Def_Id
)),
7121 Parameter_Specifications
(Parent
(Candidate
)))
7122 and then Etype
(Result_Definition
(Parent
(Def_Id
))) =
7123 Etype
(Result_Definition
(Parent
(Candidate
)))
7128 Hom
:= Homonym
(Hom
);
7132 end Overrides_Synchronized_Primitive
;
7134 -----------------------
7135 -- Private_Component --
7136 -----------------------
7138 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
7139 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
7141 function Trace_Components
7143 Check
: Boolean) return Entity_Id
;
7144 -- Recursive function that does the work, and checks against circular
7145 -- definition for each subcomponent type.
7147 ----------------------
7148 -- Trace_Components --
7149 ----------------------
7151 function Trace_Components
7153 Check
: Boolean) return Entity_Id
7155 Btype
: constant Entity_Id
:= Base_Type
(T
);
7156 Component
: Entity_Id
;
7158 Candidate
: Entity_Id
:= Empty
;
7161 if Check
and then Btype
= Ancestor
then
7162 Error_Msg_N
("circular type definition", Type_Id
);
7166 if Is_Private_Type
(Btype
)
7167 and then not Is_Generic_Type
(Btype
)
7169 if Present
(Full_View
(Btype
))
7170 and then Is_Record_Type
(Full_View
(Btype
))
7171 and then not Is_Frozen
(Btype
)
7173 -- To indicate that the ancestor depends on a private type,
7174 -- the current Btype is sufficient. However, to check for
7175 -- circular definition we must recurse on the full view.
7177 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
7179 if Candidate
= Any_Type
then
7189 elsif Is_Array_Type
(Btype
) then
7190 return Trace_Components
(Component_Type
(Btype
), True);
7192 elsif Is_Record_Type
(Btype
) then
7193 Component
:= First_Entity
(Btype
);
7194 while Present
(Component
) loop
7196 -- Skip anonymous types generated by constrained components
7198 if not Is_Type
(Component
) then
7199 P
:= Trace_Components
(Etype
(Component
), True);
7202 if P
= Any_Type
then
7210 Next_Entity
(Component
);
7218 end Trace_Components
;
7220 -- Start of processing for Private_Component
7223 return Trace_Components
(Type_Id
, False);
7224 end Private_Component
;
7226 -----------------------
7227 -- Process_End_Label --
7228 -----------------------
7230 procedure Process_End_Label
7238 Label_Ref
: Boolean;
7239 -- Set True if reference to end label itself is required
7242 -- Gets set to the operator symbol or identifier that references
7243 -- the entity Ent. For the child unit case, this is the identifier
7244 -- from the designator. For other cases, this is simply Endl.
7246 procedure Generate_Parent_Ref
(N
: Node_Id
);
7247 -- N is an identifier node that appears as a parent unit reference
7248 -- in the case where Ent is a child unit. This procedure generates
7249 -- an appropriate cross-reference entry.
7251 -------------------------
7252 -- Generate_Parent_Ref --
7253 -------------------------
7255 procedure Generate_Parent_Ref
(N
: Node_Id
) is
7256 Parent_Ent
: Entity_Id
;
7259 -- Search up scope stack. The reason we do this is that normal
7260 -- visibility analysis would not work for two reasons. First in
7261 -- some subunit cases, the entry for the parent unit may not be
7262 -- visible, and in any case there can be a local entity that
7263 -- hides the scope entity.
7265 Parent_Ent
:= Current_Scope
;
7266 while Present
(Parent_Ent
) loop
7267 if Chars
(Parent_Ent
) = Chars
(N
) then
7269 -- Generate the reference. We do NOT consider this as a
7270 -- reference for unreferenced symbol purposes, but we do
7271 -- force a cross-reference even if the end line does not
7272 -- come from source (the caller already generated the
7273 -- appropriate Typ for this situation).
7276 (Parent_Ent
, N
, 'r', Set_Ref
=> False, Force
=> True);
7277 Style
.Check_Identifier
(N
, Parent_Ent
);
7281 Parent_Ent
:= Scope
(Parent_Ent
);
7284 -- Fall through means entity was not found -- that's odd, but
7285 -- the appropriate thing is simply to ignore and not generate
7286 -- any cross-reference for this entry.
7289 end Generate_Parent_Ref
;
7291 -- Start of processing for Process_End_Label
7294 -- If no node, ignore. This happens in some error situations,
7295 -- and also for some internally generated structures where no
7296 -- end label references are required in any case.
7302 -- Nothing to do if no End_Label, happens for internally generated
7303 -- constructs where we don't want an end label reference anyway.
7304 -- Also nothing to do if Endl is a string literal, which means
7305 -- there was some prior error (bad operator symbol)
7307 Endl
:= End_Label
(N
);
7309 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
7313 -- Reference node is not in extended main source unit
7315 if not In_Extended_Main_Source_Unit
(N
) then
7317 -- Generally we do not collect references except for the
7318 -- extended main source unit. The one exception is the 'e'
7319 -- entry for a package spec, where it is useful for a client
7320 -- to have the ending information to define scopes.
7328 -- For this case, we can ignore any parent references,
7329 -- but we need the package name itself for the 'e' entry.
7331 if Nkind
(Endl
) = N_Designator
then
7332 Endl
:= Identifier
(Endl
);
7336 -- Reference is in extended main source unit
7341 -- For designator, generate references for the parent entries
7343 if Nkind
(Endl
) = N_Designator
then
7345 -- Generate references for the prefix if the END line comes
7346 -- from source (otherwise we do not need these references)
7348 if Comes_From_Source
(Endl
) then
7350 while Nkind
(Nam
) = N_Selected_Component
loop
7351 Generate_Parent_Ref
(Selector_Name
(Nam
));
7352 Nam
:= Prefix
(Nam
);
7355 Generate_Parent_Ref
(Nam
);
7358 Endl
:= Identifier
(Endl
);
7362 -- If the end label is not for the given entity, then either we have
7363 -- some previous error, or this is a generic instantiation for which
7364 -- we do not need to make a cross-reference in this case anyway. In
7365 -- either case we simply ignore the call.
7367 if Chars
(Ent
) /= Chars
(Endl
) then
7371 -- If label was really there, then generate a normal reference
7372 -- and then adjust the location in the end label to point past
7373 -- the name (which should almost always be the semicolon).
7377 if Comes_From_Source
(Endl
) then
7379 -- If a label reference is required, then do the style check
7380 -- and generate an l-type cross-reference entry for the label
7384 Style
.Check_Identifier
(Endl
, Ent
);
7386 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
7389 -- Set the location to point past the label (normally this will
7390 -- mean the semicolon immediately following the label). This is
7391 -- done for the sake of the 'e' or 't' entry generated below.
7393 Get_Decoded_Name_String
(Chars
(Endl
));
7394 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
7397 -- Now generate the e/t reference
7399 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
7401 -- Restore Sloc, in case modified above, since we have an identifier
7402 -- and the normal Sloc should be left set in the tree.
7404 Set_Sloc
(Endl
, Loc
);
7405 end Process_End_Label
;
7411 -- We do the conversion to get the value of the real string by using
7412 -- the scanner, see Sinput for details on use of the internal source
7413 -- buffer for scanning internal strings.
7415 function Real_Convert
(S
: String) return Node_Id
is
7416 Save_Src
: constant Source_Buffer_Ptr
:= Source
;
7420 Source
:= Internal_Source_Ptr
;
7423 for J
in S
'Range loop
7424 Source
(Source_Ptr
(J
)) := S
(J
);
7427 Source
(S
'Length + 1) := EOF
;
7429 if Source
(Scan_Ptr
) = '-' then
7431 Scan_Ptr
:= Scan_Ptr
+ 1;
7439 Set_Realval
(Token_Node
, UR_Negate
(Realval
(Token_Node
)));
7446 ---------------------
7447 -- Rep_To_Pos_Flag --
7448 ---------------------
7450 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
7452 return New_Occurrence_Of
7453 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
7454 end Rep_To_Pos_Flag
;
7456 --------------------
7457 -- Require_Entity --
7458 --------------------
7460 procedure Require_Entity
(N
: Node_Id
) is
7462 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
7463 if Total_Errors_Detected
/= 0 then
7464 Set_Entity
(N
, Any_Id
);
7466 raise Program_Error
;
7471 ------------------------------
7472 -- Requires_Transient_Scope --
7473 ------------------------------
7475 -- A transient scope is required when variable-sized temporaries are
7476 -- allocated in the primary or secondary stack, or when finalization
7477 -- actions must be generated before the next instruction.
7479 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
7480 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
7482 -- Start of processing for Requires_Transient_Scope
7485 -- This is a private type which is not completed yet. This can only
7486 -- happen in a default expression (of a formal parameter or of a
7487 -- record component). Do not expand transient scope in this case
7492 -- Do not expand transient scope for non-existent procedure return
7494 elsif Typ
= Standard_Void_Type
then
7497 -- Elementary types do not require a transient scope
7499 elsif Is_Elementary_Type
(Typ
) then
7502 -- Generally, indefinite subtypes require a transient scope, since the
7503 -- back end cannot generate temporaries, since this is not a valid type
7504 -- for declaring an object. It might be possible to relax this in the
7505 -- future, e.g. by declaring the maximum possible space for the type.
7507 elsif Is_Indefinite_Subtype
(Typ
) then
7510 -- Functions returning tagged types may dispatch on result so their
7511 -- returned value is allocated on the secondary stack. Controlled
7512 -- type temporaries need finalization.
7514 elsif Is_Tagged_Type
(Typ
)
7515 or else Has_Controlled_Component
(Typ
)
7521 elsif Is_Record_Type
(Typ
) then
7523 -- In GCC 2, discriminated records always require a transient
7524 -- scope because the back end otherwise tries to allocate a
7525 -- variable length temporary for the particular variant.
7527 if Opt
.GCC_Version
= 2
7528 and then Has_Discriminants
(Typ
)
7532 -- For GCC 3, or for a non-discriminated record in GCC 2, we are
7533 -- OK if none of the component types requires a transient scope.
7534 -- Note that we already know that this is a definite type (i.e.
7535 -- has discriminant defaults if it is a discriminated record).
7541 Comp
:= First_Entity
(Typ
);
7542 while Present
(Comp
) loop
7543 if Ekind
(Comp
) = E_Component
7544 and then Requires_Transient_Scope
(Etype
(Comp
))
7556 -- String literal types never require transient scope
7558 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
7561 -- Array type. Note that we already know that this is a constrained
7562 -- array, since unconstrained arrays will fail the indefinite test.
7564 elsif Is_Array_Type
(Typ
) then
7566 -- If component type requires a transient scope, the array does too
7568 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
7571 -- Otherwise, we only need a transient scope if the size is not
7572 -- known at compile time.
7575 return not Size_Known_At_Compile_Time
(Typ
);
7578 -- All other cases do not require a transient scope
7583 end Requires_Transient_Scope
;
7585 --------------------------
7586 -- Reset_Analyzed_Flags --
7587 --------------------------
7589 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
7591 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
7592 -- Function used to reset Analyzed flags in tree. Note that we do
7593 -- not reset Analyzed flags in entities, since there is no need to
7594 -- renalalyze entities, and indeed, it is wrong to do so, since it
7595 -- can result in generating auxiliary stuff more than once.
7597 --------------------
7598 -- Clear_Analyzed --
7599 --------------------
7601 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
7603 if not Has_Extension
(N
) then
7604 Set_Analyzed
(N
, False);
7610 function Reset_Analyzed
is
7611 new Traverse_Func
(Clear_Analyzed
);
7613 Discard
: Traverse_Result
;
7614 pragma Warnings
(Off
, Discard
);
7616 -- Start of processing for Reset_Analyzed_Flags
7619 Discard
:= Reset_Analyzed
(N
);
7620 end Reset_Analyzed_Flags
;
7622 ---------------------------
7623 -- Safe_To_Capture_Value --
7624 ---------------------------
7626 function Safe_To_Capture_Value
7629 Cond
: Boolean := False) return Boolean
7632 -- The only entities for which we track constant values are variables,
7633 -- which are not renamings, out parameters and in out parameters, so
7634 -- check if we have this case.
7636 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
7638 Ekind
(Ent
) = E_Out_Parameter
7640 Ekind
(Ent
) = E_In_Out_Parameter
7644 -- For conditionals, we also allow constants, loop parameters and all
7645 -- formals, including in parameters.
7649 (Ekind
(Ent
) = E_Constant
7651 Ekind
(Ent
) = E_Loop_Parameter
7653 Ekind
(Ent
) = E_In_Parameter
)
7657 -- For all other cases, not just unsafe, but impossible to capture
7658 -- Current_Value, since the above are the only entities which have
7659 -- Current_Value fields.
7665 -- Skip volatile and aliased variables, since funny things might
7666 -- be going on in these cases which we cannot necessarily track.
7667 -- Also skip any variable for which an address clause is given.
7669 if Treat_As_Volatile
(Ent
)
7670 or else Is_Aliased
(Ent
)
7671 or else Present
(Address_Clause
(Ent
))
7676 -- OK, all above conditions are met. We also require that the scope
7677 -- of the reference be the same as the scope of the entity, not
7678 -- counting packages and blocks and loops.
7681 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
7682 R_Scope
: Entity_Id
;
7685 R_Scope
:= Current_Scope
;
7686 while R_Scope
/= Standard_Standard
loop
7687 exit when R_Scope
= E_Scope
;
7689 if Ekind
(R_Scope
) /= E_Package
7691 Ekind
(R_Scope
) /= E_Block
7693 Ekind
(R_Scope
) /= E_Loop
7697 R_Scope
:= Scope
(R_Scope
);
7702 -- We also require that the reference does not appear in a context
7703 -- where it is not sure to be executed (i.e. a conditional context
7704 -- or an exception handler). We skip this if Cond is True, since the
7705 -- capturing of values from conditional tests handles this ok.
7719 while Present
(P
) loop
7720 if Nkind
(P
) = N_If_Statement
7721 or else Nkind
(P
) = N_Case_Statement
7722 or else (Nkind
(P
) = N_And_Then
and then Desc
= Right_Opnd
(P
))
7723 or else (Nkind
(P
) = N_Or_Else
and then Desc
= Right_Opnd
(P
))
7724 or else Nkind
(P
) = N_Exception_Handler
7725 or else Nkind
(P
) = N_Selective_Accept
7726 or else Nkind
(P
) = N_Conditional_Entry_Call
7727 or else Nkind
(P
) = N_Timed_Entry_Call
7728 or else Nkind
(P
) = N_Asynchronous_Select
7738 -- OK, looks safe to set value
7741 end Safe_To_Capture_Value
;
7747 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
7748 K1
: constant Node_Kind
:= Nkind
(N1
);
7749 K2
: constant Node_Kind
:= Nkind
(N2
);
7752 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
7753 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
7755 return Chars
(N1
) = Chars
(N2
);
7757 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
7758 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
7760 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
7761 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
7772 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
7777 elsif not Is_Constrained
(T1
)
7778 and then not Is_Constrained
(T2
)
7779 and then Base_Type
(T1
) = Base_Type
(T2
)
7783 -- For now don't bother with case of identical constraints, to be
7784 -- fiddled with later on perhaps (this is only used for optimization
7785 -- purposes, so it is not critical to do a best possible job)
7792 ------------------------
7793 -- Scope_Is_Transient --
7794 ------------------------
7796 function Scope_Is_Transient
return Boolean is
7798 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
7799 end Scope_Is_Transient
;
7805 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
7810 while Scop
/= Standard_Standard
loop
7811 Scop
:= Scope
(Scop
);
7813 if Scop
= Scope2
then
7821 --------------------------
7822 -- Scope_Within_Or_Same --
7823 --------------------------
7825 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
7830 while Scop
/= Standard_Standard
loop
7831 if Scop
= Scope2
then
7834 Scop
:= Scope
(Scop
);
7839 end Scope_Within_Or_Same
;
7841 ------------------------
7842 -- Set_Current_Entity --
7843 ------------------------
7845 -- The given entity is to be set as the currently visible definition
7846 -- of its associated name (i.e. the Node_Id associated with its name).
7847 -- All we have to do is to get the name from the identifier, and
7848 -- then set the associated Node_Id to point to the given entity.
7850 procedure Set_Current_Entity
(E
: Entity_Id
) is
7852 Set_Name_Entity_Id
(Chars
(E
), E
);
7853 end Set_Current_Entity
;
7855 ---------------------------------
7856 -- Set_Entity_With_Style_Check --
7857 ---------------------------------
7859 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
7860 Val_Actual
: Entity_Id
;
7864 Set_Entity
(N
, Val
);
7867 and then not Suppress_Style_Checks
(Val
)
7868 and then not In_Instance
7870 if Nkind
(N
) = N_Identifier
then
7872 elsif Nkind
(N
) = N_Expanded_Name
then
7873 Nod
:= Selector_Name
(N
);
7878 -- A special situation arises for derived operations, where we want
7879 -- to do the check against the parent (since the Sloc of the derived
7880 -- operation points to the derived type declaration itself).
7883 while not Comes_From_Source
(Val_Actual
)
7884 and then Nkind
(Val_Actual
) in N_Entity
7885 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
7886 or else Is_Subprogram
(Val_Actual
)
7887 or else Is_Generic_Subprogram
(Val_Actual
))
7888 and then Present
(Alias
(Val_Actual
))
7890 Val_Actual
:= Alias
(Val_Actual
);
7893 -- Renaming declarations for generic actuals do not come from source,
7894 -- and have a different name from that of the entity they rename, so
7895 -- there is no style check to perform here.
7897 if Chars
(Nod
) = Chars
(Val_Actual
) then
7898 Style
.Check_Identifier
(Nod
, Val_Actual
);
7902 Set_Entity
(N
, Val
);
7903 end Set_Entity_With_Style_Check
;
7905 ------------------------
7906 -- Set_Name_Entity_Id --
7907 ------------------------
7909 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
7911 Set_Name_Table_Info
(Id
, Int
(Val
));
7912 end Set_Name_Entity_Id
;
7914 ---------------------
7915 -- Set_Next_Actual --
7916 ---------------------
7918 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
7920 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
7921 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
7923 end Set_Next_Actual
;
7925 -----------------------
7926 -- Set_Public_Status --
7927 -----------------------
7929 procedure Set_Public_Status
(Id
: Entity_Id
) is
7930 S
: constant Entity_Id
:= Current_Scope
;
7933 -- Everything in the scope of Standard is public
7935 if S
= Standard_Standard
then
7938 -- Entity is definitely not public if enclosing scope is not public
7940 elsif not Is_Public
(S
) then
7943 -- An object declaration that occurs in a handled sequence of statements
7944 -- is the declaration for a temporary object generated by the expander.
7945 -- It never needs to be made public and furthermore, making it public
7946 -- can cause back end problems if it is of variable size.
7948 elsif Nkind
(Parent
(Id
)) = N_Object_Declaration
7950 Nkind
(Parent
(Parent
(Id
))) = N_Handled_Sequence_Of_Statements
7954 -- Entities in public packages or records are public
7956 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
7959 -- The bounds of an entry family declaration can generate object
7960 -- declarations that are visible to the back-end, e.g. in the
7961 -- the declaration of a composite type that contains tasks.
7963 elsif Is_Concurrent_Type
(S
)
7964 and then not Has_Completion
(S
)
7965 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
7969 end Set_Public_Status
;
7971 ----------------------------
7972 -- Set_Scope_Is_Transient --
7973 ----------------------------
7975 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
7977 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
7978 end Set_Scope_Is_Transient
;
7984 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
7986 -- We copy Esize, but not RM_Size, since in general RM_Size is
7987 -- subtype specific and does not get inherited by all subtypes.
7989 Set_Esize
(T1
, Esize
(T2
));
7990 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
7992 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
7994 Is_Discrete_Or_Fixed_Point_Type
(T2
)
7996 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
7998 Set_Alignment
(T1
, Alignment
(T2
));
8001 --------------------
8002 -- Static_Integer --
8003 --------------------
8005 function Static_Integer
(N
: Node_Id
) return Uint
is
8007 Analyze_And_Resolve
(N
, Any_Integer
);
8010 or else Error_Posted
(N
)
8011 or else Etype
(N
) = Any_Type
8016 if Is_Static_Expression
(N
) then
8017 if not Raises_Constraint_Error
(N
) then
8018 return Expr_Value
(N
);
8023 elsif Etype
(N
) = Any_Type
then
8027 Flag_Non_Static_Expr
8028 ("static integer expression required here", N
);
8033 --------------------------
8034 -- Statically_Different --
8035 --------------------------
8037 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
8038 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
8039 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
8041 return Is_Entity_Name
(R1
)
8042 and then Is_Entity_Name
(R2
)
8043 and then Entity
(R1
) /= Entity
(R2
)
8044 and then not Is_Formal
(Entity
(R1
))
8045 and then not Is_Formal
(Entity
(R2
));
8046 end Statically_Different
;
8048 -----------------------------
8049 -- Subprogram_Access_Level --
8050 -----------------------------
8052 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
8054 if Present
(Alias
(Subp
)) then
8055 return Subprogram_Access_Level
(Alias
(Subp
));
8057 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
8059 end Subprogram_Access_Level
;
8065 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
8067 if Debug_Flag_W
then
8068 for J
in 0 .. Scope_Stack
.Last
loop
8073 Write_Name
(Chars
(E
));
8074 Write_Str
(" line ");
8075 Write_Int
(Int
(Get_Logical_Line_Number
(Sloc
(N
))));
8080 -----------------------
8081 -- Transfer_Entities --
8082 -----------------------
8084 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
8085 Ent
: Entity_Id
:= First_Entity
(From
);
8092 if (Last_Entity
(To
)) = Empty
then
8093 Set_First_Entity
(To
, Ent
);
8095 Set_Next_Entity
(Last_Entity
(To
), Ent
);
8098 Set_Last_Entity
(To
, Last_Entity
(From
));
8100 while Present
(Ent
) loop
8101 Set_Scope
(Ent
, To
);
8103 if not Is_Public
(Ent
) then
8104 Set_Public_Status
(Ent
);
8107 and then Ekind
(Ent
) = E_Record_Subtype
8110 -- The components of the propagated Itype must be public
8116 Comp
:= First_Entity
(Ent
);
8117 while Present
(Comp
) loop
8118 Set_Is_Public
(Comp
);
8128 Set_First_Entity
(From
, Empty
);
8129 Set_Last_Entity
(From
, Empty
);
8130 end Transfer_Entities
;
8132 -----------------------
8133 -- Type_Access_Level --
8134 -----------------------
8136 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
8140 -- If the type is an anonymous access type we treat it as being
8141 -- declared at the library level to ensure that names such as
8142 -- X.all'access don't fail static accessibility checks.
8144 -- Ada 2005 (AI-230): In case of anonymous access types that are
8145 -- component_definition or discriminants of a nonlimited type,
8146 -- the level is the same as that of the enclosing component type.
8148 Btyp
:= Base_Type
(Typ
);
8150 if Ekind
(Btyp
) in Access_Kind
then
8151 if Ekind
(Btyp
) = E_Anonymous_Access_Type
8152 and then not Is_Local_Anonymous_Access
(Typ
) -- Ada 2005 (AI-230)
8155 -- If this is a return_subtype, the accessibility level is that
8156 -- of the result subtype of the enclosing function.
8158 if Ekind
(Scope
(Btyp
)) = E_Return_Statement
then
8162 Scop
:= Scope
(Scope
(Btyp
));
8163 while Present
(Scop
) loop
8164 exit when Ekind
(Scop
) = E_Function
;
8165 Scop
:= Scope
(Scop
);
8168 return Scope_Depth
(Scope
(Scop
));
8172 return Scope_Depth
(Standard_Standard
);
8176 Btyp
:= Root_Type
(Btyp
);
8178 -- The accessibility level of anonymous acccess types associated with
8179 -- discriminants is that of the current instance of the type, and
8180 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
8182 -- AI-402: access discriminants have accessibility based on the
8183 -- object rather than the type in Ada2005, so the above
8184 -- paragraph doesn't apply
8186 -- ??? Needs completion with rules from AI-416
8188 if Ada_Version
<= Ada_95
8189 and then Ekind
(Typ
) = E_Anonymous_Access_Type
8190 and then Present
(Associated_Node_For_Itype
(Typ
))
8191 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
8192 N_Discriminant_Specification
8194 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
8198 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
8199 end Type_Access_Level
;
8201 --------------------------
8202 -- Unit_Declaration_Node --
8203 --------------------------
8205 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
8206 N
: Node_Id
:= Parent
(Unit_Id
);
8209 -- Predefined operators do not have a full function declaration
8211 if Ekind
(Unit_Id
) = E_Operator
then
8215 -- Isn't there some better way to express the following ???
8217 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
8218 and then Nkind
(N
) /= N_Formal_Package_Declaration
8219 and then Nkind
(N
) /= N_Function_Instantiation
8220 and then Nkind
(N
) /= N_Generic_Package_Declaration
8221 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
8222 and then Nkind
(N
) /= N_Package_Declaration
8223 and then Nkind
(N
) /= N_Package_Body
8224 and then Nkind
(N
) /= N_Package_Instantiation
8225 and then Nkind
(N
) /= N_Package_Renaming_Declaration
8226 and then Nkind
(N
) /= N_Procedure_Instantiation
8227 and then Nkind
(N
) /= N_Protected_Body
8228 and then Nkind
(N
) /= N_Subprogram_Declaration
8229 and then Nkind
(N
) /= N_Subprogram_Body
8230 and then Nkind
(N
) /= N_Subprogram_Body_Stub
8231 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
8232 and then Nkind
(N
) /= N_Task_Body
8233 and then Nkind
(N
) /= N_Task_Type_Declaration
8234 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
8235 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
8238 pragma Assert
(Present
(N
));
8242 end Unit_Declaration_Node
;
8244 ------------------------------
8245 -- Universal_Interpretation --
8246 ------------------------------
8248 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
8249 Index
: Interp_Index
;
8253 -- The argument may be a formal parameter of an operator or subprogram
8254 -- with multiple interpretations, or else an expression for an actual.
8256 if Nkind
(Opnd
) = N_Defining_Identifier
8257 or else not Is_Overloaded
(Opnd
)
8259 if Etype
(Opnd
) = Universal_Integer
8260 or else Etype
(Opnd
) = Universal_Real
8262 return Etype
(Opnd
);
8268 Get_First_Interp
(Opnd
, Index
, It
);
8269 while Present
(It
.Typ
) loop
8270 if It
.Typ
= Universal_Integer
8271 or else It
.Typ
= Universal_Real
8276 Get_Next_Interp
(Index
, It
);
8281 end Universal_Interpretation
;
8287 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
8289 -- Recurse to handle unlikely case of multiple levels of qualification
8291 if Nkind
(Expr
) = N_Qualified_Expression
then
8292 return Unqualify
(Expression
(Expr
));
8294 -- Normal case, not a qualified expression
8301 ----------------------
8302 -- Within_Init_Proc --
8303 ----------------------
8305 function Within_Init_Proc
return Boolean is
8310 while not Is_Overloadable
(S
) loop
8311 if S
= Standard_Standard
then
8318 return Is_Init_Proc
(S
);
8319 end Within_Init_Proc
;
8325 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
8326 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
8327 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
8329 function Has_One_Matching_Field
return Boolean;
8330 -- Determines if Expec_Type is a record type with a single component or
8331 -- discriminant whose type matches the found type or is one dimensional
8332 -- array whose component type matches the found type.
8334 ----------------------------
8335 -- Has_One_Matching_Field --
8336 ----------------------------
8338 function Has_One_Matching_Field
return Boolean is
8342 if Is_Array_Type
(Expec_Type
)
8343 and then Number_Dimensions
(Expec_Type
) = 1
8345 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
8349 elsif not Is_Record_Type
(Expec_Type
) then
8353 E
:= First_Entity
(Expec_Type
);
8358 elsif (Ekind
(E
) /= E_Discriminant
8359 and then Ekind
(E
) /= E_Component
)
8360 or else (Chars
(E
) = Name_uTag
8361 or else Chars
(E
) = Name_uParent
)
8370 if not Covers
(Etype
(E
), Found_Type
) then
8373 elsif Present
(Next_Entity
(E
)) then
8380 end Has_One_Matching_Field
;
8382 -- Start of processing for Wrong_Type
8385 -- Don't output message if either type is Any_Type, or if a message
8386 -- has already been posted for this node. We need to do the latter
8387 -- check explicitly (it is ordinarily done in Errout), because we
8388 -- are using ! to force the output of the error messages.
8390 if Expec_Type
= Any_Type
8391 or else Found_Type
= Any_Type
8392 or else Error_Posted
(Expr
)
8396 -- In an instance, there is an ongoing problem with completion of
8397 -- type derived from private types. Their structure is what Gigi
8398 -- expects, but the Etype is the parent type rather than the
8399 -- derived private type itself. Do not flag error in this case. The
8400 -- private completion is an entity without a parent, like an Itype.
8401 -- Similarly, full and partial views may be incorrect in the instance.
8402 -- There is no simple way to insure that it is consistent ???
8404 elsif In_Instance
then
8406 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
8408 (Has_Private_Declaration
(Expected_Type
)
8409 or else Has_Private_Declaration
(Etype
(Expr
)))
8410 and then No
(Parent
(Expected_Type
))
8416 -- An interesting special check. If the expression is parenthesized
8417 -- and its type corresponds to the type of the sole component of the
8418 -- expected record type, or to the component type of the expected one
8419 -- dimensional array type, then assume we have a bad aggregate attempt.
8421 if Nkind
(Expr
) in N_Subexpr
8422 and then Paren_Count
(Expr
) /= 0
8423 and then Has_One_Matching_Field
8425 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
8427 -- Another special check, if we are looking for a pool-specific access
8428 -- type and we found an E_Access_Attribute_Type, then we have the case
8429 -- of an Access attribute being used in a context which needs a pool-
8430 -- specific type, which is never allowed. The one extra check we make
8431 -- is that the expected designated type covers the Found_Type.
8433 elsif Is_Access_Type
(Expec_Type
)
8434 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
8435 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
8436 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
8438 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
8440 Error_Msg_N
("result must be general access type!", Expr
);
8441 Error_Msg_NE
("add ALL to }!", Expr
, Expec_Type
);
8443 -- If the expected type is an anonymous access type, as for access
8444 -- parameters and discriminants, the error is on the designated types.
8446 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
8447 if Comes_From_Source
(Expec_Type
) then
8448 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
8451 ("expected an access type with designated}",
8452 Expr
, Designated_Type
(Expec_Type
));
8455 if Is_Access_Type
(Found_Type
)
8456 and then not Comes_From_Source
(Found_Type
)
8459 ("\\found an access type with designated}!",
8460 Expr
, Designated_Type
(Found_Type
));
8462 if From_With_Type
(Found_Type
) then
8463 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
8465 ("\possibly missing with_clause on&", Expr
,
8466 Scope
(Found_Type
));
8468 Error_Msg_NE
("found}!", Expr
, Found_Type
);
8472 -- Normal case of one type found, some other type expected
8475 -- If the names of the two types are the same, see if some number
8476 -- of levels of qualification will help. Don't try more than three
8477 -- levels, and if we get to standard, it's no use (and probably
8478 -- represents an error in the compiler) Also do not bother with
8479 -- internal scope names.
8482 Expec_Scope
: Entity_Id
;
8483 Found_Scope
: Entity_Id
;
8486 Expec_Scope
:= Expec_Type
;
8487 Found_Scope
:= Found_Type
;
8489 for Levels
in Int
range 0 .. 3 loop
8490 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
8491 Error_Msg_Qual_Level
:= Levels
;
8495 Expec_Scope
:= Scope
(Expec_Scope
);
8496 Found_Scope
:= Scope
(Found_Scope
);
8498 exit when Expec_Scope
= Standard_Standard
8499 or else Found_Scope
= Standard_Standard
8500 or else not Comes_From_Source
(Expec_Scope
)
8501 or else not Comes_From_Source
(Found_Scope
);
8505 if Is_Record_Type
(Expec_Type
)
8506 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
8508 Error_Msg_NE
("expected}!", Expr
,
8509 Corresponding_Remote_Type
(Expec_Type
));
8511 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
8514 if Is_Entity_Name
(Expr
)
8515 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
8517 Error_Msg_N
("\\found package name!", Expr
);
8519 elsif Is_Entity_Name
(Expr
)
8521 (Ekind
(Entity
(Expr
)) = E_Procedure
8523 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
8525 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
8527 ("found procedure name, possibly missing Access attribute!",
8531 ("\\found procedure name instead of function!", Expr
);
8534 elsif Nkind
(Expr
) = N_Function_Call
8535 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
8536 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
8537 and then No
(Parameter_Associations
(Expr
))
8540 ("found function name, possibly missing Access attribute!",
8543 -- Catch common error: a prefix or infix operator which is not
8544 -- directly visible because the type isn't.
8546 elsif Nkind
(Expr
) in N_Op
8547 and then Is_Overloaded
(Expr
)
8548 and then not Is_Immediately_Visible
(Expec_Type
)
8549 and then not Is_Potentially_Use_Visible
(Expec_Type
)
8550 and then not In_Use
(Expec_Type
)
8551 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
8554 ("operator of the type is not directly visible!", Expr
);
8556 elsif Ekind
(Found_Type
) = E_Void
8557 and then Present
(Parent
(Found_Type
))
8558 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
8560 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
8563 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
8566 Error_Msg_Qual_Level
:= 0;