1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2002, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Debug
; use Debug
;
30 with Errout
; use Errout
;
31 with Elists
; use Elists
;
32 with Exp_Util
; use Exp_Util
;
33 with Freeze
; use Freeze
;
35 with Lib
.Xref
; use Lib
.Xref
;
36 with Namet
; use Namet
;
37 with Nlists
; use Nlists
;
38 with Nmake
; use Nmake
;
39 with Output
; use Output
;
41 with Restrict
; use Restrict
;
42 with Scans
; use Scans
;
45 with Sem_Ch8
; use Sem_Ch8
;
46 with Sem_Eval
; use Sem_Eval
;
47 with Sem_Res
; use Sem_Res
;
48 with Sem_Type
; use Sem_Type
;
49 with Sinfo
; use Sinfo
;
50 with Sinput
; use Sinput
;
51 with Snames
; use Snames
;
52 with Stand
; use Stand
;
54 with Stringt
; use Stringt
;
55 with Targparm
; use Targparm
;
56 with Tbuild
; use Tbuild
;
57 with Ttypes
; use Ttypes
;
59 package body Sem_Util
is
61 -----------------------
62 -- Local Subprograms --
63 -----------------------
65 function Build_Component_Subtype
70 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
71 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
72 -- Loc is the source location, T is the original subtype.
74 --------------------------------
75 -- Add_Access_Type_To_Process --
76 --------------------------------
78 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
)
82 Ensure_Freeze_Node
(E
);
83 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
87 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
91 end Add_Access_Type_To_Process
;
93 -----------------------
94 -- Alignment_In_Bits --
95 -----------------------
97 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
99 return Alignment
(E
) * System_Storage_Unit
;
100 end Alignment_In_Bits
;
102 -----------------------------------------
103 -- Apply_Compile_Time_Constraint_Error --
104 -----------------------------------------
106 procedure Apply_Compile_Time_Constraint_Error
109 Reason
: RT_Exception_Code
;
110 Ent
: Entity_Id
:= Empty
;
111 Typ
: Entity_Id
:= Empty
;
112 Loc
: Source_Ptr
:= No_Location
;
113 Rep
: Boolean := True)
115 Stat
: constant Boolean := Is_Static_Expression
(N
);
125 if No
(Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
))
131 -- Now we replace the node by an N_Raise_Constraint_Error node
132 -- This does not need reanalyzing, so set it as analyzed now.
135 Make_Raise_Constraint_Error
(Sloc
(N
),
137 Set_Analyzed
(N
, True);
139 Set_Raises_Constraint_Error
(N
);
141 -- If the original expression was marked as static, the result is
142 -- still marked as static, but the Raises_Constraint_Error flag is
143 -- always set so that further static evaluation is not attempted.
146 Set_Is_Static_Expression
(N
);
148 end Apply_Compile_Time_Constraint_Error
;
150 --------------------------
151 -- Build_Actual_Subtype --
152 --------------------------
154 function Build_Actual_Subtype
156 N
: Node_Or_Entity_Id
)
161 Loc
: constant Source_Ptr
:= Sloc
(N
);
162 Constraints
: List_Id
;
168 Disc_Type
: Entity_Id
;
171 if Nkind
(N
) = N_Defining_Identifier
then
172 Obj
:= New_Reference_To
(N
, Loc
);
177 if Is_Array_Type
(T
) then
178 Constraints
:= New_List
;
180 for J
in 1 .. Number_Dimensions
(T
) loop
182 -- Build an array subtype declaration with the nominal
183 -- subtype and the bounds of the actual. Add the declaration
184 -- in front of the local declarations for the subprogram,for
185 -- analysis before any reference to the formal in the body.
188 Make_Attribute_Reference
(Loc
,
190 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
191 Attribute_Name
=> Name_First
,
192 Expressions
=> New_List
(
193 Make_Integer_Literal
(Loc
, J
)));
196 Make_Attribute_Reference
(Loc
,
198 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
199 Attribute_Name
=> Name_Last
,
200 Expressions
=> New_List
(
201 Make_Integer_Literal
(Loc
, J
)));
203 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
206 -- If the type has unknown discriminants there is no constrained
209 elsif Has_Unknown_Discriminants
(T
) then
213 Constraints
:= New_List
;
215 if Is_Private_Type
(T
) and then No
(Full_View
(T
)) then
217 -- Type is a generic derived type. Inherit discriminants from
220 Disc_Type
:= Etype
(Base_Type
(T
));
225 Discr
:= First_Discriminant
(Disc_Type
);
227 while Present
(Discr
) loop
228 Append_To
(Constraints
,
229 Make_Selected_Component
(Loc
,
231 Duplicate_Subexpr_No_Checks
(Obj
),
232 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
233 Next_Discriminant
(Discr
);
238 Make_Defining_Identifier
(Loc
,
239 Chars
=> New_Internal_Name
('S'));
240 Set_Is_Internal
(Subt
);
243 Make_Subtype_Declaration
(Loc
,
244 Defining_Identifier
=> Subt
,
245 Subtype_Indication
=>
246 Make_Subtype_Indication
(Loc
,
247 Subtype_Mark
=> New_Reference_To
(T
, Loc
),
249 Make_Index_Or_Discriminant_Constraint
(Loc
,
250 Constraints
=> Constraints
)));
252 Mark_Rewrite_Insertion
(Decl
);
254 end Build_Actual_Subtype
;
256 ---------------------------------------
257 -- Build_Actual_Subtype_Of_Component --
258 ---------------------------------------
260 function Build_Actual_Subtype_Of_Component
265 Loc
: constant Source_Ptr
:= Sloc
(N
);
266 P
: constant Node_Id
:= Prefix
(N
);
269 Indx_Type
: Entity_Id
;
271 Deaccessed_T
: Entity_Id
;
272 -- This is either a copy of T, or if T is an access type, then it is
273 -- the directly designated type of this access type.
275 function Build_Actual_Array_Constraint
return List_Id
;
276 -- If one or more of the bounds of the component depends on
277 -- discriminants, build actual constraint using the discriminants
280 function Build_Actual_Record_Constraint
return List_Id
;
281 -- Similar to previous one, for discriminated components constrained
282 -- by the discriminant of the enclosing object.
284 -----------------------------------
285 -- Build_Actual_Array_Constraint --
286 -----------------------------------
288 function Build_Actual_Array_Constraint
return List_Id
is
289 Constraints
: List_Id
:= New_List
;
297 Indx
:= First_Index
(Deaccessed_T
);
298 while Present
(Indx
) loop
299 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
300 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
302 if Denotes_Discriminant
(Old_Lo
) then
304 Make_Selected_Component
(Loc
,
305 Prefix
=> New_Copy_Tree
(P
),
306 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
309 Lo
:= New_Copy_Tree
(Old_Lo
);
311 -- The new bound will be reanalyzed in the enclosing
312 -- declaration. For literal bounds that come from a type
313 -- declaration, the type of the context must be imposed, so
314 -- insure that analysis will take place. For non-universal
315 -- types this is not strictly necessary.
317 Set_Analyzed
(Lo
, False);
320 if Denotes_Discriminant
(Old_Hi
) then
322 Make_Selected_Component
(Loc
,
323 Prefix
=> New_Copy_Tree
(P
),
324 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
327 Hi
:= New_Copy_Tree
(Old_Hi
);
328 Set_Analyzed
(Hi
, False);
331 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
336 end Build_Actual_Array_Constraint
;
338 ------------------------------------
339 -- Build_Actual_Record_Constraint --
340 ------------------------------------
342 function Build_Actual_Record_Constraint
return List_Id
is
343 Constraints
: List_Id
:= New_List
;
348 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
349 while Present
(D
) loop
351 if Denotes_Discriminant
(Node
(D
)) then
352 D_Val
:= Make_Selected_Component
(Loc
,
353 Prefix
=> New_Copy_Tree
(P
),
354 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
357 D_Val
:= New_Copy_Tree
(Node
(D
));
360 Append
(D_Val
, Constraints
);
365 end Build_Actual_Record_Constraint
;
367 -- Start of processing for Build_Actual_Subtype_Of_Component
370 if Nkind
(N
) = N_Explicit_Dereference
then
371 if Is_Composite_Type
(T
)
372 and then not Is_Constrained
(T
)
373 and then not (Is_Class_Wide_Type
(T
)
374 and then Is_Constrained
(Root_Type
(T
)))
375 and then not Has_Unknown_Discriminants
(T
)
377 -- If the type of the dereference is already constrained, it
378 -- is an actual subtype.
380 if Is_Array_Type
(Etype
(N
))
381 and then Is_Constrained
(Etype
(N
))
385 Remove_Side_Effects
(P
);
386 return Build_Actual_Subtype
(T
, N
);
393 if Ekind
(T
) = E_Access_Subtype
then
394 Deaccessed_T
:= Designated_Type
(T
);
399 if Ekind
(Deaccessed_T
) = E_Array_Subtype
then
401 Id
:= First_Index
(Deaccessed_T
);
402 Indx_Type
:= Underlying_Type
(Etype
(Id
));
404 while Present
(Id
) loop
406 if Denotes_Discriminant
(Type_Low_Bound
(Indx_Type
)) or else
407 Denotes_Discriminant
(Type_High_Bound
(Indx_Type
))
409 Remove_Side_Effects
(P
);
411 Build_Component_Subtype
(
412 Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
418 elsif Is_Composite_Type
(Deaccessed_T
)
419 and then Has_Discriminants
(Deaccessed_T
)
420 and then not Has_Unknown_Discriminants
(Deaccessed_T
)
422 D
:= First_Elmt
(Discriminant_Constraint
(Deaccessed_T
));
423 while Present
(D
) loop
425 if Denotes_Discriminant
(Node
(D
)) then
426 Remove_Side_Effects
(P
);
428 Build_Component_Subtype
(
429 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
436 -- If none of the above, the actual and nominal subtypes are the same.
440 end Build_Actual_Subtype_Of_Component
;
442 -----------------------------
443 -- Build_Component_Subtype --
444 -----------------------------
446 function Build_Component_Subtype
457 Make_Defining_Identifier
(Loc
,
458 Chars
=> New_Internal_Name
('S'));
459 Set_Is_Internal
(Subt
);
462 Make_Subtype_Declaration
(Loc
,
463 Defining_Identifier
=> Subt
,
464 Subtype_Indication
=>
465 Make_Subtype_Indication
(Loc
,
466 Subtype_Mark
=> New_Reference_To
(Base_Type
(T
), Loc
),
468 Make_Index_Or_Discriminant_Constraint
(Loc
,
471 Mark_Rewrite_Insertion
(Decl
);
473 end Build_Component_Subtype
;
475 --------------------------------------------
476 -- Build_Discriminal_Subtype_Of_Component --
477 --------------------------------------------
479 function Build_Discriminal_Subtype_Of_Component
483 Loc
: constant Source_Ptr
:= Sloc
(T
);
487 function Build_Discriminal_Array_Constraint
return List_Id
;
488 -- If one or more of the bounds of the component depends on
489 -- discriminants, build actual constraint using the discriminants
492 function Build_Discriminal_Record_Constraint
return List_Id
;
493 -- Similar to previous one, for discriminated components constrained
494 -- by the discriminant of the enclosing object.
496 ----------------------------------------
497 -- Build_Discriminal_Array_Constraint --
498 ----------------------------------------
500 function Build_Discriminal_Array_Constraint
return List_Id
is
501 Constraints
: List_Id
:= New_List
;
509 Indx
:= First_Index
(T
);
510 while Present
(Indx
) loop
511 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
512 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
514 if Denotes_Discriminant
(Old_Lo
) then
515 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
518 Lo
:= New_Copy_Tree
(Old_Lo
);
521 if Denotes_Discriminant
(Old_Hi
) then
522 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
525 Hi
:= New_Copy_Tree
(Old_Hi
);
528 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
533 end Build_Discriminal_Array_Constraint
;
535 -----------------------------------------
536 -- Build_Discriminal_Record_Constraint --
537 -----------------------------------------
539 function Build_Discriminal_Record_Constraint
return List_Id
is
540 Constraints
: List_Id
:= New_List
;
545 D
:= First_Elmt
(Discriminant_Constraint
(T
));
546 while Present
(D
) loop
548 if Denotes_Discriminant
(Node
(D
)) then
550 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
553 D_Val
:= New_Copy_Tree
(Node
(D
));
556 Append
(D_Val
, Constraints
);
561 end Build_Discriminal_Record_Constraint
;
563 -- Start of processing for Build_Discriminal_Subtype_Of_Component
566 if Ekind
(T
) = E_Array_Subtype
then
568 Id
:= First_Index
(T
);
570 while Present
(Id
) loop
572 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
))) or else
573 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
575 return Build_Component_Subtype
576 (Build_Discriminal_Array_Constraint
, Loc
, T
);
582 elsif Ekind
(T
) = E_Record_Subtype
583 and then Has_Discriminants
(T
)
584 and then not Has_Unknown_Discriminants
(T
)
586 D
:= First_Elmt
(Discriminant_Constraint
(T
));
587 while Present
(D
) loop
589 if Denotes_Discriminant
(Node
(D
)) then
590 return Build_Component_Subtype
591 (Build_Discriminal_Record_Constraint
, Loc
, T
);
598 -- If none of the above, the actual and nominal subtypes are the same.
602 end Build_Discriminal_Subtype_Of_Component
;
604 ------------------------------
605 -- Build_Elaboration_Entity --
606 ------------------------------
608 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
609 Loc
: constant Source_Ptr
:= Sloc
(N
);
610 Unum
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
613 Elab_Ent
: Entity_Id
;
616 -- Ignore if already constructed
618 if Present
(Elaboration_Entity
(Spec_Id
)) then
622 -- Construct name of elaboration entity as xxx_E, where xxx
623 -- is the unit name with dots replaced by double underscore.
624 -- We have to manually construct this name, since it will
625 -- be elaborated in the outer scope, and thus will not have
626 -- the unit name automatically prepended.
628 Get_Name_String
(Unit_Name
(Unum
));
630 -- Replace the %s by _E
632 Name_Buffer
(Name_Len
- 1 .. Name_Len
) := "_E";
634 -- Replace dots by double underscore
637 while P
< Name_Len
- 2 loop
638 if Name_Buffer
(P
) = '.' then
639 Name_Buffer
(P
+ 2 .. Name_Len
+ 1) :=
640 Name_Buffer
(P
+ 1 .. Name_Len
);
641 Name_Len
:= Name_Len
+ 1;
642 Name_Buffer
(P
) := '_';
643 Name_Buffer
(P
+ 1) := '_';
650 -- Create elaboration flag
653 Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
654 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
656 if No
(Declarations
(Aux_Decls_Node
(N
))) then
657 Set_Declarations
(Aux_Decls_Node
(N
), New_List
);
661 Make_Object_Declaration
(Loc
,
662 Defining_Identifier
=> Elab_Ent
,
664 New_Occurrence_Of
(Standard_Boolean
, Loc
),
666 New_Occurrence_Of
(Standard_False
, Loc
));
668 Append_To
(Declarations
(Aux_Decls_Node
(N
)), Decl
);
671 -- Reset True_Constant indication, since we will indeed
672 -- assign a value to the variable in the binder main.
674 Set_Is_True_Constant
(Elab_Ent
, False);
676 -- We do not want any further qualification of the name (if we did
677 -- not do this, we would pick up the name of the generic package
678 -- in the case of a library level generic instantiation).
680 Set_Has_Qualified_Name
(Elab_Ent
);
681 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
682 end Build_Elaboration_Entity
;
684 -----------------------------------
685 -- Cannot_Raise_Constraint_Error --
686 -----------------------------------
688 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
690 if Compile_Time_Known_Value
(Expr
) then
693 elsif Do_Range_Check
(Expr
) then
696 elsif Raises_Constraint_Error
(Expr
) then
704 when N_Expanded_Name
=>
707 when N_Selected_Component
=>
708 return not Do_Discriminant_Check
(Expr
);
710 when N_Attribute_Reference
=>
711 if Do_Overflow_Check
(Expr
)
712 or else Do_Access_Check
(Expr
)
716 elsif No
(Expressions
(Expr
)) then
721 N
: Node_Id
:= First
(Expressions
(Expr
));
724 while Present
(N
) loop
725 if Cannot_Raise_Constraint_Error
(N
) then
736 when N_Type_Conversion
=>
737 if Do_Overflow_Check
(Expr
)
738 or else Do_Length_Check
(Expr
)
739 or else Do_Tag_Check
(Expr
)
744 Cannot_Raise_Constraint_Error
(Expression
(Expr
));
747 when N_Unchecked_Type_Conversion
=>
748 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
751 if Do_Overflow_Check
(Expr
) then
755 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
762 if Do_Division_Check
(Expr
)
763 or else Do_Overflow_Check
(Expr
)
768 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
770 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
789 N_Op_Shift_Right_Arithmetic |
793 if Do_Overflow_Check
(Expr
) then
797 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
799 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
806 end Cannot_Raise_Constraint_Error
;
808 --------------------------
809 -- Check_Fully_Declared --
810 --------------------------
812 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
814 if Ekind
(T
) = E_Incomplete_Type
then
816 ("premature usage of incomplete}", N
, First_Subtype
(T
));
818 elsif Has_Private_Component
(T
)
819 and then not Is_Generic_Type
(Root_Type
(T
))
820 and then not In_Default_Expression
823 ("premature usage of incomplete}", N
, First_Subtype
(T
));
825 end Check_Fully_Declared
;
827 ------------------------------------------
828 -- Check_Potentially_Blocking_Operation --
829 ------------------------------------------
831 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
833 Loc
: constant Source_Ptr
:= Sloc
(N
);
836 -- N is one of the potentially blocking operations listed in
837 -- 9.5.1 (8). When using the Ravenscar profile, raise Program_Error
838 -- before N if the context is a protected action. Otherwise, only issue
839 -- a warning, since some users are relying on blocking operations
840 -- inside protected objects.
841 -- Indirect blocking through a subprogram call
842 -- cannot be diagnosed statically without interprocedural analysis,
843 -- so we do not attempt to do it here.
845 S
:= Scope
(Current_Scope
);
847 while Present
(S
) and then S
/= Standard_Standard
loop
848 if Is_Protected_Type
(S
) then
849 if Restricted_Profile
then
851 Make_Raise_Program_Error
(Loc
,
852 Reason
=> PE_Potentially_Blocking_Operation
));
853 Error_Msg_N
("potentially blocking operation, " &
854 " Program Error will be raised at run time?", N
);
858 ("potentially blocking operation in protected operation?", N
);
866 end Check_Potentially_Blocking_Operation
;
872 procedure Check_VMS
(Construct
: Node_Id
) is
874 if not OpenVMS_On_Target
then
876 ("this construct is allowed only in Open'V'M'S", Construct
);
880 ----------------------------------
881 -- Collect_Primitive_Operations --
882 ----------------------------------
884 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
885 B_Type
: constant Entity_Id
:= Base_Type
(T
);
886 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
887 B_Scope
: Entity_Id
:= Scope
(B_Type
);
891 Formal_Derived
: Boolean := False;
895 -- For tagged types, the primitive operations are collected as they
896 -- are declared, and held in an explicit list which is simply returned.
898 if Is_Tagged_Type
(B_Type
) then
899 return Primitive_Operations
(B_Type
);
901 -- An untagged generic type that is a derived type inherits the
902 -- primitive operations of its parent type. Other formal types only
903 -- have predefined operators, which are not explicitly represented.
905 elsif Is_Generic_Type
(B_Type
) then
906 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
907 and then Nkind
(Formal_Type_Definition
(B_Decl
))
908 = N_Formal_Derived_Type_Definition
910 Formal_Derived
:= True;
912 return New_Elmt_List
;
916 Op_List
:= New_Elmt_List
;
918 if B_Scope
= Standard_Standard
then
919 if B_Type
= Standard_String
then
920 Append_Elmt
(Standard_Op_Concat
, Op_List
);
922 elsif B_Type
= Standard_Wide_String
then
923 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
929 elsif (Is_Package
(B_Scope
)
931 Parent
(Declaration_Node
(First_Subtype
(T
))))
934 or else Is_Derived_Type
(B_Type
)
936 -- The primitive operations appear after the base type, except
937 -- if the derivation happens within the private part of B_Scope
938 -- and the type is a private type, in which case both the type
939 -- and some primitive operations may appear before the base
940 -- type, and the list of candidates starts after the type.
942 if In_Open_Scopes
(B_Scope
)
943 and then Scope
(T
) = B_Scope
944 and then In_Private_Part
(B_Scope
)
946 Id
:= Next_Entity
(T
);
948 Id
:= Next_Entity
(B_Type
);
951 while Present
(Id
) loop
953 -- Note that generic formal subprograms are not
954 -- considered to be primitive operations and thus
955 -- are never inherited.
957 if Is_Overloadable
(Id
)
958 and then Nkind
(Parent
(Parent
(Id
)))
959 /= N_Formal_Subprogram_Declaration
963 if Base_Type
(Etype
(Id
)) = B_Type
then
966 Formal
:= First_Formal
(Id
);
967 while Present
(Formal
) loop
968 if Base_Type
(Etype
(Formal
)) = B_Type
then
972 elsif Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
974 (Designated_Type
(Etype
(Formal
))) = B_Type
980 Next_Formal
(Formal
);
984 -- For a formal derived type, the only primitives are the
985 -- ones inherited from the parent type. Operations appearing
986 -- in the package declaration are not primitive for it.
989 and then (not Formal_Derived
990 or else Present
(Alias
(Id
)))
992 Append_Elmt
(Id
, Op_List
);
998 -- For a type declared in System, some of its operations
999 -- may appear in the target-specific extension to System.
1002 and then Chars
(B_Scope
) = Name_System
1003 and then Scope
(B_Scope
) = Standard_Standard
1004 and then Present_System_Aux
1006 B_Scope
:= System_Aux_Id
;
1007 Id
:= First_Entity
(System_Aux_Id
);
1015 end Collect_Primitive_Operations
;
1017 -----------------------------------
1018 -- Compile_Time_Constraint_Error --
1019 -----------------------------------
1021 function Compile_Time_Constraint_Error
1024 Ent
: Entity_Id
:= Empty
;
1025 Loc
: Source_Ptr
:= No_Location
)
1028 Msgc
: String (1 .. Msg
'Length + 2);
1036 -- A static constraint error in an instance body is not a fatal error.
1037 -- we choose to inhibit the message altogether, because there is no
1038 -- obvious node (for now) on which to post it. On the other hand the
1039 -- offending node must be replaced with a constraint_error in any case.
1041 -- No messages are generated if we already posted an error on this node
1043 if not Error_Posted
(N
) then
1044 if Loc
/= No_Location
then
1050 -- Make all such messages unconditional
1052 Msgc
(1 .. Msg
'Length) := Msg
;
1053 Msgc
(Msg
'Length + 1) := '!';
1054 Msgl
:= Msg
'Length + 1;
1056 -- Message is a warning, even in Ada 95 case
1058 if Msg
(Msg
'Length) = '?' then
1061 -- In Ada 83, all messages are warnings. In the private part and
1062 -- the body of an instance, constraint_checks are only warnings.
1064 elsif Ada_83
and then Comes_From_Source
(N
) then
1070 elsif In_Instance_Not_Visible
then
1075 Warn_On_Instance
:= True;
1077 -- Otherwise we have a real error message (Ada 95 static case)
1083 -- Should we generate a warning? The answer is not quite yes. The
1084 -- very annoying exception occurs in the case of a short circuit
1085 -- operator where the left operand is static and decisive. Climb
1086 -- parents to see if that is the case we have here.
1094 if (Nkind
(P
) = N_And_Then
1095 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1096 and then Is_False
(Expr_Value
(Left_Opnd
(P
))))
1097 or else (Nkind
(P
) = N_Or_Else
1098 and then Compile_Time_Known_Value
(Left_Opnd
(P
))
1099 and then Is_True
(Expr_Value
(Left_Opnd
(P
))))
1104 elsif Nkind
(P
) = N_Component_Association
1105 and then Nkind
(Parent
(P
)) = N_Aggregate
1107 null; -- Keep going.
1110 exit when Nkind
(P
) not in N_Subexpr
;
1115 if Present
(Ent
) then
1116 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
1118 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
1122 if Inside_Init_Proc
then
1124 ("\& will be raised for objects of this type!?",
1125 N
, Standard_Constraint_Error
, Eloc
);
1128 ("\& will be raised at run time!?",
1129 N
, Standard_Constraint_Error
, Eloc
);
1133 ("\static expression raises&!",
1134 N
, Standard_Constraint_Error
, Eloc
);
1140 end Compile_Time_Constraint_Error
;
1142 -----------------------
1143 -- Conditional_Delay --
1144 -----------------------
1146 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
1148 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
1149 Set_Has_Delayed_Freeze
(New_Ent
);
1151 end Conditional_Delay
;
1153 --------------------
1154 -- Current_Entity --
1155 --------------------
1157 -- The currently visible definition for a given identifier is the
1158 -- one most chained at the start of the visibility chain, i.e. the
1159 -- one that is referenced by the Node_Id value of the name of the
1160 -- given identifier.
1162 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
1164 return Get_Name_Entity_Id
(Chars
(N
));
1167 -----------------------------
1168 -- Current_Entity_In_Scope --
1169 -----------------------------
1171 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
1173 CS
: constant Entity_Id
:= Current_Scope
;
1175 Transient_Case
: constant Boolean := Scope_Is_Transient
;
1178 E
:= Get_Name_Entity_Id
(Chars
(N
));
1181 and then Scope
(E
) /= CS
1182 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
1188 end Current_Entity_In_Scope
;
1194 function Current_Scope
return Entity_Id
is
1196 if Scope_Stack
.Last
= -1 then
1197 return Standard_Standard
;
1200 C
: constant Entity_Id
:=
1201 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
1206 return Standard_Standard
;
1212 ------------------------
1213 -- Current_Subprogram --
1214 ------------------------
1216 function Current_Subprogram
return Entity_Id
is
1217 Scop
: constant Entity_Id
:= Current_Scope
;
1220 if Ekind
(Scop
) = E_Function
1222 Ekind
(Scop
) = E_Procedure
1224 Ekind
(Scop
) = E_Generic_Function
1226 Ekind
(Scop
) = E_Generic_Procedure
1231 return Enclosing_Subprogram
(Scop
);
1233 end Current_Subprogram
;
1235 ---------------------
1236 -- Defining_Entity --
1237 ---------------------
1239 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
1240 K
: constant Node_Kind
:= Nkind
(N
);
1241 Err
: Entity_Id
:= Empty
;
1246 N_Subprogram_Declaration |
1247 N_Abstract_Subprogram_Declaration |
1249 N_Package_Declaration |
1250 N_Subprogram_Renaming_Declaration |
1251 N_Subprogram_Body_Stub |
1252 N_Generic_Subprogram_Declaration |
1253 N_Generic_Package_Declaration |
1254 N_Formal_Subprogram_Declaration
1256 return Defining_Entity
(Specification
(N
));
1259 N_Component_Declaration |
1260 N_Defining_Program_Unit_Name |
1261 N_Discriminant_Specification |
1263 N_Entry_Declaration |
1264 N_Entry_Index_Specification |
1265 N_Exception_Declaration |
1266 N_Exception_Renaming_Declaration |
1267 N_Formal_Object_Declaration |
1268 N_Formal_Package_Declaration |
1269 N_Formal_Type_Declaration |
1270 N_Full_Type_Declaration |
1271 N_Implicit_Label_Declaration |
1272 N_Incomplete_Type_Declaration |
1273 N_Loop_Parameter_Specification |
1274 N_Number_Declaration |
1275 N_Object_Declaration |
1276 N_Object_Renaming_Declaration |
1277 N_Package_Body_Stub |
1278 N_Parameter_Specification |
1279 N_Private_Extension_Declaration |
1280 N_Private_Type_Declaration |
1282 N_Protected_Body_Stub |
1283 N_Protected_Type_Declaration |
1284 N_Single_Protected_Declaration |
1285 N_Single_Task_Declaration |
1286 N_Subtype_Declaration |
1289 N_Task_Type_Declaration
1291 return Defining_Identifier
(N
);
1294 return Defining_Entity
(Proper_Body
(N
));
1297 N_Function_Instantiation |
1298 N_Function_Specification |
1299 N_Generic_Function_Renaming_Declaration |
1300 N_Generic_Package_Renaming_Declaration |
1301 N_Generic_Procedure_Renaming_Declaration |
1303 N_Package_Instantiation |
1304 N_Package_Renaming_Declaration |
1305 N_Package_Specification |
1306 N_Procedure_Instantiation |
1307 N_Procedure_Specification
1310 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
1313 if Nkind
(Nam
) in N_Entity
then
1316 -- For Error, make up a name and attach to declaration
1317 -- so we can continue semantic analysis
1319 elsif Nam
= Error
then
1321 Make_Defining_Identifier
(Sloc
(N
),
1322 Chars
=> New_Internal_Name
('T'));
1323 Set_Defining_Unit_Name
(N
, Err
);
1326 -- If not an entity, get defining identifier
1329 return Defining_Identifier
(Nam
);
1333 when N_Block_Statement
=>
1334 return Entity
(Identifier
(N
));
1337 raise Program_Error
;
1340 end Defining_Entity
;
1342 --------------------------
1343 -- Denotes_Discriminant --
1344 --------------------------
1346 function Denotes_Discriminant
(N
: Node_Id
) return Boolean is
1348 return Is_Entity_Name
(N
)
1349 and then Present
(Entity
(N
))
1350 and then Ekind
(Entity
(N
)) = E_Discriminant
;
1351 end Denotes_Discriminant
;
1353 -----------------------------
1354 -- Depends_On_Discriminant --
1355 -----------------------------
1357 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
1362 Get_Index_Bounds
(N
, L
, H
);
1363 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
1364 end Depends_On_Discriminant
;
1366 -------------------------
1367 -- Designate_Same_Unit --
1368 -------------------------
1370 function Designate_Same_Unit
1375 K1
: Node_Kind
:= Nkind
(Name1
);
1376 K2
: Node_Kind
:= Nkind
(Name2
);
1378 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
1379 -- Returns the parent unit name node of a defining program unit name
1380 -- or the prefix if N is a selected component or an expanded name.
1382 function Select_Node
(N
: Node_Id
) return Node_Id
;
1383 -- Returns the defining identifier node of a defining program unit
1384 -- name or the selector node if N is a selected component or an
1387 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
1389 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
1397 function Select_Node
(N
: Node_Id
) return Node_Id
is
1399 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
1400 return Defining_Identifier
(N
);
1403 return Selector_Name
(N
);
1407 -- Start of processing for Designate_Next_Unit
1410 if (K1
= N_Identifier
or else
1411 K1
= N_Defining_Identifier
)
1413 (K2
= N_Identifier
or else
1414 K2
= N_Defining_Identifier
)
1416 return Chars
(Name1
) = Chars
(Name2
);
1419 (K1
= N_Expanded_Name
or else
1420 K1
= N_Selected_Component
or else
1421 K1
= N_Defining_Program_Unit_Name
)
1423 (K2
= N_Expanded_Name
or else
1424 K2
= N_Selected_Component
or else
1425 K2
= N_Defining_Program_Unit_Name
)
1428 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
1430 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
1435 end Designate_Same_Unit
;
1437 ----------------------------
1438 -- Enclosing_Generic_Body --
1439 ----------------------------
1441 function Enclosing_Generic_Body
1452 while Present
(P
) loop
1453 if Nkind
(P
) = N_Package_Body
1454 or else Nkind
(P
) = N_Subprogram_Body
1456 Spec
:= Corresponding_Spec
(P
);
1458 if Present
(Spec
) then
1459 Decl
:= Unit_Declaration_Node
(Spec
);
1461 if Nkind
(Decl
) = N_Generic_Package_Declaration
1462 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
1473 end Enclosing_Generic_Body
;
1475 -------------------------------
1476 -- Enclosing_Lib_Unit_Entity --
1477 -------------------------------
1479 function Enclosing_Lib_Unit_Entity
return Entity_Id
is
1480 Unit_Entity
: Entity_Id
:= Current_Scope
;
1483 -- Look for enclosing library unit entity by following scope links.
1484 -- Equivalent to, but faster than indexing through the scope stack.
1486 while (Present
(Scope
(Unit_Entity
))
1487 and then Scope
(Unit_Entity
) /= Standard_Standard
)
1488 and not Is_Child_Unit
(Unit_Entity
)
1490 Unit_Entity
:= Scope
(Unit_Entity
);
1494 end Enclosing_Lib_Unit_Entity
;
1496 -----------------------------
1497 -- Enclosing_Lib_Unit_Node --
1498 -----------------------------
1500 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
1501 Current_Node
: Node_Id
:= N
;
1504 while Present
(Current_Node
)
1505 and then Nkind
(Current_Node
) /= N_Compilation_Unit
1507 Current_Node
:= Parent
(Current_Node
);
1510 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
1514 return Current_Node
;
1515 end Enclosing_Lib_Unit_Node
;
1517 --------------------------
1518 -- Enclosing_Subprogram --
1519 --------------------------
1521 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
1522 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
1525 if Dynamic_Scope
= Standard_Standard
then
1528 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
1529 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
1531 elsif Ekind
(Dynamic_Scope
) = E_Block
then
1532 return Enclosing_Subprogram
(Dynamic_Scope
);
1534 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
1535 return Get_Task_Body_Procedure
(Dynamic_Scope
);
1537 elsif Convention
(Dynamic_Scope
) = Convention_Protected
then
1538 return Protected_Body_Subprogram
(Dynamic_Scope
);
1541 return Dynamic_Scope
;
1543 end Enclosing_Subprogram
;
1545 ------------------------
1546 -- Ensure_Freeze_Node --
1547 ------------------------
1549 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
1553 if No
(Freeze_Node
(E
)) then
1554 FN
:= Make_Freeze_Entity
(Sloc
(E
));
1555 Set_Has_Delayed_Freeze
(E
);
1556 Set_Freeze_Node
(E
, FN
);
1557 Set_Access_Types_To_Process
(FN
, No_Elist
);
1558 Set_TSS_Elist
(FN
, No_Elist
);
1561 end Ensure_Freeze_Node
;
1567 procedure Enter_Name
(Def_Id
: Node_Id
) is
1568 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
1569 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
1570 S
: constant Entity_Id
:= Current_Scope
;
1573 Generate_Definition
(Def_Id
);
1575 -- Add new name to current scope declarations. Check for duplicate
1576 -- declaration, which may or may not be a genuine error.
1580 -- Case of previous entity entered because of a missing declaration
1581 -- or else a bad subtype indication. Best is to use the new entity,
1582 -- and make the previous one invisible.
1584 if Etype
(E
) = Any_Type
then
1585 Set_Is_Immediately_Visible
(E
, False);
1587 -- Case of renaming declaration constructed for package instances.
1588 -- if there is an explicit declaration with the same identifier,
1589 -- the renaming is not immediately visible any longer, but remains
1590 -- visible through selected component notation.
1592 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
1593 and then not Comes_From_Source
(E
)
1595 Set_Is_Immediately_Visible
(E
, False);
1597 -- The new entity may be the package renaming, which has the same
1598 -- same name as a generic formal which has been seen already.
1600 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
1601 and then not Comes_From_Source
(Def_Id
)
1603 Set_Is_Immediately_Visible
(E
, False);
1605 -- For a fat pointer corresponding to a remote access to subprogram,
1606 -- we use the same identifier as the RAS type, so that the proper
1607 -- name appears in the stub. This type is only retrieved through
1608 -- the RAS type and never by visibility, and is not added to the
1609 -- visibility list (see below).
1611 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
1612 and then Present
(Corresponding_Remote_Type
(Def_Id
))
1616 -- A controller component for a type extension overrides the
1617 -- inherited component.
1619 elsif Chars
(E
) = Name_uController
then
1622 -- Case of an implicit operation or derived literal. The new entity
1623 -- hides the implicit one, which is removed from all visibility,
1624 -- i.e. the entity list of its scope, and homonym chain of its name.
1626 elsif (Is_Overloadable
(E
) and then Present
(Alias
(E
)))
1627 or else Is_Internal
(E
)
1628 or else (Ekind
(E
) = E_Enumeration_Literal
1629 and then Is_Derived_Type
(Etype
(E
)))
1633 Prev_Vis
: Entity_Id
;
1636 -- If E is an implicit declaration, it cannot be the first
1637 -- entity in the scope.
1639 Prev
:= First_Entity
(Current_Scope
);
1641 while Next_Entity
(Prev
) /= E
loop
1645 Set_Next_Entity
(Prev
, Next_Entity
(E
));
1647 if No
(Next_Entity
(Prev
)) then
1648 Set_Last_Entity
(Current_Scope
, Prev
);
1651 if E
= Current_Entity
(E
) then
1654 Prev_Vis
:= Current_Entity
(E
);
1655 while Homonym
(Prev_Vis
) /= E
loop
1656 Prev_Vis
:= Homonym
(Prev_Vis
);
1660 if Present
(Prev_Vis
) then
1662 -- Skip E in the visibility chain
1664 Set_Homonym
(Prev_Vis
, Homonym
(E
));
1667 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
1671 -- This section of code could use a comment ???
1673 elsif Present
(Etype
(E
))
1674 and then Is_Concurrent_Type
(Etype
(E
))
1679 -- In the body or private part of an instance, a type extension
1680 -- may introduce a component with the same name as that of an
1681 -- actual. The legality rule is not enforced, but the semantics
1682 -- of the full type with two components of the same name are not
1683 -- clear at this point ???
1685 elsif In_Instance_Not_Visible
then
1688 -- When compiling a package body, some child units may have become
1689 -- visible. They cannot conflict with local entities that hide them.
1691 elsif Is_Child_Unit
(E
)
1692 and then In_Open_Scopes
(Scope
(E
))
1693 and then not Is_Immediately_Visible
(E
)
1697 -- Conversely, with front-end inlining we may compile the parent
1698 -- body first, and a child unit subsequently. The context is now
1699 -- the parent spec, and body entities are not visible.
1701 elsif Is_Child_Unit
(Def_Id
)
1702 and then Is_Package_Body_Entity
(E
)
1703 and then not In_Package_Body
(Current_Scope
)
1707 -- Case of genuine duplicate declaration
1710 Error_Msg_Sloc
:= Sloc
(E
);
1712 -- If the previous declaration is an incomplete type declaration
1713 -- this may be an attempt to complete it with a private type.
1714 -- The following avoids confusing cascaded errors.
1716 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
1717 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
1720 ("incomplete type cannot be completed" &
1721 " with a private declaration",
1723 Set_Is_Immediately_Visible
(E
, False);
1724 Set_Full_View
(E
, Def_Id
);
1726 elsif Ekind
(E
) = E_Discriminant
1727 and then Present
(Scope
(Def_Id
))
1728 and then Scope
(Def_Id
) /= Current_Scope
1730 -- An inherited component of a record conflicts with
1731 -- a new discriminant. The discriminant is inserted first
1732 -- in the scope, but the error should be posted on it, not
1733 -- on the component.
1735 Error_Msg_Sloc
:= Sloc
(Def_Id
);
1736 Error_Msg_N
("& conflicts with declaration#", E
);
1739 -- If the name of the unit appears in its own context clause,
1740 -- a dummy package with the name has already been created, and
1741 -- the error emitted. Try to continue quietly.
1743 elsif Error_Posted
(E
)
1744 and then Sloc
(E
) = No_Location
1745 and then Nkind
(Parent
(E
)) = N_Package_Specification
1746 and then Current_Scope
= Standard_Standard
1748 Set_Scope
(Def_Id
, Current_Scope
);
1752 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
1754 -- Avoid cascaded messages with duplicate components in
1757 if Ekind
(E
) = E_Component
1758 or else Ekind
(E
) = E_Discriminant
1764 if Nkind
(Parent
(Parent
(Def_Id
)))
1765 = N_Generic_Subprogram_Declaration
1767 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
1769 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
1772 -- If entity is in standard, then we are in trouble, because
1773 -- it means that we have a library package with a duplicated
1774 -- name. That's hard to recover from, so abort!
1776 if S
= Standard_Standard
then
1777 raise Unrecoverable_Error
;
1779 -- Otherwise we continue with the declaration. Having two
1780 -- identical declarations should not cause us too much trouble!
1788 -- If we fall through, declaration is OK , or OK enough to continue
1790 -- If Def_Id is a discriminant or a record component we are in the
1791 -- midst of inheriting components in a derived record definition.
1792 -- Preserve their Ekind and Etype.
1794 if Ekind
(Def_Id
) = E_Discriminant
1795 or else Ekind
(Def_Id
) = E_Component
1799 -- If a type is already set, leave it alone (happens whey a type
1800 -- declaration is reanalyzed following a call to the optimizer)
1802 elsif Present
(Etype
(Def_Id
)) then
1805 -- Otherwise, the kind E_Void insures that premature uses of the entity
1806 -- will be detected. Any_Type insures that no cascaded errors will occur
1809 Set_Ekind
(Def_Id
, E_Void
);
1810 Set_Etype
(Def_Id
, Any_Type
);
1813 -- Inherited discriminants and components in derived record types are
1814 -- immediately visible. Itypes are not.
1816 if Ekind
(Def_Id
) = E_Discriminant
1817 or else Ekind
(Def_Id
) = E_Component
1818 or else (No
(Corresponding_Remote_Type
(Def_Id
))
1819 and then not Is_Itype
(Def_Id
))
1821 Set_Is_Immediately_Visible
(Def_Id
);
1822 Set_Current_Entity
(Def_Id
);
1825 Set_Homonym
(Def_Id
, C
);
1826 Append_Entity
(Def_Id
, S
);
1827 Set_Public_Status
(Def_Id
);
1829 -- Warn if new entity hides an old one
1832 and then Length_Of_Name
(Chars
(C
)) /= 1
1833 and then Present
(C
)
1834 and then Comes_From_Source
(C
)
1835 and then Comes_From_Source
(Def_Id
)
1836 and then In_Extended_Main_Source_Unit
(Def_Id
)
1838 Error_Msg_Sloc
:= Sloc
(C
);
1839 Error_Msg_N
("declaration hides &#?", Def_Id
);
1844 -------------------------------------
1845 -- Find_Corresponding_Discriminant --
1846 -------------------------------------
1848 function Find_Corresponding_Discriminant
1853 Par_Disc
: Entity_Id
;
1854 Old_Disc
: Entity_Id
;
1855 New_Disc
: Entity_Id
;
1858 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
1859 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
1861 if Is_Class_Wide_Type
(Typ
) then
1862 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
1864 New_Disc
:= First_Discriminant
(Typ
);
1867 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
1868 if Old_Disc
= Par_Disc
then
1871 Next_Discriminant
(Old_Disc
);
1872 Next_Discriminant
(New_Disc
);
1876 -- Should always find it
1878 raise Program_Error
;
1879 end Find_Corresponding_Discriminant
;
1885 function First_Actual
(Node
: Node_Id
) return Node_Id
is
1889 if No
(Parameter_Associations
(Node
)) then
1893 N
:= First
(Parameter_Associations
(Node
));
1895 if Nkind
(N
) = N_Parameter_Association
then
1896 return First_Named_Actual
(Node
);
1902 -------------------------
1903 -- Full_Qualified_Name --
1904 -------------------------
1906 function Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
1910 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
;
1911 -- Compute recursively the qualified name without NUL at the end.
1913 function Internal_Full_Qualified_Name
(E
: Entity_Id
) return String_Id
is
1914 Ent
: Entity_Id
:= E
;
1915 Parent_Name
: String_Id
:= No_String
;
1918 -- Deals properly with child units
1920 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
1921 Ent
:= Defining_Identifier
(Ent
);
1924 -- Compute recursively the qualification. Only "Standard" has no
1927 if Present
(Scope
(Scope
(Ent
))) then
1928 Parent_Name
:= Internal_Full_Qualified_Name
(Scope
(Ent
));
1931 -- Every entity should have a name except some expanded blocks
1932 -- don't bother about those.
1934 if Chars
(Ent
) = No_Name
then
1938 -- Add a period between Name and qualification
1940 if Parent_Name
/= No_String
then
1941 Start_String
(Parent_Name
);
1942 Store_String_Char
(Get_Char_Code
('.'));
1948 -- Generates the entity name in upper case
1950 Get_Name_String
(Chars
(Ent
));
1952 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
1954 end Internal_Full_Qualified_Name
;
1957 Res
:= Internal_Full_Qualified_Name
(E
);
1958 Store_String_Char
(Get_Char_Code
(ASCII
.nul
));
1960 end Full_Qualified_Name
;
1962 -----------------------
1963 -- Gather_Components --
1964 -----------------------
1966 procedure Gather_Components
1968 Comp_List
: Node_Id
;
1969 Governed_By
: List_Id
;
1971 Report_Errors
: out Boolean)
1975 Discrete_Choice
: Node_Id
;
1976 Comp_Item
: Node_Id
;
1978 Discrim
: Entity_Id
;
1979 Discrim_Name
: Node_Id
;
1980 Discrim_Value
: Node_Id
;
1983 Report_Errors
:= False;
1985 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
1988 elsif Present
(Component_Items
(Comp_List
)) then
1989 Comp_Item
:= First
(Component_Items
(Comp_List
));
1995 while Present
(Comp_Item
) loop
1997 -- Skip the tag of a tagged record, as well as all items
1998 -- that are not user components (anonymous types, rep clauses,
1999 -- Parent field, controller field).
2001 if Nkind
(Comp_Item
) = N_Component_Declaration
2002 and then Chars
(Defining_Identifier
(Comp_Item
)) /= Name_uTag
2003 and then Chars
(Defining_Identifier
(Comp_Item
)) /= Name_uParent
2004 and then Chars
(Defining_Identifier
(Comp_Item
)) /= Name_uController
2006 Append_Elmt
(Defining_Identifier
(Comp_Item
), Into
);
2012 if No
(Variant_Part
(Comp_List
)) then
2015 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
2016 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
2019 -- Look for the discriminant that governs this variant part.
2020 -- The discriminant *must* be in the Governed_By List
2022 Assoc
:= First
(Governed_By
);
2023 Find_Constraint
: loop
2024 Discrim
:= First
(Choices
(Assoc
));
2025 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
2026 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
2028 Chars
(Corresponding_Discriminant
(Entity
(Discrim
)))
2029 = Chars
(Discrim_Name
))
2030 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
2031 = Chars
(Discrim_Name
);
2033 if No
(Next
(Assoc
)) then
2034 if not Is_Constrained
(Typ
)
2035 and then Is_Derived_Type
(Typ
)
2036 and then Present
(Girder_Constraint
(Typ
))
2039 -- If the type is a tagged type with inherited discriminants,
2040 -- use the girder constraint on the parent in order to find
2041 -- the values of discriminants that are otherwise hidden by an
2042 -- explicit constraint. Renamed discriminants are handled in
2050 D
:= First_Discriminant
(Etype
(Typ
));
2051 C
:= First_Elmt
(Girder_Constraint
(Typ
));
2054 and then Present
(C
)
2056 if Chars
(Discrim_Name
) = Chars
(D
) then
2058 Make_Component_Association
(Sloc
(Typ
),
2060 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
2061 Duplicate_Subexpr_No_Checks
(Node
(C
)));
2062 exit Find_Constraint
;
2065 D
:= Next_Discriminant
(D
);
2072 if No
(Next
(Assoc
)) then
2073 Error_Msg_NE
(" missing value for discriminant&",
2074 First
(Governed_By
), Discrim_Name
);
2075 Report_Errors
:= True;
2080 end loop Find_Constraint
;
2082 Discrim_Value
:= Expression
(Assoc
);
2084 if not Is_OK_Static_Expression
(Discrim_Value
) then
2086 ("value for discriminant & must be static", Discrim_Value
, Discrim
);
2087 Report_Errors
:= True;
2091 Search_For_Discriminant_Value
: declare
2097 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
2100 Find_Discrete_Value
: while Present
(Variant
) loop
2101 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
2102 while Present
(Discrete_Choice
) loop
2104 exit Find_Discrete_Value
when
2105 Nkind
(Discrete_Choice
) = N_Others_Choice
;
2107 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
2109 UI_Low
:= Expr_Value
(Low
);
2110 UI_High
:= Expr_Value
(High
);
2112 exit Find_Discrete_Value
when
2113 UI_Low
<= UI_Discrim_Value
2115 UI_High
>= UI_Discrim_Value
;
2117 Next
(Discrete_Choice
);
2120 Next_Non_Pragma
(Variant
);
2121 end loop Find_Discrete_Value
;
2122 end Search_For_Discriminant_Value
;
2124 if No
(Variant
) then
2126 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
2127 Report_Errors
:= True;
2131 -- If we have found the corresponding choice, recursively add its
2132 -- components to the Into list.
2134 Gather_Components
(Empty
,
2135 Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
2136 end Gather_Components
;
2138 ------------------------
2139 -- Get_Actual_Subtype --
2140 ------------------------
2142 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
2143 Typ
: constant Entity_Id
:= Etype
(N
);
2144 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
2149 if not Present
(Utyp
) then
2153 -- If what we have is an identifier that references a subprogram
2154 -- formal, or a variable or constant object, then we get the actual
2155 -- subtype from the referenced entity if one has been built.
2157 if Nkind
(N
) = N_Identifier
2159 (Is_Formal
(Entity
(N
))
2160 or else Ekind
(Entity
(N
)) = E_Constant
2161 or else Ekind
(Entity
(N
)) = E_Variable
)
2162 and then Present
(Actual_Subtype
(Entity
(N
)))
2164 return Actual_Subtype
(Entity
(N
));
2166 -- Actual subtype of unchecked union is always itself. We never need
2167 -- the "real" actual subtype. If we did, we couldn't get it anyway
2168 -- because the discriminant is not available. The restrictions on
2169 -- Unchecked_Union are designed to make sure that this is OK.
2171 elsif Is_Unchecked_Union
(Utyp
) then
2174 -- Here for the unconstrained case, we must find actual subtype
2175 -- No actual subtype is available, so we must build it on the fly.
2177 -- Checking the type, not the underlying type, for constrainedness
2178 -- seems to be necessary. Maybe all the tests should be on the type???
2180 elsif (not Is_Constrained
(Typ
))
2181 and then (Is_Array_Type
(Utyp
)
2182 or else (Is_Record_Type
(Utyp
)
2183 and then Has_Discriminants
(Utyp
)))
2184 and then not Has_Unknown_Discriminants
(Utyp
)
2185 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
2187 -- Nothing to do if in default expression
2189 if In_Default_Expression
then
2192 -- Else build the actual subtype
2195 Decl
:= Build_Actual_Subtype
(Typ
, N
);
2196 Atyp
:= Defining_Identifier
(Decl
);
2198 -- If Build_Actual_Subtype generated a new declaration then use it
2202 -- The actual subtype is an Itype, so analyze the declaration,
2203 -- but do not attach it to the tree, to get the type defined.
2205 Set_Parent
(Decl
, N
);
2206 Set_Is_Itype
(Atyp
);
2207 Analyze
(Decl
, Suppress
=> All_Checks
);
2208 Set_Associated_Node_For_Itype
(Atyp
, N
);
2209 Set_Has_Delayed_Freeze
(Atyp
, False);
2211 -- We need to freeze the actual subtype immediately. This is
2212 -- needed, because otherwise this Itype will not get frozen
2213 -- at all, and it is always safe to freeze on creation because
2214 -- any associated types must be frozen at this point.
2216 Freeze_Itype
(Atyp
, N
);
2219 -- Otherwise we did not build a declaration, so return original
2226 -- For all remaining cases, the actual subtype is the same as
2227 -- the nominal type.
2232 end Get_Actual_Subtype
;
2234 -------------------------------------
2235 -- Get_Actual_Subtype_If_Available --
2236 -------------------------------------
2238 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
2239 Typ
: constant Entity_Id
:= Etype
(N
);
2242 -- If what we have is an identifier that references a subprogram
2243 -- formal, or a variable or constant object, then we get the actual
2244 -- subtype from the referenced entity if one has been built.
2246 if Nkind
(N
) = N_Identifier
2248 (Is_Formal
(Entity
(N
))
2249 or else Ekind
(Entity
(N
)) = E_Constant
2250 or else Ekind
(Entity
(N
)) = E_Variable
)
2251 and then Present
(Actual_Subtype
(Entity
(N
)))
2253 return Actual_Subtype
(Entity
(N
));
2255 -- Otherwise the Etype of N is returned unchanged
2260 end Get_Actual_Subtype_If_Available
;
2262 -------------------------------
2263 -- Get_Default_External_Name --
2264 -------------------------------
2266 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
2268 Get_Decoded_Name_String
(Chars
(E
));
2270 if Opt
.External_Name_Imp_Casing
= Uppercase
then
2271 Set_Casing
(All_Upper_Case
);
2273 Set_Casing
(All_Lower_Case
);
2277 Make_String_Literal
(Sloc
(E
),
2278 Strval
=> String_From_Name_Buffer
);
2280 end Get_Default_External_Name
;
2282 ---------------------------
2283 -- Get_Enum_Lit_From_Pos --
2284 ---------------------------
2286 function Get_Enum_Lit_From_Pos
2293 P
: constant Nat
:= UI_To_Int
(Pos
);
2296 -- In the case where the literal is either of type Wide_Character
2297 -- or Character or of a type derived from them, there needs to be
2298 -- some special handling since there is no explicit chain of
2299 -- literals to search. Instead, an N_Character_Literal node is
2300 -- created with the appropriate Char_Code and Chars fields.
2302 if Root_Type
(T
) = Standard_Character
2303 or else Root_Type
(T
) = Standard_Wide_Character
2305 Set_Character_Literal_Name
(Char_Code
(P
));
2307 Make_Character_Literal
(Loc
,
2309 Char_Literal_Value
=> Char_Code
(P
));
2311 -- For all other cases, we have a complete table of literals, and
2312 -- we simply iterate through the chain of literal until the one
2313 -- with the desired position value is found.
2317 Lit
:= First_Literal
(Base_Type
(T
));
2318 for J
in 1 .. P
loop
2322 return New_Occurrence_Of
(Lit
, Loc
);
2324 end Get_Enum_Lit_From_Pos
;
2326 ------------------------
2327 -- Get_Generic_Entity --
2328 ------------------------
2330 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
2331 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
2334 if Present
(Renamed_Object
(Ent
)) then
2335 return Renamed_Object
(Ent
);
2339 end Get_Generic_Entity
;
2341 ----------------------
2342 -- Get_Index_Bounds --
2343 ----------------------
2345 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
2346 Kind
: constant Node_Kind
:= Nkind
(N
);
2350 if Kind
= N_Range
then
2352 H
:= High_Bound
(N
);
2354 elsif Kind
= N_Subtype_Indication
then
2355 R
:= Range_Expression
(Constraint
(N
));
2363 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
2364 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
2367 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
2368 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
2372 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
2373 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
2376 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
2377 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
2381 -- N is an expression, indicating a range with one value.
2386 end Get_Index_Bounds
;
2388 ------------------------
2389 -- Get_Name_Entity_Id --
2390 ------------------------
2392 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
2394 return Entity_Id
(Get_Name_Table_Info
(Id
));
2395 end Get_Name_Entity_Id
;
2397 ---------------------------
2398 -- Get_Referenced_Object --
2399 ---------------------------
2401 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
2405 while Is_Entity_Name
(R
)
2406 and then Present
(Renamed_Object
(Entity
(R
)))
2408 R
:= Renamed_Object
(Entity
(R
));
2412 end Get_Referenced_Object
;
2414 -------------------------
2415 -- Get_Subprogram_Body --
2416 -------------------------
2418 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
2422 Decl
:= Unit_Declaration_Node
(E
);
2424 if Nkind
(Decl
) = N_Subprogram_Body
then
2427 else -- Nkind (Decl) = N_Subprogram_Declaration
2429 if Present
(Corresponding_Body
(Decl
)) then
2430 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
2432 else -- imported subprogram.
2436 end Get_Subprogram_Body
;
2438 -----------------------------
2439 -- Get_Task_Body_Procedure --
2440 -----------------------------
2442 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
2444 return Task_Body_Procedure
(Declaration_Node
(Root_Type
(E
)));
2445 end Get_Task_Body_Procedure
;
2447 --------------------
2448 -- Has_Infinities --
2449 --------------------
2451 function Has_Infinities
(E
: Entity_Id
) return Boolean is
2454 Is_Floating_Point_Type
(E
)
2455 and then Nkind
(Scalar_Range
(E
)) = N_Range
2456 and then Includes_Infinities
(Scalar_Range
(E
));
2459 ---------------------------
2460 -- Has_Private_Component --
2461 ---------------------------
2463 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
2464 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
2465 Component
: Entity_Id
;
2468 if Error_Posted
(Type_Id
)
2469 or else Error_Posted
(Btype
)
2474 if Is_Class_Wide_Type
(Btype
) then
2475 Btype
:= Root_Type
(Btype
);
2478 if Is_Private_Type
(Btype
) then
2480 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
2484 if No
(Full_View
(Btype
)) then
2485 return not Is_Generic_Type
(Btype
)
2486 and then not Is_Generic_Type
(Root_Type
(Btype
));
2489 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
2493 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
2496 elsif Is_Array_Type
(Btype
) then
2497 return Has_Private_Component
(Component_Type
(Btype
));
2499 elsif Is_Record_Type
(Btype
) then
2501 Component
:= First_Component
(Btype
);
2502 while Present
(Component
) loop
2504 if Has_Private_Component
(Etype
(Component
)) then
2508 Next_Component
(Component
);
2513 elsif Is_Protected_Type
(Btype
)
2514 and then Present
(Corresponding_Record_Type
(Btype
))
2516 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
2521 end Has_Private_Component
;
2523 --------------------------
2524 -- Has_Tagged_Component --
2525 --------------------------
2527 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
2531 if Is_Private_Type
(Typ
)
2532 and then Present
(Underlying_Type
(Typ
))
2534 return Has_Tagged_Component
(Underlying_Type
(Typ
));
2536 elsif Is_Array_Type
(Typ
) then
2537 return Has_Tagged_Component
(Component_Type
(Typ
));
2539 elsif Is_Tagged_Type
(Typ
) then
2542 elsif Is_Record_Type
(Typ
) then
2543 Comp
:= First_Component
(Typ
);
2545 while Present
(Comp
) loop
2546 if Has_Tagged_Component
(Etype
(Comp
)) then
2550 Comp
:= Next_Component
(Typ
);
2558 end Has_Tagged_Component
;
2564 function In_Instance
return Boolean is
2565 S
: Entity_Id
:= Current_Scope
;
2569 and then S
/= Standard_Standard
2571 if (Ekind
(S
) = E_Function
2572 or else Ekind
(S
) = E_Package
2573 or else Ekind
(S
) = E_Procedure
)
2574 and then Is_Generic_Instance
(S
)
2585 ----------------------
2586 -- In_Instance_Body --
2587 ----------------------
2589 function In_Instance_Body
return Boolean is
2590 S
: Entity_Id
:= Current_Scope
;
2594 and then S
/= Standard_Standard
2596 if (Ekind
(S
) = E_Function
2597 or else Ekind
(S
) = E_Procedure
)
2598 and then Is_Generic_Instance
(S
)
2602 elsif Ekind
(S
) = E_Package
2603 and then In_Package_Body
(S
)
2604 and then Is_Generic_Instance
(S
)
2613 end In_Instance_Body
;
2615 -----------------------------
2616 -- In_Instance_Not_Visible --
2617 -----------------------------
2619 function In_Instance_Not_Visible
return Boolean is
2620 S
: Entity_Id
:= Current_Scope
;
2624 and then S
/= Standard_Standard
2626 if (Ekind
(S
) = E_Function
2627 or else Ekind
(S
) = E_Procedure
)
2628 and then Is_Generic_Instance
(S
)
2632 elsif Ekind
(S
) = E_Package
2633 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
2634 and then Is_Generic_Instance
(S
)
2643 end In_Instance_Not_Visible
;
2645 ------------------------------
2646 -- In_Instance_Visible_Part --
2647 ------------------------------
2649 function In_Instance_Visible_Part
return Boolean is
2650 S
: Entity_Id
:= Current_Scope
;
2654 and then S
/= Standard_Standard
2656 if Ekind
(S
) = E_Package
2657 and then Is_Generic_Instance
(S
)
2658 and then not In_Package_Body
(S
)
2659 and then not In_Private_Part
(S
)
2668 end In_Instance_Visible_Part
;
2670 --------------------------------------
2671 -- In_Subprogram_Or_Concurrent_Unit --
2672 --------------------------------------
2674 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
2679 -- Use scope chain to check successively outer scopes
2685 if K
in Subprogram_Kind
2686 or else K
in Concurrent_Kind
2687 or else K
= E_Generic_Procedure
2688 or else K
= E_Generic_Function
2692 elsif E
= Standard_Standard
then
2699 end In_Subprogram_Or_Concurrent_Unit
;
2701 ---------------------
2702 -- In_Visible_Part --
2703 ---------------------
2705 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
2708 Is_Package
(Scope_Id
)
2709 and then In_Open_Scopes
(Scope_Id
)
2710 and then not In_Package_Body
(Scope_Id
)
2711 and then not In_Private_Part
(Scope_Id
);
2712 end In_Visible_Part
;
2718 function Is_AAMP_Float
(E
: Entity_Id
) return Boolean is
2720 pragma Assert
(Is_Type
(E
));
2722 return AAMP_On_Target
2723 and then Is_Floating_Point_Type
(E
)
2724 and then E
= Base_Type
(E
);
2727 -------------------------
2728 -- Is_Actual_Parameter --
2729 -------------------------
2731 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
2732 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
2736 when N_Parameter_Association
=>
2737 return N
= Explicit_Actual_Parameter
(Parent
(N
));
2739 when N_Function_Call | N_Procedure_Call_Statement
=>
2740 return Is_List_Member
(N
)
2742 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
2747 end Is_Actual_Parameter
;
2749 ---------------------
2750 -- Is_Aliased_View --
2751 ---------------------
2753 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
2757 if Is_Entity_Name
(Obj
) then
2759 -- Shouldn't we check that we really have an object here?
2760 -- If we do, then a-caldel.adb blows up mysteriously ???
2764 return Is_Aliased
(E
)
2765 or else (Present
(Renamed_Object
(E
))
2766 and then Is_Aliased_View
(Renamed_Object
(E
)))
2768 or else ((Is_Formal
(E
)
2769 or else Ekind
(E
) = E_Generic_In_Out_Parameter
2770 or else Ekind
(E
) = E_Generic_In_Parameter
)
2771 and then Is_Tagged_Type
(Etype
(E
)))
2773 or else ((Ekind
(E
) = E_Task_Type
or else
2774 Ekind
(E
) = E_Protected_Type
)
2775 and then In_Open_Scopes
(E
))
2777 -- Current instance of type
2779 or else (Is_Type
(E
) and then E
= Current_Scope
)
2780 or else (Is_Incomplete_Or_Private_Type
(E
)
2781 and then Full_View
(E
) = Current_Scope
);
2783 elsif Nkind
(Obj
) = N_Selected_Component
then
2784 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
2786 elsif Nkind
(Obj
) = N_Indexed_Component
then
2787 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
2789 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
2791 Has_Aliased_Components
2792 (Designated_Type
(Etype
(Prefix
(Obj
)))));
2794 elsif Nkind
(Obj
) = N_Unchecked_Type_Conversion
2795 or else Nkind
(Obj
) = N_Type_Conversion
2797 return Is_Tagged_Type
(Etype
(Obj
))
2798 or else Is_Aliased_View
(Expression
(Obj
));
2800 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
2801 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
2806 end Is_Aliased_View
;
2808 ----------------------
2809 -- Is_Atomic_Object --
2810 ----------------------
2812 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
2814 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
2815 -- Determines if given object has atomic components
2817 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
2818 -- If prefix is an implicit dereference, examine designated type.
2820 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
2822 if Is_Access_Type
(Etype
(N
)) then
2824 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
2826 return Object_Has_Atomic_Components
(N
);
2828 end Is_Atomic_Prefix
;
2830 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
2832 if Has_Atomic_Components
(Etype
(N
))
2833 or else Is_Atomic
(Etype
(N
))
2837 elsif Is_Entity_Name
(N
)
2838 and then (Has_Atomic_Components
(Entity
(N
))
2839 or else Is_Atomic
(Entity
(N
)))
2843 elsif Nkind
(N
) = N_Indexed_Component
2844 or else Nkind
(N
) = N_Selected_Component
2846 return Is_Atomic_Prefix
(Prefix
(N
));
2851 end Object_Has_Atomic_Components
;
2853 -- Start of processing for Is_Atomic_Object
2856 if Is_Atomic
(Etype
(N
))
2857 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
2861 elsif Nkind
(N
) = N_Indexed_Component
2862 or else Nkind
(N
) = N_Selected_Component
2864 return Is_Atomic_Prefix
(Prefix
(N
));
2869 end Is_Atomic_Object
;
2871 ----------------------------------------------
2872 -- Is_Dependent_Component_Of_Mutable_Object --
2873 ----------------------------------------------
2875 function Is_Dependent_Component_Of_Mutable_Object
2880 Prefix_Type
: Entity_Id
;
2881 P_Aliased
: Boolean := False;
2884 function Has_Dependent_Constraint
(Comp
: Entity_Id
) return Boolean;
2885 -- Returns True if and only if Comp has a constrained subtype
2886 -- that depends on a discriminant.
2888 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
2889 -- Returns True if and only if Comp is declared within a variant part.
2891 ------------------------------
2892 -- Has_Dependent_Constraint --
2893 ------------------------------
2895 function Has_Dependent_Constraint
(Comp
: Entity_Id
) return Boolean is
2896 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
2897 Subt_Indic
: constant Node_Id
:= Subtype_Indication
(Comp_Decl
);
2902 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
2903 Constr
:= Constraint
(Subt_Indic
);
2905 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
2906 Assn
:= First
(Constraints
(Constr
));
2907 while Present
(Assn
) loop
2908 case Nkind
(Assn
) is
2909 when N_Subtype_Indication |
2913 if Depends_On_Discriminant
(Assn
) then
2917 when N_Discriminant_Association
=>
2918 if Depends_On_Discriminant
(Expression
(Assn
)) then
2933 end Has_Dependent_Constraint
;
2935 --------------------------------
2936 -- Is_Declared_Within_Variant --
2937 --------------------------------
2939 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
2940 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
2941 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
2944 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
2945 end Is_Declared_Within_Variant
;
2947 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
2950 if Is_Variable
(Object
) then
2952 if Nkind
(Object
) = N_Selected_Component
then
2953 P
:= Prefix
(Object
);
2954 Prefix_Type
:= Etype
(P
);
2956 if Is_Entity_Name
(P
) then
2958 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
2959 Prefix_Type
:= Base_Type
(Prefix_Type
);
2962 if Is_Aliased
(Entity
(P
)) then
2967 -- Check for prefix being an aliased component ???
2971 if Is_Access_Type
(Prefix_Type
)
2972 or else Nkind
(P
) = N_Explicit_Dereference
2978 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
2980 -- As per AI-0017, the renaming is illegal in a generic body,
2981 -- even if the subtype is indefinite.
2983 if not Is_Constrained
(Prefix_Type
)
2984 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
2986 (Is_Generic_Type
(Prefix_Type
)
2987 and then Ekind
(Current_Scope
) = E_Generic_Package
2988 and then In_Package_Body
(Current_Scope
)))
2990 and then (Is_Declared_Within_Variant
(Comp
)
2991 or else Has_Dependent_Constraint
(Comp
))
2992 and then not P_Aliased
2998 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
3002 elsif Nkind
(Object
) = N_Indexed_Component
3003 or else Nkind
(Object
) = N_Slice
3005 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
3010 end Is_Dependent_Component_Of_Mutable_Object
;
3016 function Is_False
(U
: Uint
) return Boolean is
3021 ---------------------------
3022 -- Is_Fixed_Model_Number --
3023 ---------------------------
3025 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
3026 S
: constant Ureal
:= Small_Value
(T
);
3027 M
: Urealp
.Save_Mark
;
3032 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
3035 end Is_Fixed_Model_Number
;
3037 -------------------------------
3038 -- Is_Fully_Initialized_Type --
3039 -------------------------------
3041 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
3043 if Is_Scalar_Type
(Typ
) then
3046 elsif Is_Access_Type
(Typ
) then
3049 elsif Is_Array_Type
(Typ
) then
3050 if Is_Fully_Initialized_Type
(Component_Type
(Typ
)) then
3054 -- An interesting case, if we have a constrained type one of whose
3055 -- bounds is known to be null, then there are no elements to be
3056 -- initialized, so all the elements are initialized!
3058 if Is_Constrained
(Typ
) then
3061 Indx_Typ
: Entity_Id
;
3065 Indx
:= First_Index
(Typ
);
3066 while Present
(Indx
) loop
3068 if Etype
(Indx
) = Any_Type
then
3071 -- If index is a range, use directly.
3073 elsif Nkind
(Indx
) = N_Range
then
3074 Lbd
:= Low_Bound
(Indx
);
3075 Hbd
:= High_Bound
(Indx
);
3078 Indx_Typ
:= Etype
(Indx
);
3080 if Is_Private_Type
(Indx_Typ
) then
3081 Indx_Typ
:= Full_View
(Indx_Typ
);
3084 if No
(Indx_Typ
) then
3087 Lbd
:= Type_Low_Bound
(Indx_Typ
);
3088 Hbd
:= Type_High_Bound
(Indx_Typ
);
3092 if Compile_Time_Known_Value
(Lbd
)
3093 and then Compile_Time_Known_Value
(Hbd
)
3095 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
3105 -- If no null indexes, then type is not fully initialized
3109 elsif Is_Record_Type
(Typ
) then
3114 Ent
:= First_Entity
(Typ
);
3116 while Present
(Ent
) loop
3117 if Ekind
(Ent
) = E_Component
3118 and then (No
(Parent
(Ent
))
3119 or else No
(Expression
(Parent
(Ent
))))
3120 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
3129 -- No uninitialized components, so type is fully initialized.
3130 -- Note that this catches the case of no components as well.
3134 elsif Is_Concurrent_Type
(Typ
) then
3137 elsif Is_Private_Type
(Typ
) then
3139 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
3145 return Is_Fully_Initialized_Type
(U
);
3152 end Is_Fully_Initialized_Type
;
3154 ----------------------------
3155 -- Is_Inherited_Operation --
3156 ----------------------------
3158 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
3159 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
3162 pragma Assert
(Is_Overloadable
(E
));
3163 return Kind
= N_Full_Type_Declaration
3164 or else Kind
= N_Private_Extension_Declaration
3165 or else Kind
= N_Subtype_Declaration
3166 or else (Ekind
(E
) = E_Enumeration_Literal
3167 and then Is_Derived_Type
(Etype
(E
)));
3168 end Is_Inherited_Operation
;
3170 -----------------------------
3171 -- Is_Library_Level_Entity --
3172 -----------------------------
3174 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
3176 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
3177 end Is_Library_Level_Entity
;
3179 ---------------------------------
3180 -- Is_Local_Variable_Reference --
3181 ---------------------------------
3183 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
3185 if not Is_Entity_Name
(Expr
) then
3190 Ent
: constant Entity_Id
:= Entity
(Expr
);
3191 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
3194 if Ekind
(Ent
) /= E_Variable
3196 Ekind
(Ent
) /= E_In_Out_Parameter
3201 return Present
(Sub
) and then Sub
= Current_Subprogram
;
3205 end Is_Local_Variable_Reference
;
3207 -------------------------
3208 -- Is_Object_Reference --
3209 -------------------------
3211 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
3213 if Is_Entity_Name
(N
) then
3214 return Is_Object
(Entity
(N
));
3218 when N_Indexed_Component | N_Slice
=>
3219 return Is_Object_Reference
(Prefix
(N
));
3221 -- In Ada95, a function call is a constant object.
3223 when N_Function_Call
=>
3226 -- A reference to the stream attribute Input is a function call.
3228 when N_Attribute_Reference
=>
3229 return Attribute_Name
(N
) = Name_Input
;
3231 when N_Selected_Component
=>
3232 return Is_Object_Reference
(Selector_Name
(N
));
3234 when N_Explicit_Dereference
=>
3237 -- An unchecked type conversion is considered to be an object if
3238 -- the operand is an object (this construction arises only as a
3239 -- result of expansion activities).
3241 when N_Unchecked_Type_Conversion
=>
3248 end Is_Object_Reference
;
3250 -----------------------------------
3251 -- Is_OK_Variable_For_Out_Formal --
3252 -----------------------------------
3254 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
3256 Note_Possible_Modification
(AV
);
3258 -- We must reject parenthesized variable names. The check for
3259 -- Comes_From_Source is present because there are currently
3260 -- cases where the compiler violates this rule (e.g. passing
3261 -- a task object to its controlled Initialize routine).
3263 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
3266 -- A variable is always allowed
3268 elsif Is_Variable
(AV
) then
3271 -- Unchecked conversions are allowed only if they come from the
3272 -- generated code, which sometimes uses unchecked conversions for
3273 -- out parameters in cases where code generation is unaffected.
3274 -- We tell source unchecked conversions by seeing if they are
3275 -- rewrites of an original UC function call, or of an explicit
3276 -- conversion of a function call.
3278 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
3279 if Nkind
(Original_Node
(AV
)) = N_Function_Call
then
3282 elsif Comes_From_Source
(AV
)
3283 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
3291 -- Normal type conversions are allowed if argument is a variable
3293 elsif Nkind
(AV
) = N_Type_Conversion
then
3294 if Is_Variable
(Expression
(AV
))
3295 and then Paren_Count
(Expression
(AV
)) = 0
3297 Note_Possible_Modification
(Expression
(AV
));
3300 -- We also allow a non-parenthesized expression that raises
3301 -- constraint error if it rewrites what used to be a variable
3303 elsif Raises_Constraint_Error
(Expression
(AV
))
3304 and then Paren_Count
(Expression
(AV
)) = 0
3305 and then Is_Variable
(Original_Node
(Expression
(AV
)))
3309 -- Type conversion of something other than a variable
3315 -- If this node is rewritten, then test the original form, if that is
3316 -- OK, then we consider the rewritten node OK (for example, if the
3317 -- original node is a conversion, then Is_Variable will not be true
3318 -- but we still want to allow the conversion if it converts a variable.
3320 elsif Original_Node
(AV
) /= AV
then
3321 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
3323 -- All other non-variables are rejected
3328 end Is_OK_Variable_For_Out_Formal
;
3330 -----------------------------------
3331 -- Is_Partially_Initialized_Type --
3332 -----------------------------------
3334 function Is_Partially_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
3336 if Is_Scalar_Type
(Typ
) then
3339 elsif Is_Access_Type
(Typ
) then
3342 elsif Is_Array_Type
(Typ
) then
3344 -- If component type is partially initialized, so is array type
3346 if Is_Partially_Initialized_Type
(Component_Type
(Typ
)) then
3349 -- Otherwise we are only partially initialized if we are fully
3350 -- initialized (this is the empty array case, no point in us
3351 -- duplicating that code here).
3354 return Is_Fully_Initialized_Type
(Typ
);
3357 elsif Is_Record_Type
(Typ
) then
3359 -- A discriminated type is always partially initialized
3361 if Has_Discriminants
(Typ
) then
3364 -- A tagged type is always partially initialized
3366 elsif Is_Tagged_Type
(Typ
) then
3369 -- Case of non-discriminated record
3375 Component_Present
: Boolean := False;
3376 -- Set True if at least one component is present. If no
3377 -- components are present, then record type is fully
3378 -- initialized (another odd case, like the null array).
3381 -- Loop through components
3383 Ent
:= First_Entity
(Typ
);
3384 while Present
(Ent
) loop
3385 if Ekind
(Ent
) = E_Component
then
3386 Component_Present
:= True;
3388 -- If a component has an initialization expression then
3389 -- the enclosing record type is partially initialized
3391 if Present
(Parent
(Ent
))
3392 and then Present
(Expression
(Parent
(Ent
)))
3396 -- If a component is of a type which is itself partially
3397 -- initialized, then the enclosing record type is also.
3399 elsif Is_Partially_Initialized_Type
(Etype
(Ent
)) then
3407 -- No initialized components found. If we found any components
3408 -- they were all uninitialized so the result is false.
3410 if Component_Present
then
3413 -- But if we found no components, then all the components are
3414 -- initialized so we consider the type to be initialized.
3422 -- Concurrent types are always fully initialized
3424 elsif Is_Concurrent_Type
(Typ
) then
3427 -- For a private type, go to underlying type. If there is no underlying
3428 -- type then just assume this partially initialized. Not clear if this
3429 -- can happen in a non-error case, but no harm in testing for this.
3431 elsif Is_Private_Type
(Typ
) then
3433 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
3439 return Is_Partially_Initialized_Type
(U
);
3443 -- For any other type (are there any?) assume partially initialized
3448 end Is_Partially_Initialized_Type
;
3450 -----------------------------
3451 -- Is_RCI_Pkg_Spec_Or_Body --
3452 -----------------------------
3454 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
3456 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
3457 -- Return True if the unit of Cunit is an RCI package declaration
3459 ---------------------------
3460 -- Is_RCI_Pkg_Decl_Cunit --
3461 ---------------------------
3463 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
3464 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
3467 if Nkind
(The_Unit
) /= N_Package_Declaration
then
3470 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
3471 end Is_RCI_Pkg_Decl_Cunit
;
3473 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
3476 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
3478 (Nkind
(Unit
(Cunit
)) = N_Package_Body
3479 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
3480 end Is_RCI_Pkg_Spec_Or_Body
;
3482 -----------------------------------------
3483 -- Is_Remote_Access_To_Class_Wide_Type --
3484 -----------------------------------------
3486 function Is_Remote_Access_To_Class_Wide_Type
3492 function Comes_From_Limited_Private_Type_Declaration
3495 -- Check if the original declaration is a limited private one and
3496 -- if all the derivations have been using private extensions.
3498 -------------------------------------------------
3499 -- Comes_From_Limited_Private_Type_Declaration --
3500 -------------------------------------------------
3502 function Comes_From_Limited_Private_Type_Declaration
(E
: in Entity_Id
)
3505 N
: constant Node_Id
:= Declaration_Node
(E
);
3507 if Nkind
(N
) = N_Private_Type_Declaration
3508 and then Limited_Present
(N
)
3513 if Nkind
(N
) = N_Private_Extension_Declaration
then
3514 return Comes_From_Limited_Private_Type_Declaration
(Etype
(E
));
3518 end Comes_From_Limited_Private_Type_Declaration
;
3520 -- Start of processing for Is_Remote_Access_To_Class_Wide_Type
3523 if not (Is_Remote_Call_Interface
(E
)
3524 or else Is_Remote_Types
(E
))
3525 or else Ekind
(E
) /= E_General_Access_Type
3530 D
:= Designated_Type
(E
);
3532 if Ekind
(D
) /= E_Class_Wide_Type
then
3536 return Comes_From_Limited_Private_Type_Declaration
3537 (Defining_Identifier
(Parent
(D
)));
3538 end Is_Remote_Access_To_Class_Wide_Type
;
3540 -----------------------------------------
3541 -- Is_Remote_Access_To_Subprogram_Type --
3542 -----------------------------------------
3544 function Is_Remote_Access_To_Subprogram_Type
3549 return (Ekind
(E
) = E_Access_Subprogram_Type
3550 or else (Ekind
(E
) = E_Record_Type
3551 and then Present
(Corresponding_Remote_Type
(E
))))
3552 and then (Is_Remote_Call_Interface
(E
)
3553 or else Is_Remote_Types
(E
));
3554 end Is_Remote_Access_To_Subprogram_Type
;
3556 --------------------
3557 -- Is_Remote_Call --
3558 --------------------
3560 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
3562 if Nkind
(N
) /= N_Procedure_Call_Statement
3563 and then Nkind
(N
) /= N_Function_Call
3565 -- An entry call cannot be remote
3569 elsif Nkind
(Name
(N
)) in N_Has_Entity
3570 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
3572 -- A subprogram declared in the spec of a RCI package is remote
3576 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
3577 and then Is_Remote_Access_To_Subprogram_Type
3578 (Etype
(Prefix
(Name
(N
))))
3580 -- The dereference of a RAS is a remote call
3584 elsif Present
(Controlling_Argument
(N
))
3585 and then Is_Remote_Access_To_Class_Wide_Type
3586 (Etype
(Controlling_Argument
(N
)))
3588 -- Any primitive operation call with a controlling argument of
3589 -- a RACW type is a remote call.
3594 -- All other calls are local calls
3599 ----------------------
3600 -- Is_Selector_Name --
3601 ----------------------
3603 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
3606 if not Is_List_Member
(N
) then
3608 P
: constant Node_Id
:= Parent
(N
);
3609 K
: constant Node_Kind
:= Nkind
(P
);
3613 (K
= N_Expanded_Name
or else
3614 K
= N_Generic_Association
or else
3615 K
= N_Parameter_Association
or else
3616 K
= N_Selected_Component
)
3617 and then Selector_Name
(P
) = N
;
3622 L
: constant List_Id
:= List_Containing
(N
);
3623 P
: constant Node_Id
:= Parent
(L
);
3626 return (Nkind
(P
) = N_Discriminant_Association
3627 and then Selector_Names
(P
) = L
)
3629 (Nkind
(P
) = N_Component_Association
3630 and then Choices
(P
) = L
);
3633 end Is_Selector_Name
;
3639 function Is_Statement
(N
: Node_Id
) return Boolean is
3642 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
3643 or else Nkind
(N
) = N_Procedure_Call_Statement
;
3650 function Is_Transfer
(N
: Node_Id
) return Boolean is
3651 Kind
: constant Node_Kind
:= Nkind
(N
);
3654 if Kind
= N_Return_Statement
3656 Kind
= N_Goto_Statement
3658 Kind
= N_Raise_Statement
3660 Kind
= N_Requeue_Statement
3664 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
3665 and then No
(Condition
(N
))
3669 elsif Kind
= N_Procedure_Call_Statement
3670 and then Is_Entity_Name
(Name
(N
))
3671 and then Present
(Entity
(Name
(N
)))
3672 and then No_Return
(Entity
(Name
(N
)))
3676 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
3688 function Is_True
(U
: Uint
) return Boolean is
3697 function Is_Variable
(N
: Node_Id
) return Boolean is
3699 Orig_Node
: constant Node_Id
:= Original_Node
(N
);
3700 -- We do the test on the original node, since this is basically a
3701 -- test of syntactic categories, so it must not be disturbed by
3702 -- whatever rewriting might have occurred. For example, an aggregate,
3703 -- which is certainly NOT a variable, could be turned into a variable
3706 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
3707 -- Within a protected function, the private components of the
3708 -- enclosing protected type are constants. A function nested within
3709 -- a (protected) procedure is not itself protected.
3711 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
3712 -- Prefixes can involve implicit dereferences, in which case we
3713 -- must test for the case of a reference of a constant access
3714 -- type, which can never be a variable.
3716 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
3717 Prot
: constant Entity_Id
:= Scope
(E
);
3721 if not Is_Protected_Type
(Prot
) then
3726 while Present
(S
) and then S
/= Prot
loop
3728 if Ekind
(S
) = E_Function
3729 and then Scope
(S
) = Prot
3739 end In_Protected_Function
;
3741 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
3743 if Is_Access_Type
(Etype
(P
)) then
3744 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
3746 return Is_Variable
(P
);
3748 end Is_Variable_Prefix
;
3750 -- Start of processing for Is_Variable
3753 -- Definitely OK if Assignment_OK is set. Since this is something that
3754 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
3756 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
3759 -- Normally we go to the original node, but there is one exception
3760 -- where we use the rewritten node, namely when it is an explicit
3761 -- dereference. The generated code may rewrite a prefix which is an
3762 -- access type with an explicit dereference. The dereference is a
3763 -- variable, even though the original node may not be (since it could
3764 -- be a constant of the access type).
3766 elsif Nkind
(N
) = N_Explicit_Dereference
3767 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
3768 and then Is_Access_Type
(Etype
(Orig_Node
))
3770 return Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
3772 -- All remaining checks use the original node
3774 elsif Is_Entity_Name
(Orig_Node
) then
3776 E
: constant Entity_Id
:= Entity
(Orig_Node
);
3777 K
: constant Entity_Kind
:= Ekind
(E
);
3780 return (K
= E_Variable
3781 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
3782 or else (K
= E_Component
3783 and then not In_Protected_Function
(E
))
3784 or else K
= E_Out_Parameter
3785 or else K
= E_In_Out_Parameter
3786 or else K
= E_Generic_In_Out_Parameter
3788 -- Current instance of type:
3790 or else (Is_Type
(E
) and then In_Open_Scopes
(E
))
3791 or else (Is_Incomplete_Or_Private_Type
(E
)
3792 and then In_Open_Scopes
(Full_View
(E
)));
3796 case Nkind
(Orig_Node
) is
3797 when N_Indexed_Component | N_Slice
=>
3798 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
3800 when N_Selected_Component
=>
3801 return Is_Variable_Prefix
(Prefix
(Orig_Node
))
3802 and then Is_Variable
(Selector_Name
(Orig_Node
));
3804 -- For an explicit dereference, we must check whether the type
3805 -- is ACCESS CONSTANT, since if it is, then it is not a variable.
3807 when N_Explicit_Dereference
=>
3808 return Is_Access_Type
(Etype
(Prefix
(Orig_Node
)))
3810 Is_Access_Constant
(Root_Type
(Etype
(Prefix
(Orig_Node
))));
3812 -- The type conversion is the case where we do not deal with the
3813 -- context dependent special case of an actual parameter. Thus
3814 -- the type conversion is only considered a variable for the
3815 -- purposes of this routine if the target type is tagged. However,
3816 -- a type conversion is considered to be a variable if it does not
3817 -- come from source (this deals for example with the conversions
3818 -- of expressions to their actual subtypes).
3820 when N_Type_Conversion
=>
3821 return Is_Variable
(Expression
(Orig_Node
))
3823 (not Comes_From_Source
(Orig_Node
)
3825 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
3827 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
3829 -- GNAT allows an unchecked type conversion as a variable. This
3830 -- only affects the generation of internal expanded code, since
3831 -- calls to instantiations of Unchecked_Conversion are never
3832 -- considered variables (since they are function calls).
3833 -- This is also true for expression actions.
3835 when N_Unchecked_Type_Conversion
=>
3836 return Is_Variable
(Expression
(Orig_Node
));
3844 ------------------------
3845 -- Is_Volatile_Object --
3846 ------------------------
3848 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
3850 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
3851 -- Determines if given object has volatile components
3853 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
3854 -- If prefix is an implicit dereference, examine designated type.
3856 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
3858 if Is_Access_Type
(Etype
(N
)) then
3859 return Has_Volatile_Components
(Designated_Type
(Etype
(N
)));
3861 return Object_Has_Volatile_Components
(N
);
3863 end Is_Volatile_Prefix
;
3865 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
3867 if Is_Volatile
(Etype
(N
))
3868 or else Has_Volatile_Components
(Etype
(N
))
3872 elsif Is_Entity_Name
(N
)
3873 and then (Has_Volatile_Components
(Entity
(N
))
3874 or else Is_Volatile
(Entity
(N
)))
3878 elsif Nkind
(N
) = N_Indexed_Component
3879 or else Nkind
(N
) = N_Selected_Component
3881 return Is_Volatile_Prefix
(Prefix
(N
));
3886 end Object_Has_Volatile_Components
;
3888 -- Start of processing for Is_Volatile_Object
3891 if Is_Volatile
(Etype
(N
))
3892 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
3896 elsif Nkind
(N
) = N_Indexed_Component
3897 or else Nkind
(N
) = N_Selected_Component
3899 return Is_Volatile_Prefix
(Prefix
(N
));
3904 end Is_Volatile_Object
;
3906 --------------------------
3907 -- Kill_Size_Check_Code --
3908 --------------------------
3910 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
3912 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
3913 and then Present
(Size_Check_Code
(E
))
3915 Remove
(Size_Check_Code
(E
));
3916 Set_Size_Check_Code
(E
, Empty
);
3918 end Kill_Size_Check_Code
;
3920 -------------------------
3921 -- New_External_Entity --
3922 -------------------------
3924 function New_External_Entity
3925 (Kind
: Entity_Kind
;
3926 Scope_Id
: Entity_Id
;
3927 Sloc_Value
: Source_Ptr
;
3928 Related_Id
: Entity_Id
;
3930 Suffix_Index
: Nat
:= 0;
3931 Prefix
: Character := ' ')
3934 N
: constant Entity_Id
:=
3935 Make_Defining_Identifier
(Sloc_Value
,
3937 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
3940 Set_Ekind
(N
, Kind
);
3941 Set_Is_Internal
(N
, True);
3942 Append_Entity
(N
, Scope_Id
);
3943 Set_Public_Status
(N
);
3945 if Kind
in Type_Kind
then
3946 Init_Size_Align
(N
);
3950 end New_External_Entity
;
3952 -------------------------
3953 -- New_Internal_Entity --
3954 -------------------------
3956 function New_Internal_Entity
3957 (Kind
: Entity_Kind
;
3958 Scope_Id
: Entity_Id
;
3959 Sloc_Value
: Source_Ptr
;
3960 Id_Char
: Character)
3963 N
: constant Entity_Id
:=
3964 Make_Defining_Identifier
(Sloc_Value
, New_Internal_Name
(Id_Char
));
3967 Set_Ekind
(N
, Kind
);
3968 Set_Is_Internal
(N
, True);
3969 Append_Entity
(N
, Scope_Id
);
3971 if Kind
in Type_Kind
then
3972 Init_Size_Align
(N
);
3976 end New_Internal_Entity
;
3982 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
3986 -- If we are pointing at a positional parameter, it is a member of
3987 -- a node list (the list of parameters), and the next parameter
3988 -- is the next node on the list, unless we hit a parameter
3989 -- association, in which case we shift to using the chain whose
3990 -- head is the First_Named_Actual in the parent, and then is
3991 -- threaded using the Next_Named_Actual of the Parameter_Association.
3992 -- All this fiddling is because the original node list is in the
3993 -- textual call order, and what we need is the declaration order.
3995 if Is_List_Member
(Actual_Id
) then
3996 N
:= Next
(Actual_Id
);
3998 if Nkind
(N
) = N_Parameter_Association
then
3999 return First_Named_Actual
(Parent
(Actual_Id
));
4005 return Next_Named_Actual
(Parent
(Actual_Id
));
4009 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
4011 Actual_Id
:= Next_Actual
(Actual_Id
);
4014 -----------------------
4015 -- Normalize_Actuals --
4016 -----------------------
4018 -- Chain actuals according to formals of subprogram. If there are
4019 -- no named associations, the chain is simply the list of Parameter
4020 -- Associations, since the order is the same as the declaration order.
4021 -- If there are named associations, then the First_Named_Actual field
4022 -- in the N_Procedure_Call_Statement node or N_Function_Call node
4023 -- points to the Parameter_Association node for the parameter that
4024 -- comes first in declaration order. The remaining named parameters
4025 -- are then chained in declaration order using Next_Named_Actual.
4027 -- This routine also verifies that the number of actuals is compatible
4028 -- with the number and default values of formals, but performs no type
4029 -- checking (type checking is done by the caller).
4031 -- If the matching succeeds, Success is set to True, and the caller
4032 -- proceeds with type-checking. If the match is unsuccessful, then
4033 -- Success is set to False, and the caller attempts a different
4034 -- interpretation, if there is one.
4036 -- If the flag Report is on, the call is not overloaded, and a failure
4037 -- to match can be reported here, rather than in the caller.
4039 procedure Normalize_Actuals
4043 Success
: out Boolean)
4045 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
4046 Actual
: Node_Id
:= Empty
;
4048 Last
: Node_Id
:= Empty
;
4049 First_Named
: Node_Id
:= Empty
;
4052 Formals_To_Match
: Integer := 0;
4053 Actuals_To_Match
: Integer := 0;
4055 procedure Chain
(A
: Node_Id
);
4056 -- Add named actual at the proper place in the list, using the
4057 -- Next_Named_Actual link.
4059 function Reporting
return Boolean;
4060 -- Determines if an error is to be reported. To report an error, we
4061 -- need Report to be True, and also we do not report errors caused
4062 -- by calls to Init_Proc's that occur within other Init_Proc's. Such
4063 -- errors must always be cascaded errors, since if all the types are
4064 -- declared correctly, the compiler will certainly build decent calls!
4066 procedure Chain
(A
: Node_Id
) is
4070 -- Call node points to first actual in list.
4072 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
4075 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
4079 Set_Next_Named_Actual
(Last
, Empty
);
4082 function Reporting
return Boolean is
4087 elsif not Within_Init_Proc
then
4090 elsif Chars
(Entity
(Name
(N
))) = Name_uInit_Proc
then
4098 -- Start of processing for Normalize_Actuals
4101 if Is_Access_Type
(S
) then
4103 -- The name in the call is a function call that returns an access
4104 -- to subprogram. The designated type has the list of formals.
4106 Formal
:= First_Formal
(Designated_Type
(S
));
4108 Formal
:= First_Formal
(S
);
4111 while Present
(Formal
) loop
4112 Formals_To_Match
:= Formals_To_Match
+ 1;
4113 Next_Formal
(Formal
);
4116 -- Find if there is a named association, and verify that no positional
4117 -- associations appear after named ones.
4119 if Present
(Actuals
) then
4120 Actual
:= First
(Actuals
);
4123 while Present
(Actual
)
4124 and then Nkind
(Actual
) /= N_Parameter_Association
4126 Actuals_To_Match
:= Actuals_To_Match
+ 1;
4130 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
4132 -- Most common case: positional notation, no defaults
4137 elsif Actuals_To_Match
> Formals_To_Match
then
4139 -- Too many actuals: will not work.
4142 Error_Msg_N
("too many arguments in call", N
);
4149 First_Named
:= Actual
;
4151 while Present
(Actual
) loop
4152 if Nkind
(Actual
) /= N_Parameter_Association
then
4154 ("positional parameters not allowed after named ones", Actual
);
4159 Actuals_To_Match
:= Actuals_To_Match
+ 1;
4165 if Present
(Actuals
) then
4166 Actual
:= First
(Actuals
);
4169 Formal
:= First_Formal
(S
);
4171 while Present
(Formal
) loop
4173 -- Match the formals in order. If the corresponding actual
4174 -- is positional, nothing to do. Else scan the list of named
4175 -- actuals to find the one with the right name.
4178 and then Nkind
(Actual
) /= N_Parameter_Association
4181 Actuals_To_Match
:= Actuals_To_Match
- 1;
4182 Formals_To_Match
:= Formals_To_Match
- 1;
4185 -- For named parameters, search the list of actuals to find
4186 -- one that matches the next formal name.
4188 Actual
:= First_Named
;
4191 while Present
(Actual
) loop
4192 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
4195 Actuals_To_Match
:= Actuals_To_Match
- 1;
4196 Formals_To_Match
:= Formals_To_Match
- 1;
4204 if Ekind
(Formal
) /= E_In_Parameter
4205 or else No
(Default_Value
(Formal
))
4208 if Comes_From_Source
(S
)
4209 and then Is_Overloadable
(S
)
4211 Error_Msg_Name_1
:= Chars
(S
);
4212 Error_Msg_Sloc
:= Sloc
(S
);
4214 ("missing argument for parameter & " &
4215 "in call to % declared #", N
, Formal
);
4218 ("missing argument for parameter &", N
, Formal
);
4226 Formals_To_Match
:= Formals_To_Match
- 1;
4231 Next_Formal
(Formal
);
4234 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
4241 -- Find some superfluous named actual that did not get
4242 -- attached to the list of associations.
4244 Actual
:= First
(Actuals
);
4246 while Present
(Actual
) loop
4248 if Nkind
(Actual
) = N_Parameter_Association
4249 and then Actual
/= Last
4250 and then No
(Next_Named_Actual
(Actual
))
4252 Error_Msg_N
("Unmatched actual in call", Actual
);
4263 end Normalize_Actuals
;
4265 --------------------------------
4266 -- Note_Possible_Modification --
4267 --------------------------------
4269 procedure Note_Possible_Modification
(N
: Node_Id
) is
4273 procedure Set_Ref
(E
: Entity_Id
; N
: Node_Id
);
4274 -- Internal routine to note modification on entity E by node N
4276 procedure Set_Ref
(E
: Entity_Id
; N
: Node_Id
) is
4278 Set_Not_Source_Assigned
(E
, False);
4279 Set_Is_True_Constant
(E
, False);
4280 Generate_Reference
(E
, N
, 'm');
4283 -- Start of processing for Note_Possible_Modification
4286 -- Loop to find referenced entity, if there is one
4290 -- Test for node rewritten as dereference (e.g. accept parameter)
4292 if Nkind
(Exp
) = N_Explicit_Dereference
4293 and then Is_Entity_Name
(Original_Node
(Exp
))
4295 Set_Ref
(Entity
(Original_Node
(Exp
)), Original_Node
(Exp
));
4298 elsif Is_Entity_Name
(Exp
) then
4299 Ent
:= Entity
(Exp
);
4301 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
4302 and then Present
(Renamed_Object
(Ent
))
4304 Exp
:= Renamed_Object
(Ent
);
4311 elsif Nkind
(Exp
) = N_Type_Conversion
4312 or else Nkind
(Exp
) = N_Unchecked_Type_Conversion
4314 Exp
:= Expression
(Exp
);
4316 elsif Nkind
(Exp
) = N_Slice
4317 or else Nkind
(Exp
) = N_Indexed_Component
4318 or else Nkind
(Exp
) = N_Selected_Component
4320 Exp
:= Prefix
(Exp
);
4326 end Note_Possible_Modification
;
4328 -------------------------
4329 -- Object_Access_Level --
4330 -------------------------
4332 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
4335 -- Returns the static accessibility level of the view denoted
4336 -- by Obj. Note that the value returned is the result of a
4337 -- call to Scope_Depth. Only scope depths associated with
4338 -- dynamic scopes can actually be returned. Since only
4339 -- relative levels matter for accessibility checking, the fact
4340 -- that the distance between successive levels of accessibility
4341 -- is not always one is immaterial (invariant: if level(E2) is
4342 -- deeper than level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
4345 if Is_Entity_Name
(Obj
) then
4348 -- If E is a type then it denotes a current instance.
4349 -- For this case we add one to the normal accessibility
4350 -- level of the type to ensure that current instances
4351 -- are treated as always being deeper than than the level
4352 -- of any visible named access type (see 3.10.2(21)).
4355 return Type_Access_Level
(E
) + 1;
4357 elsif Present
(Renamed_Object
(E
)) then
4358 return Object_Access_Level
(Renamed_Object
(E
));
4360 -- Similarly, if E is a component of the current instance of a
4361 -- protected type, any instance of it is assumed to be at a deeper
4362 -- level than the type. For a protected object (whose type is an
4363 -- anonymous protected type) its components are at the same level
4364 -- as the type itself.
4366 elsif not Is_Overloadable
(E
)
4367 and then Ekind
(Scope
(E
)) = E_Protected_Type
4368 and then Comes_From_Source
(Scope
(E
))
4370 return Type_Access_Level
(Scope
(E
)) + 1;
4373 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
4376 elsif Nkind
(Obj
) = N_Selected_Component
then
4377 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
4378 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
4380 return Object_Access_Level
(Prefix
(Obj
));
4383 elsif Nkind
(Obj
) = N_Indexed_Component
then
4384 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
4385 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
4387 return Object_Access_Level
(Prefix
(Obj
));
4390 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
4392 -- If the prefix is a selected access discriminant then
4393 -- we make a recursive call on the prefix, which will
4394 -- in turn check the level of the prefix object of
4395 -- the selected discriminant.
4397 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
4398 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
4400 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
4402 return Object_Access_Level
(Prefix
(Obj
));
4404 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
4407 elsif Nkind
(Obj
) = N_Type_Conversion
then
4408 return Object_Access_Level
(Expression
(Obj
));
4410 -- Function results are objects, so we get either the access level
4411 -- of the function or, in the case of an indirect call, the level of
4412 -- of the access-to-subprogram type.
4414 elsif Nkind
(Obj
) = N_Function_Call
then
4415 if Is_Entity_Name
(Name
(Obj
)) then
4416 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
4418 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
4421 -- For convenience we handle qualified expressions, even though
4422 -- they aren't technically object names.
4424 elsif Nkind
(Obj
) = N_Qualified_Expression
then
4425 return Object_Access_Level
(Expression
(Obj
));
4427 -- Otherwise return the scope level of Standard.
4428 -- (If there are cases that fall through
4429 -- to this point they will be treated as
4430 -- having global accessibility for now. ???)
4433 return Scope_Depth
(Standard_Standard
);
4435 end Object_Access_Level
;
4437 -----------------------
4438 -- Private_Component --
4439 -----------------------
4441 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
4442 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
4444 function Trace_Components
4448 -- Recursive function that does the work, and checks against circular
4449 -- definition for each subcomponent type.
4451 ----------------------
4452 -- Trace_Components --
4453 ----------------------
4455 function Trace_Components
4457 Check
: Boolean) return Entity_Id
4459 Btype
: constant Entity_Id
:= Base_Type
(T
);
4460 Component
: Entity_Id
;
4462 Candidate
: Entity_Id
:= Empty
;
4465 if Check
and then Btype
= Ancestor
then
4466 Error_Msg_N
("circular type definition", Type_Id
);
4470 if Is_Private_Type
(Btype
)
4471 and then not Is_Generic_Type
(Btype
)
4475 elsif Is_Array_Type
(Btype
) then
4476 return Trace_Components
(Component_Type
(Btype
), True);
4478 elsif Is_Record_Type
(Btype
) then
4479 Component
:= First_Entity
(Btype
);
4480 while Present
(Component
) loop
4482 -- skip anonymous types generated by constrained components.
4484 if not Is_Type
(Component
) then
4485 P
:= Trace_Components
(Etype
(Component
), True);
4488 if P
= Any_Type
then
4496 Next_Entity
(Component
);
4504 end Trace_Components
;
4506 -- Start of processing for Private_Component
4509 return Trace_Components
(Type_Id
, False);
4510 end Private_Component
;
4512 -----------------------
4513 -- Process_End_Label --
4514 -----------------------
4516 procedure Process_End_Label
4524 Label_Ref
: Boolean;
4525 -- Set True if reference to end label itself is required
4528 -- Gets set to the operator symbol or identifier that references
4529 -- the entity Ent. For the child unit case, this is the identifier
4530 -- from the designator. For other cases, this is simply Endl.
4532 procedure Generate_Parent_Ref
(N
: Node_Id
);
4533 -- N is an identifier node that appears as a parent unit reference
4534 -- in the case where Ent is a child unit. This procedure generates
4535 -- an appropriate cross-reference entry.
4537 -------------------------
4538 -- Generate_Parent_Ref --
4539 -------------------------
4541 procedure Generate_Parent_Ref
(N
: Node_Id
) is
4542 Parent_Ent
: Entity_Id
;
4545 -- Search up scope stack. The reason we do this is that normal
4546 -- visibility analysis would not work for two reasons. First in
4547 -- some subunit cases, the entry for the parent unit may not be
4548 -- visible, and in any case there can be a local entity that
4549 -- hides the scope entity.
4551 Parent_Ent
:= Current_Scope
;
4552 while Present
(Parent_Ent
) loop
4553 if Chars
(Parent_Ent
) = Chars
(N
) then
4555 -- Generate the reference. We do NOT consider this as a
4556 -- reference for unreferenced symbol purposes, but we do
4557 -- force a cross-reference even if the end line does not
4558 -- come from source (the caller already generated the
4559 -- appropriate Typ for this situation).
4562 (Parent_Ent
, N
, 'r', Set_Ref
=> False, Force
=> True);
4563 Style
.Check_Identifier
(N
, Parent_Ent
);
4567 Parent_Ent
:= Scope
(Parent_Ent
);
4570 -- Fall through means entity was not found -- that's odd, but
4571 -- the appropriate thing is simply to ignore and not generate
4572 -- any cross-reference for this entry.
4575 end Generate_Parent_Ref
;
4577 -- Start of processing for Process_End_Label
4580 -- If no node, ignore. This happens in some error situations,
4581 -- and also for some internally generated structures where no
4582 -- end label references are required in any case.
4588 -- Nothing to do if no End_Label, happens for internally generated
4589 -- constructs where we don't want an end label reference anyway.
4590 -- Also nothing to do if Endl is a string literal, which means
4591 -- there was some prior error (bad operator symbol)
4593 Endl
:= End_Label
(N
);
4595 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
4599 -- Reference node is not in extended main source unit
4601 if not In_Extended_Main_Source_Unit
(N
) then
4603 -- Generally we do not collect references except for the
4604 -- extended main source unit. The one exception is the 'e'
4605 -- entry for a package spec, where it is useful for a client
4606 -- to have the ending information to define scopes.
4614 -- For this case, we can ignore any parent references,
4615 -- but we need the package name itself for the 'e' entry.
4617 if Nkind
(Endl
) = N_Designator
then
4618 Endl
:= Identifier
(Endl
);
4622 -- Reference is in extended main source unit
4627 -- For designator, generate references for the parent entries
4629 if Nkind
(Endl
) = N_Designator
then
4631 -- Generate references for the prefix if the END line comes
4632 -- from source (otherwise we do not need these references)
4634 if Comes_From_Source
(Endl
) then
4636 while Nkind
(Nam
) = N_Selected_Component
loop
4637 Generate_Parent_Ref
(Selector_Name
(Nam
));
4638 Nam
:= Prefix
(Nam
);
4641 Generate_Parent_Ref
(Nam
);
4644 Endl
:= Identifier
(Endl
);
4648 -- If the end label is not for the given entity, then either we have
4649 -- some previous error, or this is a generic instantiation for which
4650 -- we do not need to make a cross-reference in this case anyway. In
4651 -- either case we simply ignore the call.
4653 if Chars
(Ent
) /= Chars
(Endl
) then
4657 -- If label was really there, then generate a normal reference
4658 -- and then adjust the location in the end label to point past
4659 -- the name (which should almost always be the semicolon).
4663 if Comes_From_Source
(Endl
) then
4665 -- If a label reference is required, then do the style check
4666 -- and generate an l-type cross-reference entry for the label
4669 Style
.Check_Identifier
(Endl
, Ent
);
4670 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
4673 -- Set the location to point past the label (normally this will
4674 -- mean the semicolon immediately following the label). This is
4675 -- done for the sake of the 'e' or 't' entry generated below.
4677 Get_Decoded_Name_String
(Chars
(Endl
));
4678 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
4681 -- Now generate the e/t reference
4683 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
4685 -- Restore Sloc, in case modified above, since we have an identifier
4686 -- and the normal Sloc should be left set in the tree.
4688 Set_Sloc
(Endl
, Loc
);
4689 end Process_End_Label
;
4695 -- We do the conversion to get the value of the real string by using
4696 -- the scanner, see Sinput for details on use of the internal source
4697 -- buffer for scanning internal strings.
4699 function Real_Convert
(S
: String) return Node_Id
is
4700 Save_Src
: constant Source_Buffer_Ptr
:= Source
;
4704 Source
:= Internal_Source_Ptr
;
4707 for J
in S
'Range loop
4708 Source
(Source_Ptr
(J
)) := S
(J
);
4711 Source
(S
'Length + 1) := EOF
;
4713 if Source
(Scan_Ptr
) = '-' then
4715 Scan_Ptr
:= Scan_Ptr
+ 1;
4723 Set_Realval
(Token_Node
, UR_Negate
(Realval
(Token_Node
)));
4730 ------------------------------
4731 -- Requires_Transient_Scope --
4732 ------------------------------
4734 -- A transient scope is required when variable-sized temporaries are
4735 -- allocated in the primary or secondary stack, or when finalization
4736 -- actions must be generated before the next instruction
4738 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
4739 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
4742 -- This is a private type which is not completed yet. This can only
4743 -- happen in a default expression (of a formal parameter or of a
4744 -- record component). Do not expand transient scope in this case
4749 elsif Typ
= Standard_Void_Type
then
4752 -- The back-end has trouble allocating variable-size temporaries so
4753 -- we generate them in the front-end and need a transient scope to
4754 -- reclaim them properly
4756 elsif not Size_Known_At_Compile_Time
(Typ
) then
4759 -- Unconstrained discriminated records always require a variable
4760 -- length temporary, since the length may depend on the variant.
4762 elsif Is_Record_Type
(Typ
)
4763 and then Has_Discriminants
(Typ
)
4764 and then not Is_Constrained
(Typ
)
4768 -- Functions returning tagged types may dispatch on result so their
4769 -- returned value is allocated on the secondary stack. Controlled
4770 -- type temporaries need finalization.
4772 elsif Is_Tagged_Type
(Typ
)
4773 or else Has_Controlled_Component
(Typ
)
4777 -- Unconstrained array types are returned on the secondary stack
4779 elsif Is_Array_Type
(Typ
) then
4780 return not Is_Constrained
(Typ
);
4784 end Requires_Transient_Scope
;
4786 --------------------------
4787 -- Reset_Analyzed_Flags --
4788 --------------------------
4790 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
4792 function Clear_Analyzed
4794 return Traverse_Result
;
4795 -- Function used to reset Analyzed flags in tree. Note that we do
4796 -- not reset Analyzed flags in entities, since there is no need to
4797 -- renalalyze entities, and indeed, it is wrong to do so, since it
4798 -- can result in generating auxiliary stuff more than once.
4800 function Clear_Analyzed
4802 return Traverse_Result
4805 if not Has_Extension
(N
) then
4806 Set_Analyzed
(N
, False);
4812 function Reset_Analyzed
is
4813 new Traverse_Func
(Clear_Analyzed
);
4815 Discard
: Traverse_Result
;
4817 -- Start of processing for Reset_Analyzed_Flags
4820 Discard
:= Reset_Analyzed
(N
);
4821 end Reset_Analyzed_Flags
;
4827 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
4828 K1
: constant Node_Kind
:= Nkind
(N1
);
4829 K2
: constant Node_Kind
:= Nkind
(N2
);
4832 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
4833 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
4835 return Chars
(N1
) = Chars
(N2
);
4837 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
4838 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
4840 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
4841 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
4852 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
4857 elsif not Is_Constrained
(T1
)
4858 and then not Is_Constrained
(T2
)
4859 and then Base_Type
(T1
) = Base_Type
(T2
)
4863 -- For now don't bother with case of identical constraints, to be
4864 -- fiddled with later on perhaps (this is only used for optimization
4865 -- purposes, so it is not critical to do a best possible job)
4872 ------------------------
4873 -- Scope_Is_Transient --
4874 ------------------------
4876 function Scope_Is_Transient
return Boolean is
4878 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
4879 end Scope_Is_Transient
;
4885 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
4890 while Scop
/= Standard_Standard
loop
4891 Scop
:= Scope
(Scop
);
4893 if Scop
= Scope2
then
4901 --------------------------
4902 -- Scope_Within_Or_Same --
4903 --------------------------
4905 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
4910 while Scop
/= Standard_Standard
loop
4911 if Scop
= Scope2
then
4914 Scop
:= Scope
(Scop
);
4919 end Scope_Within_Or_Same
;
4921 ------------------------
4922 -- Set_Current_Entity --
4923 ------------------------
4925 -- The given entity is to be set as the currently visible definition
4926 -- of its associated name (i.e. the Node_Id associated with its name).
4927 -- All we have to do is to get the name from the identifier, and
4928 -- then set the associated Node_Id to point to the given entity.
4930 procedure Set_Current_Entity
(E
: Entity_Id
) is
4932 Set_Name_Entity_Id
(Chars
(E
), E
);
4933 end Set_Current_Entity
;
4935 ---------------------------------
4936 -- Set_Entity_With_Style_Check --
4937 ---------------------------------
4939 procedure Set_Entity_With_Style_Check
(N
: Node_Id
; Val
: Entity_Id
) is
4940 Val_Actual
: Entity_Id
;
4944 Set_Entity
(N
, Val
);
4947 and then not Suppress_Style_Checks
(Val
)
4948 and then not In_Instance
4950 if Nkind
(N
) = N_Identifier
then
4953 elsif Nkind
(N
) = N_Expanded_Name
then
4954 Nod
:= Selector_Name
(N
);
4962 -- A special situation arises for derived operations, where we want
4963 -- to do the check against the parent (since the Sloc of the derived
4964 -- operation points to the derived type declaration itself).
4966 while not Comes_From_Source
(Val_Actual
)
4967 and then Nkind
(Val_Actual
) in N_Entity
4968 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
4969 or else Ekind
(Val_Actual
) = E_Function
4970 or else Ekind
(Val_Actual
) = E_Generic_Function
4971 or else Ekind
(Val_Actual
) = E_Procedure
4972 or else Ekind
(Val_Actual
) = E_Generic_Procedure
)
4973 and then Present
(Alias
(Val_Actual
))
4975 Val_Actual
:= Alias
(Val_Actual
);
4978 -- Renaming declarations for generic actuals do not come from source,
4979 -- and have a different name from that of the entity they rename, so
4980 -- there is no style check to perform here.
4982 if Chars
(Nod
) = Chars
(Val_Actual
) then
4983 Style
.Check_Identifier
(Nod
, Val_Actual
);
4988 Set_Entity
(N
, Val
);
4989 end Set_Entity_With_Style_Check
;
4991 ------------------------
4992 -- Set_Name_Entity_Id --
4993 ------------------------
4995 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
4997 Set_Name_Table_Info
(Id
, Int
(Val
));
4998 end Set_Name_Entity_Id
;
5000 ---------------------
5001 -- Set_Next_Actual --
5002 ---------------------
5004 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
5006 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
5007 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
5009 end Set_Next_Actual
;
5011 -----------------------
5012 -- Set_Public_Status --
5013 -----------------------
5015 procedure Set_Public_Status
(Id
: Entity_Id
) is
5016 S
: constant Entity_Id
:= Current_Scope
;
5019 if S
= Standard_Standard
5020 or else (Is_Public
(S
)
5021 and then (Ekind
(S
) = E_Package
5022 or else Is_Record_Type
(S
)
5023 or else Ekind
(S
) = E_Void
))
5027 -- The bounds of an entry family declaration can generate object
5028 -- declarations that are visible to the back-end, e.g. in the
5029 -- the declaration of a composite type that contains tasks.
5032 and then Is_Concurrent_Type
(S
)
5033 and then not Has_Completion
(S
)
5034 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
5038 end Set_Public_Status
;
5040 ----------------------------
5041 -- Set_Scope_Is_Transient --
5042 ----------------------------
5044 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
5046 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
5047 end Set_Scope_Is_Transient
;
5053 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
5055 -- We copy Esize, but not RM_Size, since in general RM_Size is
5056 -- subtype specific and does not get inherited by all subtypes.
5058 Set_Esize
(T1
, Esize
(T2
));
5059 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
5061 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
5063 Is_Discrete_Or_Fixed_Point_Type
(T2
)
5065 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
5068 Set_Alignment
(T1
, Alignment
(T2
));
5071 --------------------
5072 -- Static_Integer --
5073 --------------------
5075 function Static_Integer
(N
: Node_Id
) return Uint
is
5077 Analyze_And_Resolve
(N
, Any_Integer
);
5080 or else Error_Posted
(N
)
5081 or else Etype
(N
) = Any_Type
5086 if Is_Static_Expression
(N
) then
5087 if not Raises_Constraint_Error
(N
) then
5088 return Expr_Value
(N
);
5093 elsif Etype
(N
) = Any_Type
then
5097 Error_Msg_N
("static integer expression required here", N
);
5102 --------------------------
5103 -- Statically_Different --
5104 --------------------------
5106 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
5107 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
5108 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
5111 return Is_Entity_Name
(R1
)
5112 and then Is_Entity_Name
(R2
)
5113 and then Entity
(R1
) /= Entity
(R2
)
5114 and then not Is_Formal
(Entity
(R1
))
5115 and then not Is_Formal
(Entity
(R2
));
5116 end Statically_Different
;
5118 -----------------------------
5119 -- Subprogram_Access_Level --
5120 -----------------------------
5122 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
5124 if Present
(Alias
(Subp
)) then
5125 return Subprogram_Access_Level
(Alias
(Subp
));
5127 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
5129 end Subprogram_Access_Level
;
5135 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
5137 if Debug_Flag_W
then
5138 for J
in 0 .. Scope_Stack
.Last
loop
5143 Write_Name
(Chars
(E
));
5144 Write_Str
(" line ");
5145 Write_Int
(Int
(Get_Logical_Line_Number
(Sloc
(N
))));
5150 -----------------------
5151 -- Transfer_Entities --
5152 -----------------------
5154 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
5155 Ent
: Entity_Id
:= First_Entity
(From
);
5162 if (Last_Entity
(To
)) = Empty
then
5163 Set_First_Entity
(To
, Ent
);
5165 Set_Next_Entity
(Last_Entity
(To
), Ent
);
5168 Set_Last_Entity
(To
, Last_Entity
(From
));
5170 while Present
(Ent
) loop
5171 Set_Scope
(Ent
, To
);
5173 if not Is_Public
(Ent
) then
5174 Set_Public_Status
(Ent
);
5177 and then Ekind
(Ent
) = E_Record_Subtype
5180 -- The components of the propagated Itype must be public
5187 Comp
:= First_Entity
(Ent
);
5189 while Present
(Comp
) loop
5190 Set_Is_Public
(Comp
);
5200 Set_First_Entity
(From
, Empty
);
5201 Set_Last_Entity
(From
, Empty
);
5202 end Transfer_Entities
;
5204 -----------------------
5205 -- Type_Access_Level --
5206 -----------------------
5208 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
5209 Btyp
: Entity_Id
:= Base_Type
(Typ
);
5212 -- If the type is an anonymous access type we treat it as being
5213 -- declared at the library level to ensure that names such as
5214 -- X.all'access don't fail static accessibility checks.
5216 if Ekind
(Btyp
) in Access_Kind
then
5217 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
5218 return Scope_Depth
(Standard_Standard
);
5221 Btyp
:= Root_Type
(Btyp
);
5224 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
5225 end Type_Access_Level
;
5227 --------------------------
5228 -- Unit_Declaration_Node --
5229 --------------------------
5231 function Unit_Declaration_Node
(Unit_Id
: Entity_Id
) return Node_Id
is
5232 N
: Node_Id
:= Parent
(Unit_Id
);
5235 -- Predefined operators do not have a full function declaration.
5237 if Ekind
(Unit_Id
) = E_Operator
then
5241 while Nkind
(N
) /= N_Abstract_Subprogram_Declaration
5242 and then Nkind
(N
) /= N_Formal_Package_Declaration
5243 and then Nkind
(N
) /= N_Formal_Subprogram_Declaration
5244 and then Nkind
(N
) /= N_Function_Instantiation
5245 and then Nkind
(N
) /= N_Generic_Package_Declaration
5246 and then Nkind
(N
) /= N_Generic_Subprogram_Declaration
5247 and then Nkind
(N
) /= N_Package_Declaration
5248 and then Nkind
(N
) /= N_Package_Body
5249 and then Nkind
(N
) /= N_Package_Instantiation
5250 and then Nkind
(N
) /= N_Package_Renaming_Declaration
5251 and then Nkind
(N
) /= N_Procedure_Instantiation
5252 and then Nkind
(N
) /= N_Subprogram_Declaration
5253 and then Nkind
(N
) /= N_Subprogram_Body
5254 and then Nkind
(N
) /= N_Subprogram_Body_Stub
5255 and then Nkind
(N
) /= N_Subprogram_Renaming_Declaration
5256 and then Nkind
(N
) /= N_Task_Body
5257 and then Nkind
(N
) /= N_Task_Type_Declaration
5258 and then Nkind
(N
) not in N_Generic_Renaming_Declaration
5261 pragma Assert
(Present
(N
));
5265 end Unit_Declaration_Node
;
5267 ----------------------
5268 -- Within_Init_Proc --
5269 ----------------------
5271 function Within_Init_Proc
return Boolean is
5276 while not Is_Overloadable
(S
) loop
5277 if S
= Standard_Standard
then
5284 return Chars
(S
) = Name_uInit_Proc
;
5285 end Within_Init_Proc
;
5291 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
5292 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
5293 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
5295 function Has_One_Matching_Field
return Boolean;
5296 -- Determines whether Expec_Type is a record type with a single
5297 -- component or discriminant whose type matches the found type or
5298 -- is a one dimensional array whose component type matches the
5301 function Has_One_Matching_Field
return Boolean is
5305 if Is_Array_Type
(Expec_Type
)
5306 and then Number_Dimensions
(Expec_Type
) = 1
5308 Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
5312 elsif not Is_Record_Type
(Expec_Type
) then
5316 E
:= First_Entity
(Expec_Type
);
5322 elsif (Ekind
(E
) /= E_Discriminant
5323 and then Ekind
(E
) /= E_Component
)
5324 or else (Chars
(E
) = Name_uTag
5325 or else Chars
(E
) = Name_uParent
)
5334 if not Covers
(Etype
(E
), Found_Type
) then
5337 elsif Present
(Next_Entity
(E
)) then
5344 end Has_One_Matching_Field
;
5346 -- Start of processing for Wrong_Type
5349 -- Don't output message if either type is Any_Type, or if a message
5350 -- has already been posted for this node. We need to do the latter
5351 -- check explicitly (it is ordinarily done in Errout), because we
5352 -- are using ! to force the output of the error messages.
5354 if Expec_Type
= Any_Type
5355 or else Found_Type
= Any_Type
5356 or else Error_Posted
(Expr
)
5360 -- In an instance, there is an ongoing problem with completion of
5361 -- type derived from private types. Their structure is what Gigi
5362 -- expects, but the Etype is the parent type rather than the
5363 -- derived private type itself. Do not flag error in this case. The
5364 -- private completion is an entity without a parent, like an Itype.
5365 -- Similarly, full and partial views may be incorrect in the instance.
5366 -- There is no simple way to insure that it is consistent ???
5368 elsif In_Instance
then
5370 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
5371 and then No
(Parent
(Expected_Type
))
5377 -- An interesting special check. If the expression is parenthesized
5378 -- and its type corresponds to the type of the sole component of the
5379 -- expected record type, or to the component type of the expected one
5380 -- dimensional array type, then assume we have a bad aggregate attempt.
5382 if Nkind
(Expr
) in N_Subexpr
5383 and then Paren_Count
(Expr
) /= 0
5384 and then Has_One_Matching_Field
5386 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
5388 -- Another special check, if we are looking for a pool-specific access
5389 -- type and we found an E_Access_Attribute_Type, then we have the case
5390 -- of an Access attribute being used in a context which needs a pool-
5391 -- specific type, which is never allowed. The one extra check we make
5392 -- is that the expected designated type covers the Found_Type.
5394 elsif Is_Access_Type
(Expec_Type
)
5395 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
5396 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
5397 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
5399 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
5401 Error_Msg_N
("result must be general access type!", Expr
);
5402 Error_Msg_NE
("add ALL to }!", Expr
, Expec_Type
);
5404 -- If the expected type is an anonymous access type, as for access
5405 -- parameters and discriminants, the error is on the designated types.
5407 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
5408 if Comes_From_Source
(Expec_Type
) then
5409 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
5412 ("expected an access type with designated}",
5413 Expr
, Designated_Type
(Expec_Type
));
5416 if Is_Access_Type
(Found_Type
)
5417 and then not Comes_From_Source
(Found_Type
)
5420 ("found an access type with designated}!",
5421 Expr
, Designated_Type
(Found_Type
));
5423 if From_With_Type
(Found_Type
) then
5424 Error_Msg_NE
("found incomplete}!", Expr
, Found_Type
);
5426 ("\possibly missing with_clause on&", Expr
,
5427 Scope
(Found_Type
));
5429 Error_Msg_NE
("found}!", Expr
, Found_Type
);
5433 -- Normal case of one type found, some other type expected
5436 -- If the names of the two types are the same, see if some
5437 -- number of levels of qualification will help. Don't try
5438 -- more than three levels, and if we get to standard, it's
5439 -- no use (and probably represents an error in the compiler)
5440 -- Also do not bother with internal scope names.
5443 Expec_Scope
: Entity_Id
;
5444 Found_Scope
: Entity_Id
;
5447 Expec_Scope
:= Expec_Type
;
5448 Found_Scope
:= Found_Type
;
5450 for Levels
in Int
range 0 .. 3 loop
5451 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
5452 Error_Msg_Qual_Level
:= Levels
;
5456 Expec_Scope
:= Scope
(Expec_Scope
);
5457 Found_Scope
:= Scope
(Found_Scope
);
5459 exit when Expec_Scope
= Standard_Standard
5461 Found_Scope
= Standard_Standard
5463 not Comes_From_Source
(Expec_Scope
)
5465 not Comes_From_Source
(Found_Scope
);
5469 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
5471 if Is_Entity_Name
(Expr
)
5472 and then Is_Package
(Entity
(Expr
))
5474 Error_Msg_N
("found package name!", Expr
);
5476 elsif Is_Entity_Name
(Expr
)
5478 (Ekind
(Entity
(Expr
)) = E_Procedure
5480 Ekind
(Entity
(Expr
)) = E_Generic_Procedure
)
5482 Error_Msg_N
("found procedure name instead of function!", Expr
);
5484 -- catch common error: a prefix or infix operator which is not
5485 -- directly visible because the type isn't.
5487 elsif Nkind
(Expr
) in N_Op
5488 and then Is_Overloaded
(Expr
)
5489 and then not Is_Immediately_Visible
(Expec_Type
)
5490 and then not Is_Potentially_Use_Visible
(Expec_Type
)
5491 and then not In_Use
(Expec_Type
)
5492 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
5495 "operator of the type is not directly visible!", Expr
);
5498 Error_Msg_NE
("found}!", Expr
, Found_Type
);
5501 Error_Msg_Qual_Level
:= 0;