1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 ------------------------------------------------------------------------------
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Expander
; use Expander
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Freeze
; use Freeze
;
37 with Lib
.Xref
; use Lib
.Xref
;
38 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Output
; use Output
;
44 with Rtsfind
; use Rtsfind
;
46 with Sem_Cat
; use Sem_Cat
;
47 with Sem_Ch3
; use Sem_Ch3
;
48 with Sem_Ch4
; use Sem_Ch4
;
49 with Sem_Ch5
; use Sem_Ch5
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Ch12
; use Sem_Ch12
;
52 with Sem_Disp
; use Sem_Disp
;
53 with Sem_Dist
; use Sem_Dist
;
54 with Sem_Elim
; use Sem_Elim
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Mech
; use Sem_Mech
;
57 with Sem_Prag
; use Sem_Prag
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Util
; use Sem_Util
;
60 with Sem_Type
; use Sem_Type
;
61 with Sem_Warn
; use Sem_Warn
;
62 with Sinput
; use Sinput
;
63 with Stand
; use Stand
;
64 with Sinfo
; use Sinfo
;
65 with Sinfo
.CN
; use Sinfo
.CN
;
66 with Snames
; use Snames
;
67 with Stringt
; use Stringt
;
69 with Stylesw
; use Stylesw
;
70 with Tbuild
; use Tbuild
;
71 with Uintp
; use Uintp
;
72 with Urealp
; use Urealp
;
73 with Validsw
; use Validsw
;
75 package body Sem_Ch6
is
77 -----------------------
78 -- Local Subprograms --
79 -----------------------
81 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
82 -- Analyze a generic subprogram body
84 function Build_Body_To_Inline
89 -- If a subprogram has pragma Inline and inlining is active, use generic
90 -- machinery to build an unexpanded body for the subprogram. This body is
91 -- subsequenty used for inline expansions at call sites. If subprogram can
92 -- be inlined (depending on size and nature of local declarations) this
93 -- function returns true. Otherwise subprogram body is treated normally.
95 type Conformance_Type
is
96 (Type_Conformant
, Mode_Conformant
, Subtype_Conformant
, Fully_Conformant
);
97 -- Conformance type used for following call, meaning matches the
98 -- RM definitions of the corresponding terms.
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
)
711 Make_Raise_Program_Error
(Loc
,
712 Reason
=> PE_Accessibility_Check_Failed
));
716 ("cannot return a local value by reference?", N
);
718 ("& will be raised at run time?!",
719 N
, Standard_Program_Error
);
722 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
723 Error_Msg_N
("procedure cannot return value (use function)", N
);
726 Error_Msg_N
("accept statement cannot return value", N
);
729 -- No expression present
732 if Kind
= E_Function
or Kind
= E_Generic_Function
then
733 Error_Msg_N
("missing expression in return from function", N
);
736 if (Ekind
(Scope_Id
) = E_Procedure
737 or else Ekind
(Scope_Id
) = E_Generic_Procedure
)
738 and then No_Return
(Scope_Id
)
741 ("RETURN statement not allowed (No_Return)", N
);
745 Check_Unreachable_Code
(N
);
746 end Analyze_Return_Statement
;
752 function Analyze_Spec
(N
: Node_Id
) return Entity_Id
is
753 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
754 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
758 Generate_Definition
(Designator
);
760 if Nkind
(N
) = N_Function_Specification
then
761 Set_Ekind
(Designator
, E_Function
);
762 Set_Mechanism
(Designator
, Default_Mechanism
);
764 if Subtype_Mark
(N
) /= Error
then
765 Find_Type
(Subtype_Mark
(N
));
766 Typ
:= Entity
(Subtype_Mark
(N
));
767 Set_Etype
(Designator
, Typ
);
769 if (Ekind
(Typ
) = E_Incomplete_Type
770 or else (Is_Class_Wide_Type
(Typ
)
772 Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
))
775 ("invalid use of incomplete type", Subtype_Mark
(N
));
779 Set_Etype
(Designator
, Any_Type
);
783 Set_Ekind
(Designator
, E_Procedure
);
784 Set_Etype
(Designator
, Standard_Void_Type
);
787 if Present
(Formals
) then
788 Set_Scope
(Designator
, Current_Scope
);
789 New_Scope
(Designator
);
790 Process_Formals
(Formals
, N
);
794 if Nkind
(N
) = N_Function_Specification
then
795 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
796 Valid_Operator_Definition
(Designator
);
799 May_Need_Actuals
(Designator
);
801 if Is_Abstract
(Etype
(Designator
))
802 and then Nkind
(Parent
(N
)) /= N_Abstract_Subprogram_Declaration
805 ("function that returns abstract type must be abstract", N
);
812 -----------------------------
813 -- Analyze_Subprogram_Body --
814 -----------------------------
816 -- This procedure is called for regular subprogram bodies, generic bodies,
817 -- and for subprogram stubs of both kinds. In the case of stubs, only the
818 -- specification matters, and is used to create a proper declaration for
819 -- the subprogram, or to perform conformance checks.
821 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
822 Loc
: constant Source_Ptr
:= Sloc
(N
);
823 Body_Spec
: constant Node_Id
:= Specification
(N
);
824 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
825 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
829 Spec_Decl
: Node_Id
:= Empty
;
830 Last_Formal
: Entity_Id
:= Empty
;
831 Conformant
: Boolean;
832 Missing_Ret
: Boolean;
833 Body_Deleted
: Boolean := False;
838 Write_Str
("==== Compiling subprogram body ");
839 Write_Name
(Chars
(Body_Id
));
840 Write_Str
(" from ");
841 Write_Location
(Loc
);
845 Trace_Scope
(N
, Body_Id
, " Analyze subprogram");
847 -- Generic subprograms are handled separately. They always have
848 -- a generic specification. Determine whether current scope has
849 -- a previous declaration.
851 -- If the subprogram body is defined within an instance of the
852 -- same name, the instance appears as a package renaming, and
853 -- will be hidden within the subprogram.
856 and then not Is_Overloadable
(Prev_Id
)
857 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
858 or else Comes_From_Source
(Prev_Id
))
860 if Ekind
(Prev_Id
) = E_Generic_Procedure
861 or else Ekind
(Prev_Id
) = E_Generic_Function
864 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
865 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
867 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
871 -- Previous entity conflicts with subprogram name.
872 -- Attempting to enter name will post error.
874 Enter_Name
(Body_Id
);
878 -- Non-generic case, find the subprogram declaration, if one was
879 -- seen, or enter new overloaded entity in the current scope.
880 -- If the current_entity is the body_id itself, the unit is being
881 -- analyzed as part of the context of one of its subunits. No need
882 -- to redo the analysis.
884 elsif Prev_Id
= Body_Id
885 and then Has_Completion
(Body_Id
)
890 Body_Id
:= Analyze_Spec
(Body_Spec
);
892 if Nkind
(N
) = N_Subprogram_Body_Stub
893 or else No
(Corresponding_Spec
(N
))
895 Spec_Id
:= Find_Corresponding_Spec
(N
);
897 -- If this is a duplicate body, no point in analyzing it
899 if Error_Posted
(N
) then
903 -- A subprogram body should cause freezing of its own
904 -- declaration, but if there was no previous explicit
905 -- declaration, then the subprogram will get frozen too
906 -- late (there may be code within the body that depends
907 -- on the subprogram having been frozen, such as uses of
908 -- extra formals), so we force it to be frozen here.
909 -- Same holds if the body and the spec are compilation units.
912 Freeze_Before
(N
, Body_Id
);
914 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
915 Freeze_Before
(N
, Spec_Id
);
918 Spec_Id
:= Corresponding_Spec
(N
);
922 -- Do not inline any subprogram that contains nested subprograms,
923 -- since the backend inlining circuit seems to generate uninitialized
924 -- references in this case. We know this happens in the case of front
925 -- end ZCX support, but it also appears it can happen in other cases
926 -- as well. The backend often rejects attempts to inline in the case
927 -- of nested procedures anyway, so little if anything is lost by this.
929 -- Do not do this test if errors have been detected, because in some
930 -- error cases, this code blows up, and we don't need it anyway if
931 -- there have been errors, since we won't get to the linker anyway.
933 if Serious_Errors_Detected
= 0 then
936 P_Ent
:= Scope
(P_Ent
);
937 exit when No
(P_Ent
) or else P_Ent
= Standard_Standard
;
939 if Is_Subprogram
(P_Ent
) and then Is_Inlined
(P_Ent
) then
940 Set_Is_Inlined
(P_Ent
, False);
942 if Comes_From_Source
(P_Ent
)
943 and then Ineffective_Inline_Warnings
944 and then Has_Pragma_Inline
(P_Ent
)
947 ("?pragma Inline for & ignored (has nested subprogram)",
948 Get_Rep_Pragma
(P_Ent
, Name_Inline
), P_Ent
);
954 -- Case of fully private operation in the body of the protected type.
955 -- We must create a declaration for the subprogram, in order to attach
956 -- the protected subprogram that will be used in internal calls.
959 and then Comes_From_Source
(N
)
960 and then Is_Protected_Type
(Current_Scope
)
969 Formal
:= First_Formal
(Body_Id
);
971 -- The protected operation always has at least one formal,
972 -- namely the object itself, but it is only placed in the
973 -- parameter list if expansion is enabled.
976 or else Expander_Active
984 while Present
(Formal
) loop
986 (Make_Parameter_Specification
(Loc
,
987 Defining_Identifier
=>
988 Make_Defining_Identifier
(Sloc
(Formal
),
989 Chars
=> Chars
(Formal
)),
990 In_Present
=> In_Present
(Parent
(Formal
)),
991 Out_Present
=> Out_Present
(Parent
(Formal
)),
993 New_Reference_To
(Etype
(Formal
), Loc
),
995 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
998 Next_Formal
(Formal
);
1001 if Nkind
(Body_Spec
) = N_Procedure_Specification
then
1003 Make_Procedure_Specification
(Loc
,
1004 Defining_Unit_Name
=>
1005 Make_Defining_Identifier
(Sloc
(Body_Id
),
1006 Chars
=> Chars
(Body_Id
)),
1007 Parameter_Specifications
=> Plist
);
1010 Make_Function_Specification
(Loc
,
1011 Defining_Unit_Name
=>
1012 Make_Defining_Identifier
(Sloc
(Body_Id
),
1013 Chars
=> Chars
(Body_Id
)),
1014 Parameter_Specifications
=> Plist
,
1015 Subtype_Mark
=> New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
1019 Make_Subprogram_Declaration
(Loc
,
1020 Specification
=> New_Spec
);
1021 Insert_Before
(N
, Decl
);
1023 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
1024 Set_Has_Completion
(Spec_Id
);
1025 Set_Convention
(Spec_Id
, Convention_Protected
);
1028 elsif Present
(Spec_Id
) then
1029 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
1032 -- Place subprogram on scope stack, and make formals visible. If there
1033 -- is a spec, the visible entity remains that of the spec.
1035 if Present
(Spec_Id
) then
1036 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
1037 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1039 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1040 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1042 if Is_Abstract
(Spec_Id
) then
1043 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
1046 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
1047 Set_Has_Completion
(Spec_Id
);
1049 if Is_Protected_Type
(Scope
(Spec_Id
)) then
1050 Set_Privals_Chain
(Spec_Id
, New_Elmt_List
);
1053 -- If this is a body generated for a renaming, do not check for
1054 -- full conformance. The check is redundant, because the spec of
1055 -- the body is a copy of the spec in the renaming declaration,
1056 -- and the test can lead to spurious errors on nested defaults.
1058 if Present
(Spec_Decl
)
1059 and then Nkind
(Original_Node
(Spec_Decl
)) =
1060 N_Subprogram_Renaming_Declaration
1061 and then not Comes_From_Source
(N
)
1067 Fully_Conformant
, True, Conformant
, Body_Id
);
1070 -- If the body is not fully conformant, we have to decide if we
1071 -- should analyze it or not. If it has a really messed up profile
1072 -- then we probably should not analyze it, since we will get too
1073 -- many bogus messages.
1075 -- Our decision is to go ahead in the non-fully conformant case
1076 -- only if it is at least mode conformant with the spec. Note
1077 -- that the call to Check_Fully_Conformant has issued the proper
1078 -- error messages to complain about the lack of conformance.
1081 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
1087 -- Generate references from body formals to spec formals
1088 -- and also set the Spec_Entity fields for all formals. We
1089 -- do not set this reference count as a reference for the
1090 -- purposes of identifying unreferenced formals however.
1092 if Spec_Id
/= Body_Id
then
1098 Fs
:= First_Formal
(Spec_Id
);
1099 Fb
:= First_Formal
(Body_Id
);
1100 while Present
(Fs
) loop
1101 Generate_Reference
(Fs
, Fb
, 'b');
1102 Style
.Check_Identifier
(Fb
, Fs
);
1103 Set_Spec_Entity
(Fb
, Fs
);
1104 Set_Referenced
(Fs
, False);
1111 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1112 Set_Corresponding_Spec
(N
, Spec_Id
);
1113 Install_Formals
(Spec_Id
);
1114 Last_Formal
:= Last_Entity
(Spec_Id
);
1115 New_Scope
(Spec_Id
);
1117 -- Make sure that the subprogram is immediately visible. For
1118 -- child units that have no separate spec this is indispensable.
1119 -- Otherwise it is safe albeit redundant.
1121 Set_Is_Immediately_Visible
(Spec_Id
);
1124 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
1125 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1126 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
1128 -- Case of subprogram body with no previous spec
1132 and then Comes_From_Source
(Body_Id
)
1133 and then not Suppress_Style_Checks
(Body_Id
)
1134 and then not In_Instance
1136 Style
.Body_With_No_Spec
(N
);
1139 New_Overloaded_Entity
(Body_Id
);
1141 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1142 Set_Acts_As_Spec
(N
);
1143 Generate_Definition
(Body_Id
);
1144 Install_Formals
(Body_Id
);
1145 New_Scope
(Body_Id
);
1149 -- If this is the proper body of a stub, we must verify that the stub
1150 -- conforms to the body, and to the previous spec if one was present.
1151 -- we know already that the body conforms to that spec. This test is
1152 -- only required for subprograms that come from source.
1154 if Nkind
(Parent
(N
)) = N_Subunit
1155 and then Comes_From_Source
(N
)
1156 and then not Error_Posted
(Body_Id
)
1159 Conformant
: Boolean := False;
1160 Old_Id
: Entity_Id
:=
1162 (Specification
(Corresponding_Stub
(Parent
(N
))));
1165 if No
(Spec_Id
) then
1166 Check_Fully_Conformant
(Body_Id
, Old_Id
);
1170 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
1172 if not Conformant
then
1174 -- The stub was taken to be a new declaration. Indicate
1175 -- that it lacks a body.
1177 Set_Has_Completion
(Old_Id
, False);
1183 Set_Has_Completion
(Body_Id
);
1184 Check_Eliminated
(Body_Id
);
1186 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1189 elsif Present
(Spec_Id
)
1190 and then Expander_Active
1191 and then (Is_Always_Inlined
(Spec_Id
)
1192 or else (Has_Pragma_Inline
(Spec_Id
)
1194 (Front_End_Inlining
or else No_Run_Time
)))
1196 if Build_Body_To_Inline
(N
, Spec_Id
, Copy_Separate_Tree
(N
)) then
1201 -- Now we can go on to analyze the body
1203 HSS
:= Handled_Statement_Sequence
(N
);
1204 Set_Actual_Subtypes
(N
, Current_Scope
);
1205 Analyze_Declarations
(Declarations
(N
));
1208 Process_End_Label
(HSS
, 't', Current_Scope
);
1210 Check_Subprogram_Order
(N
);
1212 -- If we have a separate spec, then the analysis of the declarations
1213 -- caused the entities in the body to be chained to the spec id, but
1214 -- we want them chained to the body id. Only the formal parameters
1215 -- end up chained to the spec id in this case.
1217 if Present
(Spec_Id
) then
1219 -- If a parent unit is categorized, the context of a subunit
1220 -- must conform to the categorization. Conversely, if a child
1221 -- unit is categorized, the parents themselves must conform.
1223 if Nkind
(Parent
(N
)) = N_Subunit
then
1224 Validate_Categorization_Dependency
(N
, Spec_Id
);
1226 elsif Is_Child_Unit
(Spec_Id
) then
1227 Validate_Categorization_Dependency
1228 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
1231 if Present
(Last_Formal
) then
1233 (Last_Entity
(Body_Id
), Next_Entity
(Last_Formal
));
1234 Set_Next_Entity
(Last_Formal
, Empty
);
1235 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1236 Set_Last_Entity
(Spec_Id
, Last_Formal
);
1239 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
1240 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1241 Set_First_Entity
(Spec_Id
, Empty
);
1242 Set_Last_Entity
(Spec_Id
, Empty
);
1246 -- If function, check return statements
1248 if Nkind
(Body_Spec
) = N_Function_Specification
then
1253 if Present
(Spec_Id
) then
1259 if Return_Present
(Id
) then
1260 Check_Returns
(HSS
, 'F', Missing_Ret
);
1263 Set_Has_Missing_Return
(Id
);
1266 elsif not Is_Machine_Code_Subprogram
(Id
)
1267 and then not Body_Deleted
1269 Error_Msg_N
("missing RETURN statement in function body", N
);
1273 -- If procedure with No_Return, check returns
1275 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
1276 and then Present
(Spec_Id
)
1277 and then No_Return
(Spec_Id
)
1279 Check_Returns
(HSS
, 'P', Missing_Ret
);
1282 -- Don't worry about checking for variables that are never modified
1283 -- if the first statement of the body is a raise statement, since
1284 -- we assume this is some kind of stub. We ignore a label generated
1285 -- by the exception stuff for the purpose of this test.
1288 Stm
: Node_Id
:= First
(Statements
(HSS
));
1291 if Nkind
(Stm
) = N_Label
then
1295 if Nkind
(Original_Node
(Stm
)) = N_Raise_Statement
then
1300 -- Check for variables that are never modified
1306 -- If there is a separate spec, then transfer Not_Source_Assigned
1307 -- flags from out parameters to the corresponding entities in the
1308 -- body. The reason we do that is we want to post error flags on
1309 -- the body entities, not the spec entities.
1311 if Present
(Spec_Id
) then
1312 E1
:= First_Entity
(Spec_Id
);
1314 while Present
(E1
) loop
1315 if Ekind
(E1
) = E_Out_Parameter
then
1316 E2
:= First_Entity
(Body_Id
);
1319 -- If no matching body entity, then we already had
1320 -- a detected error of some kind, so just forget
1321 -- about worrying about these warnings.
1327 exit when Chars
(E1
) = Chars
(E2
);
1331 Set_Not_Source_Assigned
(E2
, Not_Source_Assigned
(E1
));
1338 -- Check references in body unless it was deleted. Note that the
1339 -- check of Body_Deleted here is not just for efficiency, it is
1340 -- necessary to avoid junk warnings on formal parameters.
1342 if not Body_Deleted
then
1343 Check_References
(Body_Id
);
1346 end Analyze_Subprogram_Body
;
1348 ------------------------------------
1349 -- Analyze_Subprogram_Declaration --
1350 ------------------------------------
1352 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
1353 Designator
: constant Entity_Id
:= Analyze_Spec
(Specification
(N
));
1354 Scop
: constant Entity_Id
:= Current_Scope
;
1356 -- Start of processing for Analyze_Subprogram_Declaration
1359 Generate_Definition
(Designator
);
1361 -- Check for RCI unit subprogram declarations against in-lined
1362 -- subprograms and subprograms having access parameter or limited
1363 -- parameter without Read and Write (RM E.2.3(12-13)).
1365 Validate_RCI_Subprogram_Declaration
(N
);
1369 Defining_Entity
(N
),
1370 " Analyze subprogram spec. ");
1372 if Debug_Flag_C
then
1373 Write_Str
("==== Compiling subprogram spec ");
1374 Write_Name
(Chars
(Designator
));
1375 Write_Str
(" from ");
1376 Write_Location
(Sloc
(N
));
1380 New_Overloaded_Entity
(Designator
);
1381 Check_Delayed_Subprogram
(Designator
);
1382 Set_Suppress_Elaboration_Checks
1383 (Designator
, Elaboration_Checks_Suppressed
(Designator
));
1385 if Scop
/= Standard_Standard
1386 and then not Is_Child_Unit
(Designator
)
1388 Set_Is_Pure
(Designator
,
1389 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(Designator
));
1390 Set_Is_Remote_Call_Interface
(
1391 Designator
, Is_Remote_Call_Interface
(Scop
));
1392 Set_Is_Remote_Types
(Designator
, Is_Remote_Types
(Scop
));
1395 -- For a compilation unit, check for library-unit pragmas.
1397 New_Scope
(Designator
);
1398 Set_Categorization_From_Pragmas
(N
);
1399 Validate_Categorization_Dependency
(N
, Designator
);
1403 -- For a compilation unit, set body required. This flag will only be
1404 -- reset if a valid Import or Interface pragma is processed later on.
1406 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1407 Set_Body_Required
(Parent
(N
), True);
1410 Check_Eliminated
(Designator
);
1411 end Analyze_Subprogram_Declaration
;
1413 --------------------------
1414 -- Build_Body_To_Inline --
1415 --------------------------
1417 function Build_Body_To_Inline
1420 Orig_Body
: Node_Id
) return Boolean
1422 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1423 Original_Body
: Node_Id
;
1424 Body_To_Analyze
: Node_Id
;
1425 Max_Size
: constant := 10;
1426 Stat_Count
: Integer := 0;
1428 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
1429 -- Check for declarations that make inlining not worthwhile.
1431 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
1432 -- Check for statements that make inlining not worthwhile: any
1433 -- tasking statement, nested at any level. Keep track of total
1434 -- number of elementary statements, as a measure of acceptable size.
1436 function Has_Pending_Instantiation
return Boolean;
1437 -- If some enclosing body contains instantiations that appear before
1438 -- the corresponding generic body, the enclosing body has a freeze node
1439 -- so that it can be elaborated after the generic itself. This might
1440 -- conflict with subsequent inlinings, so that it is unsafe to try to
1441 -- inline in such a case.
1447 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
);
1448 -- If subprogram has pragma Inline_Always, it is an error if
1449 -- it cannot be inlined. Otherwise, emit a warning.
1451 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
) is
1453 if Is_Always_Inlined
(Subp
) then
1454 Error_Msg_NE
(Msg
(1 .. Msg
'Length - 1), N
, Subp
);
1456 elsif Ineffective_Inline_Warnings
then
1457 Error_Msg_NE
(Msg
, N
, Subp
);
1461 ------------------------------
1462 -- Has_Excluded_Declaration --
1463 ------------------------------
1465 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
1471 while Present
(D
) loop
1472 if Nkind
(D
) = N_Function_Instantiation
1473 or else Nkind
(D
) = N_Protected_Type_Declaration
1474 or else Nkind
(D
) = N_Package_Declaration
1475 or else Nkind
(D
) = N_Package_Instantiation
1476 or else Nkind
(D
) = N_Subprogram_Body
1477 or else Nkind
(D
) = N_Procedure_Instantiation
1478 or else Nkind
(D
) = N_Task_Type_Declaration
1481 ("\declaration prevents front-end inlining of&?", D
);
1490 end Has_Excluded_Declaration
;
1492 ----------------------------
1493 -- Has_Excluded_Statement --
1494 ----------------------------
1496 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
1503 while Present
(S
) loop
1504 Stat_Count
:= Stat_Count
+ 1;
1506 if Nkind
(S
) = N_Abort_Statement
1507 or else Nkind
(S
) = N_Asynchronous_Select
1508 or else Nkind
(S
) = N_Conditional_Entry_Call
1509 or else Nkind
(S
) = N_Delay_Relative_Statement
1510 or else Nkind
(S
) = N_Delay_Until_Statement
1511 or else Nkind
(S
) = N_Selective_Accept
1512 or else Nkind
(S
) = N_Timed_Entry_Call
1515 ("\statement prevents front-end inlining of&?", S
);
1518 elsif Nkind
(S
) = N_Block_Statement
then
1519 if Present
(Declarations
(S
))
1520 and then Has_Excluded_Declaration
(Declarations
(S
))
1524 elsif Present
(Handled_Statement_Sequence
(S
))
1527 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
1529 Has_Excluded_Statement
1530 (Statements
(Handled_Statement_Sequence
(S
))))
1535 elsif Nkind
(S
) = N_Case_Statement
then
1536 E
:= First
(Alternatives
(S
));
1538 while Present
(E
) loop
1539 if Has_Excluded_Statement
(Statements
(E
)) then
1546 elsif Nkind
(S
) = N_If_Statement
then
1547 if Has_Excluded_Statement
(Then_Statements
(S
)) then
1551 if Present
(Elsif_Parts
(S
)) then
1552 E
:= First
(Elsif_Parts
(S
));
1554 while Present
(E
) loop
1555 if Has_Excluded_Statement
(Then_Statements
(E
)) then
1562 if Present
(Else_Statements
(S
))
1563 and then Has_Excluded_Statement
(Else_Statements
(S
))
1568 elsif Nkind
(S
) = N_Loop_Statement
1569 and then Has_Excluded_Statement
(Statements
(S
))
1578 end Has_Excluded_Statement
;
1580 -------------------------------
1581 -- Has_Pending_Instantiation --
1582 -------------------------------
1584 function Has_Pending_Instantiation
return Boolean is
1585 S
: Entity_Id
:= Current_Scope
;
1588 while Present
(S
) loop
1589 if Is_Compilation_Unit
(S
)
1590 or else Is_Child_Unit
(S
)
1593 elsif Ekind
(S
) = E_Package
1594 and then Has_Forward_Instantiation
(S
)
1603 end Has_Pending_Instantiation
;
1605 -- Start of processing for Build_Body_To_Inline
1608 if Nkind
(Decl
) = N_Subprogram_Declaration
1609 and then Present
(Body_To_Inline
(Decl
))
1611 return True; -- Done already.
1613 -- Functions that return unconstrained composite types will require
1614 -- secondary stack handling, and cannot currently be inlined.
1616 elsif Ekind
(Subp
) = E_Function
1617 and then not Is_Scalar_Type
(Etype
(Subp
))
1618 and then not Is_Access_Type
(Etype
(Subp
))
1619 and then not Is_Constrained
(Etype
(Subp
))
1622 ("unconstrained return type prevents front-end inlining of&?", N
);
1626 -- We need to capture references to the formals in order to substitute
1627 -- the actuals at the point of inlining, i.e. instantiation. To treat
1628 -- the formals as globals to the body to inline, we nest it within
1629 -- a dummy parameterless subprogram, declared within the real one.
1631 Original_Body
:= Orig_Body
;
1633 -- Within an instance, the current tree is already the result of
1634 -- a generic copy, and not what we need for subsequent inlining.
1635 -- We create the required body by doing an instantiating copy, to
1636 -- obtain the proper partially analyzed tree.
1639 if No
(Generic_Parent
(Specification
(N
))) then
1642 elsif Is_Child_Unit
(Scope
(Current_Scope
)) then
1645 elsif Scope
(Current_Scope
) = Cunit_Entity
(Main_Unit
) then
1647 -- compiling an instantiation. There is no point in generating
1648 -- bodies to inline, because they will not be used.
1655 (Generic_Parent
(Specification
(N
)), Empty
,
1656 Instantiating
=> True);
1660 Copy_Generic_Node
(Original_Body
, Empty
,
1661 Instantiating
=> False);
1664 Set_Parameter_Specifications
(Specification
(Original_Body
), No_List
);
1665 Set_Defining_Unit_Name
(Specification
(Original_Body
),
1666 Make_Defining_Identifier
(Sloc
(N
), New_Internal_Name
('S')));
1667 Set_Corresponding_Spec
(Original_Body
, Empty
);
1669 if Ekind
(Subp
) = E_Function
then
1670 Set_Subtype_Mark
(Specification
(Original_Body
),
1671 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
1674 if Present
(Declarations
(Orig_Body
))
1675 and then Has_Excluded_Declaration
(Declarations
(Orig_Body
))
1680 if Present
(Handled_Statement_Sequence
(N
)) then
1682 (Present
(Exception_Handlers
(Handled_Statement_Sequence
(N
))))
1684 Cannot_Inline
("handler prevents front-end inlining of&?",
1685 First
(Exception_Handlers
(Handled_Statement_Sequence
(N
))));
1688 Has_Excluded_Statement
1689 (Statements
(Handled_Statement_Sequence
(N
)))
1695 -- We do not inline a subprogram that is too large, unless it is
1696 -- marked Inline_Always. This pragma does not suppress the other
1697 -- checks on inlining (forbidden declarations, handlers, etc).
1699 if Stat_Count
> Max_Size
1700 and then not Is_Always_Inlined
(Subp
)
1702 Cannot_Inline
("body is too large for front-end inlining of&?", N
);
1706 if Has_Pending_Instantiation
then
1708 ("cannot inline& because of forward instance within enclosing body",
1713 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
1715 -- Set return type of function, which is also global and does not need
1718 if Ekind
(Subp
) = E_Function
then
1719 Set_Subtype_Mark
(Specification
(Body_To_Analyze
),
1720 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
1723 if No
(Declarations
(N
)) then
1724 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
1726 Append
(Body_To_Analyze
, Declarations
(N
));
1729 Expander_Mode_Save_And_Set
(False);
1731 Analyze
(Body_To_Analyze
);
1732 New_Scope
(Defining_Entity
(Body_To_Analyze
));
1733 Save_Global_References
(Original_Body
);
1735 Remove
(Body_To_Analyze
);
1737 Expander_Mode_Restore
;
1738 Set_Body_To_Inline
(Decl
, Original_Body
);
1739 Set_Is_Inlined
(Subp
);
1742 end Build_Body_To_Inline
;
1744 -----------------------
1745 -- Check_Conformance --
1746 -----------------------
1748 procedure Check_Conformance
1749 (New_Id
: Entity_Id
;
1751 Ctype
: Conformance_Type
;
1753 Conforms
: out Boolean;
1754 Err_Loc
: Node_Id
:= Empty
;
1755 Get_Inst
: Boolean := False)
1757 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
1758 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
1759 Old_Formal
: Entity_Id
;
1760 New_Formal
: Entity_Id
;
1762 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
1763 -- Post error message for conformance error on given node.
1764 -- Two messages are output. The first points to the previous
1765 -- declaration with a general "no conformance" message.
1766 -- The second is the detailed reason, supplied as Msg. The
1767 -- parameter N provide information for a possible & insertion
1768 -- in the message, and also provides the location for posting
1769 -- the message in the absence of a specified Err_Loc location.
1771 -----------------------
1772 -- Conformance_Error --
1773 -----------------------
1775 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
1782 if No
(Err_Loc
) then
1788 Error_Msg_Sloc
:= Sloc
(Old_Id
);
1791 when Type_Conformant
=>
1793 ("not type conformant with declaration#!", Enode
);
1795 when Mode_Conformant
=>
1797 ("not mode conformant with declaration#!", Enode
);
1799 when Subtype_Conformant
=>
1801 ("not subtype conformant with declaration#!", Enode
);
1803 when Fully_Conformant
=>
1805 ("not fully conformant with declaration#!", Enode
);
1808 Error_Msg_NE
(Msg
, Enode
, N
);
1810 end Conformance_Error
;
1812 -- Start of processing for Check_Conformance
1817 -- We need a special case for operators, since they don't
1818 -- appear explicitly.
1820 if Ctype
= Type_Conformant
then
1821 if Ekind
(New_Id
) = E_Operator
1822 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
1828 -- If both are functions/operators, check return types conform
1830 if Old_Type
/= Standard_Void_Type
1831 and then New_Type
/= Standard_Void_Type
1833 if not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
1834 Conformance_Error
("return type does not match!", New_Id
);
1838 -- If either is a function/operator and the other isn't, error
1840 elsif Old_Type
/= Standard_Void_Type
1841 or else New_Type
/= Standard_Void_Type
1843 Conformance_Error
("functions can only match functions!", New_Id
);
1847 -- In subtype conformant case, conventions must match (RM 6.3.1(16))
1848 -- If this is a renaming as body, refine error message to indicate that
1849 -- the conflict is with the original declaration. If the entity is not
1850 -- frozen, the conventions don't have to match, the one of the renamed
1851 -- entity is inherited.
1853 if Ctype
>= Subtype_Conformant
then
1855 if Convention
(Old_Id
) /= Convention
(New_Id
) then
1857 if not Is_Frozen
(New_Id
) then
1860 elsif Present
(Err_Loc
)
1861 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
1862 and then Present
(Corresponding_Spec
(Err_Loc
))
1864 Error_Msg_Name_1
:= Chars
(New_Id
);
1866 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
1868 Conformance_Error
("prior declaration for% has convention %!");
1871 Conformance_Error
("calling conventions do not match!");
1876 elsif Is_Formal_Subprogram
(Old_Id
)
1877 or else Is_Formal_Subprogram
(New_Id
)
1879 Conformance_Error
("formal subprograms not allowed!");
1884 -- Deal with parameters
1886 -- Note: we use the entity information, rather than going directly
1887 -- to the specification in the tree. This is not only simpler, but
1888 -- absolutely necessary for some cases of conformance tests between
1889 -- operators, where the declaration tree simply does not exist!
1891 Old_Formal
:= First_Formal
(Old_Id
);
1892 New_Formal
:= First_Formal
(New_Id
);
1894 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
1896 -- Types must always match. In the visible part of an instance,
1897 -- usual overloading rules for dispatching operations apply, and
1898 -- we check base types (not the actual subtypes).
1900 if In_Instance_Visible_Part
1901 and then Is_Dispatching_Operation
(New_Id
)
1903 if not Conforming_Types
1904 (Base_Type
(Etype
(Old_Formal
)),
1905 Base_Type
(Etype
(New_Formal
)), Ctype
, Get_Inst
)
1907 Conformance_Error
("type of & does not match!", New_Formal
);
1911 elsif not Conforming_Types
1912 (Etype
(Old_Formal
), Etype
(New_Formal
), Ctype
, Get_Inst
)
1914 Conformance_Error
("type of & does not match!", New_Formal
);
1918 -- For mode conformance, mode must match
1920 if Ctype
>= Mode_Conformant
1921 and then Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
)
1923 Conformance_Error
("mode of & does not match!", New_Formal
);
1927 -- Full conformance checks
1929 if Ctype
= Fully_Conformant
then
1933 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
1934 Conformance_Error
("name & does not match!", New_Formal
);
1937 -- And default expressions for in parameters
1939 elsif Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
1941 NewD
: constant Boolean :=
1942 Present
(Default_Value
(New_Formal
));
1943 OldD
: constant Boolean :=
1944 Present
(Default_Value
(Old_Formal
));
1946 if NewD
or OldD
then
1948 -- The old default value has been analyzed and expanded,
1949 -- because the current full declaration will have frozen
1950 -- everything before. The new default values have not
1951 -- been expanded, so expand now to check conformance.
1955 Analyze_Default_Expression
1956 (Default_Value
(New_Formal
), Etype
(New_Formal
));
1960 if not (NewD
and OldD
)
1961 or else not Fully_Conformant_Expressions
1962 (Default_Value
(Old_Formal
),
1963 Default_Value
(New_Formal
))
1966 ("default expression for & does not match!",
1975 -- A couple of special checks for Ada 83 mode. These checks are
1976 -- skipped if either entity is an operator in package Standard.
1977 -- or if either old or new instance is not from the source program.
1980 and then Sloc
(Old_Id
) > Standard_Location
1981 and then Sloc
(New_Id
) > Standard_Location
1982 and then Comes_From_Source
(Old_Id
)
1983 and then Comes_From_Source
(New_Id
)
1986 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
1987 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
1990 -- Explicit IN must be present or absent in both cases. This
1991 -- test is required only in the full conformance case.
1993 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
1994 and then Ctype
= Fully_Conformant
1997 ("(Ada 83) IN must appear in both declarations",
2002 -- Grouping (use of comma in param lists) must be the same
2003 -- This is where we catch a misconformance like:
2006 -- A : Integer; B : Integer
2008 -- which are represented identically in the tree except
2009 -- for the setting of the flags More_Ids and Prev_Ids.
2011 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
2012 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
2015 ("grouping of & does not match!", New_Formal
);
2021 Next_Formal
(Old_Formal
);
2022 Next_Formal
(New_Formal
);
2025 if Present
(Old_Formal
) then
2026 Conformance_Error
("too few parameters!");
2029 elsif Present
(New_Formal
) then
2030 Conformance_Error
("too many parameters!", New_Formal
);
2034 end Check_Conformance
;
2036 ------------------------------
2037 -- Check_Delayed_Subprogram --
2038 ------------------------------
2040 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
2043 procedure Possible_Freeze
(T
: Entity_Id
);
2044 -- T is the type of either a formal parameter or of the return type.
2045 -- If T is not yet frozen and needs a delayed freeze, then the
2046 -- subprogram itself must be delayed.
2048 procedure Possible_Freeze
(T
: Entity_Id
) is
2050 if Has_Delayed_Freeze
(T
)
2051 and then not Is_Frozen
(T
)
2053 Set_Has_Delayed_Freeze
(Designator
);
2055 elsif Is_Access_Type
(T
)
2056 and then Has_Delayed_Freeze
(Designated_Type
(T
))
2057 and then not Is_Frozen
(Designated_Type
(T
))
2059 Set_Has_Delayed_Freeze
(Designator
);
2061 end Possible_Freeze
;
2063 -- Start of processing for Check_Delayed_Subprogram
2066 -- Never need to freeze abstract subprogram
2068 if Is_Abstract
(Designator
) then
2071 -- Need delayed freeze if return type itself needs a delayed
2072 -- freeze and is not yet frozen.
2074 Possible_Freeze
(Etype
(Designator
));
2075 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
2077 -- Need delayed freeze if any of the formal types themselves need
2078 -- a delayed freeze and are not yet frozen.
2080 F
:= First_Formal
(Designator
);
2081 while Present
(F
) loop
2082 Possible_Freeze
(Etype
(F
));
2083 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
2088 -- Mark functions that return by reference. Note that it cannot be
2089 -- done for delayed_freeze subprograms because the underlying
2090 -- returned type may not be known yet (for private types)
2092 if not Has_Delayed_Freeze
(Designator
)
2093 and then Expander_Active
2096 Typ
: constant Entity_Id
:= Etype
(Designator
);
2097 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
2100 if Is_Return_By_Reference_Type
(Typ
) then
2101 Set_Returns_By_Ref
(Designator
);
2103 elsif Present
(Utyp
) and then Controlled_Type
(Utyp
) then
2104 Set_Returns_By_Ref
(Designator
);
2108 end Check_Delayed_Subprogram
;
2110 ------------------------------------
2111 -- Check_Discriminant_Conformance --
2112 ------------------------------------
2114 procedure Check_Discriminant_Conformance
2119 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
2120 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
2121 New_Discr_Id
: Entity_Id
;
2122 New_Discr_Type
: Entity_Id
;
2124 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
2125 -- Post error message for conformance error on given node.
2126 -- Two messages are output. The first points to the previous
2127 -- declaration with a general "no conformance" message.
2128 -- The second is the detailed reason, supplied as Msg. The
2129 -- parameter N provide information for a possible & insertion
2132 -----------------------
2133 -- Conformance_Error --
2134 -----------------------
2136 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
2138 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
2139 Error_Msg_N
("not fully conformant with declaration#!", N
);
2140 Error_Msg_NE
(Msg
, N
, N
);
2141 end Conformance_Error
;
2143 -- Start of processing for Check_Discriminant_Conformance
2146 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
2148 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
2150 -- The subtype mark of the discriminant on the full type
2151 -- has not been analyzed so we do it here. For an access
2152 -- discriminant a new type is created.
2154 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
2156 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
2159 Analyze
(Discriminant_Type
(New_Discr
));
2160 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
2163 if not Conforming_Types
2164 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
2166 Conformance_Error
("type of & does not match!", New_Discr_Id
);
2172 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
2173 Conformance_Error
("name & does not match!", New_Discr_Id
);
2177 -- Default expressions must match
2180 NewD
: constant Boolean :=
2181 Present
(Expression
(New_Discr
));
2182 OldD
: constant Boolean :=
2183 Present
(Expression
(Parent
(Old_Discr
)));
2186 if NewD
or OldD
then
2188 -- The old default value has been analyzed and expanded,
2189 -- because the current full declaration will have frozen
2190 -- everything before. The new default values have not
2191 -- been expanded, so expand now to check conformance.
2194 Analyze_Default_Expression
2195 (Expression
(New_Discr
), New_Discr_Type
);
2198 if not (NewD
and OldD
)
2199 or else not Fully_Conformant_Expressions
2200 (Expression
(Parent
(Old_Discr
)),
2201 Expression
(New_Discr
))
2205 ("default expression for & does not match!",
2212 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
2216 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
2219 -- Grouping (use of comma in param lists) must be the same
2220 -- This is where we catch a misconformance like:
2223 -- A : Integer; B : Integer
2225 -- which are represented identically in the tree except
2226 -- for the setting of the flags More_Ids and Prev_Ids.
2228 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
2229 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
2232 ("grouping of & does not match!", New_Discr_Id
);
2238 Next_Discriminant
(Old_Discr
);
2242 if Present
(Old_Discr
) then
2243 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
2246 elsif Present
(New_Discr
) then
2248 ("too many discriminants!", Defining_Identifier
(New_Discr
));
2251 end Check_Discriminant_Conformance
;
2253 ----------------------------
2254 -- Check_Fully_Conformant --
2255 ----------------------------
2257 procedure Check_Fully_Conformant
2258 (New_Id
: Entity_Id
;
2260 Err_Loc
: Node_Id
:= Empty
)
2266 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
2267 end Check_Fully_Conformant
;
2269 ---------------------------
2270 -- Check_Mode_Conformant --
2271 ---------------------------
2273 procedure Check_Mode_Conformant
2274 (New_Id
: Entity_Id
;
2276 Err_Loc
: Node_Id
:= Empty
;
2277 Get_Inst
: Boolean := False)
2283 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
2284 end Check_Mode_Conformant
;
2290 procedure Check_Returns
2297 procedure Check_Statement_Sequence
(L
: List_Id
);
2298 -- Internal recursive procedure to check a list of statements for proper
2299 -- termination by a return statement (or a transfer of control or a
2300 -- compound statement that is itself internally properly terminated).
2302 ------------------------------
2303 -- Check_Statement_Sequence --
2304 ------------------------------
2306 procedure Check_Statement_Sequence
(L
: List_Id
) is
2310 Raise_Exception_Call
: Boolean;
2311 -- Set True if statement sequence terminated by Raise_Exception call
2312 -- or a Reraise_Occurrence call.
2315 Raise_Exception_Call
:= False;
2317 -- Get last real statement
2319 Last_Stm
:= Last
(L
);
2321 -- Don't count pragmas
2323 while Nkind
(Last_Stm
) = N_Pragma
2325 -- Don't count call to SS_Release (can happen after Raise_Exception)
2328 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
2330 Nkind
(Name
(Last_Stm
)) = N_Identifier
2332 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
2334 -- Don't count exception junk
2337 ((Nkind
(Last_Stm
) = N_Goto_Statement
2338 or else Nkind
(Last_Stm
) = N_Label
2339 or else Nkind
(Last_Stm
) = N_Object_Declaration
)
2340 and then Exception_Junk
(Last_Stm
))
2345 -- Here we have the "real" last statement
2347 Kind
:= Nkind
(Last_Stm
);
2349 -- Transfer of control, OK. Note that in the No_Return procedure
2350 -- case, we already diagnosed any explicit return statements, so
2351 -- we can treat them as OK in this context.
2353 if Is_Transfer
(Last_Stm
) then
2356 -- Check cases of explicit non-indirect procedure calls
2358 elsif Kind
= N_Procedure_Call_Statement
2359 and then Is_Entity_Name
(Name
(Last_Stm
))
2361 -- Check call to Raise_Exception procedure which is treated
2362 -- specially, as is a call to Reraise_Occurrence.
2364 -- We suppress the warning in these cases since it is likely that
2365 -- the programmer really does not expect to deal with the case
2366 -- of Null_Occurrence, and thus would find a warning about a
2367 -- missing return curious, and raising Program_Error does not
2368 -- seem such a bad behavior if this does occur.
2370 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
2372 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
2374 Raise_Exception_Call
:= True;
2376 -- For Raise_Exception call, test first argument, if it is
2377 -- an attribute reference for a 'Identity call, then we know
2378 -- that the call cannot possibly return.
2381 Arg
: constant Node_Id
:=
2382 Original_Node
(First_Actual
(Last_Stm
));
2385 if Nkind
(Arg
) = N_Attribute_Reference
2386 and then Attribute_Name
(Arg
) = Name_Identity
2393 -- If statement, need to look inside if there is an else and check
2394 -- each constituent statement sequence for proper termination.
2396 elsif Kind
= N_If_Statement
2397 and then Present
(Else_Statements
(Last_Stm
))
2399 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
2400 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
2402 if Present
(Elsif_Parts
(Last_Stm
)) then
2404 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
2407 while Present
(Elsif_Part
) loop
2408 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
2416 -- Case statement, check each case for proper termination
2418 elsif Kind
= N_Case_Statement
then
2423 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
2424 while Present
(Case_Alt
) loop
2425 Check_Statement_Sequence
(Statements
(Case_Alt
));
2426 Next_Non_Pragma
(Case_Alt
);
2432 -- Block statement, check its handled sequence of statements
2434 elsif Kind
= N_Block_Statement
then
2440 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
2449 -- Loop statement. If there is an iteration scheme, we can definitely
2450 -- fall out of the loop. Similarly if there is an exit statement, we
2451 -- can fall out. In either case we need a following return.
2453 elsif Kind
= N_Loop_Statement
then
2454 if Present
(Iteration_Scheme
(Last_Stm
))
2455 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
2459 -- A loop with no exit statement or iteration scheme if either
2460 -- an inifite loop, or it has some other exit (raise/return).
2461 -- In either case, no warning is required.
2467 -- Timed entry call, check entry call and delay alternatives
2469 -- Note: in expanded code, the timed entry call has been converted
2470 -- to a set of expanded statements on which the check will work
2471 -- correctly in any case.
2473 elsif Kind
= N_Timed_Entry_Call
then
2475 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
2476 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
2479 -- If statement sequence of entry call alternative is missing,
2480 -- then we can definitely fall through, and we post the error
2481 -- message on the entry call alternative itself.
2483 if No
(Statements
(ECA
)) then
2486 -- If statement sequence of delay alternative is missing, then
2487 -- we can definitely fall through, and we post the error
2488 -- message on the delay alternative itself.
2490 -- Note: if both ECA and DCA are missing the return, then we
2491 -- post only one message, should be enough to fix the bugs.
2492 -- If not we will get a message next time on the DCA when the
2495 elsif No
(Statements
(DCA
)) then
2498 -- Else check both statement sequences
2501 Check_Statement_Sequence
(Statements
(ECA
));
2502 Check_Statement_Sequence
(Statements
(DCA
));
2507 -- Conditional entry call, check entry call and else part
2509 -- Note: in expanded code, the conditional entry call has been
2510 -- converted to a set of expanded statements on which the check
2511 -- will work correctly in any case.
2513 elsif Kind
= N_Conditional_Entry_Call
then
2515 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
2518 -- If statement sequence of entry call alternative is missing,
2519 -- then we can definitely fall through, and we post the error
2520 -- message on the entry call alternative itself.
2522 if No
(Statements
(ECA
)) then
2525 -- Else check statement sequence and else part
2528 Check_Statement_Sequence
(Statements
(ECA
));
2529 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
2535 -- If we fall through, issue appropriate message
2539 if not Raise_Exception_Call
then
2541 ("?RETURN statement missing following this statement!",
2544 ("\?Program_Error may be raised at run time",
2548 -- Note: we set Err even though we have not issued a warning
2549 -- because we still have a case of a missing return. This is
2550 -- an extremely marginal case, probably will never be noticed
2551 -- but we might as well get it right.
2557 ("implied return after this statement not allowed (No_Return)",
2560 end Check_Statement_Sequence
;
2562 -- Start of processing for Check_Returns
2566 Check_Statement_Sequence
(Statements
(HSS
));
2568 if Present
(Exception_Handlers
(HSS
)) then
2569 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
2570 while Present
(Handler
) loop
2571 Check_Statement_Sequence
(Statements
(Handler
));
2572 Next_Non_Pragma
(Handler
);
2577 ----------------------------
2578 -- Check_Subprogram_Order --
2579 ----------------------------
2581 procedure Check_Subprogram_Order
(N
: Node_Id
) is
2583 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
2584 -- This is used to check if S1 > S2 in the sense required by this
2585 -- test, for example nameab < namec, but name2 < name10.
2587 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
2592 -- Remove trailing numeric parts
2595 while S1
(L1
) in '0' .. '9' loop
2600 while S2
(L2
) in '0' .. '9' loop
2604 -- If non-numeric parts non-equal, that's decisive
2606 if S1
(S1
'First .. L1
) < S2
(S2
'First .. L2
) then
2609 elsif S1
(S1
'First .. L1
) > S2
(S2
'First .. L2
) then
2612 -- If non-numeric parts equal, compare suffixed numeric parts. Note
2613 -- that a missing suffix is treated as numeric zero in this test.
2617 while L1
< S1
'Last loop
2619 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
2623 while L2
< S2
'Last loop
2625 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
2630 end Subprogram_Name_Greater
;
2632 -- Start of processing for Check_Subprogram_Order
2635 -- Check body in alpha order if this is option
2637 if Style_Check_Subprogram_Order
2638 and then Nkind
(N
) = N_Subprogram_Body
2639 and then Comes_From_Source
(N
)
2640 and then In_Extended_Main_Source_Unit
(N
)
2644 renames Scope_Stack
.Table
2645 (Scope_Stack
.Last
).Last_Subprogram_Name
;
2647 Body_Id
: constant Entity_Id
:=
2648 Defining_Entity
(Specification
(N
));
2651 Get_Decoded_Name_String
(Chars
(Body_Id
));
2654 if Subprogram_Name_Greater
2655 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
2657 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
2663 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
2666 end Check_Subprogram_Order;
2668 ------------------------------
2669 -- Check_Subtype_Conformant --
2670 ------------------------------
2672 procedure Check_Subtype_Conformant
2673 (New_Id : Entity_Id;
2675 Err_Loc : Node_Id := Empty)
2681 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
2682 end Check_Subtype_Conformant;
2684 ---------------------------
2685 -- Check_Type_Conformant --
2686 ---------------------------
2688 procedure Check_Type_Conformant
2689 (New_Id : Entity_Id;
2691 Err_Loc : Node_Id := Empty)
2697 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
2698 end Check_Type_Conformant;
2700 ----------------------
2701 -- Conforming_Types --
2702 ----------------------
2704 function Conforming_Types
2707 Ctype : Conformance_Type;
2708 Get_Inst : Boolean := False)
2711 Type_1 : Entity_Id := T1;
2712 Type_2 : Entity_Id := T2;
2714 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
2715 -- If neither T1 nor T2 are generic actual types, or if they are
2716 -- in different scopes (e.g. parent and child instances), then verify
2717 -- that the base types are equal. Otherwise T1 and T2 must be
2718 -- on the same subtype chain. The whole purpose of this procedure
2719 -- is to prevent spurious ambiguities in an instantiation that may
2720 -- arise if two distinct generic types are instantiated with the
2723 ----------------------
2724 -- Base_Types_Match --
2725 ----------------------
2727 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
2732 elsif Base_Type (T1) = Base_Type (T2) then
2734 -- The following is too permissive. A more precise test must
2735 -- check that the generic actual is an ancestor subtype of the
2738 return not Is_Generic_Actual_Type (T1)
2739 or else not Is_Generic_Actual_Type (T2)
2740 or else Scope (T1) /= Scope (T2);
2745 end Base_Types_Match;
2748 -- The context is an instance association for a formal
2749 -- access-to-subprogram type; the formal parameter types
2750 -- require mapping because they may denote other formal
2751 -- parameters of the generic unit.
2754 Type_1 := Get_Instance_Of (T1);
2755 Type_2 := Get_Instance_Of (T2);
2758 -- First see if base types match
2760 if Base_Types_Match (Type_1, Type_2) then
2761 return Ctype <= Mode_Conformant
2762 or else Subtypes_Statically_Match (Type_1, Type_2);
2764 elsif Is_Incomplete_Or_Private_Type (Type_1)
2765 and then Present (Full_View (Type_1))
2766 and then Base_Types_Match (Full_View (Type_1), Type_2)
2768 return Ctype <= Mode_Conformant
2769 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
2771 elsif Ekind (Type_2) = E_Incomplete_Type
2772 and then Present (Full_View (Type_2))
2773 and then Base_Types_Match (Type_1, Full_View (Type_2))
2775 return Ctype <= Mode_Conformant
2776 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
2779 -- Test anonymous access type case. For this case, static subtype
2780 -- matching is required for mode conformance (RM 6.3.1(15))
2782 if Ekind (Type_1) = E_Anonymous_Access_Type
2783 and then Ekind (Type_2) = E_Anonymous_Access_Type
2786 Desig_1 : Entity_Id;
2787 Desig_2 : Entity_Id;
2790 Desig_1 := Directly_Designated_Type (Type_1);
2792 -- An access parameter can designate an incomplete type.
2794 if Ekind (Desig_1) = E_Incomplete_Type
2795 and then Present (Full_View (Desig_1))
2797 Desig_1 := Full_View (Desig_1);
2800 Desig_2 := Directly_Designated_Type (Type_2);
2802 if Ekind (Desig_2) = E_Incomplete_Type
2803 and then Present (Full_View (Desig_2))
2805 Desig_2 := Full_View (Desig_2);
2808 -- The context is an instance association for a formal
2809 -- access-to-subprogram type; formal access parameter
2810 -- designated types require mapping because they may
2811 -- denote other formal parameters of the generic unit.
2814 Desig_1 := Get_Instance_Of (Desig_1);
2815 Desig_2 := Get_Instance_Of (Desig_2);
2818 -- It is possible for a Class_Wide_Type to be introduced for
2819 -- an incomplete type, in which case there is a separate class_
2820 -- wide type for the full view. The types conform if their
2821 -- Etypes conform, i.e. one may be the full view of the other.
2822 -- This can only happen in the context of an access parameter,
2823 -- other uses of an incomplete Class_Wide_Type are illegal.
2825 if Ekind (Desig_1) = E_Class_Wide_Type
2826 and then Ekind (Desig_2) = E_Class_Wide_Type
2829 Conforming_Types (Etype (Desig_1), Etype (Desig_2), Ctype);
2831 return Base_Type (Desig_1) = Base_Type (Desig_2)
2832 and then (Ctype = Type_Conformant
2834 Subtypes_Statically_Match (Desig_1, Desig_2));
2838 -- Otherwise definitely no match
2844 end Conforming_Types;
2846 --------------------------
2847 -- Create_Extra_Formals --
2848 --------------------------
2850 procedure Create_Extra_Formals (E : Entity_Id) is
2852 Last_Formal : Entity_Id;
2853 Last_Extra : Entity_Id;
2854 Formal_Type : Entity_Id;
2855 P_Formal : Entity_Id := Empty;
2857 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id;
2858 -- Add an extra formal, associated with the current Formal. The
2859 -- extra formal is added to the list of extra formals, and also
2860 -- returned as the result. These formals are always of mode IN.
2862 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is
2863 EF : constant Entity_Id :=
2864 Make_Defining_Identifier (Sloc (Formal),
2865 Chars => New_External_Name (Chars (Formal), 'F
'));
2868 -- We never generate extra formals if expansion is not active
2869 -- because we don't need them unless we are generating code.
2871 if not Expander_Active then
2875 -- A little optimization. Never generate an extra formal for
2876 -- the _init operand of an initialization procedure, since it
2877 -- could never be used.
2879 if Chars (Formal) = Name_uInit then
2883 Set_Ekind (EF, E_In_Parameter);
2884 Set_Actual_Subtype (EF, Typ);
2885 Set_Etype (EF, Typ);
2886 Set_Scope (EF, Scope (Formal));
2887 Set_Mechanism (EF, Default_Mechanism);
2888 Set_Formal_Validity (EF);
2890 Set_Extra_Formal (Last_Extra, EF);
2893 end Add_Extra_Formal;
2895 -- Start of processing for Create_Extra_Formals
2898 -- If this is a derived subprogram then the subtypes of the
2899 -- parent subprogram's formal parameters will be used to
2900 -- to determine the need for extra formals.
2902 if Is_Overloadable (E) and then Present (Alias (E)) then
2903 P_Formal := First_Formal (Alias (E));
2906 Last_Extra := Empty;
2907 Formal := First_Formal (E);
2908 while Present (Formal) loop
2909 Last_Extra := Formal;
2910 Next_Formal (Formal);
2913 -- If Extra_formals where already created, don't do it again
2914 -- This situation may arise for subprogram types created as part
2915 -- of dispatching calls (see Expand_Dispatch_Call)
2917 if Present (Last_Extra) and then
2918 Present (Extra_Formal (Last_Extra))
2923 Formal := First_Formal (E);
2925 while Present (Formal) loop
2927 -- Create extra formal for supporting the attribute 'Constrained
.
2928 -- The case of a private type view without discriminants also
2929 -- requires the extra formal if the underlying type has defaulted
2932 if Ekind
(Formal
) /= E_In_Parameter
then
2933 if Present
(P_Formal
) then
2934 Formal_Type
:= Etype
(P_Formal
);
2936 Formal_Type
:= Etype
(Formal
);
2939 if not Has_Discriminants
(Formal_Type
)
2940 and then Ekind
(Formal_Type
) in Private_Kind
2941 and then Present
(Underlying_Type
(Formal_Type
))
2943 Formal_Type
:= Underlying_Type
(Formal_Type
);
2946 if Has_Discriminants
(Formal_Type
)
2948 ((not Is_Constrained
(Formal_Type
)
2949 and then not Is_Indefinite_Subtype
(Formal_Type
))
2950 or else Present
(Extra_Formal
(Formal
)))
2952 Set_Extra_Constrained
2953 (Formal
, Add_Extra_Formal
(Standard_Boolean
));
2957 -- Create extra formal for supporting accessibility checking
2959 -- This is suppressed if we specifically suppress accessibility
2960 -- checks for either the subprogram, or the package in which it
2961 -- resides. However, we do not suppress it simply if the scope
2962 -- has accessibility checks suppressed, since this could cause
2963 -- trouble when clients are compiled with a different suppression
2964 -- setting. The explicit checks are safe from this point of view.
2966 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
2968 (Suppress_Accessibility_Checks
(E
)
2970 Suppress_Accessibility_Checks
(Scope
(E
)))
2972 (not Present
(P_Formal
)
2973 or else Present
(Extra_Accessibility
(P_Formal
)))
2975 -- Temporary kludge: for now we avoid creating the extra
2976 -- formal for access parameters of protected operations
2977 -- because of problem with the case of internal protected
2980 if Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Definition
2981 and then Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Body
2983 Set_Extra_Accessibility
2984 (Formal
, Add_Extra_Formal
(Standard_Natural
));
2988 if Present
(P_Formal
) then
2989 Next_Formal
(P_Formal
);
2992 Last_Formal
:= Formal
;
2993 Next_Formal
(Formal
);
2995 end Create_Extra_Formals
;
2997 -----------------------------
2998 -- Enter_Overloaded_Entity --
2999 -----------------------------
3001 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
3002 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
3003 C_E
: Entity_Id
:= Current_Entity
(S
);
3007 Set_Has_Homonym
(E
);
3008 Set_Has_Homonym
(S
);
3011 Set_Is_Immediately_Visible
(S
);
3012 Set_Scope
(S
, Current_Scope
);
3014 -- Chain new entity if front of homonym in current scope, so that
3015 -- homonyms are contiguous.
3020 while Homonym
(C_E
) /= E
loop
3021 C_E
:= Homonym
(C_E
);
3024 Set_Homonym
(C_E
, S
);
3028 Set_Current_Entity
(S
);
3033 Append_Entity
(S
, Current_Scope
);
3034 Set_Public_Status
(S
);
3036 if Debug_Flag_E
then
3037 Write_Str
("New overloaded entity chain: ");
3038 Write_Name
(Chars
(S
));
3041 while Present
(E
) loop
3042 Write_Str
(" "); Write_Int
(Int
(E
));
3049 -- Generate warning for hiding
3052 and then Comes_From_Source
(S
)
3053 and then In_Extended_Main_Source_Unit
(S
)
3060 -- Warn unless genuine overloading
3062 if (not Is_Overloadable
(E
))
3063 or else Subtype_Conformant
(E
, S
)
3065 Error_Msg_Sloc
:= Sloc
(E
);
3066 Error_Msg_N
("declaration of & hides one#?", S
);
3070 end Enter_Overloaded_Entity
;
3072 -----------------------------
3073 -- Find_Corresponding_Spec --
3074 -----------------------------
3076 function Find_Corresponding_Spec
(N
: Node_Id
) return Entity_Id
is
3077 Spec
: constant Node_Id
:= Specification
(N
);
3078 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
3083 E
:= Current_Entity
(Designator
);
3085 while Present
(E
) loop
3087 -- We are looking for a matching spec. It must have the same scope,
3088 -- and the same name, and either be type conformant, or be the case
3089 -- of a library procedure spec and its body (which belong to one
3090 -- another regardless of whether they are type conformant or not).
3092 if Scope
(E
) = Current_Scope
then
3093 if (Current_Scope
= Standard_Standard
3094 or else (Ekind
(E
) = Ekind
(Designator
)
3096 Type_Conformant
(E
, Designator
)))
3098 -- Within an instantiation, we know that spec and body are
3099 -- subtype conformant, because they were subtype conformant
3100 -- in the generic. We choose the subtype-conformant entity
3101 -- here as well, to resolve spurious ambiguities in the
3102 -- instance that were not present in the generic (i.e. when
3103 -- two different types are given the same actual). If we are
3104 -- looking for a spec to match a body, full conformance is
3108 Set_Convention
(Designator
, Convention
(E
));
3110 if Nkind
(N
) = N_Subprogram_Body
3111 and then Present
(Homonym
(E
))
3112 and then not Fully_Conformant
(E
, Designator
)
3116 elsif not Subtype_Conformant
(E
, Designator
) then
3121 if not Has_Completion
(E
) then
3123 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3124 Set_Corresponding_Spec
(N
, E
);
3127 Set_Has_Completion
(E
);
3130 elsif Nkind
(Parent
(N
)) = N_Subunit
then
3132 -- If this is the proper body of a subunit, the completion
3133 -- flag is set when analyzing the stub.
3137 -- If body already exists, this is an error unless the
3138 -- previous declaration is the implicit declaration of
3139 -- a derived subprogram, or this is a spurious overloading
3142 elsif No
(Alias
(E
))
3143 and then not Is_Intrinsic_Subprogram
(E
)
3144 and then not In_Instance
3146 Error_Msg_Sloc
:= Sloc
(E
);
3147 if Is_Imported
(E
) then
3149 ("body not allowed for imported subprogram & declared#",
3152 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
3156 elsif Is_Child_Unit
(E
)
3158 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
3160 Nkind
(Parent
(Unit_Declaration_Node
(Designator
)))
3161 = N_Compilation_Unit
3164 -- Child units cannot be overloaded, so a conformance mismatch
3165 -- between body and a previous spec is an error.
3168 ("body of child unit does not match previous declaration", N
);
3176 -- On exit, we know that no previous declaration of subprogram exists
3179 end Find_Corresponding_Spec
;
3181 ----------------------
3182 -- Fully_Conformant --
3183 ----------------------
3185 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
3189 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
3191 end Fully_Conformant
;
3193 ----------------------------------
3194 -- Fully_Conformant_Expressions --
3195 ----------------------------------
3197 function Fully_Conformant_Expressions
3198 (Given_E1
: Node_Id
;
3202 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
3203 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
3204 -- We always test conformance on original nodes, since it is possible
3205 -- for analysis and/or expansion to make things look as though they
3206 -- conform when they do not, e.g. by converting 1+2 into 3.
3208 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
3209 renames Fully_Conformant_Expressions
;
3211 function FCL
(L1
, L2
: List_Id
) return Boolean;
3212 -- Compare elements of two lists for conformance. Elements have to
3213 -- be conformant, and actuals inserted as default parameters do not
3214 -- match explicit actuals with the same value.
3216 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
3217 -- Compare an operator node with a function call.
3223 function FCL
(L1
, L2
: List_Id
) return Boolean is
3227 if L1
= No_List
then
3233 if L2
= No_List
then
3239 -- Compare two lists, skipping rewrite insertions (we want to
3240 -- compare the original trees, not the expanded versions!)
3243 if Is_Rewrite_Insertion
(N1
) then
3245 elsif Is_Rewrite_Insertion
(N2
) then
3251 elsif not FCE
(N1
, N2
) then
3264 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
3265 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
3270 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
3275 Act
:= First
(Actuals
);
3277 if Nkind
(Op_Node
) in N_Binary_Op
then
3279 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
3286 return Present
(Act
)
3287 and then FCE
(Right_Opnd
(Op_Node
), Act
)
3288 and then No
(Next
(Act
));
3292 -- Start of processing for Fully_Conformant_Expressions
3295 -- Non-conformant if paren count does not match. Note: if some idiot
3296 -- complains that we don't do this right for more than 3 levels of
3297 -- parentheses, they will be treated with the respect they deserve :-)
3299 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
3302 -- If same entities are referenced, then they are conformant
3303 -- even if they have different forms (RM 8.3.1(19-20)).
3305 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
3306 if Present
(Entity
(E1
)) then
3307 return Entity
(E1
) = Entity
(E2
)
3308 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
3309 and then Ekind
(Entity
(E1
)) = E_Discriminant
3310 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
3312 elsif Nkind
(E1
) = N_Expanded_Name
3313 and then Nkind
(E2
) = N_Expanded_Name
3314 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
3315 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
3317 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
3320 -- Identifiers in component associations don't always have
3321 -- entities, but their names must conform.
3323 return Nkind
(E1
) = N_Identifier
3324 and then Nkind
(E2
) = N_Identifier
3325 and then Chars
(E1
) = Chars
(E2
);
3328 elsif Nkind
(E1
) = N_Character_Literal
3329 and then Nkind
(E2
) = N_Expanded_Name
3331 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
3332 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
3334 elsif Nkind
(E2
) = N_Character_Literal
3335 and then Nkind
(E1
) = N_Expanded_Name
3337 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
3338 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
3340 elsif Nkind
(E1
) in N_Op
3341 and then Nkind
(E2
) = N_Function_Call
3343 return FCO
(E1
, E2
);
3345 elsif Nkind
(E2
) in N_Op
3346 and then Nkind
(E1
) = N_Function_Call
3348 return FCO
(E2
, E1
);
3350 -- Otherwise we must have the same syntactic entity
3352 elsif Nkind
(E1
) /= Nkind
(E2
) then
3355 -- At this point, we specialize by node type
3362 FCL
(Expressions
(E1
), Expressions
(E2
))
3363 and then FCL
(Component_Associations
(E1
),
3364 Component_Associations
(E2
));
3367 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
3369 Nkind
(Expression
(E2
)) = N_Qualified_Expression
3371 return FCE
(Expression
(E1
), Expression
(E2
));
3373 -- Check that the subtype marks and any constraints
3378 Indic1
: constant Node_Id
:= Expression
(E1
);
3379 Indic2
: constant Node_Id
:= Expression
(E2
);
3384 if Nkind
(Indic1
) /= N_Subtype_Indication
then
3386 Nkind
(Indic2
) /= N_Subtype_Indication
3387 and then Entity
(Indic1
) = Entity
(Indic2
);
3389 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
3391 Nkind
(Indic1
) /= N_Subtype_Indication
3392 and then Entity
(Indic1
) = Entity
(Indic2
);
3395 if Entity
(Subtype_Mark
(Indic1
)) /=
3396 Entity
(Subtype_Mark
(Indic2
))
3401 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
3402 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
3404 while Present
(Elt1
) and then Present
(Elt2
) loop
3405 if not FCE
(Elt1
, Elt2
) then
3418 when N_Attribute_Reference
=>
3420 Attribute_Name
(E1
) = Attribute_Name
(E2
)
3421 and then FCL
(Expressions
(E1
), Expressions
(E2
));
3425 Entity
(E1
) = Entity
(E2
)
3426 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
3427 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3429 when N_And_Then | N_Or_Else | N_In | N_Not_In
=>
3431 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
3433 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3435 when N_Character_Literal
=>
3437 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
3439 when N_Component_Association
=>
3441 FCL
(Choices
(E1
), Choices
(E2
))
3442 and then FCE
(Expression
(E1
), Expression
(E2
));
3444 when N_Conditional_Expression
=>
3446 FCL
(Expressions
(E1
), Expressions
(E2
));
3448 when N_Explicit_Dereference
=>
3450 FCE
(Prefix
(E1
), Prefix
(E2
));
3452 when N_Extension_Aggregate
=>
3454 FCL
(Expressions
(E1
), Expressions
(E2
))
3455 and then Null_Record_Present
(E1
) =
3456 Null_Record_Present
(E2
)
3457 and then FCL
(Component_Associations
(E1
),
3458 Component_Associations
(E2
));
3460 when N_Function_Call
=>
3462 FCE
(Name
(E1
), Name
(E2
))
3463 and then FCL
(Parameter_Associations
(E1
),
3464 Parameter_Associations
(E2
));
3466 when N_Indexed_Component
=>
3468 FCE
(Prefix
(E1
), Prefix
(E2
))
3469 and then FCL
(Expressions
(E1
), Expressions
(E2
));
3471 when N_Integer_Literal
=>
3472 return (Intval
(E1
) = Intval
(E2
));
3477 when N_Operator_Symbol
=>
3479 Chars
(E1
) = Chars
(E2
);
3481 when N_Others_Choice
=>
3484 when N_Parameter_Association
=>
3487 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
3488 and then FCE
(Explicit_Actual_Parameter
(E1
),
3489 Explicit_Actual_Parameter
(E2
));
3491 when N_Qualified_Expression
=>
3493 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3494 and then FCE
(Expression
(E1
), Expression
(E2
));
3498 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
3499 and then FCE
(High_Bound
(E1
), High_Bound
(E2
));
3501 when N_Real_Literal
=>
3502 return (Realval
(E1
) = Realval
(E2
));
3504 when N_Selected_Component
=>
3506 FCE
(Prefix
(E1
), Prefix
(E2
))
3507 and then FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
3511 FCE
(Prefix
(E1
), Prefix
(E2
))
3512 and then FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
3514 when N_String_Literal
=>
3516 S1
: constant String_Id
:= Strval
(E1
);
3517 S2
: constant String_Id
:= Strval
(E2
);
3518 L1
: constant Nat
:= String_Length
(S1
);
3519 L2
: constant Nat
:= String_Length
(S2
);
3526 for J
in 1 .. L1
loop
3527 if Get_String_Char
(S1
, J
) /=
3528 Get_String_Char
(S2
, J
)
3538 when N_Type_Conversion
=>
3540 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3541 and then FCE
(Expression
(E1
), Expression
(E2
));
3545 Entity
(E1
) = Entity
(E2
)
3546 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3548 when N_Unchecked_Type_Conversion
=>
3550 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3551 and then FCE
(Expression
(E1
), Expression
(E2
));
3553 -- All other node types cannot appear in this context. Strictly
3554 -- we should raise a fatal internal error. Instead we just ignore
3555 -- the nodes. This means that if anyone makes a mistake in the
3556 -- expander and mucks an expression tree irretrievably, the
3557 -- result will be a failure to detect a (probably very obscure)
3558 -- case of non-conformance, which is better than bombing on some
3559 -- case where two expressions do in fact conform.
3566 end Fully_Conformant_Expressions
;
3568 --------------------
3569 -- Install_Entity --
3570 --------------------
3572 procedure Install_Entity
(E
: Entity_Id
) is
3573 Prev
: constant Entity_Id
:= Current_Entity
(E
);
3576 Set_Is_Immediately_Visible
(E
);
3577 Set_Current_Entity
(E
);
3578 Set_Homonym
(E
, Prev
);
3581 ---------------------
3582 -- Install_Formals --
3583 ---------------------
3585 procedure Install_Formals
(Id
: Entity_Id
) is
3589 F
:= First_Formal
(Id
);
3591 while Present
(F
) loop
3595 end Install_Formals
;
3597 ---------------------------------
3598 -- Is_Non_Overriding_Operation --
3599 ---------------------------------
3601 function Is_Non_Overriding_Operation
3602 (Prev_E
: Entity_Id
;
3608 G_Typ
: Entity_Id
:= Empty
;
3610 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
3611 -- If F_Type is a derived type associated with a generic actual
3612 -- subtype, then return its Generic_Parent_Type attribute, else
3615 function Types_Correspond
3616 (P_Type
: Entity_Id
;
3619 -- Returns true if and only if the types (or designated types
3620 -- in the case of anonymous access types) are the same or N_Type
3621 -- is derived directly or indirectly from P_Type.
3623 -----------------------------
3624 -- Get_Generic_Parent_Type --
3625 -----------------------------
3627 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
3632 if Is_Derived_Type
(F_Typ
)
3633 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
3635 -- The tree must be traversed to determine the parent
3636 -- subtype in the generic unit, which unfortunately isn't
3637 -- always available via semantic attributes. ???
3638 -- (Note: The use of Original_Node is needed for cases
3639 -- where a full derived type has been rewritten.)
3641 Indic
:= Subtype_Indication
3642 (Type_Definition
(Original_Node
(Parent
(F_Typ
))));
3644 if Nkind
(Indic
) = N_Subtype_Indication
then
3645 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
3647 G_Typ
:= Entity
(Indic
);
3650 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
3651 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
3653 return Generic_Parent_Type
(Parent
(G_Typ
));
3658 end Get_Generic_Parent_Type
;
3660 ----------------------
3661 -- Types_Correspond --
3662 ----------------------
3664 function Types_Correspond
3665 (P_Type
: Entity_Id
;
3669 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
3670 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
3673 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
3674 Prev_Type
:= Designated_Type
(Prev_Type
);
3677 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
3678 New_Type
:= Designated_Type
(New_Type
);
3681 if Prev_Type
= New_Type
then
3684 elsif not Is_Class_Wide_Type
(New_Type
) then
3685 while Etype
(New_Type
) /= New_Type
loop
3686 New_Type
:= Etype
(New_Type
);
3687 if New_Type
= Prev_Type
then
3693 end Types_Correspond
;
3695 -- Start of processing for Is_Non_Overriding_Operation
3698 -- In the case where both operations are implicit derived
3699 -- subprograms then neither overrides the other. This can
3700 -- only occur in certain obscure cases (e.g., derivation
3701 -- from homographs created in a generic instantiation).
3703 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
3706 elsif Ekind
(Current_Scope
) = E_Package
3707 and then Is_Generic_Instance
(Current_Scope
)
3708 and then In_Private_Part
(Current_Scope
)
3709 and then Comes_From_Source
(New_E
)
3711 -- We examine the formals and result subtype of the inherited
3712 -- operation, to determine whether their type is derived from
3713 -- (the instance of) a generic type.
3715 Formal
:= First_Formal
(Prev_E
);
3717 while Present
(Formal
) loop
3718 F_Typ
:= Base_Type
(Etype
(Formal
));
3720 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
3721 F_Typ
:= Designated_Type
(F_Typ
);
3724 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
3726 Next_Formal
(Formal
);
3729 if not Present
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
3730 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
3737 -- If the generic type is a private type, then the original
3738 -- operation was not overriding in the generic, because there was
3739 -- no primitive operation to override.
3741 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
3742 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
3743 N_Formal_Private_Type_Definition
3747 -- The generic parent type is the ancestor of a formal derived
3748 -- type declaration. We need to check whether it has a primitive
3749 -- operation that should be overridden by New_E in the generic.
3753 P_Formal
: Entity_Id
;
3754 N_Formal
: Entity_Id
;
3758 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
3761 while Present
(Prim_Elt
) loop
3762 P_Prim
:= Node
(Prim_Elt
);
3763 if Chars
(P_Prim
) = Chars
(New_E
)
3764 and then Ekind
(P_Prim
) = Ekind
(New_E
)
3766 P_Formal
:= First_Formal
(P_Prim
);
3767 N_Formal
:= First_Formal
(New_E
);
3768 while Present
(P_Formal
) and then Present
(N_Formal
) loop
3769 P_Typ
:= Etype
(P_Formal
);
3770 N_Typ
:= Etype
(N_Formal
);
3772 if not Types_Correspond
(P_Typ
, N_Typ
) then
3776 Next_Entity
(P_Formal
);
3777 Next_Entity
(N_Formal
);
3780 -- Found a matching primitive operation belonging to
3781 -- the formal ancestor type, so the new subprogram
3784 if not Present
(P_Formal
)
3785 and then not Present
(N_Formal
)
3786 and then (Ekind
(New_E
) /= E_Function
3789 (Etype
(P_Prim
), Etype
(New_E
)))
3795 Next_Elmt
(Prim_Elt
);
3798 -- If no match found, then the new subprogram does
3799 -- not override in the generic (nor in the instance).
3807 end Is_Non_Overriding_Operation
;
3809 ------------------------------
3810 -- Make_Inequality_Operator --
3811 ------------------------------
3813 -- S is the defining identifier of an equality operator. We build a
3814 -- subprogram declaration with the right signature. This operation is
3815 -- intrinsic, because it is always expanded as the negation of the
3816 -- call to the equality function.
3818 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
3819 Loc
: constant Source_Ptr
:= Sloc
(S
);
3822 Op_Name
: Entity_Id
;
3828 -- Check that equality was properly defined.
3830 if No
(Next_Formal
(First_Formal
(S
))) then
3834 A
:= Make_Defining_Identifier
(Loc
, Chars
(First_Formal
(S
)));
3835 B
:= Make_Defining_Identifier
(Loc
,
3836 Chars
(Next_Formal
(First_Formal
(S
))));
3838 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
3840 Formals
:= New_List
(
3841 Make_Parameter_Specification
(Loc
,
3842 Defining_Identifier
=> A
,
3844 New_Reference_To
(Etype
(First_Formal
(S
)), Loc
)),
3846 Make_Parameter_Specification
(Loc
,
3847 Defining_Identifier
=> B
,
3849 New_Reference_To
(Etype
(Next_Formal
(First_Formal
(S
))), Loc
)));
3852 Make_Subprogram_Declaration
(Loc
,
3854 Make_Function_Specification
(Loc
,
3855 Defining_Unit_Name
=> Op_Name
,
3856 Parameter_Specifications
=> Formals
,
3857 Subtype_Mark
=> New_Reference_To
(Standard_Boolean
, Loc
)));
3859 -- Insert inequality right after equality if it is explicit or after
3860 -- the derived type when implicit. These entities are created only
3861 -- for visibility purposes, and eventually replaced in the course of
3862 -- expansion, so they do not need to be attached to the tree and seen
3863 -- by the back-end. Keeping them internal also avoids spurious freezing
3864 -- problems. The parent field is set simply to make analysis safe.
3866 if No
(Alias
(S
)) then
3867 Set_Parent
(Decl
, Parent
(Unit_Declaration_Node
(S
)));
3869 Set_Parent
(Decl
, Parent
(Parent
(Etype
(First_Formal
(S
)))));
3872 Mark_Rewrite_Insertion
(Decl
);
3873 Set_Is_Intrinsic_Subprogram
(Op_Name
);
3875 Set_Has_Completion
(Op_Name
);
3876 Set_Corresponding_Equality
(Op_Name
, S
);
3877 Set_Is_Abstract
(Op_Name
, Is_Abstract
(S
));
3879 end Make_Inequality_Operator
;
3881 ----------------------
3882 -- May_Need_Actuals --
3883 ----------------------
3885 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
3890 F
:= First_Formal
(Fun
);
3893 while Present
(F
) loop
3894 if No
(Default_Value
(F
)) then
3902 Set_Needs_No_Actuals
(Fun
, B
);
3903 end May_Need_Actuals
;
3905 ---------------------
3906 -- Mode_Conformant --
3907 ---------------------
3909 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
3913 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
3915 end Mode_Conformant
;
3917 ---------------------------
3918 -- New_Overloaded_Entity --
3919 ---------------------------
3921 procedure New_Overloaded_Entity
3923 Derived_Type
: Entity_Id
:= Empty
)
3925 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
3926 Prev_Vis
: Entity_Id
:= Empty
;
3928 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
3929 -- Check that E is declared in the private part of the current package,
3930 -- or in the package body, where it may hide a previous declaration.
3931 -- We can' use In_Private_Part by itself because this flag is also
3932 -- set when freezing entities, so we must examine the place of the
3933 -- declaration in the tree, and recognize wrapper packages as well.
3935 procedure Maybe_Primitive_Operation
(Overriding
: Boolean := False);
3936 -- If the subprogram being analyzed is a primitive operation of
3937 -- the type of one of its formals, set the corresponding flag.
3939 ----------------------------
3940 -- Is_Private_Declaration --
3941 ----------------------------
3943 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
3944 Priv_Decls
: List_Id
;
3945 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
3948 if Is_Package
(Current_Scope
)
3949 and then In_Private_Part
(Current_Scope
)
3952 Private_Declarations
(
3953 Specification
(Unit_Declaration_Node
(Current_Scope
)));
3955 return In_Package_Body
(Current_Scope
)
3956 or else List_Containing
(Decl
) = Priv_Decls
3957 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
3958 and then not Is_Compilation_Unit
(
3959 Defining_Entity
(Parent
(Decl
)))
3960 and then List_Containing
(Parent
(Parent
(Decl
)))
3965 end Is_Private_Declaration
;
3967 -------------------------------
3968 -- Maybe_Primitive_Operation --
3969 -------------------------------
3971 procedure Maybe_Primitive_Operation
(Overriding
: Boolean := False) is
3976 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
3977 -- Returns true if T is declared in the visible part of
3978 -- the current package scope; otherwise returns false.
3979 -- Assumes that T is declared in a package.
3981 procedure Check_Private_Overriding
(T
: Entity_Id
);
3982 -- Checks that if a primitive abstract subprogram of a visible
3983 -- abstract type is declared in a private part, then it must
3984 -- override an abstract subprogram declared in the visible part.
3985 -- Also checks that if a primitive function with a controlling
3986 -- result is declared in a private part, then it must override
3987 -- a function declared in the visible part.
3989 ------------------------------
3990 -- Check_Private_Overriding --
3991 ------------------------------
3993 procedure Check_Private_Overriding
(T
: Entity_Id
) is
3995 if Ekind
(Current_Scope
) = E_Package
3996 and then In_Private_Part
(Current_Scope
)
3997 and then Visible_Part_Type
(T
)
3998 and then not In_Instance
4001 and then Is_Abstract
(S
)
4002 and then (not Overriding
or else not Is_Abstract
(E
))
4004 Error_Msg_N
("abstract subprograms must be visible "
4005 & "('R'M 3.9.3(10))!", S
);
4007 elsif Ekind
(S
) = E_Function
4008 and then Is_Tagged_Type
(T
)
4009 and then T
= Base_Type
(Etype
(S
))
4010 and then not Overriding
4013 ("private function with tagged result must"
4014 & " override visible-part function", S
);
4016 ("\move subprogram to the visible part"
4017 & " ('R'M 3.9.3(10))", S
);
4020 end Check_Private_Overriding
;
4022 -----------------------
4023 -- Visible_Part_Type --
4024 -----------------------
4026 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
4027 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
4031 -- If the entity is a private type, then it must be
4032 -- declared in a visible part.
4034 if Ekind
(T
) in Private_Kind
then
4038 -- Otherwise, we traverse the visible part looking for its
4039 -- corresponding declaration. We cannot use the declaration
4040 -- node directly because in the private part the entity of a
4041 -- private type is the one in the full view, which does not
4042 -- indicate that it is the completion of something visible.
4044 N
:= First
(Visible_Declarations
(Specification
(P
)));
4045 while Present
(N
) loop
4046 if Nkind
(N
) = N_Full_Type_Declaration
4047 and then Present
(Defining_Identifier
(N
))
4048 and then T
= Defining_Identifier
(N
)
4052 elsif (Nkind
(N
) = N_Private_Type_Declaration
4054 Nkind
(N
) = N_Private_Extension_Declaration
)
4055 and then Present
(Defining_Identifier
(N
))
4056 and then T
= Full_View
(Defining_Identifier
(N
))
4065 end Visible_Part_Type
;
4067 -- Start of processing for Maybe_Primitive_Operation
4070 if not Comes_From_Source
(S
) then
4073 elsif (Ekind
(Current_Scope
) = E_Package
4074 and then not In_Package_Body
(Current_Scope
))
4077 -- For function, check return type
4079 if Ekind
(S
) = E_Function
then
4080 B_Typ
:= Base_Type
(Etype
(S
));
4082 if Scope
(B_Typ
) = Current_Scope
then
4083 Set_Has_Primitive_Operations
(B_Typ
);
4084 Check_Private_Overriding
(B_Typ
);
4088 -- For all subprograms, check formals
4090 Formal
:= First_Formal
(S
);
4091 while Present
(Formal
) loop
4092 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
4093 F_Typ
:= Designated_Type
(Etype
(Formal
));
4095 F_Typ
:= Etype
(Formal
);
4098 B_Typ
:= Base_Type
(F_Typ
);
4100 if Scope
(B_Typ
) = Current_Scope
then
4101 Set_Has_Primitive_Operations
(B_Typ
);
4102 Check_Private_Overriding
(B_Typ
);
4105 Next_Formal
(Formal
);
4108 end Maybe_Primitive_Operation
;
4110 -- Start of processing for New_Overloaded_Entity
4114 Enter_Overloaded_Entity
(S
);
4115 Check_Dispatching_Operation
(S
, Empty
);
4116 Maybe_Primitive_Operation
;
4118 elsif not Is_Overloadable
(E
) then
4120 -- Check for spurious conflict produced by a subprogram that has the
4121 -- same name as that of the enclosing generic package. The conflict
4122 -- occurs within an instance, between the subprogram and the renaming
4123 -- declaration for the package. After the subprogram, the package
4124 -- renaming declaration becomes hidden.
4126 if Ekind
(E
) = E_Package
4127 and then Present
(Renamed_Object
(E
))
4128 and then Renamed_Object
(E
) = Current_Scope
4129 and then Nkind
(Parent
(Renamed_Object
(E
))) =
4130 N_Package_Specification
4131 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
4134 Set_Is_Immediately_Visible
(E
, False);
4135 Enter_Overloaded_Entity
(S
);
4136 Set_Homonym
(S
, Homonym
(E
));
4137 Check_Dispatching_Operation
(S
, Empty
);
4139 -- If the subprogram is implicit it is hidden by the previous
4140 -- declaration. However if it is dispatching, it must appear in
4141 -- the dispatch table anyway, because it can be dispatched to
4142 -- even if it cannot be called directly.
4144 elsif Present
(Alias
(S
))
4145 and then not Comes_From_Source
(S
)
4147 Set_Scope
(S
, Current_Scope
);
4149 if Is_Dispatching_Operation
(Alias
(S
)) then
4150 Check_Dispatching_Operation
(S
, Empty
);
4156 Error_Msg_Sloc
:= Sloc
(E
);
4157 Error_Msg_N
("& conflicts with declaration#", S
);
4159 -- Useful additional warning.
4161 if Is_Generic_Unit
(E
) then
4162 Error_Msg_N
("\previous generic unit cannot be overloaded", S
);
4169 -- E exists and is overloadable. Determine whether S is the body
4170 -- of E, a new overloaded entity with a different signature, or
4171 -- an error altogether.
4173 while Present
(E
) loop
4174 if Scope
(E
) /= Current_Scope
then
4177 elsif Type_Conformant
(E
, S
) then
4179 -- If the old and new entities have the same profile and
4180 -- one is not the body of the other, then this is an error,
4181 -- unless one of them is implicitly declared.
4183 -- There are some cases when both can be implicit, for example
4184 -- when both a literal and a function that overrides it are
4185 -- inherited in a derivation, or when an inhertited operation
4186 -- of a tagged full type overrides the ineherited operation of
4187 -- a private extension. Ada 83 had a special rule for the
4188 -- the literal case. In Ada95, the later implicit operation
4189 -- hides the former, and the literal is always the former.
4190 -- In the odd case where both are derived operations declared
4191 -- at the same point, both operations should be declared,
4192 -- and in that case we bypass the following test and proceed
4193 -- to the next part (this can only occur for certain obscure
4194 -- cases involving homographs in instances and can't occur for
4195 -- dispatching operations ???). Note that the following
4196 -- condition is less than clear. For example, it's not at
4197 -- all clear why there's a test for E_Entry here. ???
4199 if Present
(Alias
(S
))
4200 and then (No
(Alias
(E
))
4201 or else Comes_From_Source
(E
)
4202 or else Is_Dispatching_Operation
(E
))
4204 (Ekind
(E
) = E_Entry
4205 or else Ekind
(E
) /= E_Enumeration_Literal
)
4207 -- When an derived operation is overloaded it may be due
4208 -- to the fact that the full view of a private extension
4209 -- re-inherits. It has to be dealt with.
4211 if Is_Package
(Current_Scope
)
4212 and then In_Private_Part
(Current_Scope
)
4214 Check_Operation_From_Private_View
(S
, E
);
4217 -- In any case the implicit operation remains hidden by
4218 -- the existing declaration.
4222 -- Within an instance, the renaming declarations for
4223 -- actual subprograms may become ambiguous, but they do
4224 -- not hide each other.
4226 elsif Ekind
(E
) /= E_Entry
4227 and then not Comes_From_Source
(E
)
4228 and then not Is_Generic_Instance
(E
)
4229 and then (Present
(Alias
(E
))
4230 or else Is_Intrinsic_Subprogram
(E
))
4231 and then (not In_Instance
4232 or else No
(Parent
(E
))
4233 or else Nkind
(Unit_Declaration_Node
(E
)) /=
4234 N_Subprogram_Renaming_Declaration
)
4236 -- A subprogram child unit is not allowed to override
4237 -- an inherited subprogram (10.1.1(20)).
4239 if Is_Child_Unit
(S
) then
4241 ("child unit overrides inherited subprogram in parent",
4246 if Is_Non_Overriding_Operation
(E
, S
) then
4247 Enter_Overloaded_Entity
(S
);
4248 if not Present
(Derived_Type
)
4249 or else Is_Tagged_Type
(Derived_Type
)
4251 Check_Dispatching_Operation
(S
, Empty
);
4257 -- E is a derived operation or an internal operator which
4258 -- is being overridden. Remove E from further visibility.
4259 -- Furthermore, if E is a dispatching operation, it must be
4260 -- replaced in the list of primitive operations of its type
4261 -- (see Override_Dispatching_Operation).
4267 Prev
:= First_Entity
(Current_Scope
);
4269 while Present
(Prev
)
4270 and then Next_Entity
(Prev
) /= E
4275 -- It is possible for E to be in the current scope and
4276 -- yet not in the entity chain. This can only occur in a
4277 -- generic context where E is an implicit concatenation
4278 -- in the formal part, because in a generic body the
4279 -- entity chain starts with the formals.
4282 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
4284 -- E must be removed both from the entity_list of the
4285 -- current scope, and from the visibility chain
4287 if Debug_Flag_E
then
4288 Write_Str
("Override implicit operation ");
4289 Write_Int
(Int
(E
));
4293 -- If E is a predefined concatenation, it stands for four
4294 -- different operations. As a result, a single explicit
4295 -- declaration does not hide it. In a possible ambiguous
4296 -- situation, Disambiguate chooses the user-defined op,
4297 -- so it is correct to retain the previous internal one.
4299 if Chars
(E
) /= Name_Op_Concat
4300 or else Ekind
(E
) /= E_Operator
4302 -- For nondispatching derived operations that are
4303 -- overridden by a subprogram declared in the private
4304 -- part of a package, we retain the derived subprogram
4305 -- but mark it as not immediately visible. If the
4306 -- derived operation was declared in the visible part
4307 -- then this ensures that it will still be visible
4308 -- outside the package with the proper signature
4309 -- (calls from outside must also be directed to this
4310 -- version rather than the overriding one, unlike the
4311 -- dispatching case). Calls from inside the package
4312 -- will still resolve to the overriding subprogram
4313 -- since the derived one is marked as not visible
4314 -- within the package.
4316 -- If the private operation is dispatching, we achieve
4317 -- the overriding by keeping the implicit operation
4318 -- but setting its alias to be the overring one. In
4319 -- this fashion the proper body is executed in all
4320 -- cases, but the original signature is used outside
4323 -- If the overriding is not in the private part, we
4324 -- remove the implicit operation altogether.
4326 if Is_Private_Declaration
(S
) then
4328 if not Is_Dispatching_Operation
(E
) then
4329 Set_Is_Immediately_Visible
(E
, False);
4332 -- work done in Override_Dispatching_Operation.
4338 -- Find predecessor of E in Homonym chain.
4340 if E
= Current_Entity
(E
) then
4343 Prev_Vis
:= Current_Entity
(E
);
4344 while Homonym
(Prev_Vis
) /= E
loop
4345 Prev_Vis
:= Homonym
(Prev_Vis
);
4349 if Prev_Vis
/= Empty
then
4351 -- Skip E in the visibility chain
4353 Set_Homonym
(Prev_Vis
, Homonym
(E
));
4356 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
4359 Set_Next_Entity
(Prev
, Next_Entity
(E
));
4361 if No
(Next_Entity
(Prev
)) then
4362 Set_Last_Entity
(Current_Scope
, Prev
);
4368 Enter_Overloaded_Entity
(S
);
4370 if Is_Dispatching_Operation
(E
) then
4371 -- An overriding dispatching subprogram inherits
4372 -- the convention of the overridden subprogram
4375 Set_Convention
(S
, Convention
(E
));
4377 Check_Dispatching_Operation
(S
, E
);
4379 Check_Dispatching_Operation
(S
, Empty
);
4382 Maybe_Primitive_Operation
(Overriding
=> True);
4383 goto Check_Inequality
;
4386 -- Apparent redeclarations in instances can occur when two
4387 -- formal types get the same actual type. The subprograms in
4388 -- in the instance are legal, even if not callable from the
4389 -- outside. Calls from within are disambiguated elsewhere.
4390 -- For dispatching operations in the visible part, the usual
4391 -- rules apply, and operations with the same profile are not
4394 elsif (In_Instance_Visible_Part
4395 and then not Is_Dispatching_Operation
(E
))
4396 or else In_Instance_Not_Visible
4400 -- Here we have a real error (identical profile)
4403 Error_Msg_Sloc
:= Sloc
(E
);
4405 -- Avoid cascaded errors if the entity appears in
4406 -- subsequent calls.
4408 Set_Scope
(S
, Current_Scope
);
4410 Error_Msg_N
("& conflicts with declaration#", S
);
4412 if Is_Generic_Instance
(S
)
4413 and then not Has_Completion
(E
)
4416 ("\instantiation cannot provide body for it", S
);
4430 -- On exit, we know that S is a new entity
4432 Enter_Overloaded_Entity
(S
);
4433 Maybe_Primitive_Operation
;
4435 -- If S is a derived operation for an untagged type then
4436 -- by definition it's not a dispatching operation (even
4437 -- if the parent operation was dispatching), so we don't
4438 -- call Check_Dispatching_Operation in that case.
4440 if not Present
(Derived_Type
)
4441 or else Is_Tagged_Type
(Derived_Type
)
4443 Check_Dispatching_Operation
(S
, Empty
);
4447 -- If this is a user-defined equality operator that is not
4448 -- a derived subprogram, create the corresponding inequality.
4449 -- If the operation is dispatching, the expansion is done
4450 -- elsewhere, and we do not create an explicit inequality
4453 <<Check_Inequality
>>
4454 if Chars
(S
) = Name_Op_Eq
4455 and then Etype
(S
) = Standard_Boolean
4456 and then Present
(Parent
(S
))
4457 and then not Is_Dispatching_Operation
(S
)
4459 Make_Inequality_Operator
(S
);
4462 end New_Overloaded_Entity
;
4464 ---------------------
4465 -- Process_Formals --
4466 ---------------------
4468 procedure Process_Formals
4470 Related_Nod
: Node_Id
)
4472 Param_Spec
: Node_Id
;
4474 Formal_Type
: Entity_Id
;
4478 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
4479 -- Check whether the default has a class-wide type. After analysis
4480 -- the default has the type of the formal, so we must also check
4481 -- explicitly for an access attribute.
4483 ---------------------------
4484 -- Is_Class_Wide_Default --
4485 ---------------------------
4487 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
4489 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
4490 or else (Nkind
(D
) = N_Attribute_Reference
4491 and then Attribute_Name
(D
) = Name_Access
4492 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
4493 end Is_Class_Wide_Default
;
4495 -- Start of processing for Process_Formals
4498 -- In order to prevent premature use of the formals in the same formal
4499 -- part, the Ekind is left undefined until all default expressions are
4500 -- analyzed. The Ekind is established in a separate loop at the end.
4502 Param_Spec
:= First
(T
);
4504 while Present
(Param_Spec
) loop
4506 Formal
:= Defining_Identifier
(Param_Spec
);
4507 Enter_Name
(Formal
);
4509 -- Case of ordinary parameters
4511 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
4512 Find_Type
(Parameter_Type
(Param_Spec
));
4513 Ptype
:= Parameter_Type
(Param_Spec
);
4515 if Ptype
= Error
then
4519 Formal_Type
:= Entity
(Ptype
);
4521 if Ekind
(Formal_Type
) = E_Incomplete_Type
4522 or else (Is_Class_Wide_Type
(Formal_Type
)
4523 and then Ekind
(Root_Type
(Formal_Type
)) =
4526 if Nkind
(Parent
(T
)) /= N_Access_Function_Definition
4527 and then Nkind
(Parent
(T
)) /= N_Access_Procedure_Definition
4529 Error_Msg_N
("invalid use of incomplete type", Param_Spec
);
4532 elsif Ekind
(Formal_Type
) = E_Void
then
4533 Error_Msg_NE
("premature use of&",
4534 Parameter_Type
(Param_Spec
), Formal_Type
);
4537 -- An access formal type
4541 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
4544 Set_Etype
(Formal
, Formal_Type
);
4546 Default
:= Expression
(Param_Spec
);
4548 if Present
(Default
) then
4549 if Out_Present
(Param_Spec
) then
4551 ("default initialization only allowed for IN parameters",
4555 -- Do the special preanalysis of the expression (see section on
4556 -- "Handling of Default Expressions" in the spec of package Sem).
4558 Analyze_Default_Expression
(Default
, Formal_Type
);
4560 -- Check that the designated type of an access parameter's
4561 -- default is not a class-wide type unless the parameter's
4562 -- designated type is also class-wide.
4564 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
4565 and then Is_Class_Wide_Default
(Default
)
4566 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
4569 ("access to class-wide expression not allowed here", Default
);
4577 -- Now set the kind (mode) of each formal
4579 Param_Spec
:= First
(T
);
4581 while Present
(Param_Spec
) loop
4582 Formal
:= Defining_Identifier
(Param_Spec
);
4583 Set_Formal_Mode
(Formal
);
4585 if Ekind
(Formal
) = E_In_Parameter
then
4586 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
4588 if Present
(Expression
(Param_Spec
)) then
4589 Default
:= Expression
(Param_Spec
);
4591 if Is_Scalar_Type
(Etype
(Default
)) then
4593 (Parameter_Type
(Param_Spec
)) /= N_Access_Definition
4595 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
4598 Formal_Type
:= Access_Definition
4599 (Related_Nod
, Parameter_Type
(Param_Spec
));
4602 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
4611 end Process_Formals
;
4613 -------------------------
4614 -- Set_Actual_Subtypes --
4615 -------------------------
4617 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
4618 Loc
: constant Source_Ptr
:= Sloc
(N
);
4622 First_Stmt
: Node_Id
:= Empty
;
4623 AS_Needed
: Boolean;
4626 Formal
:= First_Formal
(Subp
);
4627 while Present
(Formal
) loop
4628 T
:= Etype
(Formal
);
4630 -- We never need an actual subtype for a constrained formal.
4632 if Is_Constrained
(T
) then
4635 -- If we have unknown discriminants, then we do not need an
4636 -- actual subtype, or more accurately we cannot figure it out!
4637 -- Note that all class-wide types have unknown discriminants.
4639 elsif Has_Unknown_Discriminants
(T
) then
4642 -- At this stage we have an unconstrained type that may need
4643 -- an actual subtype. For sure the actual subtype is needed
4644 -- if we have an unconstrained array type.
4646 elsif Is_Array_Type
(T
) then
4649 -- The only other case which needs an actual subtype is an
4650 -- unconstrained record type which is an IN parameter (we
4651 -- cannot generate actual subtypes for the OUT or IN OUT case,
4652 -- since an assignment can change the discriminant values.
4653 -- However we exclude the case of initialization procedures,
4654 -- since discriminants are handled very specially in this context,
4655 -- see the section entitled "Handling of Discriminants" in Einfo.
4656 -- We also exclude the case of Discrim_SO_Functions (functions
4657 -- used in front end layout mode for size/offset values), since
4658 -- in such functions only discriminants are referenced, and not
4659 -- only are such subtypes not needed, but they cannot always
4660 -- be generated, because of order of elaboration issues.
4662 elsif Is_Record_Type
(T
)
4663 and then Ekind
(Formal
) = E_In_Parameter
4664 and then Chars
(Formal
) /= Name_uInit
4665 and then not Is_Discrim_SO_Function
(Subp
)
4669 -- All other cases do not need an actual subtype
4675 -- Generate actual subtypes for unconstrained arrays and
4676 -- unconstrained discriminated records.
4679 Decl
:= Build_Actual_Subtype
(T
, Formal
);
4681 if Nkind
(N
) = N_Accept_Statement
then
4682 if Present
(Handled_Statement_Sequence
(N
)) then
4684 First
(Statements
(Handled_Statement_Sequence
(N
)));
4685 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
4686 Mark_Rewrite_Insertion
(Decl
);
4688 -- If the accept statement has no body, there will be
4689 -- no reference to the actuals, so no need to compute
4696 Prepend
(Decl
, Declarations
(N
));
4697 Mark_Rewrite_Insertion
(Decl
);
4702 -- We need to freeze manually the generated type when it is
4703 -- inserted anywhere else than in a declarative part.
4705 if Present
(First_Stmt
) then
4706 Insert_List_Before_And_Analyze
(First_Stmt
,
4707 Freeze_Entity
(Defining_Identifier
(Decl
), Loc
));
4710 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
4713 Next_Formal
(Formal
);
4715 end Set_Actual_Subtypes
;
4717 ---------------------
4718 -- Set_Formal_Mode --
4719 ---------------------
4721 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
4722 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
4725 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
4726 -- since we ensure that corresponding actuals are always valid at the
4727 -- point of the call.
4729 if Out_Present
(Spec
) then
4731 if Ekind
(Scope
(Formal_Id
)) = E_Function
4732 or else Ekind
(Scope
(Formal_Id
)) = E_Generic_Function
4734 Error_Msg_N
("functions can only have IN parameters", Spec
);
4735 Set_Ekind
(Formal_Id
, E_In_Parameter
);
4737 elsif In_Present
(Spec
) then
4738 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
4741 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
4742 Set_Not_Source_Assigned
(Formal_Id
);
4746 Set_Ekind
(Formal_Id
, E_In_Parameter
);
4749 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
4750 Set_Formal_Validity
(Formal_Id
);
4751 end Set_Formal_Mode
;
4753 -------------------------
4754 -- Set_Formal_Validity --
4755 -------------------------
4757 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
4759 -- If in full validity checking mode, then we can assume that
4760 -- an IN or IN OUT parameter is valid (see Exp_Ch5.Expand_Call)
4762 if not Validity_Checks_On
then
4765 elsif Ekind
(Formal_Id
) = E_In_Parameter
4766 and then Validity_Check_In_Params
4768 Set_Is_Known_Valid
(Formal_Id
, True);
4770 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
4771 and then Validity_Check_In_Out_Params
4773 Set_Is_Known_Valid
(Formal_Id
, True);
4775 end Set_Formal_Validity
;
4777 ------------------------
4778 -- Subtype_Conformant --
4779 ------------------------
4781 function Subtype_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4785 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
);
4787 end Subtype_Conformant
;
4789 ---------------------
4790 -- Type_Conformant --
4791 ---------------------
4793 function Type_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4797 Check_Conformance
(New_Id
, Old_Id
, Type_Conformant
, False, Result
);
4799 end Type_Conformant
;
4801 -------------------------------
4802 -- Valid_Operator_Definition --
4803 -------------------------------
4805 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
4808 Id
: constant Name_Id
:= Chars
(Designator
);
4812 F
:= First_Formal
(Designator
);
4814 while Present
(F
) loop
4817 if Present
(Default_Value
(F
)) then
4819 ("default values not allowed for operator parameters",
4826 -- Verify that user-defined operators have proper number of arguments
4827 -- First case of operators which can only be unary
4830 or else Id
= Name_Op_Abs
4834 -- Case of operators which can be unary or binary
4836 elsif Id
= Name_Op_Add
4837 or Id
= Name_Op_Subtract
4839 N_OK
:= (N
in 1 .. 2);
4841 -- All other operators can only be binary
4849 ("incorrect number of arguments for operator", Designator
);
4853 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
4854 and then not Is_Intrinsic_Subprogram
(Designator
)
4857 ("explicit definition of inequality not allowed", Designator
);
4859 end Valid_Operator_Definition
;