1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Atree
; use Atree
;
30 with Checks
; use Checks
;
31 with Debug
; use Debug
;
32 with Einfo
; use Einfo
;
33 with Elists
; use Elists
;
34 with Errout
; use Errout
;
35 with Expander
; use Expander
;
36 with Exp_Ch7
; use Exp_Ch7
;
37 with Fname
; use Fname
;
38 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Output
; use Output
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch4
; use Sem_Ch4
;
51 with Sem_Ch5
; use Sem_Ch5
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch12
; use Sem_Ch12
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Dist
; use Sem_Dist
;
56 with Sem_Elim
; use Sem_Elim
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Mech
; use Sem_Mech
;
59 with Sem_Prag
; use Sem_Prag
;
60 with Sem_Res
; use Sem_Res
;
61 with Sem_Util
; use Sem_Util
;
62 with Sem_Type
; use Sem_Type
;
63 with Sem_Warn
; use Sem_Warn
;
64 with Sinput
; use Sinput
;
65 with Stand
; use Stand
;
66 with Sinfo
; use Sinfo
;
67 with Sinfo
.CN
; use Sinfo
.CN
;
68 with Snames
; use Snames
;
69 with Stringt
; use Stringt
;
71 with Stylesw
; use Stylesw
;
72 with Tbuild
; use Tbuild
;
73 with Uintp
; use Uintp
;
74 with Urealp
; use Urealp
;
75 with Validsw
; use Validsw
;
77 package body Sem_Ch6
is
79 -----------------------
80 -- Local Subprograms --
81 -----------------------
83 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
84 -- Analyze a generic subprogram body
86 function Build_Body_To_Inline
91 -- If a subprogram has pragma Inline and inlining is active, use generic
92 -- machinery to build an unexpanded body for the subprogram. This body is
93 -- subsequenty used for inline expansions at call sites. If subprogram can
94 -- be inlined (depending on size and nature of local declarations) this
95 -- function returns true. Otherwise subprogram body is treated normally.
97 type Conformance_Type
is
98 (Type_Conformant
, Mode_Conformant
, Subtype_Conformant
, Fully_Conformant
);
100 procedure Check_Conformance
103 Ctype
: Conformance_Type
;
105 Conforms
: out Boolean;
106 Err_Loc
: Node_Id
:= Empty
;
107 Get_Inst
: Boolean := False);
108 -- Given two entities, this procedure checks that the profiles associated
109 -- with these entities meet the conformance criterion given by the third
110 -- parameter. If they conform, Conforms is set True and control returns
111 -- to the caller. If they do not conform, Conforms is set to False, and
112 -- in addition, if Errmsg is True on the call, proper messages are output
113 -- to complain about the conformance failure. If Err_Loc is non_Empty
114 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
115 -- error messages are placed on the appropriate part of the construct
116 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
117 -- against a formal access-to-subprogram type so Get_Instance_Of must
120 procedure Check_Subprogram_Order
(N
: Node_Id
);
121 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
122 -- the alpha ordering rule for N if this ordering requirement applicable.
124 function Is_Non_Overriding_Operation
128 -- Enforce the rule given in 12.3(18): a private operation in an instance
129 -- overrides an inherited operation only if the corresponding operation
130 -- was overriding in the generic. This can happen for primitive operations
131 -- of types derived (in the generic unit) from formal private or formal
134 procedure Check_Returns
138 -- Called to check for missing return statements in a function body,
139 -- or for returns present in a procedure body which has No_Return set.
140 -- L is the handled statement sequence for the subprogram body. This
141 -- procedure checks all flow paths to make sure they either have a
142 -- return (Mode = 'F') or do not have a return (Mode = 'P'). The flag
143 -- Err is set if there are any control paths not explicitly terminated
144 -- by a return in the function case, and is True otherwise.
146 function Conforming_Types
149 Ctype
: Conformance_Type
;
150 Get_Inst
: Boolean := False)
152 -- Check that two formal parameter types conform, checking both
153 -- for equality of base types, and where required statically
154 -- matching subtypes, depending on the setting of Ctype.
156 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
157 -- This procedure makes S, a new overloaded entity, into the first
158 -- visible entity with that name.
160 procedure Install_Entity
(E
: Entity_Id
);
161 -- Make single entity visible. Used for generic formals as well.
163 procedure Install_Formals
(Id
: Entity_Id
);
164 -- On entry to a subprogram body, make the formals visible. Note
165 -- that simply placing the subprogram on the scope stack is not
166 -- sufficient: the formals must become the current entities for
169 procedure Make_Inequality_Operator
(S
: Entity_Id
);
170 -- Create the declaration for an inequality operator that is implicitly
171 -- created by a user-defined equality operator that yields a boolean.
173 procedure May_Need_Actuals
(Fun
: Entity_Id
);
174 -- Flag functions that can be called without parameters, i.e. those that
175 -- have no parameters, or those for which defaults exist for all parameters
177 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
178 -- Formal_Id is an formal parameter entity. This procedure deals with
179 -- setting the proper validity status for this entity, which depends
180 -- on the kind of parameter and the validity checking mode.
182 ---------------------------------------------
183 -- Analyze_Abstract_Subprogram_Declaration --
184 ---------------------------------------------
186 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
187 Designator
: constant Entity_Id
:= Analyze_Spec
(Specification
(N
));
188 Scop
: constant Entity_Id
:= Current_Scope
;
191 Generate_Definition
(Designator
);
192 Set_Is_Abstract
(Designator
);
193 New_Overloaded_Entity
(Designator
);
194 Check_Delayed_Subprogram
(Designator
);
196 Set_Is_Pure
(Designator
,
197 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(Designator
));
198 Set_Is_Remote_Call_Interface
(
199 Designator
, Is_Remote_Call_Interface
(Scop
));
200 Set_Is_Remote_Types
(Designator
, Is_Remote_Types
(Scop
));
202 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
204 ("abstract subprogram not allowed in protected type", N
);
206 end Analyze_Abstract_Subprogram_Declaration
;
208 ----------------------------
209 -- Analyze_Function_Call --
210 ----------------------------
212 procedure Analyze_Function_Call
(N
: Node_Id
) is
213 P
: constant Node_Id
:= Name
(N
);
214 L
: constant List_Id
:= Parameter_Associations
(N
);
220 -- If error analyzing name, then set Any_Type as result type and return
222 if Etype
(P
) = Any_Type
then
223 Set_Etype
(N
, Any_Type
);
227 -- Otherwise analyze the parameters
232 while Present
(Actual
) loop
234 Check_Parameterless_Call
(Actual
);
241 end Analyze_Function_Call
;
243 -------------------------------------
244 -- Analyze_Generic_Subprogram_Body --
245 -------------------------------------
247 procedure Analyze_Generic_Subprogram_Body
251 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
253 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
258 -- Copy body and disable expansion while analyzing the generic
259 -- For a stub, do not copy the stub (which would load the proper body),
260 -- this will be done when the proper body is analyzed.
262 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
263 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
268 Spec
:= Specification
(N
);
270 -- Within the body of the generic, the subprogram is callable, and
271 -- behaves like the corresponding non-generic unit.
273 Nam
:= Defining_Entity
(Spec
);
275 if Kind
= E_Generic_Procedure
276 and then Nkind
(Spec
) /= N_Procedure_Specification
278 Error_Msg_N
("invalid body for generic procedure ", Nam
);
281 elsif Kind
= E_Generic_Function
282 and then Nkind
(Spec
) /= N_Function_Specification
284 Error_Msg_N
("invalid body for generic function ", Nam
);
288 Set_Corresponding_Body
(Gen_Decl
, Nam
);
290 if Has_Completion
(Gen_Id
)
291 and then Nkind
(Parent
(N
)) /= N_Subunit
293 Error_Msg_N
("duplicate generic body", N
);
296 Set_Has_Completion
(Gen_Id
);
299 if Nkind
(N
) = N_Subprogram_Body_Stub
then
300 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
302 Set_Corresponding_Spec
(N
, Gen_Id
);
305 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
306 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
309 -- Make generic parameters immediately visible in the body. They are
310 -- needed to process the formals declarations. Then make the formals
311 -- visible in a separate step.
317 First_Ent
: Entity_Id
;
320 First_Ent
:= First_Entity
(Gen_Id
);
323 while Present
(E
) and then not Is_Formal
(E
) loop
328 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
330 -- Now generic formals are visible, and the specification can be
331 -- analyzed, for subsequent conformance check.
333 Nam
:= Analyze_Spec
(Spec
);
335 if Nkind
(N
) = N_Subprogram_Body_Stub
then
337 -- Nothing to do if no body to process
339 Set_Ekind
(Nam
, Kind
);
346 -- E is the first formal parameter, which must be the first
347 -- entity in the subprogram body.
349 Set_First_Entity
(Gen_Id
, E
);
351 -- Now make formal parameters visible
353 while Present
(E
) loop
359 -- Visible generic entity is callable within its own body.
361 Set_Ekind
(Gen_Id
, Ekind
(Nam
));
362 Set_Convention
(Nam
, Convention
(Gen_Id
));
363 Set_Scope
(Nam
, Scope
(Gen_Id
));
364 Check_Fully_Conformant
(Nam
, Gen_Id
, Nam
);
366 -- If this is a compilation unit, it must be made visible
367 -- explicitly, because the compilation of the declaration,
368 -- unlike other library unit declarations, does not. If it
369 -- is not a unit, the following is redundant but harmless.
371 Set_Is_Immediately_Visible
(Gen_Id
);
373 Set_Actual_Subtypes
(N
, Current_Scope
);
374 Analyze_Declarations
(Declarations
(N
));
376 Analyze
(Handled_Statement_Sequence
(N
));
378 Save_Global_References
(Original_Node
(N
));
380 -- Prior to exiting the scope, include generic formals again
381 -- (if any are present) in the set of local entities.
383 if Present
(First_Ent
) then
384 Set_First_Entity
(Gen_Id
, First_Ent
);
390 Check_Subprogram_Order
(N
);
392 -- Outside of its body, unit is generic again.
394 Set_Ekind
(Gen_Id
, Kind
);
395 Set_Ekind
(Nam
, E_Subprogram_Body
);
396 Generate_Reference
(Gen_Id
, Nam
, 'b');
397 Style
.Check_Identifier
(Nam
, Gen_Id
);
400 end Analyze_Generic_Subprogram_Body
;
402 -----------------------------
403 -- Analyze_Operator_Symbol --
404 -----------------------------
406 -- An operator symbol such as "+" or "and" may appear in context where
407 -- the literal denotes an entity name, such as "+"(x, y) or in a
408 -- context when it is just a string, as in (conjunction = "or"). In
409 -- these cases the parser generates this node, and the semantics does
410 -- the disambiguation. Other such case are actuals in an instantiation,
411 -- the generic unit in an instantiation, and pragma arguments.
413 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
414 Par
: constant Node_Id
:= Parent
(N
);
417 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
418 or else Nkind
(Par
) = N_Function_Instantiation
419 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
420 or else (Nkind
(Par
) = N_Pragma_Argument_Association
421 and then not Is_Pragma_String_Literal
(Par
))
422 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
423 or else (Nkind
(Par
) = N_Attribute_Reference
424 and then Attribute_Name
(Par
) /= Name_Value
)
426 Find_Direct_Name
(N
);
429 Change_Operator_Symbol_To_String_Literal
(N
);
432 end Analyze_Operator_Symbol
;
434 -----------------------------------
435 -- Analyze_Parameter_Association --
436 -----------------------------------
438 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
440 Analyze
(Explicit_Actual_Parameter
(N
));
441 end Analyze_Parameter_Association
;
443 ----------------------------
444 -- Analyze_Procedure_Call --
445 ----------------------------
447 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
448 Loc
: constant Source_Ptr
:= Sloc
(N
);
449 P
: constant Node_Id
:= Name
(N
);
450 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
454 procedure Analyze_Call_And_Resolve
;
455 -- Do Analyze and Resolve calls for procedure call
457 procedure Analyze_Call_And_Resolve
is
459 if Nkind
(N
) = N_Procedure_Call_Statement
then
461 Resolve
(N
, Standard_Void_Type
);
465 end Analyze_Call_And_Resolve
;
467 -- Start of processing for Analyze_Procedure_Call
470 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
471 -- a procedure call or an entry call. The prefix may denote an access
472 -- to subprogram type, in which case an implicit dereference applies.
473 -- If the prefix is an indexed component (without implicit defererence)
474 -- then the construct denotes a call to a member of an entire family.
475 -- If the prefix is a simple name, it may still denote a call to a
476 -- parameterless member of an entry family. Resolution of these various
477 -- interpretations is delicate.
481 -- If error analyzing prefix, then set Any_Type as result and return
483 if Etype
(P
) = Any_Type
then
484 Set_Etype
(N
, Any_Type
);
488 -- Otherwise analyze the parameters
490 if Present
(Actuals
) then
491 Actual
:= First
(Actuals
);
493 while Present
(Actual
) loop
495 Check_Parameterless_Call
(Actual
);
500 -- Special processing for Elab_Spec and Elab_Body calls
502 if Nkind
(P
) = N_Attribute_Reference
503 and then (Attribute_Name
(P
) = Name_Elab_Spec
504 or else Attribute_Name
(P
) = Name_Elab_Body
)
506 if Present
(Actuals
) then
508 ("no parameters allowed for this call", First
(Actuals
));
512 Set_Etype
(N
, Standard_Void_Type
);
515 elsif Is_Entity_Name
(P
)
516 and then Is_Record_Type
(Etype
(Entity
(P
)))
517 and then Remote_AST_I_Dereference
(P
)
521 elsif Is_Entity_Name
(P
)
522 and then Ekind
(Entity
(P
)) /= E_Entry_Family
524 if Is_Access_Type
(Etype
(P
))
525 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
526 and then No
(Actuals
)
527 and then Comes_From_Source
(N
)
529 Error_Msg_N
("missing explicit dereference in call", N
);
532 Analyze_Call_And_Resolve
;
534 -- If the prefix is the simple name of an entry family, this is
535 -- a parameterless call from within the task body itself.
537 elsif Is_Entity_Name
(P
)
538 and then Nkind
(P
) = N_Identifier
539 and then Ekind
(Entity
(P
)) = E_Entry_Family
540 and then Present
(Actuals
)
541 and then No
(Next
(First
(Actuals
)))
543 -- Can be call to parameterless entry family. What appears to be
544 -- the sole argument is in fact the entry index. Rewrite prefix
545 -- of node accordingly. Source representation is unchanged by this
549 Make_Indexed_Component
(Loc
,
551 Make_Selected_Component
(Loc
,
552 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
553 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
554 Expressions
=> Actuals
);
556 Set_Etype
(New_N
, Standard_Void_Type
);
557 Set_Parameter_Associations
(N
, No_List
);
558 Analyze_Call_And_Resolve
;
560 elsif Nkind
(P
) = N_Explicit_Dereference
then
561 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
562 Analyze_Call_And_Resolve
;
564 Error_Msg_N
("expect access to procedure in call", P
);
567 -- The name can be a selected component or an indexed component
568 -- that yields an access to subprogram. Such a prefix is legal if
569 -- the call has parameter associations.
571 elsif Is_Access_Type
(Etype
(P
))
572 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
574 if Present
(Actuals
) then
575 Analyze_Call_And_Resolve
;
577 Error_Msg_N
("missing explicit dereference in call ", N
);
580 -- If not an access to subprogram, then the prefix must resolve to
581 -- the name of an entry, entry family, or protected operation.
583 -- For the case of a simple entry call, P is a selected component
584 -- where the prefix is the task and the selector name is the entry.
585 -- A call to a protected procedure will have the same syntax. If
586 -- the protected object contains overloaded operations, the entity
587 -- may appear as a function, the context will select the operation
588 -- whose type is Void.
590 elsif Nkind
(P
) = N_Selected_Component
591 and then (Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
593 Ekind
(Entity
(Selector_Name
(P
))) = E_Procedure
595 Ekind
(Entity
(Selector_Name
(P
))) = E_Function
)
597 Analyze_Call_And_Resolve
;
599 elsif Nkind
(P
) = N_Selected_Component
600 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
601 and then Present
(Actuals
)
602 and then No
(Next
(First
(Actuals
)))
604 -- Can be call to parameterless entry family. What appears to be
605 -- the sole argument is in fact the entry index. Rewrite prefix
606 -- of node accordingly. Source representation is unchanged by this
610 Make_Indexed_Component
(Loc
,
611 Prefix
=> New_Copy
(P
),
612 Expressions
=> Actuals
);
614 Set_Etype
(New_N
, Standard_Void_Type
);
615 Set_Parameter_Associations
(N
, No_List
);
616 Analyze_Call_And_Resolve
;
618 -- For the case of a reference to an element of an entry family, P is
619 -- an indexed component whose prefix is a selected component (task and
620 -- entry family), and whose index is the entry family index.
622 elsif Nkind
(P
) = N_Indexed_Component
623 and then Nkind
(Prefix
(P
)) = N_Selected_Component
624 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
626 Analyze_Call_And_Resolve
;
628 -- If the prefix is the name of an entry family, it is a call from
629 -- within the task body itself.
631 elsif Nkind
(P
) = N_Indexed_Component
632 and then Nkind
(Prefix
(P
)) = N_Identifier
633 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
636 Make_Selected_Component
(Loc
,
637 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
638 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
639 Rewrite
(Prefix
(P
), New_N
);
641 Analyze_Call_And_Resolve
;
643 -- Anything else is an error.
646 Error_Msg_N
("Invalid procedure or entry call", N
);
648 end Analyze_Procedure_Call
;
650 ------------------------------
651 -- Analyze_Return_Statement --
652 ------------------------------
654 procedure Analyze_Return_Statement
(N
: Node_Id
) is
655 Loc
: constant Source_Ptr
:= Sloc
(N
);
657 Scope_Id
: Entity_Id
;
662 -- Find subprogram or accept statement enclosing the return statement
665 for J
in reverse 0 .. Scope_Stack
.Last
loop
666 Scope_Id
:= Scope_Stack
.Table
(J
).Entity
;
667 exit when Ekind
(Scope_Id
) /= E_Block
and then
668 Ekind
(Scope_Id
) /= E_Loop
;
671 pragma Assert
(Present
(Scope_Id
));
673 Kind
:= Ekind
(Scope_Id
);
674 Expr
:= Expression
(N
);
676 if Kind
/= E_Function
677 and then Kind
/= E_Generic_Function
678 and then Kind
/= E_Procedure
679 and then Kind
/= E_Generic_Procedure
680 and then Kind
/= E_Entry
681 and then Kind
/= E_Entry_Family
683 Error_Msg_N
("illegal context for return statement", N
);
685 elsif Present
(Expr
) then
686 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
687 Set_Return_Present
(Scope_Id
);
688 R_Type
:= Etype
(Scope_Id
);
689 Set_Return_Type
(N
, R_Type
);
690 Analyze_And_Resolve
(Expr
, R_Type
);
692 if (Is_Class_Wide_Type
(Etype
(Expr
))
693 or else Is_Dynamically_Tagged
(Expr
))
694 and then not Is_Class_Wide_Type
(R_Type
)
697 ("dynamically tagged expression not allowed!", Expr
);
700 Apply_Constraint_Check
(Expr
, R_Type
);
702 -- ??? A real run-time accessibility check is needed
703 -- in cases involving dereferences of access parameters.
704 -- For now we just check the static cases.
706 if Is_Return_By_Reference_Type
(Etype
(Scope_Id
))
707 and then Object_Access_Level
(Expr
)
708 > Subprogram_Access_Level
(Scope_Id
)
710 Rewrite
(N
, Make_Raise_Program_Error
(Loc
));
714 ("cannot return a local value by reference?", N
);
716 ("& will be raised at run time?!",
717 N
, Standard_Program_Error
);
720 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
721 Error_Msg_N
("procedure cannot return value (use function)", N
);
724 Error_Msg_N
("accept statement cannot return value", N
);
727 -- No expression present
730 if Kind
= E_Function
or Kind
= E_Generic_Function
then
731 Error_Msg_N
("missing expression in return from function", N
);
734 if (Ekind
(Scope_Id
) = E_Procedure
735 or else Ekind
(Scope_Id
) = E_Generic_Procedure
)
736 and then No_Return
(Scope_Id
)
739 ("RETURN statement not allowed (No_Return)", N
);
743 Check_Unreachable_Code
(N
);
744 end Analyze_Return_Statement
;
750 function Analyze_Spec
(N
: Node_Id
) return Entity_Id
is
751 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
752 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
756 Generate_Definition
(Designator
);
758 if Nkind
(N
) = N_Function_Specification
then
759 Set_Ekind
(Designator
, E_Function
);
760 Set_Mechanism
(Designator
, Default_Mechanism
);
762 if Subtype_Mark
(N
) /= Error
then
763 Find_Type
(Subtype_Mark
(N
));
764 Typ
:= Entity
(Subtype_Mark
(N
));
765 Set_Etype
(Designator
, Typ
);
767 if (Ekind
(Typ
) = E_Incomplete_Type
768 or else (Is_Class_Wide_Type
(Typ
)
770 Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
))
773 ("invalid use of incomplete type", Subtype_Mark
(N
));
777 Set_Etype
(Designator
, Any_Type
);
781 Set_Ekind
(Designator
, E_Procedure
);
782 Set_Etype
(Designator
, Standard_Void_Type
);
785 if Present
(Formals
) then
786 Set_Scope
(Designator
, Current_Scope
);
787 New_Scope
(Designator
);
788 Process_Formals
(Designator
, Formals
, N
);
792 if Nkind
(N
) = N_Function_Specification
then
793 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
794 Valid_Operator_Definition
(Designator
);
797 May_Need_Actuals
(Designator
);
799 if Is_Abstract
(Etype
(Designator
))
800 and then Nkind
(Parent
(N
)) /= N_Abstract_Subprogram_Declaration
803 ("function that returns abstract type must be abstract", N
);
810 -----------------------------
811 -- Analyze_Subprogram_Body --
812 -----------------------------
814 -- This procedure is called for regular subprogram bodies, generic bodies,
815 -- and for subprogram stubs of both kinds. In the case of stubs, only the
816 -- specification matters, and is used to create a proper declaration for
817 -- the subprogram, or to perform conformance checks.
819 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
820 Loc
: constant Source_Ptr
:= Sloc
(N
);
821 Body_Spec
: constant Node_Id
:= Specification
(N
);
822 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
823 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
827 Spec_Decl
: Node_Id
:= Empty
;
828 Last_Formal
: Entity_Id
:= Empty
;
829 Conformant
: Boolean;
830 Missing_Ret
: Boolean;
831 Body_Deleted
: Boolean := False;
835 Write_Str
("==== Compiling subprogram body ");
836 Write_Name
(Chars
(Body_Id
));
837 Write_Str
(" from ");
838 Write_Location
(Loc
);
842 Trace_Scope
(N
, Body_Id
, " Analyze subprogram");
844 -- Generic subprograms are handled separately. They always have
845 -- a generic specification. Determine whether current scope has
846 -- a previous declaration.
848 -- If the subprogram body is defined within an instance of the
849 -- same name, the instance appears as a package renaming, and
850 -- will be hidden within the subprogram.
853 and then not Is_Overloadable
(Prev_Id
)
854 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
855 or else Comes_From_Source
(Prev_Id
))
857 if Ekind
(Prev_Id
) = E_Generic_Procedure
858 or else Ekind
(Prev_Id
) = E_Generic_Function
861 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
862 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
864 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
868 -- Previous entity conflicts with subprogram name.
869 -- Attempting to enter name will post error.
871 Enter_Name
(Body_Id
);
875 -- Non-generic case, find the subprogram declaration, if one was
876 -- seen, or enter new overloaded entity in the current scope.
877 -- If the current_entity is the body_id itself, the unit is being
878 -- analyzed as part of the context of one of its subunits. No need
879 -- to redo the analysis.
881 elsif Prev_Id
= Body_Id
882 and then Has_Completion
(Body_Id
)
887 Body_Id
:= Analyze_Spec
(Body_Spec
);
889 if Nkind
(N
) = N_Subprogram_Body_Stub
890 or else No
(Corresponding_Spec
(N
))
892 Spec_Id
:= Find_Corresponding_Spec
(N
);
894 -- If this is a duplicate body, no point in analyzing it
896 if Error_Posted
(N
) then
900 -- A subprogram body should cause freezing of its own
901 -- declaration, but if there was no previous explicit
902 -- declaration, then the subprogram will get frozen too
903 -- late (there may be code within the body that depends
904 -- on the subprogram having been frozen, such as uses of
905 -- extra formals), so we force it to be frozen here.
906 -- Same holds if the body and the spec are compilation units.
909 Freeze_Before
(N
, Body_Id
);
911 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
912 Freeze_Before
(N
, Spec_Id
);
915 Spec_Id
:= Corresponding_Spec
(N
);
920 and then Comes_From_Source
(N
)
921 and then Is_Protected_Type
(Current_Scope
)
923 -- Fully private operation in the body of the protected type. We
924 -- must create a declaration for the subprogram, in order to attach
925 -- the protected subprogram that will be used in internal calls.
934 Formal
:= First_Formal
(Body_Id
);
936 -- The protected operation always has at least one formal,
937 -- namely the object itself, but it is only placed in the
938 -- parameter list if expansion is enabled.
941 or else Expander_Active
949 while Present
(Formal
) loop
951 (Make_Parameter_Specification
(Loc
,
952 Defining_Identifier
=>
953 Make_Defining_Identifier
(Sloc
(Formal
),
954 Chars
=> Chars
(Formal
)),
955 In_Present
=> In_Present
(Parent
(Formal
)),
956 Out_Present
=> Out_Present
(Parent
(Formal
)),
958 New_Reference_To
(Etype
(Formal
), Loc
),
960 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
963 Next_Formal
(Formal
);
966 if Nkind
(Body_Spec
) = N_Procedure_Specification
then
968 Make_Procedure_Specification
(Loc
,
969 Defining_Unit_Name
=>
970 Make_Defining_Identifier
(Sloc
(Body_Id
),
971 Chars
=> Chars
(Body_Id
)),
972 Parameter_Specifications
=> Plist
);
975 Make_Function_Specification
(Loc
,
976 Defining_Unit_Name
=>
977 Make_Defining_Identifier
(Sloc
(Body_Id
),
978 Chars
=> Chars
(Body_Id
)),
979 Parameter_Specifications
=> Plist
,
980 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
984 Make_Subprogram_Declaration
(Loc
,
985 Specification
=> New_Spec
);
986 Insert_Before
(N
, Decl
);
988 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
989 Set_Has_Completion
(Spec_Id
);
990 Set_Convention
(Spec_Id
, Convention_Protected
);
993 elsif Present
(Spec_Id
) then
994 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
997 -- Place subprogram on scope stack, and make formals visible. If there
998 -- is a spec, the visible entity remains that of the spec.
1000 if Present
(Spec_Id
) then
1001 Generate_Reference
(Spec_Id
, Body_Id
, 'b');
1002 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1004 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1005 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1007 if Is_Abstract
(Spec_Id
) then
1008 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
1011 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
1012 Set_Has_Completion
(Spec_Id
);
1014 if Is_Protected_Type
(Scope
(Spec_Id
)) then
1015 Set_Privals_Chain
(Spec_Id
, New_Elmt_List
);
1018 -- If this is a body generated for a renaming, do not check for
1019 -- full conformance. The check is redundant, because the spec of
1020 -- the body is a copy of the spec in the renaming declaration,
1021 -- and the test can lead to spurious errors on nested defaults.
1023 if Present
(Spec_Decl
)
1024 and then Nkind
(Original_Node
(Spec_Decl
)) =
1025 N_Subprogram_Renaming_Declaration
1026 and then not Comes_From_Source
(N
)
1032 Fully_Conformant
, True, Conformant
, Body_Id
);
1035 -- If the body is not fully conformant, we have to decide if we
1036 -- should analyze it or not. If it has a really messed up profile
1037 -- then we probably should not analyze it, since we will get too
1038 -- many bogus messages.
1040 -- Our decision is to go ahead in the non-fully conformant case
1041 -- only if it is at least mode conformant with the spec. Note
1042 -- that the call to Check_Fully_Conformant has issued the proper
1043 -- error messages to complain about the lack of conformance.
1046 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
1052 -- Generate references from body formals to spec formals
1053 -- and also set the Spec_Entity fields for all formals
1055 if Spec_Id
/= Body_Id
then
1061 Fs
:= First_Formal
(Spec_Id
);
1062 Fb
:= First_Formal
(Body_Id
);
1063 while Present
(Fs
) loop
1064 Generate_Reference
(Fs
, Fb
, 'b');
1065 Style
.Check_Identifier
(Fb
, Fs
);
1066 Set_Spec_Entity
(Fb
, Fs
);
1073 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1074 Set_Corresponding_Spec
(N
, Spec_Id
);
1075 Install_Formals
(Spec_Id
);
1076 Last_Formal
:= Last_Entity
(Spec_Id
);
1077 New_Scope
(Spec_Id
);
1079 -- Make sure that the subprogram is immediately visible. For
1080 -- child units that have no separate spec this is indispensable.
1081 -- Otherwise it is safe albeit redundant.
1083 Set_Is_Immediately_Visible
(Spec_Id
);
1086 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
1087 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1088 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
1090 -- Case of subprogram body with no previous spec
1094 and then Comes_From_Source
(Body_Id
)
1095 and then not Suppress_Style_Checks
(Body_Id
)
1096 and then not In_Instance
1098 Style
.Body_With_No_Spec
(N
);
1101 New_Overloaded_Entity
(Body_Id
);
1103 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1104 Set_Acts_As_Spec
(N
);
1105 Generate_Definition
(Body_Id
);
1106 Install_Formals
(Body_Id
);
1107 New_Scope
(Body_Id
);
1111 -- If this is the proper body of a stub, we must verify that the stub
1112 -- conforms to the body, and to the previous spec if one was present.
1113 -- we know already that the body conforms to that spec. This test is
1114 -- only required for subprograms that come from source.
1116 if Nkind
(Parent
(N
)) = N_Subunit
1117 and then Comes_From_Source
(N
)
1118 and then not Error_Posted
(Body_Id
)
1121 Conformant
: Boolean := False;
1122 Old_Id
: Entity_Id
:=
1124 (Specification
(Corresponding_Stub
(Parent
(N
))));
1127 if No
(Spec_Id
) then
1128 Check_Fully_Conformant
(Body_Id
, Old_Id
);
1132 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
1134 if not Conformant
then
1136 -- The stub was taken to be a new declaration. Indicate
1137 -- that it lacks a body.
1139 Set_Has_Completion
(Old_Id
, False);
1145 Set_Has_Completion
(Body_Id
);
1146 Check_Eliminated
(Body_Id
);
1148 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1151 elsif Present
(Spec_Id
)
1152 and then Expander_Active
1153 and then Has_Pragma_Inline
(Spec_Id
)
1154 and then (Front_End_Inlining
1156 (No_Run_Time
and then Is_Always_Inlined
(Spec_Id
)))
1158 if Build_Body_To_Inline
(N
, Spec_Id
, Copy_Separate_Tree
(N
)) then
1163 -- Here we have a real body, not a stub. First step is to null out
1164 -- the subprogram body if we have the special case of no run time
1165 -- mode with a predefined unit, and the subprogram is not marked
1166 -- as Inline_Always. The reason is that we should never call such
1167 -- a routine in no run time mode, and it may in general have some
1168 -- statements that we cannot handle in no run time mode.
1170 -- ASIS note: we do a replace here, because we are really NOT going
1171 -- to analyze the original body and declarations at all, so it is
1172 -- useless to keep them around, we really are obliterating the body,
1173 -- basically creating a specialized no run time version on the fly
1174 -- in which the bodies *are* null.
1177 and then Present
(Spec_Id
)
1178 and then Is_Predefined_File_Name
1179 (Unit_File_Name
(Get_Source_Unit
(Loc
)))
1180 and then not Is_Always_Inlined
(Spec_Id
)
1183 Make_Subprogram_Body
(Loc
,
1184 Specification
=> Specification
(N
),
1185 Declarations
=> Empty_List
,
1186 Handled_Statement_Sequence
=>
1187 Make_Handled_Sequence_Of_Statements
(Loc
,
1188 Statements
=> New_List
(
1189 Make_Null_Statement
(Loc
)),
1191 End_Label
(Handled_Statement_Sequence
(N
)))));
1192 Set_Corresponding_Spec
(N
, Spec_Id
);
1193 Body_Deleted
:= True;
1196 -- Now we can go on to analyze the body
1198 HSS
:= Handled_Statement_Sequence
(N
);
1199 Set_Actual_Subtypes
(N
, Current_Scope
);
1200 Analyze_Declarations
(Declarations
(N
));
1203 Process_End_Label
(HSS
, 't');
1205 Check_Subprogram_Order
(N
);
1207 -- If we have a separate spec, then the analysis of the declarations
1208 -- caused the entities in the body to be chained to the spec id, but
1209 -- we want them chained to the body id. Only the formal parameters
1210 -- end up chained to the spec id in this case.
1212 if Present
(Spec_Id
) then
1214 -- If a parent unit is categorized, the context of a subunit
1215 -- must conform to the categorization. Conversely, if a child
1216 -- unit is categorized, the parents themselves must conform.
1218 if Nkind
(Parent
(N
)) = N_Subunit
then
1219 Validate_Categorization_Dependency
(N
, Spec_Id
);
1221 elsif Is_Child_Unit
(Spec_Id
) then
1222 Validate_Categorization_Dependency
1223 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
1226 if Present
(Last_Formal
) then
1228 (Last_Entity
(Body_Id
), Next_Entity
(Last_Formal
));
1229 Set_Next_Entity
(Last_Formal
, Empty
);
1230 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1231 Set_Last_Entity
(Spec_Id
, Last_Formal
);
1234 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
1235 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1236 Set_First_Entity
(Spec_Id
, Empty
);
1237 Set_Last_Entity
(Spec_Id
, Empty
);
1241 -- If function, check return statements
1243 if Nkind
(Body_Spec
) = N_Function_Specification
then
1248 if Present
(Spec_Id
) then
1254 if Return_Present
(Id
) then
1255 Check_Returns
(HSS
, 'F', Missing_Ret
);
1258 Set_Has_Missing_Return
(Id
);
1261 elsif not Is_Machine_Code_Subprogram
(Id
)
1262 and then not Body_Deleted
1264 Error_Msg_N
("missing RETURN statement in function body", N
);
1268 -- If procedure with No_Return, check returns
1270 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
1271 and then Present
(Spec_Id
)
1272 and then No_Return
(Spec_Id
)
1274 Check_Returns
(HSS
, 'P', Missing_Ret
);
1277 -- Don't worry about checking for variables that are never modified
1278 -- if the first statement of the body is a raise statement, since
1279 -- we assume this is some kind of stub. We ignore a label generated
1280 -- by the exception stuff for the purpose of this test.
1283 Stm
: Node_Id
:= First
(Statements
(HSS
));
1286 if Nkind
(Stm
) = N_Label
then
1290 if Nkind
(Original_Node
(Stm
)) = N_Raise_Statement
then
1295 -- Check for variables that are never modified
1301 -- If there is a separate spec, then transfer Not_Source_Assigned
1302 -- flags from out parameters to the corresponding entities in the
1303 -- body. The reason we do that is we want to post error flags on
1304 -- the body entities, not the spec entities.
1306 if Present
(Spec_Id
) then
1307 E1
:= First_Entity
(Spec_Id
);
1309 while Present
(E1
) loop
1310 if Ekind
(E1
) = E_Out_Parameter
then
1311 E2
:= First_Entity
(Body_Id
);
1314 -- If no matching body entity, then we already had
1315 -- a detected error of some kind, so just forget
1316 -- about worrying about these warnings.
1322 exit when Chars
(E1
) = Chars
(E2
);
1326 Set_Not_Source_Assigned
(E2
, Not_Source_Assigned
(E1
));
1333 -- Check references in body unless it was deleted. Note that the
1334 -- check of Body_Deleted here is not just for efficiency, it is
1335 -- necessary to avoid junk warnings on formal parameters.
1337 if not Body_Deleted
then
1338 Check_References
(Body_Id
);
1341 end Analyze_Subprogram_Body
;
1343 ------------------------------------
1344 -- Analyze_Subprogram_Declaration --
1345 ------------------------------------
1347 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
1348 Designator
: constant Entity_Id
:= Analyze_Spec
(Specification
(N
));
1349 Scop
: constant Entity_Id
:= Current_Scope
;
1351 -- Start of processing for Analyze_Subprogram_Declaration
1354 Generate_Definition
(Designator
);
1356 -- Check for RCI unit subprogram declarations against in-lined
1357 -- subprograms and subprograms having access parameter or limited
1358 -- parameter without Read and Write (RM E.2.3(12-13)).
1360 Validate_RCI_Subprogram_Declaration
(N
);
1364 Defining_Entity
(N
),
1365 " Analyze subprogram spec. ");
1367 if Debug_Flag_C
then
1368 Write_Str
("==== Compiling subprogram spec ");
1369 Write_Name
(Chars
(Designator
));
1370 Write_Str
(" from ");
1371 Write_Location
(Sloc
(N
));
1375 New_Overloaded_Entity
(Designator
);
1376 Check_Delayed_Subprogram
(Designator
);
1377 Set_Suppress_Elaboration_Checks
1378 (Designator
, Elaboration_Checks_Suppressed
(Designator
));
1380 if Scop
/= Standard_Standard
1381 and then not Is_Child_Unit
(Designator
)
1383 Set_Is_Pure
(Designator
,
1384 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(Designator
));
1385 Set_Is_Remote_Call_Interface
(
1386 Designator
, Is_Remote_Call_Interface
(Scop
));
1387 Set_Is_Remote_Types
(Designator
, Is_Remote_Types
(Scop
));
1390 -- For a compilation unit, check for library-unit pragmas.
1392 New_Scope
(Designator
);
1393 Set_Categorization_From_Pragmas
(N
);
1394 Validate_Categorization_Dependency
(N
, Designator
);
1398 -- For a compilation unit, set body required. This flag will only be
1399 -- reset if a valid Import or Interface pragma is processed later on.
1401 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1402 Set_Body_Required
(Parent
(N
), True);
1405 Check_Eliminated
(Designator
);
1406 end Analyze_Subprogram_Declaration
;
1408 --------------------------
1409 -- Build_Body_To_Inline --
1410 --------------------------
1412 function Build_Body_To_Inline
1415 Orig_Body
: Node_Id
) return Boolean
1417 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1418 Original_Body
: Node_Id
;
1419 Body_To_Analyze
: Node_Id
;
1420 Max_Size
: constant := 10;
1421 Stat_Count
: Integer := 0;
1423 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
1424 -- Check for declarations that make inlining not worthwhile.
1426 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
1427 -- Check for statements that make inlining not worthwhile: any
1428 -- tasking statement, nested at any level. Keep track of total
1429 -- number of elementary statements, as a measure of acceptable size.
1431 function Has_Pending_Instantiation
return Boolean;
1432 -- If some enclosing body contains instantiations that appear before
1433 -- the corresponding generic body, the enclosing body has a freeze node
1434 -- so that it can be elaborated after the generic itself. This might
1435 -- conflict with subsequent inlinings, so that it is unsafe to try to
1436 -- inline in such a case.
1442 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
);
1443 -- If subprogram has pragma Inline_Always, it is an error if
1444 -- it cannot be inlined. Otherwise, emit a warning.
1446 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
) is
1448 if Is_Always_Inlined
(Subp
) then
1449 Error_Msg_NE
(Msg
(1 .. Msg
'Length - 1), N
, Subp
);
1451 elsif Ineffective_Inline_Warnings
then
1452 Error_Msg_NE
(Msg
, N
, Subp
);
1456 ------------------------------
1457 -- Has_Excluded_Declaration --
1458 ------------------------------
1460 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
1466 while Present
(D
) loop
1467 if Nkind
(D
) = N_Function_Instantiation
1468 or else Nkind
(D
) = N_Protected_Type_Declaration
1469 or else Nkind
(D
) = N_Package_Declaration
1470 or else Nkind
(D
) = N_Package_Instantiation
1471 or else Nkind
(D
) = N_Subprogram_Body
1472 or else Nkind
(D
) = N_Procedure_Instantiation
1473 or else Nkind
(D
) = N_Task_Type_Declaration
1476 ("\declaration prevents front-end inlining of&?", D
);
1485 end Has_Excluded_Declaration
;
1487 ----------------------------
1488 -- Has_Excluded_Statement --
1489 ----------------------------
1491 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
1498 while Present
(S
) loop
1499 Stat_Count
:= Stat_Count
+ 1;
1501 if Nkind
(S
) = N_Abort_Statement
1502 or else Nkind
(S
) = N_Asynchronous_Select
1503 or else Nkind
(S
) = N_Conditional_Entry_Call
1504 or else Nkind
(S
) = N_Delay_Relative_Statement
1505 or else Nkind
(S
) = N_Delay_Until_Statement
1506 or else Nkind
(S
) = N_Selective_Accept
1507 or else Nkind
(S
) = N_Timed_Entry_Call
1510 ("\statement prevents front-end inlining of&?", S
);
1513 elsif Nkind
(S
) = N_Block_Statement
then
1514 if Present
(Declarations
(S
))
1515 and then Has_Excluded_Declaration
(Declarations
(S
))
1519 elsif Present
(Handled_Statement_Sequence
(S
))
1522 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
1524 Has_Excluded_Statement
1525 (Statements
(Handled_Statement_Sequence
(S
))))
1530 elsif Nkind
(S
) = N_Case_Statement
then
1531 E
:= First
(Alternatives
(S
));
1533 while Present
(E
) loop
1534 if Has_Excluded_Statement
(Statements
(E
)) then
1541 elsif Nkind
(S
) = N_If_Statement
then
1542 if Has_Excluded_Statement
(Then_Statements
(S
)) then
1546 if Present
(Elsif_Parts
(S
)) then
1547 E
:= First
(Elsif_Parts
(S
));
1549 while Present
(E
) loop
1550 if Has_Excluded_Statement
(Then_Statements
(E
)) then
1557 if Present
(Else_Statements
(S
))
1558 and then Has_Excluded_Statement
(Else_Statements
(S
))
1563 elsif Nkind
(S
) = N_Loop_Statement
1564 and then Has_Excluded_Statement
(Statements
(S
))
1573 end Has_Excluded_Statement
;
1575 -------------------------------
1576 -- Has_Pending_Instantiation --
1577 -------------------------------
1579 function Has_Pending_Instantiation
return Boolean is
1580 S
: Entity_Id
:= Current_Scope
;
1583 while Present
(S
) loop
1584 if Is_Compilation_Unit
(S
)
1585 or else Is_Child_Unit
(S
)
1588 elsif Ekind
(S
) = E_Package
1589 and then Has_Forward_Instantiation
(S
)
1598 end Has_Pending_Instantiation
;
1600 -- Start of processing for Build_Body_To_Inline
1603 if Nkind
(Decl
) = N_Subprogram_Declaration
1604 and then Present
(Body_To_Inline
(Decl
))
1606 return True; -- Done already.
1608 -- Functions that return unconstrained composite types will require
1609 -- secondary stack handling, and cannot currently be inlined.
1611 elsif Ekind
(Subp
) = E_Function
1612 and then not Is_Scalar_Type
(Etype
(Subp
))
1613 and then not Is_Access_Type
(Etype
(Subp
))
1614 and then not Is_Constrained
(Etype
(Subp
))
1617 ("unconstrained return type prevents front-end inlining of&?", N
);
1621 -- We need to capture references to the formals in order to substitute
1622 -- the actuals at the point of inlining, i.e. instantiation. To treat
1623 -- the formals as globals to the body to inline, we nest it within
1624 -- a dummy parameterless subprogram, declared within the real one.
1626 Original_Body
:= Orig_Body
;
1628 -- Within an instance, the current tree is already the result of
1629 -- a generic copy, and not what we need for subsequent inlining.
1630 -- We create the required body by doing an instantiating copy, to
1631 -- obtain the proper partially analyzed tree.
1634 if No
(Generic_Parent
(Specification
(N
))) then
1637 elsif Is_Child_Unit
(Scope
(Current_Scope
)) then
1640 elsif Scope
(Current_Scope
) = Cunit_Entity
(Main_Unit
) then
1642 -- compiling an instantiation. There is no point in generating
1643 -- bodies to inline, because they will not be used.
1650 (Generic_Parent
(Specification
(N
)), Empty
,
1651 Instantiating
=> True);
1655 Copy_Generic_Node
(Original_Body
, Empty
,
1656 Instantiating
=> False);
1659 Set_Parameter_Specifications
(Specification
(Original_Body
), No_List
);
1660 Set_Defining_Unit_Name
(Specification
(Original_Body
),
1661 Make_Defining_Identifier
(Sloc
(N
), New_Internal_Name
('S')));
1662 Set_Corresponding_Spec
(Original_Body
, Empty
);
1664 if Ekind
(Subp
) = E_Function
then
1665 Set_Subtype_Mark
(Specification
(Original_Body
),
1666 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
1669 if Present
(Declarations
(Orig_Body
))
1670 and then Has_Excluded_Declaration
(Declarations
(Orig_Body
))
1675 if Present
(Handled_Statement_Sequence
(N
)) then
1677 (Present
(Exception_Handlers
(Handled_Statement_Sequence
(N
))))
1679 Cannot_Inline
("handler prevents front-end inlining of&?",
1680 First
(Exception_Handlers
(Handled_Statement_Sequence
(N
))));
1683 Has_Excluded_Statement
1684 (Statements
(Handled_Statement_Sequence
(N
)))
1690 -- We do not inline a subprogram that is too large, unless it is
1691 -- marked Inline_Always. This pragma does not suppress the other
1692 -- checks on inlining (forbidden declarations, handlers, etc).
1694 if Stat_Count
> Max_Size
1695 and then not Is_Always_Inlined
(Subp
)
1697 Cannot_Inline
("body is too large for front-end inlining of&?", N
);
1701 if Has_Pending_Instantiation
then
1703 ("cannot inline& because of forward instance within enclosing body",
1708 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
1710 -- Set return type of function, which is also global and does not need
1713 if Ekind
(Subp
) = E_Function
then
1714 Set_Subtype_Mark
(Specification
(Body_To_Analyze
),
1715 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
1718 if No
(Declarations
(N
)) then
1719 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
1721 Append
(Body_To_Analyze
, Declarations
(N
));
1724 Expander_Mode_Save_And_Set
(False);
1726 Analyze
(Body_To_Analyze
);
1727 New_Scope
(Defining_Entity
(Body_To_Analyze
));
1728 Save_Global_References
(Original_Body
);
1730 Remove
(Body_To_Analyze
);
1732 Expander_Mode_Restore
;
1733 Set_Body_To_Inline
(Decl
, Original_Body
);
1734 Set_Is_Inlined
(Subp
);
1737 end Build_Body_To_Inline
;
1739 -----------------------
1740 -- Check_Conformance --
1741 -----------------------
1743 procedure Check_Conformance
1744 (New_Id
: Entity_Id
;
1746 Ctype
: Conformance_Type
;
1748 Conforms
: out Boolean;
1749 Err_Loc
: Node_Id
:= Empty
;
1750 Get_Inst
: Boolean := False)
1752 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
1753 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
1754 Old_Formal
: Entity_Id
;
1755 New_Formal
: Entity_Id
;
1757 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
1758 -- Post error message for conformance error on given node.
1759 -- Two messages are output. The first points to the previous
1760 -- declaration with a general "no conformance" message.
1761 -- The second is the detailed reason, supplied as Msg. The
1762 -- parameter N provide information for a possible & insertion
1763 -- in the message, and also provides the location for posting
1764 -- the message in the absence of a specified Err_Loc location.
1766 -----------------------
1767 -- Conformance_Error --
1768 -----------------------
1770 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
1777 if No
(Err_Loc
) then
1783 Error_Msg_Sloc
:= Sloc
(Old_Id
);
1786 when Type_Conformant
=>
1788 ("not type conformant with declaration#!", Enode
);
1790 when Mode_Conformant
=>
1792 ("not mode conformant with declaration#!", Enode
);
1794 when Subtype_Conformant
=>
1796 ("not subtype conformant with declaration#!", Enode
);
1798 when Fully_Conformant
=>
1800 ("not fully conformant with declaration#!", Enode
);
1803 Error_Msg_NE
(Msg
, Enode
, N
);
1805 end Conformance_Error
;
1807 -- Start of processing for Check_Conformance
1812 -- We need a special case for operators, since they don't
1813 -- appear explicitly.
1815 if Ctype
= Type_Conformant
then
1816 if Ekind
(New_Id
) = E_Operator
1817 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
1823 -- If both are functions/operators, check return types conform
1825 if Old_Type
/= Standard_Void_Type
1826 and then New_Type
/= Standard_Void_Type
1828 if not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
1829 Conformance_Error
("return type does not match!", New_Id
);
1833 -- If either is a function/operator and the other isn't, error
1835 elsif Old_Type
/= Standard_Void_Type
1836 or else New_Type
/= Standard_Void_Type
1838 Conformance_Error
("functions can only match functions!", New_Id
);
1842 -- In subtype conformant case, conventions must match (RM 6.3.1(16))
1843 -- If this is a renaming as body, refine error message to indicate that
1844 -- the conflict is with the original declaration. If the entity is not
1845 -- frozen, the conventions don't have to match, the one of the renamed
1846 -- entity is inherited.
1848 if Ctype
>= Subtype_Conformant
then
1850 if Convention
(Old_Id
) /= Convention
(New_Id
) then
1852 if not Is_Frozen
(New_Id
) then
1855 elsif Present
(Err_Loc
)
1856 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
1857 and then Present
(Corresponding_Spec
(Err_Loc
))
1859 Error_Msg_Name_1
:= Chars
(New_Id
);
1861 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
1863 Conformance_Error
("prior declaration for% has convention %!");
1866 Conformance_Error
("calling conventions do not match!");
1871 elsif Is_Formal_Subprogram
(Old_Id
)
1872 or else Is_Formal_Subprogram
(New_Id
)
1874 Conformance_Error
("formal subprograms not allowed!");
1879 -- Deal with parameters
1881 -- Note: we use the entity information, rather than going directly
1882 -- to the specification in the tree. This is not only simpler, but
1883 -- absolutely necessary for some cases of conformance tests between
1884 -- operators, where the declaration tree simply does not exist!
1886 Old_Formal
:= First_Formal
(Old_Id
);
1887 New_Formal
:= First_Formal
(New_Id
);
1889 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
1891 -- Types must always match. In the visible part of an instance,
1892 -- usual overloading rules for dispatching operations apply, and
1893 -- we check base types (not the actual subtypes).
1895 if In_Instance_Visible_Part
1896 and then Is_Dispatching_Operation
(New_Id
)
1898 if not Conforming_Types
1899 (Base_Type
(Etype
(Old_Formal
)),
1900 Base_Type
(Etype
(New_Formal
)), Ctype
, Get_Inst
)
1902 Conformance_Error
("type of & does not match!", New_Formal
);
1906 elsif not Conforming_Types
1907 (Etype
(Old_Formal
), Etype
(New_Formal
), Ctype
, Get_Inst
)
1909 Conformance_Error
("type of & does not match!", New_Formal
);
1913 -- For mode conformance, mode must match
1915 if Ctype
>= Mode_Conformant
1916 and then Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
)
1918 Conformance_Error
("mode of & does not match!", New_Formal
);
1922 -- Full conformance checks
1924 if Ctype
= Fully_Conformant
then
1928 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
1929 Conformance_Error
("name & does not match!", New_Formal
);
1932 -- And default expressions for in parameters
1934 elsif Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
1936 NewD
: constant Boolean :=
1937 Present
(Default_Value
(New_Formal
));
1938 OldD
: constant Boolean :=
1939 Present
(Default_Value
(Old_Formal
));
1941 if NewD
or OldD
then
1943 -- The old default value has been analyzed and expanded,
1944 -- because the current full declaration will have frozen
1945 -- everything before. The new default values have not
1946 -- been expanded, so expand now to check conformance.
1950 Analyze_Default_Expression
1951 (Default_Value
(New_Formal
), Etype
(New_Formal
));
1955 if not (NewD
and OldD
)
1956 or else not Fully_Conformant_Expressions
1957 (Default_Value
(Old_Formal
),
1958 Default_Value
(New_Formal
))
1961 ("default expression for & does not match!",
1970 -- A couple of special checks for Ada 83 mode. These checks are
1971 -- skipped if either entity is an operator in package Standard.
1972 -- or if either old or new instance is not from the source program.
1975 and then Sloc
(Old_Id
) > Standard_Location
1976 and then Sloc
(New_Id
) > Standard_Location
1977 and then Comes_From_Source
(Old_Id
)
1978 and then Comes_From_Source
(New_Id
)
1981 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
1982 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
1985 -- Explicit IN must be present or absent in both cases. This
1986 -- test is required only in the full conformance case.
1988 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
1989 and then Ctype
= Fully_Conformant
1992 ("(Ada 83) IN must appear in both declarations",
1997 -- Grouping (use of comma in param lists) must be the same
1998 -- This is where we catch a misconformance like:
2001 -- A : Integer; B : Integer
2003 -- which are represented identically in the tree except
2004 -- for the setting of the flags More_Ids and Prev_Ids.
2006 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
2007 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
2010 ("grouping of & does not match!", New_Formal
);
2016 Next_Formal
(Old_Formal
);
2017 Next_Formal
(New_Formal
);
2020 if Present
(Old_Formal
) then
2021 Conformance_Error
("too few parameters!");
2024 elsif Present
(New_Formal
) then
2025 Conformance_Error
("too many parameters!", New_Formal
);
2029 end Check_Conformance
;
2031 ------------------------------
2032 -- Check_Delayed_Subprogram --
2033 ------------------------------
2035 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
2038 procedure Possible_Freeze
(T
: Entity_Id
);
2039 -- T is the type of either a formal parameter or of the return type.
2040 -- If T is not yet frozen and needs a delayed freeze, then the
2041 -- subprogram itself must be delayed.
2043 procedure Possible_Freeze
(T
: Entity_Id
) is
2045 if Has_Delayed_Freeze
(T
)
2046 and then not Is_Frozen
(T
)
2048 Set_Has_Delayed_Freeze
(Designator
);
2050 elsif Is_Access_Type
(T
)
2051 and then Has_Delayed_Freeze
(Designated_Type
(T
))
2052 and then not Is_Frozen
(Designated_Type
(T
))
2054 Set_Has_Delayed_Freeze
(Designator
);
2056 end Possible_Freeze
;
2058 -- Start of processing for Check_Delayed_Subprogram
2061 -- Never need to freeze abstract subprogram
2063 if Is_Abstract
(Designator
) then
2066 -- Need delayed freeze if return type itself needs a delayed
2067 -- freeze and is not yet frozen.
2069 Possible_Freeze
(Etype
(Designator
));
2070 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
2072 -- Need delayed freeze if any of the formal types themselves need
2073 -- a delayed freeze and are not yet frozen.
2075 F
:= First_Formal
(Designator
);
2076 while Present
(F
) loop
2077 Possible_Freeze
(Etype
(F
));
2078 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
2083 -- Mark functions that return by reference. Note that it cannot be
2084 -- done for delayed_freeze subprograms because the underlying
2085 -- returned type may not be known yet (for private types)
2087 if not Has_Delayed_Freeze
(Designator
)
2088 and then Expander_Active
2091 Typ
: constant Entity_Id
:= Etype
(Designator
);
2092 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
2095 if Is_Return_By_Reference_Type
(Typ
) then
2096 Set_Returns_By_Ref
(Designator
);
2098 elsif Present
(Utyp
) and then Controlled_Type
(Utyp
) then
2099 Set_Returns_By_Ref
(Designator
);
2103 end Check_Delayed_Subprogram
;
2105 ------------------------------------
2106 -- Check_Discriminant_Conformance --
2107 ------------------------------------
2109 procedure Check_Discriminant_Conformance
2114 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
2115 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
2116 New_Discr_Id
: Entity_Id
;
2117 New_Discr_Type
: Entity_Id
;
2119 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
2120 -- Post error message for conformance error on given node.
2121 -- Two messages are output. The first points to the previous
2122 -- declaration with a general "no conformance" message.
2123 -- The second is the detailed reason, supplied as Msg. The
2124 -- parameter N provide information for a possible & insertion
2127 -----------------------
2128 -- Conformance_Error --
2129 -----------------------
2131 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
2133 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
2134 Error_Msg_N
("not fully conformant with declaration#!", N
);
2135 Error_Msg_NE
(Msg
, N
, N
);
2136 end Conformance_Error
;
2138 -- Start of processing for Check_Discriminant_Conformance
2141 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
2143 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
2145 -- The subtype mark of the discriminant on the full type
2146 -- has not been analyzed so we do it here. For an access
2147 -- discriminant a new type is created.
2149 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
2151 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
2154 Analyze
(Discriminant_Type
(New_Discr
));
2155 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
2158 if not Conforming_Types
2159 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
2161 Conformance_Error
("type of & does not match!", New_Discr_Id
);
2167 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
2168 Conformance_Error
("name & does not match!", New_Discr_Id
);
2172 -- Default expressions must match
2175 NewD
: constant Boolean :=
2176 Present
(Expression
(New_Discr
));
2177 OldD
: constant Boolean :=
2178 Present
(Expression
(Parent
(Old_Discr
)));
2181 if NewD
or OldD
then
2183 -- The old default value has been analyzed and expanded,
2184 -- because the current full declaration will have frozen
2185 -- everything before. The new default values have not
2186 -- been expanded, so expand now to check conformance.
2189 Analyze_Default_Expression
2190 (Expression
(New_Discr
), New_Discr_Type
);
2193 if not (NewD
and OldD
)
2194 or else not Fully_Conformant_Expressions
2195 (Expression
(Parent
(Old_Discr
)),
2196 Expression
(New_Discr
))
2200 ("default expression for & does not match!",
2207 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
2211 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
2214 -- Grouping (use of comma in param lists) must be the same
2215 -- This is where we catch a misconformance like:
2218 -- A : Integer; B : Integer
2220 -- which are represented identically in the tree except
2221 -- for the setting of the flags More_Ids and Prev_Ids.
2223 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
2224 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
2227 ("grouping of & does not match!", New_Discr_Id
);
2233 Next_Discriminant
(Old_Discr
);
2237 if Present
(Old_Discr
) then
2238 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
2241 elsif Present
(New_Discr
) then
2243 ("too many discriminants!", Defining_Identifier
(New_Discr
));
2246 end Check_Discriminant_Conformance
;
2248 ----------------------------
2249 -- Check_Fully_Conformant --
2250 ----------------------------
2252 procedure Check_Fully_Conformant
2253 (New_Id
: Entity_Id
;
2255 Err_Loc
: Node_Id
:= Empty
)
2261 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
2262 end Check_Fully_Conformant
;
2264 ---------------------------
2265 -- Check_Mode_Conformant --
2266 ---------------------------
2268 procedure Check_Mode_Conformant
2269 (New_Id
: Entity_Id
;
2271 Err_Loc
: Node_Id
:= Empty
;
2272 Get_Inst
: Boolean := False)
2278 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
2279 end Check_Mode_Conformant
;
2285 procedure Check_Returns
2292 procedure Check_Statement_Sequence
(L
: List_Id
);
2293 -- Internal recursive procedure to check a list of statements for proper
2294 -- termination by a return statement (or a transfer of control or a
2295 -- compound statement that is itself internally properly terminated).
2297 ------------------------------
2298 -- Check_Statement_Sequence --
2299 ------------------------------
2301 procedure Check_Statement_Sequence
(L
: List_Id
) is
2305 Raise_Exception_Call
: Boolean;
2306 -- Set True if statement sequence terminated by Raise_Exception call
2307 -- or a Reraise_Occurrence call.
2310 Raise_Exception_Call
:= False;
2312 -- Get last real statement
2314 Last_Stm
:= Last
(L
);
2316 -- Don't count pragmas
2318 while Nkind
(Last_Stm
) = N_Pragma
2320 -- Don't count call to SS_Release (can happen after Raise_Exception)
2323 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
2325 Nkind
(Name
(Last_Stm
)) = N_Identifier
2327 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
2329 -- Don't count exception junk
2332 ((Nkind
(Last_Stm
) = N_Goto_Statement
2333 or else Nkind
(Last_Stm
) = N_Label
2334 or else Nkind
(Last_Stm
) = N_Object_Declaration
)
2335 and then Exception_Junk
(Last_Stm
))
2340 -- Here we have the "real" last statement
2342 Kind
:= Nkind
(Last_Stm
);
2344 -- Transfer of control, OK. Note that in the No_Return procedure
2345 -- case, we already diagnosed any explicit return statements, so
2346 -- we can treat them as OK in this context.
2348 if Is_Transfer
(Last_Stm
) then
2351 -- Check cases of explicit non-indirect procedure calls
2353 elsif Kind
= N_Procedure_Call_Statement
2354 and then Is_Entity_Name
(Name
(Last_Stm
))
2356 -- Check call to Raise_Exception procedure which is treated
2357 -- specially, as is a call to Reraise_Occurrence.
2359 -- We suppress the warning in these cases since it is likely that
2360 -- the programmer really does not expect to deal with the case
2361 -- of Null_Occurrence, and thus would find a warning about a
2362 -- missing return curious, and raising Program_Error does not
2363 -- seem such a bad behavior if this does occur.
2365 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
2367 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
2369 Raise_Exception_Call
:= True;
2371 -- For Raise_Exception call, test first argument, if it is
2372 -- an attribute reference for a 'Identity call, then we know
2373 -- that the call cannot possibly return.
2376 Arg
: constant Node_Id
:=
2377 Original_Node
(First_Actual
(Last_Stm
));
2380 if Nkind
(Arg
) = N_Attribute_Reference
2381 and then Attribute_Name
(Arg
) = Name_Identity
2388 -- If statement, need to look inside if there is an else and check
2389 -- each constituent statement sequence for proper termination.
2391 elsif Kind
= N_If_Statement
2392 and then Present
(Else_Statements
(Last_Stm
))
2394 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
2395 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
2397 if Present
(Elsif_Parts
(Last_Stm
)) then
2399 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
2402 while Present
(Elsif_Part
) loop
2403 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
2411 -- Case statement, check each case for proper termination
2413 elsif Kind
= N_Case_Statement
then
2418 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
2419 while Present
(Case_Alt
) loop
2420 Check_Statement_Sequence
(Statements
(Case_Alt
));
2421 Next_Non_Pragma
(Case_Alt
);
2427 -- Block statement, check its handled sequence of statements
2429 elsif Kind
= N_Block_Statement
then
2435 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
2444 -- Loop statement. If there is an iteration scheme, we can definitely
2445 -- fall out of the loop. Similarly if there is an exit statement, we
2446 -- can fall out. In either case we need a following return.
2448 elsif Kind
= N_Loop_Statement
then
2449 if Present
(Iteration_Scheme
(Last_Stm
))
2450 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
2454 -- A loop with no exit statement or iteration scheme if either
2455 -- an inifite loop, or it has some other exit (raise/return).
2456 -- In either case, no warning is required.
2462 -- Timed entry call, check entry call and delay alternatives
2464 -- Note: in expanded code, the timed entry call has been converted
2465 -- to a set of expanded statements on which the check will work
2466 -- correctly in any case.
2468 elsif Kind
= N_Timed_Entry_Call
then
2470 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
2471 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
2474 -- If statement sequence of entry call alternative is missing,
2475 -- then we can definitely fall through, and we post the error
2476 -- message on the entry call alternative itself.
2478 if No
(Statements
(ECA
)) then
2481 -- If statement sequence of delay alternative is missing, then
2482 -- we can definitely fall through, and we post the error
2483 -- message on the delay alternative itself.
2485 -- Note: if both ECA and DCA are missing the return, then we
2486 -- post only one message, should be enough to fix the bugs.
2487 -- If not we will get a message next time on the DCA when the
2490 elsif No
(Statements
(DCA
)) then
2493 -- Else check both statement sequences
2496 Check_Statement_Sequence
(Statements
(ECA
));
2497 Check_Statement_Sequence
(Statements
(DCA
));
2502 -- Conditional entry call, check entry call and else part
2504 -- Note: in expanded code, the conditional entry call has been
2505 -- converted to a set of expanded statements on which the check
2506 -- will work correctly in any case.
2508 elsif Kind
= N_Conditional_Entry_Call
then
2510 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
2513 -- If statement sequence of entry call alternative is missing,
2514 -- then we can definitely fall through, and we post the error
2515 -- message on the entry call alternative itself.
2517 if No
(Statements
(ECA
)) then
2520 -- Else check statement sequence and else part
2523 Check_Statement_Sequence
(Statements
(ECA
));
2524 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
2530 -- If we fall through, issue appropriate message
2534 if not Raise_Exception_Call
then
2536 ("?RETURN statement missing following this statement!",
2539 ("\?Program_Error may be raised at run time",
2543 -- Note: we set Err even though we have not issued a warning
2544 -- because we still have a case of a missing return. This is
2545 -- an extremely marginal case, probably will never be noticed
2546 -- but we might as well get it right.
2552 ("implied return after this statement not allowed (No_Return)",
2555 end Check_Statement_Sequence
;
2557 -- Start of processing for Check_Returns
2561 Check_Statement_Sequence
(Statements
(HSS
));
2563 if Present
(Exception_Handlers
(HSS
)) then
2564 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
2565 while Present
(Handler
) loop
2566 Check_Statement_Sequence
(Statements
(Handler
));
2567 Next_Non_Pragma
(Handler
);
2572 ----------------------------
2573 -- Check_Subprogram_Order --
2574 ----------------------------
2576 procedure Check_Subprogram_Order
(N
: Node_Id
) is
2578 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
2579 -- This is used to check if S1 > S2 in the sense required by this
2580 -- test, for example nameab < namec, but name2 < name10.
2582 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
2587 -- Remove trailing numeric parts
2590 while S1
(L1
) in '0' .. '9' loop
2595 while S2
(L2
) in '0' .. '9' loop
2599 -- If non-numeric parts non-equal, that's decisive
2601 if S1
(S1
'First .. L1
) < S2
(S2
'First .. L2
) then
2604 elsif S1
(S1
'First .. L1
) > S2
(S2
'First .. L2
) then
2607 -- If non-numeric parts equal, compare suffixed numeric parts. Note
2608 -- that a missing suffix is treated as numeric zero in this test.
2612 while L1
< S1
'Last loop
2614 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
2618 while L2
< S2
'Last loop
2620 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
2625 end Subprogram_Name_Greater
;
2627 -- Start of processing for Check_Subprogram_Order
2630 -- Check body in alpha order if this is option
2632 if Style_Check_Subprogram_Order
2633 and then Nkind
(N
) = N_Subprogram_Body
2634 and then Comes_From_Source
(N
)
2635 and then In_Extended_Main_Source_Unit
(N
)
2639 renames Scope_Stack
.Table
2640 (Scope_Stack
.Last
).Last_Subprogram_Name
;
2642 Body_Id
: constant Entity_Id
:=
2643 Defining_Entity
(Specification
(N
));
2646 Get_Decoded_Name_String
(Chars
(Body_Id
));
2649 if Subprogram_Name_Greater
2650 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
2652 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
2658 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
2661 end Check_Subprogram_Order;
2663 ------------------------------
2664 -- Check_Subtype_Conformant --
2665 ------------------------------
2667 procedure Check_Subtype_Conformant
2668 (New_Id : Entity_Id;
2670 Err_Loc : Node_Id := Empty)
2676 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
2677 end Check_Subtype_Conformant;
2679 ---------------------------
2680 -- Check_Type_Conformant --
2681 ---------------------------
2683 procedure Check_Type_Conformant
2684 (New_Id : Entity_Id;
2686 Err_Loc : Node_Id := Empty)
2692 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
2693 end Check_Type_Conformant;
2695 ----------------------
2696 -- Conforming_Types --
2697 ----------------------
2699 function Conforming_Types
2702 Ctype : Conformance_Type;
2703 Get_Inst : Boolean := False)
2706 Type_1 : Entity_Id := T1;
2707 Type_2 : Entity_Id := T2;
2709 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
2710 -- If neither T1 nor T2 are generic actual types, then verify
2711 -- that the base types are equal. Otherwise T1 and T2 must be
2712 -- on the same subtype chain. The whole purpose of this procedure
2713 -- is to prevent spurious ambiguities in an instantiation that may
2714 -- arise if two distinct generic types are instantiated with the
2717 ----------------------
2718 -- Base_Types_Match --
2719 ----------------------
2721 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
2726 elsif Base_Type (T1) = Base_Type (T2) then
2728 -- The following is too permissive. A more precise test must
2729 -- check that the generic actual is an ancestor subtype of the
2732 return not Is_Generic_Actual_Type (T1)
2733 or else not Is_Generic_Actual_Type (T2);
2738 end Base_Types_Match;
2741 -- The context is an instance association for a formal
2742 -- access-to-subprogram type; the formal parameter types
2743 -- require mapping because they may denote other formal
2744 -- parameters of the generic unit.
2747 Type_1 := Get_Instance_Of (T1);
2748 Type_2 := Get_Instance_Of (T2);
2751 -- First see if base types match
2753 if Base_Types_Match (Type_1, Type_2) then
2754 return Ctype <= Mode_Conformant
2755 or else Subtypes_Statically_Match (Type_1, Type_2);
2757 elsif Is_Incomplete_Or_Private_Type (Type_1)
2758 and then Present (Full_View (Type_1))
2759 and then Base_Types_Match (Full_View (Type_1), Type_2)
2761 return Ctype <= Mode_Conformant
2762 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
2764 elsif Ekind (Type_2) = E_Incomplete_Type
2765 and then Present (Full_View (Type_2))
2766 and then Base_Types_Match (Type_1, Full_View (Type_2))
2768 return Ctype <= Mode_Conformant
2769 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
2772 -- Test anonymous access type case. For this case, static subtype
2773 -- matching is required for mode conformance (RM 6.3.1(15))
2775 if Ekind (Type_1) = E_Anonymous_Access_Type
2776 and then Ekind (Type_2) = E_Anonymous_Access_Type
2779 Desig_1 : Entity_Id;
2780 Desig_2 : Entity_Id;
2783 Desig_1 := Directly_Designated_Type (Type_1);
2785 -- An access parameter can designate an incomplete type.
2787 if Ekind (Desig_1) = E_Incomplete_Type
2788 and then Present (Full_View (Desig_1))
2790 Desig_1 := Full_View (Desig_1);
2793 Desig_2 := Directly_Designated_Type (Type_2);
2795 if Ekind (Desig_2) = E_Incomplete_Type
2796 and then Present (Full_View (Desig_2))
2798 Desig_2 := Full_View (Desig_2);
2801 -- The context is an instance association for a formal
2802 -- access-to-subprogram type; formal access parameter
2803 -- designated types require mapping because they may
2804 -- denote other formal parameters of the generic unit.
2807 Desig_1 := Get_Instance_Of (Desig_1);
2808 Desig_2 := Get_Instance_Of (Desig_2);
2811 -- It is possible for a Class_Wide_Type to be introduced for
2812 -- an incomplete type, in which case there is a separate class_
2813 -- wide type for the full view. The types conform if their
2814 -- Etypes conform, i.e. one may be the full view of the other.
2815 -- This can only happen in the context of an access parameter,
2816 -- other uses of an incomplete Class_Wide_Type are illegal.
2818 if Ekind (Desig_1) = E_Class_Wide_Type
2819 and then Ekind (Desig_2) = E_Class_Wide_Type
2822 Conforming_Types (Etype (Desig_1), Etype (Desig_2), Ctype);
2824 return Base_Type (Desig_1) = Base_Type (Desig_2)
2825 and then (Ctype = Type_Conformant
2827 Subtypes_Statically_Match (Desig_1, Desig_2));
2831 -- Otherwise definitely no match
2837 end Conforming_Types;
2839 --------------------------
2840 -- Create_Extra_Formals --
2841 --------------------------
2843 procedure Create_Extra_Formals (E : Entity_Id) is
2845 Last_Formal : Entity_Id;
2846 Last_Extra : Entity_Id;
2847 Formal_Type : Entity_Id;
2848 P_Formal : Entity_Id := Empty;
2850 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id;
2851 -- Add an extra formal, associated with the current Formal. The
2852 -- extra formal is added to the list of extra formals, and also
2853 -- returned as the result. These formals are always of mode IN.
2855 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is
2856 EF : constant Entity_Id :=
2857 Make_Defining_Identifier (Sloc (Formal),
2858 Chars => New_External_Name (Chars (Formal), 'F
'));
2861 -- We never generate extra formals if expansion is not active
2862 -- because we don't need them unless we are generating code.
2864 if not Expander_Active then
2868 -- A little optimization. Never generate an extra formal for
2869 -- the _init operand of an initialization procedure, since it
2870 -- could never be used.
2872 if Chars (Formal) = Name_uInit then
2876 Set_Ekind (EF, E_In_Parameter);
2877 Set_Actual_Subtype (EF, Typ);
2878 Set_Etype (EF, Typ);
2879 Set_Scope (EF, Scope (Formal));
2880 Set_Mechanism (EF, Default_Mechanism);
2881 Set_Formal_Validity (EF);
2883 Set_Extra_Formal (Last_Extra, EF);
2886 end Add_Extra_Formal;
2888 -- Start of processing for Create_Extra_Formals
2891 -- If this is a derived subprogram then the subtypes of the
2892 -- parent subprogram's formal parameters will be used to
2893 -- to determine the need for extra formals.
2895 if Is_Overloadable (E) and then Present (Alias (E)) then
2896 P_Formal := First_Formal (Alias (E));
2899 Last_Extra := Empty;
2900 Formal := First_Formal (E);
2901 while Present (Formal) loop
2902 Last_Extra := Formal;
2903 Next_Formal (Formal);
2906 -- If Extra_formals where already created, don't do it again
2907 -- This situation may arise for subprogram types created as part
2908 -- of dispatching calls (see Expand_Dispatch_Call)
2910 if Present (Last_Extra) and then
2911 Present (Extra_Formal (Last_Extra))
2916 Formal := First_Formal (E);
2918 while Present (Formal) loop
2920 -- Create extra formal for supporting the attribute 'Constrained
.
2921 -- The case of a private type view without discriminants also
2922 -- requires the extra formal if the underlying type has defaulted
2925 if Ekind
(Formal
) /= E_In_Parameter
then
2926 if Present
(P_Formal
) then
2927 Formal_Type
:= Etype
(P_Formal
);
2929 Formal_Type
:= Etype
(Formal
);
2932 if not Has_Discriminants
(Formal_Type
)
2933 and then Ekind
(Formal_Type
) in Private_Kind
2934 and then Present
(Underlying_Type
(Formal_Type
))
2936 Formal_Type
:= Underlying_Type
(Formal_Type
);
2939 if Has_Discriminants
(Formal_Type
)
2941 ((not Is_Constrained
(Formal_Type
)
2942 and then not Is_Indefinite_Subtype
(Formal_Type
))
2943 or else Present
(Extra_Formal
(Formal
)))
2945 Set_Extra_Constrained
2946 (Formal
, Add_Extra_Formal
(Standard_Boolean
));
2950 -- Create extra formal for supporting accessibility checking
2952 -- This is suppressed if we specifically suppress accessibility
2953 -- checks for either the subprogram, or the package in which it
2954 -- resides. However, we do not suppress it simply if the scope
2955 -- has accessibility checks suppressed, since this could cause
2956 -- trouble when clients are compiled with a different suppression
2957 -- setting. The explicit checks are safe from this point of view.
2959 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
2961 (Suppress_Accessibility_Checks
(E
)
2963 Suppress_Accessibility_Checks
(Scope
(E
)))
2965 (not Present
(P_Formal
)
2966 or else Present
(Extra_Accessibility
(P_Formal
)))
2968 -- Temporary kludge: for now we avoid creating the extra
2969 -- formal for access parameters of protected operations
2970 -- because of problem with the case of internal protected
2973 if Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Definition
2974 and then Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Body
2976 Set_Extra_Accessibility
2977 (Formal
, Add_Extra_Formal
(Standard_Natural
));
2981 if Present
(P_Formal
) then
2982 Next_Formal
(P_Formal
);
2985 Last_Formal
:= Formal
;
2986 Next_Formal
(Formal
);
2988 end Create_Extra_Formals
;
2990 -----------------------------
2991 -- Enter_Overloaded_Entity --
2992 -----------------------------
2994 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
2995 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
2996 C_E
: Entity_Id
:= Current_Entity
(S
);
3000 Set_Has_Homonym
(E
);
3001 Set_Has_Homonym
(S
);
3004 Set_Is_Immediately_Visible
(S
);
3005 Set_Scope
(S
, Current_Scope
);
3007 -- Chain new entity if front of homonym in current scope, so that
3008 -- homonyms are contiguous.
3013 while Homonym
(C_E
) /= E
loop
3014 C_E
:= Homonym
(C_E
);
3017 Set_Homonym
(C_E
, S
);
3021 Set_Current_Entity
(S
);
3026 Append_Entity
(S
, Current_Scope
);
3027 Set_Public_Status
(S
);
3029 if Debug_Flag_E
then
3030 Write_Str
("New overloaded entity chain: ");
3031 Write_Name
(Chars
(S
));
3034 while Present
(E
) loop
3035 Write_Str
(" "); Write_Int
(Int
(E
));
3042 -- Generate warning for hiding
3045 and then Comes_From_Source
(S
)
3046 and then In_Extended_Main_Source_Unit
(S
)
3053 -- Warn unless genuine overloading
3055 if (not Is_Overloadable
(E
))
3056 or else Subtype_Conformant
(E
, S
)
3058 Error_Msg_Sloc
:= Sloc
(E
);
3059 Error_Msg_N
("declaration of & hides one#?", S
);
3063 end Enter_Overloaded_Entity
;
3065 -----------------------------
3066 -- Find_Corresponding_Spec --
3067 -----------------------------
3069 function Find_Corresponding_Spec
(N
: Node_Id
) return Entity_Id
is
3070 Spec
: constant Node_Id
:= Specification
(N
);
3071 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
3076 E
:= Current_Entity
(Designator
);
3078 while Present
(E
) loop
3080 -- We are looking for a matching spec. It must have the same scope,
3081 -- and the same name, and either be type conformant, or be the case
3082 -- of a library procedure spec and its body (which belong to one
3083 -- another regardless of whether they are type conformant or not).
3085 if Scope
(E
) = Current_Scope
then
3086 if (Current_Scope
= Standard_Standard
3087 or else (Ekind
(E
) = Ekind
(Designator
)
3089 Type_Conformant
(E
, Designator
)))
3091 -- Within an instantiation, we know that spec and body are
3092 -- subtype conformant, because they were subtype conformant
3093 -- in the generic. We choose the subtype-conformant entity
3094 -- here as well, to resolve spurious ambiguities in the
3095 -- instance that were not present in the generic (i.e. when
3096 -- two different types are given the same actual). If we are
3097 -- looking for a spec to match a body, full conformance is
3101 Set_Convention
(Designator
, Convention
(E
));
3103 if Nkind
(N
) = N_Subprogram_Body
3104 and then Present
(Homonym
(E
))
3105 and then not Fully_Conformant
(E
, Designator
)
3109 elsif not Subtype_Conformant
(E
, Designator
) then
3114 if not Has_Completion
(E
) then
3116 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3117 Set_Corresponding_Spec
(N
, E
);
3120 Set_Has_Completion
(E
);
3123 elsif Nkind
(Parent
(N
)) = N_Subunit
then
3125 -- If this is the proper body of a subunit, the completion
3126 -- flag is set when analyzing the stub.
3130 -- If body already exists, this is an error unless the
3131 -- previous declaration is the implicit declaration of
3132 -- a derived subprogram, or this is a spurious overloading
3135 elsif No
(Alias
(E
))
3136 and then not Is_Intrinsic_Subprogram
(E
)
3137 and then not In_Instance
3139 Error_Msg_Sloc
:= Sloc
(E
);
3140 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
3143 elsif Is_Child_Unit
(E
)
3145 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
3147 Nkind
(Parent
(Unit_Declaration_Node
(Designator
)))
3148 = N_Compilation_Unit
3151 -- Child units cannot be overloaded, so a conformance mismatch
3152 -- between body and a previous spec is an error.
3155 ("body of child unit does not match previous declaration", N
);
3163 -- On exit, we know that no previous declaration of subprogram exists
3166 end Find_Corresponding_Spec
;
3168 ----------------------
3169 -- Fully_Conformant --
3170 ----------------------
3172 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
3176 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
3178 end Fully_Conformant
;
3180 ----------------------------------
3181 -- Fully_Conformant_Expressions --
3182 ----------------------------------
3184 function Fully_Conformant_Expressions
3185 (Given_E1
: Node_Id
;
3189 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
3190 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
3191 -- We always test conformance on original nodes, since it is possible
3192 -- for analysis and/or expansion to make things look as though they
3193 -- conform when they do not, e.g. by converting 1+2 into 3.
3195 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
3196 renames Fully_Conformant_Expressions
;
3198 function FCL
(L1
, L2
: List_Id
) return Boolean;
3199 -- Compare elements of two lists for conformance. Elements have to
3200 -- be conformant, and actuals inserted as default parameters do not
3201 -- match explicit actuals with the same value.
3203 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
3204 -- Compare an operator node with a function call.
3210 function FCL
(L1
, L2
: List_Id
) return Boolean is
3214 if L1
= No_List
then
3220 if L2
= No_List
then
3226 -- Compare two lists, skipping rewrite insertions (we want to
3227 -- compare the original trees, not the expanded versions!)
3230 if Is_Rewrite_Insertion
(N1
) then
3232 elsif Is_Rewrite_Insertion
(N2
) then
3238 elsif not FCE
(N1
, N2
) then
3251 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
3252 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
3257 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
3262 Act
:= First
(Actuals
);
3264 if Nkind
(Op_Node
) in N_Binary_Op
then
3266 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
3273 return Present
(Act
)
3274 and then FCE
(Right_Opnd
(Op_Node
), Act
)
3275 and then No
(Next
(Act
));
3279 -- Start of processing for Fully_Conformant_Expressions
3282 -- Non-conformant if paren count does not match. Note: if some idiot
3283 -- complains that we don't do this right for more than 3 levels of
3284 -- parentheses, they will be treated with the respect they deserve :-)
3286 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
3289 -- If same entities are referenced, then they are conformant
3290 -- even if they have different forms (RM 8.3.1(19-20)).
3292 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
3293 if Present
(Entity
(E1
)) then
3294 return Entity
(E1
) = Entity
(E2
)
3295 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
3296 and then Ekind
(Entity
(E1
)) = E_Discriminant
3297 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
3299 elsif Nkind
(E1
) = N_Expanded_Name
3300 and then Nkind
(E2
) = N_Expanded_Name
3301 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
3302 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
3304 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
3307 -- Identifiers in component associations don't always have
3308 -- entities, but their names must conform.
3310 return Nkind
(E1
) = N_Identifier
3311 and then Nkind
(E2
) = N_Identifier
3312 and then Chars
(E1
) = Chars
(E2
);
3315 elsif Nkind
(E1
) = N_Character_Literal
3316 and then Nkind
(E2
) = N_Expanded_Name
3318 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
3319 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
3321 elsif Nkind
(E2
) = N_Character_Literal
3322 and then Nkind
(E1
) = N_Expanded_Name
3324 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
3325 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
3327 elsif Nkind
(E1
) in N_Op
3328 and then Nkind
(E2
) = N_Function_Call
3330 return FCO
(E1
, E2
);
3332 elsif Nkind
(E2
) in N_Op
3333 and then Nkind
(E1
) = N_Function_Call
3335 return FCO
(E2
, E1
);
3337 -- Otherwise we must have the same syntactic entity
3339 elsif Nkind
(E1
) /= Nkind
(E2
) then
3342 -- At this point, we specialize by node type
3349 FCL
(Expressions
(E1
), Expressions
(E2
))
3350 and then FCL
(Component_Associations
(E1
),
3351 Component_Associations
(E2
));
3354 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
3356 Nkind
(Expression
(E2
)) = N_Qualified_Expression
3358 return FCE
(Expression
(E1
), Expression
(E2
));
3360 -- Check that the subtype marks and any constraints
3365 Indic1
: constant Node_Id
:= Expression
(E1
);
3366 Indic2
: constant Node_Id
:= Expression
(E2
);
3371 if Nkind
(Indic1
) /= N_Subtype_Indication
then
3373 Nkind
(Indic2
) /= N_Subtype_Indication
3374 and then Entity
(Indic1
) = Entity
(Indic2
);
3376 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
3378 Nkind
(Indic1
) /= N_Subtype_Indication
3379 and then Entity
(Indic1
) = Entity
(Indic2
);
3382 if Entity
(Subtype_Mark
(Indic1
)) /=
3383 Entity
(Subtype_Mark
(Indic2
))
3388 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
3389 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
3391 while Present
(Elt1
) and then Present
(Elt2
) loop
3392 if not FCE
(Elt1
, Elt2
) then
3405 when N_Attribute_Reference
=>
3407 Attribute_Name
(E1
) = Attribute_Name
(E2
)
3408 and then FCL
(Expressions
(E1
), Expressions
(E2
));
3412 Entity
(E1
) = Entity
(E2
)
3413 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
3414 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3416 when N_And_Then | N_Or_Else | N_In | N_Not_In
=>
3418 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
3420 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3422 when N_Character_Literal
=>
3424 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
3426 when N_Component_Association
=>
3428 FCL
(Choices
(E1
), Choices
(E2
))
3429 and then FCE
(Expression
(E1
), Expression
(E2
));
3431 when N_Conditional_Expression
=>
3433 FCL
(Expressions
(E1
), Expressions
(E2
));
3435 when N_Explicit_Dereference
=>
3437 FCE
(Prefix
(E1
), Prefix
(E2
));
3439 when N_Extension_Aggregate
=>
3441 FCL
(Expressions
(E1
), Expressions
(E2
))
3442 and then Null_Record_Present
(E1
) =
3443 Null_Record_Present
(E2
)
3444 and then FCL
(Component_Associations
(E1
),
3445 Component_Associations
(E2
));
3447 when N_Function_Call
=>
3449 FCE
(Name
(E1
), Name
(E2
))
3450 and then FCL
(Parameter_Associations
(E1
),
3451 Parameter_Associations
(E2
));
3453 when N_Indexed_Component
=>
3455 FCE
(Prefix
(E1
), Prefix
(E2
))
3456 and then FCL
(Expressions
(E1
), Expressions
(E2
));
3458 when N_Integer_Literal
=>
3459 return (Intval
(E1
) = Intval
(E2
));
3464 when N_Operator_Symbol
=>
3466 Chars
(E1
) = Chars
(E2
);
3468 when N_Others_Choice
=>
3471 when N_Parameter_Association
=>
3474 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
3475 and then FCE
(Explicit_Actual_Parameter
(E1
),
3476 Explicit_Actual_Parameter
(E2
));
3478 when N_Qualified_Expression
=>
3480 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3481 and then FCE
(Expression
(E1
), Expression
(E2
));
3485 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
3486 and then FCE
(High_Bound
(E1
), High_Bound
(E2
));
3488 when N_Real_Literal
=>
3489 return (Realval
(E1
) = Realval
(E2
));
3491 when N_Selected_Component
=>
3493 FCE
(Prefix
(E1
), Prefix
(E2
))
3494 and then FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
3498 FCE
(Prefix
(E1
), Prefix
(E2
))
3499 and then FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
3501 when N_String_Literal
=>
3503 S1
: constant String_Id
:= Strval
(E1
);
3504 S2
: constant String_Id
:= Strval
(E2
);
3505 L1
: constant Nat
:= String_Length
(S1
);
3506 L2
: constant Nat
:= String_Length
(S2
);
3513 for J
in 1 .. L1
loop
3514 if Get_String_Char
(S1
, J
) /=
3515 Get_String_Char
(S2
, J
)
3525 when N_Type_Conversion
=>
3527 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3528 and then FCE
(Expression
(E1
), Expression
(E2
));
3532 Entity
(E1
) = Entity
(E2
)
3533 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3535 when N_Unchecked_Type_Conversion
=>
3537 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3538 and then FCE
(Expression
(E1
), Expression
(E2
));
3540 -- All other node types cannot appear in this context. Strictly
3541 -- we should raise a fatal internal error. Instead we just ignore
3542 -- the nodes. This means that if anyone makes a mistake in the
3543 -- expander and mucks an expression tree irretrievably, the
3544 -- result will be a failure to detect a (probably very obscure)
3545 -- case of non-conformance, which is better than bombing on some
3546 -- case where two expressions do in fact conform.
3553 end Fully_Conformant_Expressions
;
3555 --------------------
3556 -- Install_Entity --
3557 --------------------
3559 procedure Install_Entity
(E
: Entity_Id
) is
3560 Prev
: constant Entity_Id
:= Current_Entity
(E
);
3563 Set_Is_Immediately_Visible
(E
);
3564 Set_Current_Entity
(E
);
3565 Set_Homonym
(E
, Prev
);
3568 ---------------------
3569 -- Install_Formals --
3570 ---------------------
3572 procedure Install_Formals
(Id
: Entity_Id
) is
3576 F
:= First_Formal
(Id
);
3578 while Present
(F
) loop
3582 end Install_Formals
;
3584 ---------------------------------
3585 -- Is_Non_Overriding_Operation --
3586 ---------------------------------
3588 function Is_Non_Overriding_Operation
3589 (Prev_E
: Entity_Id
;
3595 G_Typ
: Entity_Id
:= Empty
;
3597 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
3598 -- If F_Type is a derived type associated with a generic actual
3599 -- subtype, then return its Generic_Parent_Type attribute, else
3602 function Types_Correspond
3603 (P_Type
: Entity_Id
;
3606 -- Returns true if and only if the types (or designated types
3607 -- in the case of anonymous access types) are the same or N_Type
3608 -- is derived directly or indirectly from P_Type.
3610 -----------------------------
3611 -- Get_Generic_Parent_Type --
3612 -----------------------------
3614 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
3619 if Is_Derived_Type
(F_Typ
)
3620 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
3622 -- The tree must be traversed to determine the parent
3623 -- subtype in the generic unit, which unfortunately isn't
3624 -- always available via semantic attributes. ???
3625 -- (Note: The use of Original_Node is needed for cases
3626 -- where a full derived type has been rewritten.)
3628 Indic
:= Subtype_Indication
3629 (Type_Definition
(Original_Node
(Parent
(F_Typ
))));
3631 if Nkind
(Indic
) = N_Subtype_Indication
then
3632 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
3634 G_Typ
:= Entity
(Indic
);
3637 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
3638 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
3640 return Generic_Parent_Type
(Parent
(G_Typ
));
3645 end Get_Generic_Parent_Type
;
3647 ----------------------
3648 -- Types_Correspond --
3649 ----------------------
3651 function Types_Correspond
3652 (P_Type
: Entity_Id
;
3656 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
3657 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
3660 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
3661 Prev_Type
:= Designated_Type
(Prev_Type
);
3664 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
3665 New_Type
:= Designated_Type
(New_Type
);
3668 if Prev_Type
= New_Type
then
3671 elsif not Is_Class_Wide_Type
(New_Type
) then
3672 while Etype
(New_Type
) /= New_Type
loop
3673 New_Type
:= Etype
(New_Type
);
3674 if New_Type
= Prev_Type
then
3680 end Types_Correspond
;
3682 -- Start of processing for Is_Non_Overriding_Operation
3685 -- In the case where both operations are implicit derived
3686 -- subprograms then neither overrides the other. This can
3687 -- only occur in certain obscure cases (e.g., derivation
3688 -- from homographs created in a generic instantiation).
3690 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
3693 elsif Ekind
(Current_Scope
) = E_Package
3694 and then Is_Generic_Instance
(Current_Scope
)
3695 and then In_Private_Part
(Current_Scope
)
3696 and then Comes_From_Source
(New_E
)
3698 -- We examine the formals and result subtype of the inherited
3699 -- operation, to determine whether their type is derived from
3700 -- (the instance of) a generic type.
3702 Formal
:= First_Formal
(Prev_E
);
3704 while Present
(Formal
) loop
3705 F_Typ
:= Base_Type
(Etype
(Formal
));
3707 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
3708 F_Typ
:= Designated_Type
(F_Typ
);
3711 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
3713 Next_Formal
(Formal
);
3716 if not Present
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
3717 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
3724 -- If the generic type is a private type, then the original
3725 -- operation was not overriding in the generic, because there was
3726 -- no primitive operation to override.
3728 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
3729 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
3730 N_Formal_Private_Type_Definition
3734 -- The generic parent type is the ancestor of a formal derived
3735 -- type declaration. We need to check whether it has a primitive
3736 -- operation that should be overridden by New_E in the generic.
3740 P_Formal
: Entity_Id
;
3741 N_Formal
: Entity_Id
;
3745 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
3748 while Present
(Prim_Elt
) loop
3749 P_Prim
:= Node
(Prim_Elt
);
3750 if Chars
(P_Prim
) = Chars
(New_E
)
3751 and then Ekind
(P_Prim
) = Ekind
(New_E
)
3753 P_Formal
:= First_Formal
(P_Prim
);
3754 N_Formal
:= First_Formal
(New_E
);
3755 while Present
(P_Formal
) and then Present
(N_Formal
) loop
3756 P_Typ
:= Etype
(P_Formal
);
3757 N_Typ
:= Etype
(N_Formal
);
3759 if not Types_Correspond
(P_Typ
, N_Typ
) then
3763 Next_Entity
(P_Formal
);
3764 Next_Entity
(N_Formal
);
3767 -- Found a matching primitive operation belonging to
3768 -- the formal ancestor type, so the new subprogram
3771 if not Present
(P_Formal
)
3772 and then not Present
(N_Formal
)
3773 and then (Ekind
(New_E
) /= E_Function
3776 (Etype
(P_Prim
), Etype
(New_E
)))
3782 Next_Elmt
(Prim_Elt
);
3785 -- If no match found, then the new subprogram does
3786 -- not override in the generic (nor in the instance).
3794 end Is_Non_Overriding_Operation
;
3796 ------------------------------
3797 -- Make_Inequality_Operator --
3798 ------------------------------
3800 -- S is the defining identifier of an equality operator. We build a
3801 -- subprogram declaration with the right signature. This operation is
3802 -- intrinsic, because it is always expanded as the negation of the
3803 -- call to the equality function.
3805 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
3806 Loc
: constant Source_Ptr
:= Sloc
(S
);
3809 Op_Name
: Entity_Id
;
3815 -- Check that equality was properly defined.
3817 if No
(Next_Formal
(First_Formal
(S
))) then
3821 A
:= Make_Defining_Identifier
(Loc
, Chars
(First_Formal
(S
)));
3822 B
:= Make_Defining_Identifier
(Loc
,
3823 Chars
(Next_Formal
(First_Formal
(S
))));
3825 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
3827 Formals
:= New_List
(
3828 Make_Parameter_Specification
(Loc
,
3829 Defining_Identifier
=> A
,
3831 New_Reference_To
(Etype
(First_Formal
(S
)), Loc
)),
3833 Make_Parameter_Specification
(Loc
,
3834 Defining_Identifier
=> B
,
3836 New_Reference_To
(Etype
(Next_Formal
(First_Formal
(S
))), Loc
)));
3839 Make_Subprogram_Declaration
(Loc
,
3841 Make_Function_Specification
(Loc
,
3842 Defining_Unit_Name
=> Op_Name
,
3843 Parameter_Specifications
=> Formals
,
3844 Subtype_Mark
=> New_Reference_To
(Standard_Boolean
, Loc
)));
3846 -- Insert inequality right after equality if it is explicit or after
3847 -- the derived type when implicit. These entities are created only
3848 -- for visibility purposes, and eventually replaced in the course of
3849 -- expansion, so they do not need to be attached to the tree and seen
3850 -- by the back-end. Keeping them internal also avoids spurious freezing
3851 -- problems. The parent field is set simply to make analysis safe.
3853 if No
(Alias
(S
)) then
3854 Set_Parent
(Decl
, Parent
(Unit_Declaration_Node
(S
)));
3856 Set_Parent
(Decl
, Parent
(Parent
(Etype
(First_Formal
(S
)))));
3859 Mark_Rewrite_Insertion
(Decl
);
3860 Set_Is_Intrinsic_Subprogram
(Op_Name
);
3862 Set_Has_Completion
(Op_Name
);
3863 Set_Corresponding_Equality
(Op_Name
, S
);
3864 Set_Is_Abstract
(Op_Name
, Is_Abstract
(S
));
3866 end Make_Inequality_Operator
;
3868 ----------------------
3869 -- May_Need_Actuals --
3870 ----------------------
3872 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
3877 F
:= First_Formal
(Fun
);
3880 while Present
(F
) loop
3881 if No
(Default_Value
(F
)) then
3889 Set_Needs_No_Actuals
(Fun
, B
);
3890 end May_Need_Actuals
;
3892 ---------------------
3893 -- Mode_Conformant --
3894 ---------------------
3896 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
3900 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
3902 end Mode_Conformant
;
3904 ---------------------------
3905 -- New_Overloaded_Entity --
3906 ---------------------------
3908 procedure New_Overloaded_Entity
3910 Derived_Type
: Entity_Id
:= Empty
)
3912 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
3913 Prev_Vis
: Entity_Id
:= Empty
;
3915 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
3916 -- Check that E is declared in the private part of the current package,
3917 -- or in the package body, where it may hide a previous declaration.
3918 -- We can' use In_Private_Part by itself because this flag is also
3919 -- set when freezing entities, so we must examine the place of the
3920 -- declaration in the tree, and recognize wrapper packages as well.
3922 procedure Maybe_Primitive_Operation
(Overriding
: Boolean := False);
3923 -- If the subprogram being analyzed is a primitive operation of
3924 -- the type of one of its formals, set the corresponding flag.
3926 ----------------------------
3927 -- Is_Private_Declaration --
3928 ----------------------------
3930 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
3931 Priv_Decls
: List_Id
;
3932 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
3935 if Is_Package
(Current_Scope
)
3936 and then In_Private_Part
(Current_Scope
)
3939 Private_Declarations
(
3940 Specification
(Unit_Declaration_Node
(Current_Scope
)));
3942 return In_Package_Body
(Current_Scope
)
3943 or else List_Containing
(Decl
) = Priv_Decls
3944 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
3945 and then not Is_Compilation_Unit
(
3946 Defining_Entity
(Parent
(Decl
)))
3947 and then List_Containing
(Parent
(Parent
(Decl
)))
3952 end Is_Private_Declaration
;
3954 -------------------------------
3955 -- Maybe_Primitive_Operation --
3956 -------------------------------
3958 procedure Maybe_Primitive_Operation
(Overriding
: Boolean := False) is
3962 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
3963 -- Returns true if T is declared in the visible part of
3964 -- the current package scope; otherwise returns false.
3965 -- Assumes that T is declared in a package.
3967 procedure Check_Private_Overriding
(T
: Entity_Id
);
3968 -- Checks that if a primitive abstract subprogram of a visible
3969 -- abstract type is declared in a private part, then it must
3970 -- override an abstract subprogram declared in the visible part.
3971 -- Also checks that if a primitive function with a controlling
3972 -- result is declared in a private part, then it must override
3973 -- a function declared in the visible part.
3975 ------------------------------
3976 -- Check_Private_Overriding --
3977 ------------------------------
3979 procedure Check_Private_Overriding
(T
: Entity_Id
) is
3981 if Ekind
(Current_Scope
) = E_Package
3982 and then In_Private_Part
(Current_Scope
)
3983 and then Visible_Part_Type
(T
)
3984 and then not In_Instance
3987 and then Is_Abstract
(S
)
3988 and then (not Overriding
or else not Is_Abstract
(E
))
3990 Error_Msg_N
("abstract subprograms must be visible "
3991 & "('R'M 3.9.3(10))!", S
);
3993 elsif Ekind
(S
) = E_Function
3994 and then Is_Tagged_Type
(T
)
3995 and then T
= Base_Type
(Etype
(S
))
3996 and then not Overriding
3999 ("private function with tagged result must"
4000 & " override visible-part function", S
);
4002 ("\move subprogram to the visible part"
4003 & " ('R'M 3.9.3(10))", S
);
4006 end Check_Private_Overriding
;
4008 -----------------------
4009 -- Visible_Part_Type --
4010 -----------------------
4012 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
4013 P
: Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
4014 N
: Node_Id
:= First
(Visible_Declarations
(Specification
(P
)));
4017 -- If the entity is a private type, then it must be
4018 -- declared in a visible part.
4020 if Ekind
(T
) in Private_Kind
then
4024 -- Otherwise, we traverse the visible part looking for its
4025 -- corresponding declaration. We cannot use the declaration
4026 -- node directly because in the private part the entity of a
4027 -- private type is the one in the full view, which does not
4028 -- indicate that it is the completion of something visible.
4030 while Present
(N
) loop
4031 if Nkind
(N
) = N_Full_Type_Declaration
4032 and then Present
(Defining_Identifier
(N
))
4033 and then T
= Defining_Identifier
(N
)
4037 elsif (Nkind
(N
) = N_Private_Type_Declaration
4039 Nkind
(N
) = N_Private_Extension_Declaration
)
4040 and then Present
(Defining_Identifier
(N
))
4041 and then T
= Full_View
(Defining_Identifier
(N
))
4050 end Visible_Part_Type
;
4052 -- Start of processing for Maybe_Primitive_Operation
4055 if not Comes_From_Source
(S
) then
4058 elsif (Ekind
(Current_Scope
) = E_Package
4059 and then not In_Package_Body
(Current_Scope
))
4063 if Ekind
(S
) = E_Function
4064 and then Scope
(Base_Type
(Etype
(S
))) = Current_Scope
4066 Set_Has_Primitive_Operations
(Base_Type
(Etype
(S
)));
4067 Check_Private_Overriding
(Base_Type
(Etype
(S
)));
4070 Formal
:= First_Formal
(S
);
4072 while Present
(Formal
) loop
4073 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
4074 F_Typ
:= Designated_Type
(Etype
(Formal
));
4076 F_Typ
:= Etype
(Formal
);
4079 if Scope
(Base_Type
(F_Typ
)) = Current_Scope
then
4080 Set_Has_Primitive_Operations
(Base_Type
(F_Typ
));
4081 Check_Private_Overriding
(Base_Type
(F_Typ
));
4084 Next_Formal
(Formal
);
4088 end Maybe_Primitive_Operation
;
4090 -- Start of processing for New_Overloaded_Entity
4094 Enter_Overloaded_Entity
(S
);
4095 Check_Dispatching_Operation
(S
, Empty
);
4096 Maybe_Primitive_Operation
;
4098 elsif not Is_Overloadable
(E
) then
4100 -- Check for spurious conflict produced by a subprogram that has the
4101 -- same name as that of the enclosing generic package. The conflict
4102 -- occurs within an instance, between the subprogram and the renaming
4103 -- declaration for the package. After the subprogram, the package
4104 -- renaming declaration becomes hidden.
4106 if Ekind
(E
) = E_Package
4107 and then Present
(Renamed_Object
(E
))
4108 and then Renamed_Object
(E
) = Current_Scope
4109 and then Nkind
(Parent
(Renamed_Object
(E
))) =
4110 N_Package_Specification
4111 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
4114 Set_Is_Immediately_Visible
(E
, False);
4115 Enter_Overloaded_Entity
(S
);
4116 Set_Homonym
(S
, Homonym
(E
));
4117 Check_Dispatching_Operation
(S
, Empty
);
4119 -- If the subprogram is implicit it is hidden by the previous
4120 -- declaration. However if it is dispatching, it must appear in
4121 -- the dispatch table anyway, because it can be dispatched to
4122 -- even if it cannot be called directly.
4124 elsif Present
(Alias
(S
))
4125 and then not Comes_From_Source
(S
)
4127 Set_Scope
(S
, Current_Scope
);
4129 if Is_Dispatching_Operation
(Alias
(S
)) then
4130 Check_Dispatching_Operation
(S
, Empty
);
4136 Error_Msg_Sloc
:= Sloc
(E
);
4137 Error_Msg_N
("& conflicts with declaration#", S
);
4139 -- Useful additional warning.
4141 if Is_Generic_Unit
(E
) then
4142 Error_Msg_N
("\previous generic unit cannot be overloaded", S
);
4149 -- E exists and is overloadable. Determine whether S is the body
4150 -- of E, a new overloaded entity with a different signature, or
4151 -- an error altogether.
4153 while Present
(E
) loop
4154 if Scope
(E
) /= Current_Scope
then
4157 elsif Type_Conformant
(E
, S
) then
4159 -- If the old and new entities have the same profile and
4160 -- one is not the body of the other, then this is an error,
4161 -- unless one of them is implicitly declared.
4163 -- There are some cases when both can be implicit, for example
4164 -- when both a literal and a function that overrides it are
4165 -- inherited in a derivation, or when an inhertited operation
4166 -- of a tagged full type overrides the ineherited operation of
4167 -- a private extension. Ada 83 had a special rule for the
4168 -- the literal case. In Ada95, the later implicit operation
4169 -- hides the former, and the literal is always the former.
4170 -- In the odd case where both are derived operations declared
4171 -- at the same point, both operations should be declared,
4172 -- and in that case we bypass the following test and proceed
4173 -- to the next part (this can only occur for certain obscure
4174 -- cases involving homographs in instances and can't occur for
4175 -- dispatching operations ???). Note that the following
4176 -- condition is less than clear. For example, it's not at
4177 -- all clear why there's a test for E_Entry here. ???
4179 if Present
(Alias
(S
))
4180 and then (No
(Alias
(E
))
4181 or else Comes_From_Source
(E
)
4182 or else Is_Dispatching_Operation
(E
))
4184 (Ekind
(E
) = E_Entry
4185 or else Ekind
(E
) /= E_Enumeration_Literal
)
4187 -- When an derived operation is overloaded it may be due
4188 -- to the fact that the full view of a private extension
4189 -- re-inherits. It has to be dealt with.
4191 if Is_Package
(Current_Scope
)
4192 and then In_Private_Part
(Current_Scope
)
4194 Check_Operation_From_Private_View
(S
, E
);
4197 -- In any case the implicit operation remains hidden by
4198 -- the existing declaration.
4202 -- Within an instance, the renaming declarations for
4203 -- actual subprograms may become ambiguous, but they do
4204 -- not hide each other.
4206 elsif Ekind
(E
) /= E_Entry
4207 and then not Comes_From_Source
(E
)
4208 and then not Is_Generic_Instance
(E
)
4209 and then (Present
(Alias
(E
))
4210 or else Is_Intrinsic_Subprogram
(E
))
4211 and then (not In_Instance
4212 or else No
(Parent
(E
))
4213 or else Nkind
(Unit_Declaration_Node
(E
)) /=
4214 N_Subprogram_Renaming_Declaration
)
4216 -- A subprogram child unit is not allowed to override
4217 -- an inherited subprogram (10.1.1(20)).
4219 if Is_Child_Unit
(S
) then
4221 ("child unit overrides inherited subprogram in parent",
4226 if Is_Non_Overriding_Operation
(E
, S
) then
4227 Enter_Overloaded_Entity
(S
);
4228 if not Present
(Derived_Type
)
4229 or else Is_Tagged_Type
(Derived_Type
)
4231 Check_Dispatching_Operation
(S
, Empty
);
4237 -- E is a derived operation or an internal operator which
4238 -- is being overridden. Remove E from further visibility.
4239 -- Furthermore, if E is a dispatching operation, it must be
4240 -- replaced in the list of primitive operations of its type
4241 -- (see Override_Dispatching_Operation).
4247 Prev
:= First_Entity
(Current_Scope
);
4249 while Present
(Prev
)
4250 and then Next_Entity
(Prev
) /= E
4255 -- It is possible for E to be in the current scope and
4256 -- yet not in the entity chain. This can only occur in a
4257 -- generic context where E is an implicit concatenation
4258 -- in the formal part, because in a generic body the
4259 -- entity chain starts with the formals.
4262 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
4264 -- E must be removed both from the entity_list of the
4265 -- current scope, and from the visibility chain
4267 if Debug_Flag_E
then
4268 Write_Str
("Override implicit operation ");
4269 Write_Int
(Int
(E
));
4273 -- If E is a predefined concatenation, it stands for four
4274 -- different operations. As a result, a single explicit
4275 -- declaration does not hide it. In a possible ambiguous
4276 -- situation, Disambiguate chooses the user-defined op,
4277 -- so it is correct to retain the previous internal one.
4279 if Chars
(E
) /= Name_Op_Concat
4280 or else Ekind
(E
) /= E_Operator
4282 -- For nondispatching derived operations that are
4283 -- overridden by a subprogram declared in the private
4284 -- part of a package, we retain the derived subprogram
4285 -- but mark it as not immediately visible. If the
4286 -- derived operation was declared in the visible part
4287 -- then this ensures that it will still be visible
4288 -- outside the package with the proper signature
4289 -- (calls from outside must also be directed to this
4290 -- version rather than the overriding one, unlike the
4291 -- dispatching case). Calls from inside the package
4292 -- will still resolve to the overriding subprogram
4293 -- since the derived one is marked as not visible
4294 -- within the package.
4296 -- If the private operation is dispatching, we achieve
4297 -- the overriding by keeping the implicit operation
4298 -- but setting its alias to be the overring one. In
4299 -- this fashion the proper body is executed in all
4300 -- cases, but the original signature is used outside
4303 -- If the overriding is not in the private part, we
4304 -- remove the implicit operation altogether.
4306 if Is_Private_Declaration
(S
) then
4308 if not Is_Dispatching_Operation
(E
) then
4309 Set_Is_Immediately_Visible
(E
, False);
4312 -- work done in Override_Dispatching_Operation.
4318 -- Find predecessor of E in Homonym chain.
4320 if E
= Current_Entity
(E
) then
4323 Prev_Vis
:= Current_Entity
(E
);
4324 while Homonym
(Prev_Vis
) /= E
loop
4325 Prev_Vis
:= Homonym
(Prev_Vis
);
4329 if Prev_Vis
/= Empty
then
4331 -- Skip E in the visibility chain
4333 Set_Homonym
(Prev_Vis
, Homonym
(E
));
4336 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
4339 Set_Next_Entity
(Prev
, Next_Entity
(E
));
4341 if No
(Next_Entity
(Prev
)) then
4342 Set_Last_Entity
(Current_Scope
, Prev
);
4348 Enter_Overloaded_Entity
(S
);
4350 if Is_Dispatching_Operation
(E
) then
4351 -- An overriding dispatching subprogram inherits
4352 -- the convention of the overridden subprogram
4355 Set_Convention
(S
, Convention
(E
));
4357 Check_Dispatching_Operation
(S
, E
);
4359 Check_Dispatching_Operation
(S
, Empty
);
4362 Maybe_Primitive_Operation
(Overriding
=> True);
4363 goto Check_Inequality
;
4366 -- Apparent redeclarations in instances can occur when two
4367 -- formal types get the same actual type. The subprograms in
4368 -- in the instance are legal, even if not callable from the
4369 -- outside. Calls from within are disambiguated elsewhere.
4370 -- For dispatching operations in the visible part, the usual
4371 -- rules apply, and operations with the same profile are not
4374 elsif (In_Instance_Visible_Part
4375 and then not Is_Dispatching_Operation
(E
))
4376 or else In_Instance_Not_Visible
4380 -- Here we have a real error (identical profile)
4383 Error_Msg_Sloc
:= Sloc
(E
);
4385 -- Avoid cascaded errors if the entity appears in
4386 -- subsequent calls.
4388 Set_Scope
(S
, Current_Scope
);
4390 Error_Msg_N
("& conflicts with declaration#", S
);
4392 if Is_Generic_Instance
(S
)
4393 and then not Has_Completion
(E
)
4396 ("\instantiation cannot provide body for it", S
);
4410 -- On exit, we know that S is a new entity
4412 Enter_Overloaded_Entity
(S
);
4413 Maybe_Primitive_Operation
;
4415 -- If S is a derived operation for an untagged type then
4416 -- by definition it's not a dispatching operation (even
4417 -- if the parent operation was dispatching), so we don't
4418 -- call Check_Dispatching_Operation in that case.
4420 if not Present
(Derived_Type
)
4421 or else Is_Tagged_Type
(Derived_Type
)
4423 Check_Dispatching_Operation
(S
, Empty
);
4427 -- If this is a user-defined equality operator that is not
4428 -- a derived subprogram, create the corresponding inequality.
4429 -- If the operation is dispatching, the expansion is done
4430 -- elsewhere, and we do not create an explicit inequality
4433 <<Check_Inequality
>>
4434 if Chars
(S
) = Name_Op_Eq
4435 and then Etype
(S
) = Standard_Boolean
4436 and then Present
(Parent
(S
))
4437 and then not Is_Dispatching_Operation
(S
)
4439 Make_Inequality_Operator
(S
);
4442 end New_Overloaded_Entity
;
4444 ---------------------
4445 -- Process_Formals --
4446 ---------------------
4448 procedure Process_Formals
4451 Related_Nod
: Node_Id
)
4453 Param_Spec
: Node_Id
;
4455 Formal_Type
: Entity_Id
;
4460 -- In order to prevent premature use of the formals in the same formal
4461 -- part, the Ekind is left undefined until all default expressions are
4462 -- analyzed. The Ekind is established in a separate loop at the end.
4464 Param_Spec
:= First
(T
);
4466 while Present
(Param_Spec
) loop
4468 Formal
:= Defining_Identifier
(Param_Spec
);
4469 Enter_Name
(Formal
);
4471 -- Case of ordinary parameters
4473 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
4474 Find_Type
(Parameter_Type
(Param_Spec
));
4475 Ptype
:= Parameter_Type
(Param_Spec
);
4477 if Ptype
= Error
then
4481 Formal_Type
:= Entity
(Ptype
);
4483 if Ekind
(Formal_Type
) = E_Incomplete_Type
4484 or else (Is_Class_Wide_Type
(Formal_Type
)
4485 and then Ekind
(Root_Type
(Formal_Type
)) =
4488 if Nkind
(Parent
(T
)) /= N_Access_Function_Definition
4489 and then Nkind
(Parent
(T
)) /= N_Access_Procedure_Definition
4491 Error_Msg_N
("invalid use of incomplete type", Param_Spec
);
4494 elsif Ekind
(Formal_Type
) = E_Void
then
4495 Error_Msg_NE
("premature use of&",
4496 Parameter_Type
(Param_Spec
), Formal_Type
);
4499 -- An access formal type
4503 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
4506 Set_Etype
(Formal
, Formal_Type
);
4508 Default
:= Expression
(Param_Spec
);
4510 if Present
(Default
) then
4511 if Out_Present
(Param_Spec
) then
4513 ("default initialization only allowed for IN parameters",
4517 -- Do the special preanalysis of the expression (see section on
4518 -- "Handling of Default Expressions" in the spec of package Sem).
4520 Analyze_Default_Expression
(Default
, Formal_Type
);
4522 -- Check that the designated type of an access parameter's
4523 -- default is not a class-wide type unless the parameter's
4524 -- designated type is also class-wide.
4526 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
4527 and then Is_Class_Wide_Type
(Designated_Type
(Etype
(Default
)))
4528 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
4530 Wrong_Type
(Default
, Formal_Type
);
4538 -- Now set the kind (mode) of each formal
4540 Param_Spec
:= First
(T
);
4542 while Present
(Param_Spec
) loop
4543 Formal
:= Defining_Identifier
(Param_Spec
);
4544 Set_Formal_Mode
(Formal
);
4546 if Ekind
(Formal
) = E_In_Parameter
then
4547 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
4549 if Present
(Expression
(Param_Spec
)) then
4550 Default
:= Expression
(Param_Spec
);
4552 if Is_Scalar_Type
(Etype
(Default
)) then
4554 (Parameter_Type
(Param_Spec
)) /= N_Access_Definition
4556 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
4559 Formal_Type
:= Access_Definition
4560 (Related_Nod
, Parameter_Type
(Param_Spec
));
4563 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
4572 end Process_Formals
;
4574 -------------------------
4575 -- Set_Actual_Subtypes --
4576 -------------------------
4578 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
4579 Loc
: constant Source_Ptr
:= Sloc
(N
);
4583 First_Stmt
: Node_Id
:= Empty
;
4584 AS_Needed
: Boolean;
4587 Formal
:= First_Formal
(Subp
);
4588 while Present
(Formal
) loop
4589 T
:= Etype
(Formal
);
4591 -- We never need an actual subtype for a constrained formal.
4593 if Is_Constrained
(T
) then
4596 -- If we have unknown discriminants, then we do not need an
4597 -- actual subtype, or more accurately we cannot figure it out!
4598 -- Note that all class-wide types have unknown discriminants.
4600 elsif Has_Unknown_Discriminants
(T
) then
4603 -- At this stage we have an unconstrained type that may need
4604 -- an actual subtype. For sure the actual subtype is needed
4605 -- if we have an unconstrained array type.
4607 elsif Is_Array_Type
(T
) then
4610 -- The only other case which needs an actual subtype is an
4611 -- unconstrained record type which is an IN parameter (we
4612 -- cannot generate actual subtypes for the OUT or IN OUT case,
4613 -- since an assignment can change the discriminant values.
4614 -- However we exclude the case of initialization procedures,
4615 -- since discriminants are handled very specially in this context,
4616 -- see the section entitled "Handling of Discriminants" in Einfo.
4617 -- We also exclude the case of Discrim_SO_Functions (functions
4618 -- used in front end layout mode for size/offset values), since
4619 -- in such functions only discriminants are referenced, and not
4620 -- only are such subtypes not needed, but they cannot always
4621 -- be generated, because of order of elaboration issues.
4623 elsif Is_Record_Type
(T
)
4624 and then Ekind
(Formal
) = E_In_Parameter
4625 and then Chars
(Formal
) /= Name_uInit
4626 and then not Is_Discrim_SO_Function
(Subp
)
4630 -- All other cases do not need an actual subtype
4636 -- Generate actual subtypes for unconstrained arrays and
4637 -- unconstrained discriminated records.
4640 Decl
:= Build_Actual_Subtype
(T
, Formal
);
4642 if Nkind
(N
) = N_Accept_Statement
then
4643 if Present
(Handled_Statement_Sequence
(N
)) then
4645 First
(Statements
(Handled_Statement_Sequence
(N
)));
4646 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
4647 Mark_Rewrite_Insertion
(Decl
);
4649 -- If the accept statement has no body, there will be
4650 -- no reference to the actuals, so no need to compute
4657 Prepend
(Decl
, Declarations
(N
));
4658 Mark_Rewrite_Insertion
(Decl
);
4663 -- We need to freeze manually the generated type when it is
4664 -- inserted anywhere else than in a declarative part.
4666 if Present
(First_Stmt
) then
4667 Insert_List_Before_And_Analyze
(First_Stmt
,
4668 Freeze_Entity
(Defining_Identifier
(Decl
), Loc
));
4671 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
4674 Next_Formal
(Formal
);
4676 end Set_Actual_Subtypes
;
4678 ---------------------
4679 -- Set_Formal_Mode --
4680 ---------------------
4682 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
4683 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
4686 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
4687 -- since we ensure that corresponding actuals are always valid at the
4688 -- point of the call.
4690 if Out_Present
(Spec
) then
4692 if Ekind
(Scope
(Formal_Id
)) = E_Function
4693 or else Ekind
(Scope
(Formal_Id
)) = E_Generic_Function
4695 Error_Msg_N
("functions can only have IN parameters", Spec
);
4696 Set_Ekind
(Formal_Id
, E_In_Parameter
);
4698 elsif In_Present
(Spec
) then
4699 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
4702 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
4703 Set_Not_Source_Assigned
(Formal_Id
);
4707 Set_Ekind
(Formal_Id
, E_In_Parameter
);
4710 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
4711 Set_Formal_Validity
(Formal_Id
);
4712 end Set_Formal_Mode
;
4714 -------------------------
4715 -- Set_Formal_Validity --
4716 -------------------------
4718 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
4720 -- If in full validity checking mode, then we can assume that
4721 -- an IN or IN OUT parameter is valid (see Exp_Ch5.Expand_Call)
4723 if not Validity_Checks_On
then
4726 elsif Ekind
(Formal_Id
) = E_In_Parameter
4727 and then Validity_Check_In_Params
4729 Set_Is_Known_Valid
(Formal_Id
, True);
4731 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
4732 and then Validity_Check_In_Out_Params
4734 Set_Is_Known_Valid
(Formal_Id
, True);
4736 end Set_Formal_Validity
;
4738 ------------------------
4739 -- Subtype_Conformant --
4740 ------------------------
4742 function Subtype_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4746 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
);
4748 end Subtype_Conformant
;
4750 ---------------------
4751 -- Type_Conformant --
4752 ---------------------
4754 function Type_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4758 Check_Conformance
(New_Id
, Old_Id
, Type_Conformant
, False, Result
);
4760 end Type_Conformant
;
4762 -------------------------------
4763 -- Valid_Operator_Definition --
4764 -------------------------------
4766 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
4769 Id
: constant Name_Id
:= Chars
(Designator
);
4773 F
:= First_Formal
(Designator
);
4775 while Present
(F
) loop
4778 if Present
(Default_Value
(F
)) then
4780 ("default values not allowed for operator parameters",
4787 -- Verify that user-defined operators have proper number of arguments
4788 -- First case of operators which can only be unary
4791 or else Id
= Name_Op_Abs
4795 -- Case of operators which can be unary or binary
4797 elsif Id
= Name_Op_Add
4798 or Id
= Name_Op_Subtract
4800 N_OK
:= (N
in 1 .. 2);
4802 -- All other operators can only be binary
4810 ("incorrect number of arguments for operator", Designator
);
4814 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
4815 and then not Is_Intrinsic_Subprogram
(Designator
)
4818 ("explicit definition of inequality not allowed", Designator
);
4820 end Valid_Operator_Definition
;