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 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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 not Comes_From_Source
(N
)
1061 (Nkind
(Original_Node
(Spec_Decl
)) =
1062 N_Subprogram_Renaming_Declaration
1063 or else (Present
(Corresponding_Body
(Spec_Decl
))
1065 Nkind
(Unit_Declaration_Node
1066 (Corresponding_Body
(Spec_Decl
))) =
1067 N_Subprogram_Renaming_Declaration
))
1073 Fully_Conformant
, True, Conformant
, Body_Id
);
1076 -- If the body is not fully conformant, we have to decide if we
1077 -- should analyze it or not. If it has a really messed up profile
1078 -- then we probably should not analyze it, since we will get too
1079 -- many bogus messages.
1081 -- Our decision is to go ahead in the non-fully conformant case
1082 -- only if it is at least mode conformant with the spec. Note
1083 -- that the call to Check_Fully_Conformant has issued the proper
1084 -- error messages to complain about the lack of conformance.
1087 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
1093 -- Generate references from body formals to spec formals
1094 -- and also set the Spec_Entity fields for all formals. We
1095 -- do not set this reference count as a reference for the
1096 -- purposes of identifying unreferenced formals however.
1098 if Spec_Id
/= Body_Id
then
1104 Fs
:= First_Formal
(Spec_Id
);
1105 Fb
:= First_Formal
(Body_Id
);
1106 while Present
(Fs
) loop
1107 Generate_Reference
(Fs
, Fb
, 'b');
1108 Style
.Check_Identifier
(Fb
, Fs
);
1109 Set_Spec_Entity
(Fb
, Fs
);
1110 Set_Referenced
(Fs
, False);
1117 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1118 Set_Corresponding_Spec
(N
, Spec_Id
);
1119 Install_Formals
(Spec_Id
);
1120 Last_Formal
:= Last_Entity
(Spec_Id
);
1121 New_Scope
(Spec_Id
);
1123 -- Make sure that the subprogram is immediately visible. For
1124 -- child units that have no separate spec this is indispensable.
1125 -- Otherwise it is safe albeit redundant.
1127 Set_Is_Immediately_Visible
(Spec_Id
);
1130 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
1131 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1132 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
1134 -- Case of subprogram body with no previous spec
1138 and then Comes_From_Source
(Body_Id
)
1139 and then not Suppress_Style_Checks
(Body_Id
)
1140 and then not In_Instance
1142 Style
.Body_With_No_Spec
(N
);
1145 New_Overloaded_Entity
(Body_Id
);
1147 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1148 Set_Acts_As_Spec
(N
);
1149 Generate_Definition
(Body_Id
);
1150 Install_Formals
(Body_Id
);
1151 New_Scope
(Body_Id
);
1155 -- If this is the proper body of a stub, we must verify that the stub
1156 -- conforms to the body, and to the previous spec if one was present.
1157 -- we know already that the body conforms to that spec. This test is
1158 -- only required for subprograms that come from source.
1160 if Nkind
(Parent
(N
)) = N_Subunit
1161 and then Comes_From_Source
(N
)
1162 and then not Error_Posted
(Body_Id
)
1165 Conformant
: Boolean := False;
1166 Old_Id
: Entity_Id
:=
1168 (Specification
(Corresponding_Stub
(Parent
(N
))));
1171 if No
(Spec_Id
) then
1172 Check_Fully_Conformant
(Body_Id
, Old_Id
);
1176 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
1178 if not Conformant
then
1180 -- The stub was taken to be a new declaration. Indicate
1181 -- that it lacks a body.
1183 Set_Has_Completion
(Old_Id
, False);
1189 Set_Has_Completion
(Body_Id
);
1190 Check_Eliminated
(Body_Id
);
1192 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1195 elsif Present
(Spec_Id
)
1196 and then Expander_Active
1197 and then (Is_Always_Inlined
(Spec_Id
)
1198 or else (Has_Pragma_Inline
(Spec_Id
)
1200 (Front_End_Inlining
or else No_Run_Time
)))
1202 if Build_Body_To_Inline
(N
, Spec_Id
, Copy_Separate_Tree
(N
)) then
1207 -- Now we can go on to analyze the body
1209 HSS
:= Handled_Statement_Sequence
(N
);
1210 Set_Actual_Subtypes
(N
, Current_Scope
);
1211 Analyze_Declarations
(Declarations
(N
));
1214 Process_End_Label
(HSS
, 't', Current_Scope
);
1216 Check_Subprogram_Order
(N
);
1218 -- If we have a separate spec, then the analysis of the declarations
1219 -- caused the entities in the body to be chained to the spec id, but
1220 -- we want them chained to the body id. Only the formal parameters
1221 -- end up chained to the spec id in this case.
1223 if Present
(Spec_Id
) then
1225 -- If a parent unit is categorized, the context of a subunit
1226 -- must conform to the categorization. Conversely, if a child
1227 -- unit is categorized, the parents themselves must conform.
1229 if Nkind
(Parent
(N
)) = N_Subunit
then
1230 Validate_Categorization_Dependency
(N
, Spec_Id
);
1232 elsif Is_Child_Unit
(Spec_Id
) then
1233 Validate_Categorization_Dependency
1234 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
1237 if Present
(Last_Formal
) then
1239 (Last_Entity
(Body_Id
), Next_Entity
(Last_Formal
));
1240 Set_Next_Entity
(Last_Formal
, Empty
);
1241 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1242 Set_Last_Entity
(Spec_Id
, Last_Formal
);
1245 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
1246 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1247 Set_First_Entity
(Spec_Id
, Empty
);
1248 Set_Last_Entity
(Spec_Id
, Empty
);
1252 -- If function, check return statements
1254 if Nkind
(Body_Spec
) = N_Function_Specification
then
1259 if Present
(Spec_Id
) then
1265 if Return_Present
(Id
) then
1266 Check_Returns
(HSS
, 'F', Missing_Ret
);
1269 Set_Has_Missing_Return
(Id
);
1272 elsif not Is_Machine_Code_Subprogram
(Id
)
1273 and then not Body_Deleted
1275 Error_Msg_N
("missing RETURN statement in function body", N
);
1279 -- If procedure with No_Return, check returns
1281 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
1282 and then Present
(Spec_Id
)
1283 and then No_Return
(Spec_Id
)
1285 Check_Returns
(HSS
, 'P', Missing_Ret
);
1288 -- Don't worry about checking for variables that are never modified
1289 -- if the first statement of the body is a raise statement, since
1290 -- we assume this is some kind of stub. We ignore a label generated
1291 -- by the exception stuff for the purpose of this test.
1294 Stm
: Node_Id
:= First
(Statements
(HSS
));
1297 if Nkind
(Stm
) = N_Label
then
1301 if Nkind
(Original_Node
(Stm
)) = N_Raise_Statement
then
1306 -- Check for variables that are never modified
1312 -- If there is a separate spec, then transfer Not_Source_Assigned
1313 -- flags from out parameters to the corresponding entities in the
1314 -- body. The reason we do that is we want to post error flags on
1315 -- the body entities, not the spec entities.
1317 if Present
(Spec_Id
) then
1318 E1
:= First_Entity
(Spec_Id
);
1320 while Present
(E1
) loop
1321 if Ekind
(E1
) = E_Out_Parameter
then
1322 E2
:= First_Entity
(Body_Id
);
1325 -- If no matching body entity, then we already had
1326 -- a detected error of some kind, so just forget
1327 -- about worrying about these warnings.
1333 exit when Chars
(E1
) = Chars
(E2
);
1337 Set_Not_Source_Assigned
(E2
, Not_Source_Assigned
(E1
));
1344 -- Check references in body unless it was deleted. Note that the
1345 -- check of Body_Deleted here is not just for efficiency, it is
1346 -- necessary to avoid junk warnings on formal parameters.
1348 if not Body_Deleted
then
1349 Check_References
(Body_Id
);
1352 end Analyze_Subprogram_Body
;
1354 ------------------------------------
1355 -- Analyze_Subprogram_Declaration --
1356 ------------------------------------
1358 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
1359 Designator
: constant Entity_Id
:= Analyze_Spec
(Specification
(N
));
1360 Scop
: constant Entity_Id
:= Current_Scope
;
1362 -- Start of processing for Analyze_Subprogram_Declaration
1365 Generate_Definition
(Designator
);
1367 -- Check for RCI unit subprogram declarations against in-lined
1368 -- subprograms and subprograms having access parameter or limited
1369 -- parameter without Read and Write (RM E.2.3(12-13)).
1371 Validate_RCI_Subprogram_Declaration
(N
);
1375 Defining_Entity
(N
),
1376 " Analyze subprogram spec. ");
1378 if Debug_Flag_C
then
1379 Write_Str
("==== Compiling subprogram spec ");
1380 Write_Name
(Chars
(Designator
));
1381 Write_Str
(" from ");
1382 Write_Location
(Sloc
(N
));
1386 New_Overloaded_Entity
(Designator
);
1387 Check_Delayed_Subprogram
(Designator
);
1388 Set_Suppress_Elaboration_Checks
1389 (Designator
, Elaboration_Checks_Suppressed
(Designator
));
1391 if Scop
/= Standard_Standard
1392 and then not Is_Child_Unit
(Designator
)
1394 Set_Is_Pure
(Designator
,
1395 Is_Pure
(Scop
) and then Is_Library_Level_Entity
(Designator
));
1396 Set_Is_Remote_Call_Interface
(
1397 Designator
, Is_Remote_Call_Interface
(Scop
));
1398 Set_Is_Remote_Types
(Designator
, Is_Remote_Types
(Scop
));
1401 -- For a compilation unit, check for library-unit pragmas.
1403 New_Scope
(Designator
);
1404 Set_Categorization_From_Pragmas
(N
);
1405 Validate_Categorization_Dependency
(N
, Designator
);
1409 -- For a compilation unit, set body required. This flag will only be
1410 -- reset if a valid Import or Interface pragma is processed later on.
1412 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1413 Set_Body_Required
(Parent
(N
), True);
1416 Check_Eliminated
(Designator
);
1417 end Analyze_Subprogram_Declaration
;
1419 --------------------------
1420 -- Build_Body_To_Inline --
1421 --------------------------
1423 function Build_Body_To_Inline
1426 Orig_Body
: Node_Id
) return Boolean
1428 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1429 Original_Body
: Node_Id
;
1430 Body_To_Analyze
: Node_Id
;
1431 Max_Size
: constant := 10;
1432 Stat_Count
: Integer := 0;
1434 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
1435 -- Check for declarations that make inlining not worthwhile.
1437 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
1438 -- Check for statements that make inlining not worthwhile: any
1439 -- tasking statement, nested at any level. Keep track of total
1440 -- number of elementary statements, as a measure of acceptable size.
1442 function Has_Pending_Instantiation
return Boolean;
1443 -- If some enclosing body contains instantiations that appear before
1444 -- the corresponding generic body, the enclosing body has a freeze node
1445 -- so that it can be elaborated after the generic itself. This might
1446 -- conflict with subsequent inlinings, so that it is unsafe to try to
1447 -- inline in such a case.
1453 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
);
1454 -- If subprogram has pragma Inline_Always, it is an error if
1455 -- it cannot be inlined. Otherwise, emit a warning.
1457 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
) is
1459 if Is_Always_Inlined
(Subp
) then
1460 Error_Msg_NE
(Msg
(1 .. Msg
'Length - 1), N
, Subp
);
1462 elsif Ineffective_Inline_Warnings
then
1463 Error_Msg_NE
(Msg
, N
, Subp
);
1467 ------------------------------
1468 -- Has_Excluded_Declaration --
1469 ------------------------------
1471 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
1477 while Present
(D
) loop
1478 if Nkind
(D
) = N_Function_Instantiation
1479 or else Nkind
(D
) = N_Protected_Type_Declaration
1480 or else Nkind
(D
) = N_Package_Declaration
1481 or else Nkind
(D
) = N_Package_Instantiation
1482 or else Nkind
(D
) = N_Subprogram_Body
1483 or else Nkind
(D
) = N_Procedure_Instantiation
1484 or else Nkind
(D
) = N_Task_Type_Declaration
1487 ("\declaration prevents front-end inlining of&?", D
);
1496 end Has_Excluded_Declaration
;
1498 ----------------------------
1499 -- Has_Excluded_Statement --
1500 ----------------------------
1502 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
1509 while Present
(S
) loop
1510 Stat_Count
:= Stat_Count
+ 1;
1512 if Nkind
(S
) = N_Abort_Statement
1513 or else Nkind
(S
) = N_Asynchronous_Select
1514 or else Nkind
(S
) = N_Conditional_Entry_Call
1515 or else Nkind
(S
) = N_Delay_Relative_Statement
1516 or else Nkind
(S
) = N_Delay_Until_Statement
1517 or else Nkind
(S
) = N_Selective_Accept
1518 or else Nkind
(S
) = N_Timed_Entry_Call
1521 ("\statement prevents front-end inlining of&?", S
);
1524 elsif Nkind
(S
) = N_Block_Statement
then
1525 if Present
(Declarations
(S
))
1526 and then Has_Excluded_Declaration
(Declarations
(S
))
1530 elsif Present
(Handled_Statement_Sequence
(S
))
1533 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
1535 Has_Excluded_Statement
1536 (Statements
(Handled_Statement_Sequence
(S
))))
1541 elsif Nkind
(S
) = N_Case_Statement
then
1542 E
:= First
(Alternatives
(S
));
1544 while Present
(E
) loop
1545 if Has_Excluded_Statement
(Statements
(E
)) then
1552 elsif Nkind
(S
) = N_If_Statement
then
1553 if Has_Excluded_Statement
(Then_Statements
(S
)) then
1557 if Present
(Elsif_Parts
(S
)) then
1558 E
:= First
(Elsif_Parts
(S
));
1560 while Present
(E
) loop
1561 if Has_Excluded_Statement
(Then_Statements
(E
)) then
1568 if Present
(Else_Statements
(S
))
1569 and then Has_Excluded_Statement
(Else_Statements
(S
))
1574 elsif Nkind
(S
) = N_Loop_Statement
1575 and then Has_Excluded_Statement
(Statements
(S
))
1584 end Has_Excluded_Statement
;
1586 -------------------------------
1587 -- Has_Pending_Instantiation --
1588 -------------------------------
1590 function Has_Pending_Instantiation
return Boolean is
1591 S
: Entity_Id
:= Current_Scope
;
1594 while Present
(S
) loop
1595 if Is_Compilation_Unit
(S
)
1596 or else Is_Child_Unit
(S
)
1599 elsif Ekind
(S
) = E_Package
1600 and then Has_Forward_Instantiation
(S
)
1609 end Has_Pending_Instantiation
;
1611 -- Start of processing for Build_Body_To_Inline
1614 if Nkind
(Decl
) = N_Subprogram_Declaration
1615 and then Present
(Body_To_Inline
(Decl
))
1617 return True; -- Done already.
1619 -- Functions that return unconstrained composite types will require
1620 -- secondary stack handling, and cannot currently be inlined.
1622 elsif Ekind
(Subp
) = E_Function
1623 and then not Is_Scalar_Type
(Etype
(Subp
))
1624 and then not Is_Access_Type
(Etype
(Subp
))
1625 and then not Is_Constrained
(Etype
(Subp
))
1628 ("unconstrained return type prevents front-end inlining of&?", N
);
1632 -- We need to capture references to the formals in order to substitute
1633 -- the actuals at the point of inlining, i.e. instantiation. To treat
1634 -- the formals as globals to the body to inline, we nest it within
1635 -- a dummy parameterless subprogram, declared within the real one.
1637 Original_Body
:= Orig_Body
;
1639 -- Within an instance, the current tree is already the result of
1640 -- a generic copy, and not what we need for subsequent inlining.
1641 -- We create the required body by doing an instantiating copy, to
1642 -- obtain the proper partially analyzed tree.
1645 if No
(Generic_Parent
(Specification
(N
))) then
1648 elsif Is_Child_Unit
(Scope
(Current_Scope
)) then
1651 elsif Scope
(Current_Scope
) = Cunit_Entity
(Main_Unit
) then
1653 -- compiling an instantiation. There is no point in generating
1654 -- bodies to inline, because they will not be used.
1661 (Generic_Parent
(Specification
(N
)), Empty
,
1662 Instantiating
=> True);
1666 Copy_Generic_Node
(Original_Body
, Empty
,
1667 Instantiating
=> False);
1670 Set_Parameter_Specifications
(Specification
(Original_Body
), No_List
);
1671 Set_Defining_Unit_Name
(Specification
(Original_Body
),
1672 Make_Defining_Identifier
(Sloc
(N
), New_Internal_Name
('S')));
1673 Set_Corresponding_Spec
(Original_Body
, Empty
);
1675 if Ekind
(Subp
) = E_Function
then
1676 Set_Subtype_Mark
(Specification
(Original_Body
),
1677 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
1680 if Present
(Declarations
(Orig_Body
))
1681 and then Has_Excluded_Declaration
(Declarations
(Orig_Body
))
1686 if Present
(Handled_Statement_Sequence
(N
)) then
1688 (Present
(Exception_Handlers
(Handled_Statement_Sequence
(N
))))
1690 Cannot_Inline
("handler prevents front-end inlining of&?",
1691 First
(Exception_Handlers
(Handled_Statement_Sequence
(N
))));
1694 Has_Excluded_Statement
1695 (Statements
(Handled_Statement_Sequence
(N
)))
1701 -- We do not inline a subprogram that is too large, unless it is
1702 -- marked Inline_Always. This pragma does not suppress the other
1703 -- checks on inlining (forbidden declarations, handlers, etc).
1705 if Stat_Count
> Max_Size
1706 and then not Is_Always_Inlined
(Subp
)
1708 Cannot_Inline
("body is too large for front-end inlining of&?", N
);
1712 if Has_Pending_Instantiation
then
1714 ("cannot inline& because of forward instance within enclosing body",
1719 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
1721 -- Set return type of function, which is also global and does not need
1724 if Ekind
(Subp
) = E_Function
then
1725 Set_Subtype_Mark
(Specification
(Body_To_Analyze
),
1726 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
1729 if No
(Declarations
(N
)) then
1730 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
1732 Append
(Body_To_Analyze
, Declarations
(N
));
1735 Expander_Mode_Save_And_Set
(False);
1737 Analyze
(Body_To_Analyze
);
1738 New_Scope
(Defining_Entity
(Body_To_Analyze
));
1739 Save_Global_References
(Original_Body
);
1741 Remove
(Body_To_Analyze
);
1743 Expander_Mode_Restore
;
1744 Set_Body_To_Inline
(Decl
, Original_Body
);
1745 Set_Is_Inlined
(Subp
);
1748 end Build_Body_To_Inline
;
1750 -----------------------
1751 -- Check_Conformance --
1752 -----------------------
1754 procedure Check_Conformance
1755 (New_Id
: Entity_Id
;
1757 Ctype
: Conformance_Type
;
1759 Conforms
: out Boolean;
1760 Err_Loc
: Node_Id
:= Empty
;
1761 Get_Inst
: Boolean := False)
1763 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
1764 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
1765 Old_Formal
: Entity_Id
;
1766 New_Formal
: Entity_Id
;
1768 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
1769 -- Post error message for conformance error on given node.
1770 -- Two messages are output. The first points to the previous
1771 -- declaration with a general "no conformance" message.
1772 -- The second is the detailed reason, supplied as Msg. The
1773 -- parameter N provide information for a possible & insertion
1774 -- in the message, and also provides the location for posting
1775 -- the message in the absence of a specified Err_Loc location.
1777 -----------------------
1778 -- Conformance_Error --
1779 -----------------------
1781 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
1788 if No
(Err_Loc
) then
1794 Error_Msg_Sloc
:= Sloc
(Old_Id
);
1797 when Type_Conformant
=>
1799 ("not type conformant with declaration#!", Enode
);
1801 when Mode_Conformant
=>
1803 ("not mode conformant with declaration#!", Enode
);
1805 when Subtype_Conformant
=>
1807 ("not subtype conformant with declaration#!", Enode
);
1809 when Fully_Conformant
=>
1811 ("not fully conformant with declaration#!", Enode
);
1814 Error_Msg_NE
(Msg
, Enode
, N
);
1816 end Conformance_Error
;
1818 -- Start of processing for Check_Conformance
1823 -- We need a special case for operators, since they don't
1824 -- appear explicitly.
1826 if Ctype
= Type_Conformant
then
1827 if Ekind
(New_Id
) = E_Operator
1828 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
1834 -- If both are functions/operators, check return types conform
1836 if Old_Type
/= Standard_Void_Type
1837 and then New_Type
/= Standard_Void_Type
1839 if not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
1840 Conformance_Error
("return type does not match!", New_Id
);
1844 -- If either is a function/operator and the other isn't, error
1846 elsif Old_Type
/= Standard_Void_Type
1847 or else New_Type
/= Standard_Void_Type
1849 Conformance_Error
("functions can only match functions!", New_Id
);
1853 -- In subtype conformant case, conventions must match (RM 6.3.1(16))
1854 -- If this is a renaming as body, refine error message to indicate that
1855 -- the conflict is with the original declaration. If the entity is not
1856 -- frozen, the conventions don't have to match, the one of the renamed
1857 -- entity is inherited.
1859 if Ctype
>= Subtype_Conformant
then
1861 if Convention
(Old_Id
) /= Convention
(New_Id
) then
1863 if not Is_Frozen
(New_Id
) then
1866 elsif Present
(Err_Loc
)
1867 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
1868 and then Present
(Corresponding_Spec
(Err_Loc
))
1870 Error_Msg_Name_1
:= Chars
(New_Id
);
1872 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
1874 Conformance_Error
("prior declaration for% has convention %!");
1877 Conformance_Error
("calling conventions do not match!");
1882 elsif Is_Formal_Subprogram
(Old_Id
)
1883 or else Is_Formal_Subprogram
(New_Id
)
1885 Conformance_Error
("formal subprograms not allowed!");
1890 -- Deal with parameters
1892 -- Note: we use the entity information, rather than going directly
1893 -- to the specification in the tree. This is not only simpler, but
1894 -- absolutely necessary for some cases of conformance tests between
1895 -- operators, where the declaration tree simply does not exist!
1897 Old_Formal
:= First_Formal
(Old_Id
);
1898 New_Formal
:= First_Formal
(New_Id
);
1900 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
1902 -- Types must always match. In the visible part of an instance,
1903 -- usual overloading rules for dispatching operations apply, and
1904 -- we check base types (not the actual subtypes).
1906 if In_Instance_Visible_Part
1907 and then Is_Dispatching_Operation
(New_Id
)
1909 if not Conforming_Types
1910 (Base_Type
(Etype
(Old_Formal
)),
1911 Base_Type
(Etype
(New_Formal
)), Ctype
, Get_Inst
)
1913 Conformance_Error
("type of & does not match!", New_Formal
);
1917 elsif not Conforming_Types
1918 (Etype
(Old_Formal
), Etype
(New_Formal
), Ctype
, Get_Inst
)
1920 Conformance_Error
("type of & does not match!", New_Formal
);
1924 -- For mode conformance, mode must match
1926 if Ctype
>= Mode_Conformant
1927 and then Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
)
1929 Conformance_Error
("mode of & does not match!", New_Formal
);
1933 -- Full conformance checks
1935 if Ctype
= Fully_Conformant
then
1939 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
1940 Conformance_Error
("name & does not match!", New_Formal
);
1943 -- And default expressions for in parameters
1945 elsif Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
1947 NewD
: constant Boolean :=
1948 Present
(Default_Value
(New_Formal
));
1949 OldD
: constant Boolean :=
1950 Present
(Default_Value
(Old_Formal
));
1952 if NewD
or OldD
then
1954 -- The old default value has been analyzed and expanded,
1955 -- because the current full declaration will have frozen
1956 -- everything before. The new default values have not
1957 -- been expanded, so expand now to check conformance.
1961 Analyze_Default_Expression
1962 (Default_Value
(New_Formal
), Etype
(New_Formal
));
1966 if not (NewD
and OldD
)
1967 or else not Fully_Conformant_Expressions
1968 (Default_Value
(Old_Formal
),
1969 Default_Value
(New_Formal
))
1972 ("default expression for & does not match!",
1981 -- A couple of special checks for Ada 83 mode. These checks are
1982 -- skipped if either entity is an operator in package Standard.
1983 -- or if either old or new instance is not from the source program.
1986 and then Sloc
(Old_Id
) > Standard_Location
1987 and then Sloc
(New_Id
) > Standard_Location
1988 and then Comes_From_Source
(Old_Id
)
1989 and then Comes_From_Source
(New_Id
)
1992 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
1993 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
1996 -- Explicit IN must be present or absent in both cases. This
1997 -- test is required only in the full conformance case.
1999 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
2000 and then Ctype
= Fully_Conformant
2003 ("(Ada 83) IN must appear in both declarations",
2008 -- Grouping (use of comma in param lists) must be the same
2009 -- This is where we catch a misconformance like:
2012 -- A : Integer; B : Integer
2014 -- which are represented identically in the tree except
2015 -- for the setting of the flags More_Ids and Prev_Ids.
2017 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
2018 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
2021 ("grouping of & does not match!", New_Formal
);
2027 Next_Formal
(Old_Formal
);
2028 Next_Formal
(New_Formal
);
2031 if Present
(Old_Formal
) then
2032 Conformance_Error
("too few parameters!");
2035 elsif Present
(New_Formal
) then
2036 Conformance_Error
("too many parameters!", New_Formal
);
2040 end Check_Conformance
;
2042 ------------------------------
2043 -- Check_Delayed_Subprogram --
2044 ------------------------------
2046 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
2049 procedure Possible_Freeze
(T
: Entity_Id
);
2050 -- T is the type of either a formal parameter or of the return type.
2051 -- If T is not yet frozen and needs a delayed freeze, then the
2052 -- subprogram itself must be delayed.
2054 procedure Possible_Freeze
(T
: Entity_Id
) is
2056 if Has_Delayed_Freeze
(T
)
2057 and then not Is_Frozen
(T
)
2059 Set_Has_Delayed_Freeze
(Designator
);
2061 elsif Is_Access_Type
(T
)
2062 and then Has_Delayed_Freeze
(Designated_Type
(T
))
2063 and then not Is_Frozen
(Designated_Type
(T
))
2065 Set_Has_Delayed_Freeze
(Designator
);
2067 end Possible_Freeze
;
2069 -- Start of processing for Check_Delayed_Subprogram
2072 -- Never need to freeze abstract subprogram
2074 if Is_Abstract
(Designator
) then
2077 -- Need delayed freeze if return type itself needs a delayed
2078 -- freeze and is not yet frozen.
2080 Possible_Freeze
(Etype
(Designator
));
2081 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
2083 -- Need delayed freeze if any of the formal types themselves need
2084 -- a delayed freeze and are not yet frozen.
2086 F
:= First_Formal
(Designator
);
2087 while Present
(F
) loop
2088 Possible_Freeze
(Etype
(F
));
2089 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
2094 -- Mark functions that return by reference. Note that it cannot be
2095 -- done for delayed_freeze subprograms because the underlying
2096 -- returned type may not be known yet (for private types)
2098 if not Has_Delayed_Freeze
(Designator
)
2099 and then Expander_Active
2102 Typ
: constant Entity_Id
:= Etype
(Designator
);
2103 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
2106 if Is_Return_By_Reference_Type
(Typ
) then
2107 Set_Returns_By_Ref
(Designator
);
2109 elsif Present
(Utyp
) and then Controlled_Type
(Utyp
) then
2110 Set_Returns_By_Ref
(Designator
);
2114 end Check_Delayed_Subprogram
;
2116 ------------------------------------
2117 -- Check_Discriminant_Conformance --
2118 ------------------------------------
2120 procedure Check_Discriminant_Conformance
2125 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
2126 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
2127 New_Discr_Id
: Entity_Id
;
2128 New_Discr_Type
: Entity_Id
;
2130 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
2131 -- Post error message for conformance error on given node.
2132 -- Two messages are output. The first points to the previous
2133 -- declaration with a general "no conformance" message.
2134 -- The second is the detailed reason, supplied as Msg. The
2135 -- parameter N provide information for a possible & insertion
2138 -----------------------
2139 -- Conformance_Error --
2140 -----------------------
2142 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
2144 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
2145 Error_Msg_N
("not fully conformant with declaration#!", N
);
2146 Error_Msg_NE
(Msg
, N
, N
);
2147 end Conformance_Error
;
2149 -- Start of processing for Check_Discriminant_Conformance
2152 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
2154 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
2156 -- The subtype mark of the discriminant on the full type
2157 -- has not been analyzed so we do it here. For an access
2158 -- discriminant a new type is created.
2160 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
2162 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
2165 Analyze
(Discriminant_Type
(New_Discr
));
2166 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
2169 if not Conforming_Types
2170 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
2172 Conformance_Error
("type of & does not match!", New_Discr_Id
);
2178 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
2179 Conformance_Error
("name & does not match!", New_Discr_Id
);
2183 -- Default expressions must match
2186 NewD
: constant Boolean :=
2187 Present
(Expression
(New_Discr
));
2188 OldD
: constant Boolean :=
2189 Present
(Expression
(Parent
(Old_Discr
)));
2192 if NewD
or OldD
then
2194 -- The old default value has been analyzed and expanded,
2195 -- because the current full declaration will have frozen
2196 -- everything before. The new default values have not
2197 -- been expanded, so expand now to check conformance.
2200 Analyze_Default_Expression
2201 (Expression
(New_Discr
), New_Discr_Type
);
2204 if not (NewD
and OldD
)
2205 or else not Fully_Conformant_Expressions
2206 (Expression
(Parent
(Old_Discr
)),
2207 Expression
(New_Discr
))
2211 ("default expression for & does not match!",
2218 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
2222 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
2225 -- Grouping (use of comma in param lists) must be the same
2226 -- This is where we catch a misconformance like:
2229 -- A : Integer; B : Integer
2231 -- which are represented identically in the tree except
2232 -- for the setting of the flags More_Ids and Prev_Ids.
2234 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
2235 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
2238 ("grouping of & does not match!", New_Discr_Id
);
2244 Next_Discriminant
(Old_Discr
);
2248 if Present
(Old_Discr
) then
2249 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
2252 elsif Present
(New_Discr
) then
2254 ("too many discriminants!", Defining_Identifier
(New_Discr
));
2257 end Check_Discriminant_Conformance
;
2259 ----------------------------
2260 -- Check_Fully_Conformant --
2261 ----------------------------
2263 procedure Check_Fully_Conformant
2264 (New_Id
: Entity_Id
;
2266 Err_Loc
: Node_Id
:= Empty
)
2272 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
2273 end Check_Fully_Conformant
;
2275 ---------------------------
2276 -- Check_Mode_Conformant --
2277 ---------------------------
2279 procedure Check_Mode_Conformant
2280 (New_Id
: Entity_Id
;
2282 Err_Loc
: Node_Id
:= Empty
;
2283 Get_Inst
: Boolean := False)
2289 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
2290 end Check_Mode_Conformant
;
2296 procedure Check_Returns
2303 procedure Check_Statement_Sequence
(L
: List_Id
);
2304 -- Internal recursive procedure to check a list of statements for proper
2305 -- termination by a return statement (or a transfer of control or a
2306 -- compound statement that is itself internally properly terminated).
2308 ------------------------------
2309 -- Check_Statement_Sequence --
2310 ------------------------------
2312 procedure Check_Statement_Sequence
(L
: List_Id
) is
2316 Raise_Exception_Call
: Boolean;
2317 -- Set True if statement sequence terminated by Raise_Exception call
2318 -- or a Reraise_Occurrence call.
2321 Raise_Exception_Call
:= False;
2323 -- Get last real statement
2325 Last_Stm
:= Last
(L
);
2327 -- Don't count pragmas
2329 while Nkind
(Last_Stm
) = N_Pragma
2331 -- Don't count call to SS_Release (can happen after Raise_Exception)
2334 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
2336 Nkind
(Name
(Last_Stm
)) = N_Identifier
2338 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
2340 -- Don't count exception junk
2343 ((Nkind
(Last_Stm
) = N_Goto_Statement
2344 or else Nkind
(Last_Stm
) = N_Label
2345 or else Nkind
(Last_Stm
) = N_Object_Declaration
)
2346 and then Exception_Junk
(Last_Stm
))
2351 -- Here we have the "real" last statement
2353 Kind
:= Nkind
(Last_Stm
);
2355 -- Transfer of control, OK. Note that in the No_Return procedure
2356 -- case, we already diagnosed any explicit return statements, so
2357 -- we can treat them as OK in this context.
2359 if Is_Transfer
(Last_Stm
) then
2362 -- Check cases of explicit non-indirect procedure calls
2364 elsif Kind
= N_Procedure_Call_Statement
2365 and then Is_Entity_Name
(Name
(Last_Stm
))
2367 -- Check call to Raise_Exception procedure which is treated
2368 -- specially, as is a call to Reraise_Occurrence.
2370 -- We suppress the warning in these cases since it is likely that
2371 -- the programmer really does not expect to deal with the case
2372 -- of Null_Occurrence, and thus would find a warning about a
2373 -- missing return curious, and raising Program_Error does not
2374 -- seem such a bad behavior if this does occur.
2376 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
2378 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
2380 Raise_Exception_Call
:= True;
2382 -- For Raise_Exception call, test first argument, if it is
2383 -- an attribute reference for a 'Identity call, then we know
2384 -- that the call cannot possibly return.
2387 Arg
: constant Node_Id
:=
2388 Original_Node
(First_Actual
(Last_Stm
));
2391 if Nkind
(Arg
) = N_Attribute_Reference
2392 and then Attribute_Name
(Arg
) = Name_Identity
2399 -- If statement, need to look inside if there is an else and check
2400 -- each constituent statement sequence for proper termination.
2402 elsif Kind
= N_If_Statement
2403 and then Present
(Else_Statements
(Last_Stm
))
2405 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
2406 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
2408 if Present
(Elsif_Parts
(Last_Stm
)) then
2410 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
2413 while Present
(Elsif_Part
) loop
2414 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
2422 -- Case statement, check each case for proper termination
2424 elsif Kind
= N_Case_Statement
then
2429 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
2430 while Present
(Case_Alt
) loop
2431 Check_Statement_Sequence
(Statements
(Case_Alt
));
2432 Next_Non_Pragma
(Case_Alt
);
2438 -- Block statement, check its handled sequence of statements
2440 elsif Kind
= N_Block_Statement
then
2446 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
2455 -- Loop statement. If there is an iteration scheme, we can definitely
2456 -- fall out of the loop. Similarly if there is an exit statement, we
2457 -- can fall out. In either case we need a following return.
2459 elsif Kind
= N_Loop_Statement
then
2460 if Present
(Iteration_Scheme
(Last_Stm
))
2461 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
2465 -- A loop with no exit statement or iteration scheme if either
2466 -- an inifite loop, or it has some other exit (raise/return).
2467 -- In either case, no warning is required.
2473 -- Timed entry call, check entry call and delay alternatives
2475 -- Note: in expanded code, the timed entry call has been converted
2476 -- to a set of expanded statements on which the check will work
2477 -- correctly in any case.
2479 elsif Kind
= N_Timed_Entry_Call
then
2481 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
2482 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
2485 -- If statement sequence of entry call alternative is missing,
2486 -- then we can definitely fall through, and we post the error
2487 -- message on the entry call alternative itself.
2489 if No
(Statements
(ECA
)) then
2492 -- If statement sequence of delay alternative is missing, then
2493 -- we can definitely fall through, and we post the error
2494 -- message on the delay alternative itself.
2496 -- Note: if both ECA and DCA are missing the return, then we
2497 -- post only one message, should be enough to fix the bugs.
2498 -- If not we will get a message next time on the DCA when the
2501 elsif No
(Statements
(DCA
)) then
2504 -- Else check both statement sequences
2507 Check_Statement_Sequence
(Statements
(ECA
));
2508 Check_Statement_Sequence
(Statements
(DCA
));
2513 -- Conditional entry call, check entry call and else part
2515 -- Note: in expanded code, the conditional entry call has been
2516 -- converted to a set of expanded statements on which the check
2517 -- will work correctly in any case.
2519 elsif Kind
= N_Conditional_Entry_Call
then
2521 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
2524 -- If statement sequence of entry call alternative is missing,
2525 -- then we can definitely fall through, and we post the error
2526 -- message on the entry call alternative itself.
2528 if No
(Statements
(ECA
)) then
2531 -- Else check statement sequence and else part
2534 Check_Statement_Sequence
(Statements
(ECA
));
2535 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
2541 -- If we fall through, issue appropriate message
2545 if not Raise_Exception_Call
then
2547 ("?RETURN statement missing following this statement!",
2550 ("\?Program_Error may be raised at run time",
2554 -- Note: we set Err even though we have not issued a warning
2555 -- because we still have a case of a missing return. This is
2556 -- an extremely marginal case, probably will never be noticed
2557 -- but we might as well get it right.
2563 ("implied return after this statement not allowed (No_Return)",
2566 end Check_Statement_Sequence
;
2568 -- Start of processing for Check_Returns
2572 Check_Statement_Sequence
(Statements
(HSS
));
2574 if Present
(Exception_Handlers
(HSS
)) then
2575 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
2576 while Present
(Handler
) loop
2577 Check_Statement_Sequence
(Statements
(Handler
));
2578 Next_Non_Pragma
(Handler
);
2583 ----------------------------
2584 -- Check_Subprogram_Order --
2585 ----------------------------
2587 procedure Check_Subprogram_Order
(N
: Node_Id
) is
2589 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
2590 -- This is used to check if S1 > S2 in the sense required by this
2591 -- test, for example nameab < namec, but name2 < name10.
2593 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
2598 -- Remove trailing numeric parts
2601 while S1
(L1
) in '0' .. '9' loop
2606 while S2
(L2
) in '0' .. '9' loop
2610 -- If non-numeric parts non-equal, that's decisive
2612 if S1
(S1
'First .. L1
) < S2
(S2
'First .. L2
) then
2615 elsif S1
(S1
'First .. L1
) > S2
(S2
'First .. L2
) then
2618 -- If non-numeric parts equal, compare suffixed numeric parts. Note
2619 -- that a missing suffix is treated as numeric zero in this test.
2623 while L1
< S1
'Last loop
2625 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
2629 while L2
< S2
'Last loop
2631 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
2636 end Subprogram_Name_Greater
;
2638 -- Start of processing for Check_Subprogram_Order
2641 -- Check body in alpha order if this is option
2643 if Style_Check_Subprogram_Order
2644 and then Nkind
(N
) = N_Subprogram_Body
2645 and then Comes_From_Source
(N
)
2646 and then In_Extended_Main_Source_Unit
(N
)
2650 renames Scope_Stack
.Table
2651 (Scope_Stack
.Last
).Last_Subprogram_Name
;
2653 Body_Id
: constant Entity_Id
:=
2654 Defining_Entity
(Specification
(N
));
2657 Get_Decoded_Name_String
(Chars
(Body_Id
));
2660 if Subprogram_Name_Greater
2661 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
2663 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
2669 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
2672 end Check_Subprogram_Order;
2674 ------------------------------
2675 -- Check_Subtype_Conformant --
2676 ------------------------------
2678 procedure Check_Subtype_Conformant
2679 (New_Id : Entity_Id;
2681 Err_Loc : Node_Id := Empty)
2687 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
2688 end Check_Subtype_Conformant;
2690 ---------------------------
2691 -- Check_Type_Conformant --
2692 ---------------------------
2694 procedure Check_Type_Conformant
2695 (New_Id : Entity_Id;
2697 Err_Loc : Node_Id := Empty)
2703 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
2704 end Check_Type_Conformant;
2706 ----------------------
2707 -- Conforming_Types --
2708 ----------------------
2710 function Conforming_Types
2713 Ctype : Conformance_Type;
2714 Get_Inst : Boolean := False)
2717 Type_1 : Entity_Id := T1;
2718 Type_2 : Entity_Id := T2;
2720 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
2721 -- If neither T1 nor T2 are generic actual types, or if they are
2722 -- in different scopes (e.g. parent and child instances), then verify
2723 -- that the base types are equal. Otherwise T1 and T2 must be
2724 -- on the same subtype chain. The whole purpose of this procedure
2725 -- is to prevent spurious ambiguities in an instantiation that may
2726 -- arise if two distinct generic types are instantiated with the
2729 ----------------------
2730 -- Base_Types_Match --
2731 ----------------------
2733 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
2738 elsif Base_Type (T1) = Base_Type (T2) then
2740 -- The following is too permissive. A more precise test must
2741 -- check that the generic actual is an ancestor subtype of the
2744 return not Is_Generic_Actual_Type (T1)
2745 or else not Is_Generic_Actual_Type (T2)
2746 or else Scope (T1) /= Scope (T2);
2751 end Base_Types_Match;
2754 -- The context is an instance association for a formal
2755 -- access-to-subprogram type; the formal parameter types
2756 -- require mapping because they may denote other formal
2757 -- parameters of the generic unit.
2760 Type_1 := Get_Instance_Of (T1);
2761 Type_2 := Get_Instance_Of (T2);
2764 -- First see if base types match
2766 if Base_Types_Match (Type_1, Type_2) then
2767 return Ctype <= Mode_Conformant
2768 or else Subtypes_Statically_Match (Type_1, Type_2);
2770 elsif Is_Incomplete_Or_Private_Type (Type_1)
2771 and then Present (Full_View (Type_1))
2772 and then Base_Types_Match (Full_View (Type_1), Type_2)
2774 return Ctype <= Mode_Conformant
2775 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
2777 elsif Ekind (Type_2) = E_Incomplete_Type
2778 and then Present (Full_View (Type_2))
2779 and then Base_Types_Match (Type_1, Full_View (Type_2))
2781 return Ctype <= Mode_Conformant
2782 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
2785 -- Test anonymous access type case. For this case, static subtype
2786 -- matching is required for mode conformance (RM 6.3.1(15))
2788 if Ekind (Type_1) = E_Anonymous_Access_Type
2789 and then Ekind (Type_2) = E_Anonymous_Access_Type
2792 Desig_1 : Entity_Id;
2793 Desig_2 : Entity_Id;
2796 Desig_1 := Directly_Designated_Type (Type_1);
2798 -- An access parameter can designate an incomplete type.
2800 if Ekind (Desig_1) = E_Incomplete_Type
2801 and then Present (Full_View (Desig_1))
2803 Desig_1 := Full_View (Desig_1);
2806 Desig_2 := Directly_Designated_Type (Type_2);
2808 if Ekind (Desig_2) = E_Incomplete_Type
2809 and then Present (Full_View (Desig_2))
2811 Desig_2 := Full_View (Desig_2);
2814 -- The context is an instance association for a formal
2815 -- access-to-subprogram type; formal access parameter
2816 -- designated types require mapping because they may
2817 -- denote other formal parameters of the generic unit.
2820 Desig_1 := Get_Instance_Of (Desig_1);
2821 Desig_2 := Get_Instance_Of (Desig_2);
2824 -- It is possible for a Class_Wide_Type to be introduced for
2825 -- an incomplete type, in which case there is a separate class_
2826 -- wide type for the full view. The types conform if their
2827 -- Etypes conform, i.e. one may be the full view of the other.
2828 -- This can only happen in the context of an access parameter,
2829 -- other uses of an incomplete Class_Wide_Type are illegal.
2831 if Ekind (Desig_1) = E_Class_Wide_Type
2832 and then Ekind (Desig_2) = E_Class_Wide_Type
2835 Conforming_Types (Etype (Desig_1), Etype (Desig_2), Ctype);
2837 return Base_Type (Desig_1) = Base_Type (Desig_2)
2838 and then (Ctype = Type_Conformant
2840 Subtypes_Statically_Match (Desig_1, Desig_2));
2844 -- Otherwise definitely no match
2850 end Conforming_Types;
2852 --------------------------
2853 -- Create_Extra_Formals --
2854 --------------------------
2856 procedure Create_Extra_Formals (E : Entity_Id) is
2858 Last_Formal : Entity_Id;
2859 Last_Extra : Entity_Id;
2860 Formal_Type : Entity_Id;
2861 P_Formal : Entity_Id := Empty;
2863 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id;
2864 -- Add an extra formal, associated with the current Formal. The
2865 -- extra formal is added to the list of extra formals, and also
2866 -- returned as the result. These formals are always of mode IN.
2868 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is
2869 EF : constant Entity_Id :=
2870 Make_Defining_Identifier (Sloc (Formal),
2871 Chars => New_External_Name (Chars (Formal), 'F
'));
2874 -- We never generate extra formals if expansion is not active
2875 -- because we don't need them unless we are generating code.
2877 if not Expander_Active then
2881 -- A little optimization. Never generate an extra formal for
2882 -- the _init operand of an initialization procedure, since it
2883 -- could never be used.
2885 if Chars (Formal) = Name_uInit then
2889 Set_Ekind (EF, E_In_Parameter);
2890 Set_Actual_Subtype (EF, Typ);
2891 Set_Etype (EF, Typ);
2892 Set_Scope (EF, Scope (Formal));
2893 Set_Mechanism (EF, Default_Mechanism);
2894 Set_Formal_Validity (EF);
2896 Set_Extra_Formal (Last_Extra, EF);
2899 end Add_Extra_Formal;
2901 -- Start of processing for Create_Extra_Formals
2904 -- If this is a derived subprogram then the subtypes of the
2905 -- parent subprogram's formal parameters will be used to
2906 -- to determine the need for extra formals.
2908 if Is_Overloadable (E) and then Present (Alias (E)) then
2909 P_Formal := First_Formal (Alias (E));
2912 Last_Extra := Empty;
2913 Formal := First_Formal (E);
2914 while Present (Formal) loop
2915 Last_Extra := Formal;
2916 Next_Formal (Formal);
2919 -- If Extra_formals where already created, don't do it again
2920 -- This situation may arise for subprogram types created as part
2921 -- of dispatching calls (see Expand_Dispatch_Call)
2923 if Present (Last_Extra) and then
2924 Present (Extra_Formal (Last_Extra))
2929 Formal := First_Formal (E);
2931 while Present (Formal) loop
2933 -- Create extra formal for supporting the attribute 'Constrained
.
2934 -- The case of a private type view without discriminants also
2935 -- requires the extra formal if the underlying type has defaulted
2938 if Ekind
(Formal
) /= E_In_Parameter
then
2939 if Present
(P_Formal
) then
2940 Formal_Type
:= Etype
(P_Formal
);
2942 Formal_Type
:= Etype
(Formal
);
2945 if not Has_Discriminants
(Formal_Type
)
2946 and then Ekind
(Formal_Type
) in Private_Kind
2947 and then Present
(Underlying_Type
(Formal_Type
))
2949 Formal_Type
:= Underlying_Type
(Formal_Type
);
2952 if Has_Discriminants
(Formal_Type
)
2954 ((not Is_Constrained
(Formal_Type
)
2955 and then not Is_Indefinite_Subtype
(Formal_Type
))
2956 or else Present
(Extra_Formal
(Formal
)))
2958 Set_Extra_Constrained
2959 (Formal
, Add_Extra_Formal
(Standard_Boolean
));
2963 -- Create extra formal for supporting accessibility checking
2965 -- This is suppressed if we specifically suppress accessibility
2966 -- checks for either the subprogram, or the package in which it
2967 -- resides. However, we do not suppress it simply if the scope
2968 -- has accessibility checks suppressed, since this could cause
2969 -- trouble when clients are compiled with a different suppression
2970 -- setting. The explicit checks are safe from this point of view.
2972 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
2974 (Suppress_Accessibility_Checks
(E
)
2976 Suppress_Accessibility_Checks
(Scope
(E
)))
2978 (not Present
(P_Formal
)
2979 or else Present
(Extra_Accessibility
(P_Formal
)))
2981 -- Temporary kludge: for now we avoid creating the extra
2982 -- formal for access parameters of protected operations
2983 -- because of problem with the case of internal protected
2986 if Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Definition
2987 and then Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Body
2989 Set_Extra_Accessibility
2990 (Formal
, Add_Extra_Formal
(Standard_Natural
));
2994 if Present
(P_Formal
) then
2995 Next_Formal
(P_Formal
);
2998 Last_Formal
:= Formal
;
2999 Next_Formal
(Formal
);
3001 end Create_Extra_Formals
;
3003 -----------------------------
3004 -- Enter_Overloaded_Entity --
3005 -----------------------------
3007 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
3008 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
3009 C_E
: Entity_Id
:= Current_Entity
(S
);
3013 Set_Has_Homonym
(E
);
3014 Set_Has_Homonym
(S
);
3017 Set_Is_Immediately_Visible
(S
);
3018 Set_Scope
(S
, Current_Scope
);
3020 -- Chain new entity if front of homonym in current scope, so that
3021 -- homonyms are contiguous.
3026 while Homonym
(C_E
) /= E
loop
3027 C_E
:= Homonym
(C_E
);
3030 Set_Homonym
(C_E
, S
);
3034 Set_Current_Entity
(S
);
3039 Append_Entity
(S
, Current_Scope
);
3040 Set_Public_Status
(S
);
3042 if Debug_Flag_E
then
3043 Write_Str
("New overloaded entity chain: ");
3044 Write_Name
(Chars
(S
));
3047 while Present
(E
) loop
3048 Write_Str
(" "); Write_Int
(Int
(E
));
3055 -- Generate warning for hiding
3058 and then Comes_From_Source
(S
)
3059 and then In_Extended_Main_Source_Unit
(S
)
3066 -- Warn unless genuine overloading
3068 if (not Is_Overloadable
(E
))
3069 or else Subtype_Conformant
(E
, S
)
3071 Error_Msg_Sloc
:= Sloc
(E
);
3072 Error_Msg_N
("declaration of & hides one#?", S
);
3076 end Enter_Overloaded_Entity
;
3078 -----------------------------
3079 -- Find_Corresponding_Spec --
3080 -----------------------------
3082 function Find_Corresponding_Spec
(N
: Node_Id
) return Entity_Id
is
3083 Spec
: constant Node_Id
:= Specification
(N
);
3084 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
3089 E
:= Current_Entity
(Designator
);
3091 while Present
(E
) loop
3093 -- We are looking for a matching spec. It must have the same scope,
3094 -- and the same name, and either be type conformant, or be the case
3095 -- of a library procedure spec and its body (which belong to one
3096 -- another regardless of whether they are type conformant or not).
3098 if Scope
(E
) = Current_Scope
then
3099 if (Current_Scope
= Standard_Standard
3100 or else (Ekind
(E
) = Ekind
(Designator
)
3102 Type_Conformant
(E
, Designator
)))
3104 -- Within an instantiation, we know that spec and body are
3105 -- subtype conformant, because they were subtype conformant
3106 -- in the generic. We choose the subtype-conformant entity
3107 -- here as well, to resolve spurious ambiguities in the
3108 -- instance that were not present in the generic (i.e. when
3109 -- two different types are given the same actual). If we are
3110 -- looking for a spec to match a body, full conformance is
3114 Set_Convention
(Designator
, Convention
(E
));
3116 if Nkind
(N
) = N_Subprogram_Body
3117 and then Present
(Homonym
(E
))
3118 and then not Fully_Conformant
(E
, Designator
)
3122 elsif not Subtype_Conformant
(E
, Designator
) then
3127 if not Has_Completion
(E
) then
3129 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3130 Set_Corresponding_Spec
(N
, E
);
3133 Set_Has_Completion
(E
);
3136 elsif Nkind
(Parent
(N
)) = N_Subunit
then
3138 -- If this is the proper body of a subunit, the completion
3139 -- flag is set when analyzing the stub.
3143 -- If body already exists, this is an error unless the
3144 -- previous declaration is the implicit declaration of
3145 -- a derived subprogram, or this is a spurious overloading
3148 elsif No
(Alias
(E
))
3149 and then not Is_Intrinsic_Subprogram
(E
)
3150 and then not In_Instance
3152 Error_Msg_Sloc
:= Sloc
(E
);
3153 if Is_Imported
(E
) then
3155 ("body not allowed for imported subprogram & declared#",
3158 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
3162 elsif Is_Child_Unit
(E
)
3164 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
3166 Nkind
(Parent
(Unit_Declaration_Node
(Designator
)))
3167 = N_Compilation_Unit
3170 -- Child units cannot be overloaded, so a conformance mismatch
3171 -- between body and a previous spec is an error.
3174 ("body of child unit does not match previous declaration", N
);
3182 -- On exit, we know that no previous declaration of subprogram exists
3185 end Find_Corresponding_Spec
;
3187 ----------------------
3188 -- Fully_Conformant --
3189 ----------------------
3191 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
3195 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
3197 end Fully_Conformant
;
3199 ----------------------------------
3200 -- Fully_Conformant_Expressions --
3201 ----------------------------------
3203 function Fully_Conformant_Expressions
3204 (Given_E1
: Node_Id
;
3208 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
3209 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
3210 -- We always test conformance on original nodes, since it is possible
3211 -- for analysis and/or expansion to make things look as though they
3212 -- conform when they do not, e.g. by converting 1+2 into 3.
3214 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
3215 renames Fully_Conformant_Expressions
;
3217 function FCL
(L1
, L2
: List_Id
) return Boolean;
3218 -- Compare elements of two lists for conformance. Elements have to
3219 -- be conformant, and actuals inserted as default parameters do not
3220 -- match explicit actuals with the same value.
3222 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
3223 -- Compare an operator node with a function call.
3229 function FCL
(L1
, L2
: List_Id
) return Boolean is
3233 if L1
= No_List
then
3239 if L2
= No_List
then
3245 -- Compare two lists, skipping rewrite insertions (we want to
3246 -- compare the original trees, not the expanded versions!)
3249 if Is_Rewrite_Insertion
(N1
) then
3251 elsif Is_Rewrite_Insertion
(N2
) then
3257 elsif not FCE
(N1
, N2
) then
3270 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
3271 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
3276 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
3281 Act
:= First
(Actuals
);
3283 if Nkind
(Op_Node
) in N_Binary_Op
then
3285 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
3292 return Present
(Act
)
3293 and then FCE
(Right_Opnd
(Op_Node
), Act
)
3294 and then No
(Next
(Act
));
3298 -- Start of processing for Fully_Conformant_Expressions
3301 -- Non-conformant if paren count does not match. Note: if some idiot
3302 -- complains that we don't do this right for more than 3 levels of
3303 -- parentheses, they will be treated with the respect they deserve :-)
3305 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
3308 -- If same entities are referenced, then they are conformant
3309 -- even if they have different forms (RM 8.3.1(19-20)).
3311 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
3312 if Present
(Entity
(E1
)) then
3313 return Entity
(E1
) = Entity
(E2
)
3314 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
3315 and then Ekind
(Entity
(E1
)) = E_Discriminant
3316 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
3318 elsif Nkind
(E1
) = N_Expanded_Name
3319 and then Nkind
(E2
) = N_Expanded_Name
3320 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
3321 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
3323 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
3326 -- Identifiers in component associations don't always have
3327 -- entities, but their names must conform.
3329 return Nkind
(E1
) = N_Identifier
3330 and then Nkind
(E2
) = N_Identifier
3331 and then Chars
(E1
) = Chars
(E2
);
3334 elsif Nkind
(E1
) = N_Character_Literal
3335 and then Nkind
(E2
) = N_Expanded_Name
3337 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
3338 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
3340 elsif Nkind
(E2
) = N_Character_Literal
3341 and then Nkind
(E1
) = N_Expanded_Name
3343 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
3344 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
3346 elsif Nkind
(E1
) in N_Op
3347 and then Nkind
(E2
) = N_Function_Call
3349 return FCO
(E1
, E2
);
3351 elsif Nkind
(E2
) in N_Op
3352 and then Nkind
(E1
) = N_Function_Call
3354 return FCO
(E2
, E1
);
3356 -- Otherwise we must have the same syntactic entity
3358 elsif Nkind
(E1
) /= Nkind
(E2
) then
3361 -- At this point, we specialize by node type
3368 FCL
(Expressions
(E1
), Expressions
(E2
))
3369 and then FCL
(Component_Associations
(E1
),
3370 Component_Associations
(E2
));
3373 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
3375 Nkind
(Expression
(E2
)) = N_Qualified_Expression
3377 return FCE
(Expression
(E1
), Expression
(E2
));
3379 -- Check that the subtype marks and any constraints
3384 Indic1
: constant Node_Id
:= Expression
(E1
);
3385 Indic2
: constant Node_Id
:= Expression
(E2
);
3390 if Nkind
(Indic1
) /= N_Subtype_Indication
then
3392 Nkind
(Indic2
) /= N_Subtype_Indication
3393 and then Entity
(Indic1
) = Entity
(Indic2
);
3395 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
3397 Nkind
(Indic1
) /= N_Subtype_Indication
3398 and then Entity
(Indic1
) = Entity
(Indic2
);
3401 if Entity
(Subtype_Mark
(Indic1
)) /=
3402 Entity
(Subtype_Mark
(Indic2
))
3407 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
3408 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
3410 while Present
(Elt1
) and then Present
(Elt2
) loop
3411 if not FCE
(Elt1
, Elt2
) then
3424 when N_Attribute_Reference
=>
3426 Attribute_Name
(E1
) = Attribute_Name
(E2
)
3427 and then FCL
(Expressions
(E1
), Expressions
(E2
));
3431 Entity
(E1
) = Entity
(E2
)
3432 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
3433 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3435 when N_And_Then | N_Or_Else | N_In | N_Not_In
=>
3437 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
3439 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3441 when N_Character_Literal
=>
3443 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
3445 when N_Component_Association
=>
3447 FCL
(Choices
(E1
), Choices
(E2
))
3448 and then FCE
(Expression
(E1
), Expression
(E2
));
3450 when N_Conditional_Expression
=>
3452 FCL
(Expressions
(E1
), Expressions
(E2
));
3454 when N_Explicit_Dereference
=>
3456 FCE
(Prefix
(E1
), Prefix
(E2
));
3458 when N_Extension_Aggregate
=>
3460 FCL
(Expressions
(E1
), Expressions
(E2
))
3461 and then Null_Record_Present
(E1
) =
3462 Null_Record_Present
(E2
)
3463 and then FCL
(Component_Associations
(E1
),
3464 Component_Associations
(E2
));
3466 when N_Function_Call
=>
3468 FCE
(Name
(E1
), Name
(E2
))
3469 and then FCL
(Parameter_Associations
(E1
),
3470 Parameter_Associations
(E2
));
3472 when N_Indexed_Component
=>
3474 FCE
(Prefix
(E1
), Prefix
(E2
))
3475 and then FCL
(Expressions
(E1
), Expressions
(E2
));
3477 when N_Integer_Literal
=>
3478 return (Intval
(E1
) = Intval
(E2
));
3483 when N_Operator_Symbol
=>
3485 Chars
(E1
) = Chars
(E2
);
3487 when N_Others_Choice
=>
3490 when N_Parameter_Association
=>
3493 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
3494 and then FCE
(Explicit_Actual_Parameter
(E1
),
3495 Explicit_Actual_Parameter
(E2
));
3497 when N_Qualified_Expression
=>
3499 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3500 and then FCE
(Expression
(E1
), Expression
(E2
));
3504 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
3505 and then FCE
(High_Bound
(E1
), High_Bound
(E2
));
3507 when N_Real_Literal
=>
3508 return (Realval
(E1
) = Realval
(E2
));
3510 when N_Selected_Component
=>
3512 FCE
(Prefix
(E1
), Prefix
(E2
))
3513 and then FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
3517 FCE
(Prefix
(E1
), Prefix
(E2
))
3518 and then FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
3520 when N_String_Literal
=>
3522 S1
: constant String_Id
:= Strval
(E1
);
3523 S2
: constant String_Id
:= Strval
(E2
);
3524 L1
: constant Nat
:= String_Length
(S1
);
3525 L2
: constant Nat
:= String_Length
(S2
);
3532 for J
in 1 .. L1
loop
3533 if Get_String_Char
(S1
, J
) /=
3534 Get_String_Char
(S2
, J
)
3544 when N_Type_Conversion
=>
3546 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3547 and then FCE
(Expression
(E1
), Expression
(E2
));
3551 Entity
(E1
) = Entity
(E2
)
3552 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
3554 when N_Unchecked_Type_Conversion
=>
3556 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
3557 and then FCE
(Expression
(E1
), Expression
(E2
));
3559 -- All other node types cannot appear in this context. Strictly
3560 -- we should raise a fatal internal error. Instead we just ignore
3561 -- the nodes. This means that if anyone makes a mistake in the
3562 -- expander and mucks an expression tree irretrievably, the
3563 -- result will be a failure to detect a (probably very obscure)
3564 -- case of non-conformance, which is better than bombing on some
3565 -- case where two expressions do in fact conform.
3572 end Fully_Conformant_Expressions
;
3574 --------------------
3575 -- Install_Entity --
3576 --------------------
3578 procedure Install_Entity
(E
: Entity_Id
) is
3579 Prev
: constant Entity_Id
:= Current_Entity
(E
);
3582 Set_Is_Immediately_Visible
(E
);
3583 Set_Current_Entity
(E
);
3584 Set_Homonym
(E
, Prev
);
3587 ---------------------
3588 -- Install_Formals --
3589 ---------------------
3591 procedure Install_Formals
(Id
: Entity_Id
) is
3595 F
:= First_Formal
(Id
);
3597 while Present
(F
) loop
3601 end Install_Formals
;
3603 ---------------------------------
3604 -- Is_Non_Overriding_Operation --
3605 ---------------------------------
3607 function Is_Non_Overriding_Operation
3608 (Prev_E
: Entity_Id
;
3614 G_Typ
: Entity_Id
:= Empty
;
3616 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
3617 -- If F_Type is a derived type associated with a generic actual
3618 -- subtype, then return its Generic_Parent_Type attribute, else
3621 function Types_Correspond
3622 (P_Type
: Entity_Id
;
3625 -- Returns true if and only if the types (or designated types
3626 -- in the case of anonymous access types) are the same or N_Type
3627 -- is derived directly or indirectly from P_Type.
3629 -----------------------------
3630 -- Get_Generic_Parent_Type --
3631 -----------------------------
3633 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
3638 if Is_Derived_Type
(F_Typ
)
3639 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
3641 -- The tree must be traversed to determine the parent
3642 -- subtype in the generic unit, which unfortunately isn't
3643 -- always available via semantic attributes. ???
3644 -- (Note: The use of Original_Node is needed for cases
3645 -- where a full derived type has been rewritten.)
3647 Indic
:= Subtype_Indication
3648 (Type_Definition
(Original_Node
(Parent
(F_Typ
))));
3650 if Nkind
(Indic
) = N_Subtype_Indication
then
3651 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
3653 G_Typ
:= Entity
(Indic
);
3656 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
3657 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
3659 return Generic_Parent_Type
(Parent
(G_Typ
));
3664 end Get_Generic_Parent_Type
;
3666 ----------------------
3667 -- Types_Correspond --
3668 ----------------------
3670 function Types_Correspond
3671 (P_Type
: Entity_Id
;
3675 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
3676 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
3679 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
3680 Prev_Type
:= Designated_Type
(Prev_Type
);
3683 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
3684 New_Type
:= Designated_Type
(New_Type
);
3687 if Prev_Type
= New_Type
then
3690 elsif not Is_Class_Wide_Type
(New_Type
) then
3691 while Etype
(New_Type
) /= New_Type
loop
3692 New_Type
:= Etype
(New_Type
);
3693 if New_Type
= Prev_Type
then
3699 end Types_Correspond
;
3701 -- Start of processing for Is_Non_Overriding_Operation
3704 -- In the case where both operations are implicit derived
3705 -- subprograms then neither overrides the other. This can
3706 -- only occur in certain obscure cases (e.g., derivation
3707 -- from homographs created in a generic instantiation).
3709 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
3712 elsif Ekind
(Current_Scope
) = E_Package
3713 and then Is_Generic_Instance
(Current_Scope
)
3714 and then In_Private_Part
(Current_Scope
)
3715 and then Comes_From_Source
(New_E
)
3717 -- We examine the formals and result subtype of the inherited
3718 -- operation, to determine whether their type is derived from
3719 -- (the instance of) a generic type.
3721 Formal
:= First_Formal
(Prev_E
);
3723 while Present
(Formal
) loop
3724 F_Typ
:= Base_Type
(Etype
(Formal
));
3726 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
3727 F_Typ
:= Designated_Type
(F_Typ
);
3730 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
3732 Next_Formal
(Formal
);
3735 if not Present
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
3736 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
3743 -- If the generic type is a private type, then the original
3744 -- operation was not overriding in the generic, because there was
3745 -- no primitive operation to override.
3747 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
3748 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
3749 N_Formal_Private_Type_Definition
3753 -- The generic parent type is the ancestor of a formal derived
3754 -- type declaration. We need to check whether it has a primitive
3755 -- operation that should be overridden by New_E in the generic.
3759 P_Formal
: Entity_Id
;
3760 N_Formal
: Entity_Id
;
3764 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
3767 while Present
(Prim_Elt
) loop
3768 P_Prim
:= Node
(Prim_Elt
);
3769 if Chars
(P_Prim
) = Chars
(New_E
)
3770 and then Ekind
(P_Prim
) = Ekind
(New_E
)
3772 P_Formal
:= First_Formal
(P_Prim
);
3773 N_Formal
:= First_Formal
(New_E
);
3774 while Present
(P_Formal
) and then Present
(N_Formal
) loop
3775 P_Typ
:= Etype
(P_Formal
);
3776 N_Typ
:= Etype
(N_Formal
);
3778 if not Types_Correspond
(P_Typ
, N_Typ
) then
3782 Next_Entity
(P_Formal
);
3783 Next_Entity
(N_Formal
);
3786 -- Found a matching primitive operation belonging to
3787 -- the formal ancestor type, so the new subprogram
3790 if not Present
(P_Formal
)
3791 and then not Present
(N_Formal
)
3792 and then (Ekind
(New_E
) /= E_Function
3795 (Etype
(P_Prim
), Etype
(New_E
)))
3801 Next_Elmt
(Prim_Elt
);
3804 -- If no match found, then the new subprogram does
3805 -- not override in the generic (nor in the instance).
3813 end Is_Non_Overriding_Operation
;
3815 ------------------------------
3816 -- Make_Inequality_Operator --
3817 ------------------------------
3819 -- S is the defining identifier of an equality operator. We build a
3820 -- subprogram declaration with the right signature. This operation is
3821 -- intrinsic, because it is always expanded as the negation of the
3822 -- call to the equality function.
3824 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
3825 Loc
: constant Source_Ptr
:= Sloc
(S
);
3828 Op_Name
: Entity_Id
;
3834 -- Check that equality was properly defined.
3836 if No
(Next_Formal
(First_Formal
(S
))) then
3840 A
:= Make_Defining_Identifier
(Loc
, Chars
(First_Formal
(S
)));
3841 B
:= Make_Defining_Identifier
(Loc
,
3842 Chars
(Next_Formal
(First_Formal
(S
))));
3844 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
3846 Formals
:= New_List
(
3847 Make_Parameter_Specification
(Loc
,
3848 Defining_Identifier
=> A
,
3850 New_Reference_To
(Etype
(First_Formal
(S
)), Loc
)),
3852 Make_Parameter_Specification
(Loc
,
3853 Defining_Identifier
=> B
,
3855 New_Reference_To
(Etype
(Next_Formal
(First_Formal
(S
))), Loc
)));
3858 Make_Subprogram_Declaration
(Loc
,
3860 Make_Function_Specification
(Loc
,
3861 Defining_Unit_Name
=> Op_Name
,
3862 Parameter_Specifications
=> Formals
,
3863 Subtype_Mark
=> New_Reference_To
(Standard_Boolean
, Loc
)));
3865 -- Insert inequality right after equality if it is explicit or after
3866 -- the derived type when implicit. These entities are created only
3867 -- for visibility purposes, and eventually replaced in the course of
3868 -- expansion, so they do not need to be attached to the tree and seen
3869 -- by the back-end. Keeping them internal also avoids spurious freezing
3870 -- problems. The parent field is set simply to make analysis safe.
3872 if No
(Alias
(S
)) then
3873 Set_Parent
(Decl
, Parent
(Unit_Declaration_Node
(S
)));
3875 Set_Parent
(Decl
, Parent
(Parent
(Etype
(First_Formal
(S
)))));
3878 Mark_Rewrite_Insertion
(Decl
);
3879 Set_Is_Intrinsic_Subprogram
(Op_Name
);
3881 Set_Has_Completion
(Op_Name
);
3882 Set_Corresponding_Equality
(Op_Name
, S
);
3883 Set_Is_Abstract
(Op_Name
, Is_Abstract
(S
));
3885 end Make_Inequality_Operator
;
3887 ----------------------
3888 -- May_Need_Actuals --
3889 ----------------------
3891 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
3896 F
:= First_Formal
(Fun
);
3899 while Present
(F
) loop
3900 if No
(Default_Value
(F
)) then
3908 Set_Needs_No_Actuals
(Fun
, B
);
3909 end May_Need_Actuals
;
3911 ---------------------
3912 -- Mode_Conformant --
3913 ---------------------
3915 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
3919 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
3921 end Mode_Conformant
;
3923 ---------------------------
3924 -- New_Overloaded_Entity --
3925 ---------------------------
3927 procedure New_Overloaded_Entity
3929 Derived_Type
: Entity_Id
:= Empty
)
3931 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
3932 Prev_Vis
: Entity_Id
:= Empty
;
3934 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
3935 -- Check that E is declared in the private part of the current package,
3936 -- or in the package body, where it may hide a previous declaration.
3937 -- We can' use In_Private_Part by itself because this flag is also
3938 -- set when freezing entities, so we must examine the place of the
3939 -- declaration in the tree, and recognize wrapper packages as well.
3941 procedure Maybe_Primitive_Operation
(Overriding
: Boolean := False);
3942 -- If the subprogram being analyzed is a primitive operation of
3943 -- the type of one of its formals, set the corresponding flag.
3945 ----------------------------
3946 -- Is_Private_Declaration --
3947 ----------------------------
3949 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
3950 Priv_Decls
: List_Id
;
3951 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
3954 if Is_Package
(Current_Scope
)
3955 and then In_Private_Part
(Current_Scope
)
3958 Private_Declarations
(
3959 Specification
(Unit_Declaration_Node
(Current_Scope
)));
3961 return In_Package_Body
(Current_Scope
)
3962 or else List_Containing
(Decl
) = Priv_Decls
3963 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
3964 and then not Is_Compilation_Unit
(
3965 Defining_Entity
(Parent
(Decl
)))
3966 and then List_Containing
(Parent
(Parent
(Decl
)))
3971 end Is_Private_Declaration
;
3973 -------------------------------
3974 -- Maybe_Primitive_Operation --
3975 -------------------------------
3977 procedure Maybe_Primitive_Operation
(Overriding
: Boolean := False) is
3982 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
3983 -- Returns true if T is declared in the visible part of
3984 -- the current package scope; otherwise returns false.
3985 -- Assumes that T is declared in a package.
3987 procedure Check_Private_Overriding
(T
: Entity_Id
);
3988 -- Checks that if a primitive abstract subprogram of a visible
3989 -- abstract type is declared in a private part, then it must
3990 -- override an abstract subprogram declared in the visible part.
3991 -- Also checks that if a primitive function with a controlling
3992 -- result is declared in a private part, then it must override
3993 -- a function declared in the visible part.
3995 ------------------------------
3996 -- Check_Private_Overriding --
3997 ------------------------------
3999 procedure Check_Private_Overriding
(T
: Entity_Id
) is
4001 if Ekind
(Current_Scope
) = E_Package
4002 and then In_Private_Part
(Current_Scope
)
4003 and then Visible_Part_Type
(T
)
4004 and then not In_Instance
4007 and then Is_Abstract
(S
)
4008 and then (not Overriding
or else not Is_Abstract
(E
))
4010 Error_Msg_N
("abstract subprograms must be visible "
4011 & "('R'M 3.9.3(10))!", S
);
4013 elsif Ekind
(S
) = E_Function
4014 and then Is_Tagged_Type
(T
)
4015 and then T
= Base_Type
(Etype
(S
))
4016 and then not Overriding
4019 ("private function with tagged result must"
4020 & " override visible-part function", S
);
4022 ("\move subprogram to the visible part"
4023 & " ('R'M 3.9.3(10))", S
);
4026 end Check_Private_Overriding
;
4028 -----------------------
4029 -- Visible_Part_Type --
4030 -----------------------
4032 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
4033 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
4037 -- If the entity is a private type, then it must be
4038 -- declared in a visible part.
4040 if Ekind
(T
) in Private_Kind
then
4044 -- Otherwise, we traverse the visible part looking for its
4045 -- corresponding declaration. We cannot use the declaration
4046 -- node directly because in the private part the entity of a
4047 -- private type is the one in the full view, which does not
4048 -- indicate that it is the completion of something visible.
4050 N
:= First
(Visible_Declarations
(Specification
(P
)));
4051 while Present
(N
) loop
4052 if Nkind
(N
) = N_Full_Type_Declaration
4053 and then Present
(Defining_Identifier
(N
))
4054 and then T
= Defining_Identifier
(N
)
4058 elsif (Nkind
(N
) = N_Private_Type_Declaration
4060 Nkind
(N
) = N_Private_Extension_Declaration
)
4061 and then Present
(Defining_Identifier
(N
))
4062 and then T
= Full_View
(Defining_Identifier
(N
))
4071 end Visible_Part_Type
;
4073 -- Start of processing for Maybe_Primitive_Operation
4076 if not Comes_From_Source
(S
) then
4079 elsif (Ekind
(Current_Scope
) = E_Package
4080 and then not In_Package_Body
(Current_Scope
))
4083 -- For function, check return type
4085 if Ekind
(S
) = E_Function
then
4086 B_Typ
:= Base_Type
(Etype
(S
));
4088 if Scope
(B_Typ
) = Current_Scope
then
4089 Set_Has_Primitive_Operations
(B_Typ
);
4090 Check_Private_Overriding
(B_Typ
);
4094 -- For all subprograms, check formals
4096 Formal
:= First_Formal
(S
);
4097 while Present
(Formal
) loop
4098 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
4099 F_Typ
:= Designated_Type
(Etype
(Formal
));
4101 F_Typ
:= Etype
(Formal
);
4104 B_Typ
:= Base_Type
(F_Typ
);
4106 if Scope
(B_Typ
) = Current_Scope
then
4107 Set_Has_Primitive_Operations
(B_Typ
);
4108 Check_Private_Overriding
(B_Typ
);
4111 Next_Formal
(Formal
);
4114 end Maybe_Primitive_Operation
;
4116 -- Start of processing for New_Overloaded_Entity
4120 Enter_Overloaded_Entity
(S
);
4121 Check_Dispatching_Operation
(S
, Empty
);
4122 Maybe_Primitive_Operation
;
4124 elsif not Is_Overloadable
(E
) then
4126 -- Check for spurious conflict produced by a subprogram that has the
4127 -- same name as that of the enclosing generic package. The conflict
4128 -- occurs within an instance, between the subprogram and the renaming
4129 -- declaration for the package. After the subprogram, the package
4130 -- renaming declaration becomes hidden.
4132 if Ekind
(E
) = E_Package
4133 and then Present
(Renamed_Object
(E
))
4134 and then Renamed_Object
(E
) = Current_Scope
4135 and then Nkind
(Parent
(Renamed_Object
(E
))) =
4136 N_Package_Specification
4137 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
4140 Set_Is_Immediately_Visible
(E
, False);
4141 Enter_Overloaded_Entity
(S
);
4142 Set_Homonym
(S
, Homonym
(E
));
4143 Check_Dispatching_Operation
(S
, Empty
);
4145 -- If the subprogram is implicit it is hidden by the previous
4146 -- declaration. However if it is dispatching, it must appear in
4147 -- the dispatch table anyway, because it can be dispatched to
4148 -- even if it cannot be called directly.
4150 elsif Present
(Alias
(S
))
4151 and then not Comes_From_Source
(S
)
4153 Set_Scope
(S
, Current_Scope
);
4155 if Is_Dispatching_Operation
(Alias
(S
)) then
4156 Check_Dispatching_Operation
(S
, Empty
);
4162 Error_Msg_Sloc
:= Sloc
(E
);
4163 Error_Msg_N
("& conflicts with declaration#", S
);
4165 -- Useful additional warning.
4167 if Is_Generic_Unit
(E
) then
4168 Error_Msg_N
("\previous generic unit cannot be overloaded", S
);
4175 -- E exists and is overloadable. Determine whether S is the body
4176 -- of E, a new overloaded entity with a different signature, or
4177 -- an error altogether.
4179 while Present
(E
) loop
4180 if Scope
(E
) /= Current_Scope
then
4183 elsif Type_Conformant
(E
, S
) then
4185 -- If the old and new entities have the same profile and
4186 -- one is not the body of the other, then this is an error,
4187 -- unless one of them is implicitly declared.
4189 -- There are some cases when both can be implicit, for example
4190 -- when both a literal and a function that overrides it are
4191 -- inherited in a derivation, or when an inhertited operation
4192 -- of a tagged full type overrides the ineherited operation of
4193 -- a private extension. Ada 83 had a special rule for the
4194 -- the literal case. In Ada95, the later implicit operation
4195 -- hides the former, and the literal is always the former.
4196 -- In the odd case where both are derived operations declared
4197 -- at the same point, both operations should be declared,
4198 -- and in that case we bypass the following test and proceed
4199 -- to the next part (this can only occur for certain obscure
4200 -- cases involving homographs in instances and can't occur for
4201 -- dispatching operations ???). Note that the following
4202 -- condition is less than clear. For example, it's not at
4203 -- all clear why there's a test for E_Entry here. ???
4205 if Present
(Alias
(S
))
4206 and then (No
(Alias
(E
))
4207 or else Comes_From_Source
(E
)
4208 or else Is_Dispatching_Operation
(E
))
4210 (Ekind
(E
) = E_Entry
4211 or else Ekind
(E
) /= E_Enumeration_Literal
)
4213 -- When an derived operation is overloaded it may be due
4214 -- to the fact that the full view of a private extension
4215 -- re-inherits. It has to be dealt with.
4217 if Is_Package
(Current_Scope
)
4218 and then In_Private_Part
(Current_Scope
)
4220 Check_Operation_From_Private_View
(S
, E
);
4223 -- In any case the implicit operation remains hidden by
4224 -- the existing declaration.
4228 -- Within an instance, the renaming declarations for
4229 -- actual subprograms may become ambiguous, but they do
4230 -- not hide each other.
4232 elsif Ekind
(E
) /= E_Entry
4233 and then not Comes_From_Source
(E
)
4234 and then not Is_Generic_Instance
(E
)
4235 and then (Present
(Alias
(E
))
4236 or else Is_Intrinsic_Subprogram
(E
))
4237 and then (not In_Instance
4238 or else No
(Parent
(E
))
4239 or else Nkind
(Unit_Declaration_Node
(E
)) /=
4240 N_Subprogram_Renaming_Declaration
)
4242 -- A subprogram child unit is not allowed to override
4243 -- an inherited subprogram (10.1.1(20)).
4245 if Is_Child_Unit
(S
) then
4247 ("child unit overrides inherited subprogram in parent",
4252 if Is_Non_Overriding_Operation
(E
, S
) then
4253 Enter_Overloaded_Entity
(S
);
4254 if not Present
(Derived_Type
)
4255 or else Is_Tagged_Type
(Derived_Type
)
4257 Check_Dispatching_Operation
(S
, Empty
);
4263 -- E is a derived operation or an internal operator which
4264 -- is being overridden. Remove E from further visibility.
4265 -- Furthermore, if E is a dispatching operation, it must be
4266 -- replaced in the list of primitive operations of its type
4267 -- (see Override_Dispatching_Operation).
4273 Prev
:= First_Entity
(Current_Scope
);
4275 while Present
(Prev
)
4276 and then Next_Entity
(Prev
) /= E
4281 -- It is possible for E to be in the current scope and
4282 -- yet not in the entity chain. This can only occur in a
4283 -- generic context where E is an implicit concatenation
4284 -- in the formal part, because in a generic body the
4285 -- entity chain starts with the formals.
4288 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
4290 -- E must be removed both from the entity_list of the
4291 -- current scope, and from the visibility chain
4293 if Debug_Flag_E
then
4294 Write_Str
("Override implicit operation ");
4295 Write_Int
(Int
(E
));
4299 -- If E is a predefined concatenation, it stands for four
4300 -- different operations. As a result, a single explicit
4301 -- declaration does not hide it. In a possible ambiguous
4302 -- situation, Disambiguate chooses the user-defined op,
4303 -- so it is correct to retain the previous internal one.
4305 if Chars
(E
) /= Name_Op_Concat
4306 or else Ekind
(E
) /= E_Operator
4308 -- For nondispatching derived operations that are
4309 -- overridden by a subprogram declared in the private
4310 -- part of a package, we retain the derived subprogram
4311 -- but mark it as not immediately visible. If the
4312 -- derived operation was declared in the visible part
4313 -- then this ensures that it will still be visible
4314 -- outside the package with the proper signature
4315 -- (calls from outside must also be directed to this
4316 -- version rather than the overriding one, unlike the
4317 -- dispatching case). Calls from inside the package
4318 -- will still resolve to the overriding subprogram
4319 -- since the derived one is marked as not visible
4320 -- within the package.
4322 -- If the private operation is dispatching, we achieve
4323 -- the overriding by keeping the implicit operation
4324 -- but setting its alias to be the overring one. In
4325 -- this fashion the proper body is executed in all
4326 -- cases, but the original signature is used outside
4329 -- If the overriding is not in the private part, we
4330 -- remove the implicit operation altogether.
4332 if Is_Private_Declaration
(S
) then
4334 if not Is_Dispatching_Operation
(E
) then
4335 Set_Is_Immediately_Visible
(E
, False);
4338 -- work done in Override_Dispatching_Operation.
4344 -- Find predecessor of E in Homonym chain.
4346 if E
= Current_Entity
(E
) then
4349 Prev_Vis
:= Current_Entity
(E
);
4350 while Homonym
(Prev_Vis
) /= E
loop
4351 Prev_Vis
:= Homonym
(Prev_Vis
);
4355 if Prev_Vis
/= Empty
then
4357 -- Skip E in the visibility chain
4359 Set_Homonym
(Prev_Vis
, Homonym
(E
));
4362 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
4365 Set_Next_Entity
(Prev
, Next_Entity
(E
));
4367 if No
(Next_Entity
(Prev
)) then
4368 Set_Last_Entity
(Current_Scope
, Prev
);
4374 Enter_Overloaded_Entity
(S
);
4376 if Is_Dispatching_Operation
(E
) then
4377 -- An overriding dispatching subprogram inherits
4378 -- the convention of the overridden subprogram
4381 Set_Convention
(S
, Convention
(E
));
4383 Check_Dispatching_Operation
(S
, E
);
4385 Check_Dispatching_Operation
(S
, Empty
);
4388 Maybe_Primitive_Operation
(Overriding
=> True);
4389 goto Check_Inequality
;
4392 -- Apparent redeclarations in instances can occur when two
4393 -- formal types get the same actual type. The subprograms in
4394 -- in the instance are legal, even if not callable from the
4395 -- outside. Calls from within are disambiguated elsewhere.
4396 -- For dispatching operations in the visible part, the usual
4397 -- rules apply, and operations with the same profile are not
4400 elsif (In_Instance_Visible_Part
4401 and then not Is_Dispatching_Operation
(E
))
4402 or else In_Instance_Not_Visible
4406 -- Here we have a real error (identical profile)
4409 Error_Msg_Sloc
:= Sloc
(E
);
4411 -- Avoid cascaded errors if the entity appears in
4412 -- subsequent calls.
4414 Set_Scope
(S
, Current_Scope
);
4416 Error_Msg_N
("& conflicts with declaration#", S
);
4418 if Is_Generic_Instance
(S
)
4419 and then not Has_Completion
(E
)
4422 ("\instantiation cannot provide body for it", S
);
4436 -- On exit, we know that S is a new entity
4438 Enter_Overloaded_Entity
(S
);
4439 Maybe_Primitive_Operation
;
4441 -- If S is a derived operation for an untagged type then
4442 -- by definition it's not a dispatching operation (even
4443 -- if the parent operation was dispatching), so we don't
4444 -- call Check_Dispatching_Operation in that case.
4446 if not Present
(Derived_Type
)
4447 or else Is_Tagged_Type
(Derived_Type
)
4449 Check_Dispatching_Operation
(S
, Empty
);
4453 -- If this is a user-defined equality operator that is not
4454 -- a derived subprogram, create the corresponding inequality.
4455 -- If the operation is dispatching, the expansion is done
4456 -- elsewhere, and we do not create an explicit inequality
4459 <<Check_Inequality
>>
4460 if Chars
(S
) = Name_Op_Eq
4461 and then Etype
(S
) = Standard_Boolean
4462 and then Present
(Parent
(S
))
4463 and then not Is_Dispatching_Operation
(S
)
4465 Make_Inequality_Operator
(S
);
4468 end New_Overloaded_Entity
;
4470 ---------------------
4471 -- Process_Formals --
4472 ---------------------
4474 procedure Process_Formals
4476 Related_Nod
: Node_Id
)
4478 Param_Spec
: Node_Id
;
4480 Formal_Type
: Entity_Id
;
4484 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
4485 -- Check whether the default has a class-wide type. After analysis
4486 -- the default has the type of the formal, so we must also check
4487 -- explicitly for an access attribute.
4489 ---------------------------
4490 -- Is_Class_Wide_Default --
4491 ---------------------------
4493 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
4495 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
4496 or else (Nkind
(D
) = N_Attribute_Reference
4497 and then Attribute_Name
(D
) = Name_Access
4498 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
4499 end Is_Class_Wide_Default
;
4501 -- Start of processing for Process_Formals
4504 -- In order to prevent premature use of the formals in the same formal
4505 -- part, the Ekind is left undefined until all default expressions are
4506 -- analyzed. The Ekind is established in a separate loop at the end.
4508 Param_Spec
:= First
(T
);
4510 while Present
(Param_Spec
) loop
4512 Formal
:= Defining_Identifier
(Param_Spec
);
4513 Enter_Name
(Formal
);
4515 -- Case of ordinary parameters
4517 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
4518 Find_Type
(Parameter_Type
(Param_Spec
));
4519 Ptype
:= Parameter_Type
(Param_Spec
);
4521 if Ptype
= Error
then
4525 Formal_Type
:= Entity
(Ptype
);
4527 if Ekind
(Formal_Type
) = E_Incomplete_Type
4528 or else (Is_Class_Wide_Type
(Formal_Type
)
4529 and then Ekind
(Root_Type
(Formal_Type
)) =
4532 if Nkind
(Parent
(T
)) /= N_Access_Function_Definition
4533 and then Nkind
(Parent
(T
)) /= N_Access_Procedure_Definition
4535 Error_Msg_N
("invalid use of incomplete type", Param_Spec
);
4538 elsif Ekind
(Formal_Type
) = E_Void
then
4539 Error_Msg_NE
("premature use of&",
4540 Parameter_Type
(Param_Spec
), Formal_Type
);
4543 -- An access formal type
4547 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
4550 Set_Etype
(Formal
, Formal_Type
);
4552 Default
:= Expression
(Param_Spec
);
4554 if Present
(Default
) then
4555 if Out_Present
(Param_Spec
) then
4557 ("default initialization only allowed for IN parameters",
4561 -- Do the special preanalysis of the expression (see section on
4562 -- "Handling of Default Expressions" in the spec of package Sem).
4564 Analyze_Default_Expression
(Default
, Formal_Type
);
4566 -- Check that the designated type of an access parameter's
4567 -- default is not a class-wide type unless the parameter's
4568 -- designated type is also class-wide.
4570 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
4571 and then Is_Class_Wide_Default
(Default
)
4572 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
4575 ("access to class-wide expression not allowed here", Default
);
4583 -- Now set the kind (mode) of each formal
4585 Param_Spec
:= First
(T
);
4587 while Present
(Param_Spec
) loop
4588 Formal
:= Defining_Identifier
(Param_Spec
);
4589 Set_Formal_Mode
(Formal
);
4591 if Ekind
(Formal
) = E_In_Parameter
then
4592 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
4594 if Present
(Expression
(Param_Spec
)) then
4595 Default
:= Expression
(Param_Spec
);
4597 if Is_Scalar_Type
(Etype
(Default
)) then
4599 (Parameter_Type
(Param_Spec
)) /= N_Access_Definition
4601 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
4604 Formal_Type
:= Access_Definition
4605 (Related_Nod
, Parameter_Type
(Param_Spec
));
4608 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
4617 end Process_Formals
;
4619 -------------------------
4620 -- Set_Actual_Subtypes --
4621 -------------------------
4623 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
4624 Loc
: constant Source_Ptr
:= Sloc
(N
);
4628 First_Stmt
: Node_Id
:= Empty
;
4629 AS_Needed
: Boolean;
4632 Formal
:= First_Formal
(Subp
);
4633 while Present
(Formal
) loop
4634 T
:= Etype
(Formal
);
4636 -- We never need an actual subtype for a constrained formal.
4638 if Is_Constrained
(T
) then
4641 -- If we have unknown discriminants, then we do not need an
4642 -- actual subtype, or more accurately we cannot figure it out!
4643 -- Note that all class-wide types have unknown discriminants.
4645 elsif Has_Unknown_Discriminants
(T
) then
4648 -- At this stage we have an unconstrained type that may need
4649 -- an actual subtype. For sure the actual subtype is needed
4650 -- if we have an unconstrained array type.
4652 elsif Is_Array_Type
(T
) then
4655 -- The only other case which needs an actual subtype is an
4656 -- unconstrained record type which is an IN parameter (we
4657 -- cannot generate actual subtypes for the OUT or IN OUT case,
4658 -- since an assignment can change the discriminant values.
4659 -- However we exclude the case of initialization procedures,
4660 -- since discriminants are handled very specially in this context,
4661 -- see the section entitled "Handling of Discriminants" in Einfo.
4662 -- We also exclude the case of Discrim_SO_Functions (functions
4663 -- used in front end layout mode for size/offset values), since
4664 -- in such functions only discriminants are referenced, and not
4665 -- only are such subtypes not needed, but they cannot always
4666 -- be generated, because of order of elaboration issues.
4668 elsif Is_Record_Type
(T
)
4669 and then Ekind
(Formal
) = E_In_Parameter
4670 and then Chars
(Formal
) /= Name_uInit
4671 and then not Is_Discrim_SO_Function
(Subp
)
4675 -- All other cases do not need an actual subtype
4681 -- Generate actual subtypes for unconstrained arrays and
4682 -- unconstrained discriminated records.
4685 Decl
:= Build_Actual_Subtype
(T
, Formal
);
4687 if Nkind
(N
) = N_Accept_Statement
then
4688 if Present
(Handled_Statement_Sequence
(N
)) then
4690 First
(Statements
(Handled_Statement_Sequence
(N
)));
4691 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
4692 Mark_Rewrite_Insertion
(Decl
);
4694 -- If the accept statement has no body, there will be
4695 -- no reference to the actuals, so no need to compute
4702 Prepend
(Decl
, Declarations
(N
));
4703 Mark_Rewrite_Insertion
(Decl
);
4708 -- We need to freeze manually the generated type when it is
4709 -- inserted anywhere else than in a declarative part.
4711 if Present
(First_Stmt
) then
4712 Insert_List_Before_And_Analyze
(First_Stmt
,
4713 Freeze_Entity
(Defining_Identifier
(Decl
), Loc
));
4716 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
4719 Next_Formal
(Formal
);
4721 end Set_Actual_Subtypes
;
4723 ---------------------
4724 -- Set_Formal_Mode --
4725 ---------------------
4727 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
4728 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
4731 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
4732 -- since we ensure that corresponding actuals are always valid at the
4733 -- point of the call.
4735 if Out_Present
(Spec
) then
4737 if Ekind
(Scope
(Formal_Id
)) = E_Function
4738 or else Ekind
(Scope
(Formal_Id
)) = E_Generic_Function
4740 Error_Msg_N
("functions can only have IN parameters", Spec
);
4741 Set_Ekind
(Formal_Id
, E_In_Parameter
);
4743 elsif In_Present
(Spec
) then
4744 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
4747 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
4748 Set_Not_Source_Assigned
(Formal_Id
);
4752 Set_Ekind
(Formal_Id
, E_In_Parameter
);
4755 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
4756 Set_Formal_Validity
(Formal_Id
);
4757 end Set_Formal_Mode
;
4759 -------------------------
4760 -- Set_Formal_Validity --
4761 -------------------------
4763 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
4765 -- If in full validity checking mode, then we can assume that
4766 -- an IN or IN OUT parameter is valid (see Exp_Ch5.Expand_Call)
4768 if not Validity_Checks_On
then
4771 elsif Ekind
(Formal_Id
) = E_In_Parameter
4772 and then Validity_Check_In_Params
4774 Set_Is_Known_Valid
(Formal_Id
, True);
4776 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
4777 and then Validity_Check_In_Out_Params
4779 Set_Is_Known_Valid
(Formal_Id
, True);
4781 end Set_Formal_Validity
;
4783 ------------------------
4784 -- Subtype_Conformant --
4785 ------------------------
4787 function Subtype_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4791 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
);
4793 end Subtype_Conformant
;
4795 ---------------------
4796 -- Type_Conformant --
4797 ---------------------
4799 function Type_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4803 Check_Conformance
(New_Id
, Old_Id
, Type_Conformant
, False, Result
);
4805 end Type_Conformant
;
4807 -------------------------------
4808 -- Valid_Operator_Definition --
4809 -------------------------------
4811 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
4814 Id
: constant Name_Id
:= Chars
(Designator
);
4818 F
:= First_Formal
(Designator
);
4820 while Present
(F
) loop
4823 if Present
(Default_Value
(F
)) then
4825 ("default values not allowed for operator parameters",
4832 -- Verify that user-defined operators have proper number of arguments
4833 -- First case of operators which can only be unary
4836 or else Id
= Name_Op_Abs
4840 -- Case of operators which can be unary or binary
4842 elsif Id
= Name_Op_Add
4843 or Id
= Name_Op_Subtract
4845 N_OK
:= (N
in 1 .. 2);
4847 -- All other operators can only be binary
4855 ("incorrect number of arguments for operator", Designator
);
4859 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
4860 and then not Is_Intrinsic_Subprogram
(Designator
)
4863 ("explicit definition of inequality not allowed", Designator
);
4865 end Valid_Operator_Definition
;