1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- As a special exception, if other files instantiate generics from this --
22 -- unit, or you link this unit with other files to produce an executable, --
23 -- this unit does not by itself cause the resulting executable to be --
24 -- covered by the GNU General Public License. This exception does not --
25 -- however invalidate any other reasons why the executable file might be --
26 -- covered by the GNU Public License. --
28 -- GNAT was originally developed by the GNAT team at New York University. --
29 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 ------------------------------------------------------------------------------
33 with Atree
; use Atree
;
34 with Einfo
; use Einfo
;
35 with Sinfo
; use Sinfo
;
36 with Snames
; use Snames
;
37 with Stand
; use Stand
;
39 package body Sem_Aux
is
41 ----------------------
42 -- Ancestor_Subtype --
43 ----------------------
45 function Ancestor_Subtype
(Typ
: Entity_Id
) return Entity_Id
is
47 -- If this is first subtype, or is a base type, then there is no
48 -- ancestor subtype, so we return Empty to indicate this fact.
50 if Is_First_Subtype
(Typ
) or else Is_Base_Type
(Typ
) then
55 D
: constant Node_Id
:= Declaration_Node
(Typ
);
58 -- If we have a subtype declaration, get the ancestor subtype
60 if Nkind
(D
) = N_Subtype_Declaration
then
61 if Nkind
(Subtype_Indication
(D
)) = N_Subtype_Indication
then
62 return Entity
(Subtype_Mark
(Subtype_Indication
(D
)));
64 return Entity
(Subtype_Indication
(D
));
67 -- If not, then no subtype indication is available
79 function Available_View
(Ent
: Entity_Id
) return Entity_Id
is
81 -- Obtain the non-limited (non-abstract) view of a state or variable
83 if Ekind
(Ent
) = E_Abstract_State
84 and then Present
(Non_Limited_View
(Ent
))
86 return Non_Limited_View
(Ent
);
88 -- The non-limited view of an incomplete type may itself be incomplete
89 -- in which case obtain its full view.
91 elsif Is_Incomplete_Type
(Ent
)
92 and then Present
(Non_Limited_View
(Ent
))
94 return Get_Full_View
(Non_Limited_View
(Ent
));
96 -- If it is class_wide, check whether the specific type comes from a
99 elsif Is_Class_Wide_Type
(Ent
)
100 and then Is_Incomplete_Type
(Etype
(Ent
))
101 and then From_Limited_With
(Etype
(Ent
))
102 and then Present
(Non_Limited_View
(Etype
(Ent
)))
104 return Class_Wide_Type
(Non_Limited_View
(Etype
(Ent
)));
106 -- In all other cases, return entity unchanged
117 function Constant_Value
(Ent
: Entity_Id
) return Node_Id
is
118 D
: constant Node_Id
:= Declaration_Node
(Ent
);
122 -- If we have no declaration node, then return no constant value. Not
123 -- clear how this can happen, but it does sometimes and this is the
129 -- Normal case where a declaration node is present
131 elsif Nkind
(D
) = N_Object_Renaming_Declaration
then
132 return Renamed_Object
(Ent
);
134 -- If this is a component declaration whose entity is a constant, it is
135 -- a prival within a protected function (and so has no constant value).
137 elsif Nkind
(D
) = N_Component_Declaration
then
140 -- If there is an expression, return it
142 elsif Present
(Expression
(D
)) then
143 return (Expression
(D
));
145 -- For a constant, see if we have a full view
147 elsif Ekind
(Ent
) = E_Constant
148 and then Present
(Full_View
(Ent
))
150 Full_D
:= Parent
(Full_View
(Ent
));
152 -- The full view may have been rewritten as an object renaming
154 if Nkind
(Full_D
) = N_Object_Renaming_Declaration
then
155 return Name
(Full_D
);
157 return Expression
(Full_D
);
160 -- Otherwise we have no expression to return
167 -----------------------------
168 -- Enclosing_Dynamic_Scope --
169 -----------------------------
171 function Enclosing_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
175 -- The following test is an error defense against some syntax errors
176 -- that can leave scopes very messed up.
178 if Ent
= Standard_Standard
then
182 -- Normal case, search enclosing scopes
184 -- Note: the test for Present (S) should not be required, it defends
185 -- against an ill-formed tree.
189 -- If we somehow got an empty value for Scope, the tree must be
190 -- malformed. Rather than blow up we return Standard in this case.
193 return Standard_Standard
;
195 -- Quit if we get to standard or a dynamic scope. We must also
196 -- handle enclosing scopes that have a full view; required to
197 -- locate enclosing scopes that are synchronized private types
198 -- whose full view is a task type.
200 elsif S
= Standard_Standard
201 or else Is_Dynamic_Scope
(S
)
202 or else (Is_Private_Type
(S
)
203 and then Present
(Full_View
(S
))
204 and then Is_Dynamic_Scope
(Full_View
(S
)))
208 -- Otherwise keep climbing
214 end Enclosing_Dynamic_Scope
;
216 ------------------------
217 -- First_Discriminant --
218 ------------------------
220 function First_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
225 (Has_Discriminants
(Typ
) or else Has_Unknown_Discriminants
(Typ
));
227 Ent
:= First_Entity
(Typ
);
229 -- The discriminants are not necessarily contiguous, because access
230 -- discriminants will generate itypes. They are not the first entities
231 -- either because the tag must be ahead of them.
233 if Chars
(Ent
) = Name_uTag
then
234 Ent
:= Next_Entity
(Ent
);
237 -- Skip all hidden stored discriminants if any
239 while Present
(Ent
) loop
240 exit when Ekind
(Ent
) = E_Discriminant
241 and then not Is_Completely_Hidden
(Ent
);
243 Ent
:= Next_Entity
(Ent
);
246 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
249 end First_Discriminant
;
251 -------------------------------
252 -- First_Stored_Discriminant --
253 -------------------------------
255 function First_Stored_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
258 function Has_Completely_Hidden_Discriminant
259 (Typ
: Entity_Id
) return Boolean;
260 -- Scans the Discriminants to see whether any are Completely_Hidden
261 -- (the mechanism for describing non-specified stored discriminants)
263 ----------------------------------------
264 -- Has_Completely_Hidden_Discriminant --
265 ----------------------------------------
267 function Has_Completely_Hidden_Discriminant
268 (Typ
: Entity_Id
) return Boolean
273 pragma Assert
(Ekind
(Typ
) = E_Discriminant
);
276 while Present
(Ent
) and then Ekind
(Ent
) = E_Discriminant
loop
277 if Is_Completely_Hidden
(Ent
) then
281 Ent
:= Next_Entity
(Ent
);
285 end Has_Completely_Hidden_Discriminant
;
287 -- Start of processing for First_Stored_Discriminant
291 (Has_Discriminants
(Typ
)
292 or else Has_Unknown_Discriminants
(Typ
));
294 Ent
:= First_Entity
(Typ
);
296 if Chars
(Ent
) = Name_uTag
then
297 Ent
:= Next_Entity
(Ent
);
300 if Has_Completely_Hidden_Discriminant
(Ent
) then
301 while Present
(Ent
) loop
302 exit when Is_Completely_Hidden
(Ent
);
303 Ent
:= Next_Entity
(Ent
);
307 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
310 end First_Stored_Discriminant
;
316 function First_Subtype
(Typ
: Entity_Id
) return Entity_Id
is
317 B
: constant Entity_Id
:= Base_Type
(Typ
);
318 F
: constant Node_Id
:= Freeze_Node
(B
);
322 -- If the base type has no freeze node, it is a type in Standard, and
323 -- always acts as its own first subtype, except where it is one of the
324 -- predefined integer types. If the type is formal, it is also a first
325 -- subtype, and its base type has no freeze node. On the other hand, a
326 -- subtype of a generic formal is not its own first subtype. Its base
327 -- type, if anonymous, is attached to the formal type decl. from which
328 -- the first subtype is obtained.
331 if B
= Base_Type
(Standard_Integer
) then
332 return Standard_Integer
;
334 elsif B
= Base_Type
(Standard_Long_Integer
) then
335 return Standard_Long_Integer
;
337 elsif B
= Base_Type
(Standard_Short_Short_Integer
) then
338 return Standard_Short_Short_Integer
;
340 elsif B
= Base_Type
(Standard_Short_Integer
) then
341 return Standard_Short_Integer
;
343 elsif B
= Base_Type
(Standard_Long_Long_Integer
) then
344 return Standard_Long_Long_Integer
;
346 elsif Is_Generic_Type
(Typ
) then
347 if Present
(Parent
(B
)) then
348 return Defining_Identifier
(Parent
(B
));
350 return Defining_Identifier
(Associated_Node_For_Itype
(B
));
357 -- Otherwise we check the freeze node, if it has a First_Subtype_Link
358 -- then we use that link, otherwise (happens with some Itypes), we use
359 -- the base type itself.
362 Ent
:= First_Subtype_Link
(F
);
364 if Present
(Ent
) then
372 -------------------------
373 -- First_Tag_Component --
374 -------------------------
376 function First_Tag_Component
(Typ
: Entity_Id
) return Entity_Id
is
382 pragma Assert
(Is_Tagged_Type
(Ctyp
));
384 if Is_Class_Wide_Type
(Ctyp
) then
385 Ctyp
:= Root_Type
(Ctyp
);
388 if Is_Private_Type
(Ctyp
) then
389 Ctyp
:= Underlying_Type
(Ctyp
);
391 -- If the underlying type is missing then the source program has
392 -- errors and there is nothing else to do (the full-type declaration
393 -- associated with the private type declaration is missing).
400 Comp
:= First_Entity
(Ctyp
);
401 while Present
(Comp
) loop
402 if Is_Tag
(Comp
) then
406 Comp
:= Next_Entity
(Comp
);
409 -- No tag component found
412 end First_Tag_Component
;
418 function Get_Rep_Item
421 Check_Parents
: Boolean := True) return Node_Id
426 N
:= First_Rep_Item
(E
);
427 while Present
(N
) loop
429 -- Only one of Priority / Interrupt_Priority can be specified, so
430 -- return whichever one is present to catch illegal duplication.
432 if Nkind
(N
) = N_Pragma
434 (Pragma_Name
(N
) = Nam
435 or else (Nam
= Name_Priority
436 and then Pragma_Name
(N
) = Name_Interrupt_Priority
)
437 or else (Nam
= Name_Interrupt_Priority
438 and then Pragma_Name
(N
) = Name_Priority
))
440 if Check_Parents
then
443 -- If Check_Parents is False, return N if the pragma doesn't
444 -- appear in the Rep_Item chain of the parent.
448 Par
: constant Entity_Id
:= Nearest_Ancestor
(E
);
449 -- This node represents the parent type of type E (if any)
455 elsif not Present_In_Rep_Item
(Par
, N
) then
461 elsif Nkind
(N
) = N_Attribute_Definition_Clause
464 or else (Nam
= Name_Priority
465 and then Chars
(N
) = Name_Interrupt_Priority
))
467 if Check_Parents
or else Entity
(N
) = E
then
471 elsif Nkind
(N
) = N_Aspect_Specification
473 (Chars
(Identifier
(N
)) = Nam
476 and then Chars
(Identifier
(N
)) = Name_Interrupt_Priority
))
478 if Check_Parents
then
481 elsif Entity
(N
) = E
then
492 function Get_Rep_Item
496 Check_Parents
: Boolean := True) return Node_Id
498 Nam1_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam1
, Check_Parents
);
499 Nam2_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam2
, Check_Parents
);
504 -- Check both Nam1_Item and Nam2_Item are present
506 if No
(Nam1_Item
) then
508 elsif No
(Nam2_Item
) then
512 -- Return the first node encountered in the list
514 N
:= First_Rep_Item
(E
);
515 while Present
(N
) loop
516 if N
= Nam1_Item
or else N
= Nam2_Item
then
530 function Get_Rep_Pragma
533 Check_Parents
: Boolean := True) return Node_Id
538 N
:= Get_Rep_Item
(E
, Nam
, Check_Parents
);
540 if Present
(N
) and then Nkind
(N
) = N_Pragma
then
547 function Get_Rep_Pragma
551 Check_Parents
: Boolean := True) return Node_Id
553 Nam1_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam1
, Check_Parents
);
554 Nam2_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam2
, Check_Parents
);
559 -- Check both Nam1_Item and Nam2_Item are present
561 if No
(Nam1_Item
) then
563 elsif No
(Nam2_Item
) then
567 -- Return the first node encountered in the list
569 N
:= First_Rep_Item
(E
);
570 while Present
(N
) loop
571 if N
= Nam1_Item
or else N
= Nam2_Item
then
585 function Has_Rep_Item
588 Check_Parents
: Boolean := True) return Boolean
591 return Present
(Get_Rep_Item
(E
, Nam
, Check_Parents
));
594 function Has_Rep_Item
598 Check_Parents
: Boolean := True) return Boolean
601 return Present
(Get_Rep_Item
(E
, Nam1
, Nam2
, Check_Parents
));
608 function Has_Rep_Pragma
611 Check_Parents
: Boolean := True) return Boolean
614 return Present
(Get_Rep_Pragma
(E
, Nam
, Check_Parents
));
617 function Has_Rep_Pragma
621 Check_Parents
: Boolean := True) return Boolean
624 return Present
(Get_Rep_Pragma
(E
, Nam1
, Nam2
, Check_Parents
));
627 --------------------------------
628 -- Has_Unconstrained_Elements --
629 --------------------------------
631 function Has_Unconstrained_Elements
(T
: Entity_Id
) return Boolean is
632 U_T
: constant Entity_Id
:= Underlying_Type
(T
);
636 elsif Is_Record_Type
(U_T
) then
637 return Has_Discriminants
(U_T
) and then not Is_Constrained
(U_T
);
638 elsif Is_Array_Type
(U_T
) then
639 return Has_Unconstrained_Elements
(Component_Type
(U_T
));
643 end Has_Unconstrained_Elements
;
645 ---------------------
646 -- In_Generic_Body --
647 ---------------------
649 function In_Generic_Body
(Id
: Entity_Id
) return Boolean is
653 -- Climb scopes looking for generic body
656 while Present
(S
) and then S
/= Standard_Standard
loop
658 -- Generic package body
660 if Ekind
(S
) = E_Generic_Package
661 and then In_Package_Body
(S
)
665 -- Generic subprogram body
667 elsif Is_Subprogram
(S
)
668 and then Nkind
(Unit_Declaration_Node
(S
))
669 = N_Generic_Subprogram_Declaration
677 -- False if top of scope stack without finding a generic body
682 -------------------------------
683 -- Initialization_Suppressed --
684 -------------------------------
686 function Initialization_Suppressed
(Typ
: Entity_Id
) return Boolean is
688 return Suppress_Initialization
(Typ
)
689 or else Suppress_Initialization
(Base_Type
(Typ
));
690 end Initialization_Suppressed
;
696 procedure Initialize
is
698 Obsolescent_Warnings
.Init
;
705 function Is_Body
(N
: Node_Id
) return Boolean is
708 Nkind
(N
) in N_Body_Stub
709 or else Nkind_In
(N
, N_Entry_Body
,
716 ---------------------
717 -- Is_By_Copy_Type --
718 ---------------------
720 function Is_By_Copy_Type
(Ent
: Entity_Id
) return Boolean is
722 -- If Id is a private type whose full declaration has not been seen,
723 -- we assume for now that it is not a By_Copy type. Clearly this
724 -- attribute should not be used before the type is frozen, but it is
725 -- needed to build the associated record of a protected type. Another
726 -- place where some lookahead for a full view is needed ???
729 Is_Elementary_Type
(Ent
)
730 or else (Is_Private_Type
(Ent
)
731 and then Present
(Underlying_Type
(Ent
))
732 and then Is_Elementary_Type
(Underlying_Type
(Ent
)));
735 --------------------------
736 -- Is_By_Reference_Type --
737 --------------------------
739 function Is_By_Reference_Type
(Ent
: Entity_Id
) return Boolean is
740 Btype
: constant Entity_Id
:= Base_Type
(Ent
);
743 if Error_Posted
(Ent
) or else Error_Posted
(Btype
) then
746 elsif Is_Private_Type
(Btype
) then
748 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
753 return Is_By_Reference_Type
(Utyp
);
757 elsif Is_Incomplete_Type
(Btype
) then
759 Ftyp
: constant Entity_Id
:= Full_View
(Btype
);
764 return Is_By_Reference_Type
(Ftyp
);
768 elsif Is_Concurrent_Type
(Btype
) then
771 elsif Is_Record_Type
(Btype
) then
772 if Is_Limited_Record
(Btype
)
773 or else Is_Tagged_Type
(Btype
)
774 or else Is_Volatile
(Btype
)
783 C
:= First_Component
(Btype
);
784 while Present
(C
) loop
785 if Is_By_Reference_Type
(Etype
(C
))
786 or else Is_Volatile
(Etype
(C
))
791 C
:= Next_Component
(C
);
798 elsif Is_Array_Type
(Btype
) then
801 or else Is_By_Reference_Type
(Component_Type
(Btype
))
802 or else Is_Volatile
(Component_Type
(Btype
))
803 or else Has_Volatile_Components
(Btype
);
808 end Is_By_Reference_Type
;
810 ---------------------
811 -- Is_Derived_Type --
812 ---------------------
814 function Is_Derived_Type
(Ent
: E
) return B
is
819 and then Base_Type
(Ent
) /= Root_Type
(Ent
)
820 and then not Is_Class_Wide_Type
(Ent
)
822 if not Is_Numeric_Type
(Root_Type
(Ent
)) then
826 Par
:= Parent
(First_Subtype
(Ent
));
829 and then Nkind
(Par
) = N_Full_Type_Declaration
830 and then Nkind
(Type_Definition
(Par
)) =
831 N_Derived_Type_Definition
;
839 -----------------------
840 -- Is_Generic_Formal --
841 -----------------------
843 function Is_Generic_Formal
(E
: Entity_Id
) return Boolean is
849 Kind
:= Nkind
(Parent
(E
));
851 Nkind_In
(Kind
, N_Formal_Object_Declaration
,
852 N_Formal_Package_Declaration
,
853 N_Formal_Type_Declaration
)
854 or else Is_Formal_Subprogram
(E
);
856 end Is_Generic_Formal
;
858 -------------------------------
859 -- Is_Immutably_Limited_Type --
860 -------------------------------
862 function Is_Immutably_Limited_Type
(Ent
: Entity_Id
) return Boolean is
863 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
866 if Is_Limited_Record
(Btype
) then
869 elsif Ekind
(Btype
) = E_Limited_Private_Type
870 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
872 return not In_Package_Body
(Scope
((Btype
)));
874 elsif Is_Private_Type
(Btype
) then
876 -- AI05-0063: A type derived from a limited private formal type is
877 -- not immutably limited in a generic body.
879 if Is_Derived_Type
(Btype
)
880 and then Is_Generic_Type
(Etype
(Btype
))
882 if not Is_Limited_Type
(Etype
(Btype
)) then
885 -- A descendant of a limited formal type is not immutably limited
886 -- in the generic body, or in the body of a generic child.
888 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
889 return not In_Package_Body
(Scope
(Btype
));
897 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
902 return Is_Immutably_Limited_Type
(Utyp
);
907 elsif Is_Concurrent_Type
(Btype
) then
913 end Is_Immutably_Limited_Type
;
915 ---------------------------
916 -- Is_Indefinite_Subtype --
917 ---------------------------
919 function Is_Indefinite_Subtype
(Ent
: Entity_Id
) return Boolean is
920 K
: constant Entity_Kind
:= Ekind
(Ent
);
923 if Is_Constrained
(Ent
) then
926 elsif K
in Array_Kind
927 or else K
in Class_Wide_Kind
928 or else Has_Unknown_Discriminants
(Ent
)
932 -- Known discriminants: indefinite if there are no default values
934 elsif K
in Record_Kind
935 or else Is_Incomplete_Or_Private_Type
(Ent
)
936 or else Is_Concurrent_Type
(Ent
)
938 return (Has_Discriminants
(Ent
)
940 No
(Discriminant_Default_Value
(First_Discriminant
(Ent
))));
945 end Is_Indefinite_Subtype
;
947 ---------------------
948 -- Is_Limited_Type --
949 ---------------------
951 function Is_Limited_Type
(Ent
: Entity_Id
) return Boolean is
952 Btype
: constant E
:= Base_Type
(Ent
);
953 Rtype
: constant E
:= Root_Type
(Btype
);
956 if not Is_Type
(Ent
) then
959 elsif Ekind
(Btype
) = E_Limited_Private_Type
960 or else Is_Limited_Composite
(Btype
)
964 elsif Is_Concurrent_Type
(Btype
) then
967 -- The Is_Limited_Record flag normally indicates that the type is
968 -- limited. The exception is that a type does not inherit limitedness
969 -- from its interface ancestor. So the type may be derived from a
970 -- limited interface, but is not limited.
972 elsif Is_Limited_Record
(Ent
)
973 and then not Is_Interface
(Ent
)
977 -- Otherwise we will look around to see if there is some other reason
978 -- for it to be limited, except that if an error was posted on the
979 -- entity, then just assume it is non-limited, because it can cause
980 -- trouble to recurse into a murky erroneous entity.
982 elsif Error_Posted
(Ent
) then
985 elsif Is_Record_Type
(Btype
) then
987 if Is_Limited_Interface
(Ent
) then
990 -- AI-419: limitedness is not inherited from a limited interface
992 elsif Is_Limited_Record
(Rtype
) then
993 return not Is_Interface
(Rtype
)
994 or else Is_Protected_Interface
(Rtype
)
995 or else Is_Synchronized_Interface
(Rtype
)
996 or else Is_Task_Interface
(Rtype
);
998 elsif Is_Class_Wide_Type
(Btype
) then
999 return Is_Limited_Type
(Rtype
);
1006 C
:= First_Component
(Btype
);
1007 while Present
(C
) loop
1008 if Is_Limited_Type
(Etype
(C
)) then
1012 C
:= Next_Component
(C
);
1019 elsif Is_Array_Type
(Btype
) then
1020 return Is_Limited_Type
(Component_Type
(Btype
));
1025 end Is_Limited_Type
;
1027 ---------------------
1028 -- Is_Limited_View --
1029 ---------------------
1031 function Is_Limited_View
(Ent
: Entity_Id
) return Boolean is
1032 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
1035 if Is_Limited_Record
(Btype
) then
1038 elsif Ekind
(Btype
) = E_Limited_Private_Type
1039 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
1041 return not In_Package_Body
(Scope
((Btype
)));
1043 elsif Is_Private_Type
(Btype
) then
1045 -- AI05-0063: A type derived from a limited private formal type is
1046 -- not immutably limited in a generic body.
1048 if Is_Derived_Type
(Btype
)
1049 and then Is_Generic_Type
(Etype
(Btype
))
1051 if not Is_Limited_Type
(Etype
(Btype
)) then
1054 -- A descendant of a limited formal type is not immutably limited
1055 -- in the generic body, or in the body of a generic child.
1057 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
1058 return not In_Package_Body
(Scope
(Btype
));
1066 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
1071 return Is_Limited_View
(Utyp
);
1076 elsif Is_Concurrent_Type
(Btype
) then
1079 elsif Is_Record_Type
(Btype
) then
1081 -- Note that we return True for all limited interfaces, even though
1082 -- (unsynchronized) limited interfaces can have descendants that are
1083 -- nonlimited, because this is a predicate on the type itself, and
1084 -- things like functions with limited interface results need to be
1085 -- handled as build in place even though they might return objects
1086 -- of a type that is not inherently limited.
1088 if Is_Class_Wide_Type
(Btype
) then
1089 return Is_Limited_View
(Root_Type
(Btype
));
1096 C
:= First_Component
(Btype
);
1097 while Present
(C
) loop
1099 -- Don't consider components with interface types (which can
1100 -- only occur in the case of a _parent component anyway).
1101 -- They don't have any components, plus it would cause this
1102 -- function to return true for nonlimited types derived from
1103 -- limited interfaces.
1105 if not Is_Interface
(Etype
(C
))
1106 and then Is_Limited_View
(Etype
(C
))
1111 C
:= Next_Component
(C
);
1118 elsif Is_Array_Type
(Btype
) then
1119 return Is_Limited_View
(Component_Type
(Btype
));
1124 end Is_Limited_View
;
1126 ----------------------
1127 -- Nearest_Ancestor --
1128 ----------------------
1130 function Nearest_Ancestor
(Typ
: Entity_Id
) return Entity_Id
is
1131 D
: constant Node_Id
:= Declaration_Node
(Typ
);
1134 -- If we have a subtype declaration, get the ancestor subtype
1136 if Nkind
(D
) = N_Subtype_Declaration
then
1137 if Nkind
(Subtype_Indication
(D
)) = N_Subtype_Indication
then
1138 return Entity
(Subtype_Mark
(Subtype_Indication
(D
)));
1140 return Entity
(Subtype_Indication
(D
));
1143 -- If derived type declaration, find who we are derived from
1145 elsif Nkind
(D
) = N_Full_Type_Declaration
1146 and then Nkind
(Type_Definition
(D
)) = N_Derived_Type_Definition
1149 DTD
: constant Entity_Id
:= Type_Definition
(D
);
1150 SI
: constant Entity_Id
:= Subtype_Indication
(DTD
);
1152 if Is_Entity_Name
(SI
) then
1155 return Entity
(Subtype_Mark
(SI
));
1159 -- If derived type and private type, get the full view to find who we
1160 -- are derived from.
1162 elsif Is_Derived_Type
(Typ
)
1163 and then Is_Private_Type
(Typ
)
1164 and then Present
(Full_View
(Typ
))
1166 return Nearest_Ancestor
(Full_View
(Typ
));
1168 -- Otherwise, nothing useful to return, return Empty
1173 end Nearest_Ancestor
;
1175 ---------------------------
1176 -- Nearest_Dynamic_Scope --
1177 ---------------------------
1179 function Nearest_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
1181 if Is_Dynamic_Scope
(Ent
) then
1184 return Enclosing_Dynamic_Scope
(Ent
);
1186 end Nearest_Dynamic_Scope
;
1188 ------------------------
1189 -- Next_Tag_Component --
1190 ------------------------
1192 function Next_Tag_Component
(Tag
: Entity_Id
) return Entity_Id
is
1196 pragma Assert
(Is_Tag
(Tag
));
1198 -- Loop to look for next tag component
1200 Comp
:= Next_Entity
(Tag
);
1201 while Present
(Comp
) loop
1202 if Is_Tag
(Comp
) then
1203 pragma Assert
(Chars
(Comp
) /= Name_uTag
);
1207 Comp
:= Next_Entity
(Comp
);
1210 -- No tag component found
1213 end Next_Tag_Component
;
1215 --------------------------
1216 -- Number_Discriminants --
1217 --------------------------
1219 function Number_Discriminants
(Typ
: Entity_Id
) return Pos
is
1225 Discr
:= First_Discriminant
(Typ
);
1226 while Present
(Discr
) loop
1228 Discr
:= Next_Discriminant
(Discr
);
1232 end Number_Discriminants
;
1234 ----------------------------------------------
1235 -- Object_Type_Has_Constrained_Partial_View --
1236 ----------------------------------------------
1238 function Object_Type_Has_Constrained_Partial_View
1240 Scop
: Entity_Id
) return Boolean
1243 return Has_Constrained_Partial_View
(Typ
)
1244 or else (In_Generic_Body
(Scop
)
1245 and then Is_Generic_Type
(Base_Type
(Typ
))
1246 and then Is_Private_Type
(Base_Type
(Typ
))
1247 and then not Is_Tagged_Type
(Typ
)
1248 and then not (Is_Array_Type
(Typ
)
1249 and then not Is_Constrained
(Typ
))
1250 and then Has_Discriminants
(Typ
));
1251 end Object_Type_Has_Constrained_Partial_View
;
1253 ---------------------------
1254 -- Package_Specification --
1255 ---------------------------
1257 function Package_Specification
(Pack_Id
: Entity_Id
) return Node_Id
is
1261 N
:= Parent
(Pack_Id
);
1262 while Nkind
(N
) /= N_Package_Specification
loop
1266 raise Program_Error
;
1271 end Package_Specification
;
1277 procedure Tree_Read
is
1279 Obsolescent_Warnings
.Tree_Read
;
1286 procedure Tree_Write
is
1288 Obsolescent_Warnings
.Tree_Write
;
1291 --------------------
1292 -- Ultimate_Alias --
1293 --------------------
1295 function Ultimate_Alias
(Prim
: Entity_Id
) return Entity_Id
is
1296 E
: Entity_Id
:= Prim
;
1299 while Present
(Alias
(E
)) loop
1300 pragma Assert
(Alias
(E
) /= E
);
1307 --------------------------
1308 -- Unit_Declaration_Node --
1309 --------------------------
1311 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
1312 N
: Node_Id
:= Parent
(Unit_Id
);
1315 -- Predefined operators do not have a full function declaration
1317 if Ekind
(Unit_Id
) = E_Operator
then
1321 -- Isn't there some better way to express the following ???
1323 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
1324 and then Nkind
(N
) /= N_Formal_Package_Declaration
1325 and then Nkind
(N
) /= N_Function_Instantiation
1326 and then Nkind
(N
) /= N_Generic_Package_Declaration
1327 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
1328 and then Nkind
(N
) /= N_Package_Declaration
1329 and then Nkind
(N
) /= N_Package_Body
1330 and then Nkind
(N
) /= N_Package_Instantiation
1331 and then Nkind
(N
) /= N_Package_Renaming_Declaration
1332 and then Nkind
(N
) /= N_Procedure_Instantiation
1333 and then Nkind
(N
) /= N_Protected_Body
1334 and then Nkind
(N
) /= N_Subprogram_Declaration
1335 and then Nkind
(N
) /= N_Subprogram_Body
1336 and then Nkind
(N
) /= N_Subprogram_Body_Stub
1337 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
1338 and then Nkind
(N
) /= N_Task_Body
1339 and then Nkind
(N
) /= N_Task_Type_Declaration
1340 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
1341 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
1345 -- We don't use Assert here, because that causes an infinite loop
1346 -- when assertions are turned off. Better to crash.
1349 raise Program_Error
;
1354 end Unit_Declaration_Node
;