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_Ch6
; use Exp_Ch6
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Fname
; use Fname
;
39 with Freeze
; use Freeze
;
40 with Itypes
; use Itypes
;
41 with Lib
.Xref
; use Lib
.Xref
;
42 with Layout
; use Layout
;
43 with Namet
; use Namet
;
45 with Nlists
; use Nlists
;
46 with Nmake
; use Nmake
;
48 with Output
; use Output
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Cat
; use Sem_Cat
;
52 with Sem_Ch3
; use Sem_Ch3
;
53 with Sem_Ch4
; use Sem_Ch4
;
54 with Sem_Ch5
; use Sem_Ch5
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Ch10
; use Sem_Ch10
;
57 with Sem_Ch12
; use Sem_Ch12
;
58 with Sem_Disp
; use Sem_Disp
;
59 with Sem_Dist
; use Sem_Dist
;
60 with Sem_Elim
; use Sem_Elim
;
61 with Sem_Eval
; use Sem_Eval
;
62 with Sem_Mech
; use Sem_Mech
;
63 with Sem_Prag
; use Sem_Prag
;
64 with Sem_Res
; use Sem_Res
;
65 with Sem_Util
; use Sem_Util
;
66 with Sem_Type
; use Sem_Type
;
67 with Sem_Warn
; use Sem_Warn
;
68 with Sinput
; use Sinput
;
69 with Stand
; use Stand
;
70 with Sinfo
; use Sinfo
;
71 with Sinfo
.CN
; use Sinfo
.CN
;
72 with Snames
; use Snames
;
73 with Stringt
; use Stringt
;
75 with Stylesw
; use Stylesw
;
76 with Tbuild
; use Tbuild
;
77 with Uintp
; use Uintp
;
78 with Urealp
; use Urealp
;
79 with Validsw
; use Validsw
;
81 package body Sem_Ch6
is
83 Enable_New_Return_Processing
: constant Boolean := True;
84 -- ??? This flag is temporary. False causes the compiler to use the old
85 -- version of Analyze_Return_Statement; True, the new version, which does
86 -- not yet work. You probably want this to match the corresponding thing
89 May_Hide_Profile
: Boolean := False;
90 -- This flag is used to indicate that two formals in two subprograms being
91 -- checked for conformance differ only in that one is an access parameter
92 -- while the other is of a general access type with the same designated
93 -- type. In this case, if the rest of the signatures match, a call to
94 -- either subprogram may be ambiguous, which is worth a warning. The flag
95 -- is set in Compatible_Types, and the warning emitted in
96 -- New_Overloaded_Entity.
98 -----------------------
99 -- Local Subprograms --
100 -----------------------
102 procedure Analyze_A_Return_Statement
(N
: Node_Id
);
103 -- Common processing for simple_ and extended_return_statements
105 procedure Analyze_Function_Return
(N
: Node_Id
);
106 -- Subsidiary to Analyze_A_Return_Statement.
107 -- Called when the return statement applies to a [generic] function.
109 procedure Analyze_Return_Type
(N
: Node_Id
);
110 -- Subsidiary to Process_Formals: analyze subtype mark in function
111 -- specification, in a context where the formals are visible and hide
114 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
115 -- Analyze a generic subprogram body. N is the body to be analyzed, and
116 -- Gen_Id is the defining entity Id for the corresponding spec.
118 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
);
119 -- If a subprogram has pragma Inline and inlining is active, use generic
120 -- machinery to build an unexpanded body for the subprogram. This body is
121 -- subsequenty used for inline expansions at call sites. If subprogram can
122 -- be inlined (depending on size and nature of local declarations) this
123 -- function returns true. Otherwise subprogram body is treated normally.
124 -- If proper warnings are enabled and the subprogram contains a construct
125 -- that cannot be inlined, the offending construct is flagged accordingly.
127 type Conformance_Type
is
128 (Type_Conformant
, Mode_Conformant
, Subtype_Conformant
, Fully_Conformant
);
129 -- Conformance type used for following call, meaning matches the
130 -- RM definitions of the corresponding terms.
132 procedure Check_Conformance
135 Ctype
: Conformance_Type
;
137 Conforms
: out Boolean;
138 Err_Loc
: Node_Id
:= Empty
;
139 Get_Inst
: Boolean := False;
140 Skip_Controlling_Formals
: Boolean := False);
141 -- Given two entities, this procedure checks that the profiles associated
142 -- with these entities meet the conformance criterion given by the third
143 -- parameter. If they conform, Conforms is set True and control returns
144 -- to the caller. If they do not conform, Conforms is set to False, and
145 -- in addition, if Errmsg is True on the call, proper messages are output
146 -- to complain about the conformance failure. If Err_Loc is non_Empty
147 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
148 -- error messages are placed on the appropriate part of the construct
149 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
150 -- against a formal access-to-subprogram type so Get_Instance_Of must
153 procedure Check_Overriding_Indicator
155 Overridden_Subp
: Entity_Id
:= Empty
);
156 -- Verify the consistency of an overriding_indicator given for subprogram
157 -- declaration, body, renaming, or instantiation. Overridden_Subp is set
158 -- if the scope into which we are introducing the subprogram contains a
159 -- type-conformant subprogram that becomes hidden by the new subprogram.
161 procedure Check_Subprogram_Order
(N
: Node_Id
);
162 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
163 -- the alpha ordering rule for N if this ordering requirement applicable.
165 procedure Check_Returns
169 Proc
: Entity_Id
:= Empty
);
170 -- Called to check for missing return statements in a function body, or for
171 -- returns present in a procedure body which has No_Return set. L is the
172 -- handled statement sequence for the subprogram body. This procedure
173 -- checks all flow paths to make sure they either have return (Mode = 'F',
174 -- used for functions) or do not have a return (Mode = 'P', used for
175 -- No_Return procedures). The flag Err is set if there are any control
176 -- paths not explicitly terminated by a return in the function case, and is
177 -- True otherwise. Proc is the entity for the procedure case and is used
178 -- in posting the warning message.
180 function Conforming_Types
183 Ctype
: Conformance_Type
;
184 Get_Inst
: Boolean := False) return Boolean;
185 -- Check that two formal parameter types conform, checking both for
186 -- equality of base types, and where required statically matching
187 -- subtypes, depending on the setting of Ctype.
189 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
190 -- This procedure makes S, a new overloaded entity, into the first visible
191 -- entity with that name.
193 procedure Install_Entity
(E
: Entity_Id
);
194 -- Make single entity visible. Used for generic formals as well
196 procedure Install_Formals
(Id
: Entity_Id
);
197 -- On entry to a subprogram body, make the formals visible. Note that
198 -- simply placing the subprogram on the scope stack is not sufficient:
199 -- the formals must become the current entities for their names.
201 function Is_Non_Overriding_Operation
203 New_E
: Entity_Id
) return Boolean;
204 -- Enforce the rule given in 12.3(18): a private operation in an instance
205 -- overrides an inherited operation only if the corresponding operation
206 -- was overriding in the generic. This can happen for primitive operations
207 -- of types derived (in the generic unit) from formal private or formal
210 procedure Make_Inequality_Operator
(S
: Entity_Id
);
211 -- Create the declaration for an inequality operator that is implicitly
212 -- created by a user-defined equality operator that yields a boolean.
214 procedure May_Need_Actuals
(Fun
: Entity_Id
);
215 -- Flag functions that can be called without parameters, i.e. those that
216 -- have no parameters, or those for which defaults exist for all parameters
218 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
);
219 -- If there is a separate spec for a subprogram or generic subprogram, the
220 -- formals of the body are treated as references to the corresponding
221 -- formals of the spec. This reference does not count as an actual use of
222 -- the formal, in order to diagnose formals that are unused in the body.
224 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
225 -- Formal_Id is an formal parameter entity. This procedure deals with
226 -- setting the proper validity status for this entity, which depends
227 -- on the kind of parameter and the validity checking mode.
229 --------------------------------
230 -- Analyze_A_Return_Statement --
231 --------------------------------
233 procedure Analyze_A_Return_Statement
(N
: Node_Id
) is
234 -- ???This should be called Analyze_Return_Statement, and
235 -- Analyze_Return_Statement should be called
236 -- Analyze_Simple_Return_Statement!
238 pragma Assert
(Nkind
(N
) = N_Return_Statement
239 or else Nkind
(N
) = N_Extended_Return_Statement
);
241 Returns_Object
: constant Boolean :=
242 Nkind
(N
) = N_Extended_Return_Statement
244 (Nkind
(N
) = N_Return_Statement
and then Present
(Expression
(N
)));
246 -- True if we're returning something; that is, "return <expression>;"
247 -- or "return Result : T [:= ...]". False for "return;".
248 -- Used for error checking: If Returns_Object is True, N should apply
249 -- to a function body; otherwise N should apply to a procedure body,
250 -- entry body, accept statement, or extended return statement.
252 function Find_What_It_Applies_To
return Entity_Id
;
253 -- Find the entity representing the innermost enclosing body, accept
254 -- statement, or extended return statement. If the result is a
255 -- callable construct or extended return statement, then this will be
256 -- the value of the Return_Applies_To attribute. Otherwise, the program
257 -- is illegal. See RM-6.5(4/2). I am disinclined to call this
258 -- Find_The_Construct_To_Which_This_Return_Statement_Applies. ;-)
260 -----------------------------
261 -- Find_What_It_Applies_To --
262 -----------------------------
264 function Find_What_It_Applies_To
return Entity_Id
is
265 Result
: Entity_Id
:= Empty
;
268 -- Loop outward through the Scope_Stack, skipping blocks and loops
270 for J
in reverse 0 .. Scope_Stack
.Last
loop
271 Result
:= Scope_Stack
.Table
(J
).Entity
;
272 exit when Ekind
(Result
) /= E_Block
and then
273 Ekind
(Result
) /= E_Loop
;
276 pragma Assert
(Present
(Result
));
279 end Find_What_It_Applies_To
;
281 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
282 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
284 Loc
: constant Source_Ptr
:= Sloc
(N
);
285 Stm_Entity
: constant Entity_Id
:=
287 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
289 -- Start of processing for Analyze_A_Return_Statement
293 Set_Return_Statement_Entity
(N
, Stm_Entity
);
295 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
296 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
298 -- Place the Return entity on scope stack, to simplify enforcement
299 -- of 6.5 (4/2): an inner return statement will apply to this extended
302 if Nkind
(N
) = N_Extended_Return_Statement
then
303 New_Scope
(Stm_Entity
);
306 -- Check that pragma No_Return is obeyed:
308 if No_Return
(Scope_Id
) then
309 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
312 -- Check that functions return objects, and other things do not:
314 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
315 if not Returns_Object
then
316 Error_Msg_N
("missing expression in return from function", N
);
319 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
320 if Returns_Object
then
321 Error_Msg_N
("procedure cannot return value (use function)", N
);
324 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
325 if Returns_Object
then
326 if Is_Protected_Type
(Scope
(Scope_Id
)) then
327 Error_Msg_N
("entry body cannot return value", N
);
329 Error_Msg_N
("accept statement cannot return value", N
);
333 elsif Kind
= E_Return_Statement
then
335 -- We are nested within another return statement, which must be an
336 -- extended_return_statement.
338 if Returns_Object
then
340 ("extended_return_statement cannot return value; " &
341 "use `""RETURN;""`", N
);
345 Error_Msg_N
("illegal context for return statement", N
);
348 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
349 Analyze_Function_Return
(N
);
352 if Nkind
(N
) = N_Extended_Return_Statement
then
356 Check_Unreachable_Code
(N
);
357 end Analyze_A_Return_Statement
;
359 ---------------------------------------------
360 -- Analyze_Abstract_Subprogram_Declaration --
361 ---------------------------------------------
363 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
364 Designator
: constant Entity_Id
:=
365 Analyze_Subprogram_Specification
(Specification
(N
));
366 Scop
: constant Entity_Id
:= Current_Scope
;
369 Generate_Definition
(Designator
);
370 Set_Is_Abstract
(Designator
);
371 New_Overloaded_Entity
(Designator
);
372 Check_Delayed_Subprogram
(Designator
);
374 Set_Categorization_From_Scope
(Designator
, Scop
);
376 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
378 ("abstract subprogram not allowed in protected type", N
);
381 Generate_Reference_To_Formals
(Designator
);
382 end Analyze_Abstract_Subprogram_Declaration
;
384 ----------------------------------------
385 -- Analyze_Extended_Return_Statement --
386 ----------------------------------------
388 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
390 Analyze_A_Return_Statement
(N
);
391 end Analyze_Extended_Return_Statement
;
393 ----------------------------
394 -- Analyze_Function_Call --
395 ----------------------------
397 procedure Analyze_Function_Call
(N
: Node_Id
) is
398 P
: constant Node_Id
:= Name
(N
);
399 L
: constant List_Id
:= Parameter_Associations
(N
);
405 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
406 -- as B (A, X). If the rewriting is successful, the call has been
407 -- analyzed and we just return.
409 if Nkind
(P
) = N_Selected_Component
410 and then Name
(N
) /= P
411 and then Is_Rewrite_Substitution
(N
)
412 and then Present
(Etype
(N
))
417 -- If error analyzing name, then set Any_Type as result type and return
419 if Etype
(P
) = Any_Type
then
420 Set_Etype
(N
, Any_Type
);
424 -- Otherwise analyze the parameters
428 while Present
(Actual
) loop
430 Check_Parameterless_Call
(Actual
);
436 end Analyze_Function_Call
;
438 -----------------------------
439 -- Analyze_Function_Return --
440 -----------------------------
442 procedure Analyze_Function_Return
(N
: Node_Id
) is
443 Loc
: constant Source_Ptr
:= Sloc
(N
);
444 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
445 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
447 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
448 -- Function result subtype
450 procedure Check_Limited_Return
(Expr
: Node_Id
);
451 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
452 -- limited types. Used only for simple return statements.
453 -- Expr is the expression returned.
455 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
456 -- Check that the return_subtype_indication properly matches the result
457 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
459 --------------------------
460 -- Check_Limited_Return --
461 --------------------------
463 procedure Check_Limited_Return
(Expr
: Node_Id
) is
465 -- Ada 2005 (AI-318-02): Return-by-reference types have been
466 -- removed and replaced by anonymous access results. This is an
467 -- incompatibility with Ada 95. Not clear whether this should be
468 -- enforced yet or perhaps controllable with special switch. ???
470 if Is_Limited_Type
(R_Type
)
471 and then Comes_From_Source
(N
)
472 and then not In_Instance_Body
473 and then not OK_For_Limited_Init_In_05
(Expr
)
477 if Ada_Version
>= Ada_05
478 and then not Debug_Flag_Dot_L
479 and then not GNAT_Mode
482 ("(Ada 2005) cannot copy object of a limited type " &
483 "('R'M'-2005 6.5(5.5/2))", Expr
);
484 if Is_Inherently_Limited_Type
(R_Type
) then
486 ("\return by reference not permitted in Ada 2005", Expr
);
489 -- Warn in Ada 95 mode, to give folks a heads up about this
492 -- In GNAT mode, this is just a warning, to allow it to be
493 -- evilly turned off. Otherwise it is a real error.
495 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
496 if Is_Inherently_Limited_Type
(R_Type
) then
498 ("return by reference not permitted in Ada 2005 " &
499 "('R'M'-2005 6.5(5.5/2))?", Expr
);
502 ("cannot copy object of a limited type in Ada 2005 " &
503 "('R'M'-2005 6.5(5.5/2))?", Expr
);
506 -- Ada 95 mode, compatibility warnings disabled
509 return; -- skip continuation messages below
513 ("\consider switching to return of access type", Expr
);
514 Explain_Limited_Type
(R_Type
, Expr
);
516 end Check_Limited_Return
;
518 -------------------------------------
519 -- Check_Return_Subtype_Indication --
520 -------------------------------------
522 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
523 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
524 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
525 -- Subtype given in the extended return statement;
526 -- this must match R_Type.
528 Subtype_Ind
: constant Node_Id
:=
529 Object_Definition
(Original_Node
(Obj_Decl
));
531 R_Type_Is_Anon_Access
:
533 Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
535 Ekind
(R_Type
) = E_Anonymous_Access_Protected_Subprogram_Type
537 Ekind
(R_Type
) = E_Anonymous_Access_Type
;
538 -- True if return type of the function is an anonymous access type
539 -- Can't we make Is_Anonymous_Access_Type in einfo ???
541 R_Stm_Type_Is_Anon_Access
:
543 Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
545 Ekind
(R_Type
) = E_Anonymous_Access_Protected_Subprogram_Type
547 Ekind
(R_Type
) = E_Anonymous_Access_Type
;
548 -- True if type of the return object is an anonymous access type
551 -- First, avoid cascade errors:
553 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
557 -- "return access T" case; check that the return statement also has
558 -- "access T", and that the subtypes statically match:
560 if R_Type_Is_Anon_Access
then
561 if R_Stm_Type_Is_Anon_Access
then
562 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
564 ("subtypes must statically match", Subtype_Ind
);
567 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
570 -- Subtype_indication case; check that the types are the same, and
571 -- statically match if appropriate:
573 elsif Base_Type
(R_Stm_Type
) = Base_Type
(R_Type
) then
574 if Is_Constrained
(R_Type
) then
575 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
577 ("subtypes must statically match", Subtype_Ind
);
583 ("wrong type for return_subtype_indication", Subtype_Ind
);
585 end Check_Return_Subtype_Indication
;
587 ---------------------
588 -- Local Variables --
589 ---------------------
593 -- Start of processing for Analyze_Function_Return
596 Set_Return_Present
(Scope_Id
);
598 if Nkind
(N
) = N_Return_Statement
then
599 Expr
:= Expression
(N
);
600 Analyze_And_Resolve
(Expr
, R_Type
);
601 Check_Limited_Return
(Expr
);
604 -- Analyze parts specific to extended_return_statement:
607 Obj_Decl
: constant Node_Id
:=
608 Last
(Return_Object_Declarations
(N
));
610 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
613 Expr
:= Expression
(Obj_Decl
);
615 -- Note: The check for OK_For_Limited_Init will happen in
616 -- Analyze_Object_Declaration; we treat it as a normal
617 -- object declaration.
621 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
622 Check_Return_Subtype_Indication
(Obj_Decl
);
624 if Present
(HSS
) then
627 if Present
(Exception_Handlers
(HSS
)) then
629 -- ???Has_Nested_Block_With_Handler needs to be set.
630 -- Probably by creating an actual N_Block_Statement.
631 -- Probably in Expand.
637 Check_References
(Stm_Entity
);
641 -- ???Check for not-yet-implemented cases of AI-318. Currently we
642 -- warn, because that's convenient for our own use. We might want to
643 -- change these warnings to errors at some point. This will go away
644 -- once AI-318 is fully implemented.
646 -- In the first version, we plan not to implement limited function
647 -- returns when the result type contains tasks or protected objects,
648 -- and when the result subtype is unconstrained.
650 if Ada_Version
>= Ada_05
651 and then not Debug_Flag_Dot_L
652 and then Is_Inherently_Limited_Type
(R_Type
)
654 if Has_Task
(R_Type
) then
655 Error_Msg_N
("(Ada 2005) return of task objects" &
656 " is not yet implemented", N
);
659 if Is_Controlled
(R_Type
)
660 or else Has_Controlled_Component
(R_Type
)
663 ("(Ada 2005) return of limited controlled objects" &
664 " is not yet implemented", N
);
668 Is_Composite_Type
(R_Type
) and then not Is_Constrained
(R_Type
)
671 ("(Ada 2005) return of unconstrained limited composite objects" &
672 " is not yet implemented", N
);
677 and then Present
(Etype
(Expr
)) -- Could be False in case of errors.
679 -- Ada 2005 (AI-318-02): When the result type is an anonymous
680 -- access type, apply an implicit conversion of the expression
681 -- to that type to force appropriate static and run-time
682 -- accessibility checks.
684 if Ada_Version
>= Ada_05
685 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
687 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
688 Analyze_And_Resolve
(Expr
, R_Type
);
691 if (Is_Class_Wide_Type
(Etype
(Expr
))
692 or else Is_Dynamically_Tagged
(Expr
))
693 and then not Is_Class_Wide_Type
(R_Type
)
696 ("dynamically tagged expression not allowed!", Expr
);
699 Apply_Constraint_Check
(Expr
, R_Type
);
701 -- ??? A real run-time accessibility check is needed in cases
702 -- involving dereferences of access parameters. For now we just
703 -- check the static cases.
705 if (Ada_Version
< Ada_05
or else Debug_Flag_Dot_L
)
706 and then Is_Inherently_Limited_Type
(Etype
(Scope_Id
))
707 and then Object_Access_Level
(Expr
) >
708 Subprogram_Access_Level
(Scope_Id
)
711 Make_Raise_Program_Error
(Loc
,
712 Reason
=> PE_Accessibility_Check_Failed
));
716 ("cannot return a local value by reference?", N
);
718 ("\& will be raised at run time?",
719 N
, Standard_Program_Error
);
722 end Analyze_Function_Return
;
724 -------------------------------------
725 -- Analyze_Generic_Subprogram_Body --
726 -------------------------------------
728 procedure Analyze_Generic_Subprogram_Body
732 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
733 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
739 -- Copy body and disable expansion while analyzing the generic For a
740 -- stub, do not copy the stub (which would load the proper body), this
741 -- will be done when the proper body is analyzed.
743 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
744 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
749 Spec
:= Specification
(N
);
751 -- Within the body of the generic, the subprogram is callable, and
752 -- behaves like the corresponding non-generic unit.
754 Body_Id
:= Defining_Entity
(Spec
);
756 if Kind
= E_Generic_Procedure
757 and then Nkind
(Spec
) /= N_Procedure_Specification
759 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
762 elsif Kind
= E_Generic_Function
763 and then Nkind
(Spec
) /= N_Function_Specification
765 Error_Msg_N
("invalid body for generic function ", Body_Id
);
769 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
771 if Has_Completion
(Gen_Id
)
772 and then Nkind
(Parent
(N
)) /= N_Subunit
774 Error_Msg_N
("duplicate generic body", N
);
777 Set_Has_Completion
(Gen_Id
);
780 if Nkind
(N
) = N_Subprogram_Body_Stub
then
781 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
783 Set_Corresponding_Spec
(N
, Gen_Id
);
786 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
787 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
790 -- Make generic parameters immediately visible in the body. They are
791 -- needed to process the formals declarations. Then make the formals
792 -- visible in a separate step.
798 First_Ent
: Entity_Id
;
801 First_Ent
:= First_Entity
(Gen_Id
);
804 while Present
(E
) and then not Is_Formal
(E
) loop
809 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
811 -- Now generic formals are visible, and the specification can be
812 -- analyzed, for subsequent conformance check.
814 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
816 -- Make formal parameters visible
820 -- E is the first formal parameter, we loop through the formals
821 -- installing them so that they will be visible.
823 Set_First_Entity
(Gen_Id
, E
);
824 while Present
(E
) loop
830 -- Visible generic entity is callable within its own body
832 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
833 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
834 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
835 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
836 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
837 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
839 if Nkind
(N
) = N_Subprogram_Body_Stub
then
841 -- No body to analyze, so restore state of generic unit
843 Set_Ekind
(Gen_Id
, Kind
);
844 Set_Ekind
(Body_Id
, Kind
);
846 if Present
(First_Ent
) then
847 Set_First_Entity
(Gen_Id
, First_Ent
);
854 -- If this is a compilation unit, it must be made visible explicitly,
855 -- because the compilation of the declaration, unlike other library
856 -- unit declarations, does not. If it is not a unit, the following
857 -- is redundant but harmless.
859 Set_Is_Immediately_Visible
(Gen_Id
);
860 Reference_Body_Formals
(Gen_Id
, Body_Id
);
862 if Is_Child_Unit
(Gen_Id
) then
863 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
866 Set_Actual_Subtypes
(N
, Current_Scope
);
867 Analyze_Declarations
(Declarations
(N
));
869 Analyze
(Handled_Statement_Sequence
(N
));
871 Save_Global_References
(Original_Node
(N
));
873 -- Prior to exiting the scope, include generic formals again (if any
874 -- are present) in the set of local entities.
876 if Present
(First_Ent
) then
877 Set_First_Entity
(Gen_Id
, First_Ent
);
880 Check_References
(Gen_Id
);
883 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
885 Check_Subprogram_Order
(N
);
887 -- Outside of its body, unit is generic again
889 Set_Ekind
(Gen_Id
, Kind
);
890 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
891 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
893 end Analyze_Generic_Subprogram_Body
;
895 -----------------------------
896 -- Analyze_Operator_Symbol --
897 -----------------------------
899 -- An operator symbol such as "+" or "and" may appear in context where the
900 -- literal denotes an entity name, such as "+"(x, y) or in context when it
901 -- is just a string, as in (conjunction = "or"). In these cases the parser
902 -- generates this node, and the semantics does the disambiguation. Other
903 -- such case are actuals in an instantiation, the generic unit in an
904 -- instantiation, and pragma arguments.
906 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
907 Par
: constant Node_Id
:= Parent
(N
);
910 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
911 or else Nkind
(Par
) = N_Function_Instantiation
912 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
913 or else (Nkind
(Par
) = N_Pragma_Argument_Association
914 and then not Is_Pragma_String_Literal
(Par
))
915 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
916 or else (Nkind
(Par
) = N_Attribute_Reference
917 and then Attribute_Name
(Par
) /= Name_Value
)
919 Find_Direct_Name
(N
);
922 Change_Operator_Symbol_To_String_Literal
(N
);
925 end Analyze_Operator_Symbol
;
927 -----------------------------------
928 -- Analyze_Parameter_Association --
929 -----------------------------------
931 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
933 Analyze
(Explicit_Actual_Parameter
(N
));
934 end Analyze_Parameter_Association
;
936 ----------------------------
937 -- Analyze_Procedure_Call --
938 ----------------------------
940 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
941 Loc
: constant Source_Ptr
:= Sloc
(N
);
942 P
: constant Node_Id
:= Name
(N
);
943 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
947 procedure Analyze_Call_And_Resolve
;
948 -- Do Analyze and Resolve calls for procedure call
950 ------------------------------
951 -- Analyze_Call_And_Resolve --
952 ------------------------------
954 procedure Analyze_Call_And_Resolve
is
956 if Nkind
(N
) = N_Procedure_Call_Statement
then
958 Resolve
(N
, Standard_Void_Type
);
962 end Analyze_Call_And_Resolve
;
964 -- Start of processing for Analyze_Procedure_Call
967 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
968 -- a procedure call or an entry call. The prefix may denote an access
969 -- to subprogram type, in which case an implicit dereference applies.
970 -- If the prefix is an indexed component (without implicit defererence)
971 -- then the construct denotes a call to a member of an entire family.
972 -- If the prefix is a simple name, it may still denote a call to a
973 -- parameterless member of an entry family. Resolution of these various
974 -- interpretations is delicate.
978 -- If this is a call of the form Obj.Op, the call may have been
979 -- analyzed and possibly rewritten into a block, in which case
986 -- If error analyzing prefix, then set Any_Type as result and return
988 if Etype
(P
) = Any_Type
then
989 Set_Etype
(N
, Any_Type
);
993 -- Otherwise analyze the parameters
995 if Present
(Actuals
) then
996 Actual
:= First
(Actuals
);
998 while Present
(Actual
) loop
1000 Check_Parameterless_Call
(Actual
);
1005 -- Special processing for Elab_Spec and Elab_Body calls
1007 if Nkind
(P
) = N_Attribute_Reference
1008 and then (Attribute_Name
(P
) = Name_Elab_Spec
1009 or else Attribute_Name
(P
) = Name_Elab_Body
)
1011 if Present
(Actuals
) then
1013 ("no parameters allowed for this call", First
(Actuals
));
1017 Set_Etype
(N
, Standard_Void_Type
);
1020 elsif Is_Entity_Name
(P
)
1021 and then Is_Record_Type
(Etype
(Entity
(P
)))
1022 and then Remote_AST_I_Dereference
(P
)
1026 elsif Is_Entity_Name
(P
)
1027 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1029 if Is_Access_Type
(Etype
(P
))
1030 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1031 and then No
(Actuals
)
1032 and then Comes_From_Source
(N
)
1034 Error_Msg_N
("missing explicit dereference in call", N
);
1037 Analyze_Call_And_Resolve
;
1039 -- If the prefix is the simple name of an entry family, this is
1040 -- a parameterless call from within the task body itself.
1042 elsif Is_Entity_Name
(P
)
1043 and then Nkind
(P
) = N_Identifier
1044 and then Ekind
(Entity
(P
)) = E_Entry_Family
1045 and then Present
(Actuals
)
1046 and then No
(Next
(First
(Actuals
)))
1048 -- Can be call to parameterless entry family. What appears to be the
1049 -- sole argument is in fact the entry index. Rewrite prefix of node
1050 -- accordingly. Source representation is unchanged by this
1054 Make_Indexed_Component
(Loc
,
1056 Make_Selected_Component
(Loc
,
1057 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1058 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1059 Expressions
=> Actuals
);
1060 Set_Name
(N
, New_N
);
1061 Set_Etype
(New_N
, Standard_Void_Type
);
1062 Set_Parameter_Associations
(N
, No_List
);
1063 Analyze_Call_And_Resolve
;
1065 elsif Nkind
(P
) = N_Explicit_Dereference
then
1066 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1067 Analyze_Call_And_Resolve
;
1069 Error_Msg_N
("expect access to procedure in call", P
);
1072 -- The name can be a selected component or an indexed component that
1073 -- yields an access to subprogram. Such a prefix is legal if the call
1074 -- has parameter associations.
1076 elsif Is_Access_Type
(Etype
(P
))
1077 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1079 if Present
(Actuals
) then
1080 Analyze_Call_And_Resolve
;
1082 Error_Msg_N
("missing explicit dereference in call ", N
);
1085 -- If not an access to subprogram, then the prefix must resolve to the
1086 -- name of an entry, entry family, or protected operation.
1088 -- For the case of a simple entry call, P is a selected component where
1089 -- the prefix is the task and the selector name is the entry. A call to
1090 -- a protected procedure will have the same syntax. If the protected
1091 -- object contains overloaded operations, the entity may appear as a
1092 -- function, the context will select the operation whose type is Void.
1094 elsif Nkind
(P
) = N_Selected_Component
1095 and then (Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
1097 Ekind
(Entity
(Selector_Name
(P
))) = E_Procedure
1099 Ekind
(Entity
(Selector_Name
(P
))) = E_Function
)
1101 Analyze_Call_And_Resolve
;
1103 elsif Nkind
(P
) = N_Selected_Component
1104 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1105 and then Present
(Actuals
)
1106 and then No
(Next
(First
(Actuals
)))
1108 -- Can be call to parameterless entry family. What appears to be the
1109 -- sole argument is in fact the entry index. Rewrite prefix of node
1110 -- accordingly. Source representation is unchanged by this
1114 Make_Indexed_Component
(Loc
,
1115 Prefix
=> New_Copy
(P
),
1116 Expressions
=> Actuals
);
1117 Set_Name
(N
, New_N
);
1118 Set_Etype
(New_N
, Standard_Void_Type
);
1119 Set_Parameter_Associations
(N
, No_List
);
1120 Analyze_Call_And_Resolve
;
1122 -- For the case of a reference to an element of an entry family, P is
1123 -- an indexed component whose prefix is a selected component (task and
1124 -- entry family), and whose index is the entry family index.
1126 elsif Nkind
(P
) = N_Indexed_Component
1127 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1128 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1130 Analyze_Call_And_Resolve
;
1132 -- If the prefix is the name of an entry family, it is a call from
1133 -- within the task body itself.
1135 elsif Nkind
(P
) = N_Indexed_Component
1136 and then Nkind
(Prefix
(P
)) = N_Identifier
1137 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1140 Make_Selected_Component
(Loc
,
1141 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1142 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1143 Rewrite
(Prefix
(P
), New_N
);
1145 Analyze_Call_And_Resolve
;
1147 -- Anything else is an error
1150 Error_Msg_N
("invalid procedure or entry call", N
);
1152 end Analyze_Procedure_Call
;
1154 ------------------------------
1155 -- Analyze_Return_Statement --
1156 ------------------------------
1158 procedure Analyze_Return_Statement
(N
: Node_Id
) is
1159 Loc
: constant Source_Ptr
:= Sloc
(N
);
1161 Scope_Id
: Entity_Id
;
1165 Stm_Entity
: constant Entity_Id
:=
1167 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
1170 if Enable_New_Return_Processing
then -- ???Temporary hack.
1171 Analyze_A_Return_Statement
(N
);
1175 -- Find subprogram or accept statement enclosing the return statement
1178 for J
in reverse 0 .. Scope_Stack
.Last
loop
1179 Scope_Id
:= Scope_Stack
.Table
(J
).Entity
;
1180 exit when Ekind
(Scope_Id
) /= E_Block
and then
1181 Ekind
(Scope_Id
) /= E_Loop
;
1184 pragma Assert
(Present
(Scope_Id
));
1186 Set_Return_Statement_Entity
(N
, Stm_Entity
);
1187 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
1189 Kind
:= Ekind
(Scope_Id
);
1190 Expr
:= Expression
(N
);
1192 if Kind
/= E_Function
1193 and then Kind
/= E_Generic_Function
1194 and then Kind
/= E_Procedure
1195 and then Kind
/= E_Generic_Procedure
1196 and then Kind
/= E_Entry
1197 and then Kind
/= E_Entry_Family
1199 Error_Msg_N
("illegal context for return statement", N
);
1201 elsif Present
(Expr
) then
1202 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
1203 Set_Return_Present
(Scope_Id
);
1204 R_Type
:= Etype
(Scope_Id
);
1205 Analyze_And_Resolve
(Expr
, R_Type
);
1207 -- Ada 2005 (AI-318-02): When the result type is an anonymous
1208 -- access type, apply an implicit conversion of the expression
1209 -- to that type to force appropriate static and run-time
1210 -- accessibility checks.
1212 if Ada_Version
>= Ada_05
1213 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1215 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1216 Analyze_And_Resolve
(Expr
, R_Type
);
1219 if (Is_Class_Wide_Type
(Etype
(Expr
))
1220 or else Is_Dynamically_Tagged
(Expr
))
1221 and then not Is_Class_Wide_Type
(R_Type
)
1224 ("dynamically tagged expression not allowed!", Expr
);
1227 Apply_Constraint_Check
(Expr
, R_Type
);
1229 -- Ada 2005 (AI-318-02): Return-by-reference types have been
1230 -- removed and replaced by anonymous access results. This is
1231 -- an incompatibility with Ada 95. Not clear whether this
1232 -- should be enforced yet or perhaps controllable with a
1233 -- special switch. ???
1235 -- if Ada_Version >= Ada_05
1236 -- and then Is_Limited_Type (R_Type)
1237 -- and then Nkind (Expr) /= N_Aggregate
1238 -- and then Nkind (Expr) /= N_Extension_Aggregate
1239 -- and then Nkind (Expr) /= N_Function_Call
1242 -- ("(Ada 2005) illegal operand for limited return", N);
1245 -- ??? A real run-time accessibility check is needed in cases
1246 -- involving dereferences of access parameters. For now we just
1247 -- check the static cases.
1249 if Is_Inherently_Limited_Type
(Etype
(Scope_Id
))
1250 and then Object_Access_Level
(Expr
)
1251 > Subprogram_Access_Level
(Scope_Id
)
1254 Make_Raise_Program_Error
(Loc
,
1255 Reason
=> PE_Accessibility_Check_Failed
));
1259 ("cannot return a local value by reference?", N
);
1261 ("\& will be raised at run time?",
1262 N
, Standard_Program_Error
);
1265 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
1266 Error_Msg_N
("procedure cannot return value (use function)", N
);
1269 Error_Msg_N
("accept statement cannot return value", N
);
1272 -- No expression present
1275 if Kind
= E_Function
or Kind
= E_Generic_Function
then
1276 Error_Msg_N
("missing expression in return from function", N
);
1279 if (Ekind
(Scope_Id
) = E_Procedure
1280 or else Ekind
(Scope_Id
) = E_Generic_Procedure
)
1281 and then No_Return
(Scope_Id
)
1284 ("RETURN statement not allowed (No_Return)", N
);
1288 Check_Unreachable_Code
(N
);
1289 end Analyze_Return_Statement
;
1291 -------------------------
1292 -- Analyze_Return_Type --
1293 -------------------------
1295 procedure Analyze_Return_Type
(N
: Node_Id
) is
1296 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1297 Typ
: Entity_Id
:= Empty
;
1300 -- Normal case where result definition does not indicate an error
1302 if Result_Definition
(N
) /= Error
then
1303 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
1304 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
1305 Set_Parent
(Typ
, Result_Definition
(N
));
1306 Set_Is_Local_Anonymous_Access
(Typ
);
1307 Set_Etype
(Designator
, Typ
);
1309 -- Subtype_Mark case
1312 Find_Type
(Result_Definition
(N
));
1313 Typ
:= Entity
(Result_Definition
(N
));
1314 Set_Etype
(Designator
, Typ
);
1316 if Ekind
(Typ
) = E_Incomplete_Type
1317 or else (Is_Class_Wide_Type
(Typ
)
1319 Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
1322 ("invalid use of incomplete type", Result_Definition
(N
));
1326 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1328 Null_Exclusion_Static_Checks
(N
);
1330 -- Case where result definition does indicate an error
1333 Set_Etype
(Designator
, Any_Type
);
1335 end Analyze_Return_Type
;
1337 -----------------------------
1338 -- Analyze_Subprogram_Body --
1339 -----------------------------
1341 -- This procedure is called for regular subprogram bodies, generic bodies,
1342 -- and for subprogram stubs of both kinds. In the case of stubs, only the
1343 -- specification matters, and is used to create a proper declaration for
1344 -- the subprogram, or to perform conformance checks.
1346 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
1347 Loc
: constant Source_Ptr
:= Sloc
(N
);
1348 Body_Spec
: constant Node_Id
:= Specification
(N
);
1349 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
1350 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
1351 Body_Deleted
: constant Boolean := False;
1354 Spec_Id
: Entity_Id
;
1355 Spec_Decl
: Node_Id
:= Empty
;
1356 Last_Formal
: Entity_Id
:= Empty
;
1357 Conformant
: Boolean;
1358 Missing_Ret
: Boolean;
1361 procedure Check_Anonymous_Return
;
1362 -- (Ada 2005): if a function returns an access type that denotes a task,
1363 -- or a type that contains tasks, we must create a master entity for
1364 -- the anonymous type, which typically will be used in an allocator
1365 -- in the body of the function.
1367 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
1368 -- Look ahead to recognize a pragma that may appear after the body.
1369 -- If there is a previous spec, check that it appears in the same
1370 -- declarative part. If the pragma is Inline_Always, perform inlining
1371 -- unconditionally, otherwise only if Front_End_Inlining is requested.
1372 -- If the body acts as a spec, and inlining is required, we create a
1373 -- subprogram declaration for it, in order to attach the body to inline.
1375 procedure Copy_Parameter_List
(Plist
: List_Id
);
1376 -- Comment required ???
1378 procedure Verify_Overriding_Indicator
;
1379 -- If there was a previous spec, the entity has been entered in the
1380 -- current scope previously. If the body itself carries an overriding
1381 -- indicator, check that it is consistent with the known status of the
1384 ----------------------------
1385 -- Check_Anonymous_Return --
1386 ----------------------------
1388 procedure Check_Anonymous_Return
is
1393 if Present
(Spec_Id
) then
1399 if Ekind
(Scop
) = E_Function
1400 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
1401 and then Has_Task
(Designated_Type
(Etype
(Scop
)))
1402 and then Expander_Active
1405 Make_Object_Declaration
(Loc
,
1406 Defining_Identifier
=>
1407 Make_Defining_Identifier
(Loc
, Name_uMaster
),
1408 Constant_Present
=> True,
1409 Object_Definition
=>
1410 New_Reference_To
(RTE
(RE_Master_Id
), Loc
),
1412 Make_Explicit_Dereference
(Loc
,
1413 New_Reference_To
(RTE
(RE_Current_Master
), Loc
)));
1415 if Present
(Declarations
(N
)) then
1416 Prepend
(Decl
, Declarations
(N
));
1418 Set_Declarations
(N
, New_List
(Decl
));
1421 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
1422 Set_Has_Master_Entity
(Scop
);
1424 end Check_Anonymous_Return
;
1426 -------------------------
1427 -- Check_Inline_Pragma --
1428 -------------------------
1430 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
1435 if not Expander_Active
then
1439 if Is_List_Member
(N
)
1440 and then Present
(Next
(N
))
1441 and then Nkind
(Next
(N
)) = N_Pragma
1445 if Nkind
(Prag
) = N_Pragma
1447 (Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline_Always
1450 and then Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline
))
1453 (Expression
(First
(Pragma_Argument_Associations
(Prag
))))
1464 if Present
(Prag
) then
1465 if Present
(Spec_Id
) then
1466 if List_Containing
(N
) =
1467 List_Containing
(Unit_Declaration_Node
(Spec_Id
))
1473 -- Create a subprogram declaration, to make treatment uniform
1476 Subp
: constant Entity_Id
:=
1477 Make_Defining_Identifier
(Loc
, Chars
(Body_Id
));
1478 Decl
: constant Node_Id
:=
1479 Make_Subprogram_Declaration
(Loc
,
1480 Specification
=> New_Copy_Tree
(Specification
(N
)));
1482 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
1484 if Present
(First_Formal
(Body_Id
)) then
1486 Copy_Parameter_List
(Plist
);
1487 Set_Parameter_Specifications
1488 (Specification
(Decl
), Plist
);
1491 Insert_Before
(N
, Decl
);
1494 Set_Has_Pragma_Inline
(Subp
);
1496 if Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline_Always
then
1497 Set_Is_Inlined
(Subp
);
1498 Set_Next_Rep_Item
(Prag
, First_Rep_Item
(Subp
));
1499 Set_First_Rep_Item
(Subp
, Prag
);
1506 end Check_Inline_Pragma
;
1508 -------------------------
1509 -- Copy_Parameter_List --
1510 -------------------------
1512 procedure Copy_Parameter_List
(Plist
: List_Id
) is
1516 Formal
:= First_Formal
(Body_Id
);
1518 while Present
(Formal
) loop
1520 (Make_Parameter_Specification
(Loc
,
1521 Defining_Identifier
=>
1522 Make_Defining_Identifier
(Sloc
(Formal
),
1523 Chars
=> Chars
(Formal
)),
1524 In_Present
=> In_Present
(Parent
(Formal
)),
1525 Out_Present
=> Out_Present
(Parent
(Formal
)),
1527 New_Reference_To
(Etype
(Formal
), Loc
),
1529 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
1532 Next_Formal
(Formal
);
1534 end Copy_Parameter_List
;
1536 ---------------------------------
1537 -- Verify_Overriding_Indicator --
1538 ---------------------------------
1540 procedure Verify_Overriding_Indicator
is
1542 if Must_Override
(Body_Spec
)
1543 and then not Is_Overriding_Operation
(Spec_Id
)
1546 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
1548 elsif Must_Not_Override
(Body_Spec
)
1549 and then Is_Overriding_Operation
(Spec_Id
)
1552 ("subprogram& overrides inherited operation",
1553 Body_Spec
, Spec_Id
);
1555 end Verify_Overriding_Indicator
;
1557 -- Start of processing for Analyze_Subprogram_Body
1560 if Debug_Flag_C
then
1561 Write_Str
("==== Compiling subprogram body ");
1562 Write_Name
(Chars
(Body_Id
));
1563 Write_Str
(" from ");
1564 Write_Location
(Loc
);
1568 Trace_Scope
(N
, Body_Id
, " Analyze subprogram");
1570 -- Generic subprograms are handled separately. They always have a
1571 -- generic specification. Determine whether current scope has a
1572 -- previous declaration.
1574 -- If the subprogram body is defined within an instance of the same
1575 -- name, the instance appears as a package renaming, and will be hidden
1576 -- within the subprogram.
1578 if Present
(Prev_Id
)
1579 and then not Is_Overloadable
(Prev_Id
)
1580 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
1581 or else Comes_From_Source
(Prev_Id
))
1583 if Is_Generic_Subprogram
(Prev_Id
) then
1585 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1586 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1588 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
1592 -- Previous entity conflicts with subprogram name. Attempting to
1593 -- enter name will post error.
1595 Enter_Name
(Body_Id
);
1599 -- Non-generic case, find the subprogram declaration, if one was seen,
1600 -- or enter new overloaded entity in the current scope. If the
1601 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
1602 -- part of the context of one of its subunits. No need to redo the
1605 elsif Prev_Id
= Body_Id
1606 and then Has_Completion
(Body_Id
)
1611 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
1613 if Nkind
(N
) = N_Subprogram_Body_Stub
1614 or else No
(Corresponding_Spec
(N
))
1616 Spec_Id
:= Find_Corresponding_Spec
(N
);
1618 -- If this is a duplicate body, no point in analyzing it
1620 if Error_Posted
(N
) then
1624 -- A subprogram body should cause freezing of its own declaration,
1625 -- but if there was no previous explicit declaration, then the
1626 -- subprogram will get frozen too late (there may be code within
1627 -- the body that depends on the subprogram having been frozen,
1628 -- such as uses of extra formals), so we force it to be frozen
1629 -- here. Same holds if the body and the spec are compilation
1632 if No
(Spec_Id
) then
1633 Freeze_Before
(N
, Body_Id
);
1635 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1636 Freeze_Before
(N
, Spec_Id
);
1639 Spec_Id
:= Corresponding_Spec
(N
);
1643 -- Do not inline any subprogram that contains nested subprograms, since
1644 -- the backend inlining circuit seems to generate uninitialized
1645 -- references in this case. We know this happens in the case of front
1646 -- end ZCX support, but it also appears it can happen in other cases as
1647 -- well. The backend often rejects attempts to inline in the case of
1648 -- nested procedures anyway, so little if anything is lost by this.
1649 -- Note that this is test is for the benefit of the back-end. There is
1650 -- a separate test for front-end inlining that also rejects nested
1653 -- Do not do this test if errors have been detected, because in some
1654 -- error cases, this code blows up, and we don't need it anyway if
1655 -- there have been errors, since we won't get to the linker anyway.
1657 if Comes_From_Source
(Body_Id
)
1658 and then Serious_Errors_Detected
= 0
1662 P_Ent
:= Scope
(P_Ent
);
1663 exit when No
(P_Ent
) or else P_Ent
= Standard_Standard
;
1665 if Is_Subprogram
(P_Ent
) then
1666 Set_Is_Inlined
(P_Ent
, False);
1668 if Comes_From_Source
(P_Ent
)
1669 and then Has_Pragma_Inline
(P_Ent
)
1672 ("cannot inline& (nested subprogram)?",
1679 Check_Inline_Pragma
(Spec_Id
);
1681 -- Case of fully private operation in the body of the protected type.
1682 -- We must create a declaration for the subprogram, in order to attach
1683 -- the protected subprogram that will be used in internal calls.
1686 and then Comes_From_Source
(N
)
1687 and then Is_Protected_Type
(Current_Scope
)
1696 Formal
:= First_Formal
(Body_Id
);
1698 -- The protected operation always has at least one formal, namely
1699 -- the object itself, but it is only placed in the parameter list
1700 -- if expansion is enabled.
1703 or else Expander_Active
1711 Copy_Parameter_List
(Plist
);
1713 if Nkind
(Body_Spec
) = N_Procedure_Specification
then
1715 Make_Procedure_Specification
(Loc
,
1716 Defining_Unit_Name
=>
1717 Make_Defining_Identifier
(Sloc
(Body_Id
),
1718 Chars
=> Chars
(Body_Id
)),
1719 Parameter_Specifications
=> Plist
);
1722 Make_Function_Specification
(Loc
,
1723 Defining_Unit_Name
=>
1724 Make_Defining_Identifier
(Sloc
(Body_Id
),
1725 Chars
=> Chars
(Body_Id
)),
1726 Parameter_Specifications
=> Plist
,
1727 Result_Definition
=>
1728 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
1732 Make_Subprogram_Declaration
(Loc
,
1733 Specification
=> New_Spec
);
1734 Insert_Before
(N
, Decl
);
1735 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
1737 -- Indicate that the entity comes from source, to ensure that
1738 -- cross-reference information is properly generated. The body
1739 -- itself is rewritten during expansion, and the body entity will
1740 -- not appear in calls to the operation.
1742 Set_Comes_From_Source
(Spec_Id
, True);
1744 Set_Has_Completion
(Spec_Id
);
1745 Set_Convention
(Spec_Id
, Convention_Protected
);
1748 elsif Present
(Spec_Id
) then
1749 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
1750 Verify_Overriding_Indicator
;
1753 -- Place subprogram on scope stack, and make formals visible. If there
1754 -- is a spec, the visible entity remains that of the spec.
1756 if Present
(Spec_Id
) then
1757 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
1759 if Is_Child_Unit
(Spec_Id
) then
1760 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
1764 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1767 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1768 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1770 if Is_Abstract
(Spec_Id
) then
1771 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
1774 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
1775 Set_Has_Completion
(Spec_Id
);
1777 if Is_Protected_Type
(Scope
(Spec_Id
)) then
1778 Set_Privals_Chain
(Spec_Id
, New_Elmt_List
);
1781 -- If this is a body generated for a renaming, do not check for
1782 -- full conformance. The check is redundant, because the spec of
1783 -- the body is a copy of the spec in the renaming declaration,
1784 -- and the test can lead to spurious errors on nested defaults.
1786 if Present
(Spec_Decl
)
1787 and then not Comes_From_Source
(N
)
1789 (Nkind
(Original_Node
(Spec_Decl
)) =
1790 N_Subprogram_Renaming_Declaration
1791 or else (Present
(Corresponding_Body
(Spec_Decl
))
1793 Nkind
(Unit_Declaration_Node
1794 (Corresponding_Body
(Spec_Decl
))) =
1795 N_Subprogram_Renaming_Declaration
))
1801 Fully_Conformant
, True, Conformant
, Body_Id
);
1804 -- If the body is not fully conformant, we have to decide if we
1805 -- should analyze it or not. If it has a really messed up profile
1806 -- then we probably should not analyze it, since we will get too
1807 -- many bogus messages.
1809 -- Our decision is to go ahead in the non-fully conformant case
1810 -- only if it is at least mode conformant with the spec. Note
1811 -- that the call to Check_Fully_Conformant has issued the proper
1812 -- error messages to complain about the lack of conformance.
1815 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
1821 if Spec_Id
/= Body_Id
then
1822 Reference_Body_Formals
(Spec_Id
, Body_Id
);
1825 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1826 Set_Corresponding_Spec
(N
, Spec_Id
);
1828 -- Ada 2005 (AI-345): Restore the correct Etype: here we undo the
1829 -- work done by Analyze_Subprogram_Specification to allow the
1830 -- overriding of task, protected and interface primitives.
1832 if Comes_From_Source
(Spec_Id
)
1833 and then Present
(First_Entity
(Spec_Id
))
1834 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
1835 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
1836 and then Present
(Abstract_Interfaces
1837 (Etype
(First_Entity
(Spec_Id
))))
1838 and then Present
(Corresponding_Concurrent_Type
1839 (Etype
(First_Entity
(Spec_Id
))))
1841 Set_Etype
(First_Entity
(Spec_Id
),
1842 Corresponding_Concurrent_Type
1843 (Etype
(First_Entity
(Spec_Id
))));
1846 -- Ada 2005: A formal that is an access parameter may have a
1847 -- designated type imported through a limited_with clause, while
1848 -- the body has a regular with clause. Update the types of the
1849 -- formals accordingly, so that the non-limited view of each type
1850 -- is available in the body. We have already verified that the
1851 -- declarations are type-conformant.
1853 if Ada_Version
>= Ada_05
then
1859 F_Spec
:= First_Formal
(Spec_Id
);
1860 F_Body
:= First_Formal
(Body_Id
);
1862 while Present
(F_Spec
) loop
1863 if Ekind
(Etype
(F_Spec
)) = E_Anonymous_Access_Type
1865 From_With_Type
(Designated_Type
(Etype
(F_Spec
)))
1867 Set_Etype
(F_Spec
, Etype
(F_Body
));
1870 Next_Formal
(F_Spec
);
1871 Next_Formal
(F_Body
);
1876 -- Now make the formals visible, and place subprogram
1879 Install_Formals
(Spec_Id
);
1880 Last_Formal
:= Last_Entity
(Spec_Id
);
1881 New_Scope
(Spec_Id
);
1883 -- Make sure that the subprogram is immediately visible. For
1884 -- child units that have no separate spec this is indispensable.
1885 -- Otherwise it is safe albeit redundant.
1887 Set_Is_Immediately_Visible
(Spec_Id
);
1890 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
1891 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1892 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
1893 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
1895 -- Case of subprogram body with no previous spec
1899 and then Comes_From_Source
(Body_Id
)
1900 and then not Suppress_Style_Checks
(Body_Id
)
1901 and then not In_Instance
1903 Style
.Body_With_No_Spec
(N
);
1906 New_Overloaded_Entity
(Body_Id
);
1908 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1909 Set_Acts_As_Spec
(N
);
1910 Generate_Definition
(Body_Id
);
1912 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
1913 Generate_Reference_To_Formals
(Body_Id
);
1914 Install_Formals
(Body_Id
);
1915 New_Scope
(Body_Id
);
1919 -- Ada 2005 (AI-251): Check wrong placement of abstract interface
1922 if Ada_Version
>= Ada_05
1923 and then Comes_From_Source
(N
)
1930 -- Check the type of the formals
1932 E
:= First_Entity
(Body_Id
);
1933 while Present
(E
) loop
1936 if Is_Access_Type
(Etyp
) then
1937 Etyp
:= Directly_Designated_Type
(Etyp
);
1940 if not Is_Class_Wide_Type
(Etyp
)
1941 and then Is_Interface
(Etyp
)
1943 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
1945 ("(Ada 2005) abstract interface primitives must be" &
1946 " defined in package specs", N
);
1953 -- In case of functions, check the type of the result
1955 if Ekind
(Body_Id
) = E_Function
then
1956 Etyp
:= Etype
(Body_Id
);
1958 if Is_Access_Type
(Etyp
) then
1959 Etyp
:= Directly_Designated_Type
(Etyp
);
1962 if not Is_Class_Wide_Type
(Etyp
)
1963 and then Is_Interface
(Etyp
)
1965 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
1967 ("(Ada 2005) abstract interface primitives must be" &
1968 " defined in package specs", N
);
1974 -- If this is the proper body of a stub, we must verify that the stub
1975 -- conforms to the body, and to the previous spec if one was present.
1976 -- we know already that the body conforms to that spec. This test is
1977 -- only required for subprograms that come from source.
1979 if Nkind
(Parent
(N
)) = N_Subunit
1980 and then Comes_From_Source
(N
)
1981 and then not Error_Posted
(Body_Id
)
1982 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
1983 N_Subprogram_Body_Stub
1986 Old_Id
: constant Entity_Id
:=
1988 (Specification
(Corresponding_Stub
(Parent
(N
))));
1990 Conformant
: Boolean := False;
1993 if No
(Spec_Id
) then
1994 Check_Fully_Conformant
(Body_Id
, Old_Id
);
1998 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
2000 if not Conformant
then
2002 -- The stub was taken to be a new declaration. Indicate
2003 -- that it lacks a body.
2005 Set_Has_Completion
(Old_Id
, False);
2011 Set_Has_Completion
(Body_Id
);
2012 Check_Eliminated
(Body_Id
);
2014 if Nkind
(N
) = N_Subprogram_Body_Stub
then
2017 elsif Present
(Spec_Id
)
2018 and then Expander_Active
2020 (Is_Always_Inlined
(Spec_Id
)
2021 or else (Has_Pragma_Inline
(Spec_Id
) and Front_End_Inlining
))
2023 Build_Body_To_Inline
(N
, Spec_Id
);
2026 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
2027 -- if its specification we have to install the private withed units.
2029 if Is_Compilation_Unit
(Body_Id
)
2030 and then Scope
(Body_Id
) = Standard_Standard
2032 Install_Private_With_Clauses
(Body_Id
);
2035 Check_Anonymous_Return
;
2037 -- Now we can go on to analyze the body
2039 HSS
:= Handled_Statement_Sequence
(N
);
2040 Set_Actual_Subtypes
(N
, Current_Scope
);
2041 Analyze_Declarations
(Declarations
(N
));
2044 Process_End_Label
(HSS
, 't', Current_Scope
);
2046 Check_Subprogram_Order
(N
);
2047 Set_Analyzed
(Body_Id
);
2049 -- If we have a separate spec, then the analysis of the declarations
2050 -- caused the entities in the body to be chained to the spec id, but
2051 -- we want them chained to the body id. Only the formal parameters
2052 -- end up chained to the spec id in this case.
2054 if Present
(Spec_Id
) then
2056 -- We must conform to the categorization of our spec
2058 Validate_Categorization_Dependency
(N
, Spec_Id
);
2060 -- And if this is a child unit, the parent units must conform
2062 if Is_Child_Unit
(Spec_Id
) then
2063 Validate_Categorization_Dependency
2064 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
2067 if Present
(Last_Formal
) then
2069 (Last_Entity
(Body_Id
), Next_Entity
(Last_Formal
));
2070 Set_Next_Entity
(Last_Formal
, Empty
);
2071 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
2072 Set_Last_Entity
(Spec_Id
, Last_Formal
);
2075 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
2076 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
2077 Set_First_Entity
(Spec_Id
, Empty
);
2078 Set_Last_Entity
(Spec_Id
, Empty
);
2082 -- If function, check return statements
2084 if Nkind
(Body_Spec
) = N_Function_Specification
then
2089 if Present
(Spec_Id
) then
2095 if Return_Present
(Id
) then
2096 Check_Returns
(HSS
, 'F', Missing_Ret
);
2099 Set_Has_Missing_Return
(Id
);
2102 elsif not Is_Machine_Code_Subprogram
(Id
)
2103 and then not Body_Deleted
2105 Error_Msg_N
("missing RETURN statement in function body", N
);
2109 -- If procedure with No_Return, check returns
2111 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2112 and then Present
(Spec_Id
)
2113 and then No_Return
(Spec_Id
)
2115 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
2118 -- Now we are going to check for variables that are never modified in
2119 -- the body of the procedure. We omit these checks if the first
2120 -- statement of the procedure raises an exception. In particular this
2121 -- deals with the common idiom of a stubbed function, which might
2122 -- appear as something like
2124 -- function F (A : Integer) return Some_Type;
2127 -- raise Program_Error;
2131 -- Here the purpose of X is simply to satisfy the (annoying)
2132 -- requirement in Ada that there be at least one return, and we
2133 -- certainly do not want to go posting warnings on X that it is not
2137 Stm
: Node_Id
:= First
(Statements
(HSS
));
2140 -- Skip an initial label (for one thing this occurs when we are in
2141 -- front end ZCX mode, but in any case it is irrelevant).
2143 if Nkind
(Stm
) = N_Label
then
2147 -- Do the test on the original statement before expansion
2150 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
2153 -- If explicit raise statement, return with no checks
2155 if Nkind
(Ostm
) = N_Raise_Statement
then
2158 -- Check for explicit call cases which likely raise an exception
2160 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
2161 if Is_Entity_Name
(Name
(Ostm
)) then
2163 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
2166 -- If the procedure is marked No_Return, then likely it
2167 -- raises an exception, but in any case it is not coming
2168 -- back here, so no need to check beyond the call.
2170 if Ekind
(Ent
) = E_Procedure
2171 and then No_Return
(Ent
)
2175 -- If the procedure name is Raise_Exception, then also
2176 -- assume that it raises an exception. The main target
2177 -- here is Ada.Exceptions.Raise_Exception, but this name
2178 -- is pretty evocative in any context! Note that the
2179 -- procedure in Ada.Exceptions is not marked No_Return
2180 -- because of the annoying case of the null exception Id.
2182 elsif Chars
(Ent
) = Name_Raise_Exception
then
2191 -- Check for variables that are never modified
2197 -- If there is a separate spec, then transfer Never_Set_In_Source
2198 -- flags from out parameters to the corresponding entities in the
2199 -- body. The reason we do that is we want to post error flags on
2200 -- the body entities, not the spec entities.
2202 if Present
(Spec_Id
) then
2203 E1
:= First_Entity
(Spec_Id
);
2204 while Present
(E1
) loop
2205 if Ekind
(E1
) = E_Out_Parameter
then
2206 E2
:= First_Entity
(Body_Id
);
2207 while Present
(E2
) loop
2208 exit when Chars
(E1
) = Chars
(E2
);
2212 if Present
(E2
) then
2213 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
2221 -- Check references in body unless it was deleted. Note that the
2222 -- check of Body_Deleted here is not just for efficiency, it is
2223 -- necessary to avoid junk warnings on formal parameters.
2225 if not Body_Deleted
then
2226 Check_References
(Body_Id
);
2229 end Analyze_Subprogram_Body
;
2231 ------------------------------------
2232 -- Analyze_Subprogram_Declaration --
2233 ------------------------------------
2235 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
2236 Designator
: constant Entity_Id
:=
2237 Analyze_Subprogram_Specification
(Specification
(N
));
2238 Scop
: constant Entity_Id
:= Current_Scope
;
2240 -- Start of processing for Analyze_Subprogram_Declaration
2243 Generate_Definition
(Designator
);
2245 -- Check for RCI unit subprogram declarations against in-lined
2246 -- subprograms and subprograms having access parameter or limited
2247 -- parameter without Read and Write (RM E.2.3(12-13)).
2249 Validate_RCI_Subprogram_Declaration
(N
);
2253 Defining_Entity
(N
),
2254 " Analyze subprogram spec. ");
2256 if Debug_Flag_C
then
2257 Write_Str
("==== Compiling subprogram spec ");
2258 Write_Name
(Chars
(Designator
));
2259 Write_Str
(" from ");
2260 Write_Location
(Sloc
(N
));
2264 New_Overloaded_Entity
(Designator
);
2265 Check_Delayed_Subprogram
(Designator
);
2267 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
2270 if Ada_Version
>= Ada_05
2271 and then Comes_From_Source
(N
)
2272 and then Is_Dispatching_Operation
(Designator
)
2279 if Has_Controlling_Result
(Designator
) then
2280 Etyp
:= Etype
(Designator
);
2283 E
:= First_Entity
(Designator
);
2285 and then Is_Formal
(E
)
2286 and then not Is_Controlling_Formal
(E
)
2294 if Is_Access_Type
(Etyp
) then
2295 Etyp
:= Directly_Designated_Type
(Etyp
);
2298 if Is_Interface
(Etyp
)
2299 and then not Is_Abstract
(Designator
)
2300 and then not (Ekind
(Designator
) = E_Procedure
2301 and then Null_Present
(Specification
(N
)))
2303 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
2305 ("(Ada 2005) interface subprogram % must be abstract or null",
2311 -- What is the following code for, it used to be
2313 -- ??? Set_Suppress_Elaboration_Checks
2314 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
2316 -- The following seems equivalent, but a bit dubious
2318 if Elaboration_Checks_Suppressed
(Designator
) then
2319 Set_Kill_Elaboration_Checks
(Designator
);
2322 if Scop
/= Standard_Standard
2323 and then not Is_Child_Unit
(Designator
)
2325 Set_Categorization_From_Scope
(Designator
, Scop
);
2327 -- For a compilation unit, check for library-unit pragmas
2329 New_Scope
(Designator
);
2330 Set_Categorization_From_Pragmas
(N
);
2331 Validate_Categorization_Dependency
(N
, Designator
);
2335 -- For a compilation unit, set body required. This flag will only be
2336 -- reset if a valid Import or Interface pragma is processed later on.
2338 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
2339 Set_Body_Required
(Parent
(N
), True);
2341 if Ada_Version
>= Ada_05
2342 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
2343 and then Null_Present
(Specification
(N
))
2346 ("null procedure cannot be declared at library level", N
);
2350 Generate_Reference_To_Formals
(Designator
);
2351 Check_Eliminated
(Designator
);
2353 -- Ada 2005: if procedure is declared with "is null" qualifier,
2354 -- it requires no body.
2356 if Nkind
(Specification
(N
)) = N_Procedure_Specification
2357 and then Null_Present
(Specification
(N
))
2359 Set_Has_Completion
(Designator
);
2360 Set_Is_Inlined
(Designator
);
2362 if Is_Protected_Type
(Current_Scope
) then
2364 ("protected operation cannot be a null procedure", N
);
2367 end Analyze_Subprogram_Declaration
;
2369 --------------------------------------
2370 -- Analyze_Subprogram_Specification --
2371 --------------------------------------
2373 -- Reminder: N here really is a subprogram specification (not a subprogram
2374 -- declaration). This procedure is called to analyze the specification in
2375 -- both subprogram bodies and subprogram declarations (specs).
2377 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
2378 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
2379 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
2381 -- Start of processing for Analyze_Subprogram_Specification
2384 Generate_Definition
(Designator
);
2386 if Nkind
(N
) = N_Function_Specification
then
2387 Set_Ekind
(Designator
, E_Function
);
2388 Set_Mechanism
(Designator
, Default_Mechanism
);
2391 Set_Ekind
(Designator
, E_Procedure
);
2392 Set_Etype
(Designator
, Standard_Void_Type
);
2395 -- Introduce new scope for analysis of the formals and of the
2398 Set_Scope
(Designator
, Current_Scope
);
2400 if Present
(Formals
) then
2401 New_Scope
(Designator
);
2402 Process_Formals
(Formals
, N
);
2404 -- Ada 2005 (AI-345): Allow overriding primitives of protected
2405 -- interfaces by means of normal subprograms. For this purpose
2406 -- temporarily use the corresponding record type as the etype
2407 -- of the first formal.
2409 if Ada_Version
>= Ada_05
2410 and then Comes_From_Source
(Designator
)
2411 and then Present
(First_Entity
(Designator
))
2412 and then (Ekind
(Etype
(First_Entity
(Designator
)))
2415 Ekind
(Etype
(First_Entity
(Designator
)))
2417 and then Present
(Corresponding_Record_Type
2418 (Etype
(First_Entity
(Designator
))))
2419 and then Present
(Abstract_Interfaces
2420 (Corresponding_Record_Type
2421 (Etype
(First_Entity
(Designator
)))))
2423 Set_Etype
(First_Entity
(Designator
),
2424 Corresponding_Record_Type
(Etype
(First_Entity
(Designator
))));
2429 elsif Nkind
(N
) = N_Function_Specification
then
2430 Analyze_Return_Type
(N
);
2433 if Nkind
(N
) = N_Function_Specification
then
2434 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
2435 Valid_Operator_Definition
(Designator
);
2438 May_Need_Actuals
(Designator
);
2440 -- Ada 2005 (AI-251): In case of primitives associated with abstract
2441 -- interface types the following error message will be reported later
2442 -- (see Analyze_Subprogram_Declaration).
2444 if Is_Abstract
(Etype
(Designator
))
2445 and then not Is_Interface
(Etype
(Designator
))
2446 and then Nkind
(Parent
(N
))
2447 /= N_Abstract_Subprogram_Declaration
2448 and then (Nkind
(Parent
(N
)))
2449 /= N_Formal_Abstract_Subprogram_Declaration
2450 and then (Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
2451 or else not Is_Entity_Name
(Name
(Parent
(N
)))
2452 or else not Is_Abstract
(Entity
(Name
(Parent
(N
)))))
2455 ("function that returns abstract type must be abstract", N
);
2460 end Analyze_Subprogram_Specification
;
2462 --------------------------
2463 -- Build_Body_To_Inline --
2464 --------------------------
2466 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
) is
2467 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
2468 Original_Body
: Node_Id
;
2469 Body_To_Analyze
: Node_Id
;
2470 Max_Size
: constant := 10;
2471 Stat_Count
: Integer := 0;
2473 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
2474 -- Check for declarations that make inlining not worthwhile
2476 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
2477 -- Check for statements that make inlining not worthwhile: any tasking
2478 -- statement, nested at any level. Keep track of total number of
2479 -- elementary statements, as a measure of acceptable size.
2481 function Has_Pending_Instantiation
return Boolean;
2482 -- If some enclosing body contains instantiations that appear before
2483 -- the corresponding generic body, the enclosing body has a freeze node
2484 -- so that it can be elaborated after the generic itself. This might
2485 -- conflict with subsequent inlinings, so that it is unsafe to try to
2486 -- inline in such a case.
2488 function Has_Single_Return
return Boolean;
2489 -- In general we cannot inline functions that return unconstrained
2490 -- type. However, we can handle such functions if all return statements
2491 -- return a local variable that is the only declaration in the body
2492 -- of the function. In that case the call can be replaced by that
2493 -- local variable as is done for other inlined calls.
2495 procedure Remove_Pragmas
;
2496 -- A pragma Unreferenced that mentions a formal parameter has no
2497 -- meaning when the body is inlined and the formals are rewritten.
2498 -- Remove it from body to inline. The analysis of the non-inlined body
2499 -- will handle the pragma properly.
2501 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean;
2502 -- If the body of the subprogram includes a call that returns an
2503 -- unconstrained type, the secondary stack is involved, and it
2504 -- is not worth inlining.
2506 ------------------------------
2507 -- Has_Excluded_Declaration --
2508 ------------------------------
2510 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
2513 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean;
2514 -- Nested subprograms make a given body ineligible for inlining, but
2515 -- we make an exception for instantiations of unchecked conversion.
2516 -- The body has not been analyzed yet, so check the name, and verify
2517 -- that the visible entity with that name is the predefined unit.
2519 -----------------------------
2520 -- Is_Unchecked_Conversion --
2521 -----------------------------
2523 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean is
2524 Id
: constant Node_Id
:= Name
(D
);
2528 if Nkind
(Id
) = N_Identifier
2529 and then Chars
(Id
) = Name_Unchecked_Conversion
2531 Conv
:= Current_Entity
(Id
);
2533 elsif (Nkind
(Id
) = N_Selected_Component
2534 or else Nkind
(Id
) = N_Expanded_Name
)
2535 and then Chars
(Selector_Name
(Id
)) = Name_Unchecked_Conversion
2537 Conv
:= Current_Entity
(Selector_Name
(Id
));
2543 return Present
(Conv
)
2544 and then Is_Predefined_File_Name
2545 (Unit_File_Name
(Get_Source_Unit
(Conv
)))
2546 and then Is_Intrinsic_Subprogram
(Conv
);
2547 end Is_Unchecked_Conversion
;
2549 -- Start of processing for Has_Excluded_Declaration
2554 while Present
(D
) loop
2555 if (Nkind
(D
) = N_Function_Instantiation
2556 and then not Is_Unchecked_Conversion
(D
))
2557 or else Nkind
(D
) = N_Protected_Type_Declaration
2558 or else Nkind
(D
) = N_Package_Declaration
2559 or else Nkind
(D
) = N_Package_Instantiation
2560 or else Nkind
(D
) = N_Subprogram_Body
2561 or else Nkind
(D
) = N_Procedure_Instantiation
2562 or else Nkind
(D
) = N_Task_Type_Declaration
2565 ("cannot inline & (non-allowed declaration)?", D
, Subp
);
2573 end Has_Excluded_Declaration
;
2575 ----------------------------
2576 -- Has_Excluded_Statement --
2577 ----------------------------
2579 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
2585 while Present
(S
) loop
2586 Stat_Count
:= Stat_Count
+ 1;
2588 if Nkind
(S
) = N_Abort_Statement
2589 or else Nkind
(S
) = N_Asynchronous_Select
2590 or else Nkind
(S
) = N_Conditional_Entry_Call
2591 or else Nkind
(S
) = N_Delay_Relative_Statement
2592 or else Nkind
(S
) = N_Delay_Until_Statement
2593 or else Nkind
(S
) = N_Selective_Accept
2594 or else Nkind
(S
) = N_Timed_Entry_Call
2597 ("cannot inline & (non-allowed statement)?", S
, Subp
);
2600 elsif Nkind
(S
) = N_Block_Statement
then
2601 if Present
(Declarations
(S
))
2602 and then Has_Excluded_Declaration
(Declarations
(S
))
2606 elsif Present
(Handled_Statement_Sequence
(S
))
2609 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
2611 Has_Excluded_Statement
2612 (Statements
(Handled_Statement_Sequence
(S
))))
2617 elsif Nkind
(S
) = N_Case_Statement
then
2618 E
:= First
(Alternatives
(S
));
2619 while Present
(E
) loop
2620 if Has_Excluded_Statement
(Statements
(E
)) then
2627 elsif Nkind
(S
) = N_If_Statement
then
2628 if Has_Excluded_Statement
(Then_Statements
(S
)) then
2632 if Present
(Elsif_Parts
(S
)) then
2633 E
:= First
(Elsif_Parts
(S
));
2634 while Present
(E
) loop
2635 if Has_Excluded_Statement
(Then_Statements
(E
)) then
2642 if Present
(Else_Statements
(S
))
2643 and then Has_Excluded_Statement
(Else_Statements
(S
))
2648 elsif Nkind
(S
) = N_Loop_Statement
2649 and then Has_Excluded_Statement
(Statements
(S
))
2658 end Has_Excluded_Statement
;
2660 -------------------------------
2661 -- Has_Pending_Instantiation --
2662 -------------------------------
2664 function Has_Pending_Instantiation
return Boolean is
2669 while Present
(S
) loop
2670 if Is_Compilation_Unit
(S
)
2671 or else Is_Child_Unit
(S
)
2674 elsif Ekind
(S
) = E_Package
2675 and then Has_Forward_Instantiation
(S
)
2684 end Has_Pending_Instantiation
;
2686 ------------------------
2687 -- Has_Single_Return --
2688 ------------------------
2690 function Has_Single_Return
return Boolean is
2691 Return_Statement
: Node_Id
:= Empty
;
2693 function Check_Return
(N
: Node_Id
) return Traverse_Result
;
2699 function Check_Return
(N
: Node_Id
) return Traverse_Result
is
2701 if Nkind
(N
) = N_Return_Statement
then
2702 if Present
(Expression
(N
))
2703 and then Is_Entity_Name
(Expression
(N
))
2705 if No
(Return_Statement
) then
2706 Return_Statement
:= N
;
2709 elsif Chars
(Expression
(N
)) =
2710 Chars
(Expression
(Return_Statement
))
2719 -- Expression has wrong form
2729 function Check_All_Returns
is new Traverse_Func
(Check_Return
);
2731 -- Start of processing for Has_Single_Return
2734 return Check_All_Returns
(N
) = OK
2735 and then Present
(Declarations
(N
))
2736 and then Chars
(Expression
(Return_Statement
)) =
2737 Chars
(Defining_Identifier
(First
(Declarations
(N
))));
2738 end Has_Single_Return
;
2740 --------------------
2741 -- Remove_Pragmas --
2742 --------------------
2744 procedure Remove_Pragmas
is
2749 Decl
:= First
(Declarations
(Body_To_Analyze
));
2750 while Present
(Decl
) loop
2753 if Nkind
(Decl
) = N_Pragma
2754 and then Chars
(Decl
) = Name_Unreferenced
2763 --------------------------
2764 -- Uses_Secondary_Stack --
2765 --------------------------
2767 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean is
2768 function Check_Call
(N
: Node_Id
) return Traverse_Result
;
2769 -- Look for function calls that return an unconstrained type
2775 function Check_Call
(N
: Node_Id
) return Traverse_Result
is
2777 if Nkind
(N
) = N_Function_Call
2778 and then Is_Entity_Name
(Name
(N
))
2779 and then Is_Composite_Type
(Etype
(Entity
(Name
(N
))))
2780 and then not Is_Constrained
(Etype
(Entity
(Name
(N
))))
2783 ("cannot inline & (call returns unconstrained type)?",
2791 function Check_Calls
is new Traverse_Func
(Check_Call
);
2794 return Check_Calls
(Bod
) = Abandon
;
2795 end Uses_Secondary_Stack
;
2797 -- Start of processing for Build_Body_To_Inline
2800 if Nkind
(Decl
) = N_Subprogram_Declaration
2801 and then Present
(Body_To_Inline
(Decl
))
2803 return; -- Done already.
2805 -- Functions that return unconstrained composite types require
2806 -- secondary stack handling, and cannot currently be inlined, unless
2807 -- all return statements return a local variable that is the first
2808 -- local declaration in the body.
2810 elsif Ekind
(Subp
) = E_Function
2811 and then not Is_Scalar_Type
(Etype
(Subp
))
2812 and then not Is_Access_Type
(Etype
(Subp
))
2813 and then not Is_Constrained
(Etype
(Subp
))
2815 if not Has_Single_Return
then
2817 ("cannot inline & (unconstrained return type)?", N
, Subp
);
2821 -- Ditto for functions that return controlled types, where controlled
2822 -- actions interfere in complex ways with inlining.
2824 elsif Ekind
(Subp
) = E_Function
2825 and then Controlled_Type
(Etype
(Subp
))
2828 ("cannot inline & (controlled return type)?", N
, Subp
);
2832 if Present
(Declarations
(N
))
2833 and then Has_Excluded_Declaration
(Declarations
(N
))
2838 if Present
(Handled_Statement_Sequence
(N
)) then
2839 if Present
(Exception_Handlers
(Handled_Statement_Sequence
(N
))) then
2841 ("cannot inline& (exception handler)?",
2842 First
(Exception_Handlers
(Handled_Statement_Sequence
(N
))),
2846 Has_Excluded_Statement
2847 (Statements
(Handled_Statement_Sequence
(N
)))
2853 -- We do not inline a subprogram that is too large, unless it is
2854 -- marked Inline_Always. This pragma does not suppress the other
2855 -- checks on inlining (forbidden declarations, handlers, etc).
2857 if Stat_Count
> Max_Size
2858 and then not Is_Always_Inlined
(Subp
)
2860 Cannot_Inline
("cannot inline& (body too large)?", N
, Subp
);
2864 if Has_Pending_Instantiation
then
2866 ("cannot inline& (forward instance within enclosing body)?",
2871 -- Within an instance, the body to inline must be treated as a nested
2872 -- generic, so that the proper global references are preserved.
2875 Save_Env
(Scope
(Current_Scope
), Scope
(Current_Scope
));
2876 Original_Body
:= Copy_Generic_Node
(N
, Empty
, True);
2878 Original_Body
:= Copy_Separate_Tree
(N
);
2881 -- We need to capture references to the formals in order to substitute
2882 -- the actuals at the point of inlining, i.e. instantiation. To treat
2883 -- the formals as globals to the body to inline, we nest it within
2884 -- a dummy parameterless subprogram, declared within the real one.
2885 -- To avoid generating an internal name (which is never public, and
2886 -- which affects serial numbers of other generated names), we use
2887 -- an internal symbol that cannot conflict with user declarations.
2889 Set_Parameter_Specifications
(Specification
(Original_Body
), No_List
);
2890 Set_Defining_Unit_Name
2891 (Specification
(Original_Body
),
2892 Make_Defining_Identifier
(Sloc
(N
), Name_uParent
));
2893 Set_Corresponding_Spec
(Original_Body
, Empty
);
2895 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
2897 -- Set return type of function, which is also global and does not need
2900 if Ekind
(Subp
) = E_Function
then
2901 Set_Result_Definition
(Specification
(Body_To_Analyze
),
2902 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
2905 if No
(Declarations
(N
)) then
2906 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
2908 Append
(Body_To_Analyze
, Declarations
(N
));
2911 Expander_Mode_Save_And_Set
(False);
2914 Analyze
(Body_To_Analyze
);
2915 New_Scope
(Defining_Entity
(Body_To_Analyze
));
2916 Save_Global_References
(Original_Body
);
2918 Remove
(Body_To_Analyze
);
2920 Expander_Mode_Restore
;
2926 -- If secondary stk used there is no point in inlining. We have
2927 -- already issued the warning in this case, so nothing to do.
2929 if Uses_Secondary_Stack
(Body_To_Analyze
) then
2933 Set_Body_To_Inline
(Decl
, Original_Body
);
2934 Set_Ekind
(Defining_Entity
(Original_Body
), Ekind
(Subp
));
2935 Set_Is_Inlined
(Subp
);
2936 end Build_Body_To_Inline
;
2942 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
; Subp
: Entity_Id
) is
2944 -- Do not emit warning if this is a predefined unit which is not
2945 -- the main unit. With validity checks enabled, some predefined
2946 -- subprograms may contain nested subprograms and become ineligible
2949 if Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(Subp
)))
2950 and then not In_Extended_Main_Source_Unit
(Subp
)
2954 elsif Is_Always_Inlined
(Subp
) then
2956 -- Remove last character (question mark) to make this into an error,
2957 -- because the Inline_Always pragma cannot be obeyed.
2959 Error_Msg_NE
(Msg
(Msg
'First .. Msg
'Last - 1), N
, Subp
);
2961 elsif Ineffective_Inline_Warnings
then
2962 Error_Msg_NE
(Msg
, N
, Subp
);
2966 -----------------------
2967 -- Check_Conformance --
2968 -----------------------
2970 procedure Check_Conformance
2971 (New_Id
: Entity_Id
;
2973 Ctype
: Conformance_Type
;
2975 Conforms
: out Boolean;
2976 Err_Loc
: Node_Id
:= Empty
;
2977 Get_Inst
: Boolean := False;
2978 Skip_Controlling_Formals
: Boolean := False)
2980 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
2981 -- Post error message for conformance error on given node. Two messages
2982 -- are output. The first points to the previous declaration with a
2983 -- general "no conformance" message. The second is the detailed reason,
2984 -- supplied as Msg. The parameter N provide information for a possible
2985 -- & insertion in the message, and also provides the location for
2986 -- posting the message in the absence of a specified Err_Loc location.
2988 -----------------------
2989 -- Conformance_Error --
2990 -----------------------
2992 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
2999 if No
(Err_Loc
) then
3005 Error_Msg_Sloc
:= Sloc
(Old_Id
);
3008 when Type_Conformant
=>
3010 ("not type conformant with declaration#!", Enode
);
3012 when Mode_Conformant
=>
3014 ("not mode conformant with declaration#!", Enode
);
3016 when Subtype_Conformant
=>
3018 ("not subtype conformant with declaration#!", Enode
);
3020 when Fully_Conformant
=>
3022 ("not fully conformant with declaration#!", Enode
);
3025 Error_Msg_NE
(Msg
, Enode
, N
);
3027 end Conformance_Error
;
3031 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
3032 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
3033 Old_Formal
: Entity_Id
;
3034 New_Formal
: Entity_Id
;
3035 Access_Types_Match
: Boolean;
3036 Old_Formal_Base
: Entity_Id
;
3037 New_Formal_Base
: Entity_Id
;
3039 -- Start of processing for Check_Conformance
3044 -- We need a special case for operators, since they don't appear
3047 if Ctype
= Type_Conformant
then
3048 if Ekind
(New_Id
) = E_Operator
3049 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
3055 -- If both are functions/operators, check return types conform
3057 if Old_Type
/= Standard_Void_Type
3058 and then New_Type
/= Standard_Void_Type
3060 if not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
3061 Conformance_Error
("return type does not match!", New_Id
);
3065 -- Ada 2005 (AI-231): In case of anonymous access types check the
3066 -- null-exclusion and access-to-constant attributes must match.
3068 if Ada_Version
>= Ada_05
3069 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
3071 (Can_Never_Be_Null
(Old_Type
)
3072 /= Can_Never_Be_Null
(New_Type
)
3073 or else Is_Access_Constant
(Etype
(Old_Type
))
3074 /= Is_Access_Constant
(Etype
(New_Type
)))
3076 Conformance_Error
("return type does not match!", New_Id
);
3080 -- If either is a function/operator and the other isn't, error
3082 elsif Old_Type
/= Standard_Void_Type
3083 or else New_Type
/= Standard_Void_Type
3085 Conformance_Error
("functions can only match functions!", New_Id
);
3089 -- In subtype conformant case, conventions must match (RM 6.3.1(16))
3090 -- If this is a renaming as body, refine error message to indicate that
3091 -- the conflict is with the original declaration. If the entity is not
3092 -- frozen, the conventions don't have to match, the one of the renamed
3093 -- entity is inherited.
3095 if Ctype
>= Subtype_Conformant
then
3096 if Convention
(Old_Id
) /= Convention
(New_Id
) then
3098 if not Is_Frozen
(New_Id
) then
3101 elsif Present
(Err_Loc
)
3102 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
3103 and then Present
(Corresponding_Spec
(Err_Loc
))
3105 Error_Msg_Name_1
:= Chars
(New_Id
);
3107 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
3109 Conformance_Error
("prior declaration for% has convention %!");
3112 Conformance_Error
("calling conventions do not match!");
3117 elsif Is_Formal_Subprogram
(Old_Id
)
3118 or else Is_Formal_Subprogram
(New_Id
)
3120 Conformance_Error
("formal subprograms not allowed!");
3125 -- Deal with parameters
3127 -- Note: we use the entity information, rather than going directly
3128 -- to the specification in the tree. This is not only simpler, but
3129 -- absolutely necessary for some cases of conformance tests between
3130 -- operators, where the declaration tree simply does not exist!
3132 Old_Formal
:= First_Formal
(Old_Id
);
3133 New_Formal
:= First_Formal
(New_Id
);
3135 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
3136 if Is_Controlling_Formal
(Old_Formal
)
3137 and then Is_Controlling_Formal
(New_Formal
)
3138 and then Skip_Controlling_Formals
3140 goto Skip_Controlling_Formal
;
3143 if Ctype
= Fully_Conformant
then
3145 -- Names must match. Error message is more accurate if we do
3146 -- this before checking that the types of the formals match.
3148 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
3149 Conformance_Error
("name & does not match!", New_Formal
);
3151 -- Set error posted flag on new formal as well to stop
3152 -- junk cascaded messages in some cases.
3154 Set_Error_Posted
(New_Formal
);
3159 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
3160 -- case occurs whenever a subprogram is being renamed and one of its
3161 -- parameters imposes a null exclusion. For example:
3163 -- type T is null record;
3164 -- type Acc_T is access T;
3165 -- subtype Acc_T_Sub is Acc_T;
3167 -- procedure P (Obj : not null Acc_T_Sub); -- itype
3168 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
3171 Old_Formal_Base
:= Etype
(Old_Formal
);
3172 New_Formal_Base
:= Etype
(New_Formal
);
3175 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
3176 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
3179 Access_Types_Match
:= Ada_Version
>= Ada_05
3181 -- Ensure that this rule is only applied when New_Id is a
3182 -- renaming of Old_Id
3184 and then Nkind
(Parent
(Parent
(New_Id
)))
3185 = N_Subprogram_Renaming_Declaration
3186 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
3187 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
3188 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
3190 -- Now handle the allowed access-type case
3192 and then Is_Access_Type
(Old_Formal_Base
)
3193 and then Is_Access_Type
(New_Formal_Base
)
3194 and then Directly_Designated_Type
(Old_Formal_Base
) =
3195 Directly_Designated_Type
(New_Formal_Base
)
3196 and then ((Is_Itype
(Old_Formal_Base
)
3197 and then Can_Never_Be_Null
(Old_Formal_Base
))
3199 (Is_Itype
(New_Formal_Base
)
3200 and then Can_Never_Be_Null
(New_Formal_Base
)));
3202 -- Types must always match. In the visible part of an instance,
3203 -- usual overloading rules for dispatching operations apply, and
3204 -- we check base types (not the actual subtypes).
3206 if In_Instance_Visible_Part
3207 and then Is_Dispatching_Operation
(New_Id
)
3209 if not Conforming_Types
3210 (T1
=> Base_Type
(Etype
(Old_Formal
)),
3211 T2
=> Base_Type
(Etype
(New_Formal
)),
3213 Get_Inst
=> Get_Inst
)
3214 and then not Access_Types_Match
3216 Conformance_Error
("type of & does not match!", New_Formal
);
3220 elsif not Conforming_Types
3221 (T1
=> Etype
(Old_Formal
),
3222 T2
=> Etype
(New_Formal
),
3224 Get_Inst
=> Get_Inst
)
3225 and then not Access_Types_Match
3227 Conformance_Error
("type of & does not match!", New_Formal
);
3231 -- For mode conformance, mode must match
3233 if Ctype
>= Mode_Conformant
3234 and then Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
)
3236 Conformance_Error
("mode of & does not match!", New_Formal
);
3240 -- Full conformance checks
3242 if Ctype
= Fully_Conformant
then
3244 -- We have checked already that names match
3246 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
3248 -- Ada 2005 (AI-231): In case of anonymous access types check
3249 -- the null-exclusion and access-to-constant attributes must
3252 if Ada_Version
>= Ada_05
3253 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
3255 (Can_Never_Be_Null
(Old_Formal
)
3256 /= Can_Never_Be_Null
(New_Formal
)
3257 or else Is_Access_Constant
(Etype
(Old_Formal
))
3258 /= Is_Access_Constant
(Etype
(New_Formal
)))
3260 -- It is allowed to omit the null-exclusion in case of
3261 -- stream attribute subprograms
3264 TSS_Name
: TSS_Name_Type
;
3267 Get_Name_String
(Chars
(New_Id
));
3271 (Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
3273 if TSS_Name
/= TSS_Stream_Read
3274 and then TSS_Name
/= TSS_Stream_Write
3275 and then TSS_Name
/= TSS_Stream_Input
3276 and then TSS_Name
/= TSS_Stream_Output
3279 ("type of & does not match!", New_Formal
);
3285 -- Check default expressions for in parameters
3288 NewD
: constant Boolean :=
3289 Present
(Default_Value
(New_Formal
));
3290 OldD
: constant Boolean :=
3291 Present
(Default_Value
(Old_Formal
));
3293 if NewD
or OldD
then
3295 -- The old default value has been analyzed because the
3296 -- current full declaration will have frozen everything
3297 -- before. The new default values have not been
3298 -- analyzed, so analyze them now before we check for
3303 Analyze_Per_Use_Expression
3304 (Default_Value
(New_Formal
), Etype
(New_Formal
));
3308 if not (NewD
and OldD
)
3309 or else not Fully_Conformant_Expressions
3310 (Default_Value
(Old_Formal
),
3311 Default_Value
(New_Formal
))
3314 ("default expression for & does not match!",
3323 -- A couple of special checks for Ada 83 mode. These checks are
3324 -- skipped if either entity is an operator in package Standard.
3325 -- or if either old or new instance is not from the source program.
3327 if Ada_Version
= Ada_83
3328 and then Sloc
(Old_Id
) > Standard_Location
3329 and then Sloc
(New_Id
) > Standard_Location
3330 and then Comes_From_Source
(Old_Id
)
3331 and then Comes_From_Source
(New_Id
)
3334 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
3335 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
3338 -- Explicit IN must be present or absent in both cases. This
3339 -- test is required only in the full conformance case.
3341 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
3342 and then Ctype
= Fully_Conformant
3345 ("(Ada 83) IN must appear in both declarations",
3350 -- Grouping (use of comma in param lists) must be the same
3351 -- This is where we catch a misconformance like:
3354 -- A : Integer; B : Integer
3356 -- which are represented identically in the tree except
3357 -- for the setting of the flags More_Ids and Prev_Ids.
3359 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
3360 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
3363 ("grouping of & does not match!", New_Formal
);
3369 -- This label is required when skipping controlling formals
3371 <<Skip_Controlling_Formal
>>
3373 Next_Formal
(Old_Formal
);
3374 Next_Formal
(New_Formal
);
3377 if Present
(Old_Formal
) then
3378 Conformance_Error
("too few parameters!");
3381 elsif Present
(New_Formal
) then
3382 Conformance_Error
("too many parameters!", New_Formal
);
3385 end Check_Conformance
;
3387 -----------------------
3388 -- Check_Conventions --
3389 -----------------------
3391 procedure Check_Conventions
(Typ
: Entity_Id
) is
3392 procedure Check_Convention
3394 Search_From
: Elmt_Id
);
3395 -- Verify that the convention of inherited dispatching operation
3396 -- Op is consistent among all subprograms it overrides. In order
3397 -- to minimize the search, Search_From is utilized to designate
3398 -- a specific point in the list rather than iterating over the
3399 -- whole list once more.
3401 ----------------------
3402 -- Check_Convention --
3403 ----------------------
3405 procedure Check_Convention
3407 Search_From
: Elmt_Id
)
3409 procedure Error_Msg_Operation
(Op
: Entity_Id
);
3410 -- Emit a continuation to an error message depicting the kind,
3411 -- name, convention and source location of subprogram Op.
3413 -------------------------
3414 -- Error_Msg_Operation --
3415 -------------------------
3417 procedure Error_Msg_Operation
(Op
: Entity_Id
) is
3419 Error_Msg_Name_1
:= Chars
(Op
);
3421 -- Error messages of primitive subprograms do not contain a
3422 -- convention attribute since the convention may have been
3423 -- first inherited from a parent subprogram, then changed by
3426 if Comes_From_Source
(Op
) then
3427 Error_Msg_Sloc
:= Sloc
(Op
);
3429 ("\ primitive % defined #", Typ
);
3432 Error_Msg_Name_2
:= Get_Convention_Name
(Convention
(Op
));
3434 if Present
(Abstract_Interface_Alias
(Op
)) then
3435 Error_Msg_Sloc
:= Sloc
(Abstract_Interface_Alias
(Op
));
3436 Error_Msg_N
("\\overridden operation % with " &
3437 "convention % defined #", Typ
);
3439 else pragma Assert
(Present
(Alias
(Op
)));
3440 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
3441 Error_Msg_N
("\\inherited operation % with " &
3442 "convention % defined #", Typ
);
3445 end Error_Msg_Operation
;
3449 Prim_Op
: Entity_Id
;
3450 Prim_Op_Elmt
: Elmt_Id
;
3452 -- Start of processing for Check_Convention
3455 Prim_Op_Elmt
:= Next_Elmt
(Search_From
);
3456 while Present
(Prim_Op_Elmt
) loop
3457 Prim_Op
:= Node
(Prim_Op_Elmt
);
3459 -- A small optimization, skip the predefined dispatching
3460 -- operations since they always have the same convention.
3461 -- Also do not consider abstract primitives since those
3462 -- are left by an erroneous overriding.
3464 if not Is_Predefined_Dispatching_Operation
(Prim_Op
)
3465 and then not Is_Abstract
(Prim_Op
)
3466 and then Chars
(Prim_Op
) = Chars
(Op
)
3467 and then Type_Conformant
(Prim_Op
, Op
)
3468 and then Convention
(Prim_Op
) /= Convention
(Op
)
3471 ("inconsistent conventions in primitive operations", Typ
);
3473 Error_Msg_Operation
(Op
);
3474 Error_Msg_Operation
(Prim_Op
);
3476 -- Avoid cascading errors
3481 Next_Elmt
(Prim_Op_Elmt
);
3483 end Check_Convention
;
3487 Prim_Op
: Entity_Id
;
3488 Prim_Op_Elmt
: Elmt_Id
;
3490 -- Start of processing for Check_Conventions
3493 -- The algorithm checks every overriding dispatching operation
3494 -- against all the corresponding overridden dispatching operations,
3495 -- detecting differences in coventions.
3497 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3498 while Present
(Prim_Op_Elmt
) loop
3499 Prim_Op
:= Node
(Prim_Op_Elmt
);
3501 -- A small optimization, skip the predefined dispatching operations
3502 -- since they always have the same convention. Also avoid processing
3503 -- of abstract primitives left from an erroneous overriding.
3505 if not Is_Predefined_Dispatching_Operation
(Prim_Op
)
3506 and then not Is_Abstract
(Prim_Op
)
3510 Search_From
=> Prim_Op_Elmt
);
3513 Next_Elmt
(Prim_Op_Elmt
);
3515 end Check_Conventions
;
3517 ------------------------------
3518 -- Check_Delayed_Subprogram --
3519 ------------------------------
3521 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
3524 procedure Possible_Freeze
(T
: Entity_Id
);
3525 -- T is the type of either a formal parameter or of the return type.
3526 -- If T is not yet frozen and needs a delayed freeze, then the
3527 -- subprogram itself must be delayed.
3529 ---------------------
3530 -- Possible_Freeze --
3531 ---------------------
3533 procedure Possible_Freeze
(T
: Entity_Id
) is
3535 if Has_Delayed_Freeze
(T
)
3536 and then not Is_Frozen
(T
)
3538 Set_Has_Delayed_Freeze
(Designator
);
3540 elsif Is_Access_Type
(T
)
3541 and then Has_Delayed_Freeze
(Designated_Type
(T
))
3542 and then not Is_Frozen
(Designated_Type
(T
))
3544 Set_Has_Delayed_Freeze
(Designator
);
3546 end Possible_Freeze
;
3548 -- Start of processing for Check_Delayed_Subprogram
3551 -- Never need to freeze abstract subprogram
3553 if Is_Abstract
(Designator
) then
3556 -- Need delayed freeze if return type itself needs a delayed
3557 -- freeze and is not yet frozen.
3559 Possible_Freeze
(Etype
(Designator
));
3560 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
3562 -- Need delayed freeze if any of the formal types themselves need
3563 -- a delayed freeze and are not yet frozen.
3565 F
:= First_Formal
(Designator
);
3566 while Present
(F
) loop
3567 Possible_Freeze
(Etype
(F
));
3568 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
3573 -- Mark functions that return by reference. Note that it cannot be
3574 -- done for delayed_freeze subprograms because the underlying
3575 -- returned type may not be known yet (for private types)
3577 if not Has_Delayed_Freeze
(Designator
)
3578 and then Expander_Active
3581 Typ
: constant Entity_Id
:= Etype
(Designator
);
3582 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
3585 if Is_Inherently_Limited_Type
(Typ
) then
3586 Set_Returns_By_Ref
(Designator
);
3588 elsif Present
(Utyp
) and then Controlled_Type
(Utyp
) then
3589 Set_Returns_By_Ref
(Designator
);
3593 end Check_Delayed_Subprogram
;
3595 ------------------------------------
3596 -- Check_Discriminant_Conformance --
3597 ------------------------------------
3599 procedure Check_Discriminant_Conformance
3604 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
3605 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
3606 New_Discr_Id
: Entity_Id
;
3607 New_Discr_Type
: Entity_Id
;
3609 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
3610 -- Post error message for conformance error on given node. Two messages
3611 -- are output. The first points to the previous declaration with a
3612 -- general "no conformance" message. The second is the detailed reason,
3613 -- supplied as Msg. The parameter N provide information for a possible
3614 -- & insertion in the message.
3616 -----------------------
3617 -- Conformance_Error --
3618 -----------------------
3620 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
3622 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
3623 Error_Msg_N
("not fully conformant with declaration#!", N
);
3624 Error_Msg_NE
(Msg
, N
, N
);
3625 end Conformance_Error
;
3627 -- Start of processing for Check_Discriminant_Conformance
3630 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
3632 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
3634 -- The subtype mark of the discriminant on the full type has not
3635 -- been analyzed so we do it here. For an access discriminant a new
3638 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
3640 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
3643 Analyze
(Discriminant_Type
(New_Discr
));
3644 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
3647 if not Conforming_Types
3648 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
3650 Conformance_Error
("type of & does not match!", New_Discr_Id
);
3653 -- Treat the new discriminant as an occurrence of the old one,
3654 -- for navigation purposes, and fill in some semantic
3655 -- information, for completeness.
3657 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
3658 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
3659 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
3664 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
3665 Conformance_Error
("name & does not match!", New_Discr_Id
);
3669 -- Default expressions must match
3672 NewD
: constant Boolean :=
3673 Present
(Expression
(New_Discr
));
3674 OldD
: constant Boolean :=
3675 Present
(Expression
(Parent
(Old_Discr
)));
3678 if NewD
or OldD
then
3680 -- The old default value has been analyzed and expanded,
3681 -- because the current full declaration will have frozen
3682 -- everything before. The new default values have not been
3683 -- expanded, so expand now to check conformance.
3686 Analyze_Per_Use_Expression
3687 (Expression
(New_Discr
), New_Discr_Type
);
3690 if not (NewD
and OldD
)
3691 or else not Fully_Conformant_Expressions
3692 (Expression
(Parent
(Old_Discr
)),
3693 Expression
(New_Discr
))
3697 ("default expression for & does not match!",
3704 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
3706 if Ada_Version
= Ada_83
then
3708 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
3711 -- Grouping (use of comma in param lists) must be the same
3712 -- This is where we catch a misconformance like:
3715 -- A : Integer; B : Integer
3717 -- which are represented identically in the tree except
3718 -- for the setting of the flags More_Ids and Prev_Ids.
3720 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
3721 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
3724 ("grouping of & does not match!", New_Discr_Id
);
3730 Next_Discriminant
(Old_Discr
);
3734 if Present
(Old_Discr
) then
3735 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
3738 elsif Present
(New_Discr
) then
3740 ("too many discriminants!", Defining_Identifier
(New_Discr
));
3743 end Check_Discriminant_Conformance
;
3745 ----------------------------
3746 -- Check_Fully_Conformant --
3747 ----------------------------
3749 procedure Check_Fully_Conformant
3750 (New_Id
: Entity_Id
;
3752 Err_Loc
: Node_Id
:= Empty
)
3757 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
3758 end Check_Fully_Conformant
;
3760 ---------------------------
3761 -- Check_Mode_Conformant --
3762 ---------------------------
3764 procedure Check_Mode_Conformant
3765 (New_Id
: Entity_Id
;
3767 Err_Loc
: Node_Id
:= Empty
;
3768 Get_Inst
: Boolean := False)
3774 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
3775 end Check_Mode_Conformant
;
3777 --------------------------------
3778 -- Check_Overriding_Indicator --
3779 --------------------------------
3781 procedure Check_Overriding_Indicator
3783 Overridden_Subp
: Entity_Id
:= Empty
)
3789 -- No overriding indicator for literals
3791 if Ekind
(Subp
) = E_Enumeration_Literal
then
3794 elsif Ekind
(Subp
) = E_Entry
then
3795 Decl
:= Parent
(Subp
);
3798 Decl
:= Unit_Declaration_Node
(Subp
);
3801 if Nkind
(Decl
) = N_Subprogram_Body
3802 or else Nkind
(Decl
) = N_Subprogram_Body_Stub
3803 or else Nkind
(Decl
) = N_Subprogram_Declaration
3804 or else Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
3806 Spec
:= Specification
(Decl
);
3808 elsif Nkind
(Decl
) = N_Entry_Declaration
then
3815 if Present
(Overridden_Subp
) then
3816 if Must_Not_Override
(Spec
) then
3817 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
3819 if Ekind
(Subp
) = E_Entry
then
3820 Error_Msg_NE
("entry & overrides inherited operation #",
3823 Error_Msg_NE
("subprogram & overrides inherited operation #",
3828 if Must_Override
(Spec
) then
3829 if Ekind
(Subp
) = E_Entry
then
3830 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
3832 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
3836 end Check_Overriding_Indicator
;
3842 procedure Check_Returns
3846 Proc
: Entity_Id
:= Empty
)
3850 procedure Check_Statement_Sequence
(L
: List_Id
);
3851 -- Internal recursive procedure to check a list of statements for proper
3852 -- termination by a return statement (or a transfer of control or a
3853 -- compound statement that is itself internally properly terminated).
3855 ------------------------------
3856 -- Check_Statement_Sequence --
3857 ------------------------------
3859 procedure Check_Statement_Sequence
(L
: List_Id
) is
3863 Raise_Exception_Call
: Boolean;
3864 -- Set True if statement sequence terminated by Raise_Exception call
3865 -- or a Reraise_Occurrence call.
3868 Raise_Exception_Call
:= False;
3870 -- Get last real statement
3872 Last_Stm
:= Last
(L
);
3874 -- Don't count pragmas
3876 while Nkind
(Last_Stm
) = N_Pragma
3878 -- Don't count call to SS_Release (can happen after Raise_Exception)
3881 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
3883 Nkind
(Name
(Last_Stm
)) = N_Identifier
3885 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
3887 -- Don't count exception junk
3890 ((Nkind
(Last_Stm
) = N_Goto_Statement
3891 or else Nkind
(Last_Stm
) = N_Label
3892 or else Nkind
(Last_Stm
) = N_Object_Declaration
)
3893 and then Exception_Junk
(Last_Stm
))
3898 -- Here we have the "real" last statement
3900 Kind
:= Nkind
(Last_Stm
);
3902 -- Transfer of control, OK. Note that in the No_Return procedure
3903 -- case, we already diagnosed any explicit return statements, so
3904 -- we can treat them as OK in this context.
3906 if Is_Transfer
(Last_Stm
) then
3909 -- Check cases of explicit non-indirect procedure calls
3911 elsif Kind
= N_Procedure_Call_Statement
3912 and then Is_Entity_Name
(Name
(Last_Stm
))
3914 -- Check call to Raise_Exception procedure which is treated
3915 -- specially, as is a call to Reraise_Occurrence.
3917 -- We suppress the warning in these cases since it is likely that
3918 -- the programmer really does not expect to deal with the case
3919 -- of Null_Occurrence, and thus would find a warning about a
3920 -- missing return curious, and raising Program_Error does not
3921 -- seem such a bad behavior if this does occur.
3923 -- Note that in the Ada 2005 case for Raise_Exception, the actual
3924 -- behavior will be to raise Constraint_Error (see AI-329).
3926 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
3928 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
3930 Raise_Exception_Call
:= True;
3932 -- For Raise_Exception call, test first argument, if it is
3933 -- an attribute reference for a 'Identity call, then we know
3934 -- that the call cannot possibly return.
3937 Arg
: constant Node_Id
:=
3938 Original_Node
(First_Actual
(Last_Stm
));
3941 if Nkind
(Arg
) = N_Attribute_Reference
3942 and then Attribute_Name
(Arg
) = Name_Identity
3949 -- If statement, need to look inside if there is an else and check
3950 -- each constituent statement sequence for proper termination.
3952 elsif Kind
= N_If_Statement
3953 and then Present
(Else_Statements
(Last_Stm
))
3955 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
3956 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
3958 if Present
(Elsif_Parts
(Last_Stm
)) then
3960 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
3963 while Present
(Elsif_Part
) loop
3964 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
3972 -- Case statement, check each case for proper termination
3974 elsif Kind
= N_Case_Statement
then
3979 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
3980 while Present
(Case_Alt
) loop
3981 Check_Statement_Sequence
(Statements
(Case_Alt
));
3982 Next_Non_Pragma
(Case_Alt
);
3988 -- Block statement, check its handled sequence of statements
3990 elsif Kind
= N_Block_Statement
then
3996 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
4005 -- Loop statement. If there is an iteration scheme, we can definitely
4006 -- fall out of the loop. Similarly if there is an exit statement, we
4007 -- can fall out. In either case we need a following return.
4009 elsif Kind
= N_Loop_Statement
then
4010 if Present
(Iteration_Scheme
(Last_Stm
))
4011 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
4015 -- A loop with no exit statement or iteration scheme if either
4016 -- an inifite loop, or it has some other exit (raise/return).
4017 -- In either case, no warning is required.
4023 -- Timed entry call, check entry call and delay alternatives
4025 -- Note: in expanded code, the timed entry call has been converted
4026 -- to a set of expanded statements on which the check will work
4027 -- correctly in any case.
4029 elsif Kind
= N_Timed_Entry_Call
then
4031 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
4032 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
4035 -- If statement sequence of entry call alternative is missing,
4036 -- then we can definitely fall through, and we post the error
4037 -- message on the entry call alternative itself.
4039 if No
(Statements
(ECA
)) then
4042 -- If statement sequence of delay alternative is missing, then
4043 -- we can definitely fall through, and we post the error
4044 -- message on the delay alternative itself.
4046 -- Note: if both ECA and DCA are missing the return, then we
4047 -- post only one message, should be enough to fix the bugs.
4048 -- If not we will get a message next time on the DCA when the
4051 elsif No
(Statements
(DCA
)) then
4054 -- Else check both statement sequences
4057 Check_Statement_Sequence
(Statements
(ECA
));
4058 Check_Statement_Sequence
(Statements
(DCA
));
4063 -- Conditional entry call, check entry call and else part
4065 -- Note: in expanded code, the conditional entry call has been
4066 -- converted to a set of expanded statements on which the check
4067 -- will work correctly in any case.
4069 elsif Kind
= N_Conditional_Entry_Call
then
4071 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
4074 -- If statement sequence of entry call alternative is missing,
4075 -- then we can definitely fall through, and we post the error
4076 -- message on the entry call alternative itself.
4078 if No
(Statements
(ECA
)) then
4081 -- Else check statement sequence and else part
4084 Check_Statement_Sequence
(Statements
(ECA
));
4085 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
4091 -- If we fall through, issue appropriate message
4094 if not Raise_Exception_Call
then
4096 ("?RETURN statement missing following this statement",
4099 ("\?Program_Error may be raised at run time",
4103 -- Note: we set Err even though we have not issued a warning
4104 -- because we still have a case of a missing return. This is
4105 -- an extremely marginal case, probably will never be noticed
4106 -- but we might as well get it right.
4110 -- Otherwise we have the case of a procedure marked No_Return
4114 ("?implied return after this statement will raise Program_Error",
4117 ("?procedure & is marked as No_Return",
4121 RE
: constant Node_Id
:=
4122 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
4123 Reason
=> PE_Implicit_Return
);
4125 Insert_After
(Last_Stm
, RE
);
4129 end Check_Statement_Sequence
;
4131 -- Start of processing for Check_Returns
4135 Check_Statement_Sequence
(Statements
(HSS
));
4137 if Present
(Exception_Handlers
(HSS
)) then
4138 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
4139 while Present
(Handler
) loop
4140 Check_Statement_Sequence
(Statements
(Handler
));
4141 Next_Non_Pragma
(Handler
);
4146 ----------------------------
4147 -- Check_Subprogram_Order --
4148 ----------------------------
4150 procedure Check_Subprogram_Order
(N
: Node_Id
) is
4152 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
4153 -- This is used to check if S1 > S2 in the sense required by this
4154 -- test, for example nameab < namec, but name2 < name10.
4156 -----------------------------
4157 -- Subprogram_Name_Greater --
4158 -----------------------------
4160 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
4165 -- Remove trailing numeric parts
4168 while S1
(L1
) in '0' .. '9' loop
4173 while S2
(L2
) in '0' .. '9' loop
4177 -- If non-numeric parts non-equal, that's decisive
4179 if S1
(S1
'First .. L1
) < S2
(S2
'First .. L2
) then
4182 elsif S1
(S1
'First .. L1
) > S2
(S2
'First .. L2
) then
4185 -- If non-numeric parts equal, compare suffixed numeric parts. Note
4186 -- that a missing suffix is treated as numeric zero in this test.
4190 while L1
< S1
'Last loop
4192 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
4196 while L2
< S2
'Last loop
4198 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
4203 end Subprogram_Name_Greater
;
4205 -- Start of processing for Check_Subprogram_Order
4208 -- Check body in alpha order if this is option
4211 and then Style_Check_Order_Subprograms
4212 and then Nkind
(N
) = N_Subprogram_Body
4213 and then Comes_From_Source
(N
)
4214 and then In_Extended_Main_Source_Unit
(N
)
4218 renames Scope_Stack
.Table
4219 (Scope_Stack
.Last
).Last_Subprogram_Name
;
4221 Body_Id
: constant Entity_Id
:=
4222 Defining_Entity
(Specification
(N
));
4225 Get_Decoded_Name_String
(Chars
(Body_Id
));
4228 if Subprogram_Name_Greater
4229 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
4231 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
4237 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
4240 end Check_Subprogram_Order;
4242 ------------------------------
4243 -- Check_Subtype_Conformant --
4244 ------------------------------
4246 procedure Check_Subtype_Conformant
4247 (New_Id : Entity_Id;
4249 Err_Loc : Node_Id := Empty)
4254 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
4255 end Check_Subtype_Conformant;
4257 ---------------------------
4258 -- Check_Type_Conformant --
4259 ---------------------------
4261 procedure Check_Type_Conformant
4262 (New_Id : Entity_Id;
4264 Err_Loc : Node_Id := Empty)
4269 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
4270 end Check_Type_Conformant;
4272 ----------------------
4273 -- Conforming_Types --
4274 ----------------------
4276 function Conforming_Types
4279 Ctype : Conformance_Type;
4280 Get_Inst : Boolean := False) return Boolean
4282 Type_1 : Entity_Id := T1;
4283 Type_2 : Entity_Id := T2;
4284 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
4286 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
4287 -- If neither T1 nor T2 are generic actual types, or if they are
4288 -- in different scopes (e.g. parent and child instances), then verify
4289 -- that the base types are equal. Otherwise T1 and T2 must be
4290 -- on the same subtype chain. The whole purpose of this procedure
4291 -- is to prevent spurious ambiguities in an instantiation that may
4292 -- arise if two distinct generic types are instantiated with the
4295 ----------------------
4296 -- Base_Types_Match --
4297 ----------------------
4299 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
4304 elsif Base_Type (T1) = Base_Type (T2) then
4306 -- The following is too permissive. A more precise test must
4307 -- check that the generic actual is an ancestor subtype of the
4310 return not Is_Generic_Actual_Type (T1)
4311 or else not Is_Generic_Actual_Type (T2)
4312 or else Scope (T1) /= Scope (T2);
4314 -- In some cases a type imported through a limited_with clause,
4315 -- and its non-limited view are both visible, for example in an
4316 -- anonymous access_to_classwide type in a formal. Both entities
4317 -- designate the same type.
4319 elsif From_With_Type (T1)
4320 and then Ekind (T1) = E_Incomplete_Type
4321 and then T2 = Non_Limited_View (T1)
4325 elsif From_With_Type (T2)
4326 and then Ekind (T2) = E_Incomplete_Type
4327 and then T1 = Non_Limited_View (T2)
4334 end Base_Types_Match;
4336 -- Start of processing for Conforming_Types
4339 -- The context is an instance association for a formal
4340 -- access-to-subprogram type; the formal parameter types require
4341 -- mapping because they may denote other formal parameters of the
4345 Type_1 := Get_Instance_Of (T1);
4346 Type_2 := Get_Instance_Of (T2);
4349 -- First see if base types match
4351 if Base_Types_Match (Type_1, Type_2) then
4352 return Ctype <= Mode_Conformant
4353 or else Subtypes_Statically_Match (Type_1, Type_2);
4355 elsif Is_Incomplete_Or_Private_Type (Type_1)
4356 and then Present (Full_View (Type_1))
4357 and then Base_Types_Match (Full_View (Type_1), Type_2)
4359 return Ctype <= Mode_Conformant
4360 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
4362 elsif Ekind (Type_2) = E_Incomplete_Type
4363 and then Present (Full_View (Type_2))
4364 and then Base_Types_Match (Type_1, Full_View (Type_2))
4366 return Ctype <= Mode_Conformant
4367 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
4369 elsif Is_Private_Type (Type_2)
4370 and then In_Instance
4371 and then Present (Full_View (Type_2))
4372 and then Base_Types_Match (Type_1, Full_View (Type_2))
4374 return Ctype <= Mode_Conformant
4375 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
4378 -- Ada 2005 (AI-254): Anonymous access to subprogram types must be
4379 -- treated recursively because they carry a signature.
4381 Are_Anonymous_Access_To_Subprogram_Types :=
4383 -- Case 1: Anonymous access to subprogram types
4385 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
4386 and then Ekind (Type_2) = E_Anonymous_Access_Subprogram_Type)
4388 -- Case 2: Anonymous access to PROTECTED subprogram types. In this
4389 -- case the anonymous type_declaration has been replaced by an
4390 -- occurrence of an internal access to subprogram type declaration
4391 -- available through the Original_Access_Type attribute
4394 (Ekind (Type_1) = E_Access_Protected_Subprogram_Type
4395 and then Ekind (Type_2) = E_Access_Protected_Subprogram_Type
4396 and then not Comes_From_Source (Type_1)
4397 and then not Comes_From_Source (Type_2)
4398 and then Present (Original_Access_Type (Type_1))
4399 and then Present (Original_Access_Type (Type_2))
4400 and then Ekind (Original_Access_Type (Type_1)) =
4401 E_Anonymous_Access_Protected_Subprogram_Type
4402 and then Ekind (Original_Access_Type (Type_2)) =
4403 E_Anonymous_Access_Protected_Subprogram_Type);
4405 -- Test anonymous access type case. For this case, static subtype
4406 -- matching is required for mode conformance (RM 6.3.1(15))
4408 if (Ekind (Type_1) = E_Anonymous_Access_Type
4409 and then Ekind (Type_2) = E_Anonymous_Access_Type)
4410 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
4413 Desig_1 : Entity_Id;
4414 Desig_2 : Entity_Id;
4417 Desig_1 := Directly_Designated_Type (Type_1);
4419 -- An access parameter can designate an incomplete type
4420 -- If the incomplete type is the limited view of a type
4421 -- from a limited_with_clause, check whether the non-limited
4422 -- view is available.
4424 if Ekind (Desig_1) = E_Incomplete_Type then
4425 if Present (Full_View (Desig_1)) then
4426 Desig_1 := Full_View (Desig_1);
4428 elsif Present (Non_Limited_View (Desig_1)) then
4429 Desig_1 := Non_Limited_View (Desig_1);
4433 Desig_2 := Directly_Designated_Type (Type_2);
4435 if Ekind (Desig_2) = E_Incomplete_Type then
4436 if Present (Full_View (Desig_2)) then
4437 Desig_2 := Full_View (Desig_2);
4438 elsif Present (Non_Limited_View (Desig_2)) then
4439 Desig_2 := Non_Limited_View (Desig_2);
4443 -- The context is an instance association for a formal
4444 -- access-to-subprogram type; formal access parameter designated
4445 -- types require mapping because they may denote other formal
4446 -- parameters of the generic unit.
4449 Desig_1 := Get_Instance_Of (Desig_1);
4450 Desig_2 := Get_Instance_Of (Desig_2);
4453 -- It is possible for a Class_Wide_Type to be introduced for an
4454 -- incomplete type, in which case there is a separate class_ wide
4455 -- type for the full view. The types conform if their Etypes
4456 -- conform, i.e. one may be the full view of the other. This can
4457 -- only happen in the context of an access parameter, other uses
4458 -- of an incomplete Class_Wide_Type are illegal.
4460 if Is_Class_Wide_Type (Desig_1)
4461 and then Is_Class_Wide_Type (Desig_2)
4465 (Etype (Base_Type (Desig_1)),
4466 Etype (Base_Type (Desig_2)), Ctype);
4468 elsif Are_Anonymous_Access_To_Subprogram_Types then
4469 if Ada_Version < Ada_05 then
4470 return Ctype = Type_Conformant
4472 Subtypes_Statically_Match (Desig_1, Desig_2);
4474 -- We must check the conformance of the signatures themselves
4478 Conformant : Boolean;
4481 (Desig_1, Desig_2, Ctype, False, Conformant);
4487 return Base_Type (Desig_1) = Base_Type (Desig_2)
4488 and then (Ctype = Type_Conformant
4490 Subtypes_Statically_Match (Desig_1, Desig_2));
4494 -- Otherwise definitely no match
4497 if ((Ekind (Type_1) = E_Anonymous_Access_Type
4498 and then Is_Access_Type (Type_2))
4499 or else (Ekind (Type_2) = E_Anonymous_Access_Type
4500 and then Is_Access_Type (Type_1)))
4503 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
4505 May_Hide_Profile := True;
4510 end Conforming_Types;
4512 --------------------------
4513 -- Create_Extra_Formals --
4514 --------------------------
4516 procedure Create_Extra_Formals (E : Entity_Id) is
4518 First_Extra : Entity_Id := Empty;
4519 Last_Extra : Entity_Id;
4520 Formal_Type : Entity_Id;
4521 P_Formal : Entity_Id := Empty;
4523 function Add_Extra_Formal
4524 (Assoc_Entity : Entity_Id;
4527 Suffix : String) return Entity_Id;
4528 -- Add an extra formal to the current list of formals and extra formals.
4529 -- The extra formal is added to the end of the list of extra formals,
4530 -- and also returned as the result. These formals are always of mode IN.
4531 -- The new formal has the type Typ, is declared in Scope, and its name
4532 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
4534 ----------------------
4535 -- Add_Extra_Formal --
4536 ----------------------
4538 function Add_Extra_Formal
4539 (Assoc_Entity : Entity_Id;
4542 Suffix : String) return Entity_Id
4544 EF : constant Entity_Id :=
4545 Make_Defining_Identifier (Sloc (Assoc_Entity),
4546 Chars => New_External_Name (Chars (Assoc_Entity),
4550 -- We never generate extra formals if expansion is not active
4551 -- because we don't need them unless we are generating code.
4553 if not Expander_Active then
4557 -- A little optimization. Never generate an extra formal for the
4558 -- _init operand of an initialization procedure, since it could
4561 if Chars (Formal) = Name_uInit then
4565 Set_Ekind (EF, E_In_Parameter);
4566 Set_Actual_Subtype (EF, Typ);
4567 Set_Etype (EF, Typ);
4568 Set_Scope (EF, Scope);
4569 Set_Mechanism (EF, Default_Mechanism);
4570 Set_Formal_Validity (EF);
4572 if No (First_Extra) then
4574 Set_Extra_Formals (Scope, First_Extra);
4577 if Present (Last_Extra) then
4578 Set_Extra_Formal (Last_Extra, EF);
4584 end Add_Extra_Formal;
4586 -- Start of processing for Create_Extra_Formals
4589 -- If this is a derived subprogram then the subtypes of the parent
4590 -- subprogram's formal parameters will be used to to determine the need
4591 -- for extra formals.
4593 if Is_Overloadable (E) and then Present (Alias (E)) then
4594 P_Formal := First_Formal (Alias (E));
4597 Last_Extra := Empty;
4598 Formal := First_Formal (E);
4599 while Present (Formal) loop
4600 Last_Extra := Formal;
4601 Next_Formal (Formal);
4604 -- If Extra_formals where already created, don't do it again. This
4605 -- situation may arise for subprogram types created as part of
4606 -- dispatching calls (see Expand_Dispatching_Call)
4608 if Present (Last_Extra) and then
4609 Present (Extra_Formal (Last_Extra))
4614 Formal := First_Formal (E);
4616 while Present (Formal) loop
4618 -- Create extra formal for supporting the attribute 'Constrained
.
4619 -- The case of a private type view without discriminants also
4620 -- requires the extra formal if the underlying type has defaulted
4623 if Ekind
(Formal
) /= E_In_Parameter
then
4624 if Present
(P_Formal
) then
4625 Formal_Type
:= Etype
(P_Formal
);
4627 Formal_Type
:= Etype
(Formal
);
4630 -- Do not produce extra formals for Unchecked_Union parameters.
4631 -- Jump directly to the end of the loop.
4633 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
4634 goto Skip_Extra_Formal_Generation
;
4637 if not Has_Discriminants
(Formal_Type
)
4638 and then Ekind
(Formal_Type
) in Private_Kind
4639 and then Present
(Underlying_Type
(Formal_Type
))
4641 Formal_Type
:= Underlying_Type
(Formal_Type
);
4644 if Has_Discriminants
(Formal_Type
)
4646 ((not Is_Constrained
(Formal_Type
)
4647 and then not Is_Indefinite_Subtype
(Formal_Type
))
4648 or else Present
(Extra_Formal
(Formal
)))
4650 Set_Extra_Constrained
4653 (Formal
, Standard_Boolean
, Scope
(Formal
), "F"));
4657 -- Create extra formal for supporting accessibility checking
4659 -- This is suppressed if we specifically suppress accessibility
4660 -- checks at the pacage level for either the subprogram, or the
4661 -- package in which it resides. However, we do not suppress it
4662 -- simply if the scope has accessibility checks suppressed, since
4663 -- this could cause trouble when clients are compiled with a
4664 -- different suppression setting. The explicit checks at the
4665 -- package level are safe from this point of view.
4667 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
4669 (Explicit_Suppress
(E
, Accessibility_Check
)
4671 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
4674 or else Present
(Extra_Accessibility
(P_Formal
)))
4676 -- Temporary kludge: for now we avoid creating the extra formal
4677 -- for access parameters of protected operations because of
4678 -- problem with the case of internal protected calls. ???
4680 if Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Definition
4681 and then Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Body
4683 Set_Extra_Accessibility
4686 (Formal
, Standard_Natural
, Scope
(Formal
), "F"));
4690 if Present
(P_Formal
) then
4691 Next_Formal
(P_Formal
);
4694 -- This label is required when skipping extra formal generation for
4695 -- Unchecked_Union parameters.
4697 <<Skip_Extra_Formal_Generation
>>
4699 Next_Formal
(Formal
);
4702 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
4703 -- an extra formal that will be passed the address of the return object
4704 -- within the caller. This is added as the last extra formal, but
4705 -- eventually will be accompanied by other implicit formals related to
4706 -- build-in-place functions (such as allocate/deallocate subprograms,
4707 -- finalization list, constrained flag, task master, task activation
4711 and then Ada_Version
>= Ada_05
4712 and then Is_Build_In_Place_Function
(E
)
4715 Formal_Type
: constant Entity_Id
:=
4717 (E_Anonymous_Access_Type
,
4718 E
, Scope_Id
=> Scope
(E
));
4719 Result_Subt
: constant Entity_Id
:= Etype
(E
);
4720 Result_Addr_Formal
: Entity_Id
;
4723 Set_Directly_Designated_Type
(Formal_Type
, Result_Subt
);
4724 Set_Etype
(Formal_Type
, Formal_Type
);
4725 Init_Size_Align
(Formal_Type
);
4726 Set_Depends_On_Private
4727 (Formal_Type
, Has_Private_Component
(Formal_Type
));
4728 Set_Is_Public
(Formal_Type
, Is_Public
(Scope
(Formal_Type
)));
4729 Set_Is_Access_Constant
(Formal_Type
, False);
4730 Set_Can_Never_Be_Null
(Formal_Type
);
4732 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
4733 -- the designated type comes from the limited view (for back-end
4736 Set_From_With_Type
(Formal_Type
, From_With_Type
(Result_Subt
));
4738 Layout_Type
(Formal_Type
);
4740 Result_Addr_Formal
:= Add_Extra_Formal
(E
, Formal_Type
, E
, "RA");
4742 -- For some reason the following is not effective and the
4743 -- dereference of the formal within the function still gets
4746 Set_Can_Never_Be_Null
(Result_Addr_Formal
);
4749 end Create_Extra_Formals
;
4751 -----------------------------
4752 -- Enter_Overloaded_Entity --
4753 -----------------------------
4755 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
4756 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
4757 C_E
: Entity_Id
:= Current_Entity
(S
);
4761 Set_Has_Homonym
(E
);
4762 Set_Has_Homonym
(S
);
4765 Set_Is_Immediately_Visible
(S
);
4766 Set_Scope
(S
, Current_Scope
);
4768 -- Chain new entity if front of homonym in current scope, so that
4769 -- homonyms are contiguous.
4774 while Homonym
(C_E
) /= E
loop
4775 C_E
:= Homonym
(C_E
);
4778 Set_Homonym
(C_E
, S
);
4782 Set_Current_Entity
(S
);
4787 Append_Entity
(S
, Current_Scope
);
4788 Set_Public_Status
(S
);
4790 if Debug_Flag_E
then
4791 Write_Str
("New overloaded entity chain: ");
4792 Write_Name
(Chars
(S
));
4795 while Present
(E
) loop
4796 Write_Str
(" "); Write_Int
(Int
(E
));
4803 -- Generate warning for hiding
4806 and then Comes_From_Source
(S
)
4807 and then In_Extended_Main_Source_Unit
(S
)
4814 -- Warn unless genuine overloading
4816 if (not Is_Overloadable
(E
))
4817 or else Subtype_Conformant
(E
, S
)
4819 Error_Msg_Sloc
:= Sloc
(E
);
4820 Error_Msg_N
("declaration of & hides one#?", S
);
4824 end Enter_Overloaded_Entity
;
4826 -----------------------------
4827 -- Find_Corresponding_Spec --
4828 -----------------------------
4830 function Find_Corresponding_Spec
(N
: Node_Id
) return Entity_Id
is
4831 Spec
: constant Node_Id
:= Specification
(N
);
4832 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
4837 E
:= Current_Entity
(Designator
);
4839 while Present
(E
) loop
4841 -- We are looking for a matching spec. It must have the same scope,
4842 -- and the same name, and either be type conformant, or be the case
4843 -- of a library procedure spec and its body (which belong to one
4844 -- another regardless of whether they are type conformant or not).
4846 if Scope
(E
) = Current_Scope
then
4847 if Current_Scope
= Standard_Standard
4848 or else (Ekind
(E
) = Ekind
(Designator
)
4849 and then Type_Conformant
(E
, Designator
))
4851 -- Within an instantiation, we know that spec and body are
4852 -- subtype conformant, because they were subtype conformant
4853 -- in the generic. We choose the subtype-conformant entity
4854 -- here as well, to resolve spurious ambiguities in the
4855 -- instance that were not present in the generic (i.e. when
4856 -- two different types are given the same actual). If we are
4857 -- looking for a spec to match a body, full conformance is
4861 Set_Convention
(Designator
, Convention
(E
));
4863 if Nkind
(N
) = N_Subprogram_Body
4864 and then Present
(Homonym
(E
))
4865 and then not Fully_Conformant
(E
, Designator
)
4869 elsif not Subtype_Conformant
(E
, Designator
) then
4874 if not Has_Completion
(E
) then
4876 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
4877 Set_Corresponding_Spec
(N
, E
);
4880 Set_Has_Completion
(E
);
4883 elsif Nkind
(Parent
(N
)) = N_Subunit
then
4885 -- If this is the proper body of a subunit, the completion
4886 -- flag is set when analyzing the stub.
4890 -- If body already exists, this is an error unless the
4891 -- previous declaration is the implicit declaration of
4892 -- a derived subprogram, or this is a spurious overloading
4895 elsif No
(Alias
(E
))
4896 and then not Is_Intrinsic_Subprogram
(E
)
4897 and then not In_Instance
4899 Error_Msg_Sloc
:= Sloc
(E
);
4900 if Is_Imported
(E
) then
4902 ("body not allowed for imported subprogram & declared#",
4905 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
4909 elsif Is_Child_Unit
(E
)
4911 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
4913 Nkind
(Parent
(Unit_Declaration_Node
(Designator
)))
4914 = N_Compilation_Unit
4917 -- Child units cannot be overloaded, so a conformance mismatch
4918 -- between body and a previous spec is an error.
4921 ("body of child unit does not match previous declaration", N
);
4929 -- On exit, we know that no previous declaration of subprogram exists
4932 end Find_Corresponding_Spec
;
4934 ----------------------
4935 -- Fully_Conformant --
4936 ----------------------
4938 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4941 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
4943 end Fully_Conformant
;
4945 ----------------------------------
4946 -- Fully_Conformant_Expressions --
4947 ----------------------------------
4949 function Fully_Conformant_Expressions
4950 (Given_E1
: Node_Id
;
4951 Given_E2
: Node_Id
) return Boolean
4953 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
4954 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
4955 -- We always test conformance on original nodes, since it is possible
4956 -- for analysis and/or expansion to make things look as though they
4957 -- conform when they do not, e.g. by converting 1+2 into 3.
4959 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
4960 renames Fully_Conformant_Expressions
;
4962 function FCL
(L1
, L2
: List_Id
) return Boolean;
4963 -- Compare elements of two lists for conformance. Elements have to
4964 -- be conformant, and actuals inserted as default parameters do not
4965 -- match explicit actuals with the same value.
4967 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
4968 -- Compare an operator node with a function call
4974 function FCL
(L1
, L2
: List_Id
) return Boolean is
4978 if L1
= No_List
then
4984 if L2
= No_List
then
4990 -- Compare two lists, skipping rewrite insertions (we want to
4991 -- compare the original trees, not the expanded versions!)
4994 if Is_Rewrite_Insertion
(N1
) then
4996 elsif Is_Rewrite_Insertion
(N2
) then
5002 elsif not FCE
(N1
, N2
) then
5015 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
5016 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
5021 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
5026 Act
:= First
(Actuals
);
5028 if Nkind
(Op_Node
) in N_Binary_Op
then
5030 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
5037 return Present
(Act
)
5038 and then FCE
(Right_Opnd
(Op_Node
), Act
)
5039 and then No
(Next
(Act
));
5043 -- Start of processing for Fully_Conformant_Expressions
5046 -- Non-conformant if paren count does not match. Note: if some idiot
5047 -- complains that we don't do this right for more than 3 levels of
5048 -- parentheses, they will be treated with the respect they deserve :-)
5050 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
5053 -- If same entities are referenced, then they are conformant even if
5054 -- they have different forms (RM 8.3.1(19-20)).
5056 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
5057 if Present
(Entity
(E1
)) then
5058 return Entity
(E1
) = Entity
(E2
)
5059 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
5060 and then Ekind
(Entity
(E1
)) = E_Discriminant
5061 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
5063 elsif Nkind
(E1
) = N_Expanded_Name
5064 and then Nkind
(E2
) = N_Expanded_Name
5065 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
5066 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
5068 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
5071 -- Identifiers in component associations don't always have
5072 -- entities, but their names must conform.
5074 return Nkind
(E1
) = N_Identifier
5075 and then Nkind
(E2
) = N_Identifier
5076 and then Chars
(E1
) = Chars
(E2
);
5079 elsif Nkind
(E1
) = N_Character_Literal
5080 and then Nkind
(E2
) = N_Expanded_Name
5082 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
5083 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
5085 elsif Nkind
(E2
) = N_Character_Literal
5086 and then Nkind
(E1
) = N_Expanded_Name
5088 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
5089 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
5091 elsif Nkind
(E1
) in N_Op
5092 and then Nkind
(E2
) = N_Function_Call
5094 return FCO
(E1
, E2
);
5096 elsif Nkind
(E2
) in N_Op
5097 and then Nkind
(E1
) = N_Function_Call
5099 return FCO
(E2
, E1
);
5101 -- Otherwise we must have the same syntactic entity
5103 elsif Nkind
(E1
) /= Nkind
(E2
) then
5106 -- At this point, we specialize by node type
5113 FCL
(Expressions
(E1
), Expressions
(E2
))
5114 and then FCL
(Component_Associations
(E1
),
5115 Component_Associations
(E2
));
5118 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
5120 Nkind
(Expression
(E2
)) = N_Qualified_Expression
5122 return FCE
(Expression
(E1
), Expression
(E2
));
5124 -- Check that the subtype marks and any constraints
5129 Indic1
: constant Node_Id
:= Expression
(E1
);
5130 Indic2
: constant Node_Id
:= Expression
(E2
);
5135 if Nkind
(Indic1
) /= N_Subtype_Indication
then
5137 Nkind
(Indic2
) /= N_Subtype_Indication
5138 and then Entity
(Indic1
) = Entity
(Indic2
);
5140 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
5142 Nkind
(Indic1
) /= N_Subtype_Indication
5143 and then Entity
(Indic1
) = Entity
(Indic2
);
5146 if Entity
(Subtype_Mark
(Indic1
)) /=
5147 Entity
(Subtype_Mark
(Indic2
))
5152 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
5153 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
5155 while Present
(Elt1
) and then Present
(Elt2
) loop
5156 if not FCE
(Elt1
, Elt2
) then
5169 when N_Attribute_Reference
=>
5171 Attribute_Name
(E1
) = Attribute_Name
(E2
)
5172 and then FCL
(Expressions
(E1
), Expressions
(E2
));
5176 Entity
(E1
) = Entity
(E2
)
5177 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
5178 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
5180 when N_And_Then | N_Or_Else | N_Membership_Test
=>
5182 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
5184 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
5186 when N_Character_Literal
=>
5188 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
5190 when N_Component_Association
=>
5192 FCL
(Choices
(E1
), Choices
(E2
))
5193 and then FCE
(Expression
(E1
), Expression
(E2
));
5195 when N_Conditional_Expression
=>
5197 FCL
(Expressions
(E1
), Expressions
(E2
));
5199 when N_Explicit_Dereference
=>
5201 FCE
(Prefix
(E1
), Prefix
(E2
));
5203 when N_Extension_Aggregate
=>
5205 FCL
(Expressions
(E1
), Expressions
(E2
))
5206 and then Null_Record_Present
(E1
) =
5207 Null_Record_Present
(E2
)
5208 and then FCL
(Component_Associations
(E1
),
5209 Component_Associations
(E2
));
5211 when N_Function_Call
=>
5213 FCE
(Name
(E1
), Name
(E2
))
5214 and then FCL
(Parameter_Associations
(E1
),
5215 Parameter_Associations
(E2
));
5217 when N_Indexed_Component
=>
5219 FCE
(Prefix
(E1
), Prefix
(E2
))
5220 and then FCL
(Expressions
(E1
), Expressions
(E2
));
5222 when N_Integer_Literal
=>
5223 return (Intval
(E1
) = Intval
(E2
));
5228 when N_Operator_Symbol
=>
5230 Chars
(E1
) = Chars
(E2
);
5232 when N_Others_Choice
=>
5235 when N_Parameter_Association
=>
5237 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
5238 and then FCE
(Explicit_Actual_Parameter
(E1
),
5239 Explicit_Actual_Parameter
(E2
));
5241 when N_Qualified_Expression
=>
5243 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
5244 and then FCE
(Expression
(E1
), Expression
(E2
));
5248 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
5249 and then FCE
(High_Bound
(E1
), High_Bound
(E2
));
5251 when N_Real_Literal
=>
5252 return (Realval
(E1
) = Realval
(E2
));
5254 when N_Selected_Component
=>
5256 FCE
(Prefix
(E1
), Prefix
(E2
))
5257 and then FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
5261 FCE
(Prefix
(E1
), Prefix
(E2
))
5262 and then FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
5264 when N_String_Literal
=>
5266 S1
: constant String_Id
:= Strval
(E1
);
5267 S2
: constant String_Id
:= Strval
(E2
);
5268 L1
: constant Nat
:= String_Length
(S1
);
5269 L2
: constant Nat
:= String_Length
(S2
);
5276 for J
in 1 .. L1
loop
5277 if Get_String_Char
(S1
, J
) /=
5278 Get_String_Char
(S2
, J
)
5288 when N_Type_Conversion
=>
5290 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
5291 and then FCE
(Expression
(E1
), Expression
(E2
));
5295 Entity
(E1
) = Entity
(E2
)
5296 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
5298 when N_Unchecked_Type_Conversion
=>
5300 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
5301 and then FCE
(Expression
(E1
), Expression
(E2
));
5303 -- All other node types cannot appear in this context. Strictly
5304 -- we should raise a fatal internal error. Instead we just ignore
5305 -- the nodes. This means that if anyone makes a mistake in the
5306 -- expander and mucks an expression tree irretrievably, the
5307 -- result will be a failure to detect a (probably very obscure)
5308 -- case of non-conformance, which is better than bombing on some
5309 -- case where two expressions do in fact conform.
5316 end Fully_Conformant_Expressions
;
5318 ----------------------------------------
5319 -- Fully_Conformant_Discrete_Subtypes --
5320 ----------------------------------------
5322 function Fully_Conformant_Discrete_Subtypes
5323 (Given_S1
: Node_Id
;
5324 Given_S2
: Node_Id
) return Boolean
5326 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
5327 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
5329 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
5330 -- Special-case for a bound given by a discriminant, which in the body
5331 -- is replaced with the discriminal of the enclosing type.
5333 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
5334 -- Check both bounds
5336 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
5338 if Is_Entity_Name
(B1
)
5339 and then Is_Entity_Name
(B2
)
5340 and then Ekind
(Entity
(B1
)) = E_Discriminant
5342 return Chars
(B1
) = Chars
(B2
);
5345 return Fully_Conformant_Expressions
(B1
, B2
);
5347 end Conforming_Bounds
;
5349 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
5352 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
5354 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
5355 end Conforming_Ranges
;
5357 -- Start of processing for Fully_Conformant_Discrete_Subtypes
5360 if Nkind
(S1
) /= Nkind
(S2
) then
5363 elsif Is_Entity_Name
(S1
) then
5364 return Entity
(S1
) = Entity
(S2
);
5366 elsif Nkind
(S1
) = N_Range
then
5367 return Conforming_Ranges
(S1
, S2
);
5369 elsif Nkind
(S1
) = N_Subtype_Indication
then
5371 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
5374 (Range_Expression
(Constraint
(S1
)),
5375 Range_Expression
(Constraint
(S2
)));
5379 end Fully_Conformant_Discrete_Subtypes
;
5381 --------------------
5382 -- Install_Entity --
5383 --------------------
5385 procedure Install_Entity
(E
: Entity_Id
) is
5386 Prev
: constant Entity_Id
:= Current_Entity
(E
);
5388 Set_Is_Immediately_Visible
(E
);
5389 Set_Current_Entity
(E
);
5390 Set_Homonym
(E
, Prev
);
5393 ---------------------
5394 -- Install_Formals --
5395 ---------------------
5397 procedure Install_Formals
(Id
: Entity_Id
) is
5400 F
:= First_Formal
(Id
);
5401 while Present
(F
) loop
5405 end Install_Formals
;
5407 ---------------------------------
5408 -- Is_Non_Overriding_Operation --
5409 ---------------------------------
5411 function Is_Non_Overriding_Operation
5412 (Prev_E
: Entity_Id
;
5413 New_E
: Entity_Id
) return Boolean
5417 G_Typ
: Entity_Id
:= Empty
;
5419 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
5420 -- If F_Type is a derived type associated with a generic actual
5421 -- subtype, then return its Generic_Parent_Type attribute, else return
5424 function Types_Correspond
5425 (P_Type
: Entity_Id
;
5426 N_Type
: Entity_Id
) return Boolean;
5427 -- Returns true if and only if the types (or designated types in the
5428 -- case of anonymous access types) are the same or N_Type is derived
5429 -- directly or indirectly from P_Type.
5431 -----------------------------
5432 -- Get_Generic_Parent_Type --
5433 -----------------------------
5435 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
5440 if Is_Derived_Type
(F_Typ
)
5441 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
5443 -- The tree must be traversed to determine the parent subtype in
5444 -- the generic unit, which unfortunately isn't always available
5445 -- via semantic attributes. ??? (Note: The use of Original_Node
5446 -- is needed for cases where a full derived type has been
5449 Indic
:= Subtype_Indication
5450 (Type_Definition
(Original_Node
(Parent
(F_Typ
))));
5452 if Nkind
(Indic
) = N_Subtype_Indication
then
5453 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
5455 G_Typ
:= Entity
(Indic
);
5458 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
5459 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
5461 return Generic_Parent_Type
(Parent
(G_Typ
));
5466 end Get_Generic_Parent_Type
;
5468 ----------------------
5469 -- Types_Correspond --
5470 ----------------------
5472 function Types_Correspond
5473 (P_Type
: Entity_Id
;
5474 N_Type
: Entity_Id
) return Boolean
5476 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
5477 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
5480 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
5481 Prev_Type
:= Designated_Type
(Prev_Type
);
5484 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
5485 New_Type
:= Designated_Type
(New_Type
);
5488 if Prev_Type
= New_Type
then
5491 elsif not Is_Class_Wide_Type
(New_Type
) then
5492 while Etype
(New_Type
) /= New_Type
loop
5493 New_Type
:= Etype
(New_Type
);
5494 if New_Type
= Prev_Type
then
5500 end Types_Correspond
;
5502 -- Start of processing for Is_Non_Overriding_Operation
5505 -- In the case where both operations are implicit derived subprograms
5506 -- then neither overrides the other. This can only occur in certain
5507 -- obscure cases (e.g., derivation from homographs created in a generic
5510 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
5513 elsif Ekind
(Current_Scope
) = E_Package
5514 and then Is_Generic_Instance
(Current_Scope
)
5515 and then In_Private_Part
(Current_Scope
)
5516 and then Comes_From_Source
(New_E
)
5518 -- We examine the formals and result subtype of the inherited
5519 -- operation, to determine whether their type is derived from (the
5520 -- instance of) a generic type.
5522 Formal
:= First_Formal
(Prev_E
);
5524 while Present
(Formal
) loop
5525 F_Typ
:= Base_Type
(Etype
(Formal
));
5527 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
5528 F_Typ
:= Designated_Type
(F_Typ
);
5531 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
5533 Next_Formal
(Formal
);
5536 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
5537 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
5544 -- If the generic type is a private type, then the original
5545 -- operation was not overriding in the generic, because there was
5546 -- no primitive operation to override.
5548 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
5549 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
5550 N_Formal_Private_Type_Definition
5554 -- The generic parent type is the ancestor of a formal derived
5555 -- type declaration. We need to check whether it has a primitive
5556 -- operation that should be overridden by New_E in the generic.
5560 P_Formal
: Entity_Id
;
5561 N_Formal
: Entity_Id
;
5565 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
5568 while Present
(Prim_Elt
) loop
5569 P_Prim
:= Node
(Prim_Elt
);
5571 if Chars
(P_Prim
) = Chars
(New_E
)
5572 and then Ekind
(P_Prim
) = Ekind
(New_E
)
5574 P_Formal
:= First_Formal
(P_Prim
);
5575 N_Formal
:= First_Formal
(New_E
);
5576 while Present
(P_Formal
) and then Present
(N_Formal
) loop
5577 P_Typ
:= Etype
(P_Formal
);
5578 N_Typ
:= Etype
(N_Formal
);
5580 if not Types_Correspond
(P_Typ
, N_Typ
) then
5584 Next_Entity
(P_Formal
);
5585 Next_Entity
(N_Formal
);
5588 -- Found a matching primitive operation belonging to the
5589 -- formal ancestor type, so the new subprogram is
5593 and then No
(N_Formal
)
5594 and then (Ekind
(New_E
) /= E_Function
5597 (Etype
(P_Prim
), Etype
(New_E
)))
5603 Next_Elmt
(Prim_Elt
);
5606 -- If no match found, then the new subprogram does not
5607 -- override in the generic (nor in the instance).
5615 end Is_Non_Overriding_Operation
;
5617 ------------------------------
5618 -- Make_Inequality_Operator --
5619 ------------------------------
5621 -- S is the defining identifier of an equality operator. We build a
5622 -- subprogram declaration with the right signature. This operation is
5623 -- intrinsic, because it is always expanded as the negation of the
5624 -- call to the equality function.
5626 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
5627 Loc
: constant Source_Ptr
:= Sloc
(S
);
5630 Op_Name
: Entity_Id
;
5632 FF
: constant Entity_Id
:= First_Formal
(S
);
5633 NF
: constant Entity_Id
:= Next_Formal
(FF
);
5636 -- Check that equality was properly defined, ignore call if not
5643 A
: constant Entity_Id
:=
5644 Make_Defining_Identifier
(Sloc
(FF
),
5645 Chars
=> Chars
(FF
));
5647 B
: constant Entity_Id
:=
5648 Make_Defining_Identifier
(Sloc
(NF
),
5649 Chars
=> Chars
(NF
));
5652 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
5654 Formals
:= New_List
(
5655 Make_Parameter_Specification
(Loc
,
5656 Defining_Identifier
=> A
,
5658 New_Reference_To
(Etype
(First_Formal
(S
)),
5659 Sloc
(Etype
(First_Formal
(S
))))),
5661 Make_Parameter_Specification
(Loc
,
5662 Defining_Identifier
=> B
,
5664 New_Reference_To
(Etype
(Next_Formal
(First_Formal
(S
))),
5665 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
5668 Make_Subprogram_Declaration
(Loc
,
5670 Make_Function_Specification
(Loc
,
5671 Defining_Unit_Name
=> Op_Name
,
5672 Parameter_Specifications
=> Formals
,
5673 Result_Definition
=>
5674 New_Reference_To
(Standard_Boolean
, Loc
)));
5676 -- Insert inequality right after equality if it is explicit or after
5677 -- the derived type when implicit. These entities are created only
5678 -- for visibility purposes, and eventually replaced in the course of
5679 -- expansion, so they do not need to be attached to the tree and seen
5680 -- by the back-end. Keeping them internal also avoids spurious
5681 -- freezing problems. The declaration is inserted in the tree for
5682 -- analysis, and removed afterwards. If the equality operator comes
5683 -- from an explicit declaration, attach the inequality immediately
5684 -- after. Else the equality is inherited from a derived type
5685 -- declaration, so insert inequality after that declaration.
5687 if No
(Alias
(S
)) then
5688 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
5689 elsif Is_List_Member
(Parent
(S
)) then
5690 Insert_After
(Parent
(S
), Decl
);
5692 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
5695 Mark_Rewrite_Insertion
(Decl
);
5696 Set_Is_Intrinsic_Subprogram
(Op_Name
);
5699 Set_Has_Completion
(Op_Name
);
5700 Set_Corresponding_Equality
(Op_Name
, S
);
5701 Set_Is_Abstract
(Op_Name
, Is_Abstract
(S
));
5703 end Make_Inequality_Operator
;
5705 ----------------------
5706 -- May_Need_Actuals --
5707 ----------------------
5709 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
5714 F
:= First_Formal
(Fun
);
5717 while Present
(F
) loop
5718 if No
(Default_Value
(F
)) then
5726 Set_Needs_No_Actuals
(Fun
, B
);
5727 end May_Need_Actuals
;
5729 ---------------------
5730 -- Mode_Conformant --
5731 ---------------------
5733 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
5736 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
5738 end Mode_Conformant
;
5740 ---------------------------
5741 -- New_Overloaded_Entity --
5742 ---------------------------
5744 procedure New_Overloaded_Entity
5746 Derived_Type
: Entity_Id
:= Empty
)
5748 Overridden_Subp
: Entity_Id
:= Empty
;
5749 -- Set if the current scope has an operation that is type-conformant
5750 -- with S, and becomes hidden by S.
5753 -- Entity that S overrides
5755 Prev_Vis
: Entity_Id
:= Empty
;
5756 -- Predecessor of E in Homonym chain
5758 procedure Check_Synchronized_Overriding
5759 (Def_Id
: Entity_Id
;
5760 First_Hom
: Entity_Id
;
5761 Overridden_Subp
: out Entity_Id
);
5762 -- First determine if Def_Id is an entry or a subprogram either defined
5763 -- in the scope of a task or protected type, or is a primitive of such
5764 -- a type. Check whether Def_Id overrides a subprogram of an interface
5765 -- implemented by the synchronized type, return the overridden entity
5768 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
5769 -- Check that E is declared in the private part of the current package,
5770 -- or in the package body, where it may hide a previous declaration.
5771 -- We can't use In_Private_Part by itself because this flag is also
5772 -- set when freezing entities, so we must examine the place of the
5773 -- declaration in the tree, and recognize wrapper packages as well.
5775 procedure Maybe_Primitive_Operation
(Is_Overriding
: Boolean := False);
5776 -- If the subprogram being analyzed is a primitive operation of
5777 -- the type of one of its formals, set the corresponding flag.
5779 -----------------------------------
5780 -- Check_Synchronized_Overriding --
5781 -----------------------------------
5783 procedure Check_Synchronized_Overriding
5784 (Def_Id
: Entity_Id
;
5785 First_Hom
: Entity_Id
;
5786 Overridden_Subp
: out Entity_Id
)
5788 Ifaces_List
: Elist_Id
;
5793 Overridden_Subp
:= Empty
;
5795 -- Def_Id must be an entry or a subprogram
5797 if Ekind
(Def_Id
) /= E_Entry
5798 and then Ekind
(Def_Id
) /= E_Function
5799 and then Ekind
(Def_Id
) /= E_Procedure
5804 -- Def_Id must be declared withing the scope of a protected or
5805 -- task type or be a primitive operation of such a type.
5807 if Present
(Scope
(Def_Id
))
5808 and then Is_Concurrent_Type
(Scope
(Def_Id
))
5809 and then not Is_Generic_Actual_Type
(Scope
(Def_Id
))
5811 Typ
:= Scope
(Def_Id
);
5814 elsif Present
(First_Formal
(Def_Id
))
5815 and then Is_Concurrent_Type
(Etype
(First_Formal
(Def_Id
)))
5816 and then not Is_Generic_Actual_Type
(Etype
(First_Formal
(Def_Id
)))
5818 Typ
:= Etype
(First_Formal
(Def_Id
));
5825 -- Gather all limited, protected and task interfaces that Typ
5826 -- implements. Do not collect the interfaces in case of full type
5827 -- declarations because they don't have interface lists.
5829 if Nkind
(Parent
(Typ
)) /= N_Full_Type_Declaration
then
5830 Collect_Synchronized_Interfaces
(Typ
, Ifaces_List
);
5832 if not Is_Empty_Elmt_List
(Ifaces_List
) then
5834 Overrides_Synchronized_Primitive
5835 (Def_Id
, First_Hom
, Ifaces_List
, In_Scope
);
5838 end Check_Synchronized_Overriding
;
5840 ----------------------------
5841 -- Is_Private_Declaration --
5842 ----------------------------
5844 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
5845 Priv_Decls
: List_Id
;
5846 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
5849 if Is_Package_Or_Generic_Package
(Current_Scope
)
5850 and then In_Private_Part
(Current_Scope
)
5853 Private_Declarations
(
5854 Specification
(Unit_Declaration_Node
(Current_Scope
)));
5856 return In_Package_Body
(Current_Scope
)
5858 (Is_List_Member
(Decl
)
5859 and then List_Containing
(Decl
) = Priv_Decls
)
5860 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
5861 and then not Is_Compilation_Unit
(
5862 Defining_Entity
(Parent
(Decl
)))
5863 and then List_Containing
(Parent
(Parent
(Decl
)))
5868 end Is_Private_Declaration
;
5870 -------------------------------
5871 -- Maybe_Primitive_Operation --
5872 -------------------------------
5874 procedure Maybe_Primitive_Operation
(Is_Overriding
: Boolean := False) is
5879 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
5880 -- Returns true if T is declared in the visible part of
5881 -- the current package scope; otherwise returns false.
5882 -- Assumes that T is declared in a package.
5884 procedure Check_Private_Overriding
(T
: Entity_Id
);
5885 -- Checks that if a primitive abstract subprogram of a visible
5886 -- abstract type is declared in a private part, then it must
5887 -- override an abstract subprogram declared in the visible part.
5888 -- Also checks that if a primitive function with a controlling
5889 -- result is declared in a private part, then it must override
5890 -- a function declared in the visible part.
5892 ------------------------------
5893 -- Check_Private_Overriding --
5894 ------------------------------
5896 procedure Check_Private_Overriding
(T
: Entity_Id
) is
5898 if Ekind
(Current_Scope
) = E_Package
5899 and then In_Private_Part
(Current_Scope
)
5900 and then Visible_Part_Type
(T
)
5901 and then not In_Instance
5904 and then Is_Abstract
(S
)
5905 and then (not Is_Overriding
or else not Is_Abstract
(E
))
5907 if not Is_Interface
(T
) then
5908 Error_Msg_N
("abstract subprograms must be visible "
5909 & "('R'M 3.9.3(10))!", S
);
5911 -- Ada 2005 (AI-251)
5914 Error_Msg_N
("primitive subprograms of interface types "
5915 & "declared in a visible part, must be declared in "
5916 & "the visible part ('R'M 3.9.4)!", S
);
5919 elsif Ekind
(S
) = E_Function
5920 and then Is_Tagged_Type
(T
)
5921 and then T
= Base_Type
(Etype
(S
))
5922 and then not Is_Overriding
5925 ("private function with tagged result must"
5926 & " override visible-part function", S
);
5928 ("\move subprogram to the visible part"
5929 & " ('R'M 3.9.3(10))", S
);
5932 end Check_Private_Overriding
;
5934 -----------------------
5935 -- Visible_Part_Type --
5936 -----------------------
5938 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
5939 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
5943 -- If the entity is a private type, then it must be
5944 -- declared in a visible part.
5946 if Ekind
(T
) in Private_Kind
then
5950 -- Otherwise, we traverse the visible part looking for its
5951 -- corresponding declaration. We cannot use the declaration
5952 -- node directly because in the private part the entity of a
5953 -- private type is the one in the full view, which does not
5954 -- indicate that it is the completion of something visible.
5956 N
:= First
(Visible_Declarations
(Specification
(P
)));
5957 while Present
(N
) loop
5958 if Nkind
(N
) = N_Full_Type_Declaration
5959 and then Present
(Defining_Identifier
(N
))
5960 and then T
= Defining_Identifier
(N
)
5964 elsif (Nkind
(N
) = N_Private_Type_Declaration
5966 Nkind
(N
) = N_Private_Extension_Declaration
)
5967 and then Present
(Defining_Identifier
(N
))
5968 and then T
= Full_View
(Defining_Identifier
(N
))
5977 end Visible_Part_Type
;
5979 -- Start of processing for Maybe_Primitive_Operation
5982 if not Comes_From_Source
(S
) then
5985 -- If the subprogram is at library level, it is not primitive
5988 elsif Current_Scope
= Standard_Standard
then
5991 elsif (Ekind
(Current_Scope
) = E_Package
5992 and then not In_Package_Body
(Current_Scope
))
5993 or else Is_Overriding
5995 -- For function, check return type
5997 if Ekind
(S
) = E_Function
then
5998 B_Typ
:= Base_Type
(Etype
(S
));
6000 if Scope
(B_Typ
) = Current_Scope
then
6001 Set_Has_Primitive_Operations
(B_Typ
);
6002 Check_Private_Overriding
(B_Typ
);
6006 -- For all subprograms, check formals
6008 Formal
:= First_Formal
(S
);
6009 while Present
(Formal
) loop
6010 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
6011 F_Typ
:= Designated_Type
(Etype
(Formal
));
6013 F_Typ
:= Etype
(Formal
);
6016 B_Typ
:= Base_Type
(F_Typ
);
6018 if Ekind
(B_Typ
) = E_Access_Subtype
then
6019 B_Typ
:= Base_Type
(B_Typ
);
6022 if Scope
(B_Typ
) = Current_Scope
then
6023 Set_Has_Primitive_Operations
(B_Typ
);
6024 Check_Private_Overriding
(B_Typ
);
6027 Next_Formal
(Formal
);
6030 end Maybe_Primitive_Operation
;
6032 -- Start of processing for New_Overloaded_Entity
6035 -- We need to look for an entity that S may override. This must be a
6036 -- homonym in the current scope, so we look for the first homonym of
6037 -- S in the current scope as the starting point for the search.
6039 E
:= Current_Entity_In_Scope
(S
);
6041 -- If there is no homonym then this is definitely not overriding
6044 Enter_Overloaded_Entity
(S
);
6045 Check_Dispatching_Operation
(S
, Empty
);
6046 Maybe_Primitive_Operation
;
6048 -- If subprogram has an explicit declaration, check whether it
6049 -- has an overriding indicator.
6051 if Comes_From_Source
(S
) then
6052 Check_Synchronized_Overriding
(S
, Homonym
(S
), Overridden_Subp
);
6053 Check_Overriding_Indicator
(S
, Overridden_Subp
);
6056 -- If there is a homonym that is not overloadable, then we have an
6057 -- error, except for the special cases checked explicitly below.
6059 elsif not Is_Overloadable
(E
) then
6061 -- Check for spurious conflict produced by a subprogram that has the
6062 -- same name as that of the enclosing generic package. The conflict
6063 -- occurs within an instance, between the subprogram and the renaming
6064 -- declaration for the package. After the subprogram, the package
6065 -- renaming declaration becomes hidden.
6067 if Ekind
(E
) = E_Package
6068 and then Present
(Renamed_Object
(E
))
6069 and then Renamed_Object
(E
) = Current_Scope
6070 and then Nkind
(Parent
(Renamed_Object
(E
))) =
6071 N_Package_Specification
6072 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
6075 Set_Is_Immediately_Visible
(E
, False);
6076 Enter_Overloaded_Entity
(S
);
6077 Set_Homonym
(S
, Homonym
(E
));
6078 Check_Dispatching_Operation
(S
, Empty
);
6079 Check_Overriding_Indicator
(S
, Empty
);
6081 -- If the subprogram is implicit it is hidden by the previous
6082 -- declaration. However if it is dispatching, it must appear in the
6083 -- dispatch table anyway, because it can be dispatched to even if it
6084 -- cannot be called directly.
6086 elsif Present
(Alias
(S
))
6087 and then not Comes_From_Source
(S
)
6089 Set_Scope
(S
, Current_Scope
);
6091 if Is_Dispatching_Operation
(Alias
(S
)) then
6092 Check_Dispatching_Operation
(S
, Empty
);
6098 Error_Msg_Sloc
:= Sloc
(E
);
6099 Error_Msg_N
("& conflicts with declaration#", S
);
6101 -- Useful additional warning
6103 if Is_Generic_Unit
(E
) then
6104 Error_Msg_N
("\previous generic unit cannot be overloaded", S
);
6110 -- E exists and is overloadable
6113 -- Ada 2005 (AI-251): Derivation of abstract interface primitives
6114 -- need no check against the homonym chain. They are directly added
6115 -- to the list of primitive operations of Derived_Type.
6117 if Ada_Version
>= Ada_05
6118 and then Present
(Derived_Type
)
6119 and then Is_Dispatching_Operation
(Alias
(S
))
6120 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
6121 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
6122 and then not Is_Predefined_Dispatching_Operation
(Alias
(S
))
6124 goto Add_New_Entity
;
6127 Check_Synchronized_Overriding
(S
, E
, Overridden_Subp
);
6129 -- Loop through E and its homonyms to determine if any of them is
6130 -- the candidate for overriding by S.
6132 while Present
(E
) loop
6134 -- Definitely not interesting if not in the current scope
6136 if Scope
(E
) /= Current_Scope
then
6139 -- Check if we have type conformance
6141 elsif Type_Conformant
(E
, S
) then
6143 -- If the old and new entities have the same profile and one
6144 -- is not the body of the other, then this is an error, unless
6145 -- one of them is implicitly declared.
6147 -- There are some cases when both can be implicit, for example
6148 -- when both a literal and a function that overrides it are
6149 -- inherited in a derivation, or when an inhertited operation
6150 -- of a tagged full type overrides the inherited operation of
6151 -- a private extension. Ada 83 had a special rule for the the
6152 -- literal case. In Ada95, the later implicit operation hides
6153 -- the former, and the literal is always the former. In the
6154 -- odd case where both are derived operations declared at the
6155 -- same point, both operations should be declared, and in that
6156 -- case we bypass the following test and proceed to the next
6157 -- part (this can only occur for certain obscure cases
6158 -- involving homographs in instances and can't occur for
6159 -- dispatching operations ???). Note that the following
6160 -- condition is less than clear. For example, it's not at all
6161 -- clear why there's a test for E_Entry here. ???
6163 if Present
(Alias
(S
))
6164 and then (No
(Alias
(E
))
6165 or else Comes_From_Source
(E
)
6166 or else Is_Dispatching_Operation
(E
))
6168 (Ekind
(E
) = E_Entry
6169 or else Ekind
(E
) /= E_Enumeration_Literal
)
6171 -- When an derived operation is overloaded it may be due to
6172 -- the fact that the full view of a private extension
6173 -- re-inherits. It has to be dealt with.
6175 if Is_Package_Or_Generic_Package
(Current_Scope
)
6176 and then In_Private_Part
(Current_Scope
)
6178 Check_Operation_From_Private_View
(S
, E
);
6181 -- In any case the implicit operation remains hidden by
6182 -- the existing declaration, which is overriding.
6184 Set_Is_Overriding_Operation
(E
);
6186 if Comes_From_Source
(E
) then
6187 Check_Overriding_Indicator
(E
, S
);
6189 -- Indicate that E overrides the operation from which
6192 if Present
(Alias
(S
)) then
6193 Set_Overridden_Operation
(E
, Alias
(S
));
6195 Set_Overridden_Operation
(E
, S
);
6201 -- Within an instance, the renaming declarations for
6202 -- actual subprograms may become ambiguous, but they do
6203 -- not hide each other.
6205 elsif Ekind
(E
) /= E_Entry
6206 and then not Comes_From_Source
(E
)
6207 and then not Is_Generic_Instance
(E
)
6208 and then (Present
(Alias
(E
))
6209 or else Is_Intrinsic_Subprogram
(E
))
6210 and then (not In_Instance
6211 or else No
(Parent
(E
))
6212 or else Nkind
(Unit_Declaration_Node
(E
)) /=
6213 N_Subprogram_Renaming_Declaration
)
6215 -- A subprogram child unit is not allowed to override
6216 -- an inherited subprogram (10.1.1(20)).
6218 if Is_Child_Unit
(S
) then
6220 ("child unit overrides inherited subprogram in parent",
6225 if Is_Non_Overriding_Operation
(E
, S
) then
6226 Enter_Overloaded_Entity
(S
);
6227 if No
(Derived_Type
)
6228 or else Is_Tagged_Type
(Derived_Type
)
6230 Check_Dispatching_Operation
(S
, Empty
);
6236 -- E is a derived operation or an internal operator which
6237 -- is being overridden. Remove E from further visibility.
6238 -- Furthermore, if E is a dispatching operation, it must be
6239 -- replaced in the list of primitive operations of its type
6240 -- (see Override_Dispatching_Operation).
6242 Overridden_Subp
:= E
;
6248 Prev
:= First_Entity
(Current_Scope
);
6250 while Present
(Prev
)
6251 and then Next_Entity
(Prev
) /= E
6256 -- It is possible for E to be in the current scope and
6257 -- yet not in the entity chain. This can only occur in a
6258 -- generic context where E is an implicit concatenation
6259 -- in the formal part, because in a generic body the
6260 -- entity chain starts with the formals.
6263 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
6265 -- E must be removed both from the entity_list of the
6266 -- current scope, and from the visibility chain
6268 if Debug_Flag_E
then
6269 Write_Str
("Override implicit operation ");
6270 Write_Int
(Int
(E
));
6274 -- If E is a predefined concatenation, it stands for four
6275 -- different operations. As a result, a single explicit
6276 -- declaration does not hide it. In a possible ambiguous
6277 -- situation, Disambiguate chooses the user-defined op,
6278 -- so it is correct to retain the previous internal one.
6280 if Chars
(E
) /= Name_Op_Concat
6281 or else Ekind
(E
) /= E_Operator
6283 -- For nondispatching derived operations that are
6284 -- overridden by a subprogram declared in the private
6285 -- part of a package, we retain the derived
6286 -- subprogram but mark it as not immediately visible.
6287 -- If the derived operation was declared in the
6288 -- visible part then this ensures that it will still
6289 -- be visible outside the package with the proper
6290 -- signature (calls from outside must also be
6291 -- directed to this version rather than the
6292 -- overriding one, unlike the dispatching case).
6293 -- Calls from inside the package will still resolve
6294 -- to the overriding subprogram since the derived one
6295 -- is marked as not visible within the package.
6297 -- If the private operation is dispatching, we achieve
6298 -- the overriding by keeping the implicit operation
6299 -- but setting its alias to be the overriding one. In
6300 -- this fashion the proper body is executed in all
6301 -- cases, but the original signature is used outside
6304 -- If the overriding is not in the private part, we
6305 -- remove the implicit operation altogether.
6307 if Is_Private_Declaration
(S
) then
6309 if not Is_Dispatching_Operation
(E
) then
6310 Set_Is_Immediately_Visible
(E
, False);
6312 -- Work done in Override_Dispatching_Operation,
6313 -- so nothing else need to be done here.
6319 -- Find predecessor of E in Homonym chain
6321 if E
= Current_Entity
(E
) then
6324 Prev_Vis
:= Current_Entity
(E
);
6325 while Homonym
(Prev_Vis
) /= E
loop
6326 Prev_Vis
:= Homonym
(Prev_Vis
);
6330 if Prev_Vis
/= Empty
then
6332 -- Skip E in the visibility chain
6334 Set_Homonym
(Prev_Vis
, Homonym
(E
));
6337 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6340 Set_Next_Entity
(Prev
, Next_Entity
(E
));
6342 if No
(Next_Entity
(Prev
)) then
6343 Set_Last_Entity
(Current_Scope
, Prev
);
6349 Enter_Overloaded_Entity
(S
);
6350 Set_Is_Overriding_Operation
(S
);
6351 Check_Overriding_Indicator
(S
, E
);
6353 -- Indicate that S overrides the operation from which
6356 if Comes_From_Source
(S
) then
6357 if Present
(Alias
(E
)) then
6358 Set_Overridden_Operation
(S
, Alias
(E
));
6360 Set_Overridden_Operation
(S
, E
);
6364 if Is_Dispatching_Operation
(E
) then
6366 -- An overriding dispatching subprogram inherits the
6367 -- convention of the overridden subprogram (by
6370 Set_Convention
(S
, Convention
(E
));
6371 Check_Dispatching_Operation
(S
, E
);
6374 Check_Dispatching_Operation
(S
, Empty
);
6377 Maybe_Primitive_Operation
(Is_Overriding
=> True);
6378 goto Check_Inequality
;
6381 -- Apparent redeclarations in instances can occur when two
6382 -- formal types get the same actual type. The subprograms in
6383 -- in the instance are legal, even if not callable from the
6384 -- outside. Calls from within are disambiguated elsewhere.
6385 -- For dispatching operations in the visible part, the usual
6386 -- rules apply, and operations with the same profile are not
6389 elsif (In_Instance_Visible_Part
6390 and then not Is_Dispatching_Operation
(E
))
6391 or else In_Instance_Not_Visible
6395 -- Here we have a real error (identical profile)
6398 Error_Msg_Sloc
:= Sloc
(E
);
6400 -- Avoid cascaded errors if the entity appears in
6401 -- subsequent calls.
6403 Set_Scope
(S
, Current_Scope
);
6405 Error_Msg_N
("& conflicts with declaration#", S
);
6407 if Is_Generic_Instance
(S
)
6408 and then not Has_Completion
(E
)
6411 ("\instantiation cannot provide body for it", S
);
6418 -- If one subprogram has an access parameter and the other
6419 -- a parameter of an access type, calls to either might be
6420 -- ambiguous. Verify that parameters match except for the
6421 -- access parameter.
6423 if May_Hide_Profile
then
6428 F1
:= First_Formal
(S
);
6429 F2
:= First_Formal
(E
);
6430 while Present
(F1
) and then Present
(F2
) loop
6431 if Is_Access_Type
(Etype
(F1
)) then
6432 if not Is_Access_Type
(Etype
(F2
))
6433 or else not Conforming_Types
6434 (Designated_Type
(Etype
(F1
)),
6435 Designated_Type
(Etype
(F2
)),
6438 May_Hide_Profile
:= False;
6442 not Conforming_Types
6443 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
6445 May_Hide_Profile
:= False;
6456 Error_Msg_NE
("calls to& may be ambiguous?", S
, S
);
6467 -- On exit, we know that S is a new entity
6469 Enter_Overloaded_Entity
(S
);
6470 Maybe_Primitive_Operation
;
6471 Check_Overriding_Indicator
(S
, Overridden_Subp
);
6473 -- If S is a derived operation for an untagged type then by
6474 -- definition it's not a dispatching operation (even if the parent
6475 -- operation was dispatching), so we don't call
6476 -- Check_Dispatching_Operation in that case.
6478 if No
(Derived_Type
)
6479 or else Is_Tagged_Type
(Derived_Type
)
6481 Check_Dispatching_Operation
(S
, Empty
);
6485 -- If this is a user-defined equality operator that is not a derived
6486 -- subprogram, create the corresponding inequality. If the operation is
6487 -- dispatching, the expansion is done elsewhere, and we do not create
6488 -- an explicit inequality operation.
6490 <<Check_Inequality
>>
6491 if Chars
(S
) = Name_Op_Eq
6492 and then Etype
(S
) = Standard_Boolean
6493 and then Present
(Parent
(S
))
6494 and then not Is_Dispatching_Operation
(S
)
6496 Make_Inequality_Operator
(S
);
6498 end New_Overloaded_Entity
;
6500 ---------------------
6501 -- Process_Formals --
6502 ---------------------
6504 procedure Process_Formals
6506 Related_Nod
: Node_Id
)
6508 Param_Spec
: Node_Id
;
6510 Formal_Type
: Entity_Id
;
6514 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
6515 -- Check whether the default has a class-wide type. After analysis the
6516 -- default has the type of the formal, so we must also check explicitly
6517 -- for an access attribute.
6519 ---------------------------
6520 -- Is_Class_Wide_Default --
6521 ---------------------------
6523 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
6525 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
6526 or else (Nkind
(D
) = N_Attribute_Reference
6527 and then Attribute_Name
(D
) = Name_Access
6528 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
6529 end Is_Class_Wide_Default
;
6531 -- Start of processing for Process_Formals
6534 -- In order to prevent premature use of the formals in the same formal
6535 -- part, the Ekind is left undefined until all default expressions are
6536 -- analyzed. The Ekind is established in a separate loop at the end.
6538 Param_Spec
:= First
(T
);
6540 while Present
(Param_Spec
) loop
6542 Formal
:= Defining_Identifier
(Param_Spec
);
6543 Enter_Name
(Formal
);
6545 -- Case of ordinary parameters
6547 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
6548 Find_Type
(Parameter_Type
(Param_Spec
));
6549 Ptype
:= Parameter_Type
(Param_Spec
);
6551 if Ptype
= Error
then
6555 Formal_Type
:= Entity
(Ptype
);
6557 if Is_Incomplete_Type
(Formal_Type
)
6559 (Is_Class_Wide_Type
(Formal_Type
)
6560 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
6562 -- Ada 2005 (AI-326): Tagged incomplete types allowed
6564 if Is_Tagged_Type
(Formal_Type
) then
6567 elsif Nkind
(Parent
(T
)) /= N_Access_Function_Definition
6568 and then Nkind
(Parent
(T
)) /= N_Access_Procedure_Definition
6570 Error_Msg_N
("invalid use of incomplete type", Param_Spec
);
6573 elsif Ekind
(Formal_Type
) = E_Void
then
6574 Error_Msg_NE
("premature use of&",
6575 Parameter_Type
(Param_Spec
), Formal_Type
);
6578 -- Ada 2005 (AI-231): Create and decorate an internal subtype
6579 -- declaration corresponding to the null-excluding type of the
6580 -- formal in the enclosing scope. Finally, replace the parameter
6581 -- type of the formal with the internal subtype.
6583 if Ada_Version
>= Ada_05
6584 and then Null_Exclusion_Present
(Param_Spec
)
6586 if not Is_Access_Type
(Formal_Type
) then
6587 Error_Msg_N
("null-exclusion must be applied to an " &
6588 "access type", Param_Spec
);
6590 if Can_Never_Be_Null
(Formal_Type
)
6591 and then Comes_From_Source
(Related_Nod
)
6594 ("null-exclusion cannot be applied to " &
6595 "a null excluding type", Param_Spec
);
6599 Create_Null_Excluding_Itype
6601 Related_Nod
=> Related_Nod
,
6602 Scope_Id
=> Scope
(Current_Scope
));
6606 -- An access formal type
6610 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
6612 -- Ada 2005 (AI-254)
6615 AD
: constant Node_Id
:=
6616 Access_To_Subprogram_Definition
6617 (Parameter_Type
(Param_Spec
));
6619 if Present
(AD
) and then Protected_Present
(AD
) then
6621 Replace_Anonymous_Access_To_Protected_Subprogram
6622 (Param_Spec
, Formal_Type
);
6627 Set_Etype
(Formal
, Formal_Type
);
6628 Default
:= Expression
(Param_Spec
);
6630 if Present
(Default
) then
6631 if Out_Present
(Param_Spec
) then
6633 ("default initialization only allowed for IN parameters",
6637 -- Do the special preanalysis of the expression (see section on
6638 -- "Handling of Default Expressions" in the spec of package Sem).
6640 Analyze_Per_Use_Expression
(Default
, Formal_Type
);
6642 -- Check that the designated type of an access parameter's default
6643 -- is not a class-wide type unless the parameter's designated type
6644 -- is also class-wide.
6646 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
6647 and then not From_With_Type
(Formal_Type
)
6648 and then Is_Class_Wide_Default
(Default
)
6649 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
6652 ("access to class-wide expression not allowed here", Default
);
6656 -- Ada 2005 (AI-231): Static checks
6658 if Ada_Version
>= Ada_05
6659 and then Is_Access_Type
(Etype
(Formal
))
6660 and then Can_Never_Be_Null
(Etype
(Formal
))
6662 Null_Exclusion_Static_Checks
(Param_Spec
);
6669 -- If this is the formal part of a function specification, analyze the
6670 -- subtype mark in the context where the formals are visible but not
6671 -- yet usable, and may hide outer homographs.
6673 if Nkind
(Related_Nod
) = N_Function_Specification
then
6674 Analyze_Return_Type
(Related_Nod
);
6677 -- Now set the kind (mode) of each formal
6679 Param_Spec
:= First
(T
);
6681 while Present
(Param_Spec
) loop
6682 Formal
:= Defining_Identifier
(Param_Spec
);
6683 Set_Formal_Mode
(Formal
);
6685 if Ekind
(Formal
) = E_In_Parameter
then
6686 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
6688 if Present
(Expression
(Param_Spec
)) then
6689 Default
:= Expression
(Param_Spec
);
6691 if Is_Scalar_Type
(Etype
(Default
)) then
6693 (Parameter_Type
(Param_Spec
)) /= N_Access_Definition
6695 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
6698 Formal_Type
:= Access_Definition
6699 (Related_Nod
, Parameter_Type
(Param_Spec
));
6702 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
6710 end Process_Formals
;
6712 ----------------------------
6713 -- Reference_Body_Formals --
6714 ----------------------------
6716 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
6721 if Error_Posted
(Spec
) then
6725 Fs
:= First_Formal
(Spec
);
6726 Fb
:= First_Formal
(Bod
);
6728 while Present
(Fs
) loop
6729 Generate_Reference
(Fs
, Fb
, 'b');
6732 Style
.Check_Identifier
(Fb
, Fs
);
6735 Set_Spec_Entity
(Fb
, Fs
);
6736 Set_Referenced
(Fs
, False);
6740 end Reference_Body_Formals
;
6742 -------------------------
6743 -- Set_Actual_Subtypes --
6744 -------------------------
6746 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
6747 Loc
: constant Source_Ptr
:= Sloc
(N
);
6751 First_Stmt
: Node_Id
:= Empty
;
6752 AS_Needed
: Boolean;
6755 -- If this is an emtpy initialization procedure, no need to create
6756 -- actual subtypes (small optimization).
6758 if Ekind
(Subp
) = E_Procedure
6759 and then Is_Null_Init_Proc
(Subp
)
6764 Formal
:= First_Formal
(Subp
);
6765 while Present
(Formal
) loop
6766 T
:= Etype
(Formal
);
6768 -- We never need an actual subtype for a constrained formal
6770 if Is_Constrained
(T
) then
6773 -- If we have unknown discriminants, then we do not need an actual
6774 -- subtype, or more accurately we cannot figure it out! Note that
6775 -- all class-wide types have unknown discriminants.
6777 elsif Has_Unknown_Discriminants
(T
) then
6780 -- At this stage we have an unconstrained type that may need an
6781 -- actual subtype. For sure the actual subtype is needed if we have
6782 -- an unconstrained array type.
6784 elsif Is_Array_Type
(T
) then
6787 -- The only other case needing an actual subtype is an unconstrained
6788 -- record type which is an IN parameter (we cannot generate actual
6789 -- subtypes for the OUT or IN OUT case, since an assignment can
6790 -- change the discriminant values. However we exclude the case of
6791 -- initialization procedures, since discriminants are handled very
6792 -- specially in this context, see the section entitled "Handling of
6793 -- Discriminants" in Einfo.
6795 -- We also exclude the case of Discrim_SO_Functions (functions used
6796 -- in front end layout mode for size/offset values), since in such
6797 -- functions only discriminants are referenced, and not only are such
6798 -- subtypes not needed, but they cannot always be generated, because
6799 -- of order of elaboration issues.
6801 elsif Is_Record_Type
(T
)
6802 and then Ekind
(Formal
) = E_In_Parameter
6803 and then Chars
(Formal
) /= Name_uInit
6804 and then not Is_Unchecked_Union
(T
)
6805 and then not Is_Discrim_SO_Function
(Subp
)
6809 -- All other cases do not need an actual subtype
6815 -- Generate actual subtypes for unconstrained arrays and
6816 -- unconstrained discriminated records.
6819 if Nkind
(N
) = N_Accept_Statement
then
6821 -- If expansion is active, The formal is replaced by a local
6822 -- variable that renames the corresponding entry of the
6823 -- parameter block, and it is this local variable that may
6824 -- require an actual subtype.
6826 if Expander_Active
then
6827 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
6829 Decl
:= Build_Actual_Subtype
(T
, Formal
);
6832 if Present
(Handled_Statement_Sequence
(N
)) then
6834 First
(Statements
(Handled_Statement_Sequence
(N
)));
6835 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
6836 Mark_Rewrite_Insertion
(Decl
);
6838 -- If the accept statement has no body, there will be no
6839 -- reference to the actuals, so no need to compute actual
6846 Decl
:= Build_Actual_Subtype
(T
, Formal
);
6847 Prepend
(Decl
, Declarations
(N
));
6848 Mark_Rewrite_Insertion
(Decl
);
6851 -- The declaration uses the bounds of an existing object, and
6852 -- therefore needs no constraint checks.
6854 Analyze
(Decl
, Suppress
=> All_Checks
);
6856 -- We need to freeze manually the generated type when it is
6857 -- inserted anywhere else than in a declarative part.
6859 if Present
(First_Stmt
) then
6860 Insert_List_Before_And_Analyze
(First_Stmt
,
6861 Freeze_Entity
(Defining_Identifier
(Decl
), Loc
));
6864 if Nkind
(N
) = N_Accept_Statement
6865 and then Expander_Active
6867 Set_Actual_Subtype
(Renamed_Object
(Formal
),
6868 Defining_Identifier
(Decl
));
6870 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
6874 Next_Formal
(Formal
);
6876 end Set_Actual_Subtypes
;
6878 ---------------------
6879 -- Set_Formal_Mode --
6880 ---------------------
6882 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
6883 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
6886 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
6887 -- since we ensure that corresponding actuals are always valid at the
6888 -- point of the call.
6890 if Out_Present
(Spec
) then
6891 if Ekind
(Scope
(Formal_Id
)) = E_Function
6892 or else Ekind
(Scope
(Formal_Id
)) = E_Generic_Function
6894 Error_Msg_N
("functions can only have IN parameters", Spec
);
6895 Set_Ekind
(Formal_Id
, E_In_Parameter
);
6897 elsif In_Present
(Spec
) then
6898 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
6901 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
6902 Set_Never_Set_In_Source
(Formal_Id
, True);
6903 Set_Is_True_Constant
(Formal_Id
, False);
6904 Set_Current_Value
(Formal_Id
, Empty
);
6908 Set_Ekind
(Formal_Id
, E_In_Parameter
);
6911 -- Set Is_Known_Non_Null for access parameters since the language
6912 -- guarantees that access parameters are always non-null. We also set
6913 -- Can_Never_Be_Null, since there is no way to change the value.
6915 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
6917 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
6918 -- null; In Ada 2005, only if then null_exclusion is explicit.
6920 if Ada_Version
< Ada_05
6921 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
6923 Set_Is_Known_Non_Null
(Formal_Id
);
6924 Set_Can_Never_Be_Null
(Formal_Id
);
6927 -- Ada 2005 (AI-231): Null-exclusion access subtype
6929 elsif Is_Access_Type
(Etype
(Formal_Id
))
6930 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
6932 Set_Is_Known_Non_Null
(Formal_Id
);
6935 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
6936 Set_Formal_Validity
(Formal_Id
);
6937 end Set_Formal_Mode
;
6939 -------------------------
6940 -- Set_Formal_Validity --
6941 -------------------------
6943 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
6945 -- If no validity checking, then we cannot assume anything about the
6946 -- validity of parameters, since we do not know there is any checking
6947 -- of the validity on the call side.
6949 if not Validity_Checks_On
then
6952 -- If validity checking for parameters is enabled, this means we are
6953 -- not supposed to make any assumptions about argument values.
6955 elsif Validity_Check_Parameters
then
6958 -- If we are checking in parameters, we will assume that the caller is
6959 -- also checking parameters, so we can assume the parameter is valid.
6961 elsif Ekind
(Formal_Id
) = E_In_Parameter
6962 and then Validity_Check_In_Params
6964 Set_Is_Known_Valid
(Formal_Id
, True);
6966 -- Similar treatment for IN OUT parameters
6968 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
6969 and then Validity_Check_In_Out_Params
6971 Set_Is_Known_Valid
(Formal_Id
, True);
6973 end Set_Formal_Validity
;
6975 ------------------------
6976 -- Subtype_Conformant --
6977 ------------------------
6979 function Subtype_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
6982 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
);
6984 end Subtype_Conformant
;
6986 ---------------------
6987 -- Type_Conformant --
6988 ---------------------
6990 function Type_Conformant
6991 (New_Id
: Entity_Id
;
6993 Skip_Controlling_Formals
: Boolean := False) return Boolean
6997 May_Hide_Profile
:= False;
7000 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
7001 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
7003 end Type_Conformant
;
7005 -------------------------------
7006 -- Valid_Operator_Definition --
7007 -------------------------------
7009 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
7012 Id
: constant Name_Id
:= Chars
(Designator
);
7016 F
:= First_Formal
(Designator
);
7017 while Present
(F
) loop
7020 if Present
(Default_Value
(F
)) then
7022 ("default values not allowed for operator parameters",
7029 -- Verify that user-defined operators have proper number of arguments
7030 -- First case of operators which can only be unary
7033 or else Id
= Name_Op_Abs
7037 -- Case of operators which can be unary or binary
7039 elsif Id
= Name_Op_Add
7040 or Id
= Name_Op_Subtract
7042 N_OK
:= (N
in 1 .. 2);
7044 -- All other operators can only be binary
7052 ("incorrect number of arguments for operator", Designator
);
7056 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
7057 and then not Is_Intrinsic_Subprogram
(Designator
)
7060 ("explicit definition of inequality not allowed", Designator
);
7062 end Valid_Operator_Definition
;