1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Expander
; use Expander
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Fname
; use Fname
;
37 with Freeze
; use Freeze
;
38 with Itypes
; use Itypes
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
45 with Output
; use Output
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch3
; use Sem_Ch3
;
50 with Sem_Ch4
; use Sem_Ch4
;
51 with Sem_Ch5
; use Sem_Ch5
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch10
; use Sem_Ch10
;
54 with Sem_Ch12
; use Sem_Ch12
;
55 with Sem_Disp
; use Sem_Disp
;
56 with Sem_Dist
; use Sem_Dist
;
57 with Sem_Elim
; use Sem_Elim
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Mech
; use Sem_Mech
;
60 with Sem_Prag
; use Sem_Prag
;
61 with Sem_Res
; use Sem_Res
;
62 with Sem_Util
; use Sem_Util
;
63 with Sem_Type
; use Sem_Type
;
64 with Sem_Warn
; use Sem_Warn
;
65 with Sinput
; use Sinput
;
66 with Stand
; use Stand
;
67 with Sinfo
; use Sinfo
;
68 with Sinfo
.CN
; use Sinfo
.CN
;
69 with Snames
; use Snames
;
70 with Stringt
; use Stringt
;
72 with Stylesw
; use Stylesw
;
73 with Tbuild
; use Tbuild
;
74 with Uintp
; use Uintp
;
75 with Urealp
; use Urealp
;
76 with Validsw
; use Validsw
;
78 package body Sem_Ch6
is
80 -- The following flag is used to indicate that two formals in two
81 -- subprograms being checked for conformance differ only in that one is
82 -- an access parameter while the other is of a general access type with
83 -- the same designated type. In this case, if the rest of the signatures
84 -- match, a call to either subprogram may be ambiguous, which is worth
85 -- a warning. The flag is set in Compatible_Types, and the warning emitted
86 -- in New_Overloaded_Entity.
88 May_Hide_Profile
: Boolean := False;
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Analyze_Return_Type
(N
: Node_Id
);
95 -- Subsidiary to Process_Formals: analyze subtype mark in function
96 -- specification, in a context where the formals are visible and hide
99 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
100 -- Analyze a generic subprogram body. N is the body to be analyzed, and
101 -- Gen_Id is the defining entity Id for the corresponding spec.
103 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
);
104 -- If a subprogram has pragma Inline and inlining is active, use generic
105 -- machinery to build an unexpanded body for the subprogram. This body is
106 -- subsequenty used for inline expansions at call sites. If subprogram can
107 -- be inlined (depending on size and nature of local declarations) this
108 -- function returns true. Otherwise subprogram body is treated normally.
109 -- If proper warnings are enabled and the subprogram contains a construct
110 -- that cannot be inlined, the offending construct is flagged accordingly.
112 type Conformance_Type
is
113 (Type_Conformant
, Mode_Conformant
, Subtype_Conformant
, Fully_Conformant
);
114 -- Conformance type used for following call, meaning matches the
115 -- RM definitions of the corresponding terms.
117 procedure Check_Conformance
120 Ctype
: Conformance_Type
;
122 Conforms
: out Boolean;
123 Err_Loc
: Node_Id
:= Empty
;
124 Get_Inst
: Boolean := False;
125 Skip_Controlling_Formals
: Boolean := False);
126 -- Given two entities, this procedure checks that the profiles associated
127 -- with these entities meet the conformance criterion given by the third
128 -- parameter. If they conform, Conforms is set True and control returns
129 -- to the caller. If they do not conform, Conforms is set to False, and
130 -- in addition, if Errmsg is True on the call, proper messages are output
131 -- to complain about the conformance failure. If Err_Loc is non_Empty
132 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
133 -- error messages are placed on the appropriate part of the construct
134 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
135 -- against a formal access-to-subprogram type so Get_Instance_Of must
138 procedure Check_Overriding_Indicator
140 Does_Override
: Boolean);
141 -- Verify the consistency of an overriding_indicator given for subprogram
142 -- declaration, body, renaming, or instantiation. The flag Does_Override
143 -- is set if the scope into which we are introducing the subprogram
144 -- contains a type-conformant subprogram that becomes hidden by the new
147 procedure Check_Subprogram_Order
(N
: Node_Id
);
148 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
149 -- the alpha ordering rule for N if this ordering requirement applicable.
151 procedure Check_Returns
155 Proc
: Entity_Id
:= Empty
);
156 -- Called to check for missing return statements in a function body, or for
157 -- returns present in a procedure body which has No_Return set. L is the
158 -- handled statement sequence for the subprogram body. This procedure
159 -- checks all flow paths to make sure they either have return (Mode = 'F',
160 -- used for functions) or do not have a return (Mode = 'P', used for
161 -- No_Return procedures). The flag Err is set if there are any control
162 -- paths not explicitly terminated by a return in the function case, and is
163 -- True otherwise. Proc is the entity for the procedure case and is used
164 -- in posting the warning message.
166 function Conforming_Types
169 Ctype
: Conformance_Type
;
170 Get_Inst
: Boolean := False) return Boolean;
171 -- Check that two formal parameter types conform, checking both for
172 -- equality of base types, and where required statically matching
173 -- subtypes, depending on the setting of Ctype.
175 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
176 -- This procedure makes S, a new overloaded entity, into the first visible
177 -- entity with that name.
179 procedure Install_Entity
(E
: Entity_Id
);
180 -- Make single entity visible. Used for generic formals as well
182 procedure Install_Formals
(Id
: Entity_Id
);
183 -- On entry to a subprogram body, make the formals visible. Note that
184 -- simply placing the subprogram on the scope stack is not sufficient:
185 -- the formals must become the current entities for their names.
187 function Is_Non_Overriding_Operation
189 New_E
: Entity_Id
) return Boolean;
190 -- Enforce the rule given in 12.3(18): a private operation in an instance
191 -- overrides an inherited operation only if the corresponding operation
192 -- was overriding in the generic. This can happen for primitive operations
193 -- of types derived (in the generic unit) from formal private or formal
196 procedure Make_Inequality_Operator
(S
: Entity_Id
);
197 -- Create the declaration for an inequality operator that is implicitly
198 -- created by a user-defined equality operator that yields a boolean.
200 procedure May_Need_Actuals
(Fun
: Entity_Id
);
201 -- Flag functions that can be called without parameters, i.e. those that
202 -- have no parameters, or those for which defaults exist for all parameters
204 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
);
205 -- If there is a separate spec for a subprogram or generic subprogram, the
206 -- formals of the body are treated as references to the corresponding
207 -- formals of the spec. This reference does not count as an actual use of
208 -- the formal, in order to diagnose formals that are unused in the body.
210 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
211 -- Formal_Id is an formal parameter entity. This procedure deals with
212 -- setting the proper validity status for this entity, which depends
213 -- on the kind of parameter and the validity checking mode.
215 ---------------------------------------------
216 -- Analyze_Abstract_Subprogram_Declaration --
217 ---------------------------------------------
219 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
220 Designator
: constant Entity_Id
:=
221 Analyze_Subprogram_Specification
(Specification
(N
));
222 Scop
: constant Entity_Id
:= Current_Scope
;
225 Generate_Definition
(Designator
);
226 Set_Is_Abstract
(Designator
);
227 New_Overloaded_Entity
(Designator
);
228 Check_Delayed_Subprogram
(Designator
);
230 Set_Categorization_From_Scope
(Designator
, Scop
);
232 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
234 ("abstract subprogram not allowed in protected type", N
);
237 Generate_Reference_To_Formals
(Designator
);
238 end Analyze_Abstract_Subprogram_Declaration
;
240 ----------------------------
241 -- Analyze_Function_Call --
242 ----------------------------
244 procedure Analyze_Function_Call
(N
: Node_Id
) is
245 P
: constant Node_Id
:= Name
(N
);
246 L
: constant List_Id
:= Parameter_Associations
(N
);
252 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
253 -- as B (A, X). If the rewriting is successful, the call has been
254 -- analyzed and we just return.
256 if Nkind
(P
) = N_Selected_Component
257 and then Name
(N
) /= P
258 and then Is_Rewrite_Substitution
(N
)
259 and then Present
(Etype
(N
))
264 -- If error analyzing name, then set Any_Type as result type and return
266 if Etype
(P
) = Any_Type
then
267 Set_Etype
(N
, Any_Type
);
271 -- Otherwise analyze the parameters
275 while Present
(Actual
) loop
277 Check_Parameterless_Call
(Actual
);
283 end Analyze_Function_Call
;
285 -------------------------------------
286 -- Analyze_Generic_Subprogram_Body --
287 -------------------------------------
289 procedure Analyze_Generic_Subprogram_Body
293 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
294 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
300 -- Copy body and disable expansion while analyzing the generic For a
301 -- stub, do not copy the stub (which would load the proper body), this
302 -- will be done when the proper body is analyzed.
304 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
305 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
310 Spec
:= Specification
(N
);
312 -- Within the body of the generic, the subprogram is callable, and
313 -- behaves like the corresponding non-generic unit.
315 Body_Id
:= Defining_Entity
(Spec
);
317 if Kind
= E_Generic_Procedure
318 and then Nkind
(Spec
) /= N_Procedure_Specification
320 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
323 elsif Kind
= E_Generic_Function
324 and then Nkind
(Spec
) /= N_Function_Specification
326 Error_Msg_N
("invalid body for generic function ", Body_Id
);
330 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
332 if Has_Completion
(Gen_Id
)
333 and then Nkind
(Parent
(N
)) /= N_Subunit
335 Error_Msg_N
("duplicate generic body", N
);
338 Set_Has_Completion
(Gen_Id
);
341 if Nkind
(N
) = N_Subprogram_Body_Stub
then
342 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
344 Set_Corresponding_Spec
(N
, Gen_Id
);
347 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
348 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
351 -- Make generic parameters immediately visible in the body. They are
352 -- needed to process the formals declarations. Then make the formals
353 -- visible in a separate step.
359 First_Ent
: Entity_Id
;
362 First_Ent
:= First_Entity
(Gen_Id
);
365 while Present
(E
) and then not Is_Formal
(E
) loop
370 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
372 -- Now generic formals are visible, and the specification can be
373 -- analyzed, for subsequent conformance check.
375 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
377 -- Make formal parameters visible
381 -- E is the first formal parameter, we loop through the formals
382 -- installing them so that they will be visible.
384 Set_First_Entity
(Gen_Id
, E
);
385 while Present
(E
) loop
391 -- Visible generic entity is callable within its own body
393 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
394 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
395 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
396 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
397 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
399 if Nkind
(N
) = N_Subprogram_Body_Stub
then
401 -- No body to analyze, so restore state of generic unit
403 Set_Ekind
(Gen_Id
, Kind
);
404 Set_Ekind
(Body_Id
, Kind
);
406 if Present
(First_Ent
) then
407 Set_First_Entity
(Gen_Id
, First_Ent
);
414 -- If this is a compilation unit, it must be made visible explicitly,
415 -- because the compilation of the declaration, unlike other library
416 -- unit declarations, does not. If it is not a unit, the following
417 -- is redundant but harmless.
419 Set_Is_Immediately_Visible
(Gen_Id
);
420 Reference_Body_Formals
(Gen_Id
, Body_Id
);
422 Set_Actual_Subtypes
(N
, Current_Scope
);
423 Analyze_Declarations
(Declarations
(N
));
425 Analyze
(Handled_Statement_Sequence
(N
));
427 Save_Global_References
(Original_Node
(N
));
429 -- Prior to exiting the scope, include generic formals again (if any
430 -- are present) in the set of local entities.
432 if Present
(First_Ent
) then
433 Set_First_Entity
(Gen_Id
, First_Ent
);
436 Check_References
(Gen_Id
);
439 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
441 Check_Subprogram_Order
(N
);
443 -- Outside of its body, unit is generic again
445 Set_Ekind
(Gen_Id
, Kind
);
446 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
447 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
449 end Analyze_Generic_Subprogram_Body
;
451 -----------------------------
452 -- Analyze_Operator_Symbol --
453 -----------------------------
455 -- An operator symbol such as "+" or "and" may appear in context where the
456 -- literal denotes an entity name, such as "+"(x, y) or in context when it
457 -- is just a string, as in (conjunction = "or"). In these cases the parser
458 -- generates this node, and the semantics does the disambiguation. Other
459 -- such case are actuals in an instantiation, the generic unit in an
460 -- instantiation, and pragma arguments.
462 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
463 Par
: constant Node_Id
:= Parent
(N
);
466 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
467 or else Nkind
(Par
) = N_Function_Instantiation
468 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
469 or else (Nkind
(Par
) = N_Pragma_Argument_Association
470 and then not Is_Pragma_String_Literal
(Par
))
471 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
472 or else (Nkind
(Par
) = N_Attribute_Reference
473 and then Attribute_Name
(Par
) /= Name_Value
)
475 Find_Direct_Name
(N
);
478 Change_Operator_Symbol_To_String_Literal
(N
);
481 end Analyze_Operator_Symbol
;
483 -----------------------------------
484 -- Analyze_Parameter_Association --
485 -----------------------------------
487 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
489 Analyze
(Explicit_Actual_Parameter
(N
));
490 end Analyze_Parameter_Association
;
492 ----------------------------
493 -- Analyze_Procedure_Call --
494 ----------------------------
496 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
497 Loc
: constant Source_Ptr
:= Sloc
(N
);
498 P
: constant Node_Id
:= Name
(N
);
499 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
503 procedure Analyze_Call_And_Resolve
;
504 -- Do Analyze and Resolve calls for procedure call
506 ------------------------------
507 -- Analyze_Call_And_Resolve --
508 ------------------------------
510 procedure Analyze_Call_And_Resolve
is
512 if Nkind
(N
) = N_Procedure_Call_Statement
then
514 Resolve
(N
, Standard_Void_Type
);
518 end Analyze_Call_And_Resolve
;
520 -- Start of processing for Analyze_Procedure_Call
523 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
524 -- a procedure call or an entry call. The prefix may denote an access
525 -- to subprogram type, in which case an implicit dereference applies.
526 -- If the prefix is an indexed component (without implicit defererence)
527 -- then the construct denotes a call to a member of an entire family.
528 -- If the prefix is a simple name, it may still denote a call to a
529 -- parameterless member of an entry family. Resolution of these various
530 -- interpretations is delicate.
534 -- If this is a call of the form Obj.Op, the call may have been
535 -- analyzed and possibly rewritten into a block, in which case
542 -- If error analyzing prefix, then set Any_Type as result and return
544 if Etype
(P
) = Any_Type
then
545 Set_Etype
(N
, Any_Type
);
549 -- Otherwise analyze the parameters
551 if Present
(Actuals
) then
552 Actual
:= First
(Actuals
);
554 while Present
(Actual
) loop
556 Check_Parameterless_Call
(Actual
);
561 -- Special processing for Elab_Spec and Elab_Body calls
563 if Nkind
(P
) = N_Attribute_Reference
564 and then (Attribute_Name
(P
) = Name_Elab_Spec
565 or else Attribute_Name
(P
) = Name_Elab_Body
)
567 if Present
(Actuals
) then
569 ("no parameters allowed for this call", First
(Actuals
));
573 Set_Etype
(N
, Standard_Void_Type
);
576 elsif Is_Entity_Name
(P
)
577 and then Is_Record_Type
(Etype
(Entity
(P
)))
578 and then Remote_AST_I_Dereference
(P
)
582 elsif Is_Entity_Name
(P
)
583 and then Ekind
(Entity
(P
)) /= E_Entry_Family
585 if Is_Access_Type
(Etype
(P
))
586 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
587 and then No
(Actuals
)
588 and then Comes_From_Source
(N
)
590 Error_Msg_N
("missing explicit dereference in call", N
);
593 Analyze_Call_And_Resolve
;
595 -- If the prefix is the simple name of an entry family, this is
596 -- a parameterless call from within the task body itself.
598 elsif Is_Entity_Name
(P
)
599 and then Nkind
(P
) = N_Identifier
600 and then Ekind
(Entity
(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 the
605 -- sole argument is in fact the entry index. Rewrite prefix of node
606 -- accordingly. Source representation is unchanged by this
610 Make_Indexed_Component
(Loc
,
612 Make_Selected_Component
(Loc
,
613 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
614 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
615 Expressions
=> Actuals
);
617 Set_Etype
(New_N
, Standard_Void_Type
);
618 Set_Parameter_Associations
(N
, No_List
);
619 Analyze_Call_And_Resolve
;
621 elsif Nkind
(P
) = N_Explicit_Dereference
then
622 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
623 Analyze_Call_And_Resolve
;
625 Error_Msg_N
("expect access to procedure in call", P
);
628 -- The name can be a selected component or an indexed component that
629 -- yields an access to subprogram. Such a prefix is legal if the call
630 -- has parameter associations.
632 elsif Is_Access_Type
(Etype
(P
))
633 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
635 if Present
(Actuals
) then
636 Analyze_Call_And_Resolve
;
638 Error_Msg_N
("missing explicit dereference in call ", N
);
641 -- If not an access to subprogram, then the prefix must resolve to the
642 -- name of an entry, entry family, or protected operation.
644 -- For the case of a simple entry call, P is a selected component where
645 -- the prefix is the task and the selector name is the entry. A call to
646 -- a protected procedure will have the same syntax. If the protected
647 -- object contains overloaded operations, the entity may appear as a
648 -- function, the context will select the operation whose type is Void.
650 elsif Nkind
(P
) = N_Selected_Component
651 and then (Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
653 Ekind
(Entity
(Selector_Name
(P
))) = E_Procedure
655 Ekind
(Entity
(Selector_Name
(P
))) = E_Function
)
657 Analyze_Call_And_Resolve
;
659 elsif Nkind
(P
) = N_Selected_Component
660 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
661 and then Present
(Actuals
)
662 and then No
(Next
(First
(Actuals
)))
664 -- Can be call to parameterless entry family. What appears to be the
665 -- sole argument is in fact the entry index. Rewrite prefix of node
666 -- accordingly. Source representation is unchanged by this
670 Make_Indexed_Component
(Loc
,
671 Prefix
=> New_Copy
(P
),
672 Expressions
=> Actuals
);
674 Set_Etype
(New_N
, Standard_Void_Type
);
675 Set_Parameter_Associations
(N
, No_List
);
676 Analyze_Call_And_Resolve
;
678 -- For the case of a reference to an element of an entry family, P is
679 -- an indexed component whose prefix is a selected component (task and
680 -- entry family), and whose index is the entry family index.
682 elsif Nkind
(P
) = N_Indexed_Component
683 and then Nkind
(Prefix
(P
)) = N_Selected_Component
684 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
686 Analyze_Call_And_Resolve
;
688 -- If the prefix is the name of an entry family, it is a call from
689 -- within the task body itself.
691 elsif Nkind
(P
) = N_Indexed_Component
692 and then Nkind
(Prefix
(P
)) = N_Identifier
693 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
696 Make_Selected_Component
(Loc
,
697 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
698 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
699 Rewrite
(Prefix
(P
), New_N
);
701 Analyze_Call_And_Resolve
;
703 -- Anything else is an error
706 Error_Msg_N
("invalid procedure or entry call", N
);
708 end Analyze_Procedure_Call
;
710 ------------------------------
711 -- Analyze_Return_Statement --
712 ------------------------------
714 procedure Analyze_Return_Statement
(N
: Node_Id
) is
715 Loc
: constant Source_Ptr
:= Sloc
(N
);
717 Scope_Id
: Entity_Id
;
722 -- Find subprogram or accept statement enclosing the return statement
725 for J
in reverse 0 .. Scope_Stack
.Last
loop
726 Scope_Id
:= Scope_Stack
.Table
(J
).Entity
;
727 exit when Ekind
(Scope_Id
) /= E_Block
and then
728 Ekind
(Scope_Id
) /= E_Loop
;
731 pragma Assert
(Present
(Scope_Id
));
733 Kind
:= Ekind
(Scope_Id
);
734 Expr
:= Expression
(N
);
736 if Kind
/= E_Function
737 and then Kind
/= E_Generic_Function
738 and then Kind
/= E_Procedure
739 and then Kind
/= E_Generic_Procedure
740 and then Kind
/= E_Entry
741 and then Kind
/= E_Entry_Family
743 Error_Msg_N
("illegal context for return statement", N
);
745 elsif Present
(Expr
) then
746 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
747 Set_Return_Present
(Scope_Id
);
748 R_Type
:= Etype
(Scope_Id
);
749 Set_Return_Type
(N
, R_Type
);
750 Analyze_And_Resolve
(Expr
, R_Type
);
752 -- Ada 2005 (AI-318-02): When the result type is an anonymous
753 -- access type, apply an implicit conversion of the expression
754 -- to that type to force appropriate static and run-time
755 -- accessibility checks.
757 if Ada_Version
>= Ada_05
758 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
760 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
761 Analyze_And_Resolve
(Expr
, R_Type
);
764 if (Is_Class_Wide_Type
(Etype
(Expr
))
765 or else Is_Dynamically_Tagged
(Expr
))
766 and then not Is_Class_Wide_Type
(R_Type
)
769 ("dynamically tagged expression not allowed!", Expr
);
772 Apply_Constraint_Check
(Expr
, R_Type
);
774 -- Ada 2005 (AI-318-02): Return-by-reference types have been
775 -- removed and replaced by anonymous access results. This is
776 -- an incompatibility with Ada 95. Not clear whether this
777 -- should be enforced yet or perhaps controllable with a
778 -- special switch. ???
780 -- if Ada_Version >= Ada_05
781 -- and then Is_Limited_Type (R_Type)
782 -- and then Nkind (Expr) /= N_Aggregate
783 -- and then Nkind (Expr) /= N_Extension_Aggregate
784 -- and then Nkind (Expr) /= N_Function_Call
787 -- ("(Ada 2005) illegal operand for limited return", N);
790 -- ??? A real run-time accessibility check is needed in cases
791 -- involving dereferences of access parameters. For now we just
792 -- check the static cases.
794 if Is_Return_By_Reference_Type
(Etype
(Scope_Id
))
795 and then Object_Access_Level
(Expr
)
796 > Subprogram_Access_Level
(Scope_Id
)
799 Make_Raise_Program_Error
(Loc
,
800 Reason
=> PE_Accessibility_Check_Failed
));
804 ("cannot return a local value by reference?", N
);
806 ("\& will be raised at run time?",
807 N
, Standard_Program_Error
);
810 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
811 Error_Msg_N
("procedure cannot return value (use function)", N
);
814 Error_Msg_N
("accept statement cannot return value", N
);
817 -- No expression present
820 if Kind
= E_Function
or Kind
= E_Generic_Function
then
821 Error_Msg_N
("missing expression in return from function", N
);
824 if (Ekind
(Scope_Id
) = E_Procedure
825 or else Ekind
(Scope_Id
) = E_Generic_Procedure
)
826 and then No_Return
(Scope_Id
)
829 ("RETURN statement not allowed (No_Return)", N
);
833 Check_Unreachable_Code
(N
);
834 end Analyze_Return_Statement
;
836 -------------------------
837 -- Analyze_Return_Type --
838 -------------------------
840 procedure Analyze_Return_Type
(N
: Node_Id
) is
841 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
842 Typ
: Entity_Id
:= Empty
;
845 if Result_Definition
(N
) /= Error
then
846 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
847 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
848 Set_Parent
(Typ
, Result_Definition
(N
));
849 Set_Is_Local_Anonymous_Access
(Typ
);
850 Set_Etype
(Designator
, Typ
);
852 -- Ada 2005 (AI-231): Static checks
854 -- Null_Exclusion_Static_Checks needs to be extended to handle
855 -- null exclusion checks for function specifications. ???
857 -- if Null_Exclusion_Present (N) then
858 -- Null_Exclusion_Static_Checks (Param_Spec);
864 Find_Type
(Result_Definition
(N
));
865 Typ
:= Entity
(Result_Definition
(N
));
866 Set_Etype
(Designator
, Typ
);
868 if Ekind
(Typ
) = E_Incomplete_Type
869 or else (Is_Class_Wide_Type
(Typ
)
871 Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
874 ("invalid use of incomplete type", Result_Definition
(N
));
879 Set_Etype
(Designator
, Any_Type
);
881 end Analyze_Return_Type
;
883 -----------------------------
884 -- Analyze_Subprogram_Body --
885 -----------------------------
887 -- This procedure is called for regular subprogram bodies, generic bodies,
888 -- and for subprogram stubs of both kinds. In the case of stubs, only the
889 -- specification matters, and is used to create a proper declaration for
890 -- the subprogram, or to perform conformance checks.
892 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
893 Loc
: constant Source_Ptr
:= Sloc
(N
);
894 Body_Spec
: constant Node_Id
:= Specification
(N
);
895 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
896 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
897 Body_Deleted
: constant Boolean := False;
901 Spec_Decl
: Node_Id
:= Empty
;
902 Last_Formal
: Entity_Id
:= Empty
;
903 Conformant
: Boolean;
904 Missing_Ret
: Boolean;
907 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
908 -- Look ahead to recognize a pragma that may appear after the body.
909 -- If there is a previous spec, check that it appears in the same
910 -- declarative part. If the pragma is Inline_Always, perform inlining
911 -- unconditionally, otherwise only if Front_End_Inlining is requested.
912 -- If the body acts as a spec, and inlining is required, we create a
913 -- subprogram declaration for it, in order to attach the body to inline.
915 procedure Copy_Parameter_List
(Plist
: List_Id
);
916 -- Comment required ???
918 procedure Verify_Overriding_Indicator
;
919 -- If there was a previous spec, the entity has been entered in the
920 -- current scope previously. If the body itself carries an overriding
921 -- indicator, check that it is consistent with the known status of the
924 -------------------------
925 -- Check_Inline_Pragma --
926 -------------------------
928 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
933 if not Expander_Active
then
937 if Is_List_Member
(N
)
938 and then Present
(Next
(N
))
939 and then Nkind
(Next
(N
)) = N_Pragma
943 if Nkind
(Prag
) = N_Pragma
945 (Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline_Always
948 and then Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline
))
951 (Expression
(First
(Pragma_Argument_Associations
(Prag
))))
962 if Present
(Prag
) then
963 if Present
(Spec_Id
) then
964 if List_Containing
(N
) =
965 List_Containing
(Unit_Declaration_Node
(Spec_Id
))
971 -- Create a subprogram declaration, to make treatment uniform
974 Subp
: constant Entity_Id
:=
975 Make_Defining_Identifier
(Loc
, Chars
(Body_Id
));
976 Decl
: constant Node_Id
:=
977 Make_Subprogram_Declaration
(Loc
,
978 Specification
=> New_Copy_Tree
(Specification
(N
)));
980 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
982 if Present
(First_Formal
(Body_Id
)) then
984 Copy_Parameter_List
(Plist
);
985 Set_Parameter_Specifications
986 (Specification
(Decl
), Plist
);
989 Insert_Before
(N
, Decl
);
992 Set_Has_Pragma_Inline
(Subp
);
994 if Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline_Always
then
995 Set_Is_Inlined
(Subp
);
996 Set_Next_Rep_Item
(Prag
, First_Rep_Item
(Subp
));
997 Set_First_Rep_Item
(Subp
, Prag
);
1004 end Check_Inline_Pragma
;
1006 -------------------------
1007 -- Copy_Parameter_List --
1008 -------------------------
1010 procedure Copy_Parameter_List
(Plist
: List_Id
) is
1014 Formal
:= First_Formal
(Body_Id
);
1016 while Present
(Formal
) loop
1018 (Make_Parameter_Specification
(Loc
,
1019 Defining_Identifier
=>
1020 Make_Defining_Identifier
(Sloc
(Formal
),
1021 Chars
=> Chars
(Formal
)),
1022 In_Present
=> In_Present
(Parent
(Formal
)),
1023 Out_Present
=> Out_Present
(Parent
(Formal
)),
1025 New_Reference_To
(Etype
(Formal
), Loc
),
1027 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
1030 Next_Formal
(Formal
);
1032 end Copy_Parameter_List
;
1034 ---------------------------------
1035 -- Verify_Overriding_Indicator --
1036 ---------------------------------
1038 procedure Verify_Overriding_Indicator
is
1040 if Must_Override
(Body_Spec
)
1041 and then not Is_Overriding_Operation
(Spec_Id
)
1044 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
1046 elsif Must_Not_Override
(Body_Spec
)
1047 and then Is_Overriding_Operation
(Spec_Id
)
1050 ("subprogram& overrides inherited operation",
1051 Body_Spec
, Spec_Id
);
1053 end Verify_Overriding_Indicator
;
1055 -- Start of processing for Analyze_Subprogram_Body
1058 if Debug_Flag_C
then
1059 Write_Str
("==== Compiling subprogram body ");
1060 Write_Name
(Chars
(Body_Id
));
1061 Write_Str
(" from ");
1062 Write_Location
(Loc
);
1066 Trace_Scope
(N
, Body_Id
, " Analyze subprogram");
1068 -- Generic subprograms are handled separately. They always have a
1069 -- generic specification. Determine whether current scope has a
1070 -- previous declaration.
1072 -- If the subprogram body is defined within an instance of the same
1073 -- name, the instance appears as a package renaming, and will be hidden
1074 -- within the subprogram.
1076 if Present
(Prev_Id
)
1077 and then not Is_Overloadable
(Prev_Id
)
1078 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
1079 or else Comes_From_Source
(Prev_Id
))
1081 if Is_Generic_Subprogram
(Prev_Id
) then
1083 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1084 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1086 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
1090 -- Previous entity conflicts with subprogram name. Attempting to
1091 -- enter name will post error.
1093 Enter_Name
(Body_Id
);
1097 -- Non-generic case, find the subprogram declaration, if one was seen,
1098 -- or enter new overloaded entity in the current scope. If the
1099 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
1100 -- part of the context of one of its subunits. No need to redo the
1103 elsif Prev_Id
= Body_Id
1104 and then Has_Completion
(Body_Id
)
1109 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
1111 if Nkind
(N
) = N_Subprogram_Body_Stub
1112 or else No
(Corresponding_Spec
(N
))
1114 Spec_Id
:= Find_Corresponding_Spec
(N
);
1116 -- If this is a duplicate body, no point in analyzing it
1118 if Error_Posted
(N
) then
1122 -- A subprogram body should cause freezing of its own declaration,
1123 -- but if there was no previous explicit declaration, then the
1124 -- subprogram will get frozen too late (there may be code within
1125 -- the body that depends on the subprogram having been frozen,
1126 -- such as uses of extra formals), so we force it to be frozen
1127 -- here. Same holds if the body and the spec are compilation
1130 if No
(Spec_Id
) then
1131 Freeze_Before
(N
, Body_Id
);
1133 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1134 Freeze_Before
(N
, Spec_Id
);
1137 Spec_Id
:= Corresponding_Spec
(N
);
1141 -- Do not inline any subprogram that contains nested subprograms, since
1142 -- the backend inlining circuit seems to generate uninitialized
1143 -- references in this case. We know this happens in the case of front
1144 -- end ZCX support, but it also appears it can happen in other cases as
1145 -- well. The backend often rejects attempts to inline in the case of
1146 -- nested procedures anyway, so little if anything is lost by this.
1147 -- Note that this is test is for the benefit of the back-end. There is
1148 -- a separate test for front-end inlining that also rejects nested
1151 -- Do not do this test if errors have been detected, because in some
1152 -- error cases, this code blows up, and we don't need it anyway if
1153 -- there have been errors, since we won't get to the linker anyway.
1155 if Comes_From_Source
(Body_Id
)
1156 and then Serious_Errors_Detected
= 0
1160 P_Ent
:= Scope
(P_Ent
);
1161 exit when No
(P_Ent
) or else P_Ent
= Standard_Standard
;
1163 if Is_Subprogram
(P_Ent
) then
1164 Set_Is_Inlined
(P_Ent
, False);
1166 if Comes_From_Source
(P_Ent
)
1167 and then Has_Pragma_Inline
(P_Ent
)
1170 ("cannot inline& (nested subprogram)?",
1177 Check_Inline_Pragma
(Spec_Id
);
1179 -- Case of fully private operation in the body of the protected type.
1180 -- We must create a declaration for the subprogram, in order to attach
1181 -- the protected subprogram that will be used in internal calls.
1184 and then Comes_From_Source
(N
)
1185 and then Is_Protected_Type
(Current_Scope
)
1194 Formal
:= First_Formal
(Body_Id
);
1196 -- The protected operation always has at least one formal, namely
1197 -- the object itself, but it is only placed in the parameter list
1198 -- if expansion is enabled.
1201 or else Expander_Active
1209 Copy_Parameter_List
(Plist
);
1211 if Nkind
(Body_Spec
) = N_Procedure_Specification
then
1213 Make_Procedure_Specification
(Loc
,
1214 Defining_Unit_Name
=>
1215 Make_Defining_Identifier
(Sloc
(Body_Id
),
1216 Chars
=> Chars
(Body_Id
)),
1217 Parameter_Specifications
=> Plist
);
1220 Make_Function_Specification
(Loc
,
1221 Defining_Unit_Name
=>
1222 Make_Defining_Identifier
(Sloc
(Body_Id
),
1223 Chars
=> Chars
(Body_Id
)),
1224 Parameter_Specifications
=> Plist
,
1225 Result_Definition
=>
1226 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
1230 Make_Subprogram_Declaration
(Loc
,
1231 Specification
=> New_Spec
);
1232 Insert_Before
(N
, Decl
);
1233 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
1235 -- Indicate that the entity comes from source, to ensure that
1236 -- cross-reference information is properly generated. The body
1237 -- itself is rewritten during expansion, and the body entity will
1238 -- not appear in calls to the operation.
1240 Set_Comes_From_Source
(Spec_Id
, True);
1242 Set_Has_Completion
(Spec_Id
);
1243 Set_Convention
(Spec_Id
, Convention_Protected
);
1246 elsif Present
(Spec_Id
) then
1247 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
1248 Verify_Overriding_Indicator
;
1251 -- Place subprogram on scope stack, and make formals visible. If there
1252 -- is a spec, the visible entity remains that of the spec.
1254 if Present
(Spec_Id
) then
1255 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
1257 if Is_Child_Unit
(Spec_Id
) then
1258 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
1262 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1265 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1266 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1268 if Is_Abstract
(Spec_Id
) then
1269 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
1272 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
1273 Set_Has_Completion
(Spec_Id
);
1275 if Is_Protected_Type
(Scope
(Spec_Id
)) then
1276 Set_Privals_Chain
(Spec_Id
, New_Elmt_List
);
1279 -- If this is a body generated for a renaming, do not check for
1280 -- full conformance. The check is redundant, because the spec of
1281 -- the body is a copy of the spec in the renaming declaration,
1282 -- and the test can lead to spurious errors on nested defaults.
1284 if Present
(Spec_Decl
)
1285 and then not Comes_From_Source
(N
)
1287 (Nkind
(Original_Node
(Spec_Decl
)) =
1288 N_Subprogram_Renaming_Declaration
1289 or else (Present
(Corresponding_Body
(Spec_Decl
))
1291 Nkind
(Unit_Declaration_Node
1292 (Corresponding_Body
(Spec_Decl
))) =
1293 N_Subprogram_Renaming_Declaration
))
1299 Fully_Conformant
, True, Conformant
, Body_Id
);
1302 -- If the body is not fully conformant, we have to decide if we
1303 -- should analyze it or not. If it has a really messed up profile
1304 -- then we probably should not analyze it, since we will get too
1305 -- many bogus messages.
1307 -- Our decision is to go ahead in the non-fully conformant case
1308 -- only if it is at least mode conformant with the spec. Note
1309 -- that the call to Check_Fully_Conformant has issued the proper
1310 -- error messages to complain about the lack of conformance.
1313 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
1319 if Spec_Id
/= Body_Id
then
1320 Reference_Body_Formals
(Spec_Id
, Body_Id
);
1323 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1324 Set_Corresponding_Spec
(N
, Spec_Id
);
1326 -- Ada 2005 (AI-345): Restore the correct Etype: here we undo the
1327 -- work done by Analyze_Subprogram_Specification to allow the
1328 -- overriding of task, protected and interface primitives.
1330 if Comes_From_Source
(Spec_Id
)
1331 and then Present
(First_Entity
(Spec_Id
))
1332 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
1333 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
1334 and then Present
(Abstract_Interfaces
1335 (Etype
(First_Entity
(Spec_Id
))))
1336 and then Present
(Corresponding_Concurrent_Type
1337 (Etype
(First_Entity
(Spec_Id
))))
1339 Set_Etype
(First_Entity
(Spec_Id
),
1340 Corresponding_Concurrent_Type
1341 (Etype
(First_Entity
(Spec_Id
))));
1344 -- Ada 2005: A formal that is an access parameter may have a
1345 -- designated type imported through a limited_with clause, while
1346 -- the body has a regular with clause. Update the types of the
1347 -- formals accordingly, so that the non-limited view of each type
1348 -- is available in the body. We have already verified that the
1349 -- declarations are type-conformant.
1351 if Ada_Version
>= Ada_05
then
1357 F_Spec
:= First_Formal
(Spec_Id
);
1358 F_Body
:= First_Formal
(Body_Id
);
1360 while Present
(F_Spec
) loop
1361 if Ekind
(Etype
(F_Spec
)) = E_Anonymous_Access_Type
1363 From_With_Type
(Designated_Type
(Etype
(F_Spec
)))
1365 Set_Etype
(F_Spec
, Etype
(F_Body
));
1368 Next_Formal
(F_Spec
);
1369 Next_Formal
(F_Body
);
1374 -- Now make the formals visible, and place subprogram
1377 Install_Formals
(Spec_Id
);
1378 Last_Formal
:= Last_Entity
(Spec_Id
);
1379 New_Scope
(Spec_Id
);
1381 -- Make sure that the subprogram is immediately visible. For
1382 -- child units that have no separate spec this is indispensable.
1383 -- Otherwise it is safe albeit redundant.
1385 Set_Is_Immediately_Visible
(Spec_Id
);
1388 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
1389 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1390 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
1392 -- Case of subprogram body with no previous spec
1396 and then Comes_From_Source
(Body_Id
)
1397 and then not Suppress_Style_Checks
(Body_Id
)
1398 and then not In_Instance
1400 Style
.Body_With_No_Spec
(N
);
1403 New_Overloaded_Entity
(Body_Id
);
1405 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1406 Set_Acts_As_Spec
(N
);
1407 Generate_Definition
(Body_Id
);
1409 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
1410 Generate_Reference_To_Formals
(Body_Id
);
1411 Install_Formals
(Body_Id
);
1412 New_Scope
(Body_Id
);
1416 -- If this is the proper body of a stub, we must verify that the stub
1417 -- conforms to the body, and to the previous spec if one was present.
1418 -- we know already that the body conforms to that spec. This test is
1419 -- only required for subprograms that come from source.
1421 if Nkind
(Parent
(N
)) = N_Subunit
1422 and then Comes_From_Source
(N
)
1423 and then not Error_Posted
(Body_Id
)
1424 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
1425 N_Subprogram_Body_Stub
1428 Old_Id
: constant Entity_Id
:=
1430 (Specification
(Corresponding_Stub
(Parent
(N
))));
1432 Conformant
: Boolean := False;
1435 if No
(Spec_Id
) then
1436 Check_Fully_Conformant
(Body_Id
, Old_Id
);
1440 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
1442 if not Conformant
then
1444 -- The stub was taken to be a new declaration. Indicate
1445 -- that it lacks a body.
1447 Set_Has_Completion
(Old_Id
, False);
1453 Set_Has_Completion
(Body_Id
);
1454 Check_Eliminated
(Body_Id
);
1456 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1459 elsif Present
(Spec_Id
)
1460 and then Expander_Active
1462 (Is_Always_Inlined
(Spec_Id
)
1463 or else (Has_Pragma_Inline
(Spec_Id
) and Front_End_Inlining
))
1465 Build_Body_To_Inline
(N
, Spec_Id
);
1468 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
1469 -- if its specification we have to install the private withed units.
1471 if Is_Compilation_Unit
(Body_Id
)
1472 and then Scope
(Body_Id
) = Standard_Standard
1474 Install_Private_With_Clauses
(Body_Id
);
1477 -- Now we can go on to analyze the body
1479 HSS
:= Handled_Statement_Sequence
(N
);
1480 Set_Actual_Subtypes
(N
, Current_Scope
);
1481 Analyze_Declarations
(Declarations
(N
));
1484 Process_End_Label
(HSS
, 't', Current_Scope
);
1486 Check_Subprogram_Order
(N
);
1487 Set_Analyzed
(Body_Id
);
1489 -- If we have a separate spec, then the analysis of the declarations
1490 -- caused the entities in the body to be chained to the spec id, but
1491 -- we want them chained to the body id. Only the formal parameters
1492 -- end up chained to the spec id in this case.
1494 if Present
(Spec_Id
) then
1496 -- We must conform to the categorization of our spec
1498 Validate_Categorization_Dependency
(N
, Spec_Id
);
1500 -- And if this is a child unit, the parent units must conform
1502 if Is_Child_Unit
(Spec_Id
) then
1503 Validate_Categorization_Dependency
1504 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
1507 if Present
(Last_Formal
) then
1509 (Last_Entity
(Body_Id
), Next_Entity
(Last_Formal
));
1510 Set_Next_Entity
(Last_Formal
, Empty
);
1511 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1512 Set_Last_Entity
(Spec_Id
, Last_Formal
);
1515 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
1516 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1517 Set_First_Entity
(Spec_Id
, Empty
);
1518 Set_Last_Entity
(Spec_Id
, Empty
);
1522 -- If function, check return statements
1524 if Nkind
(Body_Spec
) = N_Function_Specification
then
1529 if Present
(Spec_Id
) then
1535 if Return_Present
(Id
) then
1536 Check_Returns
(HSS
, 'F', Missing_Ret
);
1539 Set_Has_Missing_Return
(Id
);
1542 elsif not Is_Machine_Code_Subprogram
(Id
)
1543 and then not Body_Deleted
1545 Error_Msg_N
("missing RETURN statement in function body", N
);
1549 -- If procedure with No_Return, check returns
1551 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
1552 and then Present
(Spec_Id
)
1553 and then No_Return
(Spec_Id
)
1555 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
1558 -- Now we are going to check for variables that are never modified in
1559 -- the body of the procedure. We omit these checks if the first
1560 -- statement of the procedure raises an exception. In particular this
1561 -- deals with the common idiom of a stubbed function, which might
1562 -- appear as something like
1564 -- function F (A : Integer) return Some_Type;
1567 -- raise Program_Error;
1571 -- Here the purpose of X is simply to satisfy the (annoying)
1572 -- requirement in Ada that there be at least one return, and we
1573 -- certainly do not want to go posting warnings on X that it is not
1577 Stm
: Node_Id
:= First
(Statements
(HSS
));
1580 -- Skip an initial label (for one thing this occurs when we are in
1581 -- front end ZCX mode, but in any case it is irrelevant).
1583 if Nkind
(Stm
) = N_Label
then
1587 -- Do the test on the original statement before expansion
1590 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
1593 -- If explicit raise statement, return with no checks
1595 if Nkind
(Ostm
) = N_Raise_Statement
then
1598 -- Check for explicit call cases which likely raise an exception
1600 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
1601 if Is_Entity_Name
(Name
(Ostm
)) then
1603 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
1606 -- If the procedure is marked No_Return, then likely it
1607 -- raises an exception, but in any case it is not coming
1608 -- back here, so no need to check beyond the call.
1610 if Ekind
(Ent
) = E_Procedure
1611 and then No_Return
(Ent
)
1615 -- If the procedure name is Raise_Exception, then also
1616 -- assume that it raises an exception. The main target
1617 -- here is Ada.Exceptions.Raise_Exception, but this name
1618 -- is pretty evocative in any context! Note that the
1619 -- procedure in Ada.Exceptions is not marked No_Return
1620 -- because of the annoying case of the null exception Id.
1622 elsif Chars
(Ent
) = Name_Raise_Exception
then
1631 -- Check for variables that are never modified
1637 -- If there is a separate spec, then transfer Never_Set_In_Source
1638 -- flags from out parameters to the corresponding entities in the
1639 -- body. The reason we do that is we want to post error flags on
1640 -- the body entities, not the spec entities.
1642 if Present
(Spec_Id
) then
1643 E1
:= First_Entity
(Spec_Id
);
1645 while Present
(E1
) loop
1646 if Ekind
(E1
) = E_Out_Parameter
then
1647 E2
:= First_Entity
(Body_Id
);
1648 while Present
(E2
) loop
1649 exit when Chars
(E1
) = Chars
(E2
);
1653 if Present
(E2
) then
1654 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
1662 -- Check references in body unless it was deleted. Note that the
1663 -- check of Body_Deleted here is not just for efficiency, it is
1664 -- necessary to avoid junk warnings on formal parameters.
1666 if not Body_Deleted
then
1667 Check_References
(Body_Id
);
1670 end Analyze_Subprogram_Body
;
1672 ------------------------------------
1673 -- Analyze_Subprogram_Declaration --
1674 ------------------------------------
1676 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
1677 Designator
: constant Entity_Id
:=
1678 Analyze_Subprogram_Specification
(Specification
(N
));
1679 Scop
: constant Entity_Id
:= Current_Scope
;
1681 -- Start of processing for Analyze_Subprogram_Declaration
1684 Generate_Definition
(Designator
);
1686 -- Check for RCI unit subprogram declarations against in-lined
1687 -- subprograms and subprograms having access parameter or limited
1688 -- parameter without Read and Write (RM E.2.3(12-13)).
1690 Validate_RCI_Subprogram_Declaration
(N
);
1694 Defining_Entity
(N
),
1695 " Analyze subprogram spec. ");
1697 if Debug_Flag_C
then
1698 Write_Str
("==== Compiling subprogram spec ");
1699 Write_Name
(Chars
(Designator
));
1700 Write_Str
(" from ");
1701 Write_Location
(Sloc
(N
));
1705 New_Overloaded_Entity
(Designator
);
1706 Check_Delayed_Subprogram
(Designator
);
1708 -- What is the following code for, it used to be
1710 -- ??? Set_Suppress_Elaboration_Checks
1711 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
1713 -- The following seems equivalent, but a bit dubious
1715 if Elaboration_Checks_Suppressed
(Designator
) then
1716 Set_Kill_Elaboration_Checks
(Designator
);
1719 if Scop
/= Standard_Standard
1720 and then not Is_Child_Unit
(Designator
)
1722 Set_Categorization_From_Scope
(Designator
, Scop
);
1724 -- For a compilation unit, check for library-unit pragmas
1726 New_Scope
(Designator
);
1727 Set_Categorization_From_Pragmas
(N
);
1728 Validate_Categorization_Dependency
(N
, Designator
);
1732 -- For a compilation unit, set body required. This flag will only be
1733 -- reset if a valid Import or Interface pragma is processed later on.
1735 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1736 Set_Body_Required
(Parent
(N
), True);
1738 if Ada_Version
>= Ada_05
1739 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
1740 and then Null_Present
(Specification
(N
))
1743 ("null procedure cannot be declared at library level", N
);
1747 Generate_Reference_To_Formals
(Designator
);
1748 Check_Eliminated
(Designator
);
1750 -- Ada 2005: if procedure is declared with "is null" qualifier,
1751 -- it requires no body.
1753 if Nkind
(Specification
(N
)) = N_Procedure_Specification
1754 and then Null_Present
(Specification
(N
))
1756 Set_Has_Completion
(Designator
);
1757 Set_Is_Inlined
(Designator
);
1759 end Analyze_Subprogram_Declaration
;
1761 --------------------------------------
1762 -- Analyze_Subprogram_Specification --
1763 --------------------------------------
1765 -- Reminder: N here really is a subprogram specification (not a subprogram
1766 -- declaration). This procedure is called to analyze the specification in
1767 -- both subprogram bodies and subprogram declarations (specs).
1769 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
1770 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1771 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
1773 function Has_Interface_Formals
(T
: List_Id
) return Boolean;
1774 -- Ada 2005 (AI-251): Returns true if some non class-wide interface
1777 ---------------------------
1778 -- Has_Interface_Formals --
1779 ---------------------------
1781 function Has_Interface_Formals
(T
: List_Id
) return Boolean is
1782 Param_Spec
: Node_Id
;
1786 Param_Spec
:= First
(T
);
1788 while Present
(Param_Spec
) loop
1789 Formal
:= Defining_Identifier
(Param_Spec
);
1791 if Is_Class_Wide_Type
(Etype
(Formal
)) then
1794 elsif Is_Interface
(Etype
(Formal
)) then
1802 end Has_Interface_Formals
;
1804 -- Start of processing for Analyze_Subprogram_Specification
1807 Generate_Definition
(Designator
);
1809 if Nkind
(N
) = N_Function_Specification
then
1810 Set_Ekind
(Designator
, E_Function
);
1811 Set_Mechanism
(Designator
, Default_Mechanism
);
1814 Set_Ekind
(Designator
, E_Procedure
);
1815 Set_Etype
(Designator
, Standard_Void_Type
);
1818 -- Introduce new scope for analysis of the formals and of the
1821 Set_Scope
(Designator
, Current_Scope
);
1823 if Present
(Formals
) then
1824 New_Scope
(Designator
);
1825 Process_Formals
(Formals
, N
);
1827 -- Ada 2005 (AI-345): Allow overriding primitives of protected
1828 -- interfaces by means of normal subprograms. For this purpose
1829 -- temporarily use the corresponding record type as the etype
1830 -- of the first formal.
1832 if Ada_Version
>= Ada_05
1833 and then Comes_From_Source
(Designator
)
1834 and then Present
(First_Entity
(Designator
))
1835 and then (Ekind
(Etype
(First_Entity
(Designator
)))
1838 Ekind
(Etype
(First_Entity
(Designator
)))
1840 and then Present
(Corresponding_Record_Type
1841 (Etype
(First_Entity
(Designator
))))
1842 and then Present
(Abstract_Interfaces
1843 (Corresponding_Record_Type
1844 (Etype
(First_Entity
(Designator
)))))
1846 Set_Etype
(First_Entity
(Designator
),
1847 Corresponding_Record_Type
(Etype
(First_Entity
(Designator
))));
1852 elsif Nkind
(N
) = N_Function_Specification
then
1853 Analyze_Return_Type
(N
);
1856 if Nkind
(N
) = N_Function_Specification
then
1857 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
1858 Valid_Operator_Definition
(Designator
);
1861 May_Need_Actuals
(Designator
);
1863 if Is_Abstract
(Etype
(Designator
))
1864 and then Nkind
(Parent
(N
))
1865 /= N_Abstract_Subprogram_Declaration
1866 and then (Nkind
(Parent
(N
)))
1867 /= N_Formal_Abstract_Subprogram_Declaration
1868 and then (Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1869 or else not Is_Entity_Name
(Name
(Parent
(N
)))
1870 or else not Is_Abstract
(Entity
(Name
(Parent
(N
)))))
1873 ("function that returns abstract type must be abstract", N
);
1877 if Ada_Version
>= Ada_05
1878 and then Comes_From_Source
(N
)
1879 and then Nkind
(Parent
(N
)) /= N_Abstract_Subprogram_Declaration
1880 and then (Nkind
(N
) /= N_Procedure_Specification
1882 not Null_Present
(N
))
1883 and then Has_Interface_Formals
(Formals
)
1885 Error_Msg_Name_1
:= Chars
(Defining_Unit_Name
1886 (Specification
(Parent
(N
))));
1888 ("(Ada 2005) interface subprogram % must be abstract or null", N
);
1892 end Analyze_Subprogram_Specification
;
1894 --------------------------
1895 -- Build_Body_To_Inline --
1896 --------------------------
1898 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
) is
1899 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1900 Original_Body
: Node_Id
;
1901 Body_To_Analyze
: Node_Id
;
1902 Max_Size
: constant := 10;
1903 Stat_Count
: Integer := 0;
1905 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
1906 -- Check for declarations that make inlining not worthwhile
1908 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
1909 -- Check for statements that make inlining not worthwhile: any tasking
1910 -- statement, nested at any level. Keep track of total number of
1911 -- elementary statements, as a measure of acceptable size.
1913 function Has_Pending_Instantiation
return Boolean;
1914 -- If some enclosing body contains instantiations that appear before
1915 -- the corresponding generic body, the enclosing body has a freeze node
1916 -- so that it can be elaborated after the generic itself. This might
1917 -- conflict with subsequent inlinings, so that it is unsafe to try to
1918 -- inline in such a case.
1920 function Has_Single_Return
return Boolean;
1921 -- In general we cannot inline functions that return unconstrained
1922 -- type. However, we can handle such functions if all return statements
1923 -- return a local variable that is the only declaration in the body
1924 -- of the function. In that case the call can be replaced by that
1925 -- local variable as is done for other inlined calls.
1927 procedure Remove_Pragmas
;
1928 -- A pragma Unreferenced that mentions a formal parameter has no
1929 -- meaning when the body is inlined and the formals are rewritten.
1930 -- Remove it from body to inline. The analysis of the non-inlined body
1931 -- will handle the pragma properly.
1933 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean;
1934 -- If the body of the subprogram includes a call that returns an
1935 -- unconstrained type, the secondary stack is involved, and it
1936 -- is not worth inlining.
1938 ------------------------------
1939 -- Has_Excluded_Declaration --
1940 ------------------------------
1942 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
1945 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean;
1946 -- Nested subprograms make a given body ineligible for inlining, but
1947 -- we make an exception for instantiations of unchecked conversion.
1948 -- The body has not been analyzed yet, so check the name, and verify
1949 -- that the visible entity with that name is the predefined unit.
1951 -----------------------------
1952 -- Is_Unchecked_Conversion --
1953 -----------------------------
1955 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean is
1956 Id
: constant Node_Id
:= Name
(D
);
1960 if Nkind
(Id
) = N_Identifier
1961 and then Chars
(Id
) = Name_Unchecked_Conversion
1963 Conv
:= Current_Entity
(Id
);
1965 elsif (Nkind
(Id
) = N_Selected_Component
1966 or else Nkind
(Id
) = N_Expanded_Name
)
1967 and then Chars
(Selector_Name
(Id
)) = Name_Unchecked_Conversion
1969 Conv
:= Current_Entity
(Selector_Name
(Id
));
1975 return Present
(Conv
)
1976 and then Is_Predefined_File_Name
1977 (Unit_File_Name
(Get_Source_Unit
(Conv
)))
1978 and then Is_Intrinsic_Subprogram
(Conv
);
1979 end Is_Unchecked_Conversion
;
1981 -- Start of processing for Has_Excluded_Declaration
1986 while Present
(D
) loop
1987 if (Nkind
(D
) = N_Function_Instantiation
1988 and then not Is_Unchecked_Conversion
(D
))
1989 or else Nkind
(D
) = N_Protected_Type_Declaration
1990 or else Nkind
(D
) = N_Package_Declaration
1991 or else Nkind
(D
) = N_Package_Instantiation
1992 or else Nkind
(D
) = N_Subprogram_Body
1993 or else Nkind
(D
) = N_Procedure_Instantiation
1994 or else Nkind
(D
) = N_Task_Type_Declaration
1997 ("cannot inline & (non-allowed declaration)?", D
, Subp
);
2005 end Has_Excluded_Declaration
;
2007 ----------------------------
2008 -- Has_Excluded_Statement --
2009 ----------------------------
2011 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
2018 while Present
(S
) loop
2019 Stat_Count
:= Stat_Count
+ 1;
2021 if Nkind
(S
) = N_Abort_Statement
2022 or else Nkind
(S
) = N_Asynchronous_Select
2023 or else Nkind
(S
) = N_Conditional_Entry_Call
2024 or else Nkind
(S
) = N_Delay_Relative_Statement
2025 or else Nkind
(S
) = N_Delay_Until_Statement
2026 or else Nkind
(S
) = N_Selective_Accept
2027 or else Nkind
(S
) = N_Timed_Entry_Call
2030 ("cannot inline & (non-allowed statement)?", S
, Subp
);
2033 elsif Nkind
(S
) = N_Block_Statement
then
2034 if Present
(Declarations
(S
))
2035 and then Has_Excluded_Declaration
(Declarations
(S
))
2039 elsif Present
(Handled_Statement_Sequence
(S
))
2042 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
2044 Has_Excluded_Statement
2045 (Statements
(Handled_Statement_Sequence
(S
))))
2050 elsif Nkind
(S
) = N_Case_Statement
then
2051 E
:= First
(Alternatives
(S
));
2052 while Present
(E
) loop
2053 if Has_Excluded_Statement
(Statements
(E
)) then
2060 elsif Nkind
(S
) = N_If_Statement
then
2061 if Has_Excluded_Statement
(Then_Statements
(S
)) then
2065 if Present
(Elsif_Parts
(S
)) then
2066 E
:= First
(Elsif_Parts
(S
));
2067 while Present
(E
) loop
2068 if Has_Excluded_Statement
(Then_Statements
(E
)) then
2075 if Present
(Else_Statements
(S
))
2076 and then Has_Excluded_Statement
(Else_Statements
(S
))
2081 elsif Nkind
(S
) = N_Loop_Statement
2082 and then Has_Excluded_Statement
(Statements
(S
))
2091 end Has_Excluded_Statement
;
2093 -------------------------------
2094 -- Has_Pending_Instantiation --
2095 -------------------------------
2097 function Has_Pending_Instantiation
return Boolean is
2098 S
: Entity_Id
:= Current_Scope
;
2101 while Present
(S
) loop
2102 if Is_Compilation_Unit
(S
)
2103 or else Is_Child_Unit
(S
)
2106 elsif Ekind
(S
) = E_Package
2107 and then Has_Forward_Instantiation
(S
)
2116 end Has_Pending_Instantiation
;
2118 ------------------------
2119 -- Has_Single_Return --
2120 ------------------------
2122 function Has_Single_Return
return Boolean is
2123 Return_Statement
: Node_Id
:= Empty
;
2125 function Check_Return
(N
: Node_Id
) return Traverse_Result
;
2131 function Check_Return
(N
: Node_Id
) return Traverse_Result
is
2133 if Nkind
(N
) = N_Return_Statement
then
2134 if Present
(Expression
(N
))
2135 and then Is_Entity_Name
(Expression
(N
))
2137 if No
(Return_Statement
) then
2138 Return_Statement
:= N
;
2141 elsif Chars
(Expression
(N
)) =
2142 Chars
(Expression
(Return_Statement
))
2151 -- Expression has wrong form
2161 function Check_All_Returns
is new Traverse_Func
(Check_Return
);
2163 -- Start of processing for Has_Single_Return
2166 return Check_All_Returns
(N
) = OK
2167 and then Present
(Declarations
(N
))
2168 and then Chars
(Expression
(Return_Statement
)) =
2169 Chars
(Defining_Identifier
(First
(Declarations
(N
))));
2170 end Has_Single_Return
;
2172 --------------------
2173 -- Remove_Pragmas --
2174 --------------------
2176 procedure Remove_Pragmas
is
2181 Decl
:= First
(Declarations
(Body_To_Analyze
));
2182 while Present
(Decl
) loop
2185 if Nkind
(Decl
) = N_Pragma
2186 and then Chars
(Decl
) = Name_Unreferenced
2195 --------------------------
2196 -- Uses_Secondary_Stack --
2197 --------------------------
2199 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean is
2200 function Check_Call
(N
: Node_Id
) return Traverse_Result
;
2201 -- Look for function calls that return an unconstrained type
2207 function Check_Call
(N
: Node_Id
) return Traverse_Result
is
2209 if Nkind
(N
) = N_Function_Call
2210 and then Is_Entity_Name
(Name
(N
))
2211 and then Is_Composite_Type
(Etype
(Entity
(Name
(N
))))
2212 and then not Is_Constrained
(Etype
(Entity
(Name
(N
))))
2215 ("cannot inline & (call returns unconstrained type)?",
2223 function Check_Calls
is new Traverse_Func
(Check_Call
);
2226 return Check_Calls
(Bod
) = Abandon
;
2227 end Uses_Secondary_Stack
;
2229 -- Start of processing for Build_Body_To_Inline
2232 if Nkind
(Decl
) = N_Subprogram_Declaration
2233 and then Present
(Body_To_Inline
(Decl
))
2235 return; -- Done already.
2237 -- Functions that return unconstrained composite types require
2238 -- secondary stack handling, and cannot currently be inlined, unless
2239 -- all return statements return a local variable that is the first
2240 -- local declaration in the body.
2242 elsif Ekind
(Subp
) = E_Function
2243 and then not Is_Scalar_Type
(Etype
(Subp
))
2244 and then not Is_Access_Type
(Etype
(Subp
))
2245 and then not Is_Constrained
(Etype
(Subp
))
2247 if not Has_Single_Return
then
2249 ("cannot inline & (unconstrained return type)?", N
, Subp
);
2253 -- Ditto for functions that return controlled types, where controlled
2254 -- actions interfere in complex ways with inlining.
2256 elsif Ekind
(Subp
) = E_Function
2257 and then Controlled_Type
(Etype
(Subp
))
2260 ("cannot inline & (controlled return type)?", N
, Subp
);
2264 if Present
(Declarations
(N
))
2265 and then Has_Excluded_Declaration
(Declarations
(N
))
2270 if Present
(Handled_Statement_Sequence
(N
)) then
2271 if Present
(Exception_Handlers
(Handled_Statement_Sequence
(N
))) then
2273 ("cannot inline& (exception handler)?",
2274 First
(Exception_Handlers
(Handled_Statement_Sequence
(N
))),
2278 Has_Excluded_Statement
2279 (Statements
(Handled_Statement_Sequence
(N
)))
2285 -- We do not inline a subprogram that is too large, unless it is
2286 -- marked Inline_Always. This pragma does not suppress the other
2287 -- checks on inlining (forbidden declarations, handlers, etc).
2289 if Stat_Count
> Max_Size
2290 and then not Is_Always_Inlined
(Subp
)
2292 Cannot_Inline
("cannot inline& (body too large)?", N
, Subp
);
2296 if Has_Pending_Instantiation
then
2298 ("cannot inline& (forward instance within enclosing body)?",
2303 -- Within an instance, the body to inline must be treated as a nested
2304 -- generic, so that the proper global references are preserved.
2307 Save_Env
(Scope
(Current_Scope
), Scope
(Current_Scope
));
2308 Original_Body
:= Copy_Generic_Node
(N
, Empty
, True);
2310 Original_Body
:= Copy_Separate_Tree
(N
);
2313 -- We need to capture references to the formals in order to substitute
2314 -- the actuals at the point of inlining, i.e. instantiation. To treat
2315 -- the formals as globals to the body to inline, we nest it within
2316 -- a dummy parameterless subprogram, declared within the real one.
2317 -- To avoid generating an internal name (which is never public, and
2318 -- which affects serial numbers of other generated names), we use
2319 -- an internal symbol that cannot conflict with user declarations.
2321 Set_Parameter_Specifications
(Specification
(Original_Body
), No_List
);
2322 Set_Defining_Unit_Name
2323 (Specification
(Original_Body
),
2324 Make_Defining_Identifier
(Sloc
(N
), Name_uParent
));
2325 Set_Corresponding_Spec
(Original_Body
, Empty
);
2327 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
2329 -- Set return type of function, which is also global and does not need
2332 if Ekind
(Subp
) = E_Function
then
2333 Set_Result_Definition
(Specification
(Body_To_Analyze
),
2334 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
2337 if No
(Declarations
(N
)) then
2338 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
2340 Append
(Body_To_Analyze
, Declarations
(N
));
2343 Expander_Mode_Save_And_Set
(False);
2346 Analyze
(Body_To_Analyze
);
2347 New_Scope
(Defining_Entity
(Body_To_Analyze
));
2348 Save_Global_References
(Original_Body
);
2350 Remove
(Body_To_Analyze
);
2352 Expander_Mode_Restore
;
2358 -- If secondary stk used there is no point in inlining. We have
2359 -- already issued the warning in this case, so nothing to do.
2361 if Uses_Secondary_Stack
(Body_To_Analyze
) then
2365 Set_Body_To_Inline
(Decl
, Original_Body
);
2366 Set_Ekind
(Defining_Entity
(Original_Body
), Ekind
(Subp
));
2367 Set_Is_Inlined
(Subp
);
2368 end Build_Body_To_Inline
;
2374 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
; Subp
: Entity_Id
) is
2376 -- Do not emit warning if this is a predefined unit which is not
2377 -- the main unit. With validity checks enabled, some predefined
2378 -- subprograms may contain nested subprograms and become ineligible
2381 if Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(Subp
)))
2382 and then not In_Extended_Main_Source_Unit
(Subp
)
2386 elsif Is_Always_Inlined
(Subp
) then
2388 -- Remove last character (question mark) to make this into an error,
2389 -- because the Inline_Always pragma cannot be obeyed.
2391 Error_Msg_NE
(Msg
(1 .. Msg
'Length - 1), N
, Subp
);
2393 elsif Ineffective_Inline_Warnings
then
2394 Error_Msg_NE
(Msg
, N
, Subp
);
2398 -----------------------
2399 -- Check_Conformance --
2400 -----------------------
2402 procedure Check_Conformance
2403 (New_Id
: Entity_Id
;
2405 Ctype
: Conformance_Type
;
2407 Conforms
: out Boolean;
2408 Err_Loc
: Node_Id
:= Empty
;
2409 Get_Inst
: Boolean := False;
2410 Skip_Controlling_Formals
: Boolean := False)
2412 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
2413 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
2414 Old_Formal
: Entity_Id
;
2415 New_Formal
: Entity_Id
;
2417 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
2418 -- Post error message for conformance error on given node. Two messages
2419 -- are output. The first points to the previous declaration with a
2420 -- general "no conformance" message. The second is the detailed reason,
2421 -- supplied as Msg. The parameter N provide information for a possible
2422 -- & insertion in the message, and also provides the location for
2423 -- posting the message in the absence of a specified Err_Loc location.
2425 -----------------------
2426 -- Conformance_Error --
2427 -----------------------
2429 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
2436 if No
(Err_Loc
) then
2442 Error_Msg_Sloc
:= Sloc
(Old_Id
);
2445 when Type_Conformant
=>
2447 ("not type conformant with declaration#!", Enode
);
2449 when Mode_Conformant
=>
2451 ("not mode conformant with declaration#!", Enode
);
2453 when Subtype_Conformant
=>
2455 ("not subtype conformant with declaration#!", Enode
);
2457 when Fully_Conformant
=>
2459 ("not fully conformant with declaration#!", Enode
);
2462 Error_Msg_NE
(Msg
, Enode
, N
);
2464 end Conformance_Error
;
2466 -- Start of processing for Check_Conformance
2471 -- We need a special case for operators, since they don't appear
2474 if Ctype
= Type_Conformant
then
2475 if Ekind
(New_Id
) = E_Operator
2476 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
2482 -- If both are functions/operators, check return types conform
2484 if Old_Type
/= Standard_Void_Type
2485 and then New_Type
/= Standard_Void_Type
2487 if not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
2488 Conformance_Error
("return type does not match!", New_Id
);
2492 -- Ada 2005 (AI-231): In case of anonymous access types check the
2493 -- null-exclusion and access-to-constant attributes must match.
2495 if Ada_Version
>= Ada_05
2496 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
2498 (Can_Never_Be_Null
(Old_Type
)
2499 /= Can_Never_Be_Null
(New_Type
)
2500 or else Is_Access_Constant
(Etype
(Old_Type
))
2501 /= Is_Access_Constant
(Etype
(New_Type
)))
2503 Conformance_Error
("return type does not match!", New_Id
);
2507 -- If either is a function/operator and the other isn't, error
2509 elsif Old_Type
/= Standard_Void_Type
2510 or else New_Type
/= Standard_Void_Type
2512 Conformance_Error
("functions can only match functions!", New_Id
);
2516 -- In subtype conformant case, conventions must match (RM 6.3.1(16))
2517 -- If this is a renaming as body, refine error message to indicate that
2518 -- the conflict is with the original declaration. If the entity is not
2519 -- frozen, the conventions don't have to match, the one of the renamed
2520 -- entity is inherited.
2522 if Ctype
>= Subtype_Conformant
then
2523 if Convention
(Old_Id
) /= Convention
(New_Id
) then
2525 if not Is_Frozen
(New_Id
) then
2528 elsif Present
(Err_Loc
)
2529 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
2530 and then Present
(Corresponding_Spec
(Err_Loc
))
2532 Error_Msg_Name_1
:= Chars
(New_Id
);
2534 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
2536 Conformance_Error
("prior declaration for% has convention %!");
2539 Conformance_Error
("calling conventions do not match!");
2544 elsif Is_Formal_Subprogram
(Old_Id
)
2545 or else Is_Formal_Subprogram
(New_Id
)
2547 Conformance_Error
("formal subprograms not allowed!");
2552 -- Deal with parameters
2554 -- Note: we use the entity information, rather than going directly
2555 -- to the specification in the tree. This is not only simpler, but
2556 -- absolutely necessary for some cases of conformance tests between
2557 -- operators, where the declaration tree simply does not exist!
2559 Old_Formal
:= First_Formal
(Old_Id
);
2560 New_Formal
:= First_Formal
(New_Id
);
2562 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
2563 if Is_Controlling_Formal
(Old_Formal
)
2564 and then Is_Controlling_Formal
(New_Formal
)
2565 and then Skip_Controlling_Formals
2567 goto Skip_Controlling_Formal
;
2570 if Ctype
= Fully_Conformant
then
2572 -- Names must match. Error message is more accurate if we do
2573 -- this before checking that the types of the formals match.
2575 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
2576 Conformance_Error
("name & does not match!", New_Formal
);
2578 -- Set error posted flag on new formal as well to stop
2579 -- junk cascaded messages in some cases.
2581 Set_Error_Posted
(New_Formal
);
2586 -- Types must always match. In the visible part of an instance,
2587 -- usual overloading rules for dispatching operations apply, and
2588 -- we check base types (not the actual subtypes).
2590 if In_Instance_Visible_Part
2591 and then Is_Dispatching_Operation
(New_Id
)
2593 if not Conforming_Types
2594 (Base_Type
(Etype
(Old_Formal
)),
2595 Base_Type
(Etype
(New_Formal
)), Ctype
, Get_Inst
)
2597 Conformance_Error
("type of & does not match!", New_Formal
);
2601 elsif not Conforming_Types
2602 (Etype
(Old_Formal
), Etype
(New_Formal
), Ctype
, Get_Inst
)
2604 Conformance_Error
("type of & does not match!", New_Formal
);
2608 -- For mode conformance, mode must match
2610 if Ctype
>= Mode_Conformant
2611 and then Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
)
2613 Conformance_Error
("mode of & does not match!", New_Formal
);
2617 -- Full conformance checks
2619 if Ctype
= Fully_Conformant
then
2621 -- We have checked already that names match
2623 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
2625 -- Ada 2005 (AI-231): In case of anonymous access types check
2626 -- the null-exclusion and access-to-constant attributes must
2629 if Ada_Version
>= Ada_05
2630 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
2632 (Can_Never_Be_Null
(Old_Formal
)
2633 /= Can_Never_Be_Null
(New_Formal
)
2634 or else Is_Access_Constant
(Etype
(Old_Formal
))
2635 /= Is_Access_Constant
(Etype
(New_Formal
)))
2637 -- It is allowed to omit the null-exclusion in case of
2638 -- stream attribute subprograms
2641 TSS_Name
: TSS_Name_Type
;
2644 Get_Name_String
(Chars
(New_Id
));
2648 (Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2650 if TSS_Name
/= TSS_Stream_Read
2651 and then TSS_Name
/= TSS_Stream_Write
2652 and then TSS_Name
/= TSS_Stream_Input
2653 and then TSS_Name
/= TSS_Stream_Output
2656 ("type of & does not match!", New_Formal
);
2662 -- Check default expressions for in parameters
2665 NewD
: constant Boolean :=
2666 Present
(Default_Value
(New_Formal
));
2667 OldD
: constant Boolean :=
2668 Present
(Default_Value
(Old_Formal
));
2670 if NewD
or OldD
then
2672 -- The old default value has been analyzed because the
2673 -- current full declaration will have frozen everything
2674 -- before. The new default values have not been
2675 -- analyzed, so analyze them now before we check for
2680 Analyze_Per_Use_Expression
2681 (Default_Value
(New_Formal
), Etype
(New_Formal
));
2685 if not (NewD
and OldD
)
2686 or else not Fully_Conformant_Expressions
2687 (Default_Value
(Old_Formal
),
2688 Default_Value
(New_Formal
))
2691 ("default expression for & does not match!",
2700 -- A couple of special checks for Ada 83 mode. These checks are
2701 -- skipped if either entity is an operator in package Standard.
2702 -- or if either old or new instance is not from the source program.
2704 if Ada_Version
= Ada_83
2705 and then Sloc
(Old_Id
) > Standard_Location
2706 and then Sloc
(New_Id
) > Standard_Location
2707 and then Comes_From_Source
(Old_Id
)
2708 and then Comes_From_Source
(New_Id
)
2711 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
2712 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
2715 -- Explicit IN must be present or absent in both cases. This
2716 -- test is required only in the full conformance case.
2718 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
2719 and then Ctype
= Fully_Conformant
2722 ("(Ada 83) IN must appear in both declarations",
2727 -- Grouping (use of comma in param lists) must be the same
2728 -- This is where we catch a misconformance like:
2731 -- A : Integer; B : Integer
2733 -- which are represented identically in the tree except
2734 -- for the setting of the flags More_Ids and Prev_Ids.
2736 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
2737 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
2740 ("grouping of & does not match!", New_Formal
);
2746 -- This label is required when skipping controlling formals
2748 <<Skip_Controlling_Formal
>>
2750 Next_Formal
(Old_Formal
);
2751 Next_Formal
(New_Formal
);
2754 if Present
(Old_Formal
) then
2755 Conformance_Error
("too few parameters!");
2758 elsif Present
(New_Formal
) then
2759 Conformance_Error
("too many parameters!", New_Formal
);
2762 end Check_Conformance
;
2764 ------------------------------
2765 -- Check_Delayed_Subprogram --
2766 ------------------------------
2768 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
2771 procedure Possible_Freeze
(T
: Entity_Id
);
2772 -- T is the type of either a formal parameter or of the return type.
2773 -- If T is not yet frozen and needs a delayed freeze, then the
2774 -- subprogram itself must be delayed.
2776 ---------------------
2777 -- Possible_Freeze --
2778 ---------------------
2780 procedure Possible_Freeze
(T
: Entity_Id
) is
2782 if Has_Delayed_Freeze
(T
)
2783 and then not Is_Frozen
(T
)
2785 Set_Has_Delayed_Freeze
(Designator
);
2787 elsif Is_Access_Type
(T
)
2788 and then Has_Delayed_Freeze
(Designated_Type
(T
))
2789 and then not Is_Frozen
(Designated_Type
(T
))
2791 Set_Has_Delayed_Freeze
(Designator
);
2793 end Possible_Freeze
;
2795 -- Start of processing for Check_Delayed_Subprogram
2798 -- Never need to freeze abstract subprogram
2800 if Is_Abstract
(Designator
) then
2803 -- Need delayed freeze if return type itself needs a delayed
2804 -- freeze and is not yet frozen.
2806 Possible_Freeze
(Etype
(Designator
));
2807 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
2809 -- Need delayed freeze if any of the formal types themselves need
2810 -- a delayed freeze and are not yet frozen.
2812 F
:= First_Formal
(Designator
);
2813 while Present
(F
) loop
2814 Possible_Freeze
(Etype
(F
));
2815 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
2820 -- Mark functions that return by reference. Note that it cannot be
2821 -- done for delayed_freeze subprograms because the underlying
2822 -- returned type may not be known yet (for private types)
2824 if not Has_Delayed_Freeze
(Designator
)
2825 and then Expander_Active
2828 Typ
: constant Entity_Id
:= Etype
(Designator
);
2829 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
2832 if Is_Return_By_Reference_Type
(Typ
) then
2833 Set_Returns_By_Ref
(Designator
);
2835 elsif Present
(Utyp
) and then Controlled_Type
(Utyp
) then
2836 Set_Returns_By_Ref
(Designator
);
2840 end Check_Delayed_Subprogram
;
2842 ------------------------------------
2843 -- Check_Discriminant_Conformance --
2844 ------------------------------------
2846 procedure Check_Discriminant_Conformance
2851 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
2852 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
2853 New_Discr_Id
: Entity_Id
;
2854 New_Discr_Type
: Entity_Id
;
2856 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
2857 -- Post error message for conformance error on given node. Two messages
2858 -- are output. The first points to the previous declaration with a
2859 -- general "no conformance" message. The second is the detailed reason,
2860 -- supplied as Msg. The parameter N provide information for a possible
2861 -- & insertion in the message.
2863 -----------------------
2864 -- Conformance_Error --
2865 -----------------------
2867 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
2869 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
2870 Error_Msg_N
("not fully conformant with declaration#!", N
);
2871 Error_Msg_NE
(Msg
, N
, N
);
2872 end Conformance_Error
;
2874 -- Start of processing for Check_Discriminant_Conformance
2877 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
2879 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
2881 -- The subtype mark of the discriminant on the full type has not
2882 -- been analyzed so we do it here. For an access discriminant a new
2885 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
2887 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
2890 Analyze
(Discriminant_Type
(New_Discr
));
2891 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
2894 if not Conforming_Types
2895 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
2897 Conformance_Error
("type of & does not match!", New_Discr_Id
);
2900 -- Treat the new discriminant as an occurrence of the old one,
2901 -- for navigation purposes, and fill in some semantic
2902 -- information, for completeness.
2904 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
2905 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
2906 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
2911 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
2912 Conformance_Error
("name & does not match!", New_Discr_Id
);
2916 -- Default expressions must match
2919 NewD
: constant Boolean :=
2920 Present
(Expression
(New_Discr
));
2921 OldD
: constant Boolean :=
2922 Present
(Expression
(Parent
(Old_Discr
)));
2925 if NewD
or OldD
then
2927 -- The old default value has been analyzed and expanded,
2928 -- because the current full declaration will have frozen
2929 -- everything before. The new default values have not been
2930 -- expanded, so expand now to check conformance.
2933 Analyze_Per_Use_Expression
2934 (Expression
(New_Discr
), New_Discr_Type
);
2937 if not (NewD
and OldD
)
2938 or else not Fully_Conformant_Expressions
2939 (Expression
(Parent
(Old_Discr
)),
2940 Expression
(New_Discr
))
2944 ("default expression for & does not match!",
2951 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
2953 if Ada_Version
= Ada_83
then
2955 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
2958 -- Grouping (use of comma in param lists) must be the same
2959 -- This is where we catch a misconformance like:
2962 -- A : Integer; B : Integer
2964 -- which are represented identically in the tree except
2965 -- for the setting of the flags More_Ids and Prev_Ids.
2967 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
2968 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
2971 ("grouping of & does not match!", New_Discr_Id
);
2977 Next_Discriminant
(Old_Discr
);
2981 if Present
(Old_Discr
) then
2982 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
2985 elsif Present
(New_Discr
) then
2987 ("too many discriminants!", Defining_Identifier
(New_Discr
));
2990 end Check_Discriminant_Conformance
;
2992 ----------------------------
2993 -- Check_Fully_Conformant --
2994 ----------------------------
2996 procedure Check_Fully_Conformant
2997 (New_Id
: Entity_Id
;
2999 Err_Loc
: Node_Id
:= Empty
)
3004 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
3005 end Check_Fully_Conformant
;
3007 ---------------------------
3008 -- Check_Mode_Conformant --
3009 ---------------------------
3011 procedure Check_Mode_Conformant
3012 (New_Id
: Entity_Id
;
3014 Err_Loc
: Node_Id
:= Empty
;
3015 Get_Inst
: Boolean := False)
3021 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
3022 end Check_Mode_Conformant
;
3024 --------------------------------
3025 -- Check_Overriding_Indicator --
3026 --------------------------------
3028 procedure Check_Overriding_Indicator
3030 Does_Override
: Boolean)
3036 if Ekind
(Subp
) = E_Enumeration_Literal
then
3038 -- No overriding indicator for literals
3043 Decl
:= Unit_Declaration_Node
(Subp
);
3046 if Nkind
(Decl
) = N_Subprogram_Declaration
3047 or else Nkind
(Decl
) = N_Subprogram_Body
3048 or else Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
3049 or else Nkind
(Decl
) = N_Subprogram_Body_Stub
3051 Spec
:= Specification
(Decl
);
3056 if not Does_Override
then
3057 if Must_Override
(Spec
) then
3058 Error_Msg_NE
("subprogram& is not overriding", Spec
, Subp
);
3062 if Must_Not_Override
(Spec
) then
3064 ("subprogram& overrides inherited operation", Spec
, Subp
);
3067 end Check_Overriding_Indicator
;
3073 procedure Check_Returns
3077 Proc
: Entity_Id
:= Empty
)
3081 procedure Check_Statement_Sequence
(L
: List_Id
);
3082 -- Internal recursive procedure to check a list of statements for proper
3083 -- termination by a return statement (or a transfer of control or a
3084 -- compound statement that is itself internally properly terminated).
3086 ------------------------------
3087 -- Check_Statement_Sequence --
3088 ------------------------------
3090 procedure Check_Statement_Sequence
(L
: List_Id
) is
3094 Raise_Exception_Call
: Boolean;
3095 -- Set True if statement sequence terminated by Raise_Exception call
3096 -- or a Reraise_Occurrence call.
3099 Raise_Exception_Call
:= False;
3101 -- Get last real statement
3103 Last_Stm
:= Last
(L
);
3105 -- Don't count pragmas
3107 while Nkind
(Last_Stm
) = N_Pragma
3109 -- Don't count call to SS_Release (can happen after Raise_Exception)
3112 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
3114 Nkind
(Name
(Last_Stm
)) = N_Identifier
3116 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
3118 -- Don't count exception junk
3121 ((Nkind
(Last_Stm
) = N_Goto_Statement
3122 or else Nkind
(Last_Stm
) = N_Label
3123 or else Nkind
(Last_Stm
) = N_Object_Declaration
)
3124 and then Exception_Junk
(Last_Stm
))
3129 -- Here we have the "real" last statement
3131 Kind
:= Nkind
(Last_Stm
);
3133 -- Transfer of control, OK. Note that in the No_Return procedure
3134 -- case, we already diagnosed any explicit return statements, so
3135 -- we can treat them as OK in this context.
3137 if Is_Transfer
(Last_Stm
) then
3140 -- Check cases of explicit non-indirect procedure calls
3142 elsif Kind
= N_Procedure_Call_Statement
3143 and then Is_Entity_Name
(Name
(Last_Stm
))
3145 -- Check call to Raise_Exception procedure which is treated
3146 -- specially, as is a call to Reraise_Occurrence.
3148 -- We suppress the warning in these cases since it is likely that
3149 -- the programmer really does not expect to deal with the case
3150 -- of Null_Occurrence, and thus would find a warning about a
3151 -- missing return curious, and raising Program_Error does not
3152 -- seem such a bad behavior if this does occur.
3154 -- Note that in the Ada 2005 case for Raise_Exception, the actual
3155 -- behavior will be to raise Constraint_Error (see AI-329).
3157 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
3159 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
3161 Raise_Exception_Call
:= True;
3163 -- For Raise_Exception call, test first argument, if it is
3164 -- an attribute reference for a 'Identity call, then we know
3165 -- that the call cannot possibly return.
3168 Arg
: constant Node_Id
:=
3169 Original_Node
(First_Actual
(Last_Stm
));
3172 if Nkind
(Arg
) = N_Attribute_Reference
3173 and then Attribute_Name
(Arg
) = Name_Identity
3180 -- If statement, need to look inside if there is an else and check
3181 -- each constituent statement sequence for proper termination.
3183 elsif Kind
= N_If_Statement
3184 and then Present
(Else_Statements
(Last_Stm
))
3186 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
3187 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
3189 if Present
(Elsif_Parts
(Last_Stm
)) then
3191 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
3194 while Present
(Elsif_Part
) loop
3195 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
3203 -- Case statement, check each case for proper termination
3205 elsif Kind
= N_Case_Statement
then
3210 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
3211 while Present
(Case_Alt
) loop
3212 Check_Statement_Sequence
(Statements
(Case_Alt
));
3213 Next_Non_Pragma
(Case_Alt
);
3219 -- Block statement, check its handled sequence of statements
3221 elsif Kind
= N_Block_Statement
then
3227 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
3236 -- Loop statement. If there is an iteration scheme, we can definitely
3237 -- fall out of the loop. Similarly if there is an exit statement, we
3238 -- can fall out. In either case we need a following return.
3240 elsif Kind
= N_Loop_Statement
then
3241 if Present
(Iteration_Scheme
(Last_Stm
))
3242 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
3246 -- A loop with no exit statement or iteration scheme if either
3247 -- an inifite loop, or it has some other exit (raise/return).
3248 -- In either case, no warning is required.
3254 -- Timed entry call, check entry call and delay alternatives
3256 -- Note: in expanded code, the timed entry call has been converted
3257 -- to a set of expanded statements on which the check will work
3258 -- correctly in any case.
3260 elsif Kind
= N_Timed_Entry_Call
then
3262 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
3263 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
3266 -- If statement sequence of entry call alternative is missing,
3267 -- then we can definitely fall through, and we post the error
3268 -- message on the entry call alternative itself.
3270 if No
(Statements
(ECA
)) then
3273 -- If statement sequence of delay alternative is missing, then
3274 -- we can definitely fall through, and we post the error
3275 -- message on the delay alternative itself.
3277 -- Note: if both ECA and DCA are missing the return, then we
3278 -- post only one message, should be enough to fix the bugs.
3279 -- If not we will get a message next time on the DCA when the
3282 elsif No
(Statements
(DCA
)) then
3285 -- Else check both statement sequences
3288 Check_Statement_Sequence
(Statements
(ECA
));
3289 Check_Statement_Sequence
(Statements
(DCA
));
3294 -- Conditional entry call, check entry call and else part
3296 -- Note: in expanded code, the conditional entry call has been
3297 -- converted to a set of expanded statements on which the check
3298 -- will work correctly in any case.
3300 elsif Kind
= N_Conditional_Entry_Call
then
3302 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
3305 -- If statement sequence of entry call alternative is missing,
3306 -- then we can definitely fall through, and we post the error
3307 -- message on the entry call alternative itself.
3309 if No
(Statements
(ECA
)) then
3312 -- Else check statement sequence and else part
3315 Check_Statement_Sequence
(Statements
(ECA
));
3316 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
3322 -- If we fall through, issue appropriate message
3325 if not Raise_Exception_Call
then
3327 ("?RETURN statement missing following this statement",
3330 ("\?Program_Error may be raised at run time",
3334 -- Note: we set Err even though we have not issued a warning
3335 -- because we still have a case of a missing return. This is
3336 -- an extremely marginal case, probably will never be noticed
3337 -- but we might as well get it right.
3341 -- Otherwise we have the case of a procedure marked No_Return
3345 ("?implied return after this statement will raise Program_Error",
3348 ("?procedure & is marked as No_Return",
3352 RE
: constant Node_Id
:=
3353 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
3354 Reason
=> PE_Implicit_Return
);
3356 Insert_After
(Last_Stm
, RE
);
3360 end Check_Statement_Sequence
;
3362 -- Start of processing for Check_Returns
3366 Check_Statement_Sequence
(Statements
(HSS
));
3368 if Present
(Exception_Handlers
(HSS
)) then
3369 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
3370 while Present
(Handler
) loop
3371 Check_Statement_Sequence
(Statements
(Handler
));
3372 Next_Non_Pragma
(Handler
);
3377 ----------------------------
3378 -- Check_Subprogram_Order --
3379 ----------------------------
3381 procedure Check_Subprogram_Order
(N
: Node_Id
) is
3383 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
3384 -- This is used to check if S1 > S2 in the sense required by this
3385 -- test, for example nameab < namec, but name2 < name10.
3387 -----------------------------
3388 -- Subprogram_Name_Greater --
3389 -----------------------------
3391 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
3396 -- Remove trailing numeric parts
3399 while S1
(L1
) in '0' .. '9' loop
3404 while S2
(L2
) in '0' .. '9' loop
3408 -- If non-numeric parts non-equal, that's decisive
3410 if S1
(S1
'First .. L1
) < S2
(S2
'First .. L2
) then
3413 elsif S1
(S1
'First .. L1
) > S2
(S2
'First .. L2
) then
3416 -- If non-numeric parts equal, compare suffixed numeric parts. Note
3417 -- that a missing suffix is treated as numeric zero in this test.
3421 while L1
< S1
'Last loop
3423 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
3427 while L2
< S2
'Last loop
3429 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
3434 end Subprogram_Name_Greater
;
3436 -- Start of processing for Check_Subprogram_Order
3439 -- Check body in alpha order if this is option
3442 and then Style_Check_Order_Subprograms
3443 and then Nkind
(N
) = N_Subprogram_Body
3444 and then Comes_From_Source
(N
)
3445 and then In_Extended_Main_Source_Unit
(N
)
3449 renames Scope_Stack
.Table
3450 (Scope_Stack
.Last
).Last_Subprogram_Name
;
3452 Body_Id
: constant Entity_Id
:=
3453 Defining_Entity
(Specification
(N
));
3456 Get_Decoded_Name_String
(Chars
(Body_Id
));
3459 if Subprogram_Name_Greater
3460 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
3462 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
3468 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
3471 end Check_Subprogram_Order;
3473 ------------------------------
3474 -- Check_Subtype_Conformant --
3475 ------------------------------
3477 procedure Check_Subtype_Conformant
3478 (New_Id : Entity_Id;
3480 Err_Loc : Node_Id := Empty)
3485 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
3486 end Check_Subtype_Conformant;
3488 ---------------------------
3489 -- Check_Type_Conformant --
3490 ---------------------------
3492 procedure Check_Type_Conformant
3493 (New_Id : Entity_Id;
3495 Err_Loc : Node_Id := Empty)
3500 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
3501 end Check_Type_Conformant;
3503 ----------------------
3504 -- Conforming_Types --
3505 ----------------------
3507 function Conforming_Types
3510 Ctype : Conformance_Type;
3511 Get_Inst : Boolean := False) return Boolean
3513 Type_1 : Entity_Id := T1;
3514 Type_2 : Entity_Id := T2;
3515 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
3517 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
3518 -- If neither T1 nor T2 are generic actual types, or if they are
3519 -- in different scopes (e.g. parent and child instances), then verify
3520 -- that the base types are equal. Otherwise T1 and T2 must be
3521 -- on the same subtype chain. The whole purpose of this procedure
3522 -- is to prevent spurious ambiguities in an instantiation that may
3523 -- arise if two distinct generic types are instantiated with the
3526 ----------------------
3527 -- Base_Types_Match --
3528 ----------------------
3530 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
3535 elsif Base_Type (T1) = Base_Type (T2) then
3537 -- The following is too permissive. A more precise test must
3538 -- check that the generic actual is an ancestor subtype of the
3541 return not Is_Generic_Actual_Type (T1)
3542 or else not Is_Generic_Actual_Type (T2)
3543 or else Scope (T1) /= Scope (T2);
3545 -- In some cases a type imported through a limited_with clause,
3546 -- and its non-limited view are both visible, for example in an
3547 -- anonymous access_to_classwide type in a formal. Both entities
3548 -- designate the same type.
3550 elsif From_With_Type (T1)
3551 and then Ekind (T1) = E_Incomplete_Type
3552 and then T2 = Non_Limited_View (T1)
3556 elsif From_With_Type (T2)
3557 and then Ekind (T2) = E_Incomplete_Type
3558 and then T1 = Non_Limited_View (T2)
3565 end Base_Types_Match;
3567 -- Start of processing for Conforming_Types
3570 -- The context is an instance association for a formal
3571 -- access-to-subprogram type; the formal parameter types require
3572 -- mapping because they may denote other formal parameters of the
3576 Type_1 := Get_Instance_Of (T1);
3577 Type_2 := Get_Instance_Of (T2);
3580 -- First see if base types match
3582 if Base_Types_Match (Type_1, Type_2) then
3583 return Ctype <= Mode_Conformant
3584 or else Subtypes_Statically_Match (Type_1, Type_2);
3586 elsif Is_Incomplete_Or_Private_Type (Type_1)
3587 and then Present (Full_View (Type_1))
3588 and then Base_Types_Match (Full_View (Type_1), Type_2)
3590 return Ctype <= Mode_Conformant
3591 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
3593 elsif Ekind (Type_2) = E_Incomplete_Type
3594 and then Present (Full_View (Type_2))
3595 and then Base_Types_Match (Type_1, Full_View (Type_2))
3597 return Ctype <= Mode_Conformant
3598 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
3600 elsif Is_Private_Type (Type_2)
3601 and then In_Instance
3602 and then Present (Full_View (Type_2))
3603 and then Base_Types_Match (Type_1, Full_View (Type_2))
3605 return Ctype <= Mode_Conformant
3606 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
3609 -- Ada 2005 (AI-254): Anonymous access to subprogram types must be
3610 -- treated recursively because they carry a signature.
3612 Are_Anonymous_Access_To_Subprogram_Types :=
3614 -- Case 1: Anonymous access to subprogram types
3616 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
3617 and then Ekind (Type_2) = E_Anonymous_Access_Subprogram_Type)
3619 -- Case 2: Anonymous access to PROTECTED subprogram types. In this
3620 -- case the anonymous type_declaration has been replaced by an
3621 -- occurrence of an internal access to subprogram type declaration
3622 -- available through the Original_Access_Type attribute
3625 (Ekind (Type_1) = E_Access_Protected_Subprogram_Type
3626 and then Ekind (Type_2) = E_Access_Protected_Subprogram_Type
3627 and then not Comes_From_Source (Type_1)
3628 and then not Comes_From_Source (Type_2)
3629 and then Present (Original_Access_Type (Type_1))
3630 and then Present (Original_Access_Type (Type_2))
3631 and then Ekind (Original_Access_Type (Type_1)) =
3632 E_Anonymous_Access_Protected_Subprogram_Type
3633 and then Ekind (Original_Access_Type (Type_2)) =
3634 E_Anonymous_Access_Protected_Subprogram_Type);
3636 -- Test anonymous access type case. For this case, static subtype
3637 -- matching is required for mode conformance (RM 6.3.1(15))
3639 if (Ekind (Type_1) = E_Anonymous_Access_Type
3640 and then Ekind (Type_2) = E_Anonymous_Access_Type)
3641 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
3644 Desig_1 : Entity_Id;
3645 Desig_2 : Entity_Id;
3648 Desig_1 := Directly_Designated_Type (Type_1);
3650 -- An access parameter can designate an incomplete type
3651 -- If the incomplete type is the limited view of a type
3652 -- from a limited_with_clause, check whether the non-limited
3653 -- view is available.
3655 if Ekind (Desig_1) = E_Incomplete_Type then
3656 if Present (Full_View (Desig_1)) then
3657 Desig_1 := Full_View (Desig_1);
3659 elsif Present (Non_Limited_View (Desig_1)) then
3660 Desig_1 := Non_Limited_View (Desig_1);
3664 Desig_2 := Directly_Designated_Type (Type_2);
3666 if Ekind (Desig_2) = E_Incomplete_Type then
3667 if Present (Full_View (Desig_2)) then
3668 Desig_2 := Full_View (Desig_2);
3669 elsif Present (Non_Limited_View (Desig_2)) then
3670 Desig_2 := Non_Limited_View (Desig_2);
3674 -- The context is an instance association for a formal
3675 -- access-to-subprogram type; formal access parameter designated
3676 -- types require mapping because they may denote other formal
3677 -- parameters of the generic unit.
3680 Desig_1 := Get_Instance_Of (Desig_1);
3681 Desig_2 := Get_Instance_Of (Desig_2);
3684 -- It is possible for a Class_Wide_Type to be introduced for an
3685 -- incomplete type, in which case there is a separate class_ wide
3686 -- type for the full view. The types conform if their Etypes
3687 -- conform, i.e. one may be the full view of the other. This can
3688 -- only happen in the context of an access parameter, other uses
3689 -- of an incomplete Class_Wide_Type are illegal.
3691 if Is_Class_Wide_Type (Desig_1)
3692 and then Is_Class_Wide_Type (Desig_2)
3696 (Etype (Base_Type (Desig_1)),
3697 Etype (Base_Type (Desig_2)), Ctype);
3699 elsif Are_Anonymous_Access_To_Subprogram_Types then
3700 if Ada_Version < Ada_05 then
3701 return Ctype = Type_Conformant
3703 Subtypes_Statically_Match (Desig_1, Desig_2);
3705 -- We must check the conformance of the signatures themselves
3709 Conformant : Boolean;
3712 (Desig_1, Desig_2, Ctype, False, Conformant);
3718 return Base_Type (Desig_1) = Base_Type (Desig_2)
3719 and then (Ctype = Type_Conformant
3721 Subtypes_Statically_Match (Desig_1, Desig_2));
3725 -- Otherwise definitely no match
3728 if ((Ekind (Type_1) = E_Anonymous_Access_Type
3729 and then Is_Access_Type (Type_2))
3730 or else (Ekind (Type_2) = E_Anonymous_Access_Type
3731 and then Is_Access_Type (Type_1)))
3734 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
3736 May_Hide_Profile := True;
3741 end Conforming_Types;
3743 --------------------------
3744 -- Create_Extra_Formals --
3745 --------------------------
3747 procedure Create_Extra_Formals (E : Entity_Id) is
3749 Last_Extra : Entity_Id;
3750 Formal_Type : Entity_Id;
3751 P_Formal : Entity_Id := Empty;
3753 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id;
3754 -- Add an extra formal, associated with the current Formal. The extra
3755 -- formal is added to the list of extra formals, and also returned as
3756 -- the result. These formals are always of mode IN.
3758 ----------------------
3759 -- Add_Extra_Formal --
3760 ----------------------
3762 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is
3763 EF : constant Entity_Id :=
3764 Make_Defining_Identifier (Sloc (Formal),
3765 Chars => New_External_Name (Chars (Formal), 'F
'));
3768 -- We never generate extra formals if expansion is not active
3769 -- because we don't need them unless we are generating code.
3771 if not Expander_Active then
3775 -- A little optimization. Never generate an extra formal for the
3776 -- _init operand of an initialization procedure, since it could
3779 if Chars (Formal) = Name_uInit then
3783 Set_Ekind (EF, E_In_Parameter);
3784 Set_Actual_Subtype (EF, Typ);
3785 Set_Etype (EF, Typ);
3786 Set_Scope (EF, Scope (Formal));
3787 Set_Mechanism (EF, Default_Mechanism);
3788 Set_Formal_Validity (EF);
3790 Set_Extra_Formal (Last_Extra, EF);
3793 end Add_Extra_Formal;
3795 -- Start of processing for Create_Extra_Formals
3798 -- If this is a derived subprogram then the subtypes of the parent
3799 -- subprogram's formal parameters will be used to to determine the need
3800 -- for extra formals.
3802 if Is_Overloadable (E) and then Present (Alias (E)) then
3803 P_Formal := First_Formal (Alias (E));
3806 Last_Extra := Empty;
3807 Formal := First_Formal (E);
3808 while Present (Formal) loop
3809 Last_Extra := Formal;
3810 Next_Formal (Formal);
3813 -- If Extra_formals where already created, don't do it again. This
3814 -- situation may arise for subprogram types created as part of
3815 -- dispatching calls (see Expand_Dispatching_Call)
3817 if Present (Last_Extra) and then
3818 Present (Extra_Formal (Last_Extra))
3823 Formal := First_Formal (E);
3825 while Present (Formal) loop
3827 -- Create extra formal for supporting the attribute 'Constrained
.
3828 -- The case of a private type view without discriminants also
3829 -- requires the extra formal if the underlying type has defaulted
3832 if Ekind
(Formal
) /= E_In_Parameter
then
3833 if Present
(P_Formal
) then
3834 Formal_Type
:= Etype
(P_Formal
);
3836 Formal_Type
:= Etype
(Formal
);
3839 -- Do not produce extra formals for Unchecked_Union parameters.
3840 -- Jump directly to the end of the loop.
3842 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
3843 goto Skip_Extra_Formal_Generation
;
3846 if not Has_Discriminants
(Formal_Type
)
3847 and then Ekind
(Formal_Type
) in Private_Kind
3848 and then Present
(Underlying_Type
(Formal_Type
))
3850 Formal_Type
:= Underlying_Type
(Formal_Type
);
3853 if Has_Discriminants
(Formal_Type
)
3855 ((not Is_Constrained
(Formal_Type
)
3856 and then not Is_Indefinite_Subtype
(Formal_Type
))
3857 or else Present
(Extra_Formal
(Formal
)))
3859 Set_Extra_Constrained
3860 (Formal
, Add_Extra_Formal
(Standard_Boolean
));
3864 -- Create extra formal for supporting accessibility checking
3866 -- This is suppressed if we specifically suppress accessibility
3867 -- checks at the pacage level for either the subprogram, or the
3868 -- package in which it resides. However, we do not suppress it
3869 -- simply if the scope has accessibility checks suppressed, since
3870 -- this could cause trouble when clients are compiled with a
3871 -- different suppression setting. The explicit checks at the
3872 -- package level are safe from this point of view.
3874 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
3876 (Explicit_Suppress
(E
, Accessibility_Check
)
3878 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
3881 or else Present
(Extra_Accessibility
(P_Formal
)))
3883 -- Temporary kludge: for now we avoid creating the extra formal
3884 -- for access parameters of protected operations because of
3885 -- problem with the case of internal protected calls. ???
3887 if Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Definition
3888 and then Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Body
3890 Set_Extra_Accessibility
3891 (Formal
, Add_Extra_Formal
(Standard_Natural
));
3895 if Present
(P_Formal
) then
3896 Next_Formal
(P_Formal
);
3899 -- This label is required when skipping extra formal generation for
3900 -- Unchecked_Union parameters.
3902 <<Skip_Extra_Formal_Generation
>>
3904 Next_Formal
(Formal
);
3906 end Create_Extra_Formals
;
3908 -----------------------------
3909 -- Enter_Overloaded_Entity --
3910 -----------------------------
3912 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
3913 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
3914 C_E
: Entity_Id
:= Current_Entity
(S
);
3918 Set_Has_Homonym
(E
);
3919 Set_Has_Homonym
(S
);
3922 Set_Is_Immediately_Visible
(S
);
3923 Set_Scope
(S
, Current_Scope
);
3925 -- Chain new entity if front of homonym in current scope, so that
3926 -- homonyms are contiguous.
3931 while Homonym
(C_E
) /= E
loop
3932 C_E
:= Homonym
(C_E
);
3935 Set_Homonym
(C_E
, S
);
3939 Set_Current_Entity
(S
);
3944 Append_Entity
(S
, Current_Scope
);
3945 Set_Public_Status
(S
);
3947 if Debug_Flag_E
then
3948 Write_Str
("New overloaded entity chain: ");
3949 Write_Name
(Chars
(S
));
3952 while Present
(E
) loop
3953 Write_Str
(" "); Write_Int
(Int
(E
));
3960 -- Generate warning for hiding
3963 and then Comes_From_Source
(S
)
3964 and then In_Extended_Main_Source_Unit
(S
)
3971 -- Warn unless genuine overloading
3973 if (not Is_Overloadable
(E
))
3974 or else Subtype_Conformant
(E
, S
)
3976 Error_Msg_Sloc
:= Sloc
(E
);
3977 Error_Msg_N
("declaration of & hides one#?", S
);
3981 end Enter_Overloaded_Entity
;
3983 -----------------------------
3984 -- Find_Corresponding_Spec --
3985 -----------------------------
3987 function Find_Corresponding_Spec
(N
: Node_Id
) return Entity_Id
is
3988 Spec
: constant Node_Id
:= Specification
(N
);
3989 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
3994 E
:= Current_Entity
(Designator
);
3996 while Present
(E
) loop
3998 -- We are looking for a matching spec. It must have the same scope,
3999 -- and the same name, and either be type conformant, or be the case
4000 -- of a library procedure spec and its body (which belong to one
4001 -- another regardless of whether they are type conformant or not).
4003 if Scope
(E
) = Current_Scope
then
4004 if Current_Scope
= Standard_Standard
4005 or else (Ekind
(E
) = Ekind
(Designator
)
4006 and then Type_Conformant
(E
, Designator
))
4008 -- Within an instantiation, we know that spec and body are
4009 -- subtype conformant, because they were subtype conformant
4010 -- in the generic. We choose the subtype-conformant entity
4011 -- here as well, to resolve spurious ambiguities in the
4012 -- instance that were not present in the generic (i.e. when
4013 -- two different types are given the same actual). If we are
4014 -- looking for a spec to match a body, full conformance is
4018 Set_Convention
(Designator
, Convention
(E
));
4020 if Nkind
(N
) = N_Subprogram_Body
4021 and then Present
(Homonym
(E
))
4022 and then not Fully_Conformant
(E
, Designator
)
4026 elsif not Subtype_Conformant
(E
, Designator
) then
4031 if not Has_Completion
(E
) then
4033 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
4034 Set_Corresponding_Spec
(N
, E
);
4037 Set_Has_Completion
(E
);
4040 elsif Nkind
(Parent
(N
)) = N_Subunit
then
4042 -- If this is the proper body of a subunit, the completion
4043 -- flag is set when analyzing the stub.
4047 -- If body already exists, this is an error unless the
4048 -- previous declaration is the implicit declaration of
4049 -- a derived subprogram, or this is a spurious overloading
4052 elsif No
(Alias
(E
))
4053 and then not Is_Intrinsic_Subprogram
(E
)
4054 and then not In_Instance
4056 Error_Msg_Sloc
:= Sloc
(E
);
4057 if Is_Imported
(E
) then
4059 ("body not allowed for imported subprogram & declared#",
4062 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
4066 elsif Is_Child_Unit
(E
)
4068 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
4070 Nkind
(Parent
(Unit_Declaration_Node
(Designator
)))
4071 = N_Compilation_Unit
4074 -- Child units cannot be overloaded, so a conformance mismatch
4075 -- between body and a previous spec is an error.
4078 ("body of child unit does not match previous declaration", N
);
4086 -- On exit, we know that no previous declaration of subprogram exists
4089 end Find_Corresponding_Spec
;
4091 ----------------------
4092 -- Fully_Conformant --
4093 ----------------------
4095 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4098 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
4100 end Fully_Conformant
;
4102 ----------------------------------
4103 -- Fully_Conformant_Expressions --
4104 ----------------------------------
4106 function Fully_Conformant_Expressions
4107 (Given_E1
: Node_Id
;
4108 Given_E2
: Node_Id
) return Boolean
4110 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
4111 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
4112 -- We always test conformance on original nodes, since it is possible
4113 -- for analysis and/or expansion to make things look as though they
4114 -- conform when they do not, e.g. by converting 1+2 into 3.
4116 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
4117 renames Fully_Conformant_Expressions
;
4119 function FCL
(L1
, L2
: List_Id
) return Boolean;
4120 -- Compare elements of two lists for conformance. Elements have to
4121 -- be conformant, and actuals inserted as default parameters do not
4122 -- match explicit actuals with the same value.
4124 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
4125 -- Compare an operator node with a function call
4131 function FCL
(L1
, L2
: List_Id
) return Boolean is
4135 if L1
= No_List
then
4141 if L2
= No_List
then
4147 -- Compare two lists, skipping rewrite insertions (we want to
4148 -- compare the original trees, not the expanded versions!)
4151 if Is_Rewrite_Insertion
(N1
) then
4153 elsif Is_Rewrite_Insertion
(N2
) then
4159 elsif not FCE
(N1
, N2
) then
4172 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
4173 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
4178 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
4183 Act
:= First
(Actuals
);
4185 if Nkind
(Op_Node
) in N_Binary_Op
then
4187 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
4194 return Present
(Act
)
4195 and then FCE
(Right_Opnd
(Op_Node
), Act
)
4196 and then No
(Next
(Act
));
4200 -- Start of processing for Fully_Conformant_Expressions
4203 -- Non-conformant if paren count does not match. Note: if some idiot
4204 -- complains that we don't do this right for more than 3 levels of
4205 -- parentheses, they will be treated with the respect they deserve :-)
4207 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
4210 -- If same entities are referenced, then they are conformant even if
4211 -- they have different forms (RM 8.3.1(19-20)).
4213 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
4214 if Present
(Entity
(E1
)) then
4215 return Entity
(E1
) = Entity
(E2
)
4216 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
4217 and then Ekind
(Entity
(E1
)) = E_Discriminant
4218 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
4220 elsif Nkind
(E1
) = N_Expanded_Name
4221 and then Nkind
(E2
) = N_Expanded_Name
4222 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
4223 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
4225 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
4228 -- Identifiers in component associations don't always have
4229 -- entities, but their names must conform.
4231 return Nkind
(E1
) = N_Identifier
4232 and then Nkind
(E2
) = N_Identifier
4233 and then Chars
(E1
) = Chars
(E2
);
4236 elsif Nkind
(E1
) = N_Character_Literal
4237 and then Nkind
(E2
) = N_Expanded_Name
4239 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
4240 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
4242 elsif Nkind
(E2
) = N_Character_Literal
4243 and then Nkind
(E1
) = N_Expanded_Name
4245 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
4246 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
4248 elsif Nkind
(E1
) in N_Op
4249 and then Nkind
(E2
) = N_Function_Call
4251 return FCO
(E1
, E2
);
4253 elsif Nkind
(E2
) in N_Op
4254 and then Nkind
(E1
) = N_Function_Call
4256 return FCO
(E2
, E1
);
4258 -- Otherwise we must have the same syntactic entity
4260 elsif Nkind
(E1
) /= Nkind
(E2
) then
4263 -- At this point, we specialize by node type
4270 FCL
(Expressions
(E1
), Expressions
(E2
))
4271 and then FCL
(Component_Associations
(E1
),
4272 Component_Associations
(E2
));
4275 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
4277 Nkind
(Expression
(E2
)) = N_Qualified_Expression
4279 return FCE
(Expression
(E1
), Expression
(E2
));
4281 -- Check that the subtype marks and any constraints
4286 Indic1
: constant Node_Id
:= Expression
(E1
);
4287 Indic2
: constant Node_Id
:= Expression
(E2
);
4292 if Nkind
(Indic1
) /= N_Subtype_Indication
then
4294 Nkind
(Indic2
) /= N_Subtype_Indication
4295 and then Entity
(Indic1
) = Entity
(Indic2
);
4297 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
4299 Nkind
(Indic1
) /= N_Subtype_Indication
4300 and then Entity
(Indic1
) = Entity
(Indic2
);
4303 if Entity
(Subtype_Mark
(Indic1
)) /=
4304 Entity
(Subtype_Mark
(Indic2
))
4309 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
4310 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
4312 while Present
(Elt1
) and then Present
(Elt2
) loop
4313 if not FCE
(Elt1
, Elt2
) then
4326 when N_Attribute_Reference
=>
4328 Attribute_Name
(E1
) = Attribute_Name
(E2
)
4329 and then FCL
(Expressions
(E1
), Expressions
(E2
));
4333 Entity
(E1
) = Entity
(E2
)
4334 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
4335 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
4337 when N_And_Then | N_Or_Else | N_In | N_Not_In
=>
4339 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
4341 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
4343 when N_Character_Literal
=>
4345 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
4347 when N_Component_Association
=>
4349 FCL
(Choices
(E1
), Choices
(E2
))
4350 and then FCE
(Expression
(E1
), Expression
(E2
));
4352 when N_Conditional_Expression
=>
4354 FCL
(Expressions
(E1
), Expressions
(E2
));
4356 when N_Explicit_Dereference
=>
4358 FCE
(Prefix
(E1
), Prefix
(E2
));
4360 when N_Extension_Aggregate
=>
4362 FCL
(Expressions
(E1
), Expressions
(E2
))
4363 and then Null_Record_Present
(E1
) =
4364 Null_Record_Present
(E2
)
4365 and then FCL
(Component_Associations
(E1
),
4366 Component_Associations
(E2
));
4368 when N_Function_Call
=>
4370 FCE
(Name
(E1
), Name
(E2
))
4371 and then FCL
(Parameter_Associations
(E1
),
4372 Parameter_Associations
(E2
));
4374 when N_Indexed_Component
=>
4376 FCE
(Prefix
(E1
), Prefix
(E2
))
4377 and then FCL
(Expressions
(E1
), Expressions
(E2
));
4379 when N_Integer_Literal
=>
4380 return (Intval
(E1
) = Intval
(E2
));
4385 when N_Operator_Symbol
=>
4387 Chars
(E1
) = Chars
(E2
);
4389 when N_Others_Choice
=>
4392 when N_Parameter_Association
=>
4394 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
4395 and then FCE
(Explicit_Actual_Parameter
(E1
),
4396 Explicit_Actual_Parameter
(E2
));
4398 when N_Qualified_Expression
=>
4400 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
4401 and then FCE
(Expression
(E1
), Expression
(E2
));
4405 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
4406 and then FCE
(High_Bound
(E1
), High_Bound
(E2
));
4408 when N_Real_Literal
=>
4409 return (Realval
(E1
) = Realval
(E2
));
4411 when N_Selected_Component
=>
4413 FCE
(Prefix
(E1
), Prefix
(E2
))
4414 and then FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
4418 FCE
(Prefix
(E1
), Prefix
(E2
))
4419 and then FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
4421 when N_String_Literal
=>
4423 S1
: constant String_Id
:= Strval
(E1
);
4424 S2
: constant String_Id
:= Strval
(E2
);
4425 L1
: constant Nat
:= String_Length
(S1
);
4426 L2
: constant Nat
:= String_Length
(S2
);
4433 for J
in 1 .. L1
loop
4434 if Get_String_Char
(S1
, J
) /=
4435 Get_String_Char
(S2
, J
)
4445 when N_Type_Conversion
=>
4447 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
4448 and then FCE
(Expression
(E1
), Expression
(E2
));
4452 Entity
(E1
) = Entity
(E2
)
4453 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
4455 when N_Unchecked_Type_Conversion
=>
4457 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
4458 and then FCE
(Expression
(E1
), Expression
(E2
));
4460 -- All other node types cannot appear in this context. Strictly
4461 -- we should raise a fatal internal error. Instead we just ignore
4462 -- the nodes. This means that if anyone makes a mistake in the
4463 -- expander and mucks an expression tree irretrievably, the
4464 -- result will be a failure to detect a (probably very obscure)
4465 -- case of non-conformance, which is better than bombing on some
4466 -- case where two expressions do in fact conform.
4473 end Fully_Conformant_Expressions
;
4475 ----------------------------------------
4476 -- Fully_Conformant_Discrete_Subtypes --
4477 ----------------------------------------
4479 function Fully_Conformant_Discrete_Subtypes
4480 (Given_S1
: Node_Id
;
4481 Given_S2
: Node_Id
) return Boolean
4483 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
4484 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
4486 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
4487 -- Special-case for a bound given by a discriminant, which in the body
4488 -- is replaced with the discriminal of the enclosing type.
4490 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
4491 -- Check both bounds
4493 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
4495 if Is_Entity_Name
(B1
)
4496 and then Is_Entity_Name
(B2
)
4497 and then Ekind
(Entity
(B1
)) = E_Discriminant
4499 return Chars
(B1
) = Chars
(B2
);
4502 return Fully_Conformant_Expressions
(B1
, B2
);
4504 end Conforming_Bounds
;
4506 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
4509 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
4511 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
4512 end Conforming_Ranges
;
4514 -- Start of processing for Fully_Conformant_Discrete_Subtypes
4517 if Nkind
(S1
) /= Nkind
(S2
) then
4520 elsif Is_Entity_Name
(S1
) then
4521 return Entity
(S1
) = Entity
(S2
);
4523 elsif Nkind
(S1
) = N_Range
then
4524 return Conforming_Ranges
(S1
, S2
);
4526 elsif Nkind
(S1
) = N_Subtype_Indication
then
4528 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
4531 (Range_Expression
(Constraint
(S1
)),
4532 Range_Expression
(Constraint
(S2
)));
4536 end Fully_Conformant_Discrete_Subtypes
;
4538 --------------------
4539 -- Install_Entity --
4540 --------------------
4542 procedure Install_Entity
(E
: Entity_Id
) is
4543 Prev
: constant Entity_Id
:= Current_Entity
(E
);
4545 Set_Is_Immediately_Visible
(E
);
4546 Set_Current_Entity
(E
);
4547 Set_Homonym
(E
, Prev
);
4550 ---------------------
4551 -- Install_Formals --
4552 ---------------------
4554 procedure Install_Formals
(Id
: Entity_Id
) is
4557 F
:= First_Formal
(Id
);
4558 while Present
(F
) loop
4562 end Install_Formals
;
4564 ---------------------------------
4565 -- Is_Non_Overriding_Operation --
4566 ---------------------------------
4568 function Is_Non_Overriding_Operation
4569 (Prev_E
: Entity_Id
;
4570 New_E
: Entity_Id
) return Boolean
4574 G_Typ
: Entity_Id
:= Empty
;
4576 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
4577 -- If F_Type is a derived type associated with a generic actual
4578 -- subtype, then return its Generic_Parent_Type attribute, else return
4581 function Types_Correspond
4582 (P_Type
: Entity_Id
;
4583 N_Type
: Entity_Id
) return Boolean;
4584 -- Returns true if and only if the types (or designated types in the
4585 -- case of anonymous access types) are the same or N_Type is derived
4586 -- directly or indirectly from P_Type.
4588 -----------------------------
4589 -- Get_Generic_Parent_Type --
4590 -----------------------------
4592 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
4597 if Is_Derived_Type
(F_Typ
)
4598 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
4600 -- The tree must be traversed to determine the parent subtype in
4601 -- the generic unit, which unfortunately isn't always available
4602 -- via semantic attributes. ??? (Note: The use of Original_Node
4603 -- is needed for cases where a full derived type has been
4606 Indic
:= Subtype_Indication
4607 (Type_Definition
(Original_Node
(Parent
(F_Typ
))));
4609 if Nkind
(Indic
) = N_Subtype_Indication
then
4610 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
4612 G_Typ
:= Entity
(Indic
);
4615 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
4616 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
4618 return Generic_Parent_Type
(Parent
(G_Typ
));
4623 end Get_Generic_Parent_Type
;
4625 ----------------------
4626 -- Types_Correspond --
4627 ----------------------
4629 function Types_Correspond
4630 (P_Type
: Entity_Id
;
4631 N_Type
: Entity_Id
) return Boolean
4633 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
4634 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
4637 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
4638 Prev_Type
:= Designated_Type
(Prev_Type
);
4641 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
4642 New_Type
:= Designated_Type
(New_Type
);
4645 if Prev_Type
= New_Type
then
4648 elsif not Is_Class_Wide_Type
(New_Type
) then
4649 while Etype
(New_Type
) /= New_Type
loop
4650 New_Type
:= Etype
(New_Type
);
4651 if New_Type
= Prev_Type
then
4657 end Types_Correspond
;
4659 -- Start of processing for Is_Non_Overriding_Operation
4662 -- In the case where both operations are implicit derived subprograms
4663 -- then neither overrides the other. This can only occur in certain
4664 -- obscure cases (e.g., derivation from homographs created in a generic
4667 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
4670 elsif Ekind
(Current_Scope
) = E_Package
4671 and then Is_Generic_Instance
(Current_Scope
)
4672 and then In_Private_Part
(Current_Scope
)
4673 and then Comes_From_Source
(New_E
)
4675 -- We examine the formals and result subtype of the inherited
4676 -- operation, to determine whether their type is derived from (the
4677 -- instance of) a generic type.
4679 Formal
:= First_Formal
(Prev_E
);
4681 while Present
(Formal
) loop
4682 F_Typ
:= Base_Type
(Etype
(Formal
));
4684 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4685 F_Typ
:= Designated_Type
(F_Typ
);
4688 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
4690 Next_Formal
(Formal
);
4693 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
4694 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
4701 -- If the generic type is a private type, then the original
4702 -- operation was not overriding in the generic, because there was
4703 -- no primitive operation to override.
4705 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
4706 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
4707 N_Formal_Private_Type_Definition
4711 -- The generic parent type is the ancestor of a formal derived
4712 -- type declaration. We need to check whether it has a primitive
4713 -- operation that should be overridden by New_E in the generic.
4717 P_Formal
: Entity_Id
;
4718 N_Formal
: Entity_Id
;
4722 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
4725 while Present
(Prim_Elt
) loop
4726 P_Prim
:= Node
(Prim_Elt
);
4728 if Chars
(P_Prim
) = Chars
(New_E
)
4729 and then Ekind
(P_Prim
) = Ekind
(New_E
)
4731 P_Formal
:= First_Formal
(P_Prim
);
4732 N_Formal
:= First_Formal
(New_E
);
4733 while Present
(P_Formal
) and then Present
(N_Formal
) loop
4734 P_Typ
:= Etype
(P_Formal
);
4735 N_Typ
:= Etype
(N_Formal
);
4737 if not Types_Correspond
(P_Typ
, N_Typ
) then
4741 Next_Entity
(P_Formal
);
4742 Next_Entity
(N_Formal
);
4745 -- Found a matching primitive operation belonging to the
4746 -- formal ancestor type, so the new subprogram is
4750 and then No
(N_Formal
)
4751 and then (Ekind
(New_E
) /= E_Function
4754 (Etype
(P_Prim
), Etype
(New_E
)))
4760 Next_Elmt
(Prim_Elt
);
4763 -- If no match found, then the new subprogram does not
4764 -- override in the generic (nor in the instance).
4772 end Is_Non_Overriding_Operation
;
4774 ------------------------------
4775 -- Make_Inequality_Operator --
4776 ------------------------------
4778 -- S is the defining identifier of an equality operator. We build a
4779 -- subprogram declaration with the right signature. This operation is
4780 -- intrinsic, because it is always expanded as the negation of the
4781 -- call to the equality function.
4783 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
4784 Loc
: constant Source_Ptr
:= Sloc
(S
);
4787 Op_Name
: Entity_Id
;
4789 FF
: constant Entity_Id
:= First_Formal
(S
);
4790 NF
: constant Entity_Id
:= Next_Formal
(FF
);
4793 -- Check that equality was properly defined, ignore call if not
4800 A
: constant Entity_Id
:=
4801 Make_Defining_Identifier
(Sloc
(FF
),
4802 Chars
=> Chars
(FF
));
4804 B
: constant Entity_Id
:=
4805 Make_Defining_Identifier
(Sloc
(NF
),
4806 Chars
=> Chars
(NF
));
4809 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
4811 Formals
:= New_List
(
4812 Make_Parameter_Specification
(Loc
,
4813 Defining_Identifier
=> A
,
4815 New_Reference_To
(Etype
(First_Formal
(S
)),
4816 Sloc
(Etype
(First_Formal
(S
))))),
4818 Make_Parameter_Specification
(Loc
,
4819 Defining_Identifier
=> B
,
4821 New_Reference_To
(Etype
(Next_Formal
(First_Formal
(S
))),
4822 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
4825 Make_Subprogram_Declaration
(Loc
,
4827 Make_Function_Specification
(Loc
,
4828 Defining_Unit_Name
=> Op_Name
,
4829 Parameter_Specifications
=> Formals
,
4830 Result_Definition
=>
4831 New_Reference_To
(Standard_Boolean
, Loc
)));
4833 -- Insert inequality right after equality if it is explicit or after
4834 -- the derived type when implicit. These entities are created only
4835 -- for visibility purposes, and eventually replaced in the course of
4836 -- expansion, so they do not need to be attached to the tree and seen
4837 -- by the back-end. Keeping them internal also avoids spurious
4838 -- freezing problems. The declaration is inserted in the tree for
4839 -- analysis, and removed afterwards. If the equality operator comes
4840 -- from an explicit declaration, attach the inequality immediately
4841 -- after. Else the equality is inherited from a derived type
4842 -- declaration, so insert inequality after that declaration.
4844 if No
(Alias
(S
)) then
4845 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
4846 elsif Is_List_Member
(Parent
(S
)) then
4847 Insert_After
(Parent
(S
), Decl
);
4849 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
4852 Mark_Rewrite_Insertion
(Decl
);
4853 Set_Is_Intrinsic_Subprogram
(Op_Name
);
4856 Set_Has_Completion
(Op_Name
);
4857 Set_Corresponding_Equality
(Op_Name
, S
);
4858 Set_Is_Abstract
(Op_Name
, Is_Abstract
(S
));
4860 end Make_Inequality_Operator
;
4862 ----------------------
4863 -- May_Need_Actuals --
4864 ----------------------
4866 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
4871 F
:= First_Formal
(Fun
);
4874 while Present
(F
) loop
4875 if No
(Default_Value
(F
)) then
4883 Set_Needs_No_Actuals
(Fun
, B
);
4884 end May_Need_Actuals
;
4886 ---------------------
4887 -- Mode_Conformant --
4888 ---------------------
4890 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4893 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
4895 end Mode_Conformant
;
4897 ---------------------------
4898 -- New_Overloaded_Entity --
4899 ---------------------------
4901 procedure New_Overloaded_Entity
4903 Derived_Type
: Entity_Id
:= Empty
)
4905 Does_Override
: Boolean := False;
4906 -- Set if the current scope has an operation that is type-conformant
4907 -- with S, and becomes hidden by S.
4910 -- Entity that S overrides
4912 Prev_Vis
: Entity_Id
:= Empty
;
4913 -- Needs comment ???
4915 Is_Alias_Interface
: Boolean := False;
4917 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
4918 -- Check that E is declared in the private part of the current package,
4919 -- or in the package body, where it may hide a previous declaration.
4920 -- We can't use In_Private_Part by itself because this flag is also
4921 -- set when freezing entities, so we must examine the place of the
4922 -- declaration in the tree, and recognize wrapper packages as well.
4924 procedure Maybe_Primitive_Operation
(Is_Overriding
: Boolean := False);
4925 -- If the subprogram being analyzed is a primitive operation of
4926 -- the type of one of its formals, set the corresponding flag.
4928 ----------------------------
4929 -- Is_Private_Declaration --
4930 ----------------------------
4932 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
4933 Priv_Decls
: List_Id
;
4934 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
4937 if Is_Package_Or_Generic_Package
(Current_Scope
)
4938 and then In_Private_Part
(Current_Scope
)
4941 Private_Declarations
(
4942 Specification
(Unit_Declaration_Node
(Current_Scope
)));
4944 return In_Package_Body
(Current_Scope
)
4946 (Is_List_Member
(Decl
)
4947 and then List_Containing
(Decl
) = Priv_Decls
)
4948 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
4949 and then not Is_Compilation_Unit
(
4950 Defining_Entity
(Parent
(Decl
)))
4951 and then List_Containing
(Parent
(Parent
(Decl
)))
4956 end Is_Private_Declaration
;
4958 -------------------------------
4959 -- Maybe_Primitive_Operation --
4960 -------------------------------
4962 procedure Maybe_Primitive_Operation
(Is_Overriding
: Boolean := False) is
4967 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
4968 -- Returns true if T is declared in the visible part of
4969 -- the current package scope; otherwise returns false.
4970 -- Assumes that T is declared in a package.
4972 procedure Check_Private_Overriding
(T
: Entity_Id
);
4973 -- Checks that if a primitive abstract subprogram of a visible
4974 -- abstract type is declared in a private part, then it must
4975 -- override an abstract subprogram declared in the visible part.
4976 -- Also checks that if a primitive function with a controlling
4977 -- result is declared in a private part, then it must override
4978 -- a function declared in the visible part.
4980 ------------------------------
4981 -- Check_Private_Overriding --
4982 ------------------------------
4984 procedure Check_Private_Overriding
(T
: Entity_Id
) is
4986 if Ekind
(Current_Scope
) = E_Package
4987 and then In_Private_Part
(Current_Scope
)
4988 and then Visible_Part_Type
(T
)
4989 and then not In_Instance
4992 and then Is_Abstract
(S
)
4993 and then (not Is_Overriding
or else not Is_Abstract
(E
))
4995 if not Is_Interface
(T
) then
4996 Error_Msg_N
("abstract subprograms must be visible "
4997 & "('R'M 3.9.3(10))!", S
);
4999 -- Ada 2005 (AI-251)
5002 Error_Msg_N
("primitive subprograms of interface types "
5003 & "declared in a visible part, must be declared in "
5004 & "the visible part ('R'M 3.9.4)!", S
);
5007 elsif Ekind
(S
) = E_Function
5008 and then Is_Tagged_Type
(T
)
5009 and then T
= Base_Type
(Etype
(S
))
5010 and then not Is_Overriding
5013 ("private function with tagged result must"
5014 & " override visible-part function", S
);
5016 ("\move subprogram to the visible part"
5017 & " ('R'M 3.9.3(10))", S
);
5020 end Check_Private_Overriding
;
5022 -----------------------
5023 -- Visible_Part_Type --
5024 -----------------------
5026 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
5027 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
5031 -- If the entity is a private type, then it must be
5032 -- declared in a visible part.
5034 if Ekind
(T
) in Private_Kind
then
5038 -- Otherwise, we traverse the visible part looking for its
5039 -- corresponding declaration. We cannot use the declaration
5040 -- node directly because in the private part the entity of a
5041 -- private type is the one in the full view, which does not
5042 -- indicate that it is the completion of something visible.
5044 N
:= First
(Visible_Declarations
(Specification
(P
)));
5045 while Present
(N
) loop
5046 if Nkind
(N
) = N_Full_Type_Declaration
5047 and then Present
(Defining_Identifier
(N
))
5048 and then T
= Defining_Identifier
(N
)
5052 elsif (Nkind
(N
) = N_Private_Type_Declaration
5054 Nkind
(N
) = N_Private_Extension_Declaration
)
5055 and then Present
(Defining_Identifier
(N
))
5056 and then T
= Full_View
(Defining_Identifier
(N
))
5065 end Visible_Part_Type
;
5067 -- Start of processing for Maybe_Primitive_Operation
5070 if not Comes_From_Source
(S
) then
5073 -- If the subprogram is at library level, it is not primitive
5076 elsif Current_Scope
= Standard_Standard
then
5079 elsif (Ekind
(Current_Scope
) = E_Package
5080 and then not In_Package_Body
(Current_Scope
))
5081 or else Is_Overriding
5083 -- For function, check return type
5085 if Ekind
(S
) = E_Function
then
5086 B_Typ
:= Base_Type
(Etype
(S
));
5088 if Scope
(B_Typ
) = Current_Scope
then
5089 Set_Has_Primitive_Operations
(B_Typ
);
5090 Check_Private_Overriding
(B_Typ
);
5094 -- For all subprograms, check formals
5096 Formal
:= First_Formal
(S
);
5097 while Present
(Formal
) loop
5098 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
5099 F_Typ
:= Designated_Type
(Etype
(Formal
));
5101 F_Typ
:= Etype
(Formal
);
5104 B_Typ
:= Base_Type
(F_Typ
);
5106 if Scope
(B_Typ
) = Current_Scope
then
5107 Set_Has_Primitive_Operations
(B_Typ
);
5108 Check_Private_Overriding
(B_Typ
);
5111 Next_Formal
(Formal
);
5114 end Maybe_Primitive_Operation
;
5116 -- Start of processing for New_Overloaded_Entity
5119 -- We need to look for an entity that S may override. This must be a
5120 -- homonym in the current scope, so we look for the first homonym of
5121 -- S in the current scope as the starting point for the search.
5123 E
:= Current_Entity_In_Scope
(S
);
5125 -- If there is no homonym then this is definitely not overriding
5128 Enter_Overloaded_Entity
(S
);
5129 Check_Dispatching_Operation
(S
, Empty
);
5130 Maybe_Primitive_Operation
;
5132 -- Ada 2005 (AI-397): Subprograms in the context of protected
5133 -- types have their overriding indicators checked in Sem_Ch9.
5135 if Ekind
(S
) not in Subprogram_Kind
5136 or else Ekind
(Scope
(S
)) /= E_Protected_Type
5138 Check_Overriding_Indicator
(S
, False);
5141 -- If there is a homonym that is not overloadable, then we have an
5142 -- error, except for the special cases checked explicitly below.
5144 elsif not Is_Overloadable
(E
) then
5146 -- Check for spurious conflict produced by a subprogram that has the
5147 -- same name as that of the enclosing generic package. The conflict
5148 -- occurs within an instance, between the subprogram and the renaming
5149 -- declaration for the package. After the subprogram, the package
5150 -- renaming declaration becomes hidden.
5152 if Ekind
(E
) = E_Package
5153 and then Present
(Renamed_Object
(E
))
5154 and then Renamed_Object
(E
) = Current_Scope
5155 and then Nkind
(Parent
(Renamed_Object
(E
))) =
5156 N_Package_Specification
5157 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
5160 Set_Is_Immediately_Visible
(E
, False);
5161 Enter_Overloaded_Entity
(S
);
5162 Set_Homonym
(S
, Homonym
(E
));
5163 Check_Dispatching_Operation
(S
, Empty
);
5164 Check_Overriding_Indicator
(S
, False);
5166 -- If the subprogram is implicit it is hidden by the previous
5167 -- declaration. However if it is dispatching, it must appear in the
5168 -- dispatch table anyway, because it can be dispatched to even if it
5169 -- cannot be called directly.
5171 elsif Present
(Alias
(S
))
5172 and then not Comes_From_Source
(S
)
5174 Set_Scope
(S
, Current_Scope
);
5176 if Is_Dispatching_Operation
(Alias
(S
)) then
5177 Check_Dispatching_Operation
(S
, Empty
);
5183 Error_Msg_Sloc
:= Sloc
(E
);
5184 Error_Msg_N
("& conflicts with declaration#", S
);
5186 -- Useful additional warning
5188 if Is_Generic_Unit
(E
) then
5189 Error_Msg_N
("\previous generic unit cannot be overloaded", S
);
5195 -- E exists and is overloadable
5198 Is_Alias_Interface
:=
5200 and then Is_Dispatching_Operation
(Alias
(S
))
5201 and then Present
(DTC_Entity
(Alias
(S
)))
5202 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(S
))));
5204 -- Loop through E and its homonyms to determine if any of them is
5205 -- the candidate for overriding by S.
5207 while Present
(E
) loop
5209 -- Definitely not interesting if not in the current scope
5211 if Scope
(E
) /= Current_Scope
then
5214 -- Check if we have type conformance
5216 -- Ada 2005 (AI-251): In case of overriding an interface
5217 -- subprogram it is not an error that the old and new entities
5218 -- have the same profile, and hence we skip this code.
5220 elsif not Is_Alias_Interface
5221 and then Type_Conformant
(E
, S
)
5223 -- Ada 2005 (AI-251): Do not consider here entities that cover
5224 -- abstract interface primitives. They will be handled after
5225 -- the overriden entity is found (see comments bellow inside
5226 -- this subprogram).
5228 and then not (Is_Subprogram
(E
)
5229 and then Present
(Abstract_Interface_Alias
(E
)))
5231 -- If the old and new entities have the same profile and one
5232 -- is not the body of the other, then this is an error, unless
5233 -- one of them is implicitly declared.
5235 -- There are some cases when both can be implicit, for example
5236 -- when both a literal and a function that overrides it are
5237 -- inherited in a derivation, or when an inhertited operation
5238 -- of a tagged full type overrides the ineherited operation of
5239 -- a private extension. Ada 83 had a special rule for the the
5240 -- literal case. In Ada95, the later implicit operation hides
5241 -- the former, and the literal is always the former. In the
5242 -- odd case where both are derived operations declared at the
5243 -- same point, both operations should be declared, and in that
5244 -- case we bypass the following test and proceed to the next
5245 -- part (this can only occur for certain obscure cases
5246 -- involving homographs in instances and can't occur for
5247 -- dispatching operations ???). Note that the following
5248 -- condition is less than clear. For example, it's not at all
5249 -- clear why there's a test for E_Entry here. ???
5251 if Present
(Alias
(S
))
5252 and then (No
(Alias
(E
))
5253 or else Comes_From_Source
(E
)
5254 or else Is_Dispatching_Operation
(E
))
5256 (Ekind
(E
) = E_Entry
5257 or else Ekind
(E
) /= E_Enumeration_Literal
)
5259 -- When an derived operation is overloaded it may be due to
5260 -- the fact that the full view of a private extension
5261 -- re-inherits. It has to be dealt with.
5263 if Is_Package_Or_Generic_Package
(Current_Scope
)
5264 and then In_Private_Part
(Current_Scope
)
5266 Check_Operation_From_Private_View
(S
, E
);
5269 -- In any case the implicit operation remains hidden by
5270 -- the existing declaration, which is overriding.
5272 Set_Is_Overriding_Operation
(E
);
5274 if Comes_From_Source
(E
) then
5275 Check_Overriding_Indicator
(E
, True);
5277 -- Indicate that E overrides the operation from which
5280 if Present
(Alias
(S
)) then
5281 Set_Overridden_Operation
(E
, Alias
(S
));
5283 Set_Overridden_Operation
(E
, S
);
5289 -- Within an instance, the renaming declarations for
5290 -- actual subprograms may become ambiguous, but they do
5291 -- not hide each other.
5293 elsif Ekind
(E
) /= E_Entry
5294 and then not Comes_From_Source
(E
)
5295 and then not Is_Generic_Instance
(E
)
5296 and then (Present
(Alias
(E
))
5297 or else Is_Intrinsic_Subprogram
(E
))
5298 and then (not In_Instance
5299 or else No
(Parent
(E
))
5300 or else Nkind
(Unit_Declaration_Node
(E
)) /=
5301 N_Subprogram_Renaming_Declaration
)
5303 -- A subprogram child unit is not allowed to override
5304 -- an inherited subprogram (10.1.1(20)).
5306 if Is_Child_Unit
(S
) then
5308 ("child unit overrides inherited subprogram in parent",
5313 if Is_Non_Overriding_Operation
(E
, S
) then
5314 Enter_Overloaded_Entity
(S
);
5315 if No
(Derived_Type
)
5316 or else Is_Tagged_Type
(Derived_Type
)
5318 Check_Dispatching_Operation
(S
, Empty
);
5324 -- E is a derived operation or an internal operator which
5325 -- is being overridden. Remove E from further visibility.
5326 -- Furthermore, if E is a dispatching operation, it must be
5327 -- replaced in the list of primitive operations of its type
5328 -- (see Override_Dispatching_Operation).
5330 Does_Override
:= True;
5336 Prev
:= First_Entity
(Current_Scope
);
5338 while Present
(Prev
)
5339 and then Next_Entity
(Prev
) /= E
5344 -- It is possible for E to be in the current scope and
5345 -- yet not in the entity chain. This can only occur in a
5346 -- generic context where E is an implicit concatenation
5347 -- in the formal part, because in a generic body the
5348 -- entity chain starts with the formals.
5351 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
5353 -- E must be removed both from the entity_list of the
5354 -- current scope, and from the visibility chain
5356 if Debug_Flag_E
then
5357 Write_Str
("Override implicit operation ");
5358 Write_Int
(Int
(E
));
5362 -- If E is a predefined concatenation, it stands for four
5363 -- different operations. As a result, a single explicit
5364 -- declaration does not hide it. In a possible ambiguous
5365 -- situation, Disambiguate chooses the user-defined op,
5366 -- so it is correct to retain the previous internal one.
5368 if Chars
(E
) /= Name_Op_Concat
5369 or else Ekind
(E
) /= E_Operator
5371 -- For nondispatching derived operations that are
5372 -- overridden by a subprogram declared in the private
5373 -- part of a package, we retain the derived
5374 -- subprogram but mark it as not immediately visible.
5375 -- If the derived operation was declared in the
5376 -- visible part then this ensures that it will still
5377 -- be visible outside the package with the proper
5378 -- signature (calls from outside must also be
5379 -- directed to this version rather than the
5380 -- overriding one, unlike the dispatching case).
5381 -- Calls from inside the package will still resolve
5382 -- to the overriding subprogram since the derived one
5383 -- is marked as not visible within the package.
5385 -- If the private operation is dispatching, we achieve
5386 -- the overriding by keeping the implicit operation
5387 -- but setting its alias to be the overriding one. In
5388 -- this fashion the proper body is executed in all
5389 -- cases, but the original signature is used outside
5392 -- If the overriding is not in the private part, we
5393 -- remove the implicit operation altogether.
5395 if Is_Private_Declaration
(S
) then
5397 if not Is_Dispatching_Operation
(E
) then
5398 Set_Is_Immediately_Visible
(E
, False);
5400 -- Work done in Override_Dispatching_Operation,
5401 -- so nothing else need to be done here.
5407 -- Find predecessor of E in Homonym chain
5409 if E
= Current_Entity
(E
) then
5412 Prev_Vis
:= Current_Entity
(E
);
5413 while Homonym
(Prev_Vis
) /= E
loop
5414 Prev_Vis
:= Homonym
(Prev_Vis
);
5418 if Prev_Vis
/= Empty
then
5420 -- Skip E in the visibility chain
5422 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5425 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5428 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5430 if No
(Next_Entity
(Prev
)) then
5431 Set_Last_Entity
(Current_Scope
, Prev
);
5437 Enter_Overloaded_Entity
(S
);
5438 Set_Is_Overriding_Operation
(S
);
5439 Check_Overriding_Indicator
(S
, True);
5441 -- Indicate that S overrides the operation from which
5444 if Comes_From_Source
(S
) then
5445 if Present
(Alias
(E
)) then
5446 Set_Overridden_Operation
(S
, Alias
(E
));
5448 Set_Overridden_Operation
(S
, E
);
5452 if Is_Dispatching_Operation
(E
) then
5454 -- An overriding dispatching subprogram inherits the
5455 -- convention of the overridden subprogram (by
5458 Set_Convention
(S
, Convention
(E
));
5460 -- AI-251: For an entity overriding an interface
5461 -- primitive check if the entity also covers other
5462 -- abstract subprograms in the same scope. This is
5463 -- required to handle the general case, that is,
5464 -- 1) overriding other interface primitives, and
5465 -- 2) overriding abstract subprograms inherited from
5466 -- some abstract ancestor type.
5469 and then Present
(Alias
(E
))
5470 and then Ekind
(Alias
(E
)) /= E_Operator
5471 and then Present
(DTC_Entity
(Alias
(E
)))
5472 and then Is_Interface
(Scope
(DTC_Entity
5480 while Present
(E1
) loop
5481 if (Is_Overloadable
(E1
)
5482 or else Ekind
(E1
) = E_Subprogram_Type
)
5483 and then Present
(Alias
(E1
))
5484 and then Ekind
(Alias
(E1
)) /= E_Operator
5485 and then Present
(DTC_Entity
(Alias
(E1
)))
5486 and then Is_Abstract
5487 (Scope
(DTC_Entity
(Alias
(E1
))))
5488 and then Type_Conformant
(E1
, S
)
5490 Check_Dispatching_Operation
(S
, E1
);
5498 Check_Dispatching_Operation
(S
, E
);
5500 -- AI-251: Handle the case in which the entity
5501 -- overrides a primitive operation that covered
5502 -- several abstract interface primitives.
5507 E1
:= Current_Entity_In_Scope
(S
);
5508 while Present
(E1
) loop
5509 if Is_Subprogram
(E1
)
5511 (Abstract_Interface_Alias
(E1
))
5512 and then Alias
(E1
) = E
5522 Check_Dispatching_Operation
(S
, Empty
);
5525 Maybe_Primitive_Operation
(Is_Overriding
=> True);
5526 goto Check_Inequality
;
5529 -- Apparent redeclarations in instances can occur when two
5530 -- formal types get the same actual type. The subprograms in
5531 -- in the instance are legal, even if not callable from the
5532 -- outside. Calls from within are disambiguated elsewhere.
5533 -- For dispatching operations in the visible part, the usual
5534 -- rules apply, and operations with the same profile are not
5537 elsif (In_Instance_Visible_Part
5538 and then not Is_Dispatching_Operation
(E
))
5539 or else In_Instance_Not_Visible
5543 -- Here we have a real error (identical profile)
5546 Error_Msg_Sloc
:= Sloc
(E
);
5548 -- Avoid cascaded errors if the entity appears in
5549 -- subsequent calls.
5551 Set_Scope
(S
, Current_Scope
);
5553 Error_Msg_N
("& conflicts with declaration#", S
);
5555 if Is_Generic_Instance
(S
)
5556 and then not Has_Completion
(E
)
5559 ("\instantiation cannot provide body for it", S
);
5566 -- If one subprogram has an access parameter and the other
5567 -- a parameter of an access type, calls to either might be
5568 -- ambiguous. Verify that parameters match except for the
5569 -- access parameter.
5571 if May_Hide_Profile
then
5576 F1
:= First_Formal
(S
);
5577 F2
:= First_Formal
(E
);
5578 while Present
(F1
) and then Present
(F2
) loop
5579 if Is_Access_Type
(Etype
(F1
)) then
5580 if not Is_Access_Type
(Etype
(F2
))
5581 or else not Conforming_Types
5582 (Designated_Type
(Etype
(F1
)),
5583 Designated_Type
(Etype
(F2
)),
5586 May_Hide_Profile
:= False;
5590 not Conforming_Types
5591 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
5593 May_Hide_Profile
:= False;
5604 Error_Msg_NE
("calls to& may be ambiguous?", S
, S
);
5614 -- On exit, we know that S is a new entity
5616 Enter_Overloaded_Entity
(S
);
5617 Maybe_Primitive_Operation
;
5618 Check_Overriding_Indicator
(S
, Does_Override
);
5620 -- If S is a derived operation for an untagged type then by
5621 -- definition it's not a dispatching operation (even if the parent
5622 -- operation was dispatching), so we don't call
5623 -- Check_Dispatching_Operation in that case.
5625 if No
(Derived_Type
)
5626 or else Is_Tagged_Type
(Derived_Type
)
5628 Check_Dispatching_Operation
(S
, Empty
);
5632 -- If this is a user-defined equality operator that is not a derived
5633 -- subprogram, create the corresponding inequality. If the operation is
5634 -- dispatching, the expansion is done elsewhere, and we do not create
5635 -- an explicit inequality operation.
5637 <<Check_Inequality
>>
5638 if Chars
(S
) = Name_Op_Eq
5639 and then Etype
(S
) = Standard_Boolean
5640 and then Present
(Parent
(S
))
5641 and then not Is_Dispatching_Operation
(S
)
5643 Make_Inequality_Operator
(S
);
5645 end New_Overloaded_Entity
;
5647 ---------------------
5648 -- Process_Formals --
5649 ---------------------
5651 procedure Process_Formals
5653 Related_Nod
: Node_Id
)
5655 Param_Spec
: Node_Id
;
5657 Formal_Type
: Entity_Id
;
5661 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
5662 -- Check whether the default has a class-wide type. After analysis the
5663 -- default has the type of the formal, so we must also check explicitly
5664 -- for an access attribute.
5666 ---------------------------
5667 -- Is_Class_Wide_Default --
5668 ---------------------------
5670 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
5672 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
5673 or else (Nkind
(D
) = N_Attribute_Reference
5674 and then Attribute_Name
(D
) = Name_Access
5675 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
5676 end Is_Class_Wide_Default
;
5678 -- Start of processing for Process_Formals
5681 -- In order to prevent premature use of the formals in the same formal
5682 -- part, the Ekind is left undefined until all default expressions are
5683 -- analyzed. The Ekind is established in a separate loop at the end.
5685 Param_Spec
:= First
(T
);
5687 while Present
(Param_Spec
) loop
5689 Formal
:= Defining_Identifier
(Param_Spec
);
5690 Enter_Name
(Formal
);
5692 -- Case of ordinary parameters
5694 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
5695 Find_Type
(Parameter_Type
(Param_Spec
));
5696 Ptype
:= Parameter_Type
(Param_Spec
);
5698 if Ptype
= Error
then
5702 Formal_Type
:= Entity
(Ptype
);
5704 if Ekind
(Formal_Type
) = E_Incomplete_Type
5705 or else (Is_Class_Wide_Type
(Formal_Type
)
5706 and then Ekind
(Root_Type
(Formal_Type
)) =
5709 -- Ada 2005 (AI-326): Tagged incomplete types allowed
5711 if Is_Tagged_Type
(Formal_Type
) then
5714 elsif Nkind
(Parent
(T
)) /= N_Access_Function_Definition
5715 and then Nkind
(Parent
(T
)) /= N_Access_Procedure_Definition
5717 Error_Msg_N
("invalid use of incomplete type", Param_Spec
);
5720 elsif Ekind
(Formal_Type
) = E_Void
then
5721 Error_Msg_NE
("premature use of&",
5722 Parameter_Type
(Param_Spec
), Formal_Type
);
5725 -- Ada 2005 (AI-231): Create and decorate an internal subtype
5726 -- declaration corresponding to the null-excluding type of the
5727 -- formal in the enclosing scope. Finally, replace the parameter
5728 -- type of the formal with the internal subtype.
5730 if Ada_Version
>= Ada_05
5731 and then Is_Access_Type
(Formal_Type
)
5732 and then Null_Exclusion_Present
(Param_Spec
)
5734 if Can_Never_Be_Null
(Formal_Type
)
5735 and then Comes_From_Source
(Related_Nod
)
5738 ("null exclusion must apply to a type that does not "
5739 & "exclude null ('R'M 3.10 (14)", Related_Nod
);
5743 Create_Null_Excluding_Itype
5745 Related_Nod
=> Related_Nod
,
5746 Scope_Id
=> Scope
(Current_Scope
));
5749 -- An access formal type
5753 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
5755 -- Ada 2005 (AI-254)
5758 AD
: constant Node_Id
:=
5759 Access_To_Subprogram_Definition
5760 (Parameter_Type
(Param_Spec
));
5762 if Present
(AD
) and then Protected_Present
(AD
) then
5764 Replace_Anonymous_Access_To_Protected_Subprogram
5765 (Param_Spec
, Formal_Type
);
5770 Set_Etype
(Formal
, Formal_Type
);
5771 Default
:= Expression
(Param_Spec
);
5773 if Present
(Default
) then
5774 if Out_Present
(Param_Spec
) then
5776 ("default initialization only allowed for IN parameters",
5780 -- Do the special preanalysis of the expression (see section on
5781 -- "Handling of Default Expressions" in the spec of package Sem).
5783 Analyze_Per_Use_Expression
(Default
, Formal_Type
);
5785 -- Check that the designated type of an access parameter's default
5786 -- is not a class-wide type unless the parameter's designated type
5787 -- is also class-wide.
5789 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
5790 and then not From_With_Type
(Formal_Type
)
5791 and then Is_Class_Wide_Default
(Default
)
5792 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
5795 ("access to class-wide expression not allowed here", Default
);
5799 -- Ada 2005 (AI-231): Static checks
5801 if Ada_Version
>= Ada_05
5802 and then Is_Access_Type
(Etype
(Formal
))
5803 and then Can_Never_Be_Null
(Etype
(Formal
))
5805 Null_Exclusion_Static_Checks
(Param_Spec
);
5812 -- If this is the formal part of a function specification, analyze the
5813 -- subtype mark in the context where the formals are visible but not
5814 -- yet usable, and may hide outer homographs.
5816 if Nkind
(Related_Nod
) = N_Function_Specification
then
5817 Analyze_Return_Type
(Related_Nod
);
5820 -- Now set the kind (mode) of each formal
5822 Param_Spec
:= First
(T
);
5824 while Present
(Param_Spec
) loop
5825 Formal
:= Defining_Identifier
(Param_Spec
);
5826 Set_Formal_Mode
(Formal
);
5828 if Ekind
(Formal
) = E_In_Parameter
then
5829 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
5831 if Present
(Expression
(Param_Spec
)) then
5832 Default
:= Expression
(Param_Spec
);
5834 if Is_Scalar_Type
(Etype
(Default
)) then
5836 (Parameter_Type
(Param_Spec
)) /= N_Access_Definition
5838 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
5841 Formal_Type
:= Access_Definition
5842 (Related_Nod
, Parameter_Type
(Param_Spec
));
5845 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
5853 end Process_Formals
;
5855 ----------------------------
5856 -- Reference_Body_Formals --
5857 ----------------------------
5859 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
5864 if Error_Posted
(Spec
) then
5868 Fs
:= First_Formal
(Spec
);
5869 Fb
:= First_Formal
(Bod
);
5871 while Present
(Fs
) loop
5872 Generate_Reference
(Fs
, Fb
, 'b');
5875 Style
.Check_Identifier
(Fb
, Fs
);
5878 Set_Spec_Entity
(Fb
, Fs
);
5879 Set_Referenced
(Fs
, False);
5883 end Reference_Body_Formals
;
5885 -------------------------
5886 -- Set_Actual_Subtypes --
5887 -------------------------
5889 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
5890 Loc
: constant Source_Ptr
:= Sloc
(N
);
5894 First_Stmt
: Node_Id
:= Empty
;
5895 AS_Needed
: Boolean;
5898 -- If this is an emtpy initialization procedure, no need to create
5899 -- actual subtypes (small optimization).
5901 if Ekind
(Subp
) = E_Procedure
5902 and then Is_Null_Init_Proc
(Subp
)
5907 Formal
:= First_Formal
(Subp
);
5908 while Present
(Formal
) loop
5909 T
:= Etype
(Formal
);
5911 -- We never need an actual subtype for a constrained formal
5913 if Is_Constrained
(T
) then
5916 -- If we have unknown discriminants, then we do not need an actual
5917 -- subtype, or more accurately we cannot figure it out! Note that
5918 -- all class-wide types have unknown discriminants.
5920 elsif Has_Unknown_Discriminants
(T
) then
5923 -- At this stage we have an unconstrained type that may need an
5924 -- actual subtype. For sure the actual subtype is needed if we have
5925 -- an unconstrained array type.
5927 elsif Is_Array_Type
(T
) then
5930 -- The only other case needing an actual subtype is an unconstrained
5931 -- record type which is an IN parameter (we cannot generate actual
5932 -- subtypes for the OUT or IN OUT case, since an assignment can
5933 -- change the discriminant values. However we exclude the case of
5934 -- initialization procedures, since discriminants are handled very
5935 -- specially in this context, see the section entitled "Handling of
5936 -- Discriminants" in Einfo.
5938 -- We also exclude the case of Discrim_SO_Functions (functions used
5939 -- in front end layout mode for size/offset values), since in such
5940 -- functions only discriminants are referenced, and not only are such
5941 -- subtypes not needed, but they cannot always be generated, because
5942 -- of order of elaboration issues.
5944 elsif Is_Record_Type
(T
)
5945 and then Ekind
(Formal
) = E_In_Parameter
5946 and then Chars
(Formal
) /= Name_uInit
5947 and then not Is_Unchecked_Union
(T
)
5948 and then not Is_Discrim_SO_Function
(Subp
)
5952 -- All other cases do not need an actual subtype
5958 -- Generate actual subtypes for unconstrained arrays and
5959 -- unconstrained discriminated records.
5962 if Nkind
(N
) = N_Accept_Statement
then
5964 -- If expansion is active, The formal is replaced by a local
5965 -- variable that renames the corresponding entry of the
5966 -- parameter block, and it is this local variable that may
5967 -- require an actual subtype.
5969 if Expander_Active
then
5970 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
5972 Decl
:= Build_Actual_Subtype
(T
, Formal
);
5975 if Present
(Handled_Statement_Sequence
(N
)) then
5977 First
(Statements
(Handled_Statement_Sequence
(N
)));
5978 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
5979 Mark_Rewrite_Insertion
(Decl
);
5981 -- If the accept statement has no body, there will be no
5982 -- reference to the actuals, so no need to compute actual
5989 Decl
:= Build_Actual_Subtype
(T
, Formal
);
5990 Prepend
(Decl
, Declarations
(N
));
5991 Mark_Rewrite_Insertion
(Decl
);
5994 -- The declaration uses the bounds of an existing object, and
5995 -- therefore needs no constraint checks.
5997 Analyze
(Decl
, Suppress
=> All_Checks
);
5999 -- We need to freeze manually the generated type when it is
6000 -- inserted anywhere else than in a declarative part.
6002 if Present
(First_Stmt
) then
6003 Insert_List_Before_And_Analyze
(First_Stmt
,
6004 Freeze_Entity
(Defining_Identifier
(Decl
), Loc
));
6007 if Nkind
(N
) = N_Accept_Statement
6008 and then Expander_Active
6010 Set_Actual_Subtype
(Renamed_Object
(Formal
),
6011 Defining_Identifier
(Decl
));
6013 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
6017 Next_Formal
(Formal
);
6019 end Set_Actual_Subtypes
;
6021 ---------------------
6022 -- Set_Formal_Mode --
6023 ---------------------
6025 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
6026 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
6029 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
6030 -- since we ensure that corresponding actuals are always valid at the
6031 -- point of the call.
6033 if Out_Present
(Spec
) then
6034 if Ekind
(Scope
(Formal_Id
)) = E_Function
6035 or else Ekind
(Scope
(Formal_Id
)) = E_Generic_Function
6037 Error_Msg_N
("functions can only have IN parameters", Spec
);
6038 Set_Ekind
(Formal_Id
, E_In_Parameter
);
6040 elsif In_Present
(Spec
) then
6041 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
6044 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
6045 Set_Never_Set_In_Source
(Formal_Id
, True);
6046 Set_Is_True_Constant
(Formal_Id
, False);
6047 Set_Current_Value
(Formal_Id
, Empty
);
6051 Set_Ekind
(Formal_Id
, E_In_Parameter
);
6054 -- Set Is_Known_Non_Null for access parameters since the language
6055 -- guarantees that access parameters are always non-null. We also set
6056 -- Can_Never_Be_Null, since there is no way to change the value.
6058 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
6060 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
6061 -- null; In Ada 2005, only if then null_exclusion is explicit.
6063 if Ada_Version
< Ada_05
6064 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
6066 Set_Is_Known_Non_Null
(Formal_Id
);
6067 Set_Can_Never_Be_Null
(Formal_Id
);
6070 -- Ada 2005 (AI-231): Null-exclusion access subtype
6072 elsif Is_Access_Type
(Etype
(Formal_Id
))
6073 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
6075 Set_Is_Known_Non_Null
(Formal_Id
);
6078 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
6079 Set_Formal_Validity
(Formal_Id
);
6080 end Set_Formal_Mode
;
6082 -------------------------
6083 -- Set_Formal_Validity --
6084 -------------------------
6086 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
6088 -- If no validity checking, then we cannot assume anything about the
6089 -- validity of parameters, since we do not know there is any checking
6090 -- of the validity on the call side.
6092 if not Validity_Checks_On
then
6095 -- If validity checking for parameters is enabled, this means we are
6096 -- not supposed to make any assumptions about argument values.
6098 elsif Validity_Check_Parameters
then
6101 -- If we are checking in parameters, we will assume that the caller is
6102 -- also checking parameters, so we can assume the parameter is valid.
6104 elsif Ekind
(Formal_Id
) = E_In_Parameter
6105 and then Validity_Check_In_Params
6107 Set_Is_Known_Valid
(Formal_Id
, True);
6109 -- Similar treatment for IN OUT parameters
6111 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
6112 and then Validity_Check_In_Out_Params
6114 Set_Is_Known_Valid
(Formal_Id
, True);
6116 end Set_Formal_Validity
;
6118 ------------------------
6119 -- Subtype_Conformant --
6120 ------------------------
6122 function Subtype_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
6125 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
);
6127 end Subtype_Conformant
;
6129 ---------------------
6130 -- Type_Conformant --
6131 ---------------------
6133 function Type_Conformant
6134 (New_Id
: Entity_Id
;
6136 Skip_Controlling_Formals
: Boolean := False) return Boolean
6140 May_Hide_Profile
:= False;
6143 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
6144 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
6146 end Type_Conformant
;
6148 -------------------------------
6149 -- Valid_Operator_Definition --
6150 -------------------------------
6152 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
6155 Id
: constant Name_Id
:= Chars
(Designator
);
6159 F
:= First_Formal
(Designator
);
6160 while Present
(F
) loop
6163 if Present
(Default_Value
(F
)) then
6165 ("default values not allowed for operator parameters",
6172 -- Verify that user-defined operators have proper number of arguments
6173 -- First case of operators which can only be unary
6176 or else Id
= Name_Op_Abs
6180 -- Case of operators which can be unary or binary
6182 elsif Id
= Name_Op_Add
6183 or Id
= Name_Op_Subtract
6185 N_OK
:= (N
in 1 .. 2);
6187 -- All other operators can only be binary
6195 ("incorrect number of arguments for operator", Designator
);
6199 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
6200 and then not Is_Intrinsic_Subprogram
(Designator
)
6203 ("explicit definition of inequality not allowed", Designator
);
6205 end Valid_Operator_Definition
;