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 view (if available)
83 if Has_Non_Limited_View
(Ent
) then
84 return Get_Full_View
(Non_Limited_View
(Ent
));
86 -- In all other cases, return entity unchanged
97 function Constant_Value
(Ent
: Entity_Id
) return Node_Id
is
98 D
: constant Node_Id
:= Declaration_Node
(Ent
);
102 -- If we have no declaration node, then return no constant value. Not
103 -- clear how this can happen, but it does sometimes and this is the
109 -- Normal case where a declaration node is present
111 elsif Nkind
(D
) = N_Object_Renaming_Declaration
then
112 return Renamed_Object
(Ent
);
114 -- If this is a component declaration whose entity is a constant, it is
115 -- a prival within a protected function (and so has no constant value).
117 elsif Nkind
(D
) = N_Component_Declaration
then
120 -- If there is an expression, return it
122 elsif Present
(Expression
(D
)) then
123 return (Expression
(D
));
125 -- For a constant, see if we have a full view
127 elsif Ekind
(Ent
) = E_Constant
128 and then Present
(Full_View
(Ent
))
130 Full_D
:= Parent
(Full_View
(Ent
));
132 -- The full view may have been rewritten as an object renaming
134 if Nkind
(Full_D
) = N_Object_Renaming_Declaration
then
135 return Name
(Full_D
);
137 return Expression
(Full_D
);
140 -- Otherwise we have no expression to return
147 ---------------------------------
148 -- Corresponding_Unsigned_Type --
149 ---------------------------------
151 function Corresponding_Unsigned_Type
(Typ
: Entity_Id
) return Entity_Id
is
152 pragma Assert
(Is_Signed_Integer_Type
(Typ
));
153 Siz
: constant Uint
:= Esize
(Base_Type
(Typ
));
155 if Siz
= Esize
(Standard_Short_Short_Integer
) then
156 return Standard_Short_Short_Unsigned
;
157 elsif Siz
= Esize
(Standard_Short_Integer
) then
158 return Standard_Short_Unsigned
;
159 elsif Siz
= Esize
(Standard_Unsigned
) then
160 return Standard_Unsigned
;
161 elsif Siz
= Esize
(Standard_Long_Integer
) then
162 return Standard_Long_Unsigned
;
163 elsif Siz
= Esize
(Standard_Long_Long_Integer
) then
164 return Standard_Long_Long_Unsigned
;
168 end Corresponding_Unsigned_Type
;
170 -----------------------------
171 -- Enclosing_Dynamic_Scope --
172 -----------------------------
174 function Enclosing_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
178 -- The following test is an error defense against some syntax errors
179 -- that can leave scopes very messed up.
181 if Ent
= Standard_Standard
then
185 -- Normal case, search enclosing scopes
187 -- Note: the test for Present (S) should not be required, it defends
188 -- against an ill-formed tree.
192 -- If we somehow got an empty value for Scope, the tree must be
193 -- malformed. Rather than blow up we return Standard in this case.
196 return Standard_Standard
;
198 -- Quit if we get to standard or a dynamic scope. We must also
199 -- handle enclosing scopes that have a full view; required to
200 -- locate enclosing scopes that are synchronized private types
201 -- whose full view is a task type.
203 elsif S
= Standard_Standard
204 or else Is_Dynamic_Scope
(S
)
205 or else (Is_Private_Type
(S
)
206 and then Present
(Full_View
(S
))
207 and then Is_Dynamic_Scope
(Full_View
(S
)))
211 -- Otherwise keep climbing
217 end Enclosing_Dynamic_Scope
;
219 ------------------------
220 -- First_Discriminant --
221 ------------------------
223 function First_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
228 (Has_Discriminants
(Typ
) or else Has_Unknown_Discriminants
(Typ
));
230 Ent
:= First_Entity
(Typ
);
232 -- The discriminants are not necessarily contiguous, because access
233 -- discriminants will generate itypes. They are not the first entities
234 -- either because the tag must be ahead of them.
236 if Chars
(Ent
) = Name_uTag
then
237 Ent
:= Next_Entity
(Ent
);
240 -- Skip all hidden stored discriminants if any
242 while Present
(Ent
) loop
243 exit when Ekind
(Ent
) = E_Discriminant
244 and then not Is_Completely_Hidden
(Ent
);
246 Ent
:= Next_Entity
(Ent
);
249 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
252 end First_Discriminant
;
254 -------------------------------
255 -- First_Stored_Discriminant --
256 -------------------------------
258 function First_Stored_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
261 function Has_Completely_Hidden_Discriminant
262 (Typ
: Entity_Id
) return Boolean;
263 -- Scans the Discriminants to see whether any are Completely_Hidden
264 -- (the mechanism for describing non-specified stored discriminants)
265 -- Note that the entity list for the type may contain anonymous access
266 -- types created by expressions that constrain access discriminants.
268 ----------------------------------------
269 -- Has_Completely_Hidden_Discriminant --
270 ----------------------------------------
272 function Has_Completely_Hidden_Discriminant
273 (Typ
: Entity_Id
) return Boolean
278 pragma Assert
(Ekind
(Typ
) = E_Discriminant
);
281 while Present
(Ent
) loop
283 -- Skip anonymous types that may be created by expressions
284 -- used as discriminant constraints on inherited discriminants.
286 if Is_Itype
(Ent
) then
289 elsif Ekind
(Ent
) = E_Discriminant
290 and then Is_Completely_Hidden
(Ent
)
295 Ent
:= Next_Entity
(Ent
);
299 end Has_Completely_Hidden_Discriminant
;
301 -- Start of processing for First_Stored_Discriminant
305 (Has_Discriminants
(Typ
)
306 or else Has_Unknown_Discriminants
(Typ
));
308 Ent
:= First_Entity
(Typ
);
310 if Chars
(Ent
) = Name_uTag
then
311 Ent
:= Next_Entity
(Ent
);
314 if Has_Completely_Hidden_Discriminant
(Ent
) then
315 while Present
(Ent
) loop
316 exit when Ekind
(Ent
) = E_Discriminant
317 and then Is_Completely_Hidden
(Ent
);
318 Ent
:= Next_Entity
(Ent
);
322 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
325 end First_Stored_Discriminant
;
331 function First_Subtype
(Typ
: Entity_Id
) return Entity_Id
is
332 B
: constant Entity_Id
:= Base_Type
(Typ
);
333 F
: constant Node_Id
:= Freeze_Node
(B
);
337 -- If the base type has no freeze node, it is a type in Standard, and
338 -- always acts as its own first subtype, except where it is one of the
339 -- predefined integer types. If the type is formal, it is also a first
340 -- subtype, and its base type has no freeze node. On the other hand, a
341 -- subtype of a generic formal is not its own first subtype. Its base
342 -- type, if anonymous, is attached to the formal type decl. from which
343 -- the first subtype is obtained.
346 if B
= Base_Type
(Standard_Integer
) then
347 return Standard_Integer
;
349 elsif B
= Base_Type
(Standard_Long_Integer
) then
350 return Standard_Long_Integer
;
352 elsif B
= Base_Type
(Standard_Short_Short_Integer
) then
353 return Standard_Short_Short_Integer
;
355 elsif B
= Base_Type
(Standard_Short_Integer
) then
356 return Standard_Short_Integer
;
358 elsif B
= Base_Type
(Standard_Long_Long_Integer
) then
359 return Standard_Long_Long_Integer
;
361 elsif Is_Generic_Type
(Typ
) then
362 if Present
(Parent
(B
)) then
363 return Defining_Identifier
(Parent
(B
));
365 return Defining_Identifier
(Associated_Node_For_Itype
(B
));
372 -- Otherwise we check the freeze node, if it has a First_Subtype_Link
373 -- then we use that link, otherwise (happens with some Itypes), we use
374 -- the base type itself.
377 Ent
:= First_Subtype_Link
(F
);
379 if Present
(Ent
) then
387 -------------------------
388 -- First_Tag_Component --
389 -------------------------
391 function First_Tag_Component
(Typ
: Entity_Id
) return Entity_Id
is
397 pragma Assert
(Is_Tagged_Type
(Ctyp
));
399 if Is_Class_Wide_Type
(Ctyp
) then
400 Ctyp
:= Root_Type
(Ctyp
);
403 if Is_Private_Type
(Ctyp
) then
404 Ctyp
:= Underlying_Type
(Ctyp
);
406 -- If the underlying type is missing then the source program has
407 -- errors and there is nothing else to do (the full-type declaration
408 -- associated with the private type declaration is missing).
415 Comp
:= First_Entity
(Ctyp
);
416 while Present
(Comp
) loop
417 if Is_Tag
(Comp
) then
421 Comp
:= Next_Entity
(Comp
);
424 -- No tag component found
427 end First_Tag_Component
;
429 ---------------------
430 -- Get_Binary_Nkind --
431 ---------------------
433 function Get_Binary_Nkind
(Op
: Entity_Id
) return Node_Kind
is
438 when Name_Op_Concat
=>
440 when Name_Op_Expon
=>
442 when Name_Op_Subtract
=>
443 return N_Op_Subtract
;
446 when Name_Op_Multiply
=>
447 return N_Op_Multiply
;
448 when Name_Op_Divide
=>
473 end Get_Binary_Nkind
;
479 function Get_Rep_Item
482 Check_Parents
: Boolean := True) return Node_Id
487 N
:= First_Rep_Item
(E
);
488 while Present
(N
) loop
490 -- Only one of Priority / Interrupt_Priority can be specified, so
491 -- return whichever one is present to catch illegal duplication.
493 if Nkind
(N
) = N_Pragma
495 (Pragma_Name
(N
) = Nam
496 or else (Nam
= Name_Priority
497 and then Pragma_Name
(N
) = Name_Interrupt_Priority
)
498 or else (Nam
= Name_Interrupt_Priority
499 and then Pragma_Name
(N
) = Name_Priority
))
501 if Check_Parents
then
504 -- If Check_Parents is False, return N if the pragma doesn't
505 -- appear in the Rep_Item chain of the parent.
509 Par
: constant Entity_Id
:= Nearest_Ancestor
(E
);
510 -- This node represents the parent type of type E (if any)
516 elsif not Present_In_Rep_Item
(Par
, N
) then
522 elsif Nkind
(N
) = N_Attribute_Definition_Clause
525 or else (Nam
= Name_Priority
526 and then Chars
(N
) = Name_Interrupt_Priority
))
528 if Check_Parents
or else Entity
(N
) = E
then
532 elsif Nkind
(N
) = N_Aspect_Specification
534 (Chars
(Identifier
(N
)) = Nam
537 and then Chars
(Identifier
(N
)) = Name_Interrupt_Priority
))
539 if Check_Parents
then
542 elsif Entity
(N
) = E
then
553 function Get_Rep_Item
557 Check_Parents
: Boolean := True) return Node_Id
559 Nam1_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam1
, Check_Parents
);
560 Nam2_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam2
, Check_Parents
);
565 -- Check both Nam1_Item and Nam2_Item are present
567 if No
(Nam1_Item
) then
569 elsif No
(Nam2_Item
) then
573 -- Return the first node encountered in the list
575 N
:= First_Rep_Item
(E
);
576 while Present
(N
) loop
577 if N
= Nam1_Item
or else N
= Nam2_Item
then
591 function Get_Rep_Pragma
594 Check_Parents
: Boolean := True) return Node_Id
599 N
:= Get_Rep_Item
(E
, Nam
, Check_Parents
);
601 if Present
(N
) and then Nkind
(N
) = N_Pragma
then
608 function Get_Rep_Pragma
612 Check_Parents
: Boolean := True) return Node_Id
614 Nam1_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam1
, Check_Parents
);
615 Nam2_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam2
, Check_Parents
);
620 -- Check both Nam1_Item and Nam2_Item are present
622 if No
(Nam1_Item
) then
624 elsif No
(Nam2_Item
) then
628 -- Return the first node encountered in the list
630 N
:= First_Rep_Item
(E
);
631 while Present
(N
) loop
632 if N
= Nam1_Item
or else N
= Nam2_Item
then
642 ---------------------
643 -- Get_Unary_Nkind --
644 ---------------------
646 function Get_Unary_Nkind
(Op
: Entity_Id
) return Node_Kind
is
651 when Name_Op_Subtract
=>
662 ---------------------------------
663 -- Has_External_Tag_Rep_Clause --
664 ---------------------------------
666 function Has_External_Tag_Rep_Clause
(T
: Entity_Id
) return Boolean is
668 pragma Assert
(Is_Tagged_Type
(T
));
669 return Has_Rep_Item
(T
, Name_External_Tag
, Check_Parents
=> False);
670 end Has_External_Tag_Rep_Clause
;
676 function Has_Rep_Item
679 Check_Parents
: Boolean := True) return Boolean
682 return Present
(Get_Rep_Item
(E
, Nam
, Check_Parents
));
685 function Has_Rep_Item
689 Check_Parents
: Boolean := True) return Boolean
692 return Present
(Get_Rep_Item
(E
, Nam1
, Nam2
, Check_Parents
));
699 function Has_Rep_Pragma
702 Check_Parents
: Boolean := True) return Boolean
705 return Present
(Get_Rep_Pragma
(E
, Nam
, Check_Parents
));
708 function Has_Rep_Pragma
712 Check_Parents
: Boolean := True) return Boolean
715 return Present
(Get_Rep_Pragma
(E
, Nam1
, Nam2
, Check_Parents
));
718 --------------------------------
719 -- Has_Unconstrained_Elements --
720 --------------------------------
722 function Has_Unconstrained_Elements
(T
: Entity_Id
) return Boolean is
723 U_T
: constant Entity_Id
:= Underlying_Type
(T
);
727 elsif Is_Record_Type
(U_T
) then
728 return Has_Discriminants
(U_T
) and then not Is_Constrained
(U_T
);
729 elsif Is_Array_Type
(U_T
) then
730 return Has_Unconstrained_Elements
(Component_Type
(U_T
));
734 end Has_Unconstrained_Elements
;
736 ----------------------
737 -- Has_Variant_Part --
738 ----------------------
740 function Has_Variant_Part
(Typ
: Entity_Id
) return Boolean is
747 if not Is_Type
(Typ
) then
751 FSTyp
:= First_Subtype
(Typ
);
753 if not Has_Discriminants
(FSTyp
) then
757 -- Proceed with cautious checks here, return False if tree is not
758 -- as expected (may be caused by prior errors).
760 Decl
:= Declaration_Node
(FSTyp
);
762 if Nkind
(Decl
) /= N_Full_Type_Declaration
then
766 TDef
:= Type_Definition
(Decl
);
768 if Nkind
(TDef
) /= N_Record_Definition
then
772 CList
:= Component_List
(TDef
);
774 if Nkind
(CList
) /= N_Component_List
then
777 return Present
(Variant_Part
(CList
));
779 end Has_Variant_Part
;
781 ---------------------
782 -- In_Generic_Body --
783 ---------------------
785 function In_Generic_Body
(Id
: Entity_Id
) return Boolean is
789 -- Climb scopes looking for generic body
792 while Present
(S
) and then S
/= Standard_Standard
loop
794 -- Generic package body
796 if Ekind
(S
) = E_Generic_Package
797 and then In_Package_Body
(S
)
801 -- Generic subprogram body
803 elsif Is_Subprogram
(S
)
804 and then Nkind
(Unit_Declaration_Node
(S
))
805 = N_Generic_Subprogram_Declaration
813 -- False if top of scope stack without finding a generic body
818 -------------------------------
819 -- Initialization_Suppressed --
820 -------------------------------
822 function Initialization_Suppressed
(Typ
: Entity_Id
) return Boolean is
824 return Suppress_Initialization
(Typ
)
825 or else Suppress_Initialization
(Base_Type
(Typ
));
826 end Initialization_Suppressed
;
832 procedure Initialize
is
834 Obsolescent_Warnings
.Init
;
841 function Is_Body
(N
: Node_Id
) return Boolean is
844 Nkind
(N
) in N_Body_Stub
845 or else Nkind_In
(N
, N_Entry_Body
,
852 ---------------------
853 -- Is_By_Copy_Type --
854 ---------------------
856 function Is_By_Copy_Type
(Ent
: Entity_Id
) return Boolean is
858 -- If Id is a private type whose full declaration has not been seen,
859 -- we assume for now that it is not a By_Copy type. Clearly this
860 -- attribute should not be used before the type is frozen, but it is
861 -- needed to build the associated record of a protected type. Another
862 -- place where some lookahead for a full view is needed ???
865 Is_Elementary_Type
(Ent
)
866 or else (Is_Private_Type
(Ent
)
867 and then Present
(Underlying_Type
(Ent
))
868 and then Is_Elementary_Type
(Underlying_Type
(Ent
)));
871 --------------------------
872 -- Is_By_Reference_Type --
873 --------------------------
875 function Is_By_Reference_Type
(Ent
: Entity_Id
) return Boolean is
876 Btype
: constant Entity_Id
:= Base_Type
(Ent
);
879 if Error_Posted
(Ent
) or else Error_Posted
(Btype
) then
882 elsif Is_Private_Type
(Btype
) then
884 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
889 return Is_By_Reference_Type
(Utyp
);
893 elsif Is_Incomplete_Type
(Btype
) then
895 Ftyp
: constant Entity_Id
:= Full_View
(Btype
);
900 return Is_By_Reference_Type
(Ftyp
);
904 elsif Is_Concurrent_Type
(Btype
) then
907 elsif Is_Record_Type
(Btype
) then
908 if Is_Limited_Record
(Btype
)
909 or else Is_Tagged_Type
(Btype
)
910 or else Is_Volatile
(Btype
)
919 C
:= First_Component
(Btype
);
920 while Present
(C
) loop
922 -- For each component, test if its type is a by reference
923 -- type and if its type is volatile. Also test the component
924 -- itself for being volatile. This happens for example when
925 -- a Volatile aspect is added to a component.
927 if Is_By_Reference_Type
(Etype
(C
))
928 or else Is_Volatile
(Etype
(C
))
929 or else Is_Volatile
(C
)
934 C
:= Next_Component
(C
);
941 elsif Is_Array_Type
(Btype
) then
944 or else Is_By_Reference_Type
(Component_Type
(Btype
))
945 or else Is_Volatile
(Component_Type
(Btype
))
946 or else Has_Volatile_Components
(Btype
);
951 end Is_By_Reference_Type
;
953 ---------------------
954 -- Is_Derived_Type --
955 ---------------------
957 function Is_Derived_Type
(Ent
: E
) return B
is
962 and then Base_Type
(Ent
) /= Root_Type
(Ent
)
963 and then not Is_Class_Wide_Type
(Ent
)
965 -- An access_to_subprogram whose result type is a limited view can
966 -- appear in a return statement, without the full view of the result
967 -- type being available. Do not interpret this as a derived type.
969 and then Ekind
(Ent
) /= E_Subprogram_Type
971 if not Is_Numeric_Type
(Root_Type
(Ent
)) then
975 Par
:= Parent
(First_Subtype
(Ent
));
978 and then Nkind
(Par
) = N_Full_Type_Declaration
979 and then Nkind
(Type_Definition
(Par
)) =
980 N_Derived_Type_Definition
;
988 -----------------------
989 -- Is_Generic_Formal --
990 -----------------------
992 function Is_Generic_Formal
(E
: Entity_Id
) return Boolean is
998 Kind
:= Nkind
(Parent
(E
));
1000 Nkind_In
(Kind
, N_Formal_Object_Declaration
,
1001 N_Formal_Package_Declaration
,
1002 N_Formal_Type_Declaration
)
1003 or else Is_Formal_Subprogram
(E
);
1005 end Is_Generic_Formal
;
1007 -------------------------------
1008 -- Is_Immutably_Limited_Type --
1009 -------------------------------
1011 function Is_Immutably_Limited_Type
(Ent
: Entity_Id
) return Boolean is
1012 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
1015 if Is_Limited_Record
(Btype
) then
1018 elsif Ekind
(Btype
) = E_Limited_Private_Type
1019 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
1021 return not In_Package_Body
(Scope
((Btype
)));
1023 elsif Is_Private_Type
(Btype
) then
1025 -- AI05-0063: A type derived from a limited private formal type is
1026 -- not immutably limited in a generic body.
1028 if Is_Derived_Type
(Btype
)
1029 and then Is_Generic_Type
(Etype
(Btype
))
1031 if not Is_Limited_Type
(Etype
(Btype
)) then
1034 -- A descendant of a limited formal type is not immutably limited
1035 -- in the generic body, or in the body of a generic child.
1037 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
1038 return not In_Package_Body
(Scope
(Btype
));
1046 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
1051 return Is_Immutably_Limited_Type
(Utyp
);
1056 elsif Is_Concurrent_Type
(Btype
) then
1062 end Is_Immutably_Limited_Type
;
1064 ---------------------------
1065 -- Is_Indefinite_Subtype --
1066 ---------------------------
1068 function Is_Indefinite_Subtype
(Ent
: Entity_Id
) return Boolean is
1069 K
: constant Entity_Kind
:= Ekind
(Ent
);
1072 if Is_Constrained
(Ent
) then
1075 elsif K
in Array_Kind
1076 or else K
in Class_Wide_Kind
1077 or else Has_Unknown_Discriminants
(Ent
)
1081 -- Known discriminants: indefinite if there are no default values
1083 elsif K
in Record_Kind
1084 or else Is_Incomplete_Or_Private_Type
(Ent
)
1085 or else Is_Concurrent_Type
(Ent
)
1087 return (Has_Discriminants
(Ent
)
1089 No
(Discriminant_Default_Value
(First_Discriminant
(Ent
))));
1094 end Is_Indefinite_Subtype
;
1096 ---------------------
1097 -- Is_Limited_Type --
1098 ---------------------
1100 function Is_Limited_Type
(Ent
: Entity_Id
) return Boolean is
1101 Btype
: constant E
:= Base_Type
(Ent
);
1102 Rtype
: constant E
:= Root_Type
(Btype
);
1105 if not Is_Type
(Ent
) then
1108 elsif Ekind
(Btype
) = E_Limited_Private_Type
1109 or else Is_Limited_Composite
(Btype
)
1113 elsif Is_Concurrent_Type
(Btype
) then
1116 -- The Is_Limited_Record flag normally indicates that the type is
1117 -- limited. The exception is that a type does not inherit limitedness
1118 -- from its interface ancestor. So the type may be derived from a
1119 -- limited interface, but is not limited.
1121 elsif Is_Limited_Record
(Ent
)
1122 and then not Is_Interface
(Ent
)
1126 -- Otherwise we will look around to see if there is some other reason
1127 -- for it to be limited, except that if an error was posted on the
1128 -- entity, then just assume it is non-limited, because it can cause
1129 -- trouble to recurse into a murky entity resulting from other errors.
1131 elsif Error_Posted
(Ent
) then
1134 elsif Is_Record_Type
(Btype
) then
1136 if Is_Limited_Interface
(Ent
) then
1139 -- AI-419: limitedness is not inherited from a limited interface
1141 elsif Is_Limited_Record
(Rtype
) then
1142 return not Is_Interface
(Rtype
)
1143 or else Is_Protected_Interface
(Rtype
)
1144 or else Is_Synchronized_Interface
(Rtype
)
1145 or else Is_Task_Interface
(Rtype
);
1147 elsif Is_Class_Wide_Type
(Btype
) then
1148 return Is_Limited_Type
(Rtype
);
1155 C
:= First_Component
(Btype
);
1156 while Present
(C
) loop
1157 if Is_Limited_Type
(Etype
(C
)) then
1161 C
:= Next_Component
(C
);
1168 elsif Is_Array_Type
(Btype
) then
1169 return Is_Limited_Type
(Component_Type
(Btype
));
1174 end Is_Limited_Type
;
1176 ---------------------
1177 -- Is_Limited_View --
1178 ---------------------
1180 function Is_Limited_View
(Ent
: Entity_Id
) return Boolean is
1181 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
1184 if Is_Limited_Record
(Btype
) then
1187 elsif Ekind
(Btype
) = E_Limited_Private_Type
1188 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
1190 return not In_Package_Body
(Scope
((Btype
)));
1192 elsif Is_Private_Type
(Btype
) then
1194 -- AI05-0063: A type derived from a limited private formal type is
1195 -- not immutably limited in a generic body.
1197 if Is_Derived_Type
(Btype
)
1198 and then Is_Generic_Type
(Etype
(Btype
))
1200 if not Is_Limited_Type
(Etype
(Btype
)) then
1203 -- A descendant of a limited formal type is not immutably limited
1204 -- in the generic body, or in the body of a generic child.
1206 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
1207 return not In_Package_Body
(Scope
(Btype
));
1215 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
1220 return Is_Limited_View
(Utyp
);
1225 elsif Is_Concurrent_Type
(Btype
) then
1228 elsif Is_Record_Type
(Btype
) then
1230 -- Note that we return True for all limited interfaces, even though
1231 -- (unsynchronized) limited interfaces can have descendants that are
1232 -- nonlimited, because this is a predicate on the type itself, and
1233 -- things like functions with limited interface results need to be
1234 -- handled as build in place even though they might return objects
1235 -- of a type that is not inherently limited.
1237 if Is_Class_Wide_Type
(Btype
) then
1238 return Is_Limited_View
(Root_Type
(Btype
));
1245 C
:= First_Component
(Btype
);
1246 while Present
(C
) loop
1248 -- Don't consider components with interface types (which can
1249 -- only occur in the case of a _parent component anyway).
1250 -- They don't have any components, plus it would cause this
1251 -- function to return true for nonlimited types derived from
1252 -- limited interfaces.
1254 if not Is_Interface
(Etype
(C
))
1255 and then Is_Limited_View
(Etype
(C
))
1260 C
:= Next_Component
(C
);
1267 elsif Is_Array_Type
(Btype
) then
1268 return Is_Limited_View
(Component_Type
(Btype
));
1273 end Is_Limited_View
;
1275 ----------------------
1276 -- Nearest_Ancestor --
1277 ----------------------
1279 function Nearest_Ancestor
(Typ
: Entity_Id
) return Entity_Id
is
1280 D
: constant Node_Id
:= Declaration_Node
(Typ
);
1283 -- If we have a subtype declaration, get the ancestor subtype
1285 if Nkind
(D
) = N_Subtype_Declaration
then
1286 if Nkind
(Subtype_Indication
(D
)) = N_Subtype_Indication
then
1287 return Entity
(Subtype_Mark
(Subtype_Indication
(D
)));
1289 return Entity
(Subtype_Indication
(D
));
1292 -- If derived type declaration, find who we are derived from
1294 elsif Nkind
(D
) = N_Full_Type_Declaration
1295 and then Nkind
(Type_Definition
(D
)) = N_Derived_Type_Definition
1298 DTD
: constant Entity_Id
:= Type_Definition
(D
);
1299 SI
: constant Entity_Id
:= Subtype_Indication
(DTD
);
1301 if Is_Entity_Name
(SI
) then
1304 return Entity
(Subtype_Mark
(SI
));
1308 -- If derived type and private type, get the full view to find who we
1309 -- are derived from.
1311 elsif Is_Derived_Type
(Typ
)
1312 and then Is_Private_Type
(Typ
)
1313 and then Present
(Full_View
(Typ
))
1315 return Nearest_Ancestor
(Full_View
(Typ
));
1317 -- Otherwise, nothing useful to return, return Empty
1322 end Nearest_Ancestor
;
1324 ---------------------------
1325 -- Nearest_Dynamic_Scope --
1326 ---------------------------
1328 function Nearest_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
1330 if Is_Dynamic_Scope
(Ent
) then
1333 return Enclosing_Dynamic_Scope
(Ent
);
1335 end Nearest_Dynamic_Scope
;
1337 ------------------------
1338 -- Next_Tag_Component --
1339 ------------------------
1341 function Next_Tag_Component
(Tag
: Entity_Id
) return Entity_Id
is
1345 pragma Assert
(Is_Tag
(Tag
));
1347 -- Loop to look for next tag component
1349 Comp
:= Next_Entity
(Tag
);
1350 while Present
(Comp
) loop
1351 if Is_Tag
(Comp
) then
1352 pragma Assert
(Chars
(Comp
) /= Name_uTag
);
1356 Comp
:= Next_Entity
(Comp
);
1359 -- No tag component found
1362 end Next_Tag_Component
;
1364 --------------------------
1365 -- Number_Discriminants --
1366 --------------------------
1368 function Number_Discriminants
(Typ
: Entity_Id
) return Pos
is
1374 Discr
:= First_Discriminant
(Typ
);
1375 while Present
(Discr
) loop
1377 Discr
:= Next_Discriminant
(Discr
);
1381 end Number_Discriminants
;
1383 ----------------------------------------------
1384 -- Object_Type_Has_Constrained_Partial_View --
1385 ----------------------------------------------
1387 function Object_Type_Has_Constrained_Partial_View
1389 Scop
: Entity_Id
) return Boolean
1392 return Has_Constrained_Partial_View
(Typ
)
1393 or else (In_Generic_Body
(Scop
)
1394 and then Is_Generic_Type
(Base_Type
(Typ
))
1395 and then Is_Private_Type
(Base_Type
(Typ
))
1396 and then not Is_Tagged_Type
(Typ
)
1397 and then not (Is_Array_Type
(Typ
)
1398 and then not Is_Constrained
(Typ
))
1399 and then Has_Discriminants
(Typ
));
1400 end Object_Type_Has_Constrained_Partial_View
;
1402 ---------------------------
1403 -- Package_Specification --
1404 ---------------------------
1406 function Package_Specification
(Pack_Id
: Entity_Id
) return Node_Id
is
1410 N
:= Parent
(Pack_Id
);
1411 while Nkind
(N
) /= N_Package_Specification
loop
1415 raise Program_Error
;
1420 end Package_Specification
;
1426 procedure Tree_Read
is
1428 Obsolescent_Warnings
.Tree_Read
;
1435 procedure Tree_Write
is
1437 Obsolescent_Warnings
.Tree_Write
;
1440 --------------------
1441 -- Ultimate_Alias --
1442 --------------------
1444 function Ultimate_Alias
(Prim
: Entity_Id
) return Entity_Id
is
1445 E
: Entity_Id
:= Prim
;
1448 while Present
(Alias
(E
)) loop
1449 pragma Assert
(Alias
(E
) /= E
);
1456 --------------------------
1457 -- Unit_Declaration_Node --
1458 --------------------------
1460 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
1461 N
: Node_Id
:= Parent
(Unit_Id
);
1464 -- Predefined operators do not have a full function declaration
1466 if Ekind
(Unit_Id
) = E_Operator
then
1470 -- Isn't there some better way to express the following ???
1472 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
1473 and then Nkind
(N
) /= N_Formal_Package_Declaration
1474 and then Nkind
(N
) /= N_Function_Instantiation
1475 and then Nkind
(N
) /= N_Generic_Package_Declaration
1476 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
1477 and then Nkind
(N
) /= N_Package_Declaration
1478 and then Nkind
(N
) /= N_Package_Body
1479 and then Nkind
(N
) /= N_Package_Instantiation
1480 and then Nkind
(N
) /= N_Package_Renaming_Declaration
1481 and then Nkind
(N
) /= N_Procedure_Instantiation
1482 and then Nkind
(N
) /= N_Protected_Body
1483 and then Nkind
(N
) /= N_Subprogram_Declaration
1484 and then Nkind
(N
) /= N_Subprogram_Body
1485 and then Nkind
(N
) /= N_Subprogram_Body_Stub
1486 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
1487 and then Nkind
(N
) /= N_Task_Body
1488 and then Nkind
(N
) /= N_Task_Type_Declaration
1489 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
1490 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
1494 -- We don't use Assert here, because that causes an infinite loop
1495 -- when assertions are turned off. Better to crash.
1498 raise Program_Error
;
1503 end Unit_Declaration_Node
;