1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 Snames
; use Snames
;
36 with Stand
; use Stand
;
37 with Uintp
; use Uintp
;
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 -- Corresponding_Unsigned_Type --
169 ---------------------------------
171 function Corresponding_Unsigned_Type
(Typ
: Entity_Id
) return Entity_Id
is
172 pragma Assert
(Is_Signed_Integer_Type
(Typ
));
173 Siz
: constant Uint
:= Esize
(Base_Type
(Typ
));
175 if Siz
= Esize
(Standard_Short_Short_Integer
) then
176 return Standard_Short_Short_Unsigned
;
177 elsif Siz
= Esize
(Standard_Short_Integer
) then
178 return Standard_Short_Unsigned
;
179 elsif Siz
= Esize
(Standard_Unsigned
) then
180 return Standard_Unsigned
;
181 elsif Siz
= Esize
(Standard_Long_Integer
) then
182 return Standard_Long_Unsigned
;
183 elsif Siz
= Esize
(Standard_Long_Long_Integer
) then
184 return Standard_Long_Long_Unsigned
;
188 end Corresponding_Unsigned_Type
;
190 -----------------------------
191 -- Enclosing_Dynamic_Scope --
192 -----------------------------
194 function Enclosing_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
198 -- The following test is an error defense against some syntax errors
199 -- that can leave scopes very messed up.
201 if Ent
= Standard_Standard
then
205 -- Normal case, search enclosing scopes
207 -- Note: the test for Present (S) should not be required, it defends
208 -- against an ill-formed tree.
212 -- If we somehow got an empty value for Scope, the tree must be
213 -- malformed. Rather than blow up we return Standard in this case.
216 return Standard_Standard
;
218 -- Quit if we get to standard or a dynamic scope. We must also
219 -- handle enclosing scopes that have a full view; required to
220 -- locate enclosing scopes that are synchronized private types
221 -- whose full view is a task type.
223 elsif S
= Standard_Standard
224 or else Is_Dynamic_Scope
(S
)
225 or else (Is_Private_Type
(S
)
226 and then Present
(Full_View
(S
))
227 and then Is_Dynamic_Scope
(Full_View
(S
)))
231 -- Otherwise keep climbing
237 end Enclosing_Dynamic_Scope
;
239 ------------------------
240 -- First_Discriminant --
241 ------------------------
243 function First_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
248 (Has_Discriminants
(Typ
) or else Has_Unknown_Discriminants
(Typ
));
250 Ent
:= First_Entity
(Typ
);
252 -- The discriminants are not necessarily contiguous, because access
253 -- discriminants will generate itypes. They are not the first entities
254 -- either because the tag must be ahead of them.
256 if Chars
(Ent
) = Name_uTag
then
257 Ent
:= Next_Entity
(Ent
);
260 -- Skip all hidden stored discriminants if any
262 while Present
(Ent
) loop
263 exit when Ekind
(Ent
) = E_Discriminant
264 and then not Is_Completely_Hidden
(Ent
);
266 Ent
:= Next_Entity
(Ent
);
269 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
272 end First_Discriminant
;
274 -------------------------------
275 -- First_Stored_Discriminant --
276 -------------------------------
278 function First_Stored_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
281 function Has_Completely_Hidden_Discriminant
282 (Typ
: Entity_Id
) return Boolean;
283 -- Scans the Discriminants to see whether any are Completely_Hidden
284 -- (the mechanism for describing non-specified stored discriminants)
285 -- Note that the entity list for the type may contain anonymous access
286 -- types created by expressions that constrain access discriminants.
288 ----------------------------------------
289 -- Has_Completely_Hidden_Discriminant --
290 ----------------------------------------
292 function Has_Completely_Hidden_Discriminant
293 (Typ
: Entity_Id
) return Boolean
298 pragma Assert
(Ekind
(Typ
) = E_Discriminant
);
301 while Present
(Ent
) loop
303 -- Skip anonymous types that may be created by expressions
304 -- used as discriminant constraints on inherited discriminants.
306 if Is_Itype
(Ent
) then
309 elsif Ekind
(Ent
) = E_Discriminant
310 and then Is_Completely_Hidden
(Ent
)
315 Ent
:= Next_Entity
(Ent
);
319 end Has_Completely_Hidden_Discriminant
;
321 -- Start of processing for First_Stored_Discriminant
325 (Has_Discriminants
(Typ
)
326 or else Has_Unknown_Discriminants
(Typ
));
328 Ent
:= First_Entity
(Typ
);
330 if Chars
(Ent
) = Name_uTag
then
331 Ent
:= Next_Entity
(Ent
);
334 if Has_Completely_Hidden_Discriminant
(Ent
) then
335 while Present
(Ent
) loop
336 exit when Ekind
(Ent
) = E_Discriminant
337 and then Is_Completely_Hidden
(Ent
);
338 Ent
:= Next_Entity
(Ent
);
342 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
345 end First_Stored_Discriminant
;
351 function First_Subtype
(Typ
: Entity_Id
) return Entity_Id
is
352 B
: constant Entity_Id
:= Base_Type
(Typ
);
353 F
: constant Node_Id
:= Freeze_Node
(B
);
357 -- If the base type has no freeze node, it is a type in Standard, and
358 -- always acts as its own first subtype, except where it is one of the
359 -- predefined integer types. If the type is formal, it is also a first
360 -- subtype, and its base type has no freeze node. On the other hand, a
361 -- subtype of a generic formal is not its own first subtype. Its base
362 -- type, if anonymous, is attached to the formal type decl. from which
363 -- the first subtype is obtained.
366 if B
= Base_Type
(Standard_Integer
) then
367 return Standard_Integer
;
369 elsif B
= Base_Type
(Standard_Long_Integer
) then
370 return Standard_Long_Integer
;
372 elsif B
= Base_Type
(Standard_Short_Short_Integer
) then
373 return Standard_Short_Short_Integer
;
375 elsif B
= Base_Type
(Standard_Short_Integer
) then
376 return Standard_Short_Integer
;
378 elsif B
= Base_Type
(Standard_Long_Long_Integer
) then
379 return Standard_Long_Long_Integer
;
381 elsif Is_Generic_Type
(Typ
) then
382 if Present
(Parent
(B
)) then
383 return Defining_Identifier
(Parent
(B
));
385 return Defining_Identifier
(Associated_Node_For_Itype
(B
));
392 -- Otherwise we check the freeze node, if it has a First_Subtype_Link
393 -- then we use that link, otherwise (happens with some Itypes), we use
394 -- the base type itself.
397 Ent
:= First_Subtype_Link
(F
);
399 if Present
(Ent
) then
407 -------------------------
408 -- First_Tag_Component --
409 -------------------------
411 function First_Tag_Component
(Typ
: Entity_Id
) return Entity_Id
is
417 pragma Assert
(Is_Tagged_Type
(Ctyp
));
419 if Is_Class_Wide_Type
(Ctyp
) then
420 Ctyp
:= Root_Type
(Ctyp
);
423 if Is_Private_Type
(Ctyp
) then
424 Ctyp
:= Underlying_Type
(Ctyp
);
426 -- If the underlying type is missing then the source program has
427 -- errors and there is nothing else to do (the full-type declaration
428 -- associated with the private type declaration is missing).
435 Comp
:= First_Entity
(Ctyp
);
436 while Present
(Comp
) loop
437 if Is_Tag
(Comp
) then
441 Comp
:= Next_Entity
(Comp
);
444 -- No tag component found
447 end First_Tag_Component
;
449 ---------------------
450 -- Get_Binary_Nkind --
451 ---------------------
453 function Get_Binary_Nkind
(Op
: Entity_Id
) return Node_Kind
is
458 when Name_Op_Concat
=>
460 when Name_Op_Expon
=>
462 when Name_Op_Subtract
=>
463 return N_Op_Subtract
;
466 when Name_Op_Multiply
=>
467 return N_Op_Multiply
;
468 when Name_Op_Divide
=>
493 end Get_Binary_Nkind
;
499 function Get_Rep_Item
502 Check_Parents
: Boolean := True) return Node_Id
507 N
:= First_Rep_Item
(E
);
508 while Present
(N
) loop
510 -- Only one of Priority / Interrupt_Priority can be specified, so
511 -- return whichever one is present to catch illegal duplication.
513 if Nkind
(N
) = N_Pragma
515 (Pragma_Name
(N
) = Nam
516 or else (Nam
= Name_Priority
517 and then Pragma_Name
(N
) = Name_Interrupt_Priority
)
518 or else (Nam
= Name_Interrupt_Priority
519 and then Pragma_Name
(N
) = Name_Priority
))
521 if Check_Parents
then
524 -- If Check_Parents is False, return N if the pragma doesn't
525 -- appear in the Rep_Item chain of the parent.
529 Par
: constant Entity_Id
:= Nearest_Ancestor
(E
);
530 -- This node represents the parent type of type E (if any)
536 elsif not Present_In_Rep_Item
(Par
, N
) then
542 elsif Nkind
(N
) = N_Attribute_Definition_Clause
545 or else (Nam
= Name_Priority
546 and then Chars
(N
) = Name_Interrupt_Priority
))
548 if Check_Parents
or else Entity
(N
) = E
then
552 elsif Nkind
(N
) = N_Aspect_Specification
554 (Chars
(Identifier
(N
)) = Nam
557 and then Chars
(Identifier
(N
)) = Name_Interrupt_Priority
))
559 if Check_Parents
then
562 elsif Entity
(N
) = E
then
573 function Get_Rep_Item
577 Check_Parents
: Boolean := True) return Node_Id
579 Nam1_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam1
, Check_Parents
);
580 Nam2_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam2
, Check_Parents
);
585 -- Check both Nam1_Item and Nam2_Item are present
587 if No
(Nam1_Item
) then
589 elsif No
(Nam2_Item
) then
593 -- Return the first node encountered in the list
595 N
:= First_Rep_Item
(E
);
596 while Present
(N
) loop
597 if N
= Nam1_Item
or else N
= Nam2_Item
then
611 function Get_Rep_Pragma
614 Check_Parents
: Boolean := True) return Node_Id
619 N
:= Get_Rep_Item
(E
, Nam
, Check_Parents
);
621 if Present
(N
) and then Nkind
(N
) = N_Pragma
then
628 function Get_Rep_Pragma
632 Check_Parents
: Boolean := True) return Node_Id
634 Nam1_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam1
, Check_Parents
);
635 Nam2_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam2
, Check_Parents
);
640 -- Check both Nam1_Item and Nam2_Item are present
642 if No
(Nam1_Item
) then
644 elsif No
(Nam2_Item
) then
648 -- Return the first node encountered in the list
650 N
:= First_Rep_Item
(E
);
651 while Present
(N
) loop
652 if N
= Nam1_Item
or else N
= Nam2_Item
then
662 ---------------------
663 -- Get_Unary_Nkind --
664 ---------------------
666 function Get_Unary_Nkind
(Op
: Entity_Id
) return Node_Kind
is
671 when Name_Op_Subtract
=>
682 ---------------------------------
683 -- Has_External_Tag_Rep_Clause --
684 ---------------------------------
686 function Has_External_Tag_Rep_Clause
(T
: Entity_Id
) return Boolean is
688 pragma Assert
(Is_Tagged_Type
(T
));
689 return Has_Rep_Item
(T
, Name_External_Tag
, Check_Parents
=> False);
690 end Has_External_Tag_Rep_Clause
;
696 function Has_Rep_Item
699 Check_Parents
: Boolean := True) return Boolean
702 return Present
(Get_Rep_Item
(E
, Nam
, Check_Parents
));
705 function Has_Rep_Item
709 Check_Parents
: Boolean := True) return Boolean
712 return Present
(Get_Rep_Item
(E
, Nam1
, Nam2
, Check_Parents
));
719 function Has_Rep_Pragma
722 Check_Parents
: Boolean := True) return Boolean
725 return Present
(Get_Rep_Pragma
(E
, Nam
, Check_Parents
));
728 function Has_Rep_Pragma
732 Check_Parents
: Boolean := True) return Boolean
735 return Present
(Get_Rep_Pragma
(E
, Nam1
, Nam2
, Check_Parents
));
738 --------------------------------
739 -- Has_Unconstrained_Elements --
740 --------------------------------
742 function Has_Unconstrained_Elements
(T
: Entity_Id
) return Boolean is
743 U_T
: constant Entity_Id
:= Underlying_Type
(T
);
747 elsif Is_Record_Type
(U_T
) then
748 return Has_Discriminants
(U_T
) and then not Is_Constrained
(U_T
);
749 elsif Is_Array_Type
(U_T
) then
750 return Has_Unconstrained_Elements
(Component_Type
(U_T
));
754 end Has_Unconstrained_Elements
;
756 ----------------------
757 -- Has_Variant_Part --
758 ----------------------
760 function Has_Variant_Part
(Typ
: Entity_Id
) return Boolean is
767 if not Is_Type
(Typ
) then
771 FSTyp
:= First_Subtype
(Typ
);
773 if not Has_Discriminants
(FSTyp
) then
777 -- Proceed with cautious checks here, return False if tree is not
778 -- as expected (may be caused by prior errors).
780 Decl
:= Declaration_Node
(FSTyp
);
782 if Nkind
(Decl
) /= N_Full_Type_Declaration
then
786 TDef
:= Type_Definition
(Decl
);
788 if Nkind
(TDef
) /= N_Record_Definition
then
792 CList
:= Component_List
(TDef
);
794 if Nkind
(CList
) /= N_Component_List
then
797 return Present
(Variant_Part
(CList
));
799 end Has_Variant_Part
;
801 ---------------------
802 -- In_Generic_Body --
803 ---------------------
805 function In_Generic_Body
(Id
: Entity_Id
) return Boolean is
809 -- Climb scopes looking for generic body
812 while Present
(S
) and then S
/= Standard_Standard
loop
814 -- Generic package body
816 if Ekind
(S
) = E_Generic_Package
817 and then In_Package_Body
(S
)
821 -- Generic subprogram body
823 elsif Is_Subprogram
(S
)
824 and then Nkind
(Unit_Declaration_Node
(S
))
825 = N_Generic_Subprogram_Declaration
833 -- False if top of scope stack without finding a generic body
838 -------------------------------
839 -- Initialization_Suppressed --
840 -------------------------------
842 function Initialization_Suppressed
(Typ
: Entity_Id
) return Boolean is
844 return Suppress_Initialization
(Typ
)
845 or else Suppress_Initialization
(Base_Type
(Typ
));
846 end Initialization_Suppressed
;
852 procedure Initialize
is
854 Obsolescent_Warnings
.Init
;
861 function Is_Body
(N
: Node_Id
) return Boolean is
864 Nkind
(N
) in N_Body_Stub
865 or else Nkind_In
(N
, N_Entry_Body
,
872 ---------------------
873 -- Is_By_Copy_Type --
874 ---------------------
876 function Is_By_Copy_Type
(Ent
: Entity_Id
) return Boolean is
878 -- If Id is a private type whose full declaration has not been seen,
879 -- we assume for now that it is not a By_Copy type. Clearly this
880 -- attribute should not be used before the type is frozen, but it is
881 -- needed to build the associated record of a protected type. Another
882 -- place where some lookahead for a full view is needed ???
885 Is_Elementary_Type
(Ent
)
886 or else (Is_Private_Type
(Ent
)
887 and then Present
(Underlying_Type
(Ent
))
888 and then Is_Elementary_Type
(Underlying_Type
(Ent
)));
891 --------------------------
892 -- Is_By_Reference_Type --
893 --------------------------
895 function Is_By_Reference_Type
(Ent
: Entity_Id
) return Boolean is
896 Btype
: constant Entity_Id
:= Base_Type
(Ent
);
899 if Error_Posted
(Ent
) or else Error_Posted
(Btype
) then
902 elsif Is_Private_Type
(Btype
) then
904 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
909 return Is_By_Reference_Type
(Utyp
);
913 elsif Is_Incomplete_Type
(Btype
) then
915 Ftyp
: constant Entity_Id
:= Full_View
(Btype
);
920 return Is_By_Reference_Type
(Ftyp
);
924 elsif Is_Concurrent_Type
(Btype
) then
927 elsif Is_Record_Type
(Btype
) then
928 if Is_Limited_Record
(Btype
)
929 or else Is_Tagged_Type
(Btype
)
930 or else Is_Volatile
(Btype
)
939 C
:= First_Component
(Btype
);
940 while Present
(C
) loop
942 -- For each component, test if its type is a by reference
943 -- type and if its type is volatile. Also test the component
944 -- itself for being volatile. This happens for example when
945 -- a Volatile aspect is added to a component.
947 if Is_By_Reference_Type
(Etype
(C
))
948 or else Is_Volatile
(Etype
(C
))
949 or else Is_Volatile
(C
)
954 C
:= Next_Component
(C
);
961 elsif Is_Array_Type
(Btype
) then
964 or else Is_By_Reference_Type
(Component_Type
(Btype
))
965 or else Is_Volatile
(Component_Type
(Btype
))
966 or else Has_Volatile_Components
(Btype
);
971 end Is_By_Reference_Type
;
973 ---------------------
974 -- Is_Derived_Type --
975 ---------------------
977 function Is_Derived_Type
(Ent
: E
) return B
is
982 and then Base_Type
(Ent
) /= Root_Type
(Ent
)
983 and then not Is_Class_Wide_Type
(Ent
)
985 -- An access_to_subprogram whose result type is a limited view can
986 -- appear in a return statement, without the full view of the result
987 -- type being available. Do not interpret this as a derived type.
989 and then Ekind
(Ent
) /= E_Subprogram_Type
991 if not Is_Numeric_Type
(Root_Type
(Ent
)) then
995 Par
:= Parent
(First_Subtype
(Ent
));
998 and then Nkind
(Par
) = N_Full_Type_Declaration
999 and then Nkind
(Type_Definition
(Par
)) =
1000 N_Derived_Type_Definition
;
1006 end Is_Derived_Type
;
1008 -----------------------
1009 -- Is_Generic_Formal --
1010 -----------------------
1012 function Is_Generic_Formal
(E
: Entity_Id
) return Boolean is
1018 Kind
:= Nkind
(Parent
(E
));
1020 Nkind_In
(Kind
, N_Formal_Object_Declaration
,
1021 N_Formal_Package_Declaration
,
1022 N_Formal_Type_Declaration
)
1023 or else Is_Formal_Subprogram
(E
);
1025 end Is_Generic_Formal
;
1027 -------------------------------
1028 -- Is_Immutably_Limited_Type --
1029 -------------------------------
1031 function Is_Immutably_Limited_Type
(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_Immutably_Limited_Type
(Utyp
);
1076 elsif Is_Concurrent_Type
(Btype
) then
1082 end Is_Immutably_Limited_Type
;
1084 ---------------------------
1085 -- Is_Indefinite_Subtype --
1086 ---------------------------
1088 function Is_Indefinite_Subtype
(Ent
: Entity_Id
) return Boolean is
1089 K
: constant Entity_Kind
:= Ekind
(Ent
);
1092 if Is_Constrained
(Ent
) then
1095 elsif K
in Array_Kind
1096 or else K
in Class_Wide_Kind
1097 or else Has_Unknown_Discriminants
(Ent
)
1101 -- Known discriminants: indefinite if there are no default values
1103 elsif K
in Record_Kind
1104 or else Is_Incomplete_Or_Private_Type
(Ent
)
1105 or else Is_Concurrent_Type
(Ent
)
1107 return (Has_Discriminants
(Ent
)
1109 No
(Discriminant_Default_Value
(First_Discriminant
(Ent
))));
1114 end Is_Indefinite_Subtype
;
1116 ---------------------
1117 -- Is_Limited_Type --
1118 ---------------------
1120 function Is_Limited_Type
(Ent
: Entity_Id
) return Boolean is
1121 Btype
: constant E
:= Base_Type
(Ent
);
1122 Rtype
: constant E
:= Root_Type
(Btype
);
1125 if not Is_Type
(Ent
) then
1128 elsif Ekind
(Btype
) = E_Limited_Private_Type
1129 or else Is_Limited_Composite
(Btype
)
1133 elsif Is_Concurrent_Type
(Btype
) then
1136 -- The Is_Limited_Record flag normally indicates that the type is
1137 -- limited. The exception is that a type does not inherit limitedness
1138 -- from its interface ancestor. So the type may be derived from a
1139 -- limited interface, but is not limited.
1141 elsif Is_Limited_Record
(Ent
)
1142 and then not Is_Interface
(Ent
)
1146 -- Otherwise we will look around to see if there is some other reason
1147 -- for it to be limited, except that if an error was posted on the
1148 -- entity, then just assume it is non-limited, because it can cause
1149 -- trouble to recurse into a murky entity resulting from other errors.
1151 elsif Error_Posted
(Ent
) then
1154 elsif Is_Record_Type
(Btype
) then
1156 if Is_Limited_Interface
(Ent
) then
1159 -- AI-419: limitedness is not inherited from a limited interface
1161 elsif Is_Limited_Record
(Rtype
) then
1162 return not Is_Interface
(Rtype
)
1163 or else Is_Protected_Interface
(Rtype
)
1164 or else Is_Synchronized_Interface
(Rtype
)
1165 or else Is_Task_Interface
(Rtype
);
1167 elsif Is_Class_Wide_Type
(Btype
) then
1168 return Is_Limited_Type
(Rtype
);
1175 C
:= First_Component
(Btype
);
1176 while Present
(C
) loop
1177 if Is_Limited_Type
(Etype
(C
)) then
1181 C
:= Next_Component
(C
);
1188 elsif Is_Array_Type
(Btype
) then
1189 return Is_Limited_Type
(Component_Type
(Btype
));
1194 end Is_Limited_Type
;
1196 ---------------------
1197 -- Is_Limited_View --
1198 ---------------------
1200 function Is_Limited_View
(Ent
: Entity_Id
) return Boolean is
1201 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
1204 if Is_Limited_Record
(Btype
) then
1207 elsif Ekind
(Btype
) = E_Limited_Private_Type
1208 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
1210 return not In_Package_Body
(Scope
((Btype
)));
1212 elsif Is_Private_Type
(Btype
) then
1214 -- AI05-0063: A type derived from a limited private formal type is
1215 -- not immutably limited in a generic body.
1217 if Is_Derived_Type
(Btype
)
1218 and then Is_Generic_Type
(Etype
(Btype
))
1220 if not Is_Limited_Type
(Etype
(Btype
)) then
1223 -- A descendant of a limited formal type is not immutably limited
1224 -- in the generic body, or in the body of a generic child.
1226 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
1227 return not In_Package_Body
(Scope
(Btype
));
1235 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
1240 return Is_Limited_View
(Utyp
);
1245 elsif Is_Concurrent_Type
(Btype
) then
1248 elsif Is_Record_Type
(Btype
) then
1250 -- Note that we return True for all limited interfaces, even though
1251 -- (unsynchronized) limited interfaces can have descendants that are
1252 -- nonlimited, because this is a predicate on the type itself, and
1253 -- things like functions with limited interface results need to be
1254 -- handled as build in place even though they might return objects
1255 -- of a type that is not inherently limited.
1257 if Is_Class_Wide_Type
(Btype
) then
1258 return Is_Limited_View
(Root_Type
(Btype
));
1265 C
:= First_Component
(Btype
);
1266 while Present
(C
) loop
1268 -- Don't consider components with interface types (which can
1269 -- only occur in the case of a _parent component anyway).
1270 -- They don't have any components, plus it would cause this
1271 -- function to return true for nonlimited types derived from
1272 -- limited interfaces.
1274 if not Is_Interface
(Etype
(C
))
1275 and then Is_Limited_View
(Etype
(C
))
1280 C
:= Next_Component
(C
);
1287 elsif Is_Array_Type
(Btype
) then
1288 return Is_Limited_View
(Component_Type
(Btype
));
1293 end Is_Limited_View
;
1295 ----------------------
1296 -- Nearest_Ancestor --
1297 ----------------------
1299 function Nearest_Ancestor
(Typ
: Entity_Id
) return Entity_Id
is
1300 D
: constant Node_Id
:= Declaration_Node
(Typ
);
1303 -- If we have a subtype declaration, get the ancestor subtype
1305 if Nkind
(D
) = N_Subtype_Declaration
then
1306 if Nkind
(Subtype_Indication
(D
)) = N_Subtype_Indication
then
1307 return Entity
(Subtype_Mark
(Subtype_Indication
(D
)));
1309 return Entity
(Subtype_Indication
(D
));
1312 -- If derived type declaration, find who we are derived from
1314 elsif Nkind
(D
) = N_Full_Type_Declaration
1315 and then Nkind
(Type_Definition
(D
)) = N_Derived_Type_Definition
1318 DTD
: constant Entity_Id
:= Type_Definition
(D
);
1319 SI
: constant Entity_Id
:= Subtype_Indication
(DTD
);
1321 if Is_Entity_Name
(SI
) then
1324 return Entity
(Subtype_Mark
(SI
));
1328 -- If derived type and private type, get the full view to find who we
1329 -- are derived from.
1331 elsif Is_Derived_Type
(Typ
)
1332 and then Is_Private_Type
(Typ
)
1333 and then Present
(Full_View
(Typ
))
1335 return Nearest_Ancestor
(Full_View
(Typ
));
1337 -- Otherwise, nothing useful to return, return Empty
1342 end Nearest_Ancestor
;
1344 ---------------------------
1345 -- Nearest_Dynamic_Scope --
1346 ---------------------------
1348 function Nearest_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
1350 if Is_Dynamic_Scope
(Ent
) then
1353 return Enclosing_Dynamic_Scope
(Ent
);
1355 end Nearest_Dynamic_Scope
;
1357 ------------------------
1358 -- Next_Tag_Component --
1359 ------------------------
1361 function Next_Tag_Component
(Tag
: Entity_Id
) return Entity_Id
is
1365 pragma Assert
(Is_Tag
(Tag
));
1367 -- Loop to look for next tag component
1369 Comp
:= Next_Entity
(Tag
);
1370 while Present
(Comp
) loop
1371 if Is_Tag
(Comp
) then
1372 pragma Assert
(Chars
(Comp
) /= Name_uTag
);
1376 Comp
:= Next_Entity
(Comp
);
1379 -- No tag component found
1382 end Next_Tag_Component
;
1384 --------------------------
1385 -- Number_Discriminants --
1386 --------------------------
1388 function Number_Discriminants
(Typ
: Entity_Id
) return Pos
is
1394 Discr
:= First_Discriminant
(Typ
);
1395 while Present
(Discr
) loop
1397 Discr
:= Next_Discriminant
(Discr
);
1401 end Number_Discriminants
;
1403 ----------------------------------------------
1404 -- Object_Type_Has_Constrained_Partial_View --
1405 ----------------------------------------------
1407 function Object_Type_Has_Constrained_Partial_View
1409 Scop
: Entity_Id
) return Boolean
1412 return Has_Constrained_Partial_View
(Typ
)
1413 or else (In_Generic_Body
(Scop
)
1414 and then Is_Generic_Type
(Base_Type
(Typ
))
1415 and then Is_Private_Type
(Base_Type
(Typ
))
1416 and then not Is_Tagged_Type
(Typ
)
1417 and then not (Is_Array_Type
(Typ
)
1418 and then not Is_Constrained
(Typ
))
1419 and then Has_Discriminants
(Typ
));
1420 end Object_Type_Has_Constrained_Partial_View
;
1422 ---------------------------
1423 -- Package_Specification --
1424 ---------------------------
1426 function Package_Specification
(Pack_Id
: Entity_Id
) return Node_Id
is
1430 N
:= Parent
(Pack_Id
);
1431 while Nkind
(N
) /= N_Package_Specification
loop
1435 raise Program_Error
;
1440 end Package_Specification
;
1446 procedure Tree_Read
is
1448 Obsolescent_Warnings
.Tree_Read
;
1455 procedure Tree_Write
is
1457 Obsolescent_Warnings
.Tree_Write
;
1460 --------------------
1461 -- Ultimate_Alias --
1462 --------------------
1464 function Ultimate_Alias
(Prim
: Entity_Id
) return Entity_Id
is
1465 E
: Entity_Id
:= Prim
;
1468 while Present
(Alias
(E
)) loop
1469 pragma Assert
(Alias
(E
) /= E
);
1476 --------------------------
1477 -- Unit_Declaration_Node --
1478 --------------------------
1480 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
1481 N
: Node_Id
:= Parent
(Unit_Id
);
1484 -- Predefined operators do not have a full function declaration
1486 if Ekind
(Unit_Id
) = E_Operator
then
1490 -- Isn't there some better way to express the following ???
1492 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
1493 and then Nkind
(N
) /= N_Formal_Package_Declaration
1494 and then Nkind
(N
) /= N_Function_Instantiation
1495 and then Nkind
(N
) /= N_Generic_Package_Declaration
1496 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
1497 and then Nkind
(N
) /= N_Package_Declaration
1498 and then Nkind
(N
) /= N_Package_Body
1499 and then Nkind
(N
) /= N_Package_Instantiation
1500 and then Nkind
(N
) /= N_Package_Renaming_Declaration
1501 and then Nkind
(N
) /= N_Procedure_Instantiation
1502 and then Nkind
(N
) /= N_Protected_Body
1503 and then Nkind
(N
) /= N_Subprogram_Declaration
1504 and then Nkind
(N
) /= N_Subprogram_Body
1505 and then Nkind
(N
) /= N_Subprogram_Body_Stub
1506 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
1507 and then Nkind
(N
) /= N_Task_Body
1508 and then Nkind
(N
) /= N_Task_Type_Declaration
1509 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
1510 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
1514 -- We don't use Assert here, because that causes an infinite loop
1515 -- when assertions are turned off. Better to crash.
1518 raise Program_Error
;
1523 end Unit_Declaration_Node
;