1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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)
286 ----------------------------------------
287 -- Has_Completely_Hidden_Discriminant --
288 ----------------------------------------
290 function Has_Completely_Hidden_Discriminant
291 (Typ
: Entity_Id
) return Boolean
296 pragma Assert
(Ekind
(Typ
) = E_Discriminant
);
299 while Present
(Ent
) and then Ekind
(Ent
) = E_Discriminant
loop
300 if Is_Completely_Hidden
(Ent
) then
304 Ent
:= Next_Entity
(Ent
);
308 end Has_Completely_Hidden_Discriminant
;
310 -- Start of processing for First_Stored_Discriminant
314 (Has_Discriminants
(Typ
)
315 or else Has_Unknown_Discriminants
(Typ
));
317 Ent
:= First_Entity
(Typ
);
319 if Chars
(Ent
) = Name_uTag
then
320 Ent
:= Next_Entity
(Ent
);
323 if Has_Completely_Hidden_Discriminant
(Ent
) then
324 while Present
(Ent
) loop
325 exit when Is_Completely_Hidden
(Ent
);
326 Ent
:= Next_Entity
(Ent
);
330 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
333 end First_Stored_Discriminant
;
339 function First_Subtype
(Typ
: Entity_Id
) return Entity_Id
is
340 B
: constant Entity_Id
:= Base_Type
(Typ
);
341 F
: constant Node_Id
:= Freeze_Node
(B
);
345 -- If the base type has no freeze node, it is a type in Standard, and
346 -- always acts as its own first subtype, except where it is one of the
347 -- predefined integer types. If the type is formal, it is also a first
348 -- subtype, and its base type has no freeze node. On the other hand, a
349 -- subtype of a generic formal is not its own first subtype. Its base
350 -- type, if anonymous, is attached to the formal type decl. from which
351 -- the first subtype is obtained.
354 if B
= Base_Type
(Standard_Integer
) then
355 return Standard_Integer
;
357 elsif B
= Base_Type
(Standard_Long_Integer
) then
358 return Standard_Long_Integer
;
360 elsif B
= Base_Type
(Standard_Short_Short_Integer
) then
361 return Standard_Short_Short_Integer
;
363 elsif B
= Base_Type
(Standard_Short_Integer
) then
364 return Standard_Short_Integer
;
366 elsif B
= Base_Type
(Standard_Long_Long_Integer
) then
367 return Standard_Long_Long_Integer
;
369 elsif Is_Generic_Type
(Typ
) then
370 if Present
(Parent
(B
)) then
371 return Defining_Identifier
(Parent
(B
));
373 return Defining_Identifier
(Associated_Node_For_Itype
(B
));
380 -- Otherwise we check the freeze node, if it has a First_Subtype_Link
381 -- then we use that link, otherwise (happens with some Itypes), we use
382 -- the base type itself.
385 Ent
:= First_Subtype_Link
(F
);
387 if Present
(Ent
) then
395 -------------------------
396 -- First_Tag_Component --
397 -------------------------
399 function First_Tag_Component
(Typ
: Entity_Id
) return Entity_Id
is
405 pragma Assert
(Is_Tagged_Type
(Ctyp
));
407 if Is_Class_Wide_Type
(Ctyp
) then
408 Ctyp
:= Root_Type
(Ctyp
);
411 if Is_Private_Type
(Ctyp
) then
412 Ctyp
:= Underlying_Type
(Ctyp
);
414 -- If the underlying type is missing then the source program has
415 -- errors and there is nothing else to do (the full-type declaration
416 -- associated with the private type declaration is missing).
423 Comp
:= First_Entity
(Ctyp
);
424 while Present
(Comp
) loop
425 if Is_Tag
(Comp
) then
429 Comp
:= Next_Entity
(Comp
);
432 -- No tag component found
435 end First_Tag_Component
;
437 ---------------------
438 -- Get_Binary_Nkind --
439 ---------------------
441 function Get_Binary_Nkind
(Op
: Entity_Id
) return Node_Kind
is
446 when Name_Op_Concat
=>
448 when Name_Op_Expon
=>
450 when Name_Op_Subtract
=>
451 return N_Op_Subtract
;
454 when Name_Op_Multiply
=>
455 return N_Op_Multiply
;
456 when Name_Op_Divide
=>
481 end Get_Binary_Nkind
;
487 function Get_Rep_Item
490 Check_Parents
: Boolean := True) return Node_Id
495 N
:= First_Rep_Item
(E
);
496 while Present
(N
) loop
498 -- Only one of Priority / Interrupt_Priority can be specified, so
499 -- return whichever one is present to catch illegal duplication.
501 if Nkind
(N
) = N_Pragma
503 (Pragma_Name
(N
) = Nam
504 or else (Nam
= Name_Priority
505 and then Pragma_Name
(N
) = Name_Interrupt_Priority
)
506 or else (Nam
= Name_Interrupt_Priority
507 and then Pragma_Name
(N
) = Name_Priority
))
509 if Check_Parents
then
512 -- If Check_Parents is False, return N if the pragma doesn't
513 -- appear in the Rep_Item chain of the parent.
517 Par
: constant Entity_Id
:= Nearest_Ancestor
(E
);
518 -- This node represents the parent type of type E (if any)
524 elsif not Present_In_Rep_Item
(Par
, N
) then
530 elsif Nkind
(N
) = N_Attribute_Definition_Clause
533 or else (Nam
= Name_Priority
534 and then Chars
(N
) = Name_Interrupt_Priority
))
536 if Check_Parents
or else Entity
(N
) = E
then
540 elsif Nkind
(N
) = N_Aspect_Specification
542 (Chars
(Identifier
(N
)) = Nam
545 and then Chars
(Identifier
(N
)) = Name_Interrupt_Priority
))
547 if Check_Parents
then
550 elsif Entity
(N
) = E
then
561 function Get_Rep_Item
565 Check_Parents
: Boolean := True) return Node_Id
567 Nam1_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam1
, Check_Parents
);
568 Nam2_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam2
, Check_Parents
);
573 -- Check both Nam1_Item and Nam2_Item are present
575 if No
(Nam1_Item
) then
577 elsif No
(Nam2_Item
) then
581 -- Return the first node encountered in the list
583 N
:= First_Rep_Item
(E
);
584 while Present
(N
) loop
585 if N
= Nam1_Item
or else N
= Nam2_Item
then
599 function Get_Rep_Pragma
602 Check_Parents
: Boolean := True) return Node_Id
607 N
:= Get_Rep_Item
(E
, Nam
, Check_Parents
);
609 if Present
(N
) and then Nkind
(N
) = N_Pragma
then
616 function Get_Rep_Pragma
620 Check_Parents
: Boolean := True) return Node_Id
622 Nam1_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam1
, Check_Parents
);
623 Nam2_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam2
, Check_Parents
);
628 -- Check both Nam1_Item and Nam2_Item are present
630 if No
(Nam1_Item
) then
632 elsif No
(Nam2_Item
) then
636 -- Return the first node encountered in the list
638 N
:= First_Rep_Item
(E
);
639 while Present
(N
) loop
640 if N
= Nam1_Item
or else N
= Nam2_Item
then
650 ---------------------
651 -- Get_Unary_Nkind --
652 ---------------------
654 function Get_Unary_Nkind
(Op
: Entity_Id
) return Node_Kind
is
659 when Name_Op_Subtract
=>
670 ---------------------------------
671 -- Has_External_Tag_Rep_Clause --
672 ---------------------------------
674 function Has_External_Tag_Rep_Clause
(T
: Entity_Id
) return Boolean is
676 pragma Assert
(Is_Tagged_Type
(T
));
677 return Has_Rep_Item
(T
, Name_External_Tag
, Check_Parents
=> False);
678 end Has_External_Tag_Rep_Clause
;
684 function Has_Rep_Item
687 Check_Parents
: Boolean := True) return Boolean
690 return Present
(Get_Rep_Item
(E
, Nam
, Check_Parents
));
693 function Has_Rep_Item
697 Check_Parents
: Boolean := True) return Boolean
700 return Present
(Get_Rep_Item
(E
, Nam1
, Nam2
, Check_Parents
));
707 function Has_Rep_Pragma
710 Check_Parents
: Boolean := True) return Boolean
713 return Present
(Get_Rep_Pragma
(E
, Nam
, Check_Parents
));
716 function Has_Rep_Pragma
720 Check_Parents
: Boolean := True) return Boolean
723 return Present
(Get_Rep_Pragma
(E
, Nam1
, Nam2
, Check_Parents
));
726 --------------------------------
727 -- Has_Unconstrained_Elements --
728 --------------------------------
730 function Has_Unconstrained_Elements
(T
: Entity_Id
) return Boolean is
731 U_T
: constant Entity_Id
:= Underlying_Type
(T
);
735 elsif Is_Record_Type
(U_T
) then
736 return Has_Discriminants
(U_T
) and then not Is_Constrained
(U_T
);
737 elsif Is_Array_Type
(U_T
) then
738 return Has_Unconstrained_Elements
(Component_Type
(U_T
));
742 end Has_Unconstrained_Elements
;
744 ----------------------
745 -- Has_Variant_Part --
746 ----------------------
748 function Has_Variant_Part
(Typ
: Entity_Id
) return Boolean is
755 if not Is_Type
(Typ
) then
759 FSTyp
:= First_Subtype
(Typ
);
761 if not Has_Discriminants
(FSTyp
) then
765 -- Proceed with cautious checks here, return False if tree is not
766 -- as expected (may be caused by prior errors).
768 Decl
:= Declaration_Node
(FSTyp
);
770 if Nkind
(Decl
) /= N_Full_Type_Declaration
then
774 TDef
:= Type_Definition
(Decl
);
776 if Nkind
(TDef
) /= N_Record_Definition
then
780 CList
:= Component_List
(TDef
);
782 if Nkind
(CList
) /= N_Component_List
then
785 return Present
(Variant_Part
(CList
));
787 end Has_Variant_Part
;
789 ---------------------
790 -- In_Generic_Body --
791 ---------------------
793 function In_Generic_Body
(Id
: Entity_Id
) return Boolean is
797 -- Climb scopes looking for generic body
800 while Present
(S
) and then S
/= Standard_Standard
loop
802 -- Generic package body
804 if Ekind
(S
) = E_Generic_Package
805 and then In_Package_Body
(S
)
809 -- Generic subprogram body
811 elsif Is_Subprogram
(S
)
812 and then Nkind
(Unit_Declaration_Node
(S
))
813 = N_Generic_Subprogram_Declaration
821 -- False if top of scope stack without finding a generic body
826 -------------------------------
827 -- Initialization_Suppressed --
828 -------------------------------
830 function Initialization_Suppressed
(Typ
: Entity_Id
) return Boolean is
832 return Suppress_Initialization
(Typ
)
833 or else Suppress_Initialization
(Base_Type
(Typ
));
834 end Initialization_Suppressed
;
840 procedure Initialize
is
842 Obsolescent_Warnings
.Init
;
849 function Is_Body
(N
: Node_Id
) return Boolean is
852 Nkind
(N
) in N_Body_Stub
853 or else Nkind_In
(N
, N_Entry_Body
,
860 ---------------------
861 -- Is_By_Copy_Type --
862 ---------------------
864 function Is_By_Copy_Type
(Ent
: Entity_Id
) return Boolean is
866 -- If Id is a private type whose full declaration has not been seen,
867 -- we assume for now that it is not a By_Copy type. Clearly this
868 -- attribute should not be used before the type is frozen, but it is
869 -- needed to build the associated record of a protected type. Another
870 -- place where some lookahead for a full view is needed ???
873 Is_Elementary_Type
(Ent
)
874 or else (Is_Private_Type
(Ent
)
875 and then Present
(Underlying_Type
(Ent
))
876 and then Is_Elementary_Type
(Underlying_Type
(Ent
)));
879 --------------------------
880 -- Is_By_Reference_Type --
881 --------------------------
883 function Is_By_Reference_Type
(Ent
: Entity_Id
) return Boolean is
884 Btype
: constant Entity_Id
:= Base_Type
(Ent
);
887 if Error_Posted
(Ent
) or else Error_Posted
(Btype
) then
890 elsif Is_Private_Type
(Btype
) then
892 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
897 return Is_By_Reference_Type
(Utyp
);
901 elsif Is_Incomplete_Type
(Btype
) then
903 Ftyp
: constant Entity_Id
:= Full_View
(Btype
);
908 return Is_By_Reference_Type
(Ftyp
);
912 elsif Is_Concurrent_Type
(Btype
) then
915 elsif Is_Record_Type
(Btype
) then
916 if Is_Limited_Record
(Btype
)
917 or else Is_Tagged_Type
(Btype
)
918 or else Is_Volatile
(Btype
)
927 C
:= First_Component
(Btype
);
928 while Present
(C
) loop
930 -- For each component, test if its type is a by reference
931 -- type and if its type is volatile. Also test the component
932 -- itself for being volatile. This happens for example when
933 -- a Volatile aspect is added to a component.
935 if Is_By_Reference_Type
(Etype
(C
))
936 or else Is_Volatile
(Etype
(C
))
937 or else Is_Volatile
(C
)
942 C
:= Next_Component
(C
);
949 elsif Is_Array_Type
(Btype
) then
952 or else Is_By_Reference_Type
(Component_Type
(Btype
))
953 or else Is_Volatile
(Component_Type
(Btype
))
954 or else Has_Volatile_Components
(Btype
);
959 end Is_By_Reference_Type
;
961 ---------------------
962 -- Is_Derived_Type --
963 ---------------------
965 function Is_Derived_Type
(Ent
: E
) return B
is
970 and then Base_Type
(Ent
) /= Root_Type
(Ent
)
971 and then not Is_Class_Wide_Type
(Ent
)
973 if not Is_Numeric_Type
(Root_Type
(Ent
)) then
977 Par
:= Parent
(First_Subtype
(Ent
));
980 and then Nkind
(Par
) = N_Full_Type_Declaration
981 and then Nkind
(Type_Definition
(Par
)) =
982 N_Derived_Type_Definition
;
990 -----------------------
991 -- Is_Generic_Formal --
992 -----------------------
994 function Is_Generic_Formal
(E
: Entity_Id
) return Boolean is
1000 Kind
:= Nkind
(Parent
(E
));
1002 Nkind_In
(Kind
, N_Formal_Object_Declaration
,
1003 N_Formal_Package_Declaration
,
1004 N_Formal_Type_Declaration
)
1005 or else Is_Formal_Subprogram
(E
);
1007 end Is_Generic_Formal
;
1009 -------------------------------
1010 -- Is_Immutably_Limited_Type --
1011 -------------------------------
1013 function Is_Immutably_Limited_Type
(Ent
: Entity_Id
) return Boolean is
1014 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
1017 if Is_Limited_Record
(Btype
) then
1020 elsif Ekind
(Btype
) = E_Limited_Private_Type
1021 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
1023 return not In_Package_Body
(Scope
((Btype
)));
1025 elsif Is_Private_Type
(Btype
) then
1027 -- AI05-0063: A type derived from a limited private formal type is
1028 -- not immutably limited in a generic body.
1030 if Is_Derived_Type
(Btype
)
1031 and then Is_Generic_Type
(Etype
(Btype
))
1033 if not Is_Limited_Type
(Etype
(Btype
)) then
1036 -- A descendant of a limited formal type is not immutably limited
1037 -- in the generic body, or in the body of a generic child.
1039 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
1040 return not In_Package_Body
(Scope
(Btype
));
1048 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
1053 return Is_Immutably_Limited_Type
(Utyp
);
1058 elsif Is_Concurrent_Type
(Btype
) then
1064 end Is_Immutably_Limited_Type
;
1066 ---------------------------
1067 -- Is_Indefinite_Subtype --
1068 ---------------------------
1070 function Is_Indefinite_Subtype
(Ent
: Entity_Id
) return Boolean is
1071 K
: constant Entity_Kind
:= Ekind
(Ent
);
1074 if Is_Constrained
(Ent
) then
1077 elsif K
in Array_Kind
1078 or else K
in Class_Wide_Kind
1079 or else Has_Unknown_Discriminants
(Ent
)
1083 -- Known discriminants: indefinite if there are no default values
1085 elsif K
in Record_Kind
1086 or else Is_Incomplete_Or_Private_Type
(Ent
)
1087 or else Is_Concurrent_Type
(Ent
)
1089 return (Has_Discriminants
(Ent
)
1091 No
(Discriminant_Default_Value
(First_Discriminant
(Ent
))));
1096 end Is_Indefinite_Subtype
;
1098 ---------------------
1099 -- Is_Limited_Type --
1100 ---------------------
1102 function Is_Limited_Type
(Ent
: Entity_Id
) return Boolean is
1103 Btype
: constant E
:= Base_Type
(Ent
);
1104 Rtype
: constant E
:= Root_Type
(Btype
);
1107 if not Is_Type
(Ent
) then
1110 elsif Ekind
(Btype
) = E_Limited_Private_Type
1111 or else Is_Limited_Composite
(Btype
)
1115 elsif Is_Concurrent_Type
(Btype
) then
1118 -- The Is_Limited_Record flag normally indicates that the type is
1119 -- limited. The exception is that a type does not inherit limitedness
1120 -- from its interface ancestor. So the type may be derived from a
1121 -- limited interface, but is not limited.
1123 elsif Is_Limited_Record
(Ent
)
1124 and then not Is_Interface
(Ent
)
1128 -- Otherwise we will look around to see if there is some other reason
1129 -- for it to be limited, except that if an error was posted on the
1130 -- entity, then just assume it is non-limited, because it can cause
1131 -- trouble to recurse into a murky entity resulting from other errors.
1133 elsif Error_Posted
(Ent
) then
1136 elsif Is_Record_Type
(Btype
) then
1138 if Is_Limited_Interface
(Ent
) then
1141 -- AI-419: limitedness is not inherited from a limited interface
1143 elsif Is_Limited_Record
(Rtype
) then
1144 return not Is_Interface
(Rtype
)
1145 or else Is_Protected_Interface
(Rtype
)
1146 or else Is_Synchronized_Interface
(Rtype
)
1147 or else Is_Task_Interface
(Rtype
);
1149 elsif Is_Class_Wide_Type
(Btype
) then
1150 return Is_Limited_Type
(Rtype
);
1157 C
:= First_Component
(Btype
);
1158 while Present
(C
) loop
1159 if Is_Limited_Type
(Etype
(C
)) then
1163 C
:= Next_Component
(C
);
1170 elsif Is_Array_Type
(Btype
) then
1171 return Is_Limited_Type
(Component_Type
(Btype
));
1176 end Is_Limited_Type
;
1178 ---------------------
1179 -- Is_Limited_View --
1180 ---------------------
1182 function Is_Limited_View
(Ent
: Entity_Id
) return Boolean is
1183 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
1186 if Is_Limited_Record
(Btype
) then
1189 elsif Ekind
(Btype
) = E_Limited_Private_Type
1190 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
1192 return not In_Package_Body
(Scope
((Btype
)));
1194 elsif Is_Private_Type
(Btype
) then
1196 -- AI05-0063: A type derived from a limited private formal type is
1197 -- not immutably limited in a generic body.
1199 if Is_Derived_Type
(Btype
)
1200 and then Is_Generic_Type
(Etype
(Btype
))
1202 if not Is_Limited_Type
(Etype
(Btype
)) then
1205 -- A descendant of a limited formal type is not immutably limited
1206 -- in the generic body, or in the body of a generic child.
1208 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
1209 return not In_Package_Body
(Scope
(Btype
));
1217 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
1222 return Is_Limited_View
(Utyp
);
1227 elsif Is_Concurrent_Type
(Btype
) then
1230 elsif Is_Record_Type
(Btype
) then
1232 -- Note that we return True for all limited interfaces, even though
1233 -- (unsynchronized) limited interfaces can have descendants that are
1234 -- nonlimited, because this is a predicate on the type itself, and
1235 -- things like functions with limited interface results need to be
1236 -- handled as build in place even though they might return objects
1237 -- of a type that is not inherently limited.
1239 if Is_Class_Wide_Type
(Btype
) then
1240 return Is_Limited_View
(Root_Type
(Btype
));
1247 C
:= First_Component
(Btype
);
1248 while Present
(C
) loop
1250 -- Don't consider components with interface types (which can
1251 -- only occur in the case of a _parent component anyway).
1252 -- They don't have any components, plus it would cause this
1253 -- function to return true for nonlimited types derived from
1254 -- limited interfaces.
1256 if not Is_Interface
(Etype
(C
))
1257 and then Is_Limited_View
(Etype
(C
))
1262 C
:= Next_Component
(C
);
1269 elsif Is_Array_Type
(Btype
) then
1270 return Is_Limited_View
(Component_Type
(Btype
));
1275 end Is_Limited_View
;
1277 ----------------------
1278 -- Nearest_Ancestor --
1279 ----------------------
1281 function Nearest_Ancestor
(Typ
: Entity_Id
) return Entity_Id
is
1282 D
: constant Node_Id
:= Declaration_Node
(Typ
);
1285 -- If we have a subtype declaration, get the ancestor subtype
1287 if Nkind
(D
) = N_Subtype_Declaration
then
1288 if Nkind
(Subtype_Indication
(D
)) = N_Subtype_Indication
then
1289 return Entity
(Subtype_Mark
(Subtype_Indication
(D
)));
1291 return Entity
(Subtype_Indication
(D
));
1294 -- If derived type declaration, find who we are derived from
1296 elsif Nkind
(D
) = N_Full_Type_Declaration
1297 and then Nkind
(Type_Definition
(D
)) = N_Derived_Type_Definition
1300 DTD
: constant Entity_Id
:= Type_Definition
(D
);
1301 SI
: constant Entity_Id
:= Subtype_Indication
(DTD
);
1303 if Is_Entity_Name
(SI
) then
1306 return Entity
(Subtype_Mark
(SI
));
1310 -- If derived type and private type, get the full view to find who we
1311 -- are derived from.
1313 elsif Is_Derived_Type
(Typ
)
1314 and then Is_Private_Type
(Typ
)
1315 and then Present
(Full_View
(Typ
))
1317 return Nearest_Ancestor
(Full_View
(Typ
));
1319 -- Otherwise, nothing useful to return, return Empty
1324 end Nearest_Ancestor
;
1326 ---------------------------
1327 -- Nearest_Dynamic_Scope --
1328 ---------------------------
1330 function Nearest_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
1332 if Is_Dynamic_Scope
(Ent
) then
1335 return Enclosing_Dynamic_Scope
(Ent
);
1337 end Nearest_Dynamic_Scope
;
1339 ------------------------
1340 -- Next_Tag_Component --
1341 ------------------------
1343 function Next_Tag_Component
(Tag
: Entity_Id
) return Entity_Id
is
1347 pragma Assert
(Is_Tag
(Tag
));
1349 -- Loop to look for next tag component
1351 Comp
:= Next_Entity
(Tag
);
1352 while Present
(Comp
) loop
1353 if Is_Tag
(Comp
) then
1354 pragma Assert
(Chars
(Comp
) /= Name_uTag
);
1358 Comp
:= Next_Entity
(Comp
);
1361 -- No tag component found
1364 end Next_Tag_Component
;
1366 --------------------------
1367 -- Number_Discriminants --
1368 --------------------------
1370 function Number_Discriminants
(Typ
: Entity_Id
) return Pos
is
1376 Discr
:= First_Discriminant
(Typ
);
1377 while Present
(Discr
) loop
1379 Discr
:= Next_Discriminant
(Discr
);
1383 end Number_Discriminants
;
1385 ----------------------------------------------
1386 -- Object_Type_Has_Constrained_Partial_View --
1387 ----------------------------------------------
1389 function Object_Type_Has_Constrained_Partial_View
1391 Scop
: Entity_Id
) return Boolean
1394 return Has_Constrained_Partial_View
(Typ
)
1395 or else (In_Generic_Body
(Scop
)
1396 and then Is_Generic_Type
(Base_Type
(Typ
))
1397 and then Is_Private_Type
(Base_Type
(Typ
))
1398 and then not Is_Tagged_Type
(Typ
)
1399 and then not (Is_Array_Type
(Typ
)
1400 and then not Is_Constrained
(Typ
))
1401 and then Has_Discriminants
(Typ
));
1402 end Object_Type_Has_Constrained_Partial_View
;
1404 ---------------------------
1405 -- Package_Specification --
1406 ---------------------------
1408 function Package_Specification
(Pack_Id
: Entity_Id
) return Node_Id
is
1412 N
:= Parent
(Pack_Id
);
1413 while Nkind
(N
) /= N_Package_Specification
loop
1417 raise Program_Error
;
1422 end Package_Specification
;
1428 procedure Tree_Read
is
1430 Obsolescent_Warnings
.Tree_Read
;
1437 procedure Tree_Write
is
1439 Obsolescent_Warnings
.Tree_Write
;
1442 --------------------
1443 -- Ultimate_Alias --
1444 --------------------
1446 function Ultimate_Alias
(Prim
: Entity_Id
) return Entity_Id
is
1447 E
: Entity_Id
:= Prim
;
1450 while Present
(Alias
(E
)) loop
1451 pragma Assert
(Alias
(E
) /= E
);
1458 --------------------------
1459 -- Unit_Declaration_Node --
1460 --------------------------
1462 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
1463 N
: Node_Id
:= Parent
(Unit_Id
);
1466 -- Predefined operators do not have a full function declaration
1468 if Ekind
(Unit_Id
) = E_Operator
then
1472 -- Isn't there some better way to express the following ???
1474 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
1475 and then Nkind
(N
) /= N_Formal_Package_Declaration
1476 and then Nkind
(N
) /= N_Function_Instantiation
1477 and then Nkind
(N
) /= N_Generic_Package_Declaration
1478 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
1479 and then Nkind
(N
) /= N_Package_Declaration
1480 and then Nkind
(N
) /= N_Package_Body
1481 and then Nkind
(N
) /= N_Package_Instantiation
1482 and then Nkind
(N
) /= N_Package_Renaming_Declaration
1483 and then Nkind
(N
) /= N_Procedure_Instantiation
1484 and then Nkind
(N
) /= N_Protected_Body
1485 and then Nkind
(N
) /= N_Subprogram_Declaration
1486 and then Nkind
(N
) /= N_Subprogram_Body
1487 and then Nkind
(N
) /= N_Subprogram_Body_Stub
1488 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
1489 and then Nkind
(N
) /= N_Task_Body
1490 and then Nkind
(N
) /= N_Task_Type_Declaration
1491 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
1492 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
1496 -- We don't use Assert here, because that causes an infinite loop
1497 -- when assertions are turned off. Better to crash.
1500 raise Program_Error
;
1505 end Unit_Declaration_Node
;