1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- As a special exception, if other files instantiate generics from this --
22 -- unit, or you link this unit with other files to produce an executable, --
23 -- this unit does not by itself cause the resulting executable to be --
24 -- covered by the GNU General Public License. This exception does not --
25 -- however invalidate any other reasons why the executable file might be --
26 -- covered by the GNU Public License. --
28 -- GNAT was originally developed by the GNAT team at New York University. --
29 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 ------------------------------------------------------------------------------
33 with Atree
; use Atree
;
34 with Einfo
; use Einfo
;
35 with Sinfo
; use Sinfo
;
36 with Snames
; use Snames
;
37 with Stand
; use Stand
;
39 package body Sem_Aux
is
41 ----------------------
42 -- Ancestor_Subtype --
43 ----------------------
45 function Ancestor_Subtype
(Typ
: Entity_Id
) return Entity_Id
is
47 -- If this is first subtype, or is a base type, then there is no
48 -- ancestor subtype, so we return Empty to indicate this fact.
50 if Is_First_Subtype
(Typ
) or else Is_Base_Type
(Typ
) then
55 D
: constant Node_Id
:= Declaration_Node
(Typ
);
58 -- If we have a subtype declaration, get the ancestor subtype
60 if Nkind
(D
) = N_Subtype_Declaration
then
61 if Nkind
(Subtype_Indication
(D
)) = N_Subtype_Indication
then
62 return Entity
(Subtype_Mark
(Subtype_Indication
(D
)));
64 return Entity
(Subtype_Indication
(D
));
67 -- If not, then no subtype indication is available
79 function Available_View
(Typ
: Entity_Id
) return Entity_Id
is
81 if Is_Incomplete_Type
(Typ
)
82 and then Present
(Non_Limited_View
(Typ
))
84 -- The non-limited view may itself be an incomplete type, in which
85 -- case get its full view.
87 return Get_Full_View
(Non_Limited_View
(Typ
));
89 -- If it is class_wide, check whether the specific type comes from
92 elsif Is_Class_Wide_Type
(Typ
)
93 and then Is_Incomplete_Type
(Etype
(Typ
))
94 and then From_Limited_With
(Etype
(Typ
))
95 and then Present
(Non_Limited_View
(Etype
(Typ
)))
97 return Class_Wide_Type
(Non_Limited_View
(Etype
(Typ
)));
108 function Constant_Value
(Ent
: Entity_Id
) return Node_Id
is
109 D
: constant Node_Id
:= Declaration_Node
(Ent
);
113 -- If we have no declaration node, then return no constant value. Not
114 -- clear how this can happen, but it does sometimes and this is the
120 -- Normal case where a declaration node is present
122 elsif Nkind
(D
) = N_Object_Renaming_Declaration
then
123 return Renamed_Object
(Ent
);
125 -- If this is a component declaration whose entity is a constant, it is
126 -- a prival within a protected function (and so has no constant value).
128 elsif Nkind
(D
) = N_Component_Declaration
then
131 -- If there is an expression, return it
133 elsif Present
(Expression
(D
)) then
134 return (Expression
(D
));
136 -- For a constant, see if we have a full view
138 elsif Ekind
(Ent
) = E_Constant
139 and then Present
(Full_View
(Ent
))
141 Full_D
:= Parent
(Full_View
(Ent
));
143 -- The full view may have been rewritten as an object renaming
145 if Nkind
(Full_D
) = N_Object_Renaming_Declaration
then
146 return Name
(Full_D
);
148 return Expression
(Full_D
);
151 -- Otherwise we have no expression to return
158 -----------------------------
159 -- Enclosing_Dynamic_Scope --
160 -----------------------------
162 function Enclosing_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
166 -- The following test is an error defense against some syntax errors
167 -- that can leave scopes very messed up.
169 if Ent
= Standard_Standard
then
173 -- Normal case, search enclosing scopes
175 -- Note: the test for Present (S) should not be required, it defends
176 -- against an ill-formed tree.
180 -- If we somehow got an empty value for Scope, the tree must be
181 -- malformed. Rather than blow up we return Standard in this case.
184 return Standard_Standard
;
186 -- Quit if we get to standard or a dynamic scope. We must also
187 -- handle enclosing scopes that have a full view; required to
188 -- locate enclosing scopes that are synchronized private types
189 -- whose full view is a task type.
191 elsif S
= Standard_Standard
192 or else Is_Dynamic_Scope
(S
)
193 or else (Is_Private_Type
(S
)
194 and then Present
(Full_View
(S
))
195 and then Is_Dynamic_Scope
(Full_View
(S
)))
199 -- Otherwise keep climbing
205 end Enclosing_Dynamic_Scope
;
207 ------------------------
208 -- First_Discriminant --
209 ------------------------
211 function First_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
216 (Has_Discriminants
(Typ
) or else Has_Unknown_Discriminants
(Typ
));
218 Ent
:= First_Entity
(Typ
);
220 -- The discriminants are not necessarily contiguous, because access
221 -- discriminants will generate itypes. They are not the first entities
222 -- either because the tag must be ahead of them.
224 if Chars
(Ent
) = Name_uTag
then
225 Ent
:= Next_Entity
(Ent
);
228 -- Skip all hidden stored discriminants if any
230 while Present
(Ent
) loop
231 exit when Ekind
(Ent
) = E_Discriminant
232 and then not Is_Completely_Hidden
(Ent
);
234 Ent
:= Next_Entity
(Ent
);
237 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
240 end First_Discriminant
;
242 -------------------------------
243 -- First_Stored_Discriminant --
244 -------------------------------
246 function First_Stored_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
249 function Has_Completely_Hidden_Discriminant
250 (Typ
: Entity_Id
) return Boolean;
251 -- Scans the Discriminants to see whether any are Completely_Hidden
252 -- (the mechanism for describing non-specified stored discriminants)
254 ----------------------------------------
255 -- Has_Completely_Hidden_Discriminant --
256 ----------------------------------------
258 function Has_Completely_Hidden_Discriminant
259 (Typ
: Entity_Id
) return Boolean
264 pragma Assert
(Ekind
(Typ
) = E_Discriminant
);
267 while Present
(Ent
) and then Ekind
(Ent
) = E_Discriminant
loop
268 if Is_Completely_Hidden
(Ent
) then
272 Ent
:= Next_Entity
(Ent
);
276 end Has_Completely_Hidden_Discriminant
;
278 -- Start of processing for First_Stored_Discriminant
282 (Has_Discriminants
(Typ
)
283 or else Has_Unknown_Discriminants
(Typ
));
285 Ent
:= First_Entity
(Typ
);
287 if Chars
(Ent
) = Name_uTag
then
288 Ent
:= Next_Entity
(Ent
);
291 if Has_Completely_Hidden_Discriminant
(Ent
) then
292 while Present
(Ent
) loop
293 exit when Is_Completely_Hidden
(Ent
);
294 Ent
:= Next_Entity
(Ent
);
298 pragma Assert
(Ekind
(Ent
) = E_Discriminant
);
301 end First_Stored_Discriminant
;
307 function First_Subtype
(Typ
: Entity_Id
) return Entity_Id
is
308 B
: constant Entity_Id
:= Base_Type
(Typ
);
309 F
: constant Node_Id
:= Freeze_Node
(B
);
313 -- If the base type has no freeze node, it is a type in Standard, and
314 -- always acts as its own first subtype, except where it is one of the
315 -- predefined integer types. If the type is formal, it is also a first
316 -- subtype, and its base type has no freeze node. On the other hand, a
317 -- subtype of a generic formal is not its own first subtype. Its base
318 -- type, if anonymous, is attached to the formal type decl. from which
319 -- the first subtype is obtained.
322 if B
= Base_Type
(Standard_Integer
) then
323 return Standard_Integer
;
325 elsif B
= Base_Type
(Standard_Long_Integer
) then
326 return Standard_Long_Integer
;
328 elsif B
= Base_Type
(Standard_Short_Short_Integer
) then
329 return Standard_Short_Short_Integer
;
331 elsif B
= Base_Type
(Standard_Short_Integer
) then
332 return Standard_Short_Integer
;
334 elsif B
= Base_Type
(Standard_Long_Long_Integer
) then
335 return Standard_Long_Long_Integer
;
337 elsif Is_Generic_Type
(Typ
) then
338 if Present
(Parent
(B
)) then
339 return Defining_Identifier
(Parent
(B
));
341 return Defining_Identifier
(Associated_Node_For_Itype
(B
));
348 -- Otherwise we check the freeze node, if it has a First_Subtype_Link
349 -- then we use that link, otherwise (happens with some Itypes), we use
350 -- the base type itself.
353 Ent
:= First_Subtype_Link
(F
);
355 if Present
(Ent
) then
363 -------------------------
364 -- First_Tag_Component --
365 -------------------------
367 function First_Tag_Component
(Typ
: Entity_Id
) return Entity_Id
is
373 pragma Assert
(Is_Tagged_Type
(Ctyp
));
375 if Is_Class_Wide_Type
(Ctyp
) then
376 Ctyp
:= Root_Type
(Ctyp
);
379 if Is_Private_Type
(Ctyp
) then
380 Ctyp
:= Underlying_Type
(Ctyp
);
382 -- If the underlying type is missing then the source program has
383 -- errors and there is nothing else to do (the full-type declaration
384 -- associated with the private type declaration is missing).
391 Comp
:= First_Entity
(Ctyp
);
392 while Present
(Comp
) loop
393 if Is_Tag
(Comp
) then
397 Comp
:= Next_Entity
(Comp
);
400 -- No tag component found
403 end First_Tag_Component
;
409 function Get_Rep_Item
412 Check_Parents
: Boolean := True) return Node_Id
417 N
:= First_Rep_Item
(E
);
418 while Present
(N
) loop
420 -- Only one of Priority / Interrupt_Priority can be specified, so
421 -- return whichever one is present to catch illegal duplication.
423 if Nkind
(N
) = N_Pragma
425 (Pragma_Name
(N
) = Nam
426 or else (Nam
= Name_Priority
427 and then Pragma_Name
(N
) = Name_Interrupt_Priority
)
428 or else (Nam
= Name_Interrupt_Priority
429 and then Pragma_Name
(N
) = Name_Priority
))
431 if Check_Parents
then
434 -- If Check_Parents is False, return N if the pragma doesn't
435 -- appear in the Rep_Item chain of the parent.
439 Par
: constant Entity_Id
:= Nearest_Ancestor
(E
);
440 -- This node represents the parent type of type E (if any)
446 elsif not Present_In_Rep_Item
(Par
, N
) then
452 elsif Nkind
(N
) = N_Attribute_Definition_Clause
455 or else (Nam
= Name_Priority
456 and then Chars
(N
) = Name_Interrupt_Priority
))
458 if Check_Parents
or else Entity
(N
) = E
then
462 elsif Nkind
(N
) = N_Aspect_Specification
464 (Chars
(Identifier
(N
)) = Nam
467 and then Chars
(Identifier
(N
)) = Name_Interrupt_Priority
))
469 if Check_Parents
then
472 elsif Entity
(N
) = E
then
483 function Get_Rep_Item
487 Check_Parents
: Boolean := True) return Node_Id
489 Nam1_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam1
, Check_Parents
);
490 Nam2_Item
: constant Node_Id
:= Get_Rep_Item
(E
, Nam2
, Check_Parents
);
495 -- Check both Nam1_Item and Nam2_Item are present
497 if No
(Nam1_Item
) then
499 elsif No
(Nam2_Item
) then
503 -- Return the first node encountered in the list
505 N
:= First_Rep_Item
(E
);
506 while Present
(N
) loop
507 if N
= Nam1_Item
or else N
= Nam2_Item
then
521 function Get_Rep_Pragma
524 Check_Parents
: Boolean := True) return Node_Id
529 N
:= Get_Rep_Item
(E
, Nam
, Check_Parents
);
531 if Present
(N
) and then Nkind
(N
) = N_Pragma
then
538 function Get_Rep_Pragma
542 Check_Parents
: Boolean := True) return Node_Id
544 Nam1_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam1
, Check_Parents
);
545 Nam2_Item
: constant Node_Id
:= Get_Rep_Pragma
(E
, Nam2
, Check_Parents
);
550 -- Check both Nam1_Item and Nam2_Item are present
552 if No
(Nam1_Item
) then
554 elsif No
(Nam2_Item
) then
558 -- Return the first node encountered in the list
560 N
:= First_Rep_Item
(E
);
561 while Present
(N
) loop
562 if N
= Nam1_Item
or else N
= Nam2_Item
then
576 function Has_Rep_Item
579 Check_Parents
: Boolean := True) return Boolean
582 return Present
(Get_Rep_Item
(E
, Nam
, Check_Parents
));
585 function Has_Rep_Item
589 Check_Parents
: Boolean := True) return Boolean
592 return Present
(Get_Rep_Item
(E
, Nam1
, Nam2
, Check_Parents
));
599 function Has_Rep_Pragma
602 Check_Parents
: Boolean := True) return Boolean
605 return Present
(Get_Rep_Pragma
(E
, Nam
, Check_Parents
));
608 function Has_Rep_Pragma
612 Check_Parents
: Boolean := True) return Boolean
615 return Present
(Get_Rep_Pragma
(E
, Nam1
, Nam2
, Check_Parents
));
618 ---------------------
619 -- In_Generic_Body --
620 ---------------------
622 function In_Generic_Body
(Id
: Entity_Id
) return Boolean is
626 -- Climb scopes looking for generic body
629 while Present
(S
) and then S
/= Standard_Standard
loop
631 -- Generic package body
633 if Ekind
(S
) = E_Generic_Package
634 and then In_Package_Body
(S
)
638 -- Generic subprogram body
640 elsif Is_Subprogram
(S
)
641 and then Nkind
(Unit_Declaration_Node
(S
))
642 = N_Generic_Subprogram_Declaration
650 -- False if top of scope stack without finding a generic body
655 -------------------------------
656 -- Initialization_Suppressed --
657 -------------------------------
659 function Initialization_Suppressed
(Typ
: Entity_Id
) return Boolean is
661 return Suppress_Initialization
(Typ
)
662 or else Suppress_Initialization
(Base_Type
(Typ
));
663 end Initialization_Suppressed
;
669 procedure Initialize
is
671 Obsolescent_Warnings
.Init
;
674 ---------------------
675 -- Is_By_Copy_Type --
676 ---------------------
678 function Is_By_Copy_Type
(Ent
: Entity_Id
) return Boolean is
680 -- If Id is a private type whose full declaration has not been seen,
681 -- we assume for now that it is not a By_Copy type. Clearly this
682 -- attribute should not be used before the type is frozen, but it is
683 -- needed to build the associated record of a protected type. Another
684 -- place where some lookahead for a full view is needed ???
687 Is_Elementary_Type
(Ent
)
688 or else (Is_Private_Type
(Ent
)
689 and then Present
(Underlying_Type
(Ent
))
690 and then Is_Elementary_Type
(Underlying_Type
(Ent
)));
693 --------------------------
694 -- Is_By_Reference_Type --
695 --------------------------
697 function Is_By_Reference_Type
(Ent
: Entity_Id
) return Boolean is
698 Btype
: constant Entity_Id
:= Base_Type
(Ent
);
701 if Error_Posted
(Ent
) or else Error_Posted
(Btype
) then
704 elsif Is_Private_Type
(Btype
) then
706 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
711 return Is_By_Reference_Type
(Utyp
);
715 elsif Is_Incomplete_Type
(Btype
) then
717 Ftyp
: constant Entity_Id
:= Full_View
(Btype
);
722 return Is_By_Reference_Type
(Ftyp
);
726 elsif Is_Concurrent_Type
(Btype
) then
729 elsif Is_Record_Type
(Btype
) then
730 if Is_Limited_Record
(Btype
)
731 or else Is_Tagged_Type
(Btype
)
732 or else Is_Volatile
(Btype
)
741 C
:= First_Component
(Btype
);
742 while Present
(C
) loop
743 if Is_By_Reference_Type
(Etype
(C
))
744 or else Is_Volatile
(Etype
(C
))
749 C
:= Next_Component
(C
);
756 elsif Is_Array_Type
(Btype
) then
759 or else Is_By_Reference_Type
(Component_Type
(Btype
))
760 or else Is_Volatile
(Component_Type
(Btype
))
761 or else Has_Volatile_Components
(Btype
);
766 end Is_By_Reference_Type
;
768 ---------------------
769 -- Is_Derived_Type --
770 ---------------------
772 function Is_Derived_Type
(Ent
: E
) return B
is
777 and then Base_Type
(Ent
) /= Root_Type
(Ent
)
778 and then not Is_Class_Wide_Type
(Ent
)
780 if not Is_Numeric_Type
(Root_Type
(Ent
)) then
784 Par
:= Parent
(First_Subtype
(Ent
));
787 and then Nkind
(Par
) = N_Full_Type_Declaration
788 and then Nkind
(Type_Definition
(Par
)) =
789 N_Derived_Type_Definition
;
797 -----------------------
798 -- Is_Generic_Formal --
799 -----------------------
801 function Is_Generic_Formal
(E
: Entity_Id
) return Boolean is
807 Kind
:= Nkind
(Parent
(E
));
809 Nkind_In
(Kind
, N_Formal_Object_Declaration
,
810 N_Formal_Package_Declaration
,
811 N_Formal_Type_Declaration
)
812 or else Is_Formal_Subprogram
(E
);
814 end Is_Generic_Formal
;
816 -------------------------------
817 -- Is_Immutably_Limited_Type --
818 -------------------------------
820 function Is_Immutably_Limited_Type
(Ent
: Entity_Id
) return Boolean is
821 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
824 if Is_Limited_Record
(Btype
) then
827 elsif Ekind
(Btype
) = E_Limited_Private_Type
828 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
830 return not In_Package_Body
(Scope
((Btype
)));
832 elsif Is_Private_Type
(Btype
) then
834 -- AI05-0063: A type derived from a limited private formal type is
835 -- not immutably limited in a generic body.
837 if Is_Derived_Type
(Btype
)
838 and then Is_Generic_Type
(Etype
(Btype
))
840 if not Is_Limited_Type
(Etype
(Btype
)) then
843 -- A descendant of a limited formal type is not immutably limited
844 -- in the generic body, or in the body of a generic child.
846 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
847 return not In_Package_Body
(Scope
(Btype
));
855 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
860 return Is_Immutably_Limited_Type
(Utyp
);
865 elsif Is_Concurrent_Type
(Btype
) then
871 end Is_Immutably_Limited_Type
;
873 ---------------------------
874 -- Is_Indefinite_Subtype --
875 ---------------------------
877 function Is_Indefinite_Subtype
(Ent
: Entity_Id
) return Boolean is
878 K
: constant Entity_Kind
:= Ekind
(Ent
);
881 if Is_Constrained
(Ent
) then
884 elsif K
in Array_Kind
885 or else K
in Class_Wide_Kind
886 or else Has_Unknown_Discriminants
(Ent
)
890 -- Known discriminants: indefinite if there are no default values
892 elsif K
in Record_Kind
893 or else Is_Incomplete_Or_Private_Type
(Ent
)
894 or else Is_Concurrent_Type
(Ent
)
896 return (Has_Discriminants
(Ent
)
898 No
(Discriminant_Default_Value
(First_Discriminant
(Ent
))));
903 end Is_Indefinite_Subtype
;
905 ---------------------
906 -- Is_Limited_Type --
907 ---------------------
909 function Is_Limited_Type
(Ent
: Entity_Id
) return Boolean is
910 Btype
: constant E
:= Base_Type
(Ent
);
911 Rtype
: constant E
:= Root_Type
(Btype
);
914 if not Is_Type
(Ent
) then
917 elsif Ekind
(Btype
) = E_Limited_Private_Type
918 or else Is_Limited_Composite
(Btype
)
922 elsif Is_Concurrent_Type
(Btype
) then
925 -- The Is_Limited_Record flag normally indicates that the type is
926 -- limited. The exception is that a type does not inherit limitedness
927 -- from its interface ancestor. So the type may be derived from a
928 -- limited interface, but is not limited.
930 elsif Is_Limited_Record
(Ent
)
931 and then not Is_Interface
(Ent
)
935 -- Otherwise we will look around to see if there is some other reason
936 -- for it to be limited, except that if an error was posted on the
937 -- entity, then just assume it is non-limited, because it can cause
938 -- trouble to recurse into a murky erroneous entity!
940 elsif Error_Posted
(Ent
) then
943 elsif Is_Record_Type
(Btype
) then
945 if Is_Limited_Interface
(Ent
) then
948 -- AI-419: limitedness is not inherited from a limited interface
950 elsif Is_Limited_Record
(Rtype
) then
951 return not Is_Interface
(Rtype
)
952 or else Is_Protected_Interface
(Rtype
)
953 or else Is_Synchronized_Interface
(Rtype
)
954 or else Is_Task_Interface
(Rtype
);
956 elsif Is_Class_Wide_Type
(Btype
) then
957 return Is_Limited_Type
(Rtype
);
964 C
:= First_Component
(Btype
);
965 while Present
(C
) loop
966 if Is_Limited_Type
(Etype
(C
)) then
970 C
:= Next_Component
(C
);
977 elsif Is_Array_Type
(Btype
) then
978 return Is_Limited_Type
(Component_Type
(Btype
));
985 ---------------------
986 -- Is_Limited_View --
987 ---------------------
989 function Is_Limited_View
(Ent
: Entity_Id
) return Boolean is
990 Btype
: constant Entity_Id
:= Available_View
(Base_Type
(Ent
));
993 if Is_Limited_Record
(Btype
) then
996 elsif Ekind
(Btype
) = E_Limited_Private_Type
997 and then Nkind
(Parent
(Btype
)) = N_Formal_Type_Declaration
999 return not In_Package_Body
(Scope
((Btype
)));
1001 elsif Is_Private_Type
(Btype
) then
1003 -- AI05-0063: A type derived from a limited private formal type is
1004 -- not immutably limited in a generic body.
1006 if Is_Derived_Type
(Btype
)
1007 and then Is_Generic_Type
(Etype
(Btype
))
1009 if not Is_Limited_Type
(Etype
(Btype
)) then
1012 -- A descendant of a limited formal type is not immutably limited
1013 -- in the generic body, or in the body of a generic child.
1015 elsif Ekind
(Scope
(Etype
(Btype
))) = E_Generic_Package
then
1016 return not In_Package_Body
(Scope
(Btype
));
1024 Utyp
: constant Entity_Id
:= Underlying_Type
(Btype
);
1029 return Is_Limited_View
(Utyp
);
1034 elsif Is_Concurrent_Type
(Btype
) then
1037 elsif Is_Record_Type
(Btype
) then
1039 -- Note that we return True for all limited interfaces, even though
1040 -- (unsynchronized) limited interfaces can have descendants that are
1041 -- nonlimited, because this is a predicate on the type itself, and
1042 -- things like functions with limited interface results need to be
1043 -- handled as build in place even though they might return objects
1044 -- of a type that is not inherently limited.
1046 if Is_Class_Wide_Type
(Btype
) then
1047 return Is_Limited_View
(Root_Type
(Btype
));
1054 C
:= First_Component
(Btype
);
1055 while Present
(C
) loop
1057 -- Don't consider components with interface types (which can
1058 -- only occur in the case of a _parent component anyway).
1059 -- They don't have any components, plus it would cause this
1060 -- function to return true for nonlimited types derived from
1061 -- limited interfaces.
1063 if not Is_Interface
(Etype
(C
))
1064 and then Is_Limited_View
(Etype
(C
))
1069 C
:= Next_Component
(C
);
1076 elsif Is_Array_Type
(Btype
) then
1077 return Is_Limited_View
(Component_Type
(Btype
));
1082 end Is_Limited_View
;
1084 ----------------------
1085 -- Nearest_Ancestor --
1086 ----------------------
1088 function Nearest_Ancestor
(Typ
: Entity_Id
) return Entity_Id
is
1089 D
: constant Node_Id
:= Declaration_Node
(Typ
);
1092 -- If we have a subtype declaration, get the ancestor subtype
1094 if Nkind
(D
) = N_Subtype_Declaration
then
1095 if Nkind
(Subtype_Indication
(D
)) = N_Subtype_Indication
then
1096 return Entity
(Subtype_Mark
(Subtype_Indication
(D
)));
1098 return Entity
(Subtype_Indication
(D
));
1101 -- If derived type declaration, find who we are derived from
1103 elsif Nkind
(D
) = N_Full_Type_Declaration
1104 and then Nkind
(Type_Definition
(D
)) = N_Derived_Type_Definition
1107 DTD
: constant Entity_Id
:= Type_Definition
(D
);
1108 SI
: constant Entity_Id
:= Subtype_Indication
(DTD
);
1110 if Is_Entity_Name
(SI
) then
1113 return Entity
(Subtype_Mark
(SI
));
1117 -- If derived type and private type, get the full view to find who we
1118 -- are derived from.
1120 elsif Is_Derived_Type
(Typ
)
1121 and then Is_Private_Type
(Typ
)
1122 and then Present
(Full_View
(Typ
))
1124 return Nearest_Ancestor
(Full_View
(Typ
));
1126 -- Otherwise, nothing useful to return, return Empty
1131 end Nearest_Ancestor
;
1133 ---------------------------
1134 -- Nearest_Dynamic_Scope --
1135 ---------------------------
1137 function Nearest_Dynamic_Scope
(Ent
: Entity_Id
) return Entity_Id
is
1139 if Is_Dynamic_Scope
(Ent
) then
1142 return Enclosing_Dynamic_Scope
(Ent
);
1144 end Nearest_Dynamic_Scope
;
1146 ------------------------
1147 -- Next_Tag_Component --
1148 ------------------------
1150 function Next_Tag_Component
(Tag
: Entity_Id
) return Entity_Id
is
1154 pragma Assert
(Is_Tag
(Tag
));
1156 -- Loop to look for next tag component
1158 Comp
:= Next_Entity
(Tag
);
1159 while Present
(Comp
) loop
1160 if Is_Tag
(Comp
) then
1161 pragma Assert
(Chars
(Comp
) /= Name_uTag
);
1165 Comp
:= Next_Entity
(Comp
);
1168 -- No tag component found
1171 end Next_Tag_Component
;
1173 --------------------------
1174 -- Number_Discriminants --
1175 --------------------------
1177 function Number_Discriminants
(Typ
: Entity_Id
) return Pos
is
1183 Discr
:= First_Discriminant
(Typ
);
1184 while Present
(Discr
) loop
1186 Discr
:= Next_Discriminant
(Discr
);
1190 end Number_Discriminants
;
1192 ----------------------------------------------
1193 -- Object_Type_Has_Constrained_Partial_View --
1194 ----------------------------------------------
1196 function Object_Type_Has_Constrained_Partial_View
1198 Scop
: Entity_Id
) return Boolean
1201 return Has_Constrained_Partial_View
(Typ
)
1202 or else (In_Generic_Body
(Scop
)
1203 and then Is_Generic_Type
(Base_Type
(Typ
))
1204 and then Is_Private_Type
(Base_Type
(Typ
))
1205 and then not Is_Tagged_Type
(Typ
)
1206 and then not (Is_Array_Type
(Typ
)
1207 and then not Is_Constrained
(Typ
))
1208 and then Has_Discriminants
(Typ
));
1209 end Object_Type_Has_Constrained_Partial_View
;
1211 ---------------------------
1212 -- Package_Specification --
1213 ---------------------------
1215 function Package_Specification
(Pack_Id
: Entity_Id
) return Node_Id
is
1219 N
:= Parent
(Pack_Id
);
1220 while Nkind
(N
) /= N_Package_Specification
loop
1224 raise Program_Error
;
1229 end Package_Specification
;
1235 procedure Tree_Read
is
1237 Obsolescent_Warnings
.Tree_Read
;
1244 procedure Tree_Write
is
1246 Obsolescent_Warnings
.Tree_Write
;
1249 --------------------
1250 -- Ultimate_Alias --
1251 --------------------
1253 function Ultimate_Alias
(Prim
: Entity_Id
) return Entity_Id
is
1254 E
: Entity_Id
:= Prim
;
1257 while Present
(Alias
(E
)) loop
1258 pragma Assert
(Alias
(E
) /= E
);
1265 --------------------------
1266 -- Unit_Declaration_Node --
1267 --------------------------
1269 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
1270 N
: Node_Id
:= Parent
(Unit_Id
);
1273 -- Predefined operators do not have a full function declaration
1275 if Ekind
(Unit_Id
) = E_Operator
then
1279 -- Isn't there some better way to express the following ???
1281 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
1282 and then Nkind
(N
) /= N_Formal_Package_Declaration
1283 and then Nkind
(N
) /= N_Function_Instantiation
1284 and then Nkind
(N
) /= N_Generic_Package_Declaration
1285 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
1286 and then Nkind
(N
) /= N_Package_Declaration
1287 and then Nkind
(N
) /= N_Package_Body
1288 and then Nkind
(N
) /= N_Package_Instantiation
1289 and then Nkind
(N
) /= N_Package_Renaming_Declaration
1290 and then Nkind
(N
) /= N_Procedure_Instantiation
1291 and then Nkind
(N
) /= N_Protected_Body
1292 and then Nkind
(N
) /= N_Subprogram_Declaration
1293 and then Nkind
(N
) /= N_Subprogram_Body
1294 and then Nkind
(N
) /= N_Subprogram_Body_Stub
1295 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
1296 and then Nkind
(N
) /= N_Task_Body
1297 and then Nkind
(N
) /= N_Task_Type_Declaration
1298 and then Nkind
(N
) not in N_Formal_Subprogram_Declaration
1299 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
1303 -- We don't use Assert here, because that causes an infinite loop
1304 -- when assertions are turned off. Better to crash.
1307 raise Program_Error
;
1312 end Unit_Declaration_Node
;