1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
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_Ch9; use Exp_Ch9;
37 with Exp_Disp; use Exp_Disp;
38 with Exp_Tss; use Exp_Tss;
39 with Exp_Util; use Exp_Util;
40 with Fname; use Fname;
41 with Freeze; use Freeze;
42 with Itypes; use Itypes;
43 with Lib.Xref; use Lib.Xref;
44 with Layout; use Layout;
45 with Namet; use Namet;
47 with Nlists; use Nlists;
48 with Nmake; use Nmake;
50 with Output; use Output;
51 with Restrict; use Restrict;
52 with Rident; use Rident;
53 with Rtsfind; use Rtsfind;
55 with Sem_Aux; use Sem_Aux;
56 with Sem_Cat; use Sem_Cat;
57 with Sem_Ch3; use Sem_Ch3;
58 with Sem_Ch4; use Sem_Ch4;
59 with Sem_Ch5; use Sem_Ch5;
60 with Sem_Ch8; use Sem_Ch8;
61 with Sem_Ch10; use Sem_Ch10;
62 with Sem_Ch12; use Sem_Ch12;
63 with Sem_Ch13; use Sem_Ch13;
64 with Sem_Disp; use Sem_Disp;
65 with Sem_Dist; use Sem_Dist;
66 with Sem_Elim; use Sem_Elim;
67 with Sem_Eval; use Sem_Eval;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Prag; use Sem_Prag;
70 with Sem_Res; use Sem_Res;
71 with Sem_Util; use Sem_Util;
72 with Sem_Type; use Sem_Type;
73 with Sem_Warn; use Sem_Warn;
74 with Sinput; use Sinput;
75 with Stand; use Stand;
76 with Sinfo; use Sinfo;
77 with Sinfo.CN; use Sinfo.CN;
78 with Snames; use Snames;
79 with Stringt; use Stringt;
81 with Stylesw; use Stylesw;
82 with Tbuild; use Tbuild;
83 with Uintp; use Uintp;
84 with Urealp; use Urealp;
85 with Validsw; use Validsw;
87 package body Sem_Ch6 is
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_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_Return_Statement. Called when the return statement
107 -- 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_Subprogram_Body_Helper (N : Node_Id);
115 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
116 -- that we can use RETURN but not skip the debug output at the end.
118 procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id);
119 -- Analyze a generic subprogram body. N is the body to be analyzed, and
120 -- Gen_Id is the defining entity Id for the corresponding spec.
122 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id);
123 -- If a subprogram has pragma Inline and inlining is active, use generic
124 -- machinery to build an unexpanded body for the subprogram. This body is
125 -- subsequently used for inline expansions at call sites. If subprogram can
126 -- be inlined (depending on size and nature of local declarations) this
127 -- function returns true. Otherwise subprogram body is treated normally.
128 -- If proper warnings are enabled and the subprogram contains a construct
129 -- that cannot be inlined, the offending construct is flagged accordingly.
131 procedure Check_Conformance
134 Ctype : Conformance_Type;
136 Conforms : out Boolean;
137 Err_Loc : Node_Id := Empty;
138 Get_Inst : Boolean := False;
139 Skip_Controlling_Formals : Boolean := False);
140 -- Given two entities, this procedure checks that the profiles associated
141 -- with these entities meet the conformance criterion given by the third
142 -- parameter. If they conform, Conforms is set True and control returns
143 -- to the caller. If they do not conform, Conforms is set to False, and
144 -- in addition, if Errmsg is True on the call, proper messages are output
145 -- to complain about the conformance failure. If Err_Loc is non_Empty
146 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
147 -- error messages are placed on the appropriate part of the construct
148 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
149 -- against a formal access-to-subprogram type so Get_Instance_Of must
152 procedure Check_Subprogram_Order (N : Node_Id);
153 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
154 -- the alpha ordering rule for N if this ordering requirement applicable.
156 procedure Check_Returns
160 Proc : Entity_Id := Empty);
161 -- Called to check for missing return statements in a function body, or for
162 -- returns present in a procedure body which has No_Return set. HSS is the
163 -- handled statement sequence for the subprogram body. This procedure
164 -- checks all flow paths to make sure they either have return (Mode = 'F',
165 -- used for functions) or do not have a return (Mode = 'P', used for
166 -- No_Return procedures). The flag Err is set if there are any control
167 -- paths not explicitly terminated by a return in the function case, and is
168 -- True otherwise. Proc is the entity for the procedure case and is used
169 -- in posting the warning message.
171 procedure Check_Untagged_Equality (Eq_Op : Entity_Id);
172 -- In Ada 2012, a primitive equality operator on an untagged record type
173 -- must appear before the type is frozen, and have the same visibility as
174 -- that of the type. This procedure checks that this rule is met, and
175 -- otherwise emits an error on the subprogram declaration and a warning
176 -- on the earlier freeze point if it is easy to locate.
178 procedure Enter_Overloaded_Entity (S : Entity_Id);
179 -- This procedure makes S, a new overloaded entity, into the first visible
180 -- entity with that name.
182 procedure Install_Entity (E : Entity_Id);
183 -- Make single entity visible. Used for generic formals as well
185 function Is_Non_Overriding_Operation
187 New_E : Entity_Id) return Boolean;
188 -- Enforce the rule given in 12.3(18): a private operation in an instance
189 -- overrides an inherited operation only if the corresponding operation
190 -- was overriding in the generic. This can happen for primitive operations
191 -- of types derived (in the generic unit) from formal private or formal
194 procedure Make_Inequality_Operator (S : Entity_Id);
195 -- Create the declaration for an inequality operator that is implicitly
196 -- created by a user-defined equality operator that yields a boolean.
198 procedure May_Need_Actuals (Fun : Entity_Id);
199 -- Flag functions that can be called without parameters, i.e. those that
200 -- have no parameters, or those for which defaults exist for all parameters
202 procedure Process_PPCs
205 Body_Id : Entity_Id);
206 -- Called from Analyze[_Generic]_Subprogram_Body to deal with scanning post
207 -- conditions for the body and assembling and inserting the _postconditions
208 -- procedure. N is the node for the subprogram body and Body_Id/Spec_Id are
209 -- the entities for the body and separate spec (if there is no separate
210 -- spec, Spec_Id is Empty).
212 procedure Set_Formal_Validity (Formal_Id : Entity_Id);
213 -- Formal_Id is an formal parameter entity. This procedure deals with
214 -- setting the proper validity status for this entity, which depends on
215 -- the kind of parameter and the validity checking mode.
217 ------------------------------
218 -- Analyze_Return_Statement --
219 ------------------------------
221 procedure Analyze_Return_Statement (N : Node_Id) is
223 pragma Assert (Nkind_In (N, N_Simple_Return_Statement,
224 N_Extended_Return_Statement));
226 Returns_Object : constant Boolean :=
227 Nkind (N) = N_Extended_Return_Statement
229 (Nkind (N) = N_Simple_Return_Statement
230 and then Present (Expression (N)));
231 -- True if we're returning something; that is, "return <expression>;"
232 -- or "return Result : T [:= ...]". False for "return;". Used for error
233 -- checking: If Returns_Object is True, N should apply to a function
234 -- body; otherwise N should apply to a procedure body, entry body,
235 -- accept statement, or extended return statement.
237 function Find_What_It_Applies_To return Entity_Id;
238 -- Find the entity representing the innermost enclosing body, accept
239 -- statement, or extended return statement. If the result is a callable
240 -- construct or extended return statement, then this will be the value
241 -- of the Return_Applies_To attribute. Otherwise, the program is
242 -- illegal. See RM-6.5(4/2).
244 -----------------------------
245 -- Find_What_It_Applies_To --
246 -----------------------------
248 function Find_What_It_Applies_To return Entity_Id is
249 Result : Entity_Id := Empty;
252 -- Loop outward through the Scope_Stack, skipping blocks and loops
254 for J in reverse 0 .. Scope_Stack.Last loop
255 Result := Scope_Stack.Table (J).Entity;
256 exit when Ekind (Result) /= E_Block and then
257 Ekind (Result) /= E_Loop;
260 pragma Assert (Present (Result));
262 end Find_What_It_Applies_To;
264 -- Local declarations
266 Scope_Id : constant Entity_Id := Find_What_It_Applies_To;
267 Kind : constant Entity_Kind := Ekind (Scope_Id);
268 Loc : constant Source_Ptr := Sloc (N);
269 Stm_Entity : constant Entity_Id :=
271 (E_Return_Statement, Current_Scope, Loc, 'R');
273 -- Start of processing for Analyze_Return_Statement
276 Set_Return_Statement_Entity (N, Stm_Entity);
278 Set_Etype (Stm_Entity, Standard_Void_Type);
279 Set_Return_Applies_To (Stm_Entity, Scope_Id);
281 -- Place Return entity on scope stack, to simplify enforcement of 6.5
282 -- (4/2): an inner return statement will apply to this extended return.
284 if Nkind (N) = N_Extended_Return_Statement then
285 Push_Scope (Stm_Entity);
288 -- Check that pragma No_Return is obeyed. Don't complain about the
289 -- implicitly-generated return that is placed at the end.
291 if No_Return (Scope_Id) and then Comes_From_Source (N) then
292 Error_Msg_N ("RETURN statement not allowed (No_Return)", N);
295 -- Warn on any unassigned OUT parameters if in procedure
297 if Ekind (Scope_Id) = E_Procedure then
298 Warn_On_Unassigned_Out_Parameter (N, Scope_Id);
301 -- Check that functions return objects, and other things do not
303 if Kind = E_Function or else Kind = E_Generic_Function then
304 if not Returns_Object then
305 Error_Msg_N ("missing expression in return from function", N);
308 elsif Kind = E_Procedure or else Kind = E_Generic_Procedure then
309 if Returns_Object then
310 Error_Msg_N ("procedure cannot return value (use function)", N);
313 elsif Kind = E_Entry or else Kind = E_Entry_Family then
314 if Returns_Object then
315 if Is_Protected_Type (Scope (Scope_Id)) then
316 Error_Msg_N ("entry body cannot return value", N);
318 Error_Msg_N ("accept statement cannot return value", N);
322 elsif Kind = E_Return_Statement then
324 -- We are nested within another return statement, which must be an
325 -- extended_return_statement.
327 if Returns_Object then
329 ("extended_return_statement cannot return value; " &
330 "use `""RETURN;""`", N);
334 Error_Msg_N ("illegal context for return statement", N);
337 if Kind = E_Function or else Kind = E_Generic_Function then
338 Analyze_Function_Return (N);
341 if Nkind (N) = N_Extended_Return_Statement then
345 Kill_Current_Values (Last_Assignment_Only => True);
346 Check_Unreachable_Code (N);
347 end Analyze_Return_Statement;
349 ---------------------------------------------
350 -- Analyze_Abstract_Subprogram_Declaration --
351 ---------------------------------------------
353 procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id) is
354 Designator : constant Entity_Id :=
355 Analyze_Subprogram_Specification (Specification (N));
356 Scop : constant Entity_Id := Current_Scope;
359 Generate_Definition (Designator);
360 Set_Is_Abstract_Subprogram (Designator);
361 New_Overloaded_Entity (Designator);
362 Check_Delayed_Subprogram (Designator);
364 Set_Categorization_From_Scope (Designator, Scop);
366 if Ekind (Scope (Designator)) = E_Protected_Type then
368 ("abstract subprogram not allowed in protected type", N);
370 -- Issue a warning if the abstract subprogram is neither a dispatching
371 -- operation nor an operation that overrides an inherited subprogram or
372 -- predefined operator, since this most likely indicates a mistake.
374 elsif Warn_On_Redundant_Constructs
375 and then not Is_Dispatching_Operation (Designator)
376 and then not Is_Overriding_Operation (Designator)
377 and then (not Is_Operator_Symbol_Name (Chars (Designator))
378 or else Scop /= Scope (Etype (First_Formal (Designator))))
381 ("?abstract subprogram is not dispatching or overriding", N);
384 Generate_Reference_To_Formals (Designator);
385 Check_Eliminated (Designator);
386 Analyze_Aspect_Specifications (N, Designator, Aspect_Specifications (N));
387 end Analyze_Abstract_Subprogram_Declaration;
389 ----------------------------------------
390 -- Analyze_Extended_Return_Statement --
391 ----------------------------------------
393 procedure Analyze_Extended_Return_Statement (N : Node_Id) is
395 Analyze_Return_Statement (N);
396 end Analyze_Extended_Return_Statement;
398 ----------------------------
399 -- Analyze_Function_Call --
400 ----------------------------
402 procedure Analyze_Function_Call (N : Node_Id) is
403 P : constant Node_Id := Name (N);
404 L : constant List_Id := Parameter_Associations (N);
410 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
411 -- as B (A, X). If the rewriting is successful, the call has been
412 -- analyzed and we just return.
414 if Nkind (P) = N_Selected_Component
415 and then Name (N) /= P
416 and then Is_Rewrite_Substitution (N)
417 and then Present (Etype (N))
422 -- If error analyzing name, then set Any_Type as result type and return
424 if Etype (P) = Any_Type then
425 Set_Etype (N, Any_Type);
429 -- Otherwise analyze the parameters
433 while Present (Actual) loop
435 Check_Parameterless_Call (Actual);
441 end Analyze_Function_Call;
443 -----------------------------
444 -- Analyze_Function_Return --
445 -----------------------------
447 procedure Analyze_Function_Return (N : Node_Id) is
448 Loc : constant Source_Ptr := Sloc (N);
449 Stm_Entity : constant Entity_Id := Return_Statement_Entity (N);
450 Scope_Id : constant Entity_Id := Return_Applies_To (Stm_Entity);
452 R_Type : constant Entity_Id := Etype (Scope_Id);
453 -- Function result subtype
455 procedure Check_Limited_Return (Expr : Node_Id);
456 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
457 -- limited types. Used only for simple return statements.
458 -- Expr is the expression returned.
460 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id);
461 -- Check that the return_subtype_indication properly matches the result
462 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
464 --------------------------
465 -- Check_Limited_Return --
466 --------------------------
468 procedure Check_Limited_Return (Expr : Node_Id) is
470 -- Ada 2005 (AI-318-02): Return-by-reference types have been
471 -- removed and replaced by anonymous access results. This is an
472 -- incompatibility with Ada 95. Not clear whether this should be
473 -- enforced yet or perhaps controllable with special switch. ???
475 if Is_Limited_Type (R_Type)
476 and then Comes_From_Source (N)
477 and then not In_Instance_Body
478 and then not OK_For_Limited_Init_In_05 (R_Type, Expr)
482 if Ada_Version >= Ada_2005
483 and then not Debug_Flag_Dot_L
484 and then not GNAT_Mode
487 ("(Ada 2005) cannot copy object of a limited type " &
488 "(RM-2005 6.5(5.5/2))", Expr);
490 if Is_Immutably_Limited_Type (R_Type) then
492 ("\return by reference not permitted in Ada 2005", Expr);
495 -- Warn in Ada 95 mode, to give folks a heads up about this
498 -- In GNAT mode, this is just a warning, to allow it to be
499 -- evilly turned off. Otherwise it is a real error.
501 -- In a generic context, simplify the warning because it makes
502 -- no sense to discuss pass-by-reference or copy.
504 elsif Warn_On_Ada_2005_Compatibility or GNAT_Mode then
505 if Inside_A_Generic then
507 ("return of limited object not permitted in Ada2005 "
508 & "(RM-2005 6.5(5.5/2))?", Expr);
510 elsif Is_Immutably_Limited_Type (R_Type) then
512 ("return by reference not permitted in Ada 2005 "
513 & "(RM-2005 6.5(5.5/2))?", Expr);
516 ("cannot copy object of a limited type in Ada 2005 "
517 & "(RM-2005 6.5(5.5/2))?", Expr);
520 -- Ada 95 mode, compatibility warnings disabled
523 return; -- skip continuation messages below
526 if not Inside_A_Generic then
528 ("\consider switching to return of access type", Expr);
529 Explain_Limited_Type (R_Type, Expr);
532 end Check_Limited_Return;
534 -------------------------------------
535 -- Check_Return_Subtype_Indication --
536 -------------------------------------
538 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id) is
539 Return_Obj : constant Node_Id := Defining_Identifier (Obj_Decl);
541 R_Stm_Type : constant Entity_Id := Etype (Return_Obj);
542 -- Subtype given in the extended return statement (must match R_Type)
544 Subtype_Ind : constant Node_Id :=
545 Object_Definition (Original_Node (Obj_Decl));
547 R_Type_Is_Anon_Access :
549 Ekind (R_Type) = E_Anonymous_Access_Subprogram_Type
551 Ekind (R_Type) = E_Anonymous_Access_Protected_Subprogram_Type
553 Ekind (R_Type) = E_Anonymous_Access_Type;
554 -- True if return type of the function is an anonymous access type
555 -- Can't we make Is_Anonymous_Access_Type in einfo ???
557 R_Stm_Type_Is_Anon_Access :
559 Ekind (R_Stm_Type) = E_Anonymous_Access_Subprogram_Type
561 Ekind (R_Stm_Type) = E_Anonymous_Access_Protected_Subprogram_Type
563 Ekind (R_Stm_Type) = E_Anonymous_Access_Type;
564 -- True if type of the return object is an anonymous access type
567 -- First, avoid cascaded errors
569 if Error_Posted (Obj_Decl) or else Error_Posted (Subtype_Ind) then
573 -- "return access T" case; check that the return statement also has
574 -- "access T", and that the subtypes statically match:
575 -- if this is an access to subprogram the signatures must match.
577 if R_Type_Is_Anon_Access then
578 if R_Stm_Type_Is_Anon_Access then
580 Ekind (Designated_Type (R_Stm_Type)) /= E_Subprogram_Type
582 if Base_Type (Designated_Type (R_Stm_Type)) /=
583 Base_Type (Designated_Type (R_Type))
584 or else not Subtypes_Statically_Match (R_Stm_Type, R_Type)
587 ("subtype must statically match function result subtype",
588 Subtype_Mark (Subtype_Ind));
592 -- For two anonymous access to subprogram types, the
593 -- types themselves must be type conformant.
595 if not Conforming_Types
596 (R_Stm_Type, R_Type, Fully_Conformant)
599 ("subtype must statically match function result subtype",
605 Error_Msg_N ("must use anonymous access type", Subtype_Ind);
608 -- Subtype indication case: check that the return object's type is
609 -- covered by the result type, and that the subtypes statically match
610 -- when the result subtype is constrained. Also handle record types
611 -- with unknown discriminants for which we have built the underlying
612 -- record view. Coverage is needed to allow specific-type return
613 -- objects when the result type is class-wide (see AI05-32).
615 elsif Covers (Base_Type (R_Type), Base_Type (R_Stm_Type))
616 or else (Is_Underlying_Record_View (Base_Type (R_Stm_Type))
620 Underlying_Record_View (Base_Type (R_Stm_Type))))
622 -- A null exclusion may be present on the return type, on the
623 -- function specification, on the object declaration or on the
626 if Is_Access_Type (R_Type)
628 (Can_Never_Be_Null (R_Type)
629 or else Null_Exclusion_Present (Parent (Scope_Id))) /=
630 Can_Never_Be_Null (R_Stm_Type)
633 ("subtype must statically match function result subtype",
637 -- AI05-103: for elementary types, subtypes must statically match
639 if Is_Constrained (R_Type)
640 or else Is_Access_Type (R_Type)
642 if not Subtypes_Statically_Match (R_Stm_Type, R_Type) then
644 ("subtype must statically match function result subtype",
649 elsif Etype (Base_Type (R_Type)) = R_Stm_Type
650 and then Is_Null_Extension (Base_Type (R_Type))
656 ("wrong type for return_subtype_indication", Subtype_Ind);
658 end Check_Return_Subtype_Indication;
660 ---------------------
661 -- Local Variables --
662 ---------------------
666 -- Start of processing for Analyze_Function_Return
669 Set_Return_Present (Scope_Id);
671 if Nkind (N) = N_Simple_Return_Statement then
672 Expr := Expression (N);
673 Analyze_And_Resolve (Expr, R_Type);
674 Check_Limited_Return (Expr);
677 -- Analyze parts specific to extended_return_statement:
680 Obj_Decl : constant Node_Id :=
681 Last (Return_Object_Declarations (N));
683 HSS : constant Node_Id := Handled_Statement_Sequence (N);
686 Expr := Expression (Obj_Decl);
688 -- Note: The check for OK_For_Limited_Init will happen in
689 -- Analyze_Object_Declaration; we treat it as a normal
690 -- object declaration.
692 Set_Is_Return_Object (Defining_Identifier (Obj_Decl));
695 Check_Return_Subtype_Indication (Obj_Decl);
697 if Present (HSS) then
700 if Present (Exception_Handlers (HSS)) then
702 -- ???Has_Nested_Block_With_Handler needs to be set.
703 -- Probably by creating an actual N_Block_Statement.
704 -- Probably in Expand.
710 -- Mark the return object as referenced, since the return is an
711 -- implicit reference of the object.
713 Set_Referenced (Defining_Identifier (Obj_Decl));
715 Check_References (Stm_Entity);
719 -- Case of Expr present
723 -- Defend against previous errors
725 and then Nkind (Expr) /= N_Empty
726 and then Present (Etype (Expr))
728 -- Apply constraint check. Note that this is done before the implicit
729 -- conversion of the expression done for anonymous access types to
730 -- ensure correct generation of the null-excluding check associated
731 -- with null-excluding expressions found in return statements.
733 Apply_Constraint_Check (Expr, R_Type);
735 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
736 -- type, apply an implicit conversion of the expression to that type
737 -- to force appropriate static and run-time accessibility checks.
739 if Ada_Version >= Ada_2005
740 and then Ekind (R_Type) = E_Anonymous_Access_Type
742 Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr)));
743 Analyze_And_Resolve (Expr, R_Type);
746 -- If the result type is class-wide, then check that the return
747 -- expression's type is not declared at a deeper level than the
748 -- function (RM05-6.5(5.6/2)).
750 if Ada_Version >= Ada_2005
751 and then Is_Class_Wide_Type (R_Type)
753 if Type_Access_Level (Etype (Expr)) >
754 Subprogram_Access_Level (Scope_Id)
757 ("level of return expression type is deeper than " &
758 "class-wide function!", Expr);
762 -- Check incorrect use of dynamically tagged expression
764 if Is_Tagged_Type (R_Type) then
765 Check_Dynamically_Tagged_Expression
771 -- ??? A real run-time accessibility check is needed in cases
772 -- involving dereferences of access parameters. For now we just
773 -- check the static cases.
775 if (Ada_Version < Ada_2005 or else Debug_Flag_Dot_L)
776 and then Is_Immutably_Limited_Type (Etype (Scope_Id))
777 and then Object_Access_Level (Expr) >
778 Subprogram_Access_Level (Scope_Id)
781 -- Suppress the message in a generic, where the rewriting
784 if Inside_A_Generic then
789 Make_Raise_Program_Error (Loc,
790 Reason => PE_Accessibility_Check_Failed));
794 ("cannot return a local value by reference?", N);
796 ("\& will be raised at run time?",
797 N, Standard_Program_Error);
802 and then Nkind (Parent (Scope_Id)) = N_Function_Specification
803 and then Null_Exclusion_Present (Parent (Scope_Id))
805 Apply_Compile_Time_Constraint_Error
807 Msg => "(Ada 2005) null not allowed for "
808 & "null-excluding return?",
809 Reason => CE_Null_Not_Allowed);
812 -- Apply checks suggested by AI05-0144 (dangerous order dependence)
813 -- (Disabled for now)
815 -- Check_Order_Dependence;
817 end Analyze_Function_Return;
819 -------------------------------------
820 -- Analyze_Generic_Subprogram_Body --
821 -------------------------------------
823 procedure Analyze_Generic_Subprogram_Body
827 Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id);
828 Kind : constant Entity_Kind := Ekind (Gen_Id);
834 -- Copy body and disable expansion while analyzing the generic For a
835 -- stub, do not copy the stub (which would load the proper body), this
836 -- will be done when the proper body is analyzed.
838 if Nkind (N) /= N_Subprogram_Body_Stub then
839 New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
844 Spec := Specification (N);
846 -- Within the body of the generic, the subprogram is callable, and
847 -- behaves like the corresponding non-generic unit.
849 Body_Id := Defining_Entity (Spec);
851 if Kind = E_Generic_Procedure
852 and then Nkind (Spec) /= N_Procedure_Specification
854 Error_Msg_N ("invalid body for generic procedure ", Body_Id);
857 elsif Kind = E_Generic_Function
858 and then Nkind (Spec) /= N_Function_Specification
860 Error_Msg_N ("invalid body for generic function ", Body_Id);
864 Set_Corresponding_Body (Gen_Decl, Body_Id);
866 if Has_Completion (Gen_Id)
867 and then Nkind (Parent (N)) /= N_Subunit
869 Error_Msg_N ("duplicate generic body", N);
872 Set_Has_Completion (Gen_Id);
875 if Nkind (N) = N_Subprogram_Body_Stub then
876 Set_Ekind (Defining_Entity (Specification (N)), Kind);
878 Set_Corresponding_Spec (N, Gen_Id);
881 if Nkind (Parent (N)) = N_Compilation_Unit then
882 Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N));
885 -- Make generic parameters immediately visible in the body. They are
886 -- needed to process the formals declarations. Then make the formals
887 -- visible in a separate step.
893 First_Ent : Entity_Id;
896 First_Ent := First_Entity (Gen_Id);
899 while Present (E) and then not Is_Formal (E) loop
904 Set_Use (Generic_Formal_Declarations (Gen_Decl));
906 -- Now generic formals are visible, and the specification can be
907 -- analyzed, for subsequent conformance check.
909 Body_Id := Analyze_Subprogram_Specification (Spec);
911 -- Make formal parameters visible
915 -- E is the first formal parameter, we loop through the formals
916 -- installing them so that they will be visible.
918 Set_First_Entity (Gen_Id, E);
919 while Present (E) loop
925 -- Visible generic entity is callable within its own body
927 Set_Ekind (Gen_Id, Ekind (Body_Id));
928 Set_Ekind (Body_Id, E_Subprogram_Body);
929 Set_Convention (Body_Id, Convention (Gen_Id));
930 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Gen_Id));
931 Set_Scope (Body_Id, Scope (Gen_Id));
932 Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id);
934 if Nkind (N) = N_Subprogram_Body_Stub then
936 -- No body to analyze, so restore state of generic unit
938 Set_Ekind (Gen_Id, Kind);
939 Set_Ekind (Body_Id, Kind);
941 if Present (First_Ent) then
942 Set_First_Entity (Gen_Id, First_Ent);
949 -- If this is a compilation unit, it must be made visible explicitly,
950 -- because the compilation of the declaration, unlike other library
951 -- unit declarations, does not. If it is not a unit, the following
952 -- is redundant but harmless.
954 Set_Is_Immediately_Visible (Gen_Id);
955 Reference_Body_Formals (Gen_Id, Body_Id);
957 if Is_Child_Unit (Gen_Id) then
958 Generate_Reference (Gen_Id, Scope (Gen_Id), 'k', False);
961 Set_Actual_Subtypes (N, Current_Scope);
962 Process_PPCs (N, Gen_Id, Body_Id);
964 -- If the generic unit carries pre- or post-conditions, copy them
965 -- to the original generic tree, so that they are properly added
966 -- to any instantiation.
969 Orig : constant Node_Id := Original_Node (N);
973 Cond := First (Declarations (N));
974 while Present (Cond) loop
975 if Nkind (Cond) = N_Pragma
976 and then Pragma_Name (Cond) = Name_Check
978 Prepend (New_Copy_Tree (Cond), Declarations (Orig));
980 elsif Nkind (Cond) = N_Pragma
981 and then Pragma_Name (Cond) = Name_Postcondition
983 Set_Ekind (Defining_Entity (Orig), Ekind (Gen_Id));
984 Prepend (New_Copy_Tree (Cond), Declarations (Orig));
993 Analyze_Declarations (Declarations (N));
995 Analyze (Handled_Statement_Sequence (N));
997 Save_Global_References (Original_Node (N));
999 -- Prior to exiting the scope, include generic formals again (if any
1000 -- are present) in the set of local entities.
1002 if Present (First_Ent) then
1003 Set_First_Entity (Gen_Id, First_Ent);
1006 Check_References (Gen_Id);
1009 Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope);
1011 Check_Subprogram_Order (N);
1013 -- Outside of its body, unit is generic again
1015 Set_Ekind (Gen_Id, Kind);
1016 Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False);
1019 Style.Check_Identifier (Body_Id, Gen_Id);
1023 end Analyze_Generic_Subprogram_Body;
1025 -----------------------------
1026 -- Analyze_Operator_Symbol --
1027 -----------------------------
1029 -- An operator symbol such as "+" or "and" may appear in context where the
1030 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1031 -- is just a string, as in (conjunction = "or"). In these cases the parser
1032 -- generates this node, and the semantics does the disambiguation. Other
1033 -- such case are actuals in an instantiation, the generic unit in an
1034 -- instantiation, and pragma arguments.
1036 procedure Analyze_Operator_Symbol (N : Node_Id) is
1037 Par : constant Node_Id := Parent (N);
1040 if (Nkind (Par) = N_Function_Call
1041 and then N = Name (Par))
1042 or else Nkind (Par) = N_Function_Instantiation
1043 or else (Nkind (Par) = N_Indexed_Component
1044 and then N = Prefix (Par))
1045 or else (Nkind (Par) = N_Pragma_Argument_Association
1046 and then not Is_Pragma_String_Literal (Par))
1047 or else Nkind (Par) = N_Subprogram_Renaming_Declaration
1048 or else (Nkind (Par) = N_Attribute_Reference
1049 and then Attribute_Name (Par) /= Name_Value)
1051 Find_Direct_Name (N);
1054 Change_Operator_Symbol_To_String_Literal (N);
1057 end Analyze_Operator_Symbol;
1059 -----------------------------------
1060 -- Analyze_Parameter_Association --
1061 -----------------------------------
1063 procedure Analyze_Parameter_Association (N : Node_Id) is
1065 Analyze (Explicit_Actual_Parameter (N));
1066 end Analyze_Parameter_Association;
1068 --------------------------------------
1069 -- Analyze_Parameterized_Expression --
1070 --------------------------------------
1072 procedure Analyze_Parameterized_Expression (N : Node_Id) is
1073 Loc : constant Source_Ptr := Sloc (N);
1074 LocX : constant Source_Ptr := Sloc (Expression (N));
1077 -- This is one of the occasions on which we write things during semantic
1078 -- analysis. Transform the parameterized expression into an equivalent
1079 -- subprogram body, and then analyze that.
1082 Make_Subprogram_Body (Loc,
1083 Specification => Specification (N),
1084 Declarations => Empty_List,
1085 Handled_Statement_Sequence =>
1086 Make_Handled_Sequence_Of_Statements (LocX,
1087 Statements => New_List (
1088 Make_Simple_Return_Statement (LocX,
1089 Expression => Expression (N))))));
1091 end Analyze_Parameterized_Expression;
1093 ----------------------------
1094 -- Analyze_Procedure_Call --
1095 ----------------------------
1097 procedure Analyze_Procedure_Call (N : Node_Id) is
1098 Loc : constant Source_Ptr := Sloc (N);
1099 P : constant Node_Id := Name (N);
1100 Actuals : constant List_Id := Parameter_Associations (N);
1104 procedure Analyze_Call_And_Resolve;
1105 -- Do Analyze and Resolve calls for procedure call
1106 -- At end, check illegal order dependence.
1108 ------------------------------
1109 -- Analyze_Call_And_Resolve --
1110 ------------------------------
1112 procedure Analyze_Call_And_Resolve is
1114 if Nkind (N) = N_Procedure_Call_Statement then
1116 Resolve (N, Standard_Void_Type);
1118 -- Apply checks suggested by AI05-0144 (Disabled for now)
1120 -- Check_Order_Dependence;
1125 end Analyze_Call_And_Resolve;
1127 -- Start of processing for Analyze_Procedure_Call
1130 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1131 -- a procedure call or an entry call. The prefix may denote an access
1132 -- to subprogram type, in which case an implicit dereference applies.
1133 -- If the prefix is an indexed component (without implicit dereference)
1134 -- then the construct denotes a call to a member of an entire family.
1135 -- If the prefix is a simple name, it may still denote a call to a
1136 -- parameterless member of an entry family. Resolution of these various
1137 -- interpretations is delicate.
1141 -- If this is a call of the form Obj.Op, the call may have been
1142 -- analyzed and possibly rewritten into a block, in which case
1145 if Analyzed (N) then
1149 -- If there is an error analyzing the name (which may have been
1150 -- rewritten if the original call was in prefix notation) then error
1151 -- has been emitted already, mark node and return.
1154 or else Etype (Name (N)) = Any_Type
1156 Set_Etype (N, Any_Type);
1160 -- Otherwise analyze the parameters
1162 if Present (Actuals) then
1163 Actual := First (Actuals);
1165 while Present (Actual) loop
1167 Check_Parameterless_Call (Actual);
1172 -- Special processing for Elab_Spec and Elab_Body calls
1174 if Nkind (P) = N_Attribute_Reference
1175 and then (Attribute_Name (P) = Name_Elab_Spec
1176 or else Attribute_Name (P) = Name_Elab_Body)
1178 if Present (Actuals) then
1180 ("no parameters allowed for this call", First (Actuals));
1184 Set_Etype (N, Standard_Void_Type);
1187 elsif Is_Entity_Name (P)
1188 and then Is_Record_Type (Etype (Entity (P)))
1189 and then Remote_AST_I_Dereference (P)
1193 elsif Is_Entity_Name (P)
1194 and then Ekind (Entity (P)) /= E_Entry_Family
1196 if Is_Access_Type (Etype (P))
1197 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1198 and then No (Actuals)
1199 and then Comes_From_Source (N)
1201 Error_Msg_N ("missing explicit dereference in call", N);
1204 Analyze_Call_And_Resolve;
1206 -- If the prefix is the simple name of an entry family, this is
1207 -- a parameterless call from within the task body itself.
1209 elsif Is_Entity_Name (P)
1210 and then Nkind (P) = N_Identifier
1211 and then Ekind (Entity (P)) = E_Entry_Family
1212 and then Present (Actuals)
1213 and then No (Next (First (Actuals)))
1215 -- Can be call to parameterless entry family. What appears to be the
1216 -- sole argument is in fact the entry index. Rewrite prefix of node
1217 -- accordingly. Source representation is unchanged by this
1221 Make_Indexed_Component (Loc,
1223 Make_Selected_Component (Loc,
1224 Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc),
1225 Selector_Name => New_Occurrence_Of (Entity (P), Loc)),
1226 Expressions => Actuals);
1227 Set_Name (N, New_N);
1228 Set_Etype (New_N, Standard_Void_Type);
1229 Set_Parameter_Associations (N, No_List);
1230 Analyze_Call_And_Resolve;
1232 elsif Nkind (P) = N_Explicit_Dereference then
1233 if Ekind (Etype (P)) = E_Subprogram_Type then
1234 Analyze_Call_And_Resolve;
1236 Error_Msg_N ("expect access to procedure in call", P);
1239 -- The name can be a selected component or an indexed component that
1240 -- yields an access to subprogram. Such a prefix is legal if the call
1241 -- has parameter associations.
1243 elsif Is_Access_Type (Etype (P))
1244 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1246 if Present (Actuals) then
1247 Analyze_Call_And_Resolve;
1249 Error_Msg_N ("missing explicit dereference in call ", N);
1252 -- If not an access to subprogram, then the prefix must resolve to the
1253 -- name of an entry, entry family, or protected operation.
1255 -- For the case of a simple entry call, P is a selected component where
1256 -- the prefix is the task and the selector name is the entry. A call to
1257 -- a protected procedure will have the same syntax. If the protected
1258 -- object contains overloaded operations, the entity may appear as a
1259 -- function, the context will select the operation whose type is Void.
1261 elsif Nkind (P) = N_Selected_Component
1262 and then (Ekind (Entity (Selector_Name (P))) = E_Entry
1264 Ekind (Entity (Selector_Name (P))) = E_Procedure
1266 Ekind (Entity (Selector_Name (P))) = E_Function)
1268 Analyze_Call_And_Resolve;
1270 elsif Nkind (P) = N_Selected_Component
1271 and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family
1272 and then Present (Actuals)
1273 and then No (Next (First (Actuals)))
1275 -- Can be call to parameterless entry family. What appears to be the
1276 -- sole argument is in fact the entry index. Rewrite prefix of node
1277 -- accordingly. Source representation is unchanged by this
1281 Make_Indexed_Component (Loc,
1282 Prefix => New_Copy (P),
1283 Expressions => Actuals);
1284 Set_Name (N, New_N);
1285 Set_Etype (New_N, Standard_Void_Type);
1286 Set_Parameter_Associations (N, No_List);
1287 Analyze_Call_And_Resolve;
1289 -- For the case of a reference to an element of an entry family, P is
1290 -- an indexed component whose prefix is a selected component (task and
1291 -- entry family), and whose index is the entry family index.
1293 elsif Nkind (P) = N_Indexed_Component
1294 and then Nkind (Prefix (P)) = N_Selected_Component
1295 and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family
1297 Analyze_Call_And_Resolve;
1299 -- If the prefix is the name of an entry family, it is a call from
1300 -- within the task body itself.
1302 elsif Nkind (P) = N_Indexed_Component
1303 and then Nkind (Prefix (P)) = N_Identifier
1304 and then Ekind (Entity (Prefix (P))) = E_Entry_Family
1307 Make_Selected_Component (Loc,
1308 Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc),
1309 Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc));
1310 Rewrite (Prefix (P), New_N);
1312 Analyze_Call_And_Resolve;
1314 -- Anything else is an error
1317 Error_Msg_N ("invalid procedure or entry call", N);
1319 end Analyze_Procedure_Call;
1321 -------------------------------------
1322 -- Analyze_Simple_Return_Statement --
1323 -------------------------------------
1325 procedure Analyze_Simple_Return_Statement (N : Node_Id) is
1327 if Present (Expression (N)) then
1328 Mark_Coextensions (N, Expression (N));
1331 Analyze_Return_Statement (N);
1332 end Analyze_Simple_Return_Statement;
1334 -------------------------
1335 -- Analyze_Return_Type --
1336 -------------------------
1338 procedure Analyze_Return_Type (N : Node_Id) is
1339 Designator : constant Entity_Id := Defining_Entity (N);
1340 Typ : Entity_Id := Empty;
1343 -- Normal case where result definition does not indicate an error
1345 if Result_Definition (N) /= Error then
1346 if Nkind (Result_Definition (N)) = N_Access_Definition then
1348 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1351 AD : constant Node_Id :=
1352 Access_To_Subprogram_Definition (Result_Definition (N));
1354 if Present (AD) and then Protected_Present (AD) then
1355 Typ := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1357 Typ := Access_Definition (N, Result_Definition (N));
1361 Set_Parent (Typ, Result_Definition (N));
1362 Set_Is_Local_Anonymous_Access (Typ);
1363 Set_Etype (Designator, Typ);
1365 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1367 Null_Exclusion_Static_Checks (N);
1369 -- Subtype_Mark case
1372 Find_Type (Result_Definition (N));
1373 Typ := Entity (Result_Definition (N));
1374 Set_Etype (Designator, Typ);
1376 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1378 Null_Exclusion_Static_Checks (N);
1380 -- If a null exclusion is imposed on the result type, then create
1381 -- a null-excluding itype (an access subtype) and use it as the
1382 -- function's Etype. Note that the null exclusion checks are done
1383 -- right before this, because they don't get applied to types that
1384 -- do not come from source.
1386 if Is_Access_Type (Typ)
1387 and then Null_Exclusion_Present (N)
1389 Set_Etype (Designator,
1390 Create_Null_Excluding_Itype
1393 Scope_Id => Scope (Current_Scope)));
1395 -- The new subtype must be elaborated before use because
1396 -- it is visible outside of the function. However its base
1397 -- type may not be frozen yet, so the reference that will
1398 -- force elaboration must be attached to the freezing of
1401 -- If the return specification appears on a proper body,
1402 -- the subtype will have been created already on the spec.
1404 if Is_Frozen (Typ) then
1405 if Nkind (Parent (N)) = N_Subprogram_Body
1406 and then Nkind (Parent (Parent (N))) = N_Subunit
1410 Build_Itype_Reference (Etype (Designator), Parent (N));
1414 Ensure_Freeze_Node (Typ);
1417 IR : constant Node_Id := Make_Itype_Reference (Sloc (N));
1419 Set_Itype (IR, Etype (Designator));
1420 Append_Freeze_Actions (Typ, New_List (IR));
1425 Set_Etype (Designator, Typ);
1428 if Ekind (Typ) = E_Incomplete_Type
1429 and then Is_Value_Type (Typ)
1433 elsif Ekind (Typ) = E_Incomplete_Type
1434 or else (Is_Class_Wide_Type (Typ)
1436 Ekind (Root_Type (Typ)) = E_Incomplete_Type)
1438 -- AI05-0151: Tagged incomplete types are allowed in all formal
1439 -- parts. Untagged incomplete types are not allowed in bodies.
1441 if Ada_Version >= Ada_2012 then
1442 if Is_Tagged_Type (Typ) then
1445 elsif Nkind_In (Parent (Parent (N)),
1451 ("invalid use of untagged incomplete type&",
1457 ("invalid use of incomplete type&", Designator, Typ);
1462 -- Case where result definition does indicate an error
1465 Set_Etype (Designator, Any_Type);
1467 end Analyze_Return_Type;
1469 -----------------------------
1470 -- Analyze_Subprogram_Body --
1471 -----------------------------
1473 procedure Analyze_Subprogram_Body (N : Node_Id) is
1474 Loc : constant Source_Ptr := Sloc (N);
1475 Body_Spec : constant Node_Id := Specification (N);
1476 Body_Id : constant Entity_Id := Defining_Entity (Body_Spec);
1479 if Debug_Flag_C then
1480 Write_Str ("==> subprogram body ");
1481 Write_Name (Chars (Body_Id));
1482 Write_Str (" from ");
1483 Write_Location (Loc);
1488 Trace_Scope (N, Body_Id, " Analyze subprogram: ");
1490 -- The real work is split out into the helper, so it can do "return;"
1491 -- without skipping the debug output:
1493 Analyze_Subprogram_Body_Helper (N);
1495 if Debug_Flag_C then
1497 Write_Str ("<== subprogram body ");
1498 Write_Name (Chars (Body_Id));
1499 Write_Str (" from ");
1500 Write_Location (Loc);
1503 end Analyze_Subprogram_Body;
1505 ------------------------------------
1506 -- Analyze_Subprogram_Body_Helper --
1507 ------------------------------------
1509 -- This procedure is called for regular subprogram bodies, generic bodies,
1510 -- and for subprogram stubs of both kinds. In the case of stubs, only the
1511 -- specification matters, and is used to create a proper declaration for
1512 -- the subprogram, or to perform conformance checks.
1514 procedure Analyze_Subprogram_Body_Helper (N : Node_Id) is
1515 Loc : constant Source_Ptr := Sloc (N);
1516 Body_Deleted : constant Boolean := False;
1517 Body_Spec : constant Node_Id := Specification (N);
1518 Body_Id : Entity_Id := Defining_Entity (Body_Spec);
1519 Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id);
1520 Conformant : Boolean;
1523 Prot_Typ : Entity_Id := Empty;
1524 Spec_Id : Entity_Id;
1525 Spec_Decl : Node_Id := Empty;
1527 Last_Real_Spec_Entity : Entity_Id := Empty;
1528 -- When we analyze a separate spec, the entity chain ends up containing
1529 -- the formals, as well as any itypes generated during analysis of the
1530 -- default expressions for parameters, or the arguments of associated
1531 -- precondition/postcondition pragmas (which are analyzed in the context
1532 -- of the spec since they have visibility on formals).
1534 -- These entities belong with the spec and not the body. However we do
1535 -- the analysis of the body in the context of the spec (again to obtain
1536 -- visibility to the formals), and all the entities generated during
1537 -- this analysis end up also chained to the entity chain of the spec.
1538 -- But they really belong to the body, and there is circuitry to move
1539 -- them from the spec to the body.
1541 -- However, when we do this move, we don't want to move the real spec
1542 -- entities (first para above) to the body. The Last_Real_Spec_Entity
1543 -- variable points to the last real spec entity, so we only move those
1544 -- chained beyond that point. It is initialized to Empty to deal with
1545 -- the case where there is no separate spec.
1547 procedure Check_Anonymous_Return;
1548 -- Ada 2005: if a function returns an access type that denotes a task,
1549 -- or a type that contains tasks, we must create a master entity for
1550 -- the anonymous type, which typically will be used in an allocator
1551 -- in the body of the function.
1553 procedure Check_Inline_Pragma (Spec : in out Node_Id);
1554 -- Look ahead to recognize a pragma that may appear after the body.
1555 -- If there is a previous spec, check that it appears in the same
1556 -- declarative part. If the pragma is Inline_Always, perform inlining
1557 -- unconditionally, otherwise only if Front_End_Inlining is requested.
1558 -- If the body acts as a spec, and inlining is required, we create a
1559 -- subprogram declaration for it, in order to attach the body to inline.
1560 -- If pragma does not appear after the body, check whether there is
1561 -- an inline pragma before any local declarations.
1563 procedure Check_Missing_Return;
1564 -- Checks for a function with a no return statements, and also performs
1565 -- the warning checks implemented by Check_Returns.
1567 function Disambiguate_Spec return Entity_Id;
1568 -- When a primitive is declared between the private view and the full
1569 -- view of a concurrent type which implements an interface, a special
1570 -- mechanism is used to find the corresponding spec of the primitive
1573 function Is_Private_Concurrent_Primitive
1574 (Subp_Id : Entity_Id) return Boolean;
1575 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
1576 -- type that implements an interface and has a private view.
1578 procedure Set_Trivial_Subprogram (N : Node_Id);
1579 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
1580 -- subprogram whose body is being analyzed. N is the statement node
1581 -- causing the flag to be set, if the following statement is a return
1582 -- of an entity, we mark the entity as set in source to suppress any
1583 -- warning on the stylized use of function stubs with a dummy return.
1585 procedure Verify_Overriding_Indicator;
1586 -- If there was a previous spec, the entity has been entered in the
1587 -- current scope previously. If the body itself carries an overriding
1588 -- indicator, check that it is consistent with the known status of the
1591 ----------------------------
1592 -- Check_Anonymous_Return --
1593 ----------------------------
1595 procedure Check_Anonymous_Return is
1601 if Present (Spec_Id) then
1607 if Ekind (Scop) = E_Function
1608 and then Ekind (Etype (Scop)) = E_Anonymous_Access_Type
1609 and then not Is_Thunk (Scop)
1610 and then (Has_Task (Designated_Type (Etype (Scop)))
1612 (Is_Class_Wide_Type (Designated_Type (Etype (Scop)))
1614 Is_Limited_Record (Designated_Type (Etype (Scop)))))
1615 and then Expander_Active
1617 -- Avoid cases with no tasking support
1619 and then RTE_Available (RE_Current_Master)
1620 and then not Restriction_Active (No_Task_Hierarchy)
1623 Make_Object_Declaration (Loc,
1624 Defining_Identifier =>
1625 Make_Defining_Identifier (Loc, Name_uMaster),
1626 Constant_Present => True,
1627 Object_Definition =>
1628 New_Reference_To (RTE (RE_Master_Id), Loc),
1630 Make_Explicit_Dereference (Loc,
1631 New_Reference_To (RTE (RE_Current_Master), Loc)));
1633 if Present (Declarations (N)) then
1634 Prepend (Decl, Declarations (N));
1636 Set_Declarations (N, New_List (Decl));
1639 Set_Master_Id (Etype (Scop), Defining_Identifier (Decl));
1640 Set_Has_Master_Entity (Scop);
1642 -- Now mark the containing scope as a task master
1645 while Nkind (Par) /= N_Compilation_Unit loop
1646 Par := Parent (Par);
1647 pragma Assert (Present (Par));
1649 -- If we fall off the top, we are at the outer level, and
1650 -- the environment task is our effective master, so nothing
1654 (Par, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
1656 Set_Is_Task_Master (Par, True);
1661 end Check_Anonymous_Return;
1663 -------------------------
1664 -- Check_Inline_Pragma --
1665 -------------------------
1667 procedure Check_Inline_Pragma (Spec : in out Node_Id) is
1671 function Is_Inline_Pragma (N : Node_Id) return Boolean;
1672 -- True when N is a pragma Inline or Inline_Always that applies
1673 -- to this subprogram.
1675 -----------------------
1676 -- Is_Inline_Pragma --
1677 -----------------------
1679 function Is_Inline_Pragma (N : Node_Id) return Boolean is
1682 Nkind (N) = N_Pragma
1684 (Pragma_Name (N) = Name_Inline_Always
1687 and then Pragma_Name (N) = Name_Inline))
1690 (Expression (First (Pragma_Argument_Associations (N))))
1692 end Is_Inline_Pragma;
1694 -- Start of processing for Check_Inline_Pragma
1697 if not Expander_Active then
1701 if Is_List_Member (N)
1702 and then Present (Next (N))
1703 and then Is_Inline_Pragma (Next (N))
1707 elsif Nkind (N) /= N_Subprogram_Body_Stub
1708 and then Present (Declarations (N))
1709 and then Is_Inline_Pragma (First (Declarations (N)))
1711 Prag := First (Declarations (N));
1717 if Present (Prag) then
1718 if Present (Spec_Id) then
1719 if In_Same_List (N, Unit_Declaration_Node (Spec_Id)) then
1724 -- Create a subprogram declaration, to make treatment uniform
1727 Subp : constant Entity_Id :=
1728 Make_Defining_Identifier (Loc, Chars (Body_Id));
1729 Decl : constant Node_Id :=
1730 Make_Subprogram_Declaration (Loc,
1732 New_Copy_Tree (Specification (N)));
1735 Set_Defining_Unit_Name (Specification (Decl), Subp);
1737 if Present (First_Formal (Body_Id)) then
1738 Plist := Copy_Parameter_List (Body_Id);
1739 Set_Parameter_Specifications
1740 (Specification (Decl), Plist);
1743 Insert_Before (N, Decl);
1746 Set_Has_Pragma_Inline (Subp);
1748 if Pragma_Name (Prag) = Name_Inline_Always then
1749 Set_Is_Inlined (Subp);
1750 Set_Has_Pragma_Inline_Always (Subp);
1757 end Check_Inline_Pragma;
1759 --------------------------
1760 -- Check_Missing_Return --
1761 --------------------------
1763 procedure Check_Missing_Return is
1765 Missing_Ret : Boolean;
1768 if Nkind (Body_Spec) = N_Function_Specification then
1769 if Present (Spec_Id) then
1775 if Return_Present (Id) then
1776 Check_Returns (HSS, 'F', Missing_Ret);
1779 Set_Has_Missing_Return (Id);
1782 elsif (Is_Generic_Subprogram (Id)
1783 or else not Is_Machine_Code_Subprogram (Id))
1784 and then not Body_Deleted
1786 Error_Msg_N ("missing RETURN statement in function body", N);
1789 -- If procedure with No_Return, check returns
1791 elsif Nkind (Body_Spec) = N_Procedure_Specification
1792 and then Present (Spec_Id)
1793 and then No_Return (Spec_Id)
1795 Check_Returns (HSS, 'P', Missing_Ret, Spec_Id);
1797 end Check_Missing_Return;
1799 -----------------------
1800 -- Disambiguate_Spec --
1801 -----------------------
1803 function Disambiguate_Spec return Entity_Id is
1804 Priv_Spec : Entity_Id;
1807 procedure Replace_Types (To_Corresponding : Boolean);
1808 -- Depending on the flag, replace the type of formal parameters of
1809 -- Body_Id if it is a concurrent type implementing interfaces with
1810 -- the corresponding record type or the other way around.
1812 procedure Replace_Types (To_Corresponding : Boolean) is
1814 Formal_Typ : Entity_Id;
1817 Formal := First_Formal (Body_Id);
1818 while Present (Formal) loop
1819 Formal_Typ := Etype (Formal);
1821 -- From concurrent type to corresponding record
1823 if To_Corresponding then
1824 if Is_Concurrent_Type (Formal_Typ)
1825 and then Present (Corresponding_Record_Type (Formal_Typ))
1826 and then Present (Interfaces (
1827 Corresponding_Record_Type (Formal_Typ)))
1830 Corresponding_Record_Type (Formal_Typ));
1833 -- From corresponding record to concurrent type
1836 if Is_Concurrent_Record_Type (Formal_Typ)
1837 and then Present (Interfaces (Formal_Typ))
1840 Corresponding_Concurrent_Type (Formal_Typ));
1844 Next_Formal (Formal);
1848 -- Start of processing for Disambiguate_Spec
1851 -- Try to retrieve the specification of the body as is. All error
1852 -- messages are suppressed because the body may not have a spec in
1853 -- its current state.
1855 Spec_N := Find_Corresponding_Spec (N, False);
1857 -- It is possible that this is the body of a primitive declared
1858 -- between a private and a full view of a concurrent type. The
1859 -- controlling parameter of the spec carries the concurrent type,
1860 -- not the corresponding record type as transformed by Analyze_
1861 -- Subprogram_Specification. In such cases, we undo the change
1862 -- made by the analysis of the specification and try to find the
1865 -- Note that wrappers already have their corresponding specs and
1866 -- bodies set during their creation, so if the candidate spec is
1867 -- a wrapper, then we definitely need to swap all types to their
1868 -- original concurrent status.
1871 or else Is_Primitive_Wrapper (Spec_N)
1873 -- Restore all references of corresponding record types to the
1874 -- original concurrent types.
1876 Replace_Types (To_Corresponding => False);
1877 Priv_Spec := Find_Corresponding_Spec (N, False);
1879 -- The current body truly belongs to a primitive declared between
1880 -- a private and a full view. We leave the modified body as is,
1881 -- and return the true spec.
1883 if Present (Priv_Spec)
1884 and then Is_Private_Primitive (Priv_Spec)
1889 -- In case that this is some sort of error, restore the original
1890 -- state of the body.
1892 Replace_Types (To_Corresponding => True);
1896 end Disambiguate_Spec;
1898 -------------------------------------
1899 -- Is_Private_Concurrent_Primitive --
1900 -------------------------------------
1902 function Is_Private_Concurrent_Primitive
1903 (Subp_Id : Entity_Id) return Boolean
1905 Formal_Typ : Entity_Id;
1908 if Present (First_Formal (Subp_Id)) then
1909 Formal_Typ := Etype (First_Formal (Subp_Id));
1911 if Is_Concurrent_Record_Type (Formal_Typ) then
1912 Formal_Typ := Corresponding_Concurrent_Type (Formal_Typ);
1915 -- The type of the first formal is a concurrent tagged type with
1919 Is_Concurrent_Type (Formal_Typ)
1920 and then Is_Tagged_Type (Formal_Typ)
1921 and then Has_Private_Declaration (Formal_Typ);
1925 end Is_Private_Concurrent_Primitive;
1927 ----------------------------
1928 -- Set_Trivial_Subprogram --
1929 ----------------------------
1931 procedure Set_Trivial_Subprogram (N : Node_Id) is
1932 Nxt : constant Node_Id := Next (N);
1935 Set_Is_Trivial_Subprogram (Body_Id);
1937 if Present (Spec_Id) then
1938 Set_Is_Trivial_Subprogram (Spec_Id);
1942 and then Nkind (Nxt) = N_Simple_Return_Statement
1943 and then No (Next (Nxt))
1944 and then Present (Expression (Nxt))
1945 and then Is_Entity_Name (Expression (Nxt))
1947 Set_Never_Set_In_Source (Entity (Expression (Nxt)), False);
1949 end Set_Trivial_Subprogram;
1951 ---------------------------------
1952 -- Verify_Overriding_Indicator --
1953 ---------------------------------
1955 procedure Verify_Overriding_Indicator is
1957 if Must_Override (Body_Spec) then
1958 if Nkind (Spec_Id) = N_Defining_Operator_Symbol
1959 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1963 elsif not Is_Overriding_Operation (Spec_Id) then
1965 ("subprogram& is not overriding", Body_Spec, Spec_Id);
1968 elsif Must_Not_Override (Body_Spec) then
1969 if Is_Overriding_Operation (Spec_Id) then
1971 ("subprogram& overrides inherited operation",
1972 Body_Spec, Spec_Id);
1974 elsif Nkind (Spec_Id) = N_Defining_Operator_Symbol
1975 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1978 ("subprogram & overrides predefined operator ",
1979 Body_Spec, Spec_Id);
1981 -- If this is not a primitive operation or protected subprogram,
1982 -- then the overriding indicator is altogether illegal.
1984 elsif not Is_Primitive (Spec_Id)
1985 and then Ekind (Scope (Spec_Id)) /= E_Protected_Type
1988 ("overriding indicator only allowed " &
1989 "if subprogram is primitive",
1993 elsif Style_Check -- ??? incorrect use of Style_Check!
1994 and then Is_Overriding_Operation (Spec_Id)
1996 pragma Assert (Unit_Declaration_Node (Body_Id) = N);
1997 Style.Missing_Overriding (N, Body_Id);
1999 end Verify_Overriding_Indicator;
2001 -- Start of processing for Analyze_Subprogram_Body_Helper
2004 -- Generic subprograms are handled separately. They always have a
2005 -- generic specification. Determine whether current scope has a
2006 -- previous declaration.
2008 -- If the subprogram body is defined within an instance of the same
2009 -- name, the instance appears as a package renaming, and will be hidden
2010 -- within the subprogram.
2012 if Present (Prev_Id)
2013 and then not Is_Overloadable (Prev_Id)
2014 and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
2015 or else Comes_From_Source (Prev_Id))
2017 if Is_Generic_Subprogram (Prev_Id) then
2019 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
2020 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
2022 Analyze_Generic_Subprogram_Body (N, Spec_Id);
2024 if Nkind (N) = N_Subprogram_Body then
2025 HSS := Handled_Statement_Sequence (N);
2026 Check_Missing_Return;
2032 -- Previous entity conflicts with subprogram name. Attempting to
2033 -- enter name will post error.
2035 Enter_Name (Body_Id);
2039 -- Non-generic case, find the subprogram declaration, if one was seen,
2040 -- or enter new overloaded entity in the current scope. If the
2041 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
2042 -- part of the context of one of its subunits. No need to redo the
2045 elsif Prev_Id = Body_Id
2046 and then Has_Completion (Body_Id)
2051 Body_Id := Analyze_Subprogram_Specification (Body_Spec);
2053 if Nkind (N) = N_Subprogram_Body_Stub
2054 or else No (Corresponding_Spec (N))
2056 if Is_Private_Concurrent_Primitive (Body_Id) then
2057 Spec_Id := Disambiguate_Spec;
2059 Spec_Id := Find_Corresponding_Spec (N);
2062 -- If this is a duplicate body, no point in analyzing it
2064 if Error_Posted (N) then
2068 -- A subprogram body should cause freezing of its own declaration,
2069 -- but if there was no previous explicit declaration, then the
2070 -- subprogram will get frozen too late (there may be code within
2071 -- the body that depends on the subprogram having been frozen,
2072 -- such as uses of extra formals), so we force it to be frozen
2073 -- here. Same holds if the body and spec are compilation units.
2074 -- Finally, if the return type is an anonymous access to protected
2075 -- subprogram, it must be frozen before the body because its
2076 -- expansion has generated an equivalent type that is used when
2077 -- elaborating the body.
2079 if No (Spec_Id) then
2080 Freeze_Before (N, Body_Id);
2082 elsif Nkind (Parent (N)) = N_Compilation_Unit then
2083 Freeze_Before (N, Spec_Id);
2085 elsif Is_Access_Subprogram_Type (Etype (Body_Id)) then
2086 Freeze_Before (N, Etype (Body_Id));
2090 Spec_Id := Corresponding_Spec (N);
2094 -- Do not inline any subprogram that contains nested subprograms, since
2095 -- the backend inlining circuit seems to generate uninitialized
2096 -- references in this case. We know this happens in the case of front
2097 -- end ZCX support, but it also appears it can happen in other cases as
2098 -- well. The backend often rejects attempts to inline in the case of
2099 -- nested procedures anyway, so little if anything is lost by this.
2100 -- Note that this is test is for the benefit of the back-end. There is
2101 -- a separate test for front-end inlining that also rejects nested
2104 -- Do not do this test if errors have been detected, because in some
2105 -- error cases, this code blows up, and we don't need it anyway if
2106 -- there have been errors, since we won't get to the linker anyway.
2108 if Comes_From_Source (Body_Id)
2109 and then Serious_Errors_Detected = 0
2113 P_Ent := Scope (P_Ent);
2114 exit when No (P_Ent) or else P_Ent = Standard_Standard;
2116 if Is_Subprogram (P_Ent) then
2117 Set_Is_Inlined (P_Ent, False);
2119 if Comes_From_Source (P_Ent)
2120 and then Has_Pragma_Inline (P_Ent)
2123 ("cannot inline& (nested subprogram)?",
2130 Check_Inline_Pragma (Spec_Id);
2132 -- Deal with special case of a fully private operation in the body of
2133 -- the protected type. We must create a declaration for the subprogram,
2134 -- in order to attach the protected subprogram that will be used in
2135 -- internal calls. We exclude compiler generated bodies from the
2136 -- expander since the issue does not arise for those cases.
2139 and then Comes_From_Source (N)
2140 and then Is_Protected_Type (Current_Scope)
2142 Spec_Id := Build_Private_Protected_Declaration (N);
2145 -- If a separate spec is present, then deal with freezing issues
2147 if Present (Spec_Id) then
2148 Spec_Decl := Unit_Declaration_Node (Spec_Id);
2149 Verify_Overriding_Indicator;
2151 -- In general, the spec will be frozen when we start analyzing the
2152 -- body. However, for internally generated operations, such as
2153 -- wrapper functions for inherited operations with controlling
2154 -- results, the spec may not have been frozen by the time we
2155 -- expand the freeze actions that include the bodies. In particular,
2156 -- extra formals for accessibility or for return-in-place may need
2157 -- to be generated. Freeze nodes, if any, are inserted before the
2160 if not Is_Frozen (Spec_Id)
2161 and then Expander_Active
2163 -- Force the generation of its freezing node to ensure proper
2164 -- management of access types in the backend.
2166 -- This is definitely needed for some cases, but it is not clear
2167 -- why, to be investigated further???
2169 Set_Has_Delayed_Freeze (Spec_Id);
2170 Insert_Actions (N, Freeze_Entity (Spec_Id, N));
2174 -- Mark presence of postcondition procedure in current scope and mark
2175 -- the procedure itself as needing debug info. The latter is important
2176 -- when analyzing decision coverage (for example, for MC/DC coverage).
2178 if Chars (Body_Id) = Name_uPostconditions then
2179 Set_Has_Postconditions (Current_Scope);
2180 Set_Debug_Info_Needed (Body_Id);
2183 -- Place subprogram on scope stack, and make formals visible. If there
2184 -- is a spec, the visible entity remains that of the spec.
2186 if Present (Spec_Id) then
2187 Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
2189 if Is_Child_Unit (Spec_Id) then
2190 Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False);
2194 Style.Check_Identifier (Body_Id, Spec_Id);
2197 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
2198 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
2200 if Is_Abstract_Subprogram (Spec_Id) then
2201 Error_Msg_N ("an abstract subprogram cannot have a body", N);
2205 Set_Convention (Body_Id, Convention (Spec_Id));
2206 Set_Has_Completion (Spec_Id);
2208 if Is_Protected_Type (Scope (Spec_Id)) then
2209 Prot_Typ := Scope (Spec_Id);
2212 -- If this is a body generated for a renaming, do not check for
2213 -- full conformance. The check is redundant, because the spec of
2214 -- the body is a copy of the spec in the renaming declaration,
2215 -- and the test can lead to spurious errors on nested defaults.
2217 if Present (Spec_Decl)
2218 and then not Comes_From_Source (N)
2220 (Nkind (Original_Node (Spec_Decl)) =
2221 N_Subprogram_Renaming_Declaration
2222 or else (Present (Corresponding_Body (Spec_Decl))
2224 Nkind (Unit_Declaration_Node
2225 (Corresponding_Body (Spec_Decl))) =
2226 N_Subprogram_Renaming_Declaration))
2230 -- Conversely, the spec may have been generated for specless body
2231 -- with an inline pragma.
2233 elsif Comes_From_Source (N)
2234 and then not Comes_From_Source (Spec_Id)
2235 and then Has_Pragma_Inline (Spec_Id)
2242 Fully_Conformant, True, Conformant, Body_Id);
2245 -- If the body is not fully conformant, we have to decide if we
2246 -- should analyze it or not. If it has a really messed up profile
2247 -- then we probably should not analyze it, since we will get too
2248 -- many bogus messages.
2250 -- Our decision is to go ahead in the non-fully conformant case
2251 -- only if it is at least mode conformant with the spec. Note
2252 -- that the call to Check_Fully_Conformant has issued the proper
2253 -- error messages to complain about the lack of conformance.
2256 and then not Mode_Conformant (Body_Id, Spec_Id)
2262 if Spec_Id /= Body_Id then
2263 Reference_Body_Formals (Spec_Id, Body_Id);
2266 if Nkind (N) /= N_Subprogram_Body_Stub then
2267 Set_Corresponding_Spec (N, Spec_Id);
2269 -- Ada 2005 (AI-345): If the operation is a primitive operation
2270 -- of a concurrent type, the type of the first parameter has been
2271 -- replaced with the corresponding record, which is the proper
2272 -- run-time structure to use. However, within the body there may
2273 -- be uses of the formals that depend on primitive operations
2274 -- of the type (in particular calls in prefixed form) for which
2275 -- we need the original concurrent type. The operation may have
2276 -- several controlling formals, so the replacement must be done
2279 if Comes_From_Source (Spec_Id)
2280 and then Present (First_Entity (Spec_Id))
2281 and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type
2282 and then Is_Tagged_Type (Etype (First_Entity (Spec_Id)))
2284 Present (Interfaces (Etype (First_Entity (Spec_Id))))
2287 (Corresponding_Concurrent_Type
2288 (Etype (First_Entity (Spec_Id))))
2291 Typ : constant Entity_Id := Etype (First_Entity (Spec_Id));
2295 Form := First_Formal (Spec_Id);
2296 while Present (Form) loop
2297 if Etype (Form) = Typ then
2298 Set_Etype (Form, Corresponding_Concurrent_Type (Typ));
2306 -- Make the formals visible, and place subprogram on scope stack.
2307 -- This is also the point at which we set Last_Real_Spec_Entity
2308 -- to mark the entities which will not be moved to the body.
2310 Install_Formals (Spec_Id);
2311 Last_Real_Spec_Entity := Last_Entity (Spec_Id);
2312 Push_Scope (Spec_Id);
2314 -- Make sure that the subprogram is immediately visible. For
2315 -- child units that have no separate spec this is indispensable.
2316 -- Otherwise it is safe albeit redundant.
2318 Set_Is_Immediately_Visible (Spec_Id);
2321 Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id);
2322 Set_Ekind (Body_Id, E_Subprogram_Body);
2323 Set_Scope (Body_Id, Scope (Spec_Id));
2324 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Spec_Id));
2326 -- Case of subprogram body with no previous spec
2330 and then Comes_From_Source (Body_Id)
2331 and then not Suppress_Style_Checks (Body_Id)
2332 and then not In_Instance
2334 Style.Body_With_No_Spec (N);
2337 New_Overloaded_Entity (Body_Id);
2339 if Nkind (N) /= N_Subprogram_Body_Stub then
2340 Set_Acts_As_Spec (N);
2341 Generate_Definition (Body_Id);
2343 (Body_Id, Body_Id, 'b', Set_Ref => False, Force => True);
2344 Generate_Reference_To_Formals (Body_Id);
2345 Install_Formals (Body_Id);
2346 Push_Scope (Body_Id);
2350 -- If the return type is an anonymous access type whose designated type
2351 -- is the limited view of a class-wide type and the non-limited view is
2352 -- available, update the return type accordingly.
2354 if Ada_Version >= Ada_2005
2355 and then Comes_From_Source (N)
2362 Rtyp := Etype (Current_Scope);
2364 if Ekind (Rtyp) = E_Anonymous_Access_Type then
2365 Etyp := Directly_Designated_Type (Rtyp);
2367 if Is_Class_Wide_Type (Etyp)
2368 and then From_With_Type (Etyp)
2370 Set_Directly_Designated_Type
2371 (Etype (Current_Scope), Available_View (Etyp));
2377 -- If this is the proper body of a stub, we must verify that the stub
2378 -- conforms to the body, and to the previous spec if one was present.
2379 -- we know already that the body conforms to that spec. This test is
2380 -- only required for subprograms that come from source.
2382 if Nkind (Parent (N)) = N_Subunit
2383 and then Comes_From_Source (N)
2384 and then not Error_Posted (Body_Id)
2385 and then Nkind (Corresponding_Stub (Parent (N))) =
2386 N_Subprogram_Body_Stub
2389 Old_Id : constant Entity_Id :=
2391 (Specification (Corresponding_Stub (Parent (N))));
2393 Conformant : Boolean := False;
2396 if No (Spec_Id) then
2397 Check_Fully_Conformant (Body_Id, Old_Id);
2401 (Body_Id, Old_Id, Fully_Conformant, False, Conformant);
2403 if not Conformant then
2405 -- The stub was taken to be a new declaration. Indicate
2406 -- that it lacks a body.
2408 Set_Has_Completion (Old_Id, False);
2414 Set_Has_Completion (Body_Id);
2415 Check_Eliminated (Body_Id);
2417 if Nkind (N) = N_Subprogram_Body_Stub then
2420 elsif Present (Spec_Id)
2421 and then Expander_Active
2423 (Has_Pragma_Inline_Always (Spec_Id)
2424 or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining))
2426 Build_Body_To_Inline (N, Spec_Id);
2429 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
2430 -- if its specification we have to install the private withed units.
2431 -- This holds for child units as well.
2433 if Is_Compilation_Unit (Body_Id)
2434 or else Nkind (Parent (N)) = N_Compilation_Unit
2436 Install_Private_With_Clauses (Body_Id);
2439 Check_Anonymous_Return;
2441 -- Set the Protected_Formal field of each extra formal of the protected
2442 -- subprogram to reference the corresponding extra formal of the
2443 -- subprogram that implements it. For regular formals this occurs when
2444 -- the protected subprogram's declaration is expanded, but the extra
2445 -- formals don't get created until the subprogram is frozen. We need to
2446 -- do this before analyzing the protected subprogram's body so that any
2447 -- references to the original subprogram's extra formals will be changed
2448 -- refer to the implementing subprogram's formals (see Expand_Formal).
2450 if Present (Spec_Id)
2451 and then Is_Protected_Type (Scope (Spec_Id))
2452 and then Present (Protected_Body_Subprogram (Spec_Id))
2455 Impl_Subp : constant Entity_Id :=
2456 Protected_Body_Subprogram (Spec_Id);
2457 Prot_Ext_Formal : Entity_Id := Extra_Formals (Spec_Id);
2458 Impl_Ext_Formal : Entity_Id := Extra_Formals (Impl_Subp);
2460 while Present (Prot_Ext_Formal) loop
2461 pragma Assert (Present (Impl_Ext_Formal));
2462 Set_Protected_Formal (Prot_Ext_Formal, Impl_Ext_Formal);
2463 Next_Formal_With_Extras (Prot_Ext_Formal);
2464 Next_Formal_With_Extras (Impl_Ext_Formal);
2469 -- Now we can go on to analyze the body
2471 HSS := Handled_Statement_Sequence (N);
2472 Set_Actual_Subtypes (N, Current_Scope);
2474 -- Deal with preconditions and postconditions
2476 Process_PPCs (N, Spec_Id, Body_Id);
2478 -- Add a declaration for the Protection object, renaming declarations
2479 -- for discriminals and privals and finally a declaration for the entry
2480 -- family index (if applicable). This form of early expansion is done
2481 -- when the Expander is active because Install_Private_Data_Declarations
2482 -- references entities which were created during regular expansion.
2485 and then Comes_From_Source (N)
2486 and then Present (Prot_Typ)
2487 and then Present (Spec_Id)
2488 and then not Is_Eliminated (Spec_Id)
2490 Install_Private_Data_Declarations
2491 (Sloc (N), Spec_Id, Prot_Typ, N, Declarations (N));
2494 -- Analyze the declarations (this call will analyze the precondition
2495 -- Check pragmas we prepended to the list, as well as the declaration
2496 -- of the _Postconditions procedure).
2498 Analyze_Declarations (Declarations (N));
2500 -- Check completion, and analyze the statements
2503 Inspect_Deferred_Constant_Completion (Declarations (N));
2506 -- Deal with end of scope processing for the body
2508 Process_End_Label (HSS, 't', Current_Scope);
2510 Check_Subprogram_Order (N);
2511 Set_Analyzed (Body_Id);
2513 -- If we have a separate spec, then the analysis of the declarations
2514 -- caused the entities in the body to be chained to the spec id, but
2515 -- we want them chained to the body id. Only the formal parameters
2516 -- end up chained to the spec id in this case.
2518 if Present (Spec_Id) then
2520 -- We must conform to the categorization of our spec
2522 Validate_Categorization_Dependency (N, Spec_Id);
2524 -- And if this is a child unit, the parent units must conform
2526 if Is_Child_Unit (Spec_Id) then
2527 Validate_Categorization_Dependency
2528 (Unit_Declaration_Node (Spec_Id), Spec_Id);
2531 -- Here is where we move entities from the spec to the body
2533 -- Case where there are entities that stay with the spec
2535 if Present (Last_Real_Spec_Entity) then
2537 -- No body entities (happens when the only real spec entities
2538 -- come from precondition and postcondition pragmas)
2540 if No (Last_Entity (Body_Id)) then
2542 (Body_Id, Next_Entity (Last_Real_Spec_Entity));
2544 -- Body entities present (formals), so chain stuff past them
2548 (Last_Entity (Body_Id), Next_Entity (Last_Real_Spec_Entity));
2551 Set_Next_Entity (Last_Real_Spec_Entity, Empty);
2552 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2553 Set_Last_Entity (Spec_Id, Last_Real_Spec_Entity);
2555 -- Case where there are no spec entities, in this case there can
2556 -- be no body entities either, so just move everything.
2559 pragma Assert (No (Last_Entity (Body_Id)));
2560 Set_First_Entity (Body_Id, First_Entity (Spec_Id));
2561 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2562 Set_First_Entity (Spec_Id, Empty);
2563 Set_Last_Entity (Spec_Id, Empty);
2567 Check_Missing_Return;
2569 -- Now we are going to check for variables that are never modified in
2570 -- the body of the procedure. But first we deal with a special case
2571 -- where we want to modify this check. If the body of the subprogram
2572 -- starts with a raise statement or its equivalent, or if the body
2573 -- consists entirely of a null statement, then it is pretty obvious
2574 -- that it is OK to not reference the parameters. For example, this
2575 -- might be the following common idiom for a stubbed function:
2576 -- statement of the procedure raises an exception. In particular this
2577 -- deals with the common idiom of a stubbed function, which might
2578 -- appear as something like
2580 -- function F (A : Integer) return Some_Type;
2583 -- raise Program_Error;
2587 -- Here the purpose of X is simply to satisfy the annoying requirement
2588 -- in Ada that there be at least one return, and we certainly do not
2589 -- want to go posting warnings on X that it is not initialized! On
2590 -- the other hand, if X is entirely unreferenced that should still
2593 -- What we do is to detect these cases, and if we find them, flag the
2594 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
2595 -- suppress unwanted warnings. For the case of the function stub above
2596 -- we have a special test to set X as apparently assigned to suppress
2603 -- Skip initial labels (for one thing this occurs when we are in
2604 -- front end ZCX mode, but in any case it is irrelevant), and also
2605 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
2607 Stm := First (Statements (HSS));
2608 while Nkind (Stm) = N_Label
2609 or else Nkind (Stm) in N_Push_xxx_Label
2614 -- Do the test on the original statement before expansion
2617 Ostm : constant Node_Id := Original_Node (Stm);
2620 -- If explicit raise statement, turn on flag
2622 if Nkind (Ostm) = N_Raise_Statement then
2623 Set_Trivial_Subprogram (Stm);
2625 -- If null statement, and no following statements, turn on flag
2627 elsif Nkind (Stm) = N_Null_Statement
2628 and then Comes_From_Source (Stm)
2629 and then No (Next (Stm))
2631 Set_Trivial_Subprogram (Stm);
2633 -- Check for explicit call cases which likely raise an exception
2635 elsif Nkind (Ostm) = N_Procedure_Call_Statement then
2636 if Is_Entity_Name (Name (Ostm)) then
2638 Ent : constant Entity_Id := Entity (Name (Ostm));
2641 -- If the procedure is marked No_Return, then likely it
2642 -- raises an exception, but in any case it is not coming
2643 -- back here, so turn on the flag.
2645 if Ekind (Ent) = E_Procedure
2646 and then No_Return (Ent)
2648 Set_Trivial_Subprogram (Stm);
2656 -- Check for variables that are never modified
2662 -- If there is a separate spec, then transfer Never_Set_In_Source
2663 -- flags from out parameters to the corresponding entities in the
2664 -- body. The reason we do that is we want to post error flags on
2665 -- the body entities, not the spec entities.
2667 if Present (Spec_Id) then
2668 E1 := First_Entity (Spec_Id);
2669 while Present (E1) loop
2670 if Ekind (E1) = E_Out_Parameter then
2671 E2 := First_Entity (Body_Id);
2672 while Present (E2) loop
2673 exit when Chars (E1) = Chars (E2);
2677 if Present (E2) then
2678 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
2686 -- Check references in body unless it was deleted. Note that the
2687 -- check of Body_Deleted here is not just for efficiency, it is
2688 -- necessary to avoid junk warnings on formal parameters.
2690 if not Body_Deleted then
2691 Check_References (Body_Id);
2694 end Analyze_Subprogram_Body_Helper;
2696 ------------------------------------
2697 -- Analyze_Subprogram_Declaration --
2698 ------------------------------------
2700 procedure Analyze_Subprogram_Declaration (N : Node_Id) is
2701 Loc : constant Source_Ptr := Sloc (N);
2702 Scop : constant Entity_Id := Current_Scope;
2703 Designator : Entity_Id;
2705 Null_Body : Node_Id := Empty;
2707 -- Start of processing for Analyze_Subprogram_Declaration
2710 -- For a null procedure, capture the profile before analysis, for
2711 -- expansion at the freeze point and at each point of call. The body
2712 -- will only be used if the procedure has preconditions. In that case
2713 -- the body is analyzed at the freeze point.
2715 if Nkind (Specification (N)) = N_Procedure_Specification
2716 and then Null_Present (Specification (N))
2717 and then Expander_Active
2720 Make_Subprogram_Body (Loc,
2722 New_Copy_Tree (Specification (N)),
2725 Handled_Statement_Sequence =>
2726 Make_Handled_Sequence_Of_Statements (Loc,
2727 Statements => New_List (Make_Null_Statement (Loc))));
2729 -- Create new entities for body and formals
2731 Set_Defining_Unit_Name (Specification (Null_Body),
2732 Make_Defining_Identifier (Loc, Chars (Defining_Entity (N))));
2733 Set_Corresponding_Body (N, Defining_Entity (Null_Body));
2735 Form := First (Parameter_Specifications (Specification (Null_Body)));
2736 while Present (Form) loop
2737 Set_Defining_Identifier (Form,
2738 Make_Defining_Identifier (Loc,
2739 Chars (Defining_Identifier (Form))));
2741 -- Resolve the types of the formals now, because the freeze point
2742 -- may appear in a different context, e.g. an instantiation.
2744 if Nkind (Parameter_Type (Form)) /= N_Access_Definition then
2745 Find_Type (Parameter_Type (Form));
2748 No (Access_To_Subprogram_Definition (Parameter_Type (Form)))
2750 Find_Type (Subtype_Mark (Parameter_Type (Form)));
2754 -- the case of a null procedure with a formal that is an
2755 -- access_to_subprogram type, and that is used as an actual
2756 -- in an instantiation is left to the enthusiastic reader.
2764 if Is_Protected_Type (Current_Scope) then
2765 Error_Msg_N ("protected operation cannot be a null procedure", N);
2769 Designator := Analyze_Subprogram_Specification (Specification (N));
2770 Generate_Definition (Designator);
2772 if Debug_Flag_C then
2773 Write_Str ("==> subprogram spec ");
2774 Write_Name (Chars (Designator));
2775 Write_Str (" from ");
2776 Write_Location (Sloc (N));
2781 if Nkind (Specification (N)) = N_Procedure_Specification
2782 and then Null_Present (Specification (N))
2784 Set_Has_Completion (Designator);
2786 if Present (Null_Body) then
2787 Set_Corresponding_Body (N, Defining_Entity (Null_Body));
2788 Set_Body_To_Inline (N, Null_Body);
2789 Set_Is_Inlined (Designator);
2793 Validate_RCI_Subprogram_Declaration (N);
2794 New_Overloaded_Entity (Designator);
2795 Check_Delayed_Subprogram (Designator);
2797 -- If the type of the first formal of the current subprogram is a
2798 -- nongeneric tagged private type, mark the subprogram as being a
2799 -- private primitive. Ditto if this is a function with controlling
2800 -- result, and the return type is currently private. In both cases,
2801 -- the type of the controlling argument or result must be in the
2802 -- current scope for the operation to be primitive.
2804 if Has_Controlling_Result (Designator)
2805 and then Is_Private_Type (Etype (Designator))
2806 and then Scope (Etype (Designator)) = Current_Scope
2807 and then not Is_Generic_Actual_Type (Etype (Designator))
2809 Set_Is_Private_Primitive (Designator);
2811 elsif Present (First_Formal (Designator)) then
2813 Formal_Typ : constant Entity_Id :=
2814 Etype (First_Formal (Designator));
2816 Set_Is_Private_Primitive (Designator,
2817 Is_Tagged_Type (Formal_Typ)
2818 and then Scope (Formal_Typ) = Current_Scope
2819 and then Is_Private_Type (Formal_Typ)
2820 and then not Is_Generic_Actual_Type (Formal_Typ));
2824 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
2827 if Ada_Version >= Ada_2005
2828 and then Comes_From_Source (N)
2829 and then Is_Dispatching_Operation (Designator)
2836 if Has_Controlling_Result (Designator) then
2837 Etyp := Etype (Designator);
2840 E := First_Entity (Designator);
2842 and then Is_Formal (E)
2843 and then not Is_Controlling_Formal (E)
2851 if Is_Access_Type (Etyp) then
2852 Etyp := Directly_Designated_Type (Etyp);
2855 if Is_Interface (Etyp)
2856 and then not Is_Abstract_Subprogram (Designator)
2857 and then not (Ekind (Designator) = E_Procedure
2858 and then Null_Present (Specification (N)))
2860 Error_Msg_Name_1 := Chars (Defining_Entity (N));
2862 ("(Ada 2005) interface subprogram % must be abstract or null",
2868 -- What is the following code for, it used to be
2870 -- ??? Set_Suppress_Elaboration_Checks
2871 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
2873 -- The following seems equivalent, but a bit dubious
2875 if Elaboration_Checks_Suppressed (Designator) then
2876 Set_Kill_Elaboration_Checks (Designator);
2879 if Scop /= Standard_Standard
2880 and then not Is_Child_Unit (Designator)
2882 Set_Categorization_From_Scope (Designator, Scop);
2884 -- For a compilation unit, check for library-unit pragmas
2886 Push_Scope (Designator);
2887 Set_Categorization_From_Pragmas (N);
2888 Validate_Categorization_Dependency (N, Designator);
2892 -- For a compilation unit, set body required. This flag will only be
2893 -- reset if a valid Import or Interface pragma is processed later on.
2895 if Nkind (Parent (N)) = N_Compilation_Unit then
2896 Set_Body_Required (Parent (N), True);
2898 if Ada_Version >= Ada_2005
2899 and then Nkind (Specification (N)) = N_Procedure_Specification
2900 and then Null_Present (Specification (N))
2903 ("null procedure cannot be declared at library level", N);
2907 Generate_Reference_To_Formals (Designator);
2908 Check_Eliminated (Designator);
2910 if Debug_Flag_C then
2912 Write_Str ("<== subprogram spec ");
2913 Write_Name (Chars (Designator));
2914 Write_Str (" from ");
2915 Write_Location (Sloc (N));
2919 List_Inherited_Pre_Post_Aspects (Designator);
2920 Analyze_Aspect_Specifications (N, Designator, Aspect_Specifications (N));
2921 end Analyze_Subprogram_Declaration;
2923 --------------------------------------
2924 -- Analyze_Subprogram_Specification --
2925 --------------------------------------
2927 -- Reminder: N here really is a subprogram specification (not a subprogram
2928 -- declaration). This procedure is called to analyze the specification in
2929 -- both subprogram bodies and subprogram declarations (specs).
2931 function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is
2932 Designator : constant Entity_Id := Defining_Entity (N);
2933 Formals : constant List_Id := Parameter_Specifications (N);
2935 -- Start of processing for Analyze_Subprogram_Specification
2938 Generate_Definition (Designator);
2940 if Nkind (N) = N_Function_Specification then
2941 Set_Ekind (Designator, E_Function);
2942 Set_Mechanism (Designator, Default_Mechanism);
2945 Set_Ekind (Designator, E_Procedure);
2946 Set_Etype (Designator, Standard_Void_Type);
2949 -- Introduce new scope for analysis of the formals and the return type
2951 Set_Scope (Designator, Current_Scope);
2953 if Present (Formals) then
2954 Push_Scope (Designator);
2955 Process_Formals (Formals, N);
2957 -- Ada 2005 (AI-345): If this is an overriding operation of an
2958 -- inherited interface operation, and the controlling type is
2959 -- a synchronized type, replace the type with its corresponding
2960 -- record, to match the proper signature of an overriding operation.
2961 -- Same processing for an access parameter whose designated type is
2962 -- derived from a synchronized interface.
2964 if Ada_Version >= Ada_2005 then
2967 Formal_Typ : Entity_Id;
2968 Rec_Typ : Entity_Id;
2969 Desig_Typ : Entity_Id;
2972 Formal := First_Formal (Designator);
2973 while Present (Formal) loop
2974 Formal_Typ := Etype (Formal);
2976 if Is_Concurrent_Type (Formal_Typ)
2977 and then Present (Corresponding_Record_Type (Formal_Typ))
2979 Rec_Typ := Corresponding_Record_Type (Formal_Typ);
2981 if Present (Interfaces (Rec_Typ)) then
2982 Set_Etype (Formal, Rec_Typ);
2985 elsif Ekind (Formal_Typ) = E_Anonymous_Access_Type then
2986 Desig_Typ := Designated_Type (Formal_Typ);
2988 if Is_Concurrent_Type (Desig_Typ)
2989 and then Present (Corresponding_Record_Type (Desig_Typ))
2991 Rec_Typ := Corresponding_Record_Type (Desig_Typ);
2993 if Present (Interfaces (Rec_Typ)) then
2994 Set_Directly_Designated_Type (Formal_Typ, Rec_Typ);
2999 Next_Formal (Formal);
3006 -- The subprogram scope is pushed and popped around the processing of
3007 -- the return type for consistency with call above to Process_Formals
3008 -- (which itself can call Analyze_Return_Type), and to ensure that any
3009 -- itype created for the return type will be associated with the proper
3012 elsif Nkind (N) = N_Function_Specification then
3013 Push_Scope (Designator);
3015 Analyze_Return_Type (N);
3020 if Nkind (N) = N_Function_Specification then
3021 if Nkind (Designator) = N_Defining_Operator_Symbol then
3022 Valid_Operator_Definition (Designator);
3025 May_Need_Actuals (Designator);
3027 -- Ada 2005 (AI-251): If the return type is abstract, verify that
3028 -- the subprogram is abstract also. This does not apply to renaming
3029 -- declarations, where abstractness is inherited.
3031 -- In case of primitives associated with abstract interface types
3032 -- the check is applied later (see Analyze_Subprogram_Declaration).
3034 if not Nkind_In (Parent (N), N_Subprogram_Renaming_Declaration,
3035 N_Abstract_Subprogram_Declaration,
3036 N_Formal_Abstract_Subprogram_Declaration)
3038 if Is_Abstract_Type (Etype (Designator))
3039 and then not Is_Interface (Etype (Designator))
3042 ("function that returns abstract type must be abstract", N);
3044 -- Ada 2012 (AI-0073): extend this test to subprograms with an
3045 -- access result whose designated type is abstract.
3047 elsif Nkind (Result_Definition (N)) = N_Access_Definition
3049 not Is_Class_Wide_Type (Designated_Type (Etype (Designator)))
3050 and then Is_Abstract_Type (Designated_Type (Etype (Designator)))
3051 and then Ada_Version >= Ada_2012
3053 Error_Msg_N ("function whose access result designates "
3054 & "abstract type must be abstract", N);
3060 end Analyze_Subprogram_Specification;
3062 --------------------------
3063 -- Build_Body_To_Inline --
3064 --------------------------
3066 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is
3067 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
3068 Original_Body : Node_Id;
3069 Body_To_Analyze : Node_Id;
3070 Max_Size : constant := 10;
3071 Stat_Count : Integer := 0;
3073 function Has_Excluded_Declaration (Decls : List_Id) return Boolean;
3074 -- Check for declarations that make inlining not worthwhile
3076 function Has_Excluded_Statement (Stats : List_Id) return Boolean;
3077 -- Check for statements that make inlining not worthwhile: any tasking
3078 -- statement, nested at any level. Keep track of total number of
3079 -- elementary statements, as a measure of acceptable size.
3081 function Has_Pending_Instantiation return Boolean;
3082 -- If some enclosing body contains instantiations that appear before the
3083 -- corresponding generic body, the enclosing body has a freeze node so
3084 -- that it can be elaborated after the generic itself. This might
3085 -- conflict with subsequent inlinings, so that it is unsafe to try to
3086 -- inline in such a case.
3088 function Has_Single_Return return Boolean;
3089 -- In general we cannot inline functions that return unconstrained type.
3090 -- However, we can handle such functions if all return statements return
3091 -- a local variable that is the only declaration in the body of the
3092 -- function. In that case the call can be replaced by that local
3093 -- variable as is done for other inlined calls.
3095 procedure Remove_Pragmas;
3096 -- A pragma Unreferenced or pragma Unmodified that mentions a formal
3097 -- parameter has no meaning when the body is inlined and the formals
3098 -- are rewritten. Remove it from body to inline. The analysis of the
3099 -- non-inlined body will handle the pragma properly.
3101 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean;
3102 -- If the body of the subprogram includes a call that returns an
3103 -- unconstrained type, the secondary stack is involved, and it
3104 -- is not worth inlining.
3106 ------------------------------
3107 -- Has_Excluded_Declaration --
3108 ------------------------------
3110 function Has_Excluded_Declaration (Decls : List_Id) return Boolean is
3113 function Is_Unchecked_Conversion (D : Node_Id) return Boolean;
3114 -- Nested subprograms make a given body ineligible for inlining, but
3115 -- we make an exception for instantiations of unchecked conversion.
3116 -- The body has not been analyzed yet, so check the name, and verify
3117 -- that the visible entity with that name is the predefined unit.
3119 -----------------------------
3120 -- Is_Unchecked_Conversion --
3121 -----------------------------
3123 function Is_Unchecked_Conversion (D : Node_Id) return Boolean is
3124 Id : constant Node_Id := Name (D);
3128 if Nkind (Id) = N_Identifier
3129 and then Chars (Id) = Name_Unchecked_Conversion
3131 Conv := Current_Entity (Id);
3133 elsif Nkind_In (Id, N_Selected_Component, N_Expanded_Name)
3134 and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion
3136 Conv := Current_Entity (Selector_Name (Id));
3141 return Present (Conv)
3142 and then Is_Predefined_File_Name
3143 (Unit_File_Name (Get_Source_Unit (Conv)))
3144 and then Is_Intrinsic_Subprogram (Conv);
3145 end Is_Unchecked_Conversion;
3147 -- Start of processing for Has_Excluded_Declaration
3151 while Present (D) loop
3152 if (Nkind (D) = N_Function_Instantiation
3153 and then not Is_Unchecked_Conversion (D))
3154 or else Nkind_In (D, N_Protected_Type_Declaration,
3155 N_Package_Declaration,
3156 N_Package_Instantiation,
3158 N_Procedure_Instantiation,
3159 N_Task_Type_Declaration)
3162 ("cannot inline & (non-allowed declaration)?", D, Subp);
3170 end Has_Excluded_Declaration;
3172 ----------------------------
3173 -- Has_Excluded_Statement --
3174 ----------------------------
3176 function Has_Excluded_Statement (Stats : List_Id) return Boolean is
3182 while Present (S) loop
3183 Stat_Count := Stat_Count + 1;
3185 if Nkind_In (S, N_Abort_Statement,
3186 N_Asynchronous_Select,
3187 N_Conditional_Entry_Call,
3188 N_Delay_Relative_Statement,
3189 N_Delay_Until_Statement,
3194 ("cannot inline & (non-allowed statement)?", S, Subp);
3197 elsif Nkind (S) = N_Block_Statement then
3198 if Present (Declarations (S))
3199 and then Has_Excluded_Declaration (Declarations (S))
3203 elsif Present (Handled_Statement_Sequence (S))
3206 (Exception_Handlers (Handled_Statement_Sequence (S)))
3208 Has_Excluded_Statement
3209 (Statements (Handled_Statement_Sequence (S))))
3214 elsif Nkind (S) = N_Case_Statement then
3215 E := First (Alternatives (S));
3216 while Present (E) loop
3217 if Has_Excluded_Statement (Statements (E)) then
3224 elsif Nkind (S) = N_If_Statement then
3225 if Has_Excluded_Statement (Then_Statements (S)) then
3229 if Present (Elsif_Parts (S)) then
3230 E := First (Elsif_Parts (S));
3231 while Present (E) loop
3232 if Has_Excluded_Statement (Then_Statements (E)) then
3239 if Present (Else_Statements (S))
3240 and then Has_Excluded_Statement (Else_Statements (S))
3245 elsif Nkind (S) = N_Loop_Statement
3246 and then Has_Excluded_Statement (Statements (S))
3250 elsif Nkind (S) = N_Extended_Return_Statement then
3251 if Has_Excluded_Statement
3252 (Statements (Handled_Statement_Sequence (S)))
3254 (Exception_Handlers (Handled_Statement_Sequence (S)))
3264 end Has_Excluded_Statement;
3266 -------------------------------
3267 -- Has_Pending_Instantiation --
3268 -------------------------------
3270 function Has_Pending_Instantiation return Boolean is
3275 while Present (S) loop
3276 if Is_Compilation_Unit (S)
3277 or else Is_Child_Unit (S)
3281 elsif Ekind (S) = E_Package
3282 and then Has_Forward_Instantiation (S)
3291 end Has_Pending_Instantiation;
3293 ------------------------
3294 -- Has_Single_Return --
3295 ------------------------
3297 function Has_Single_Return return Boolean is
3298 Return_Statement : Node_Id := Empty;
3300 function Check_Return (N : Node_Id) return Traverse_Result;
3306 function Check_Return (N : Node_Id) return Traverse_Result is
3308 if Nkind (N) = N_Simple_Return_Statement then
3309 if Present (Expression (N))
3310 and then Is_Entity_Name (Expression (N))
3312 if No (Return_Statement) then
3313 Return_Statement := N;
3316 elsif Chars (Expression (N)) =
3317 Chars (Expression (Return_Statement))
3325 -- A return statement within an extended return is a noop
3328 elsif No (Expression (N))
3329 and then Nkind (Parent (Parent (N))) =
3330 N_Extended_Return_Statement
3335 -- Expression has wrong form
3340 -- We can only inline a build-in-place function if
3341 -- it has a single extended return.
3343 elsif Nkind (N) = N_Extended_Return_Statement then
3344 if No (Return_Statement) then
3345 Return_Statement := N;
3357 function Check_All_Returns is new Traverse_Func (Check_Return);
3359 -- Start of processing for Has_Single_Return
3362 if Check_All_Returns (N) /= OK then
3365 elsif Nkind (Return_Statement) = N_Extended_Return_Statement then
3369 return Present (Declarations (N))
3370 and then Present (First (Declarations (N)))
3371 and then Chars (Expression (Return_Statement)) =
3372 Chars (Defining_Identifier (First (Declarations (N))));
3374 end Has_Single_Return;
3376 --------------------
3377 -- Remove_Pragmas --
3378 --------------------
3380 procedure Remove_Pragmas is
3385 Decl := First (Declarations (Body_To_Analyze));
3386 while Present (Decl) loop
3389 if Nkind (Decl) = N_Pragma
3390 and then (Pragma_Name (Decl) = Name_Unreferenced
3392 Pragma_Name (Decl) = Name_Unmodified)
3401 --------------------------
3402 -- Uses_Secondary_Stack --
3403 --------------------------
3405 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is
3406 function Check_Call (N : Node_Id) return Traverse_Result;
3407 -- Look for function calls that return an unconstrained type
3413 function Check_Call (N : Node_Id) return Traverse_Result is
3415 if Nkind (N) = N_Function_Call
3416 and then Is_Entity_Name (Name (N))
3417 and then Is_Composite_Type (Etype (Entity (Name (N))))
3418 and then not Is_Constrained (Etype (Entity (Name (N))))
3421 ("cannot inline & (call returns unconstrained type)?",
3429 function Check_Calls is new Traverse_Func (Check_Call);
3432 return Check_Calls (Bod) = Abandon;
3433 end Uses_Secondary_Stack;
3435 -- Start of processing for Build_Body_To_Inline
3438 -- Return immediately if done already
3440 if Nkind (Decl) = N_Subprogram_Declaration
3441 and then Present (Body_To_Inline (Decl))
3445 -- Functions that return unconstrained composite types require
3446 -- secondary stack handling, and cannot currently be inlined, unless
3447 -- all return statements return a local variable that is the first
3448 -- local declaration in the body.
3450 elsif Ekind (Subp) = E_Function
3451 and then not Is_Scalar_Type (Etype (Subp))
3452 and then not Is_Access_Type (Etype (Subp))
3453 and then not Is_Constrained (Etype (Subp))
3455 if not Has_Single_Return then
3457 ("cannot inline & (unconstrained return type)?", N, Subp);
3461 -- Ditto for functions that return controlled types, where controlled
3462 -- actions interfere in complex ways with inlining.
3464 elsif Ekind (Subp) = E_Function
3465 and then Needs_Finalization (Etype (Subp))
3468 ("cannot inline & (controlled return type)?", N, Subp);
3472 if Present (Declarations (N))
3473 and then Has_Excluded_Declaration (Declarations (N))
3478 if Present (Handled_Statement_Sequence (N)) then
3479 if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then
3481 ("cannot inline& (exception handler)?",
3482 First (Exception_Handlers (Handled_Statement_Sequence (N))),
3486 Has_Excluded_Statement
3487 (Statements (Handled_Statement_Sequence (N)))
3493 -- We do not inline a subprogram that is too large, unless it is
3494 -- marked Inline_Always. This pragma does not suppress the other
3495 -- checks on inlining (forbidden declarations, handlers, etc).
3497 if Stat_Count > Max_Size
3498 and then not Has_Pragma_Inline_Always (Subp)
3500 Cannot_Inline ("cannot inline& (body too large)?", N, Subp);
3504 if Has_Pending_Instantiation then
3506 ("cannot inline& (forward instance within enclosing body)?",
3511 -- Within an instance, the body to inline must be treated as a nested
3512 -- generic, so that the proper global references are preserved.
3514 -- Note that we do not do this at the library level, because it is not
3515 -- needed, and furthermore this causes trouble if front end inlining
3516 -- is activated (-gnatN).
3518 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then
3519 Save_Env (Scope (Current_Scope), Scope (Current_Scope));
3520 Original_Body := Copy_Generic_Node (N, Empty, True);
3522 Original_Body := Copy_Separate_Tree (N);
3525 -- We need to capture references to the formals in order to substitute
3526 -- the actuals at the point of inlining, i.e. instantiation. To treat
3527 -- the formals as globals to the body to inline, we nest it within
3528 -- a dummy parameterless subprogram, declared within the real one.
3529 -- To avoid generating an internal name (which is never public, and
3530 -- which affects serial numbers of other generated names), we use
3531 -- an internal symbol that cannot conflict with user declarations.
3533 Set_Parameter_Specifications (Specification (Original_Body), No_List);
3534 Set_Defining_Unit_Name
3535 (Specification (Original_Body),
3536 Make_Defining_Identifier (Sloc (N), Name_uParent));
3537 Set_Corresponding_Spec (Original_Body, Empty);
3539 Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False);
3541 -- Set return type of function, which is also global and does not need
3544 if Ekind (Subp) = E_Function then
3545 Set_Result_Definition (Specification (Body_To_Analyze),
3546 New_Occurrence_Of (Etype (Subp), Sloc (N)));
3549 if No (Declarations (N)) then
3550 Set_Declarations (N, New_List (Body_To_Analyze));
3552 Append (Body_To_Analyze, Declarations (N));
3555 Expander_Mode_Save_And_Set (False);
3558 Analyze (Body_To_Analyze);
3559 Push_Scope (Defining_Entity (Body_To_Analyze));
3560 Save_Global_References (Original_Body);
3562 Remove (Body_To_Analyze);
3564 Expander_Mode_Restore;
3566 -- Restore environment if previously saved
3568 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then
3572 -- If secondary stk used there is no point in inlining. We have
3573 -- already issued the warning in this case, so nothing to do.
3575 if Uses_Secondary_Stack (Body_To_Analyze) then
3579 Set_Body_To_Inline (Decl, Original_Body);
3580 Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp));
3581 Set_Is_Inlined (Subp);
3582 end Build_Body_To_Inline;
3588 procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is
3590 -- Do not emit warning if this is a predefined unit which is not the
3591 -- main unit. With validity checks enabled, some predefined subprograms
3592 -- may contain nested subprograms and become ineligible for inlining.
3594 if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp)))
3595 and then not In_Extended_Main_Source_Unit (Subp)
3599 elsif Has_Pragma_Inline_Always (Subp) then
3601 -- Remove last character (question mark) to make this into an error,
3602 -- because the Inline_Always pragma cannot be obeyed.
3604 Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp);
3606 elsif Ineffective_Inline_Warnings then
3607 Error_Msg_NE (Msg, N, Subp);
3611 -----------------------
3612 -- Check_Conformance --
3613 -----------------------
3615 procedure Check_Conformance
3616 (New_Id : Entity_Id;
3618 Ctype : Conformance_Type;
3620 Conforms : out Boolean;
3621 Err_Loc : Node_Id := Empty;
3622 Get_Inst : Boolean := False;
3623 Skip_Controlling_Formals : Boolean := False)
3625 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id);
3626 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
3627 -- If Errmsg is True, then processing continues to post an error message
3628 -- for conformance error on given node. Two messages are output. The
3629 -- first message points to the previous declaration with a general "no
3630 -- conformance" message. The second is the detailed reason, supplied as
3631 -- Msg. The parameter N provide information for a possible & insertion
3632 -- in the message, and also provides the location for posting the
3633 -- message in the absence of a specified Err_Loc location.
3635 -----------------------
3636 -- Conformance_Error --
3637 -----------------------
3639 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is
3646 if No (Err_Loc) then
3652 Error_Msg_Sloc := Sloc (Old_Id);
3655 when Type_Conformant =>
3656 Error_Msg_N -- CODEFIX
3657 ("not type conformant with declaration#!", Enode);
3659 when Mode_Conformant =>
3660 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3662 ("not mode conformant with operation inherited#!",
3666 ("not mode conformant with declaration#!", Enode);
3669 when Subtype_Conformant =>
3670 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3672 ("not subtype conformant with operation inherited#!",
3676 ("not subtype conformant with declaration#!", Enode);
3679 when Fully_Conformant =>
3680 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3681 Error_Msg_N -- CODEFIX
3682 ("not fully conformant with operation inherited#!",
3685 Error_Msg_N -- CODEFIX
3686 ("not fully conformant with declaration#!", Enode);
3690 Error_Msg_NE (Msg, Enode, N);
3692 end Conformance_Error;
3696 Old_Type : constant Entity_Id := Etype (Old_Id);
3697 New_Type : constant Entity_Id := Etype (New_Id);
3698 Old_Formal : Entity_Id;
3699 New_Formal : Entity_Id;
3700 Access_Types_Match : Boolean;
3701 Old_Formal_Base : Entity_Id;
3702 New_Formal_Base : Entity_Id;
3704 -- Start of processing for Check_Conformance
3709 -- We need a special case for operators, since they don't appear
3712 if Ctype = Type_Conformant then
3713 if Ekind (New_Id) = E_Operator
3714 and then Operator_Matches_Spec (New_Id, Old_Id)
3720 -- If both are functions/operators, check return types conform
3722 if Old_Type /= Standard_Void_Type
3723 and then New_Type /= Standard_Void_Type
3726 -- If we are checking interface conformance we omit controlling
3727 -- arguments and result, because we are only checking the conformance
3728 -- of the remaining parameters.
3730 if Has_Controlling_Result (Old_Id)
3731 and then Has_Controlling_Result (New_Id)
3732 and then Skip_Controlling_Formals
3736 elsif not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then
3737 Conformance_Error ("\return type does not match!", New_Id);
3741 -- Ada 2005 (AI-231): In case of anonymous access types check the
3742 -- null-exclusion and access-to-constant attributes match.
3744 if Ada_Version >= Ada_2005
3745 and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type
3747 (Can_Never_Be_Null (Old_Type)
3748 /= Can_Never_Be_Null (New_Type)
3749 or else Is_Access_Constant (Etype (Old_Type))
3750 /= Is_Access_Constant (Etype (New_Type)))
3752 Conformance_Error ("\return type does not match!", New_Id);
3756 -- If either is a function/operator and the other isn't, error
3758 elsif Old_Type /= Standard_Void_Type
3759 or else New_Type /= Standard_Void_Type
3761 Conformance_Error ("\functions can only match functions!", New_Id);
3765 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
3766 -- If this is a renaming as body, refine error message to indicate that
3767 -- the conflict is with the original declaration. If the entity is not
3768 -- frozen, the conventions don't have to match, the one of the renamed
3769 -- entity is inherited.
3771 if Ctype >= Subtype_Conformant then
3772 if Convention (Old_Id) /= Convention (New_Id) then
3774 if not Is_Frozen (New_Id) then
3777 elsif Present (Err_Loc)
3778 and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration
3779 and then Present (Corresponding_Spec (Err_Loc))
3781 Error_Msg_Name_1 := Chars (New_Id);
3783 Name_Ada + Convention_Id'Pos (Convention (New_Id));
3784 Conformance_Error ("\prior declaration for% has convention %!");
3787 Conformance_Error ("\calling conventions do not match!");
3792 elsif Is_Formal_Subprogram (Old_Id)
3793 or else Is_Formal_Subprogram (New_Id)
3795 Conformance_Error ("\formal subprograms not allowed!");
3800 -- Deal with parameters
3802 -- Note: we use the entity information, rather than going directly
3803 -- to the specification in the tree. This is not only simpler, but
3804 -- absolutely necessary for some cases of conformance tests between
3805 -- operators, where the declaration tree simply does not exist!
3807 Old_Formal := First_Formal (Old_Id);
3808 New_Formal := First_Formal (New_Id);
3809 while Present (Old_Formal) and then Present (New_Formal) loop
3810 if Is_Controlling_Formal (Old_Formal)
3811 and then Is_Controlling_Formal (New_Formal)
3812 and then Skip_Controlling_Formals
3814 -- The controlling formals will have different types when
3815 -- comparing an interface operation with its match, but both
3816 -- or neither must be access parameters.
3818 if Is_Access_Type (Etype (Old_Formal))
3820 Is_Access_Type (Etype (New_Formal))
3822 goto Skip_Controlling_Formal;
3825 ("\access parameter does not match!", New_Formal);
3829 if Ctype = Fully_Conformant then
3831 -- Names must match. Error message is more accurate if we do
3832 -- this before checking that the types of the formals match.
3834 if Chars (Old_Formal) /= Chars (New_Formal) then
3835 Conformance_Error ("\name & does not match!", New_Formal);
3837 -- Set error posted flag on new formal as well to stop
3838 -- junk cascaded messages in some cases.
3840 Set_Error_Posted (New_Formal);
3844 -- Null exclusion must match
3846 if Null_Exclusion_Present (Parent (Old_Formal))
3848 Null_Exclusion_Present (Parent (New_Formal))
3850 -- Only give error if both come from source. This should be
3851 -- investigated some time, since it should not be needed ???
3853 if Comes_From_Source (Old_Formal)
3855 Comes_From_Source (New_Formal)
3858 ("\null exclusion for & does not match", New_Formal);
3860 -- Mark error posted on the new formal to avoid duplicated
3861 -- complaint about types not matching.
3863 Set_Error_Posted (New_Formal);
3868 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
3869 -- case occurs whenever a subprogram is being renamed and one of its
3870 -- parameters imposes a null exclusion. For example:
3872 -- type T is null record;
3873 -- type Acc_T is access T;
3874 -- subtype Acc_T_Sub is Acc_T;
3876 -- procedure P (Obj : not null Acc_T_Sub); -- itype
3877 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
3880 Old_Formal_Base := Etype (Old_Formal);
3881 New_Formal_Base := Etype (New_Formal);
3884 Old_Formal_Base := Get_Instance_Of (Old_Formal_Base);
3885 New_Formal_Base := Get_Instance_Of (New_Formal_Base);
3888 Access_Types_Match := Ada_Version >= Ada_2005
3890 -- Ensure that this rule is only applied when New_Id is a
3891 -- renaming of Old_Id.
3893 and then Nkind (Parent (Parent (New_Id))) =
3894 N_Subprogram_Renaming_Declaration
3895 and then Nkind (Name (Parent (Parent (New_Id)))) in N_Has_Entity
3896 and then Present (Entity (Name (Parent (Parent (New_Id)))))
3897 and then Entity (Name (Parent (Parent (New_Id)))) = Old_Id
3899 -- Now handle the allowed access-type case
3901 and then Is_Access_Type (Old_Formal_Base)
3902 and then Is_Access_Type (New_Formal_Base)
3904 -- The type kinds must match. The only exception occurs with
3905 -- multiple generics of the form:
3908 -- type F is private; type A is private;
3909 -- type F_Ptr is access F; type A_Ptr is access A;
3910 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
3911 -- package F_Pack is ... package A_Pack is
3912 -- package F_Inst is
3913 -- new F_Pack (A, A_Ptr, A_P);
3915 -- When checking for conformance between the parameters of A_P
3916 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
3917 -- because the compiler has transformed A_Ptr into a subtype of
3918 -- F_Ptr. We catch this case in the code below.
3920 and then (Ekind (Old_Formal_Base) = Ekind (New_Formal_Base)
3922 (Is_Generic_Type (Old_Formal_Base)
3923 and then Is_Generic_Type (New_Formal_Base)
3924 and then Is_Internal (New_Formal_Base)
3925 and then Etype (Etype (New_Formal_Base)) =
3927 and then Directly_Designated_Type (Old_Formal_Base) =
3928 Directly_Designated_Type (New_Formal_Base)
3929 and then ((Is_Itype (Old_Formal_Base)
3930 and then Can_Never_Be_Null (Old_Formal_Base))
3932 (Is_Itype (New_Formal_Base)
3933 and then Can_Never_Be_Null (New_Formal_Base)));
3935 -- Types must always match. In the visible part of an instance,
3936 -- usual overloading rules for dispatching operations apply, and
3937 -- we check base types (not the actual subtypes).
3939 if In_Instance_Visible_Part
3940 and then Is_Dispatching_Operation (New_Id)
3942 if not Conforming_Types
3943 (T1 => Base_Type (Etype (Old_Formal)),
3944 T2 => Base_Type (Etype (New_Formal)),
3946 Get_Inst => Get_Inst)
3947 and then not Access_Types_Match
3949 Conformance_Error ("\type of & does not match!", New_Formal);
3953 elsif not Conforming_Types
3954 (T1 => Old_Formal_Base,
3955 T2 => New_Formal_Base,
3957 Get_Inst => Get_Inst)
3958 and then not Access_Types_Match
3960 -- Don't give error message if old type is Any_Type. This test
3961 -- avoids some cascaded errors, e.g. in case of a bad spec.
3963 if Errmsg and then Old_Formal_Base = Any_Type then
3966 Conformance_Error ("\type of & does not match!", New_Formal);
3972 -- For mode conformance, mode must match
3974 if Ctype >= Mode_Conformant then
3975 if Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal) then
3976 Conformance_Error ("\mode of & does not match!", New_Formal);
3979 -- Part of mode conformance for access types is having the same
3980 -- constant modifier.
3982 elsif Access_Types_Match
3983 and then Is_Access_Constant (Old_Formal_Base) /=
3984 Is_Access_Constant (New_Formal_Base)
3987 ("\constant modifier does not match!", New_Formal);
3992 if Ctype >= Subtype_Conformant then
3994 -- Ada 2005 (AI-231): In case of anonymous access types check
3995 -- the null-exclusion and access-to-constant attributes must
3998 if Ada_Version >= Ada_2005
3999 and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type
4000 and then Ekind (Etype (New_Formal)) = E_Anonymous_Access_Type
4002 (Can_Never_Be_Null (Old_Formal) /=
4003 Can_Never_Be_Null (New_Formal)
4005 Is_Access_Constant (Etype (Old_Formal)) /=
4006 Is_Access_Constant (Etype (New_Formal)))
4008 -- Do not complain if error already posted on New_Formal. This
4009 -- avoids some redundant error messages.
4011 and then not Error_Posted (New_Formal)
4013 -- It is allowed to omit the null-exclusion in case of stream
4014 -- attribute subprograms. We recognize stream subprograms
4015 -- through their TSS-generated suffix.
4018 TSS_Name : constant TSS_Name_Type := Get_TSS_Name (New_Id);
4020 if TSS_Name /= TSS_Stream_Read
4021 and then TSS_Name /= TSS_Stream_Write
4022 and then TSS_Name /= TSS_Stream_Input
4023 and then TSS_Name /= TSS_Stream_Output
4026 ("\type of & does not match!", New_Formal);
4033 -- Full conformance checks
4035 if Ctype = Fully_Conformant then
4037 -- We have checked already that names match
4039 if Parameter_Mode (Old_Formal) = E_In_Parameter then
4041 -- Check default expressions for in parameters
4044 NewD : constant Boolean :=
4045 Present (Default_Value (New_Formal));
4046 OldD : constant Boolean :=
4047 Present (Default_Value (Old_Formal));
4049 if NewD or OldD then
4051 -- The old default value has been analyzed because the
4052 -- current full declaration will have frozen everything
4053 -- before. The new default value has not been analyzed,
4054 -- so analyze it now before we check for conformance.
4057 Push_Scope (New_Id);
4058 Preanalyze_Spec_Expression
4059 (Default_Value (New_Formal), Etype (New_Formal));
4063 if not (NewD and OldD)
4064 or else not Fully_Conformant_Expressions
4065 (Default_Value (Old_Formal),
4066 Default_Value (New_Formal))
4069 ("\default expression for & does not match!",
4078 -- A couple of special checks for Ada 83 mode. These checks are
4079 -- skipped if either entity is an operator in package Standard,
4080 -- or if either old or new instance is not from the source program.
4082 if Ada_Version = Ada_83
4083 and then Sloc (Old_Id) > Standard_Location
4084 and then Sloc (New_Id) > Standard_Location
4085 and then Comes_From_Source (Old_Id)
4086 and then Comes_From_Source (New_Id)
4089 Old_Param : constant Node_Id := Declaration_Node (Old_Formal);
4090 New_Param : constant Node_Id := Declaration_Node (New_Formal);
4093 -- Explicit IN must be present or absent in both cases. This
4094 -- test is required only in the full conformance case.
4096 if In_Present (Old_Param) /= In_Present (New_Param)
4097 and then Ctype = Fully_Conformant
4100 ("\(Ada 83) IN must appear in both declarations",
4105 -- Grouping (use of comma in param lists) must be the same
4106 -- This is where we catch a misconformance like:
4109 -- A : Integer; B : Integer
4111 -- which are represented identically in the tree except
4112 -- for the setting of the flags More_Ids and Prev_Ids.
4114 if More_Ids (Old_Param) /= More_Ids (New_Param)
4115 or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param)
4118 ("\grouping of & does not match!", New_Formal);
4124 -- This label is required when skipping controlling formals
4126 <<Skip_Controlling_Formal>>
4128 Next_Formal (Old_Formal);
4129 Next_Formal (New_Formal);
4132 if Present (Old_Formal) then
4133 Conformance_Error ("\too few parameters!");
4136 elsif Present (New_Formal) then
4137 Conformance_Error ("\too many parameters!", New_Formal);
4140 end Check_Conformance;
4142 -----------------------
4143 -- Check_Conventions --
4144 -----------------------
4146 procedure Check_Conventions (Typ : Entity_Id) is
4147 Ifaces_List : Elist_Id;
4149 procedure Check_Convention (Op : Entity_Id);
4150 -- Verify that the convention of inherited dispatching operation Op is
4151 -- consistent among all subprograms it overrides. In order to minimize
4152 -- the search, Search_From is utilized to designate a specific point in
4153 -- the list rather than iterating over the whole list once more.
4155 ----------------------
4156 -- Check_Convention --
4157 ----------------------
4159 procedure Check_Convention (Op : Entity_Id) is
4160 Iface_Elmt : Elmt_Id;
4161 Iface_Prim_Elmt : Elmt_Id;
4162 Iface_Prim : Entity_Id;
4165 Iface_Elmt := First_Elmt (Ifaces_List);
4166 while Present (Iface_Elmt) loop
4168 First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
4169 while Present (Iface_Prim_Elmt) loop
4170 Iface_Prim := Node (Iface_Prim_Elmt);
4172 if Is_Interface_Conformant (Typ, Iface_Prim, Op)
4173 and then Convention (Iface_Prim) /= Convention (Op)
4176 ("inconsistent conventions in primitive operations", Typ);
4178 Error_Msg_Name_1 := Chars (Op);
4179 Error_Msg_Name_2 := Get_Convention_Name (Convention (Op));
4180 Error_Msg_Sloc := Sloc (Op);
4182 if Comes_From_Source (Op) or else No (Alias (Op)) then
4183 if not Is_Overriding_Operation (Op) then
4184 Error_Msg_N ("\\primitive % defined #", Typ);
4187 ("\\overriding operation % with " &
4188 "convention % defined #", Typ);
4191 else pragma Assert (Present (Alias (Op)));
4192 Error_Msg_Sloc := Sloc (Alias (Op));
4194 ("\\inherited operation % with " &
4195 "convention % defined #", Typ);
4198 Error_Msg_Name_1 := Chars (Op);
4200 Get_Convention_Name (Convention (Iface_Prim));
4201 Error_Msg_Sloc := Sloc (Iface_Prim);
4203 ("\\overridden operation % with " &
4204 "convention % defined #", Typ);
4206 -- Avoid cascading errors
4211 Next_Elmt (Iface_Prim_Elmt);
4214 Next_Elmt (Iface_Elmt);
4216 end Check_Convention;
4220 Prim_Op : Entity_Id;
4221 Prim_Op_Elmt : Elmt_Id;
4223 -- Start of processing for Check_Conventions
4226 if not Has_Interfaces (Typ) then
4230 Collect_Interfaces (Typ, Ifaces_List);
4232 -- The algorithm checks every overriding dispatching operation against
4233 -- all the corresponding overridden dispatching operations, detecting
4234 -- differences in conventions.
4236 Prim_Op_Elmt := First_Elmt (Primitive_Operations (Typ));
4237 while Present (Prim_Op_Elmt) loop
4238 Prim_Op := Node (Prim_Op_Elmt);
4240 -- A small optimization: skip the predefined dispatching operations
4241 -- since they always have the same convention.
4243 if not Is_Predefined_Dispatching_Operation (Prim_Op) then
4244 Check_Convention (Prim_Op);
4247 Next_Elmt (Prim_Op_Elmt);
4249 end Check_Conventions;
4251 ------------------------------
4252 -- Check_Delayed_Subprogram --
4253 ------------------------------
4255 procedure Check_Delayed_Subprogram (Designator : Entity_Id) is
4258 procedure Possible_Freeze (T : Entity_Id);
4259 -- T is the type of either a formal parameter or of the return type.
4260 -- If T is not yet frozen and needs a delayed freeze, then the
4261 -- subprogram itself must be delayed. If T is the limited view of an
4262 -- incomplete type the subprogram must be frozen as well, because
4263 -- T may depend on local types that have not been frozen yet.
4265 ---------------------
4266 -- Possible_Freeze --
4267 ---------------------
4269 procedure Possible_Freeze (T : Entity_Id) is
4271 if Has_Delayed_Freeze (T) and then not Is_Frozen (T) then
4272 Set_Has_Delayed_Freeze (Designator);
4274 elsif Is_Access_Type (T)
4275 and then Has_Delayed_Freeze (Designated_Type (T))
4276 and then not Is_Frozen (Designated_Type (T))
4278 Set_Has_Delayed_Freeze (Designator);
4280 elsif Ekind (T) = E_Incomplete_Type and then From_With_Type (T) then
4281 Set_Has_Delayed_Freeze (Designator);
4284 end Possible_Freeze;
4286 -- Start of processing for Check_Delayed_Subprogram
4289 -- All subprograms, including abstract subprograms, may need a freeze
4290 -- node if some formal type or the return type needs one.
4292 Possible_Freeze (Etype (Designator));
4293 Possible_Freeze (Base_Type (Etype (Designator))); -- needed ???
4295 -- Need delayed freeze if any of the formal types themselves need
4296 -- a delayed freeze and are not yet frozen.
4298 F := First_Formal (Designator);
4299 while Present (F) loop
4300 Possible_Freeze (Etype (F));
4301 Possible_Freeze (Base_Type (Etype (F))); -- needed ???
4305 -- Mark functions that return by reference. Note that it cannot be
4306 -- done for delayed_freeze subprograms because the underlying
4307 -- returned type may not be known yet (for private types)
4309 if not Has_Delayed_Freeze (Designator)
4310 and then Expander_Active
4313 Typ : constant Entity_Id := Etype (Designator);
4314 Utyp : constant Entity_Id := Underlying_Type (Typ);
4317 if Is_Immutably_Limited_Type (Typ) then
4318 Set_Returns_By_Ref (Designator);
4320 elsif Present (Utyp) and then CW_Or_Has_Controlled_Part (Utyp) then
4321 Set_Returns_By_Ref (Designator);
4325 end Check_Delayed_Subprogram;
4327 ------------------------------------
4328 -- Check_Discriminant_Conformance --
4329 ------------------------------------
4331 procedure Check_Discriminant_Conformance
4336 Old_Discr : Entity_Id := First_Discriminant (Prev);
4337 New_Discr : Node_Id := First (Discriminant_Specifications (N));
4338 New_Discr_Id : Entity_Id;
4339 New_Discr_Type : Entity_Id;
4341 procedure Conformance_Error (Msg : String; N : Node_Id);
4342 -- Post error message for conformance error on given node. Two messages
4343 -- are output. The first points to the previous declaration with a
4344 -- general "no conformance" message. The second is the detailed reason,
4345 -- supplied as Msg. The parameter N provide information for a possible
4346 -- & insertion in the message.
4348 -----------------------
4349 -- Conformance_Error --
4350 -----------------------
4352 procedure Conformance_Error (Msg : String; N : Node_Id) is
4354 Error_Msg_Sloc := Sloc (Prev_Loc);
4355 Error_Msg_N -- CODEFIX
4356 ("not fully conformant with declaration#!", N);
4357 Error_Msg_NE (Msg, N, N);
4358 end Conformance_Error;
4360 -- Start of processing for Check_Discriminant_Conformance
4363 while Present (Old_Discr) and then Present (New_Discr) loop
4365 New_Discr_Id := Defining_Identifier (New_Discr);
4367 -- The subtype mark of the discriminant on the full type has not
4368 -- been analyzed so we do it here. For an access discriminant a new
4371 if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then
4373 Access_Definition (N, Discriminant_Type (New_Discr));
4376 Analyze (Discriminant_Type (New_Discr));
4377 New_Discr_Type := Etype (Discriminant_Type (New_Discr));
4379 -- Ada 2005: if the discriminant definition carries a null
4380 -- exclusion, create an itype to check properly for consistency
4381 -- with partial declaration.
4383 if Is_Access_Type (New_Discr_Type)
4384 and then Null_Exclusion_Present (New_Discr)
4387 Create_Null_Excluding_Itype
4388 (T => New_Discr_Type,
4389 Related_Nod => New_Discr,
4390 Scope_Id => Current_Scope);
4394 if not Conforming_Types
4395 (Etype (Old_Discr), New_Discr_Type, Fully_Conformant)
4397 Conformance_Error ("type of & does not match!", New_Discr_Id);
4400 -- Treat the new discriminant as an occurrence of the old one,
4401 -- for navigation purposes, and fill in some semantic
4402 -- information, for completeness.
4404 Generate_Reference (Old_Discr, New_Discr_Id, 'r');
4405 Set_Etype (New_Discr_Id, Etype (Old_Discr));
4406 Set_Scope (New_Discr_Id, Scope (Old_Discr));
4411 if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then
4412 Conformance_Error ("name & does not match!", New_Discr_Id);
4416 -- Default expressions must match
4419 NewD : constant Boolean :=
4420 Present (Expression (New_Discr));
4421 OldD : constant Boolean :=
4422 Present (Expression (Parent (Old_Discr)));
4425 if NewD or OldD then
4427 -- The old default value has been analyzed and expanded,
4428 -- because the current full declaration will have frozen
4429 -- everything before. The new default values have not been
4430 -- expanded, so expand now to check conformance.
4433 Preanalyze_Spec_Expression
4434 (Expression (New_Discr), New_Discr_Type);
4437 if not (NewD and OldD)
4438 or else not Fully_Conformant_Expressions
4439 (Expression (Parent (Old_Discr)),
4440 Expression (New_Discr))
4444 ("default expression for & does not match!",
4451 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
4453 if Ada_Version = Ada_83 then
4455 Old_Disc : constant Node_Id := Declaration_Node (Old_Discr);
4458 -- Grouping (use of comma in param lists) must be the same
4459 -- This is where we catch a misconformance like:
4462 -- A : Integer; B : Integer
4464 -- which are represented identically in the tree except
4465 -- for the setting of the flags More_Ids and Prev_Ids.
4467 if More_Ids (Old_Disc) /= More_Ids (New_Discr)
4468 or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr)
4471 ("grouping of & does not match!", New_Discr_Id);
4477 Next_Discriminant (Old_Discr);
4481 if Present (Old_Discr) then
4482 Conformance_Error ("too few discriminants!", Defining_Identifier (N));
4485 elsif Present (New_Discr) then
4487 ("too many discriminants!", Defining_Identifier (New_Discr));
4490 end Check_Discriminant_Conformance;
4492 ----------------------------
4493 -- Check_Fully_Conformant --
4494 ----------------------------
4496 procedure Check_Fully_Conformant
4497 (New_Id : Entity_Id;
4499 Err_Loc : Node_Id := Empty)
4502 pragma Warnings (Off, Result);
4505 (New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc);
4506 end Check_Fully_Conformant;
4508 ---------------------------
4509 -- Check_Mode_Conformant --
4510 ---------------------------
4512 procedure Check_Mode_Conformant
4513 (New_Id : Entity_Id;
4515 Err_Loc : Node_Id := Empty;
4516 Get_Inst : Boolean := False)
4519 pragma Warnings (Off, Result);
4522 (New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst);
4523 end Check_Mode_Conformant;
4525 --------------------------------
4526 -- Check_Overriding_Indicator --
4527 --------------------------------
4529 procedure Check_Overriding_Indicator
4531 Overridden_Subp : Entity_Id;
4532 Is_Primitive : Boolean)
4538 -- No overriding indicator for literals
4540 if Ekind (Subp) = E_Enumeration_Literal then
4543 elsif Ekind (Subp) = E_Entry then
4544 Decl := Parent (Subp);
4546 -- No point in analyzing a malformed operator
4548 elsif Nkind (Subp) = N_Defining_Operator_Symbol
4549 and then Error_Posted (Subp)
4554 Decl := Unit_Declaration_Node (Subp);
4557 if Nkind_In (Decl, N_Subprogram_Body,
4558 N_Subprogram_Body_Stub,
4559 N_Subprogram_Declaration,
4560 N_Abstract_Subprogram_Declaration,
4561 N_Subprogram_Renaming_Declaration)
4563 Spec := Specification (Decl);
4565 elsif Nkind (Decl) = N_Entry_Declaration then
4572 -- The overriding operation is type conformant with the overridden one,
4573 -- but the names of the formals are not required to match. If the names
4574 -- appear permuted in the overriding operation, this is a possible
4575 -- source of confusion that is worth diagnosing. Controlling formals
4576 -- often carry names that reflect the type, and it is not worthwhile
4577 -- requiring that their names match.
4579 if Present (Overridden_Subp)
4580 and then Nkind (Subp) /= N_Defining_Operator_Symbol
4587 Form1 := First_Formal (Subp);
4588 Form2 := First_Formal (Overridden_Subp);
4590 -- If the overriding operation is a synchronized operation, skip
4591 -- the first parameter of the overridden operation, which is
4592 -- implicit in the new one. If the operation is declared in the
4593 -- body it is not primitive and all formals must match.
4595 if Is_Concurrent_Type (Scope (Subp))
4596 and then Is_Tagged_Type (Scope (Subp))
4597 and then not Has_Completion (Scope (Subp))
4599 Form2 := Next_Formal (Form2);
4602 if Present (Form1) then
4603 Form1 := Next_Formal (Form1);
4604 Form2 := Next_Formal (Form2);
4607 while Present (Form1) loop
4608 if not Is_Controlling_Formal (Form1)
4609 and then Present (Next_Formal (Form2))
4610 and then Chars (Form1) = Chars (Next_Formal (Form2))
4612 Error_Msg_Node_2 := Alias (Overridden_Subp);
4613 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
4615 ("& does not match corresponding formal of&#",
4620 Next_Formal (Form1);
4621 Next_Formal (Form2);
4626 -- If there is an overridden subprogram, then check that there is no
4627 -- "not overriding" indicator, and mark the subprogram as overriding.
4628 -- This is not done if the overridden subprogram is marked as hidden,
4629 -- which can occur for the case of inherited controlled operations
4630 -- (see Derive_Subprogram), unless the inherited subprogram's parent
4631 -- subprogram is not itself hidden. (Note: This condition could probably
4632 -- be simplified, leaving out the testing for the specific controlled
4633 -- cases, but it seems safer and clearer this way, and echoes similar
4634 -- special-case tests of this kind in other places.)
4636 if Present (Overridden_Subp)
4637 and then (not Is_Hidden (Overridden_Subp)
4639 ((Chars (Overridden_Subp) = Name_Initialize
4641 Chars (Overridden_Subp) = Name_Adjust
4643 Chars (Overridden_Subp) = Name_Finalize)
4644 and then Present (Alias (Overridden_Subp))
4645 and then not Is_Hidden (Alias (Overridden_Subp))))
4647 if Must_Not_Override (Spec) then
4648 Error_Msg_Sloc := Sloc (Overridden_Subp);
4650 if Ekind (Subp) = E_Entry then
4652 ("entry & overrides inherited operation #", Spec, Subp);
4655 ("subprogram & overrides inherited operation #", Spec, Subp);
4658 elsif Is_Subprogram (Subp) then
4659 Set_Is_Overriding_Operation (Subp);
4662 -- If primitive flag is set or this is a protected operation, then
4663 -- the operation is overriding at the point of its declaration, so
4664 -- warn if necessary. Otherwise it may have been declared before the
4665 -- operation it overrides and no check is required.
4668 and then not Must_Override (Spec)
4669 and then (Is_Primitive
4670 or else Ekind (Scope (Subp)) = E_Protected_Type)
4672 Style.Missing_Overriding (Decl, Subp);
4675 -- If Subp is an operator, it may override a predefined operation, if
4676 -- it is defined in the same scope as the type to which it applies.
4677 -- In that case Overridden_Subp is empty because of our implicit
4678 -- representation for predefined operators. We have to check whether the
4679 -- signature of Subp matches that of a predefined operator. Note that
4680 -- first argument provides the name of the operator, and the second
4681 -- argument the signature that may match that of a standard operation.
4682 -- If the indicator is overriding, then the operator must match a
4683 -- predefined signature, because we know already that there is no
4684 -- explicit overridden operation.
4686 elsif Nkind (Subp) = N_Defining_Operator_Symbol then
4688 Typ : constant Entity_Id :=
4689 Base_Type (Etype (First_Formal (Subp)));
4691 Can_Override : constant Boolean :=
4692 Operator_Matches_Spec (Subp, Subp)
4693 and then Scope (Subp) = Scope (Typ)
4694 and then not Is_Class_Wide_Type (Typ);
4697 if Must_Not_Override (Spec) then
4699 -- If this is not a primitive or a protected subprogram, then
4700 -- "not overriding" is illegal.
4703 and then Ekind (Scope (Subp)) /= E_Protected_Type
4706 ("overriding indicator only allowed "
4707 & "if subprogram is primitive", Subp);
4709 elsif Can_Override then
4711 ("subprogram& overrides predefined operator ", Spec, Subp);
4714 elsif Must_Override (Spec) then
4715 if Is_Overriding_Operation (Subp) then
4718 elsif not Can_Override then
4719 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
4722 elsif not Error_Posted (Subp)
4723 and then Style_Check
4724 and then Can_Override
4726 not Is_Predefined_File_Name
4727 (Unit_File_Name (Get_Source_Unit (Subp)))
4729 Set_Is_Overriding_Operation (Subp);
4731 -- If style checks are enabled, indicate that the indicator is
4732 -- missing. However, at the point of declaration, the type of
4733 -- which this is a primitive operation may be private, in which
4734 -- case the indicator would be premature.
4736 if Has_Private_Declaration (Etype (Subp))
4737 or else Has_Private_Declaration (Etype (First_Formal (Subp)))
4741 Style.Missing_Overriding (Decl, Subp);
4746 elsif Must_Override (Spec) then
4747 if Ekind (Subp) = E_Entry then
4748 Error_Msg_NE ("entry & is not overriding", Spec, Subp);
4750 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
4753 -- If the operation is marked "not overriding" and it's not primitive
4754 -- then an error is issued, unless this is an operation of a task or
4755 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
4756 -- has been specified have already been checked above.
4758 elsif Must_Not_Override (Spec)
4759 and then not Is_Primitive
4760 and then Ekind (Subp) /= E_Entry
4761 and then Ekind (Scope (Subp)) /= E_Protected_Type
4764 ("overriding indicator only allowed if subprogram is primitive",
4768 end Check_Overriding_Indicator;
4774 -- Note: this procedure needs to know far too much about how the expander
4775 -- messes with exceptions. The use of the flag Exception_Junk and the
4776 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
4777 -- works, but is not very clean. It would be better if the expansion
4778 -- routines would leave Original_Node working nicely, and we could use
4779 -- Original_Node here to ignore all the peculiar expander messing ???
4781 procedure Check_Returns
4785 Proc : Entity_Id := Empty)
4789 procedure Check_Statement_Sequence (L : List_Id);
4790 -- Internal recursive procedure to check a list of statements for proper
4791 -- termination by a return statement (or a transfer of control or a
4792 -- compound statement that is itself internally properly terminated).
4794 ------------------------------
4795 -- Check_Statement_Sequence --
4796 ------------------------------
4798 procedure Check_Statement_Sequence (L : List_Id) is
4803 Raise_Exception_Call : Boolean;
4804 -- Set True if statement sequence terminated by Raise_Exception call
4805 -- or a Reraise_Occurrence call.
4808 Raise_Exception_Call := False;
4810 -- Get last real statement
4812 Last_Stm := Last (L);
4814 -- Deal with digging out exception handler statement sequences that
4815 -- have been transformed by the local raise to goto optimization.
4816 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
4817 -- optimization has occurred, we are looking at something like:
4820 -- original stmts in block
4824 -- goto L1; | omitted if No_Exception_Propagation
4829 -- goto L3; -- skip handler when exception not raised
4831 -- <<L1>> -- target label for local exception
4845 -- and what we have to do is to dig out the estmts1 and estmts2
4846 -- sequences (which were the original sequences of statements in
4847 -- the exception handlers) and check them.
4849 if Nkind (Last_Stm) = N_Label
4850 and then Exception_Junk (Last_Stm)
4856 exit when Nkind (Stm) /= N_Block_Statement;
4857 exit when not Exception_Junk (Stm);
4860 exit when Nkind (Stm) /= N_Label;
4861 exit when not Exception_Junk (Stm);
4862 Check_Statement_Sequence
4863 (Statements (Handled_Statement_Sequence (Next (Stm))));
4868 exit when Nkind (Stm) /= N_Goto_Statement;
4869 exit when not Exception_Junk (Stm);
4873 -- Don't count pragmas
4875 while Nkind (Last_Stm) = N_Pragma
4877 -- Don't count call to SS_Release (can happen after Raise_Exception)
4880 (Nkind (Last_Stm) = N_Procedure_Call_Statement
4882 Nkind (Name (Last_Stm)) = N_Identifier
4884 Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release))
4886 -- Don't count exception junk
4889 (Nkind_In (Last_Stm, N_Goto_Statement,
4891 N_Object_Declaration)
4892 and then Exception_Junk (Last_Stm))
4893 or else Nkind (Last_Stm) in N_Push_xxx_Label
4894 or else Nkind (Last_Stm) in N_Pop_xxx_Label
4899 -- Here we have the "real" last statement
4901 Kind := Nkind (Last_Stm);
4903 -- Transfer of control, OK. Note that in the No_Return procedure
4904 -- case, we already diagnosed any explicit return statements, so
4905 -- we can treat them as OK in this context.
4907 if Is_Transfer (Last_Stm) then
4910 -- Check cases of explicit non-indirect procedure calls
4912 elsif Kind = N_Procedure_Call_Statement
4913 and then Is_Entity_Name (Name (Last_Stm))
4915 -- Check call to Raise_Exception procedure which is treated
4916 -- specially, as is a call to Reraise_Occurrence.
4918 -- We suppress the warning in these cases since it is likely that
4919 -- the programmer really does not expect to deal with the case
4920 -- of Null_Occurrence, and thus would find a warning about a
4921 -- missing return curious, and raising Program_Error does not
4922 -- seem such a bad behavior if this does occur.
4924 -- Note that in the Ada 2005 case for Raise_Exception, the actual
4925 -- behavior will be to raise Constraint_Error (see AI-329).
4927 if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception)
4929 Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence)
4931 Raise_Exception_Call := True;
4933 -- For Raise_Exception call, test first argument, if it is
4934 -- an attribute reference for a 'Identity call, then we know
4935 -- that the call cannot possibly return.
4938 Arg : constant Node_Id :=
4939 Original_Node (First_Actual (Last_Stm));
4941 if Nkind (Arg) = N_Attribute_Reference
4942 and then Attribute_Name (Arg) = Name_Identity
4949 -- If statement, need to look inside if there is an else and check
4950 -- each constituent statement sequence for proper termination.
4952 elsif Kind = N_If_Statement
4953 and then Present (Else_Statements (Last_Stm))
4955 Check_Statement_Sequence (Then_Statements (Last_Stm));
4956 Check_Statement_Sequence (Else_Statements (Last_Stm));
4958 if Present (Elsif_Parts (Last_Stm)) then
4960 Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm));
4963 while Present (Elsif_Part) loop
4964 Check_Statement_Sequence (Then_Statements (Elsif_Part));
4972 -- Case statement, check each case for proper termination
4974 elsif Kind = N_Case_Statement then
4978 Case_Alt := First_Non_Pragma (Alternatives (Last_Stm));
4979 while Present (Case_Alt) loop
4980 Check_Statement_Sequence (Statements (Case_Alt));
4981 Next_Non_Pragma (Case_Alt);
4987 -- Block statement, check its handled sequence of statements
4989 elsif Kind = N_Block_Statement then
4995 (Handled_Statement_Sequence (Last_Stm), Mode, Err1);
5004 -- Loop statement. If there is an iteration scheme, we can definitely
5005 -- fall out of the loop. Similarly if there is an exit statement, we
5006 -- can fall out. In either case we need a following return.
5008 elsif Kind = N_Loop_Statement then
5009 if Present (Iteration_Scheme (Last_Stm))
5010 or else Has_Exit (Entity (Identifier (Last_Stm)))
5014 -- A loop with no exit statement or iteration scheme is either
5015 -- an infinite loop, or it has some other exit (raise/return).
5016 -- In either case, no warning is required.
5022 -- Timed entry call, check entry call and delay alternatives
5024 -- Note: in expanded code, the timed entry call has been converted
5025 -- to a set of expanded statements on which the check will work
5026 -- correctly in any case.
5028 elsif Kind = N_Timed_Entry_Call then
5030 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
5031 DCA : constant Node_Id := Delay_Alternative (Last_Stm);
5034 -- If statement sequence of entry call alternative is missing,
5035 -- then we can definitely fall through, and we post the error
5036 -- message on the entry call alternative itself.
5038 if No (Statements (ECA)) then
5041 -- If statement sequence of delay alternative is missing, then
5042 -- we can definitely fall through, and we post the error
5043 -- message on the delay alternative itself.
5045 -- Note: if both ECA and DCA are missing the return, then we
5046 -- post only one message, should be enough to fix the bugs.
5047 -- If not we will get a message next time on the DCA when the
5050 elsif No (Statements (DCA)) then
5053 -- Else check both statement sequences
5056 Check_Statement_Sequence (Statements (ECA));
5057 Check_Statement_Sequence (Statements (DCA));
5062 -- Conditional entry call, check entry call and else part
5064 -- Note: in expanded code, the conditional entry call has been
5065 -- converted to a set of expanded statements on which the check
5066 -- will work correctly in any case.
5068 elsif Kind = N_Conditional_Entry_Call then
5070 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
5073 -- If statement sequence of entry call alternative is missing,
5074 -- then we can definitely fall through, and we post the error
5075 -- message on the entry call alternative itself.
5077 if No (Statements (ECA)) then
5080 -- Else check statement sequence and else part
5083 Check_Statement_Sequence (Statements (ECA));
5084 Check_Statement_Sequence (Else_Statements (Last_Stm));
5090 -- If we fall through, issue appropriate message
5093 if not Raise_Exception_Call then
5095 ("?RETURN statement missing following this statement!",
5098 ("\?Program_Error may be raised at run time!",
5102 -- Note: we set Err even though we have not issued a warning
5103 -- because we still have a case of a missing return. This is
5104 -- an extremely marginal case, probably will never be noticed
5105 -- but we might as well get it right.
5109 -- Otherwise we have the case of a procedure marked No_Return
5112 if not Raise_Exception_Call then
5114 ("?implied return after this statement " &
5115 "will raise Program_Error",
5118 ("\?procedure & is marked as No_Return!",
5123 RE : constant Node_Id :=
5124 Make_Raise_Program_Error (Sloc (Last_Stm),
5125 Reason => PE_Implicit_Return);
5127 Insert_After (Last_Stm, RE);
5131 end Check_Statement_Sequence;
5133 -- Start of processing for Check_Returns
5137 Check_Statement_Sequence (Statements (HSS));
5139 if Present (Exception_Handlers (HSS)) then
5140 Handler := First_Non_Pragma (Exception_Handlers (HSS));
5141 while Present (Handler) loop
5142 Check_Statement_Sequence (Statements (Handler));
5143 Next_Non_Pragma (Handler);
5148 ----------------------------
5149 -- Check_Subprogram_Order --
5150 ----------------------------
5152 procedure Check_Subprogram_Order (N : Node_Id) is
5154 function Subprogram_Name_Greater (S1, S2 : String) return Boolean;
5155 -- This is used to check if S1 > S2 in the sense required by this
5156 -- test, for example nameab < namec, but name2 < name10.
5158 -----------------------------
5159 -- Subprogram_Name_Greater --
5160 -----------------------------
5162 function Subprogram_Name_Greater (S1, S2 : String) return Boolean is
5167 -- Remove trailing numeric parts
5170 while S1 (L1) in '0' .. '9' loop
5175 while S2 (L2) in '0' .. '9' loop
5179 -- If non-numeric parts non-equal, that's decisive
5181 if S1 (S1'First .. L1) < S2 (S2'First .. L2) then
5184 elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then
5187 -- If non-numeric parts equal, compare suffixed numeric parts. Note
5188 -- that a missing suffix is treated as numeric zero in this test.
5192 while L1 < S1'Last loop
5194 N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0');
5198 while L2 < S2'Last loop
5200 N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0');
5205 end Subprogram_Name_Greater;
5207 -- Start of processing for Check_Subprogram_Order
5210 -- Check body in alpha order if this is option
5213 and then Style_Check_Order_Subprograms
5214 and then Nkind (N) = N_Subprogram_Body
5215 and then Comes_From_Source (N)
5216 and then In_Extended_Main_Source_Unit (N)
5220 renames Scope_Stack.Table
5221 (Scope_Stack.Last).Last_Subprogram_Name;
5223 Body_Id : constant Entity_Id :=
5224 Defining_Entity (Specification (N));
5227 Get_Decoded_Name_String (Chars (Body_Id));
5230 if Subprogram_Name_Greater
5231 (LSN.all, Name_Buffer (1 .. Name_Len))
5233 Style.Subprogram_Not_In_Alpha_Order (Body_Id);
5239 LSN := new String'(Name_Buffer (1 .. Name_Len));
5242 end Check_Subprogram_Order;
5244 ------------------------------
5245 -- Check_Subtype_Conformant --
5246 ------------------------------
5248 procedure Check_Subtype_Conformant
5249 (New_Id : Entity_Id;
5251 Err_Loc : Node_Id := Empty;
5252 Skip_Controlling_Formals : Boolean := False)
5255 pragma Warnings (Off, Result);
5258 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
5259 Skip_Controlling_Formals => Skip_Controlling_Formals);
5260 end Check_Subtype_Conformant;
5262 ---------------------------
5263 -- Check_Type_Conformant --
5264 ---------------------------
5266 procedure Check_Type_Conformant
5267 (New_Id : Entity_Id;
5269 Err_Loc : Node_Id := Empty)
5272 pragma Warnings (Off, Result);
5275 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
5276 end Check_Type_Conformant;
5278 ----------------------
5279 -- Conforming_Types --
5280 ----------------------
5282 function Conforming_Types
5285 Ctype : Conformance_Type;
5286 Get_Inst : Boolean := False) return Boolean
5288 Type_1 : Entity_Id := T1;
5289 Type_2 : Entity_Id := T2;
5290 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
5292 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
5293 -- If neither T1 nor T2 are generic actual types, or if they are in
5294 -- different scopes (e.g. parent and child instances), then verify that
5295 -- the base types are equal. Otherwise T1 and T2 must be on the same
5296 -- subtype chain. The whole purpose of this procedure is to prevent
5297 -- spurious ambiguities in an instantiation that may arise if two
5298 -- distinct generic types are instantiated with the same actual.
5300 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
5301 -- An access parameter can designate an incomplete type. If the
5302 -- incomplete type is the limited view of a type from a limited_
5303 -- with_clause, check whether the non-limited view is available. If
5304 -- it is a (non-limited) incomplete type, get the full view.
5306 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
5307 -- Returns True if and only if either T1 denotes a limited view of T2
5308 -- or T2 denotes a limited view of T1. This can arise when the limited
5309 -- with view of a type is used in a subprogram declaration and the
5310 -- subprogram body is in the scope of a regular with clause for the
5311 -- same unit. In such a case, the two type entities can be considered
5312 -- identical for purposes of conformance checking.
5314 ----------------------
5315 -- Base_Types_Match --
5316 ----------------------
5318 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
5323 elsif Base_Type (T1) = Base_Type (T2) then
5325 -- The following is too permissive. A more precise test should
5326 -- check that the generic actual is an ancestor subtype of the
5329 return not Is_Generic_Actual_Type (T1)
5330 or else not Is_Generic_Actual_Type (T2)
5331 or else Scope (T1) /= Scope (T2);
5336 end Base_Types_Match;
5338 --------------------------
5339 -- Find_Designated_Type --
5340 --------------------------
5342 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
5346 Desig := Directly_Designated_Type (T);
5348 if Ekind (Desig) = E_Incomplete_Type then
5350 -- If regular incomplete type, get full view if available
5352 if Present (Full_View (Desig)) then
5353 Desig := Full_View (Desig);
5355 -- If limited view of a type, get non-limited view if available,
5356 -- and check again for a regular incomplete type.
5358 elsif Present (Non_Limited_View (Desig)) then
5359 Desig := Get_Full_View (Non_Limited_View (Desig));
5364 end Find_Designated_Type;
5366 -------------------------------
5367 -- Matches_Limited_With_View --
5368 -------------------------------
5370 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
5372 -- In some cases a type imported through a limited_with clause, and
5373 -- its nonlimited view are both visible, for example in an anonymous
5374 -- access-to-class-wide type in a formal. Both entities designate the
5377 if From_With_Type (T1)
5378 and then T2 = Available_View (T1)
5382 elsif From_With_Type (T2)
5383 and then T1 = Available_View (T2)
5390 end Matches_Limited_With_View;
5392 -- Start of processing for Conforming_Types
5395 -- The context is an instance association for a formal
5396 -- access-to-subprogram type; the formal parameter types require
5397 -- mapping because they may denote other formal parameters of the
5401 Type_1 := Get_Instance_Of (T1);
5402 Type_2 := Get_Instance_Of (T2);
5405 -- If one of the types is a view of the other introduced by a limited
5406 -- with clause, treat these as conforming for all purposes.
5408 if Matches_Limited_With_View (T1, T2) then
5411 elsif Base_Types_Match (Type_1, Type_2) then
5412 return Ctype <= Mode_Conformant
5413 or else Subtypes_Statically_Match (Type_1, Type_2);
5415 elsif Is_Incomplete_Or_Private_Type (Type_1)
5416 and then Present (Full_View (Type_1))
5417 and then Base_Types_Match (Full_View (Type_1), Type_2)
5419 return Ctype <= Mode_Conformant
5420 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
5422 elsif Ekind (Type_2) = E_Incomplete_Type
5423 and then Present (Full_View (Type_2))
5424 and then Base_Types_Match (Type_1, Full_View (Type_2))
5426 return Ctype <= Mode_Conformant
5427 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
5429 elsif Is_Private_Type (Type_2)
5430 and then In_Instance
5431 and then Present (Full_View (Type_2))
5432 and then Base_Types_Match (Type_1, Full_View (Type_2))
5434 return Ctype <= Mode_Conformant
5435 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
5438 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
5439 -- treated recursively because they carry a signature.
5441 Are_Anonymous_Access_To_Subprogram_Types :=
5442 Ekind (Type_1) = Ekind (Type_2)
5444 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
5446 Ekind (Type_1) = E_Anonymous_Access_Protected_Subprogram_Type);
5448 -- Test anonymous access type case. For this case, static subtype
5449 -- matching is required for mode conformance (RM 6.3.1(15)). We check
5450 -- the base types because we may have built internal subtype entities
5451 -- to handle null-excluding types (see Process_Formals).
5453 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
5455 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
5456 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
5459 Desig_1 : Entity_Id;
5460 Desig_2 : Entity_Id;
5463 -- In Ada2005, access constant indicators must match for
5464 -- subtype conformance.
5466 if Ada_Version >= Ada_2005
5467 and then Ctype >= Subtype_Conformant
5469 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
5474 Desig_1 := Find_Designated_Type (Type_1);
5476 Desig_2 := Find_Designated_Type (Type_2);
5478 -- If the context is an instance association for a formal
5479 -- access-to-subprogram type; formal access parameter designated
5480 -- types require mapping because they may denote other formal
5481 -- parameters of the generic unit.
5484 Desig_1 := Get_Instance_Of (Desig_1);
5485 Desig_2 := Get_Instance_Of (Desig_2);
5488 -- It is possible for a Class_Wide_Type to be introduced for an
5489 -- incomplete type, in which case there is a separate class_ wide
5490 -- type for the full view. The types conform if their Etypes
5491 -- conform, i.e. one may be the full view of the other. This can
5492 -- only happen in the context of an access parameter, other uses
5493 -- of an incomplete Class_Wide_Type are illegal.
5495 if Is_Class_Wide_Type (Desig_1)
5496 and then Is_Class_Wide_Type (Desig_2)
5500 (Etype (Base_Type (Desig_1)),
5501 Etype (Base_Type (Desig_2)), Ctype);
5503 elsif Are_Anonymous_Access_To_Subprogram_Types then
5504 if Ada_Version < Ada_2005 then
5505 return Ctype = Type_Conformant
5507 Subtypes_Statically_Match (Desig_1, Desig_2);
5509 -- We must check the conformance of the signatures themselves
5513 Conformant : Boolean;
5516 (Desig_1, Desig_2, Ctype, False, Conformant);
5522 return Base_Type (Desig_1) = Base_Type (Desig_2)
5523 and then (Ctype = Type_Conformant
5525 Subtypes_Statically_Match (Desig_1, Desig_2));
5529 -- Otherwise definitely no match
5532 if ((Ekind (Type_1) = E_Anonymous_Access_Type
5533 and then Is_Access_Type (Type_2))
5534 or else (Ekind (Type_2) = E_Anonymous_Access_Type
5535 and then Is_Access_Type (Type_1)))
5538 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
5540 May_Hide_Profile := True;
5545 end Conforming_Types;
5547 --------------------------
5548 -- Create_Extra_Formals --
5549 --------------------------
5551 procedure Create_Extra_Formals (E : Entity_Id) is
5553 First_Extra : Entity_Id := Empty;
5554 Last_Extra : Entity_Id;
5555 Formal_Type : Entity_Id;
5556 P_Formal : Entity_Id := Empty;
5558 function Add_Extra_Formal
5559 (Assoc_Entity : Entity_Id;
5562 Suffix : String) return Entity_Id;
5563 -- Add an extra formal to the current list of formals and extra formals.
5564 -- The extra formal is added to the end of the list of extra formals,
5565 -- and also returned as the result. These formals are always of mode IN.
5566 -- The new formal has the type Typ, is declared in Scope, and its name
5567 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
5568 -- The following suffixes are currently used. They should not be changed
5569 -- without coordinating with CodePeer, which makes use of these to
5570 -- provide better messages.
5572 -- O denotes the Constrained bit.
5573 -- L denotes the accessibility level.
5574 -- BIP_xxx denotes an extra formal for a build-in-place function. See
5575 -- the full list in exp_ch6.BIP_Formal_Kind.
5577 ----------------------
5578 -- Add_Extra_Formal --
5579 ----------------------
5581 function Add_Extra_Formal
5582 (Assoc_Entity : Entity_Id;
5585 Suffix : String) return Entity_Id
5587 EF : constant Entity_Id :=
5588 Make_Defining_Identifier (Sloc (Assoc_Entity),
5589 Chars => New_External_Name (Chars (Assoc_Entity),
5593 -- A little optimization. Never generate an extra formal for the
5594 -- _init operand of an initialization procedure, since it could
5597 if Chars (Formal) = Name_uInit then
5601 Set_Ekind (EF, E_In_Parameter);
5602 Set_Actual_Subtype (EF, Typ);
5603 Set_Etype (EF, Typ);
5604 Set_Scope (EF, Scope);
5605 Set_Mechanism (EF, Default_Mechanism);
5606 Set_Formal_Validity (EF);
5608 if No (First_Extra) then
5610 Set_Extra_Formals (Scope, First_Extra);
5613 if Present (Last_Extra) then
5614 Set_Extra_Formal (Last_Extra, EF);
5620 end Add_Extra_Formal;
5622 -- Start of processing for Create_Extra_Formals
5625 -- We never generate extra formals if expansion is not active
5626 -- because we don't need them unless we are generating code.
5628 if not Expander_Active then
5632 -- If this is a derived subprogram then the subtypes of the parent
5633 -- subprogram's formal parameters will be used to determine the need
5634 -- for extra formals.
5636 if Is_Overloadable (E) and then Present (Alias (E)) then
5637 P_Formal := First_Formal (Alias (E));
5640 Last_Extra := Empty;
5641 Formal := First_Formal (E);
5642 while Present (Formal) loop
5643 Last_Extra := Formal;
5644 Next_Formal (Formal);
5647 -- If Extra_formals were already created, don't do it again. This
5648 -- situation may arise for subprogram types created as part of
5649 -- dispatching calls (see Expand_Dispatching_Call)
5651 if Present (Last_Extra) and then
5652 Present (Extra_Formal (Last_Extra))
5657 -- If the subprogram is a predefined dispatching subprogram then don't
5658 -- generate any extra constrained or accessibility level formals. In
5659 -- general we suppress these for internal subprograms (by not calling
5660 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
5661 -- generated stream attributes do get passed through because extra
5662 -- build-in-place formals are needed in some cases (limited 'Input).
5664 if Is_Predefined_Internal_Operation (E) then
5665 goto Test_For_BIP_Extras;
5668 Formal := First_Formal (E);
5669 while Present (Formal) loop
5671 -- Create extra formal for supporting the attribute 'Constrained.
5672 -- The case of a private type view without discriminants also
5673 -- requires the extra formal if the underlying type has defaulted
5676 if Ekind (Formal) /= E_In_Parameter then
5677 if Present (P_Formal) then
5678 Formal_Type := Etype (P_Formal);
5680 Formal_Type := Etype (Formal);
5683 -- Do not produce extra formals for Unchecked_Union parameters.
5684 -- Jump directly to the end of the loop.
5686 if Is_Unchecked_Union (Base_Type (Formal_Type)) then
5687 goto Skip_Extra_Formal_Generation;
5690 if not Has_Discriminants (Formal_Type)
5691 and then Ekind (Formal_Type) in Private_Kind
5692 and then Present (Underlying_Type (Formal_Type))
5694 Formal_Type := Underlying_Type (Formal_Type);
5697 if Has_Discriminants (Formal_Type)
5698 and then not Is_Constrained (Formal_Type)
5699 and then not Is_Indefinite_Subtype (Formal_Type)
5701 Set_Extra_Constrained
5702 (Formal, Add_Extra_Formal (Formal, Standard_Boolean, E, "O"));
5706 -- Create extra formal for supporting accessibility checking. This
5707 -- is done for both anonymous access formals and formals of named
5708 -- access types that are marked as controlling formals. The latter
5709 -- case can occur when Expand_Dispatching_Call creates a subprogram
5710 -- type and substitutes the types of access-to-class-wide actuals
5711 -- for the anonymous access-to-specific-type of controlling formals.
5712 -- Base_Type is applied because in cases where there is a null
5713 -- exclusion the formal may have an access subtype.
5715 -- This is suppressed if we specifically suppress accessibility
5716 -- checks at the package level for either the subprogram, or the
5717 -- package in which it resides. However, we do not suppress it
5718 -- simply if the scope has accessibility checks suppressed, since
5719 -- this could cause trouble when clients are compiled with a
5720 -- different suppression setting. The explicit checks at the
5721 -- package level are safe from this point of view.
5723 if (Ekind (Base_Type (Etype (Formal))) = E_Anonymous_Access_Type
5724 or else (Is_Controlling_Formal (Formal)
5725 and then Is_Access_Type (Base_Type (Etype (Formal)))))
5727 (Explicit_Suppress (E, Accessibility_Check)
5729 Explicit_Suppress (Scope (E), Accessibility_Check))
5732 or else Present (Extra_Accessibility (P_Formal)))
5734 Set_Extra_Accessibility
5735 (Formal, Add_Extra_Formal (Formal, Standard_Natural, E, "L"));
5738 -- This label is required when skipping extra formal generation for
5739 -- Unchecked_Union parameters.
5741 <<Skip_Extra_Formal_Generation>>
5743 if Present (P_Formal) then
5744 Next_Formal (P_Formal);
5747 Next_Formal (Formal);
5750 <<Test_For_BIP_Extras>>
5752 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
5753 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
5755 if Ada_Version >= Ada_2005 and then Is_Build_In_Place_Function (E) then
5757 Result_Subt : constant Entity_Id := Etype (E);
5759 Discard : Entity_Id;
5760 pragma Warnings (Off, Discard);
5763 -- In the case of functions with unconstrained result subtypes,
5764 -- add a 4-state formal indicating whether the return object is
5765 -- allocated by the caller (1), or should be allocated by the
5766 -- callee on the secondary stack (2), in the global heap (3), or
5767 -- in a user-defined storage pool (4). For the moment we just use
5768 -- Natural for the type of this formal. Note that this formal
5769 -- isn't usually needed in the case where the result subtype is
5770 -- constrained, but it is needed when the function has a tagged
5771 -- result, because generally such functions can be called in a
5772 -- dispatching context and such calls must be handled like calls
5773 -- to a class-wide function.
5775 if not Is_Constrained (Underlying_Type (Result_Subt))
5776 or else Is_Tagged_Type (Underlying_Type (Result_Subt))
5780 (E, Standard_Natural,
5781 E, BIP_Formal_Suffix (BIP_Alloc_Form));
5784 -- For functions whose result type has controlled parts, we have
5785 -- an extra formal of type System.Finalization_Implementation.
5786 -- Finalizable_Ptr_Ptr. That is, we are passing a pointer to a
5787 -- finalization list (which is itself a pointer). This extra
5788 -- formal is then passed along to Move_Final_List in case of
5789 -- successful completion of a return statement. We cannot pass an
5790 -- 'in out' parameter, because we need to update the finalization
5791 -- list during an abort-deferred region, rather than using
5792 -- copy-back after the function returns. This is true even if we
5793 -- are able to get away with having 'in out' parameters, which are
5794 -- normally illegal for functions. This formal is also needed when
5795 -- the function has a tagged result.
5797 if Needs_BIP_Final_List (E) then
5800 (E, RTE (RE_Finalizable_Ptr_Ptr),
5801 E, BIP_Formal_Suffix (BIP_Final_List));
5804 -- If the result type contains tasks, we have two extra formals:
5805 -- the master of the tasks to be created, and the caller's
5806 -- activation chain.
5808 if Has_Task (Result_Subt) then
5811 (E, RTE (RE_Master_Id),
5812 E, BIP_Formal_Suffix (BIP_Master));
5815 (E, RTE (RE_Activation_Chain_Access),
5816 E, BIP_Formal_Suffix (BIP_Activation_Chain));
5819 -- All build-in-place functions get an extra formal that will be
5820 -- passed the address of the return object within the caller.
5823 Formal_Type : constant Entity_Id :=
5825 (E_Anonymous_Access_Type, E,
5826 Scope_Id => Scope (E));
5828 Set_Directly_Designated_Type (Formal_Type, Result_Subt);
5829 Set_Etype (Formal_Type, Formal_Type);
5830 Set_Depends_On_Private
5831 (Formal_Type, Has_Private_Component (Formal_Type));
5832 Set_Is_Public (Formal_Type, Is_Public (Scope (Formal_Type)));
5833 Set_Is_Access_Constant (Formal_Type, False);
5835 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
5836 -- the designated type comes from the limited view (for
5837 -- back-end purposes).
5839 Set_From_With_Type (Formal_Type, From_With_Type (Result_Subt));
5841 Layout_Type (Formal_Type);
5845 (E, Formal_Type, E, BIP_Formal_Suffix (BIP_Object_Access));
5849 end Create_Extra_Formals;
5851 -----------------------------
5852 -- Enter_Overloaded_Entity --
5853 -----------------------------
5855 procedure Enter_Overloaded_Entity (S : Entity_Id) is
5856 E : Entity_Id := Current_Entity_In_Scope (S);
5857 C_E : Entity_Id := Current_Entity (S);
5861 Set_Has_Homonym (E);
5862 Set_Has_Homonym (S);
5865 Set_Is_Immediately_Visible (S);
5866 Set_Scope (S, Current_Scope);
5868 -- Chain new entity if front of homonym in current scope, so that
5869 -- homonyms are contiguous.
5874 while Homonym (C_E) /= E loop
5875 C_E := Homonym (C_E);
5878 Set_Homonym (C_E, S);
5882 Set_Current_Entity (S);
5887 Append_Entity (S, Current_Scope);
5888 Set_Public_Status (S);
5890 if Debug_Flag_E then
5891 Write_Str ("New overloaded entity chain: ");
5892 Write_Name (Chars (S));
5895 while Present (E) loop
5896 Write_Str (" "); Write_Int (Int (E));
5903 -- Generate warning for hiding
5906 and then Comes_From_Source (S)
5907 and then In_Extended_Main_Source_Unit (S)
5914 -- Warn unless genuine overloading
5916 if (not Is_Overloadable (E) or else Subtype_Conformant (E, S))
5917 and then (Is_Immediately_Visible (E)
5919 Is_Potentially_Use_Visible (S))
5921 Error_Msg_Sloc := Sloc (E);
5922 Error_Msg_N ("declaration of & hides one#?", S);
5926 end Enter_Overloaded_Entity;
5928 -----------------------------
5929 -- Check_Untagged_Equality --
5930 -----------------------------
5932 procedure Check_Untagged_Equality (Eq_Op : Entity_Id) is
5933 Typ : constant Entity_Id := Etype (First_Formal (Eq_Op));
5934 Decl : constant Node_Id := Unit_Declaration_Node (Eq_Op);
5938 if Nkind (Decl) = N_Subprogram_Declaration
5939 and then Is_Record_Type (Typ)
5940 and then not Is_Tagged_Type (Typ)
5942 -- If the type is not declared in a package, or if we are in the
5943 -- body of the package or in some other scope, the new operation is
5944 -- not primitive, and therefore legal, though suspicious. If the
5945 -- type is a generic actual (sub)type, the operation is not primitive
5946 -- either because the base type is declared elsewhere.
5948 if Is_Frozen (Typ) then
5949 if Ekind (Scope (Typ)) /= E_Package
5950 or else Scope (Typ) /= Current_Scope
5954 elsif Is_Generic_Actual_Type (Typ) then
5957 elsif In_Package_Body (Scope (Typ)) then
5959 ("equality operator must be declared "
5960 & "before type& is frozen", Eq_Op, Typ);
5962 ("\move declaration to package spec", Eq_Op);
5966 ("equality operator must be declared "
5967 & "before type& is frozen", Eq_Op, Typ);
5969 Obj_Decl := Next (Parent (Typ));
5970 while Present (Obj_Decl)
5971 and then Obj_Decl /= Decl
5973 if Nkind (Obj_Decl) = N_Object_Declaration
5974 and then Etype (Defining_Identifier (Obj_Decl)) = Typ
5976 Error_Msg_NE ("type& is frozen by declaration?",
5979 ("\an equality operator cannot be declared after this "
5980 & "point ('R'M 4.5.2 (9.8)) (Ada 2012))?", Obj_Decl);
5988 elsif not In_Same_List (Parent (Typ), Decl)
5989 and then not Is_Limited_Type (Typ)
5992 -- This makes it illegal to have a primitive equality declared in
5993 -- the private part if the type is visible.
5995 Error_Msg_N ("equality operator appears too late", Eq_Op);
5998 end Check_Untagged_Equality;
6000 -----------------------------
6001 -- Find_Corresponding_Spec --
6002 -----------------------------
6004 function Find_Corresponding_Spec
6006 Post_Error : Boolean := True) return Entity_Id
6008 Spec : constant Node_Id := Specification (N);
6009 Designator : constant Entity_Id := Defining_Entity (Spec);
6014 E := Current_Entity (Designator);
6015 while Present (E) loop
6017 -- We are looking for a matching spec. It must have the same scope,
6018 -- and the same name, and either be type conformant, or be the case
6019 -- of a library procedure spec and its body (which belong to one
6020 -- another regardless of whether they are type conformant or not).
6022 if Scope (E) = Current_Scope then
6023 if Current_Scope = Standard_Standard
6024 or else (Ekind (E) = Ekind (Designator)
6025 and then Type_Conformant (E, Designator))
6027 -- Within an instantiation, we know that spec and body are
6028 -- subtype conformant, because they were subtype conformant
6029 -- in the generic. We choose the subtype-conformant entity
6030 -- here as well, to resolve spurious ambiguities in the
6031 -- instance that were not present in the generic (i.e. when
6032 -- two different types are given the same actual). If we are
6033 -- looking for a spec to match a body, full conformance is
6037 Set_Convention (Designator, Convention (E));
6039 if Nkind (N) = N_Subprogram_Body
6040 and then Present (Homonym (E))
6041 and then not Fully_Conformant (E, Designator)
6045 elsif not Subtype_Conformant (E, Designator) then
6050 if not Has_Completion (E) then
6051 if Nkind (N) /= N_Subprogram_Body_Stub then
6052 Set_Corresponding_Spec (N, E);
6055 Set_Has_Completion (E);
6058 elsif Nkind (Parent (N)) = N_Subunit then
6060 -- If this is the proper body of a subunit, the completion
6061 -- flag is set when analyzing the stub.
6065 -- If E is an internal function with a controlling result
6066 -- that was created for an operation inherited by a null
6067 -- extension, it may be overridden by a body without a previous
6068 -- spec (one more reason why these should be shunned). In that
6069 -- case remove the generated body if present, because the
6070 -- current one is the explicit overriding.
6072 elsif Ekind (E) = E_Function
6073 and then Ada_Version >= Ada_2005
6074 and then not Comes_From_Source (E)
6075 and then Has_Controlling_Result (E)
6076 and then Is_Null_Extension (Etype (E))
6077 and then Comes_From_Source (Spec)
6079 Set_Has_Completion (E, False);
6082 and then Nkind (Parent (E)) = N_Function_Specification
6085 (Unit_Declaration_Node
6086 (Corresponding_Body (Unit_Declaration_Node (E))));
6090 -- If expansion is disabled, or if the wrapper function has
6091 -- not been generated yet, this a late body overriding an
6092 -- inherited operation, or it is an overriding by some other
6093 -- declaration before the controlling result is frozen. In
6094 -- either case this is a declaration of a new entity.
6100 -- If the body already exists, then this is an error unless
6101 -- the previous declaration is the implicit declaration of a
6102 -- derived subprogram, or this is a spurious overloading in an
6105 elsif No (Alias (E))
6106 and then not Is_Intrinsic_Subprogram (E)
6107 and then not In_Instance
6110 Error_Msg_Sloc := Sloc (E);
6112 if Is_Imported (E) then
6114 ("body not allowed for imported subprogram & declared#",
6117 Error_Msg_NE ("duplicate body for & declared#", N, E);
6121 -- Child units cannot be overloaded, so a conformance mismatch
6122 -- between body and a previous spec is an error.
6124 elsif Is_Child_Unit (E)
6126 Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body
6128 Nkind (Parent (Unit_Declaration_Node (Designator))) =
6133 ("body of child unit does not match previous declaration", N);
6141 -- On exit, we know that no previous declaration of subprogram exists
6144 end Find_Corresponding_Spec;
6146 ----------------------
6147 -- Fully_Conformant --
6148 ----------------------
6150 function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
6153 Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result);
6155 end Fully_Conformant;
6157 ----------------------------------
6158 -- Fully_Conformant_Expressions --
6159 ----------------------------------
6161 function Fully_Conformant_Expressions
6162 (Given_E1 : Node_Id;
6163 Given_E2 : Node_Id) return Boolean
6165 E1 : constant Node_Id := Original_Node (Given_E1);
6166 E2 : constant Node_Id := Original_Node (Given_E2);
6167 -- We always test conformance on original nodes, since it is possible
6168 -- for analysis and/or expansion to make things look as though they
6169 -- conform when they do not, e.g. by converting 1+2 into 3.
6171 function FCE (Given_E1, Given_E2 : Node_Id) return Boolean
6172 renames Fully_Conformant_Expressions;
6174 function FCL (L1, L2 : List_Id) return Boolean;
6175 -- Compare elements of two lists for conformance. Elements have to
6176 -- be conformant, and actuals inserted as default parameters do not
6177 -- match explicit actuals with the same value.
6179 function FCO (Op_Node, Call_Node : Node_Id) return Boolean;
6180 -- Compare an operator node with a function call
6186 function FCL (L1, L2 : List_Id) return Boolean is
6190 if L1 = No_List then
6196 if L2 = No_List then
6202 -- Compare two lists, skipping rewrite insertions (we want to
6203 -- compare the original trees, not the expanded versions!)
6206 if Is_Rewrite_Insertion (N1) then
6208 elsif Is_Rewrite_Insertion (N2) then
6214 elsif not FCE (N1, N2) then
6227 function FCO (Op_Node, Call_Node : Node_Id) return Boolean is
6228 Actuals : constant List_Id := Parameter_Associations (Call_Node);
6233 or else Entity (Op_Node) /= Entity (Name (Call_Node))
6238 Act := First (Actuals);
6240 if Nkind (Op_Node) in N_Binary_Op then
6241 if not FCE (Left_Opnd (Op_Node), Act) then
6248 return Present (Act)
6249 and then FCE (Right_Opnd (Op_Node), Act)
6250 and then No (Next (Act));
6254 -- Start of processing for Fully_Conformant_Expressions
6257 -- Non-conformant if paren count does not match. Note: if some idiot
6258 -- complains that we don't do this right for more than 3 levels of
6259 -- parentheses, they will be treated with the respect they deserve!
6261 if Paren_Count (E1) /= Paren_Count (E2) then
6264 -- If same entities are referenced, then they are conformant even if
6265 -- they have different forms (RM 8.3.1(19-20)).
6267 elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then
6268 if Present (Entity (E1)) then
6269 return Entity (E1) = Entity (E2)
6270 or else (Chars (Entity (E1)) = Chars (Entity (E2))
6271 and then Ekind (Entity (E1)) = E_Discriminant
6272 and then Ekind (Entity (E2)) = E_In_Parameter);
6274 elsif Nkind (E1) = N_Expanded_Name
6275 and then Nkind (E2) = N_Expanded_Name
6276 and then Nkind (Selector_Name (E1)) = N_Character_Literal
6277 and then Nkind (Selector_Name (E2)) = N_Character_Literal
6279 return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2));
6282 -- Identifiers in component associations don't always have
6283 -- entities, but their names must conform.
6285 return Nkind (E1) = N_Identifier
6286 and then Nkind (E2) = N_Identifier
6287 and then Chars (E1) = Chars (E2);
6290 elsif Nkind (E1) = N_Character_Literal
6291 and then Nkind (E2) = N_Expanded_Name
6293 return Nkind (Selector_Name (E2)) = N_Character_Literal
6294 and then Chars (E1) = Chars (Selector_Name (E2));
6296 elsif Nkind (E2) = N_Character_Literal
6297 and then Nkind (E1) = N_Expanded_Name
6299 return Nkind (Selector_Name (E1)) = N_Character_Literal
6300 and then Chars (E2) = Chars (Selector_Name (E1));
6302 elsif Nkind (E1) in N_Op
6303 and then Nkind (E2) = N_Function_Call
6305 return FCO (E1, E2);
6307 elsif Nkind (E2) in N_Op
6308 and then Nkind (E1) = N_Function_Call
6310 return FCO (E2, E1);
6312 -- Otherwise we must have the same syntactic entity
6314 elsif Nkind (E1) /= Nkind (E2) then
6317 -- At this point, we specialize by node type
6324 FCL (Expressions (E1), Expressions (E2))
6326 FCL (Component_Associations (E1),
6327 Component_Associations (E2));
6330 if Nkind (Expression (E1)) = N_Qualified_Expression
6332 Nkind (Expression (E2)) = N_Qualified_Expression
6334 return FCE (Expression (E1), Expression (E2));
6336 -- Check that the subtype marks and any constraints
6341 Indic1 : constant Node_Id := Expression (E1);
6342 Indic2 : constant Node_Id := Expression (E2);
6347 if Nkind (Indic1) /= N_Subtype_Indication then
6349 Nkind (Indic2) /= N_Subtype_Indication
6350 and then Entity (Indic1) = Entity (Indic2);
6352 elsif Nkind (Indic2) /= N_Subtype_Indication then
6354 Nkind (Indic1) /= N_Subtype_Indication
6355 and then Entity (Indic1) = Entity (Indic2);
6358 if Entity (Subtype_Mark (Indic1)) /=
6359 Entity (Subtype_Mark (Indic2))
6364 Elt1 := First (Constraints (Constraint (Indic1)));
6365 Elt2 := First (Constraints (Constraint (Indic2)));
6366 while Present (Elt1) and then Present (Elt2) loop
6367 if not FCE (Elt1, Elt2) then
6380 when N_Attribute_Reference =>
6382 Attribute_Name (E1) = Attribute_Name (E2)
6383 and then FCL (Expressions (E1), Expressions (E2));
6387 Entity (E1) = Entity (E2)
6388 and then FCE (Left_Opnd (E1), Left_Opnd (E2))
6389 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
6391 when N_Short_Circuit | N_Membership_Test =>
6393 FCE (Left_Opnd (E1), Left_Opnd (E2))
6395 FCE (Right_Opnd (E1), Right_Opnd (E2));
6397 when N_Case_Expression =>
6403 if not FCE (Expression (E1), Expression (E2)) then
6407 Alt1 := First (Alternatives (E1));
6408 Alt2 := First (Alternatives (E2));
6410 if Present (Alt1) /= Present (Alt2) then
6412 elsif No (Alt1) then
6416 if not FCE (Expression (Alt1), Expression (Alt2))
6417 or else not FCL (Discrete_Choices (Alt1),
6418 Discrete_Choices (Alt2))
6429 when N_Character_Literal =>
6431 Char_Literal_Value (E1) = Char_Literal_Value (E2);
6433 when N_Component_Association =>
6435 FCL (Choices (E1), Choices (E2))
6437 FCE (Expression (E1), Expression (E2));
6439 when N_Conditional_Expression =>
6441 FCL (Expressions (E1), Expressions (E2));
6443 when N_Explicit_Dereference =>
6445 FCE (Prefix (E1), Prefix (E2));
6447 when N_Extension_Aggregate =>
6449 FCL (Expressions (E1), Expressions (E2))
6450 and then Null_Record_Present (E1) =
6451 Null_Record_Present (E2)
6452 and then FCL (Component_Associations (E1),
6453 Component_Associations (E2));
6455 when N_Function_Call =>
6457 FCE (Name (E1), Name (E2))
6459 FCL (Parameter_Associations (E1),
6460 Parameter_Associations (E2));
6462 when N_Indexed_Component =>
6464 FCE (Prefix (E1), Prefix (E2))
6466 FCL (Expressions (E1), Expressions (E2));
6468 when N_Integer_Literal =>
6469 return (Intval (E1) = Intval (E2));
6474 when N_Operator_Symbol =>
6476 Chars (E1) = Chars (E2);
6478 when N_Others_Choice =>
6481 when N_Parameter_Association =>
6483 Chars (Selector_Name (E1)) = Chars (Selector_Name (E2))
6484 and then FCE (Explicit_Actual_Parameter (E1),
6485 Explicit_Actual_Parameter (E2));
6487 when N_Qualified_Expression =>
6489 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
6491 FCE (Expression (E1), Expression (E2));
6495 FCE (Low_Bound (E1), Low_Bound (E2))
6497 FCE (High_Bound (E1), High_Bound (E2));
6499 when N_Real_Literal =>
6500 return (Realval (E1) = Realval (E2));
6502 when N_Selected_Component =>
6504 FCE (Prefix (E1), Prefix (E2))
6506 FCE (Selector_Name (E1), Selector_Name (E2));
6510 FCE (Prefix (E1), Prefix (E2))
6512 FCE (Discrete_Range (E1), Discrete_Range (E2));
6514 when N_String_Literal =>
6516 S1 : constant String_Id := Strval (E1);
6517 S2 : constant String_Id := Strval (E2);
6518 L1 : constant Nat := String_Length (S1);
6519 L2 : constant Nat := String_Length (S2);
6526 for J in 1 .. L1 loop
6527 if Get_String_Char (S1, J) /=
6528 Get_String_Char (S2, J)
6538 when N_Type_Conversion =>
6540 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
6542 FCE (Expression (E1), Expression (E2));
6546 Entity (E1) = Entity (E2)
6548 FCE (Right_Opnd (E1), Right_Opnd (E2));
6550 when N_Unchecked_Type_Conversion =>
6552 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
6554 FCE (Expression (E1), Expression (E2));
6556 -- All other node types cannot appear in this context. Strictly
6557 -- we should raise a fatal internal error. Instead we just ignore
6558 -- the nodes. This means that if anyone makes a mistake in the
6559 -- expander and mucks an expression tree irretrievably, the
6560 -- result will be a failure to detect a (probably very obscure)
6561 -- case of non-conformance, which is better than bombing on some
6562 -- case where two expressions do in fact conform.
6569 end Fully_Conformant_Expressions;
6571 ----------------------------------------
6572 -- Fully_Conformant_Discrete_Subtypes --
6573 ----------------------------------------
6575 function Fully_Conformant_Discrete_Subtypes
6576 (Given_S1 : Node_Id;
6577 Given_S2 : Node_Id) return Boolean
6579 S1 : constant Node_Id := Original_Node (Given_S1);
6580 S2 : constant Node_Id := Original_Node (Given_S2);
6582 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean;
6583 -- Special-case for a bound given by a discriminant, which in the body
6584 -- is replaced with the discriminal of the enclosing type.
6586 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean;
6587 -- Check both bounds
6589 -----------------------
6590 -- Conforming_Bounds --
6591 -----------------------
6593 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is
6595 if Is_Entity_Name (B1)
6596 and then Is_Entity_Name (B2)
6597 and then Ekind (Entity (B1)) = E_Discriminant
6599 return Chars (B1) = Chars (B2);
6602 return Fully_Conformant_Expressions (B1, B2);
6604 end Conforming_Bounds;
6606 -----------------------
6607 -- Conforming_Ranges --
6608 -----------------------
6610 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is
6613 Conforming_Bounds (Low_Bound (R1), Low_Bound (R2))
6615 Conforming_Bounds (High_Bound (R1), High_Bound (R2));
6616 end Conforming_Ranges;
6618 -- Start of processing for Fully_Conformant_Discrete_Subtypes
6621 if Nkind (S1) /= Nkind (S2) then
6624 elsif Is_Entity_Name (S1) then
6625 return Entity (S1) = Entity (S2);
6627 elsif Nkind (S1) = N_Range then
6628 return Conforming_Ranges (S1, S2);
6630 elsif Nkind (S1) = N_Subtype_Indication then
6632 Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2))
6635 (Range_Expression (Constraint (S1)),
6636 Range_Expression (Constraint (S2)));
6640 end Fully_Conformant_Discrete_Subtypes;
6642 --------------------
6643 -- Install_Entity --
6644 --------------------
6646 procedure Install_Entity (E : Entity_Id) is
6647 Prev : constant Entity_Id := Current_Entity (E);
6649 Set_Is_Immediately_Visible (E);
6650 Set_Current_Entity (E);
6651 Set_Homonym (E, Prev);
6654 ---------------------
6655 -- Install_Formals --
6656 ---------------------
6658 procedure Install_Formals (Id : Entity_Id) is
6661 F := First_Formal (Id);
6662 while Present (F) loop
6666 end Install_Formals;
6668 -----------------------------
6669 -- Is_Interface_Conformant --
6670 -----------------------------
6672 function Is_Interface_Conformant
6673 (Tagged_Type : Entity_Id;
6674 Iface_Prim : Entity_Id;
6675 Prim : Entity_Id) return Boolean
6677 Iface : constant Entity_Id := Find_Dispatching_Type (Iface_Prim);
6678 Typ : constant Entity_Id := Find_Dispatching_Type (Prim);
6681 pragma Assert (Is_Subprogram (Iface_Prim)
6682 and then Is_Subprogram (Prim)
6683 and then Is_Dispatching_Operation (Iface_Prim)
6684 and then Is_Dispatching_Operation (Prim));
6686 pragma Assert (Is_Interface (Iface)
6687 or else (Present (Alias (Iface_Prim))
6690 (Find_Dispatching_Type (Ultimate_Alias (Iface_Prim)))));
6692 if Prim = Iface_Prim
6693 or else not Is_Subprogram (Prim)
6694 or else Ekind (Prim) /= Ekind (Iface_Prim)
6695 or else not Is_Dispatching_Operation (Prim)
6696 or else Scope (Prim) /= Scope (Tagged_Type)
6698 or else Base_Type (Typ) /= Tagged_Type
6699 or else not Primitive_Names_Match (Iface_Prim, Prim)
6703 -- Case of a procedure, or a function that does not have a controlling
6704 -- result (I or access I).
6706 elsif Ekind (Iface_Prim) = E_Procedure
6707 or else Etype (Prim) = Etype (Iface_Prim)
6708 or else not Has_Controlling_Result (Prim)
6710 return Type_Conformant
6711 (Iface_Prim, Prim, Skip_Controlling_Formals => True);
6713 -- Case of a function returning an interface, or an access to one.
6714 -- Check that the return types correspond.
6716 elsif Implements_Interface (Typ, Iface) then
6717 if (Ekind (Etype (Prim)) = E_Anonymous_Access_Type)
6719 (Ekind (Etype (Iface_Prim)) = E_Anonymous_Access_Type)
6724 Type_Conformant (Prim, Iface_Prim,
6725 Skip_Controlling_Formals => True);
6731 end Is_Interface_Conformant;
6733 ---------------------------------
6734 -- Is_Non_Overriding_Operation --
6735 ---------------------------------
6737 function Is_Non_Overriding_Operation
6738 (Prev_E : Entity_Id;
6739 New_E : Entity_Id) return Boolean
6743 G_Typ : Entity_Id := Empty;
6745 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id;
6746 -- If F_Type is a derived type associated with a generic actual subtype,
6747 -- then return its Generic_Parent_Type attribute, else return Empty.
6749 function Types_Correspond
6750 (P_Type : Entity_Id;
6751 N_Type : Entity_Id) return Boolean;
6752 -- Returns true if and only if the types (or designated types in the
6753 -- case of anonymous access types) are the same or N_Type is derived
6754 -- directly or indirectly from P_Type.
6756 -----------------------------
6757 -- Get_Generic_Parent_Type --
6758 -----------------------------
6760 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is
6765 if Is_Derived_Type (F_Typ)
6766 and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration
6768 -- The tree must be traversed to determine the parent subtype in
6769 -- the generic unit, which unfortunately isn't always available
6770 -- via semantic attributes. ??? (Note: The use of Original_Node
6771 -- is needed for cases where a full derived type has been
6774 Indic := Subtype_Indication
6775 (Type_Definition (Original_Node (Parent (F_Typ))));
6777 if Nkind (Indic) = N_Subtype_Indication then
6778 G_Typ := Entity (Subtype_Mark (Indic));
6780 G_Typ := Entity (Indic);
6783 if Nkind (Parent (G_Typ)) = N_Subtype_Declaration
6784 and then Present (Generic_Parent_Type (Parent (G_Typ)))
6786 return Generic_Parent_Type (Parent (G_Typ));
6791 end Get_Generic_Parent_Type;
6793 ----------------------
6794 -- Types_Correspond --
6795 ----------------------
6797 function Types_Correspond
6798 (P_Type : Entity_Id;
6799 N_Type : Entity_Id) return Boolean
6801 Prev_Type : Entity_Id := Base_Type (P_Type);
6802 New_Type : Entity_Id := Base_Type (N_Type);
6805 if Ekind (Prev_Type) = E_Anonymous_Access_Type then
6806 Prev_Type := Designated_Type (Prev_Type);
6809 if Ekind (New_Type) = E_Anonymous_Access_Type then
6810 New_Type := Designated_Type (New_Type);
6813 if Prev_Type = New_Type then
6816 elsif not Is_Class_Wide_Type (New_Type) then
6817 while Etype (New_Type) /= New_Type loop
6818 New_Type := Etype (New_Type);
6819 if New_Type = Prev_Type then
6825 end Types_Correspond;
6827 -- Start of processing for Is_Non_Overriding_Operation
6830 -- In the case where both operations are implicit derived subprograms
6831 -- then neither overrides the other. This can only occur in certain
6832 -- obscure cases (e.g., derivation from homographs created in a generic
6835 if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then
6838 elsif Ekind (Current_Scope) = E_Package
6839 and then Is_Generic_Instance (Current_Scope)
6840 and then In_Private_Part (Current_Scope)
6841 and then Comes_From_Source (New_E)
6843 -- We examine the formals and result subtype of the inherited
6844 -- operation, to determine whether their type is derived from (the
6845 -- instance of) a generic type.
6847 Formal := First_Formal (Prev_E);
6848 while Present (Formal) loop
6849 F_Typ := Base_Type (Etype (Formal));
6851 if Ekind (F_Typ) = E_Anonymous_Access_Type then
6852 F_Typ := Designated_Type (F_Typ);
6855 G_Typ := Get_Generic_Parent_Type (F_Typ);
6857 Next_Formal (Formal);
6860 if No (G_Typ) and then Ekind (Prev_E) = E_Function then
6861 G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E)));
6868 -- If the generic type is a private type, then the original operation
6869 -- was not overriding in the generic, because there was no primitive
6870 -- operation to override.
6872 if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration
6873 and then Nkind (Formal_Type_Definition (Parent (G_Typ))) =
6874 N_Formal_Private_Type_Definition
6878 -- The generic parent type is the ancestor of a formal derived
6879 -- type declaration. We need to check whether it has a primitive
6880 -- operation that should be overridden by New_E in the generic.
6884 P_Formal : Entity_Id;
6885 N_Formal : Entity_Id;
6889 Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ));
6892 while Present (Prim_Elt) loop
6893 P_Prim := Node (Prim_Elt);
6895 if Chars (P_Prim) = Chars (New_E)
6896 and then Ekind (P_Prim) = Ekind (New_E)
6898 P_Formal := First_Formal (P_Prim);
6899 N_Formal := First_Formal (New_E);
6900 while Present (P_Formal) and then Present (N_Formal) loop
6901 P_Typ := Etype (P_Formal);
6902 N_Typ := Etype (N_Formal);
6904 if not Types_Correspond (P_Typ, N_Typ) then
6908 Next_Entity (P_Formal);
6909 Next_Entity (N_Formal);
6912 -- Found a matching primitive operation belonging to the
6913 -- formal ancestor type, so the new subprogram is
6917 and then No (N_Formal)
6918 and then (Ekind (New_E) /= E_Function
6921 (Etype (P_Prim), Etype (New_E)))
6927 Next_Elmt (Prim_Elt);
6930 -- If no match found, then the new subprogram does not
6931 -- override in the generic (nor in the instance).
6939 end Is_Non_Overriding_Operation;
6941 -------------------------------------
6942 -- List_Inherited_Pre_Post_Aspects --
6943 -------------------------------------
6945 procedure List_Inherited_Pre_Post_Aspects (E : Entity_Id) is
6947 if Opt.List_Inherited_Pre_Post
6948 and then (Is_Subprogram (E) or else Is_Generic_Subprogram (E))
6951 Inherited : constant Subprogram_List :=
6952 Inherited_Subprograms (E);
6956 for J in Inherited'Range loop
6957 P := Spec_PPC_List (Inherited (J));
6958 while Present (P) loop
6959 Error_Msg_Sloc := Sloc (P);
6961 if Class_Present (P) and then not Split_PPC (P) then
6962 if Pragma_Name (P) = Name_Precondition then
6964 ("?info: & inherits `Pre''Class` aspect from #", E);
6967 ("?info: & inherits `Post''Class` aspect from #", E);
6971 P := Next_Pragma (P);
6976 end List_Inherited_Pre_Post_Aspects;
6978 ------------------------------
6979 -- Make_Inequality_Operator --
6980 ------------------------------
6982 -- S is the defining identifier of an equality operator. We build a
6983 -- subprogram declaration with the right signature. This operation is
6984 -- intrinsic, because it is always expanded as the negation of the
6985 -- call to the equality function.
6987 procedure Make_Inequality_Operator (S : Entity_Id) is
6988 Loc : constant Source_Ptr := Sloc (S);
6991 Op_Name : Entity_Id;
6993 FF : constant Entity_Id := First_Formal (S);
6994 NF : constant Entity_Id := Next_Formal (FF);
6997 -- Check that equality was properly defined, ignore call if not
7004 A : constant Entity_Id :=
7005 Make_Defining_Identifier (Sloc (FF),
7006 Chars => Chars (FF));
7008 B : constant Entity_Id :=
7009 Make_Defining_Identifier (Sloc (NF),
7010 Chars => Chars (NF));
7013 Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne);
7015 Formals := New_List (
7016 Make_Parameter_Specification (Loc,
7017 Defining_Identifier => A,
7019 New_Reference_To (Etype (First_Formal (S)),
7020 Sloc (Etype (First_Formal (S))))),
7022 Make_Parameter_Specification (Loc,
7023 Defining_Identifier => B,
7025 New_Reference_To (Etype (Next_Formal (First_Formal (S))),
7026 Sloc (Etype (Next_Formal (First_Formal (S)))))));
7029 Make_Subprogram_Declaration (Loc,
7031 Make_Function_Specification (Loc,
7032 Defining_Unit_Name => Op_Name,
7033 Parameter_Specifications => Formals,
7034 Result_Definition =>
7035 New_Reference_To (Standard_Boolean, Loc)));
7037 -- Insert inequality right after equality if it is explicit or after
7038 -- the derived type when implicit. These entities are created only
7039 -- for visibility purposes, and eventually replaced in the course of
7040 -- expansion, so they do not need to be attached to the tree and seen
7041 -- by the back-end. Keeping them internal also avoids spurious
7042 -- freezing problems. The declaration is inserted in the tree for
7043 -- analysis, and removed afterwards. If the equality operator comes
7044 -- from an explicit declaration, attach the inequality immediately
7045 -- after. Else the equality is inherited from a derived type
7046 -- declaration, so insert inequality after that declaration.
7048 if No (Alias (S)) then
7049 Insert_After (Unit_Declaration_Node (S), Decl);
7050 elsif Is_List_Member (Parent (S)) then
7051 Insert_After (Parent (S), Decl);
7053 Insert_After (Parent (Etype (First_Formal (S))), Decl);
7056 Mark_Rewrite_Insertion (Decl);
7057 Set_Is_Intrinsic_Subprogram (Op_Name);
7060 Set_Has_Completion (Op_Name);
7061 Set_Corresponding_Equality (Op_Name, S);
7062 Set_Is_Abstract_Subprogram (Op_Name, Is_Abstract_Subprogram (S));
7064 end Make_Inequality_Operator;
7066 ----------------------
7067 -- May_Need_Actuals --
7068 ----------------------
7070 procedure May_Need_Actuals (Fun : Entity_Id) is
7075 F := First_Formal (Fun);
7077 while Present (F) loop
7078 if No (Default_Value (F)) then
7086 Set_Needs_No_Actuals (Fun, B);
7087 end May_Need_Actuals;
7089 ---------------------
7090 -- Mode_Conformant --
7091 ---------------------
7093 function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
7096 Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result);
7098 end Mode_Conformant;
7100 ---------------------------
7101 -- New_Overloaded_Entity --
7102 ---------------------------
7104 procedure New_Overloaded_Entity
7106 Derived_Type : Entity_Id := Empty)
7108 Overridden_Subp : Entity_Id := Empty;
7109 -- Set if the current scope has an operation that is type-conformant
7110 -- with S, and becomes hidden by S.
7112 Is_Primitive_Subp : Boolean;
7113 -- Set to True if the new subprogram is primitive
7116 -- Entity that S overrides
7118 Prev_Vis : Entity_Id := Empty;
7119 -- Predecessor of E in Homonym chain
7121 procedure Check_For_Primitive_Subprogram
7122 (Is_Primitive : out Boolean;
7123 Is_Overriding : Boolean := False);
7124 -- If the subprogram being analyzed is a primitive operation of the type
7125 -- of a formal or result, set the Has_Primitive_Operations flag on the
7126 -- type, and set Is_Primitive to True (otherwise set to False). Set the
7127 -- corresponding flag on the entity itself for later use.
7129 procedure Check_Synchronized_Overriding
7130 (Def_Id : Entity_Id;
7131 Overridden_Subp : out Entity_Id);
7132 -- First determine if Def_Id is an entry or a subprogram either defined
7133 -- in the scope of a task or protected type, or is a primitive of such
7134 -- a type. Check whether Def_Id overrides a subprogram of an interface
7135 -- implemented by the synchronized type, return the overridden entity
7138 function Is_Private_Declaration (E : Entity_Id) return Boolean;
7139 -- Check that E is declared in the private part of the current package,
7140 -- or in the package body, where it may hide a previous declaration.
7141 -- We can't use In_Private_Part by itself because this flag is also
7142 -- set when freezing entities, so we must examine the place of the
7143 -- declaration in the tree, and recognize wrapper packages as well.
7145 function Is_Overriding_Alias
7147 New_E : Entity_Id) return Boolean;
7148 -- Check whether new subprogram and old subprogram are both inherited
7149 -- from subprograms that have distinct dispatch table entries. This can
7150 -- occur with derivations from instances with accidental homonyms.
7151 -- The function is conservative given that the converse is only true
7152 -- within instances that contain accidental overloadings.
7154 ------------------------------------
7155 -- Check_For_Primitive_Subprogram --
7156 ------------------------------------
7158 procedure Check_For_Primitive_Subprogram
7159 (Is_Primitive : out Boolean;
7160 Is_Overriding : Boolean := False)
7166 function Visible_Part_Type (T : Entity_Id) return Boolean;
7167 -- Returns true if T is declared in the visible part of the current
7168 -- package scope; otherwise returns false. Assumes that T is declared
7171 procedure Check_Private_Overriding (T : Entity_Id);
7172 -- Checks that if a primitive abstract subprogram of a visible
7173 -- abstract type is declared in a private part, then it must override
7174 -- an abstract subprogram declared in the visible part. Also checks
7175 -- that if a primitive function with a controlling result is declared
7176 -- in a private part, then it must override a function declared in
7177 -- the visible part.
7179 ------------------------------
7180 -- Check_Private_Overriding --
7181 ------------------------------
7183 procedure Check_Private_Overriding (T : Entity_Id) is
7185 if Is_Package_Or_Generic_Package (Current_Scope)
7186 and then In_Private_Part (Current_Scope)
7187 and then Visible_Part_Type (T)
7188 and then not In_Instance
7190 if Is_Abstract_Type (T)
7191 and then Is_Abstract_Subprogram (S)
7192 and then (not Is_Overriding
7193 or else not Is_Abstract_Subprogram (E))
7196 ("abstract subprograms must be visible "
7197 & "(RM 3.9.3(10))!", S);
7199 elsif Ekind (S) = E_Function
7200 and then not Is_Overriding
7202 if Is_Tagged_Type (T)
7203 and then T = Base_Type (Etype (S))
7206 ("private function with tagged result must"
7207 & " override visible-part function", S);
7209 ("\move subprogram to the visible part"
7210 & " (RM 3.9.3(10))", S);
7212 -- AI05-0073: extend this test to the case of a function
7213 -- with a controlling access result.
7215 elsif Ekind (Etype (S)) = E_Anonymous_Access_Type
7216 and then Is_Tagged_Type (Designated_Type (Etype (S)))
7218 not Is_Class_Wide_Type (Designated_Type (Etype (S)))
7219 and then Ada_Version >= Ada_2012
7222 ("private function with controlling access result "
7223 & "must override visible-part function", S);
7225 ("\move subprogram to the visible part"
7226 & " (RM 3.9.3(10))", S);
7230 end Check_Private_Overriding;
7232 -----------------------
7233 -- Visible_Part_Type --
7234 -----------------------
7236 function Visible_Part_Type (T : Entity_Id) return Boolean is
7237 P : constant Node_Id := Unit_Declaration_Node (Scope (T));
7241 -- If the entity is a private type, then it must be declared in a
7244 if Ekind (T) in Private_Kind then
7248 -- Otherwise, we traverse the visible part looking for its
7249 -- corresponding declaration. We cannot use the declaration
7250 -- node directly because in the private part the entity of a
7251 -- private type is the one in the full view, which does not
7252 -- indicate that it is the completion of something visible.
7254 N := First (Visible_Declarations (Specification (P)));
7255 while Present (N) loop
7256 if Nkind (N) = N_Full_Type_Declaration
7257 and then Present (Defining_Identifier (N))
7258 and then T = Defining_Identifier (N)
7262 elsif Nkind_In (N, N_Private_Type_Declaration,
7263 N_Private_Extension_Declaration)
7264 and then Present (Defining_Identifier (N))
7265 and then T = Full_View (Defining_Identifier (N))
7274 end Visible_Part_Type;
7276 -- Start of processing for Check_For_Primitive_Subprogram
7279 Is_Primitive := False;
7281 if not Comes_From_Source (S) then
7284 -- If subprogram is at library level, it is not primitive operation
7286 elsif Current_Scope = Standard_Standard then
7289 elsif (Is_Package_Or_Generic_Package (Current_Scope)
7290 and then not In_Package_Body (Current_Scope))
7291 or else Is_Overriding
7293 -- For function, check return type
7295 if Ekind (S) = E_Function then
7296 if Ekind (Etype (S)) = E_Anonymous_Access_Type then
7297 F_Typ := Designated_Type (Etype (S));
7302 B_Typ := Base_Type (F_Typ);
7304 if Scope (B_Typ) = Current_Scope
7305 and then not Is_Class_Wide_Type (B_Typ)
7306 and then not Is_Generic_Type (B_Typ)
7308 Is_Primitive := True;
7309 Set_Has_Primitive_Operations (B_Typ);
7310 Set_Is_Primitive (S);
7311 Check_Private_Overriding (B_Typ);
7315 -- For all subprograms, check formals
7317 Formal := First_Formal (S);
7318 while Present (Formal) loop
7319 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
7320 F_Typ := Designated_Type (Etype (Formal));
7322 F_Typ := Etype (Formal);
7325 B_Typ := Base_Type (F_Typ);
7327 if Ekind (B_Typ) = E_Access_Subtype then
7328 B_Typ := Base_Type (B_Typ);
7331 if Scope (B_Typ) = Current_Scope
7332 and then not Is_Class_Wide_Type (B_Typ)
7333 and then not Is_Generic_Type (B_Typ)
7335 Is_Primitive := True;
7336 Set_Is_Primitive (S);
7337 Set_Has_Primitive_Operations (B_Typ);
7338 Check_Private_Overriding (B_Typ);
7341 Next_Formal (Formal);
7344 end Check_For_Primitive_Subprogram;
7346 -----------------------------------
7347 -- Check_Synchronized_Overriding --
7348 -----------------------------------
7350 procedure Check_Synchronized_Overriding
7351 (Def_Id : Entity_Id;
7352 Overridden_Subp : out Entity_Id)
7354 Ifaces_List : Elist_Id;
7358 function Matches_Prefixed_View_Profile
7359 (Prim_Params : List_Id;
7360 Iface_Params : List_Id) return Boolean;
7361 -- Determine whether a subprogram's parameter profile Prim_Params
7362 -- matches that of a potentially overridden interface subprogram
7363 -- Iface_Params. Also determine if the type of first parameter of
7364 -- Iface_Params is an implemented interface.
7366 -----------------------------------
7367 -- Matches_Prefixed_View_Profile --
7368 -----------------------------------
7370 function Matches_Prefixed_View_Profile
7371 (Prim_Params : List_Id;
7372 Iface_Params : List_Id) return Boolean
7374 Iface_Id : Entity_Id;
7375 Iface_Param : Node_Id;
7376 Iface_Typ : Entity_Id;
7377 Prim_Id : Entity_Id;
7378 Prim_Param : Node_Id;
7379 Prim_Typ : Entity_Id;
7381 function Is_Implemented
7382 (Ifaces_List : Elist_Id;
7383 Iface : Entity_Id) return Boolean;
7384 -- Determine if Iface is implemented by the current task or
7387 --------------------
7388 -- Is_Implemented --
7389 --------------------
7391 function Is_Implemented
7392 (Ifaces_List : Elist_Id;
7393 Iface : Entity_Id) return Boolean
7395 Iface_Elmt : Elmt_Id;
7398 Iface_Elmt := First_Elmt (Ifaces_List);
7399 while Present (Iface_Elmt) loop
7400 if Node (Iface_Elmt) = Iface then
7404 Next_Elmt (Iface_Elmt);
7410 -- Start of processing for Matches_Prefixed_View_Profile
7413 Iface_Param := First (Iface_Params);
7414 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
7416 if Is_Access_Type (Iface_Typ) then
7417 Iface_Typ := Designated_Type (Iface_Typ);
7420 Prim_Param := First (Prim_Params);
7422 -- The first parameter of the potentially overridden subprogram
7423 -- must be an interface implemented by Prim.
7425 if not Is_Interface (Iface_Typ)
7426 or else not Is_Implemented (Ifaces_List, Iface_Typ)
7431 -- The checks on the object parameters are done, move onto the
7432 -- rest of the parameters.
7434 if not In_Scope then
7435 Prim_Param := Next (Prim_Param);
7438 Iface_Param := Next (Iface_Param);
7439 while Present (Iface_Param) and then Present (Prim_Param) loop
7440 Iface_Id := Defining_Identifier (Iface_Param);
7441 Iface_Typ := Find_Parameter_Type (Iface_Param);
7443 Prim_Id := Defining_Identifier (Prim_Param);
7444 Prim_Typ := Find_Parameter_Type (Prim_Param);
7446 if Ekind (Iface_Typ) = E_Anonymous_Access_Type
7447 and then Ekind (Prim_Typ) = E_Anonymous_Access_Type
7448 and then Is_Concurrent_Type (Designated_Type (Prim_Typ))
7450 Iface_Typ := Designated_Type (Iface_Typ);
7451 Prim_Typ := Designated_Type (Prim_Typ);
7454 -- Case of multiple interface types inside a parameter profile
7456 -- (Obj_Param : in out Iface; ...; Param : Iface)
7458 -- If the interface type is implemented, then the matching type
7459 -- in the primitive should be the implementing record type.
7461 if Ekind (Iface_Typ) = E_Record_Type
7462 and then Is_Interface (Iface_Typ)
7463 and then Is_Implemented (Ifaces_List, Iface_Typ)
7465 if Prim_Typ /= Typ then
7469 -- The two parameters must be both mode and subtype conformant
7471 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
7473 Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
7482 -- One of the two lists contains more parameters than the other
7484 if Present (Iface_Param) or else Present (Prim_Param) then
7489 end Matches_Prefixed_View_Profile;
7491 -- Start of processing for Check_Synchronized_Overriding
7494 Overridden_Subp := Empty;
7496 -- Def_Id must be an entry or a subprogram. We should skip predefined
7497 -- primitives internally generated by the frontend; however at this
7498 -- stage predefined primitives are still not fully decorated. As a
7499 -- minor optimization we skip here internally generated subprograms.
7501 if (Ekind (Def_Id) /= E_Entry
7502 and then Ekind (Def_Id) /= E_Function
7503 and then Ekind (Def_Id) /= E_Procedure)
7504 or else not Comes_From_Source (Def_Id)
7509 -- Search for the concurrent declaration since it contains the list
7510 -- of all implemented interfaces. In this case, the subprogram is
7511 -- declared within the scope of a protected or a task type.
7513 if Present (Scope (Def_Id))
7514 and then Is_Concurrent_Type (Scope (Def_Id))
7515 and then not Is_Generic_Actual_Type (Scope (Def_Id))
7517 Typ := Scope (Def_Id);
7520 -- The enclosing scope is not a synchronized type and the subprogram
7523 elsif No (First_Formal (Def_Id)) then
7526 -- The subprogram has formals and hence it may be a primitive of a
7530 Typ := Etype (First_Formal (Def_Id));
7532 if Is_Access_Type (Typ) then
7533 Typ := Directly_Designated_Type (Typ);
7536 if Is_Concurrent_Type (Typ)
7537 and then not Is_Generic_Actual_Type (Typ)
7541 -- This case occurs when the concurrent type is declared within
7542 -- a generic unit. As a result the corresponding record has been
7543 -- built and used as the type of the first formal, we just have
7544 -- to retrieve the corresponding concurrent type.
7546 elsif Is_Concurrent_Record_Type (Typ)
7547 and then Present (Corresponding_Concurrent_Type (Typ))
7549 Typ := Corresponding_Concurrent_Type (Typ);
7557 -- There is no overriding to check if is an inherited operation in a
7558 -- type derivation on for a generic actual.
7560 Collect_Interfaces (Typ, Ifaces_List);
7562 if Is_Empty_Elmt_List (Ifaces_List) then
7566 -- Determine whether entry or subprogram Def_Id overrides a primitive
7567 -- operation that belongs to one of the interfaces in Ifaces_List.
7570 Candidate : Entity_Id := Empty;
7571 Hom : Entity_Id := Empty;
7572 Iface_Typ : Entity_Id;
7573 Subp : Entity_Id := Empty;
7576 -- Traverse the homonym chain, looking at a potentially
7577 -- overridden subprogram that belongs to an implemented
7580 Hom := Current_Entity_In_Scope (Def_Id);
7581 while Present (Hom) loop
7585 or else not Is_Overloadable (Subp)
7586 or else not Is_Primitive (Subp)
7587 or else not Is_Dispatching_Operation (Subp)
7588 or else not Present (Find_Dispatching_Type (Subp))
7589 or else not Is_Interface (Find_Dispatching_Type (Subp))
7593 -- Entries and procedures can override abstract or null
7594 -- interface procedures
7596 elsif (Ekind (Def_Id) = E_Procedure
7597 or else Ekind (Def_Id) = E_Entry)
7598 and then Ekind (Subp) = E_Procedure
7599 and then Matches_Prefixed_View_Profile
7600 (Parameter_Specifications (Parent (Def_Id)),
7601 Parameter_Specifications (Parent (Subp)))
7605 -- For an overridden subprogram Subp, check whether the mode
7606 -- of its first parameter is correct depending on the kind
7607 -- of synchronized type.
7610 Formal : constant Node_Id := First_Formal (Candidate);
7613 -- In order for an entry or a protected procedure to
7614 -- override, the first parameter of the overridden
7615 -- routine must be of mode "out", "in out" or
7616 -- access-to-variable.
7618 if (Ekind (Candidate) = E_Entry
7619 or else Ekind (Candidate) = E_Procedure)
7620 and then Is_Protected_Type (Typ)
7621 and then Ekind (Formal) /= E_In_Out_Parameter
7622 and then Ekind (Formal) /= E_Out_Parameter
7623 and then Nkind (Parameter_Type (Parent (Formal)))
7624 /= N_Access_Definition
7628 -- All other cases are OK since a task entry or routine
7629 -- does not have a restriction on the mode of the first
7630 -- parameter of the overridden interface routine.
7633 Overridden_Subp := Candidate;
7638 -- Functions can override abstract interface functions
7640 elsif Ekind (Def_Id) = E_Function
7641 and then Ekind (Subp) = E_Function
7642 and then Matches_Prefixed_View_Profile
7643 (Parameter_Specifications (Parent (Def_Id)),
7644 Parameter_Specifications (Parent (Subp)))
7645 and then Etype (Result_Definition (Parent (Def_Id))) =
7646 Etype (Result_Definition (Parent (Subp)))
7648 Overridden_Subp := Subp;
7652 Hom := Homonym (Hom);
7655 -- After examining all candidates for overriding, we are
7656 -- left with the best match which is a mode incompatible
7657 -- interface routine. Do not emit an error if the Expander
7658 -- is active since this error will be detected later on
7659 -- after all concurrent types are expanded and all wrappers
7660 -- are built. This check is meant for spec-only
7663 if Present (Candidate)
7664 and then not Expander_Active
7667 Find_Parameter_Type (Parent (First_Formal (Candidate)));
7669 -- Def_Id is primitive of a protected type, declared
7670 -- inside the type, and the candidate is primitive of a
7671 -- limited or synchronized interface.
7674 and then Is_Protected_Type (Typ)
7676 (Is_Limited_Interface (Iface_Typ)
7677 or else Is_Protected_Interface (Iface_Typ)
7678 or else Is_Synchronized_Interface (Iface_Typ)
7679 or else Is_Task_Interface (Iface_Typ))
7681 -- Must reword this message, comma before to in -gnatj
7685 ("first formal of & must be of mode `OUT`, `IN OUT`"
7686 & " or access-to-variable", Typ, Candidate);
7688 ("\to be overridden by protected procedure or entry "
7689 & "(RM 9.4(11.9/2))", Typ);
7693 Overridden_Subp := Candidate;
7696 end Check_Synchronized_Overriding;
7698 ----------------------------
7699 -- Is_Private_Declaration --
7700 ----------------------------
7702 function Is_Private_Declaration (E : Entity_Id) return Boolean is
7703 Priv_Decls : List_Id;
7704 Decl : constant Node_Id := Unit_Declaration_Node (E);
7707 if Is_Package_Or_Generic_Package (Current_Scope)
7708 and then In_Private_Part (Current_Scope)
7711 Private_Declarations (
7712 Specification (Unit_Declaration_Node (Current_Scope)));
7714 return In_Package_Body (Current_Scope)
7716 (Is_List_Member (Decl)
7717 and then List_Containing (Decl) = Priv_Decls)
7718 or else (Nkind (Parent (Decl)) = N_Package_Specification
7721 (Defining_Entity (Parent (Decl)))
7722 and then List_Containing (Parent (Parent (Decl)))
7727 end Is_Private_Declaration;
7729 --------------------------
7730 -- Is_Overriding_Alias --
7731 --------------------------
7733 function Is_Overriding_Alias
7735 New_E : Entity_Id) return Boolean
7737 AO : constant Entity_Id := Alias (Old_E);
7738 AN : constant Entity_Id := Alias (New_E);
7741 return Scope (AO) /= Scope (AN)
7742 or else No (DTC_Entity (AO))
7743 or else No (DTC_Entity (AN))
7744 or else DT_Position (AO) = DT_Position (AN);
7745 end Is_Overriding_Alias;
7747 -- Start of processing for New_Overloaded_Entity
7750 -- We need to look for an entity that S may override. This must be a
7751 -- homonym in the current scope, so we look for the first homonym of
7752 -- S in the current scope as the starting point for the search.
7754 E := Current_Entity_In_Scope (S);
7756 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
7757 -- They are directly added to the list of primitive operations of
7758 -- Derived_Type, unless this is a rederivation in the private part
7759 -- of an operation that was already derived in the visible part of
7760 -- the current package.
7762 if Ada_Version >= Ada_2005
7763 and then Present (Derived_Type)
7764 and then Present (Alias (S))
7765 and then Is_Dispatching_Operation (Alias (S))
7766 and then Present (Find_Dispatching_Type (Alias (S)))
7767 and then Is_Interface (Find_Dispatching_Type (Alias (S)))
7769 -- For private types, when the full-view is processed we propagate to
7770 -- the full view the non-overridden entities whose attribute "alias"
7771 -- references an interface primitive. These entities were added by
7772 -- Derive_Subprograms to ensure that interface primitives are
7775 -- Inside_Freeze_Actions is non zero when S corresponds with an
7776 -- internal entity that links an interface primitive with its
7777 -- covering primitive through attribute Interface_Alias (see
7778 -- Add_Internal_Interface_Entities)
7780 if Inside_Freezing_Actions = 0
7781 and then Is_Package_Or_Generic_Package (Current_Scope)
7782 and then In_Private_Part (Current_Scope)
7783 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
7784 and then Nkind (Parent (S)) = N_Full_Type_Declaration
7785 and then Full_View (Defining_Identifier (Parent (E)))
7786 = Defining_Identifier (Parent (S))
7787 and then Alias (E) = Alias (S)
7789 Check_Operation_From_Private_View (S, E);
7790 Set_Is_Dispatching_Operation (S);
7795 Enter_Overloaded_Entity (S);
7796 Check_Dispatching_Operation (S, Empty);
7797 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
7803 -- If there is no homonym then this is definitely not overriding
7806 Enter_Overloaded_Entity (S);
7807 Check_Dispatching_Operation (S, Empty);
7808 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
7810 -- If subprogram has an explicit declaration, check whether it
7811 -- has an overriding indicator.
7813 if Comes_From_Source (S) then
7814 Check_Synchronized_Overriding (S, Overridden_Subp);
7815 Check_Overriding_Indicator
7816 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
7819 -- If there is a homonym that is not overloadable, then we have an
7820 -- error, except for the special cases checked explicitly below.
7822 elsif not Is_Overloadable (E) then
7824 -- Check for spurious conflict produced by a subprogram that has the
7825 -- same name as that of the enclosing generic package. The conflict
7826 -- occurs within an instance, between the subprogram and the renaming
7827 -- declaration for the package. After the subprogram, the package
7828 -- renaming declaration becomes hidden.
7830 if Ekind (E) = E_Package
7831 and then Present (Renamed_Object (E))
7832 and then Renamed_Object (E) = Current_Scope
7833 and then Nkind (Parent (Renamed_Object (E))) =
7834 N_Package_Specification
7835 and then Present (Generic_Parent (Parent (Renamed_Object (E))))
7838 Set_Is_Immediately_Visible (E, False);
7839 Enter_Overloaded_Entity (S);
7840 Set_Homonym (S, Homonym (E));
7841 Check_Dispatching_Operation (S, Empty);
7842 Check_Overriding_Indicator (S, Empty, Is_Primitive => False);
7844 -- If the subprogram is implicit it is hidden by the previous
7845 -- declaration. However if it is dispatching, it must appear in the
7846 -- dispatch table anyway, because it can be dispatched to even if it
7847 -- cannot be called directly.
7849 elsif Present (Alias (S))
7850 and then not Comes_From_Source (S)
7852 Set_Scope (S, Current_Scope);
7854 if Is_Dispatching_Operation (Alias (S)) then
7855 Check_Dispatching_Operation (S, Empty);
7861 Error_Msg_Sloc := Sloc (E);
7863 -- Generate message, with useful additional warning if in generic
7865 if Is_Generic_Unit (E) then
7866 Error_Msg_N ("previous generic unit cannot be overloaded", S);
7867 Error_Msg_N ("\& conflicts with declaration#", S);
7869 Error_Msg_N ("& conflicts with declaration#", S);
7875 -- E exists and is overloadable
7878 Check_Synchronized_Overriding (S, Overridden_Subp);
7880 -- Loop through E and its homonyms to determine if any of them is
7881 -- the candidate for overriding by S.
7883 while Present (E) loop
7885 -- Definitely not interesting if not in the current scope
7887 if Scope (E) /= Current_Scope then
7890 -- Check if we have type conformance
7892 elsif Type_Conformant (E, S) then
7894 -- If the old and new entities have the same profile and one
7895 -- is not the body of the other, then this is an error, unless
7896 -- one of them is implicitly declared.
7898 -- There are some cases when both can be implicit, for example
7899 -- when both a literal and a function that overrides it are
7900 -- inherited in a derivation, or when an inherited operation
7901 -- of a tagged full type overrides the inherited operation of
7902 -- a private extension. Ada 83 had a special rule for the
7903 -- literal case. In Ada95, the later implicit operation hides
7904 -- the former, and the literal is always the former. In the
7905 -- odd case where both are derived operations declared at the
7906 -- same point, both operations should be declared, and in that
7907 -- case we bypass the following test and proceed to the next
7908 -- part. This can only occur for certain obscure cases in
7909 -- instances, when an operation on a type derived from a formal
7910 -- private type does not override a homograph inherited from
7911 -- the actual. In subsequent derivations of such a type, the
7912 -- DT positions of these operations remain distinct, if they
7915 if Present (Alias (S))
7916 and then (No (Alias (E))
7917 or else Comes_From_Source (E)
7918 or else Is_Abstract_Subprogram (S)
7920 (Is_Dispatching_Operation (E)
7921 and then Is_Overriding_Alias (E, S)))
7922 and then Ekind (E) /= E_Enumeration_Literal
7924 -- When an derived operation is overloaded it may be due to
7925 -- the fact that the full view of a private extension
7926 -- re-inherits. It has to be dealt with.
7928 if Is_Package_Or_Generic_Package (Current_Scope)
7929 and then In_Private_Part (Current_Scope)
7931 Check_Operation_From_Private_View (S, E);
7934 -- In any case the implicit operation remains hidden by
7935 -- the existing declaration, which is overriding.
7937 Set_Is_Overriding_Operation (E);
7939 if Comes_From_Source (E) then
7940 Check_Overriding_Indicator (E, S, Is_Primitive => False);
7942 -- Indicate that E overrides the operation from which
7945 if Present (Alias (S)) then
7946 Set_Overridden_Operation (E, Alias (S));
7948 Set_Overridden_Operation (E, S);
7954 -- Within an instance, the renaming declarations for actual
7955 -- subprograms may become ambiguous, but they do not hide each
7958 elsif Ekind (E) /= E_Entry
7959 and then not Comes_From_Source (E)
7960 and then not Is_Generic_Instance (E)
7961 and then (Present (Alias (E))
7962 or else Is_Intrinsic_Subprogram (E))
7963 and then (not In_Instance
7964 or else No (Parent (E))
7965 or else Nkind (Unit_Declaration_Node (E)) /=
7966 N_Subprogram_Renaming_Declaration)
7968 -- A subprogram child unit is not allowed to override an
7969 -- inherited subprogram (10.1.1(20)).
7971 if Is_Child_Unit (S) then
7973 ("child unit overrides inherited subprogram in parent",
7978 if Is_Non_Overriding_Operation (E, S) then
7979 Enter_Overloaded_Entity (S);
7981 if No (Derived_Type)
7982 or else Is_Tagged_Type (Derived_Type)
7984 Check_Dispatching_Operation (S, Empty);
7990 -- E is a derived operation or an internal operator which
7991 -- is being overridden. Remove E from further visibility.
7992 -- Furthermore, if E is a dispatching operation, it must be
7993 -- replaced in the list of primitive operations of its type
7994 -- (see Override_Dispatching_Operation).
7996 Overridden_Subp := E;
8002 Prev := First_Entity (Current_Scope);
8003 while Present (Prev)
8004 and then Next_Entity (Prev) /= E
8009 -- It is possible for E to be in the current scope and
8010 -- yet not in the entity chain. This can only occur in a
8011 -- generic context where E is an implicit concatenation
8012 -- in the formal part, because in a generic body the
8013 -- entity chain starts with the formals.
8016 (Present (Prev) or else Chars (E) = Name_Op_Concat);
8018 -- E must be removed both from the entity_list of the
8019 -- current scope, and from the visibility chain
8021 if Debug_Flag_E then
8022 Write_Str ("Override implicit operation ");
8023 Write_Int (Int (E));
8027 -- If E is a predefined concatenation, it stands for four
8028 -- different operations. As a result, a single explicit
8029 -- declaration does not hide it. In a possible ambiguous
8030 -- situation, Disambiguate chooses the user-defined op,
8031 -- so it is correct to retain the previous internal one.
8033 if Chars (E) /= Name_Op_Concat
8034 or else Ekind (E) /= E_Operator
8036 -- For nondispatching derived operations that are
8037 -- overridden by a subprogram declared in the private
8038 -- part of a package, we retain the derived subprogram
8039 -- but mark it as not immediately visible. If the
8040 -- derived operation was declared in the visible part
8041 -- then this ensures that it will still be visible
8042 -- outside the package with the proper signature
8043 -- (calls from outside must also be directed to this
8044 -- version rather than the overriding one, unlike the
8045 -- dispatching case). Calls from inside the package
8046 -- will still resolve to the overriding subprogram
8047 -- since the derived one is marked as not visible
8048 -- within the package.
8050 -- If the private operation is dispatching, we achieve
8051 -- the overriding by keeping the implicit operation
8052 -- but setting its alias to be the overriding one. In
8053 -- this fashion the proper body is executed in all
8054 -- cases, but the original signature is used outside
8057 -- If the overriding is not in the private part, we
8058 -- remove the implicit operation altogether.
8060 if Is_Private_Declaration (S) then
8061 if not Is_Dispatching_Operation (E) then
8062 Set_Is_Immediately_Visible (E, False);
8064 -- Work done in Override_Dispatching_Operation,
8065 -- so nothing else need to be done here.
8071 -- Find predecessor of E in Homonym chain
8073 if E = Current_Entity (E) then
8076 Prev_Vis := Current_Entity (E);
8077 while Homonym (Prev_Vis) /= E loop
8078 Prev_Vis := Homonym (Prev_Vis);
8082 if Prev_Vis /= Empty then
8084 -- Skip E in the visibility chain
8086 Set_Homonym (Prev_Vis, Homonym (E));
8089 Set_Name_Entity_Id (Chars (E), Homonym (E));
8092 Set_Next_Entity (Prev, Next_Entity (E));
8094 if No (Next_Entity (Prev)) then
8095 Set_Last_Entity (Current_Scope, Prev);
8101 Enter_Overloaded_Entity (S);
8102 Set_Is_Overriding_Operation (S);
8103 Check_Overriding_Indicator (S, E, Is_Primitive => True);
8105 -- If S is a user-defined subprogram or a null procedure
8106 -- expanded to override an inherited null procedure, or a
8107 -- predefined dispatching primitive then indicate that E
8108 -- overrides the operation from which S is inherited. It
8109 -- seems odd that Overridden_Operation isn't set in all
8110 -- cases where Is_Overriding_Operation is true, but doing
8111 -- so causes infinite loops in the compiler for implicit
8112 -- overriding subprograms. ???
8114 if Comes_From_Source (S)
8116 (Present (Parent (S))
8118 Nkind (Parent (S)) = N_Procedure_Specification
8120 Null_Present (Parent (S)))
8122 (Present (Alias (E))
8124 Is_Predefined_Dispatching_Operation (Alias (E)))
8126 if Present (Alias (E)) then
8127 Set_Overridden_Operation (S, Alias (E));
8129 Set_Overridden_Operation (S, E);
8133 if Is_Dispatching_Operation (E) then
8135 -- An overriding dispatching subprogram inherits the
8136 -- convention of the overridden subprogram (by
8139 Set_Convention (S, Convention (E));
8140 Check_Dispatching_Operation (S, E);
8143 Check_Dispatching_Operation (S, Empty);
8146 Check_For_Primitive_Subprogram
8147 (Is_Primitive_Subp, Is_Overriding => True);
8148 goto Check_Inequality;
8151 -- Apparent redeclarations in instances can occur when two
8152 -- formal types get the same actual type. The subprograms in
8153 -- in the instance are legal, even if not callable from the
8154 -- outside. Calls from within are disambiguated elsewhere.
8155 -- For dispatching operations in the visible part, the usual
8156 -- rules apply, and operations with the same profile are not
8159 elsif (In_Instance_Visible_Part
8160 and then not Is_Dispatching_Operation (E))
8161 or else In_Instance_Not_Visible
8165 -- Here we have a real error (identical profile)
8168 Error_Msg_Sloc := Sloc (E);
8170 -- Avoid cascaded errors if the entity appears in
8171 -- subsequent calls.
8173 Set_Scope (S, Current_Scope);
8175 -- Generate error, with extra useful warning for the case
8176 -- of a generic instance with no completion.
8178 if Is_Generic_Instance (S)
8179 and then not Has_Completion (E)
8182 ("instantiation cannot provide body for&", S);
8183 Error_Msg_N ("\& conflicts with declaration#", S);
8185 Error_Msg_N ("& conflicts with declaration#", S);
8192 -- If one subprogram has an access parameter and the other
8193 -- a parameter of an access type, calls to either might be
8194 -- ambiguous. Verify that parameters match except for the
8195 -- access parameter.
8197 if May_Hide_Profile then
8203 F1 := First_Formal (S);
8204 F2 := First_Formal (E);
8205 while Present (F1) and then Present (F2) loop
8206 if Is_Access_Type (Etype (F1)) then
8207 if not Is_Access_Type (Etype (F2))
8208 or else not Conforming_Types
8209 (Designated_Type (Etype (F1)),
8210 Designated_Type (Etype (F2)),
8213 May_Hide_Profile := False;
8217 not Conforming_Types
8218 (Etype (F1), Etype (F2), Type_Conformant)
8220 May_Hide_Profile := False;
8231 Error_Msg_NE ("calls to& may be ambiguous?", S, S);
8240 -- On exit, we know that S is a new entity
8242 Enter_Overloaded_Entity (S);
8243 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
8244 Check_Overriding_Indicator
8245 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
8247 -- If S is a derived operation for an untagged type then by
8248 -- definition it's not a dispatching operation (even if the parent
8249 -- operation was dispatching), so we don't call
8250 -- Check_Dispatching_Operation in that case.
8252 if No (Derived_Type)
8253 or else Is_Tagged_Type (Derived_Type)
8255 Check_Dispatching_Operation (S, Empty);
8259 -- If this is a user-defined equality operator that is not a derived
8260 -- subprogram, create the corresponding inequality. If the operation is
8261 -- dispatching, the expansion is done elsewhere, and we do not create
8262 -- an explicit inequality operation.
8264 <<Check_Inequality>>
8265 if Chars (S) = Name_Op_Eq
8266 and then Etype (S) = Standard_Boolean
8267 and then Present (Parent (S))
8268 and then not Is_Dispatching_Operation (S)
8270 Make_Inequality_Operator (S);
8272 if Ada_Version >= Ada_2012 then
8273 Check_Untagged_Equality (S);
8276 end New_Overloaded_Entity;
8278 ---------------------
8279 -- Process_Formals --
8280 ---------------------
8282 procedure Process_Formals
8284 Related_Nod : Node_Id)
8286 Param_Spec : Node_Id;
8288 Formal_Type : Entity_Id;
8292 Num_Out_Params : Nat := 0;
8293 First_Out_Param : Entity_Id := Empty;
8294 -- Used for setting Is_Only_Out_Parameter
8296 function Designates_From_With_Type (Typ : Entity_Id) return Boolean;
8297 -- Determine whether an access type designates a type coming from a
8300 function Is_Class_Wide_Default (D : Node_Id) return Boolean;
8301 -- Check whether the default has a class-wide type. After analysis the
8302 -- default has the type of the formal, so we must also check explicitly
8303 -- for an access attribute.
8305 -------------------------------
8306 -- Designates_From_With_Type --
8307 -------------------------------
8309 function Designates_From_With_Type (Typ : Entity_Id) return Boolean is
8310 Desig : Entity_Id := Typ;
8313 if Is_Access_Type (Desig) then
8314 Desig := Directly_Designated_Type (Desig);
8317 if Is_Class_Wide_Type (Desig) then
8318 Desig := Root_Type (Desig);
8322 Ekind (Desig) = E_Incomplete_Type
8323 and then From_With_Type (Desig);
8324 end Designates_From_With_Type;
8326 ---------------------------
8327 -- Is_Class_Wide_Default --
8328 ---------------------------
8330 function Is_Class_Wide_Default (D : Node_Id) return Boolean is
8332 return Is_Class_Wide_Type (Designated_Type (Etype (D)))
8333 or else (Nkind (D) = N_Attribute_Reference
8334 and then Attribute_Name (D) = Name_Access
8335 and then Is_Class_Wide_Type (Etype (Prefix (D))));
8336 end Is_Class_Wide_Default;
8338 -- Start of processing for Process_Formals
8341 -- In order to prevent premature use of the formals in the same formal
8342 -- part, the Ekind is left undefined until all default expressions are
8343 -- analyzed. The Ekind is established in a separate loop at the end.
8345 Param_Spec := First (T);
8346 while Present (Param_Spec) loop
8347 Formal := Defining_Identifier (Param_Spec);
8348 Set_Never_Set_In_Source (Formal, True);
8349 Enter_Name (Formal);
8351 -- Case of ordinary parameters
8353 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
8354 Find_Type (Parameter_Type (Param_Spec));
8355 Ptype := Parameter_Type (Param_Spec);
8357 if Ptype = Error then
8361 Formal_Type := Entity (Ptype);
8363 if Is_Incomplete_Type (Formal_Type)
8365 (Is_Class_Wide_Type (Formal_Type)
8366 and then Is_Incomplete_Type (Root_Type (Formal_Type)))
8368 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
8369 -- primitive operations, as long as their completion is
8370 -- in the same declarative part. If in the private part
8371 -- this means that the type cannot be a Taft-amendment type.
8372 -- Check is done on package exit. For access to subprograms,
8373 -- the use is legal for Taft-amendment types.
8375 if Is_Tagged_Type (Formal_Type) then
8376 if Ekind (Scope (Current_Scope)) = E_Package
8377 and then In_Private_Part (Scope (Current_Scope))
8378 and then not From_With_Type (Formal_Type)
8379 and then not Is_Class_Wide_Type (Formal_Type)
8382 (Parent (T), N_Access_Function_Definition,
8383 N_Access_Procedure_Definition)
8387 Private_Dependents (Base_Type (Formal_Type)));
8391 -- Special handling of Value_Type for CIL case
8393 elsif Is_Value_Type (Formal_Type) then
8396 elsif not Nkind_In (Parent (T), N_Access_Function_Definition,
8397 N_Access_Procedure_Definition)
8400 -- AI05-0151: Tagged incomplete types are allowed in all
8401 -- formal parts. Untagged incomplete types are not allowed
8404 if Ada_Version >= Ada_2012 then
8405 if Is_Tagged_Type (Formal_Type) then
8408 elsif Nkind_In (Parent (Parent (T)), N_Accept_Statement,
8413 ("invalid use of untagged incomplete type&",
8414 Ptype, Formal_Type);
8419 ("invalid use of incomplete type&",
8420 Param_Spec, Formal_Type);
8422 -- Further checks on the legality of incomplete types
8423 -- in formal parts are delayed until the freeze point
8424 -- of the enclosing subprogram or access to subprogram.
8428 elsif Ekind (Formal_Type) = E_Void then
8430 ("premature use of&",
8431 Parameter_Type (Param_Spec), Formal_Type);
8434 -- Ada 2005 (AI-231): Create and decorate an internal subtype
8435 -- declaration corresponding to the null-excluding type of the
8436 -- formal in the enclosing scope. Finally, replace the parameter
8437 -- type of the formal with the internal subtype.
8439 if Ada_Version >= Ada_2005
8440 and then Null_Exclusion_Present (Param_Spec)
8442 if not Is_Access_Type (Formal_Type) then
8444 ("`NOT NULL` allowed only for an access type", Param_Spec);
8447 if Can_Never_Be_Null (Formal_Type)
8448 and then Comes_From_Source (Related_Nod)
8451 ("`NOT NULL` not allowed (& already excludes null)",
8452 Param_Spec, Formal_Type);
8456 Create_Null_Excluding_Itype
8458 Related_Nod => Related_Nod,
8459 Scope_Id => Scope (Current_Scope));
8461 -- If the designated type of the itype is an itype we
8462 -- decorate it with the Has_Delayed_Freeze attribute to
8463 -- avoid problems with the backend.
8466 -- type T is access procedure;
8467 -- procedure Op (O : not null T);
8469 if Is_Itype (Directly_Designated_Type (Formal_Type)) then
8470 Set_Has_Delayed_Freeze (Formal_Type);
8475 -- An access formal type
8479 Access_Definition (Related_Nod, Parameter_Type (Param_Spec));
8481 -- No need to continue if we already notified errors
8483 if not Present (Formal_Type) then
8487 -- Ada 2005 (AI-254)
8490 AD : constant Node_Id :=
8491 Access_To_Subprogram_Definition
8492 (Parameter_Type (Param_Spec));
8494 if Present (AD) and then Protected_Present (AD) then
8496 Replace_Anonymous_Access_To_Protected_Subprogram
8502 Set_Etype (Formal, Formal_Type);
8503 Default := Expression (Param_Spec);
8505 if Present (Default) then
8506 if Out_Present (Param_Spec) then
8508 ("default initialization only allowed for IN parameters",
8512 -- Do the special preanalysis of the expression (see section on
8513 -- "Handling of Default Expressions" in the spec of package Sem).
8515 Preanalyze_Spec_Expression (Default, Formal_Type);
8517 -- An access to constant cannot be the default for
8518 -- an access parameter that is an access to variable.
8520 if Ekind (Formal_Type) = E_Anonymous_Access_Type
8521 and then not Is_Access_Constant (Formal_Type)
8522 and then Is_Access_Type (Etype (Default))
8523 and then Is_Access_Constant (Etype (Default))
8526 ("formal that is access to variable cannot be initialized " &
8527 "with an access-to-constant expression", Default);
8530 -- Check that the designated type of an access parameter's default
8531 -- is not a class-wide type unless the parameter's designated type
8532 -- is also class-wide.
8534 if Ekind (Formal_Type) = E_Anonymous_Access_Type
8535 and then not Designates_From_With_Type (Formal_Type)
8536 and then Is_Class_Wide_Default (Default)
8537 and then not Is_Class_Wide_Type (Designated_Type (Formal_Type))
8540 ("access to class-wide expression not allowed here", Default);
8543 -- Check incorrect use of dynamically tagged expressions
8545 if Is_Tagged_Type (Formal_Type) then
8546 Check_Dynamically_Tagged_Expression
8549 Related_Nod => Default);
8553 -- Ada 2005 (AI-231): Static checks
8555 if Ada_Version >= Ada_2005
8556 and then Is_Access_Type (Etype (Formal))
8557 and then Can_Never_Be_Null (Etype (Formal))
8559 Null_Exclusion_Static_Checks (Param_Spec);
8566 -- If this is the formal part of a function specification, analyze the
8567 -- subtype mark in the context where the formals are visible but not
8568 -- yet usable, and may hide outer homographs.
8570 if Nkind (Related_Nod) = N_Function_Specification then
8571 Analyze_Return_Type (Related_Nod);
8574 -- Now set the kind (mode) of each formal
8576 Param_Spec := First (T);
8577 while Present (Param_Spec) loop
8578 Formal := Defining_Identifier (Param_Spec);
8579 Set_Formal_Mode (Formal);
8581 if Ekind (Formal) = E_In_Parameter then
8582 Set_Default_Value (Formal, Expression (Param_Spec));
8584 if Present (Expression (Param_Spec)) then
8585 Default := Expression (Param_Spec);
8587 if Is_Scalar_Type (Etype (Default)) then
8589 (Parameter_Type (Param_Spec)) /= N_Access_Definition
8591 Formal_Type := Entity (Parameter_Type (Param_Spec));
8594 Formal_Type := Access_Definition
8595 (Related_Nod, Parameter_Type (Param_Spec));
8598 Apply_Scalar_Range_Check (Default, Formal_Type);
8602 elsif Ekind (Formal) = E_Out_Parameter then
8603 Num_Out_Params := Num_Out_Params + 1;
8605 if Num_Out_Params = 1 then
8606 First_Out_Param := Formal;
8609 elsif Ekind (Formal) = E_In_Out_Parameter then
8610 Num_Out_Params := Num_Out_Params + 1;
8616 if Present (First_Out_Param) and then Num_Out_Params = 1 then
8617 Set_Is_Only_Out_Parameter (First_Out_Param);
8619 end Process_Formals;
8625 procedure Process_PPCs
8627 Spec_Id : Entity_Id;
8628 Body_Id : Entity_Id)
8630 Loc : constant Source_Ptr := Sloc (N);
8635 Precond : Node_Id := Empty;
8636 -- Set non-Empty if we prepend precondition to the declarations. This
8637 -- is used to hook up inherited preconditions (adding the condition
8638 -- expression with OR ELSE, and adding the message).
8640 Inherited_Precond : Node_Id;
8641 -- Precondition inherited from parent subprogram
8643 Inherited : constant Subprogram_List :=
8644 Inherited_Subprograms (Spec_Id);
8645 -- List of subprograms inherited by this subprogram, null if no Spec_Id
8647 Plist : List_Id := No_List;
8648 -- List of generated postconditions
8650 function Grab_PPC (Pspec : Entity_Id := Empty) return Node_Id;
8651 -- Prag contains an analyzed precondition or postcondition pragma. This
8652 -- function copies the pragma, changes it to the corresponding Check
8653 -- pragma and returns the Check pragma as the result. If Pspec is non-
8654 -- empty, this is the case of inheriting a PPC, where we must change
8655 -- references to parameters of the inherited subprogram to point to the
8656 -- corresponding parameters of the current subprogram.
8662 function Grab_PPC (Pspec : Entity_Id := Empty) return Node_Id is
8663 Nam : constant Name_Id := Pragma_Name (Prag);
8668 -- Prepare map if this is the case where we have to map entities of
8669 -- arguments in the overridden subprogram to corresponding entities
8670 -- of the current subprogram.
8681 Map := New_Elmt_List;
8682 PF := First_Formal (Pspec);
8683 CF := First_Formal (Spec_Id);
8684 while Present (PF) loop
8685 Append_Elmt (PF, Map);
8686 Append_Elmt (CF, Map);
8693 -- Now we can copy the tree, doing any required substituations
8695 CP := New_Copy_Tree (Prag, Map => Map, New_Scope => Current_Scope);
8697 -- Set Analyzed to false, since we want to reanalyze the check
8698 -- procedure. Note that it is only at the outer level that we
8699 -- do this fiddling, for the spec cases, the already preanalyzed
8700 -- parameters are not affected.
8702 Set_Analyzed (CP, False);
8704 -- We also make sure Comes_From_Source is False for the copy
8706 Set_Comes_From_Source (CP, False);
8708 -- For a postcondition pragma within a generic, preserve the pragma
8709 -- for later expansion.
8711 if Nam = Name_Postcondition
8712 and then not Expander_Active
8717 -- Change copy of pragma into corresponding pragma Check
8719 Prepend_To (Pragma_Argument_Associations (CP),
8720 Make_Pragma_Argument_Association (Sloc (Prag),
8722 Make_Identifier (Loc,
8724 Set_Pragma_Identifier (CP,
8725 Make_Identifier (Sloc (Prag),
8726 Chars => Name_Check));
8728 -- If this is inherited case and the current message starts with
8729 -- "failed p", we change it to "failed inherited p...".
8731 if Present (Pspec) then
8733 Msg : constant Node_Id :=
8734 Last (Pragma_Argument_Associations (CP));
8737 if Chars (Msg) = Name_Message then
8738 String_To_Name_Buffer (Strval (Expression (Msg)));
8740 if Name_Buffer (1 .. 8) = "failed p" then
8741 Insert_Str_In_Name_Buffer ("inherited ", 8);
8743 (Expression (Last (Pragma_Argument_Associations (CP))),
8744 String_From_Name_Buffer);
8750 -- Return the check pragma
8755 -- Start of processing for Process_PPCs
8758 -- Grab preconditions from spec
8760 if Present (Spec_Id) then
8762 -- Loop through PPC pragmas from spec. Note that preconditions from
8763 -- the body will be analyzed and converted when we scan the body
8764 -- declarations below.
8766 Prag := Spec_PPC_List (Spec_Id);
8767 while Present (Prag) loop
8768 if Pragma_Name (Prag) = Name_Precondition then
8770 -- For Pre (or Precondition pragma), we simply prepend the
8771 -- pragma to the list of declarations right away so that it
8772 -- will be executed at the start of the procedure. Note that
8773 -- this processing reverses the order of the list, which is
8774 -- what we want since new entries were chained to the head of
8775 -- the list. There can be more then one precondition when we
8776 -- use pragma Precondition
8778 if not Class_Present (Prag) then
8779 Prepend (Grab_PPC, Declarations (N));
8781 -- For Pre'Class there can only be one pragma, and we save
8782 -- it in Precond for now. We will add inherited Pre'Class
8783 -- stuff before inserting this pragma in the declarations.
8785 Precond := Grab_PPC;
8789 Prag := Next_Pragma (Prag);
8792 -- Now deal with inherited preconditions
8794 for J in Inherited'Range loop
8795 Prag := Spec_PPC_List (Inherited (J));
8797 while Present (Prag) loop
8798 if Pragma_Name (Prag) = Name_Precondition
8799 and then Class_Present (Prag)
8801 Inherited_Precond := Grab_PPC (Inherited (J));
8803 -- No precondition so far, so establish this as the first
8805 if No (Precond) then
8806 Precond := Inherited_Precond;
8808 -- Here we already have a precondition, add inherited one
8811 -- Add new precondition to old one using OR ELSE
8814 New_Expr : constant Node_Id :=
8818 (Pragma_Argument_Associations
8819 (Inherited_Precond))));
8820 Old_Expr : constant Node_Id :=
8824 (Pragma_Argument_Associations
8828 if Paren_Count (Old_Expr) = 0 then
8829 Set_Paren_Count (Old_Expr, 1);
8832 if Paren_Count (New_Expr) = 0 then
8833 Set_Paren_Count (New_Expr, 1);
8837 Make_Or_Else (Sloc (Old_Expr),
8838 Left_Opnd => Relocate_Node (Old_Expr),
8839 Right_Opnd => New_Expr));
8842 -- Add new message in the form:
8844 -- failed precondition from bla
8845 -- also failed inherited precondition from bla
8848 -- Skip this if exception locations are suppressed
8850 if not Exception_Locations_Suppressed then
8852 New_Msg : constant Node_Id :=
8855 (Pragma_Argument_Associations
8856 (Inherited_Precond)));
8857 Old_Msg : constant Node_Id :=
8860 (Pragma_Argument_Associations
8863 Start_String (Strval (Old_Msg));
8864 Store_String_Chars (ASCII.LF & " also ");
8865 Store_String_Chars (Strval (New_Msg));
8866 Set_Strval (Old_Msg, End_String);
8872 Prag := Next_Pragma (Prag);
8876 -- If we have built a precondition for Pre'Class (including any
8877 -- Pre'Class aspects inherited from parent subprograms), then we
8878 -- insert this composite precondition at this stage.
8880 if Present (Precond) then
8881 Prepend (Precond, Declarations (N));
8885 -- Build postconditions procedure if needed and prepend the following
8886 -- declaration to the start of the declarations for the subprogram.
8888 -- procedure _postconditions [(_Result : resulttype)] is
8890 -- pragma Check (Postcondition, condition [,message]);
8891 -- pragma Check (Postcondition, condition [,message]);
8895 -- First we deal with the postconditions in the body
8897 if Is_Non_Empty_List (Declarations (N)) then
8899 -- Loop through declarations
8901 Prag := First (Declarations (N));
8902 while Present (Prag) loop
8903 if Nkind (Prag) = N_Pragma then
8905 -- If pragma, capture if enabled postcondition, else ignore
8907 if Pragma_Name (Prag) = Name_Postcondition
8908 and then Check_Enabled (Name_Postcondition)
8910 if Plist = No_List then
8911 Plist := Empty_List;
8916 -- If expansion is disabled, as in a generic unit, save
8917 -- pragma for later expansion.
8919 if not Expander_Active then
8920 Prepend (Grab_PPC, Declarations (N));
8922 Append (Grab_PPC, Plist);
8928 -- Not a pragma, if comes from source, then end scan
8930 elsif Comes_From_Source (Prag) then
8933 -- Skip stuff not coming from source
8941 -- Now deal with any postconditions from the spec
8943 if Present (Spec_Id) then
8945 procedure Process_Post_Conditions
8948 -- This processes the Spec_PPC_List from Spec, processing any
8949 -- postconditions from the list. If Class is True, then only
8950 -- postconditions marked with Class_Present are considered.
8951 -- The caller has checked that Spec_PPC_List is non-Empty.
8953 -----------------------------
8954 -- Process_Post_Conditions --
8955 -----------------------------
8957 procedure Process_Post_Conditions
8970 -- Loop through PPC pragmas from spec
8972 Prag := Spec_PPC_List (Spec);
8974 if Pragma_Name (Prag) = Name_Postcondition
8975 and then (not Class or else Class_Present (Prag))
8977 if Plist = No_List then
8978 Plist := Empty_List;
8981 if not Expander_Active then
8983 (Grab_PPC (Pspec), Declarations (N));
8985 Append (Grab_PPC (Pspec), Plist);
8989 Prag := Next_Pragma (Prag);
8990 exit when No (Prag);
8992 end Process_Post_Conditions;
8995 if Present (Spec_PPC_List (Spec_Id)) then
8996 Process_Post_Conditions (Spec_Id, Class => False);
8999 -- Process inherited postconditions
9001 for J in Inherited'Range loop
9002 if Present (Spec_PPC_List (Inherited (J))) then
9003 Process_Post_Conditions (Inherited (J), Class => True);
9009 -- If we had any postconditions and expansion is enabled, build
9010 -- the _Postconditions procedure.
9013 and then Expander_Active
9015 Subp := Defining_Entity (N);
9017 if Etype (Subp) /= Standard_Void_Type then
9019 Make_Parameter_Specification (Loc,
9020 Defining_Identifier =>
9021 Make_Defining_Identifier (Loc,
9022 Chars => Name_uResult),
9023 Parameter_Type => New_Occurrence_Of (Etype (Subp), Loc)));
9029 Post_Proc : constant Entity_Id :=
9030 Make_Defining_Identifier (Loc,
9031 Chars => Name_uPostconditions);
9032 -- The entity for the _Postconditions procedure
9035 Prepend_To (Declarations (N),
9036 Make_Subprogram_Body (Loc,
9038 Make_Procedure_Specification (Loc,
9039 Defining_Unit_Name => Post_Proc,
9040 Parameter_Specifications => Parms),
9042 Declarations => Empty_List,
9044 Handled_Statement_Sequence =>
9045 Make_Handled_Sequence_Of_Statements (Loc,
9046 Statements => Plist)));
9048 -- If this is a procedure, set the Postcondition_Proc attribute on
9049 -- the proper defining entity for the subprogram.
9051 if Etype (Subp) = Standard_Void_Type then
9052 if Present (Spec_Id) then
9053 Set_Postcondition_Proc (Spec_Id, Post_Proc);
9055 Set_Postcondition_Proc (Body_Id, Post_Proc);
9060 if Present (Spec_Id) then
9061 Set_Has_Postconditions (Spec_Id);
9063 Set_Has_Postconditions (Body_Id);
9068 ----------------------------
9069 -- Reference_Body_Formals --
9070 ----------------------------
9072 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is
9077 if Error_Posted (Spec) then
9081 -- Iterate over both lists. They may be of different lengths if the two
9082 -- specs are not conformant.
9084 Fs := First_Formal (Spec);
9085 Fb := First_Formal (Bod);
9086 while Present (Fs) and then Present (Fb) loop
9087 Generate_Reference (Fs, Fb, 'b');
9090 Style.Check_Identifier (Fb, Fs);
9093 Set_Spec_Entity (Fb, Fs);
9094 Set_Referenced (Fs, False);
9098 end Reference_Body_Formals;
9100 -------------------------
9101 -- Set_Actual_Subtypes --
9102 -------------------------
9104 procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is
9108 First_Stmt : Node_Id := Empty;
9109 AS_Needed : Boolean;
9112 -- If this is an empty initialization procedure, no need to create
9113 -- actual subtypes (small optimization).
9115 if Ekind (Subp) = E_Procedure
9116 and then Is_Null_Init_Proc (Subp)
9121 Formal := First_Formal (Subp);
9122 while Present (Formal) loop
9123 T := Etype (Formal);
9125 -- We never need an actual subtype for a constrained formal
9127 if Is_Constrained (T) then
9130 -- If we have unknown discriminants, then we do not need an actual
9131 -- subtype, or more accurately we cannot figure it out! Note that
9132 -- all class-wide types have unknown discriminants.
9134 elsif Has_Unknown_Discriminants (T) then
9137 -- At this stage we have an unconstrained type that may need an
9138 -- actual subtype. For sure the actual subtype is needed if we have
9139 -- an unconstrained array type.
9141 elsif Is_Array_Type (T) then
9144 -- The only other case needing an actual subtype is an unconstrained
9145 -- record type which is an IN parameter (we cannot generate actual
9146 -- subtypes for the OUT or IN OUT case, since an assignment can
9147 -- change the discriminant values. However we exclude the case of
9148 -- initialization procedures, since discriminants are handled very
9149 -- specially in this context, see the section entitled "Handling of
9150 -- Discriminants" in Einfo.
9152 -- We also exclude the case of Discrim_SO_Functions (functions used
9153 -- in front end layout mode for size/offset values), since in such
9154 -- functions only discriminants are referenced, and not only are such
9155 -- subtypes not needed, but they cannot always be generated, because
9156 -- of order of elaboration issues.
9158 elsif Is_Record_Type (T)
9159 and then Ekind (Formal) = E_In_Parameter
9160 and then Chars (Formal) /= Name_uInit
9161 and then not Is_Unchecked_Union (T)
9162 and then not Is_Discrim_SO_Function (Subp)
9166 -- All other cases do not need an actual subtype
9172 -- Generate actual subtypes for unconstrained arrays and
9173 -- unconstrained discriminated records.
9176 if Nkind (N) = N_Accept_Statement then
9178 -- If expansion is active, The formal is replaced by a local
9179 -- variable that renames the corresponding entry of the
9180 -- parameter block, and it is this local variable that may
9181 -- require an actual subtype.
9183 if Expander_Active then
9184 Decl := Build_Actual_Subtype (T, Renamed_Object (Formal));
9186 Decl := Build_Actual_Subtype (T, Formal);
9189 if Present (Handled_Statement_Sequence (N)) then
9191 First (Statements (Handled_Statement_Sequence (N)));
9192 Prepend (Decl, Statements (Handled_Statement_Sequence (N)));
9193 Mark_Rewrite_Insertion (Decl);
9195 -- If the accept statement has no body, there will be no
9196 -- reference to the actuals, so no need to compute actual
9203 Decl := Build_Actual_Subtype (T, Formal);
9204 Prepend (Decl, Declarations (N));
9205 Mark_Rewrite_Insertion (Decl);
9208 -- The declaration uses the bounds of an existing object, and
9209 -- therefore needs no constraint checks.
9211 Analyze (Decl, Suppress => All_Checks);
9213 -- We need to freeze manually the generated type when it is
9214 -- inserted anywhere else than in a declarative part.
9216 if Present (First_Stmt) then
9217 Insert_List_Before_And_Analyze (First_Stmt,
9218 Freeze_Entity (Defining_Identifier (Decl), N));
9221 if Nkind (N) = N_Accept_Statement
9222 and then Expander_Active
9224 Set_Actual_Subtype (Renamed_Object (Formal),
9225 Defining_Identifier (Decl));
9227 Set_Actual_Subtype (Formal, Defining_Identifier (Decl));
9231 Next_Formal (Formal);
9233 end Set_Actual_Subtypes;
9235 ---------------------
9236 -- Set_Formal_Mode --
9237 ---------------------
9239 procedure Set_Formal_Mode (Formal_Id : Entity_Id) is
9240 Spec : constant Node_Id := Parent (Formal_Id);
9243 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
9244 -- since we ensure that corresponding actuals are always valid at the
9245 -- point of the call.
9247 if Out_Present (Spec) then
9248 if Ekind (Scope (Formal_Id)) = E_Function
9249 or else Ekind (Scope (Formal_Id)) = E_Generic_Function
9251 Error_Msg_N ("functions can only have IN parameters", Spec);
9252 Set_Ekind (Formal_Id, E_In_Parameter);
9254 elsif In_Present (Spec) then
9255 Set_Ekind (Formal_Id, E_In_Out_Parameter);
9258 Set_Ekind (Formal_Id, E_Out_Parameter);
9259 Set_Never_Set_In_Source (Formal_Id, True);
9260 Set_Is_True_Constant (Formal_Id, False);
9261 Set_Current_Value (Formal_Id, Empty);
9265 Set_Ekind (Formal_Id, E_In_Parameter);
9268 -- Set Is_Known_Non_Null for access parameters since the language
9269 -- guarantees that access parameters are always non-null. We also set
9270 -- Can_Never_Be_Null, since there is no way to change the value.
9272 if Nkind (Parameter_Type (Spec)) = N_Access_Definition then
9274 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
9275 -- null; In Ada 2005, only if then null_exclusion is explicit.
9277 if Ada_Version < Ada_2005
9278 or else Can_Never_Be_Null (Etype (Formal_Id))
9280 Set_Is_Known_Non_Null (Formal_Id);
9281 Set_Can_Never_Be_Null (Formal_Id);
9284 -- Ada 2005 (AI-231): Null-exclusion access subtype
9286 elsif Is_Access_Type (Etype (Formal_Id))
9287 and then Can_Never_Be_Null (Etype (Formal_Id))
9289 Set_Is_Known_Non_Null (Formal_Id);
9292 Set_Mechanism (Formal_Id, Default_Mechanism);
9293 Set_Formal_Validity (Formal_Id);
9294 end Set_Formal_Mode;
9296 -------------------------
9297 -- Set_Formal_Validity --
9298 -------------------------
9300 procedure Set_Formal_Validity (Formal_Id : Entity_Id) is
9302 -- If no validity checking, then we cannot assume anything about the
9303 -- validity of parameters, since we do not know there is any checking
9304 -- of the validity on the call side.
9306 if not Validity_Checks_On then
9309 -- If validity checking for parameters is enabled, this means we are
9310 -- not supposed to make any assumptions about argument values.
9312 elsif Validity_Check_Parameters then
9315 -- If we are checking in parameters, we will assume that the caller is
9316 -- also checking parameters, so we can assume the parameter is valid.
9318 elsif Ekind (Formal_Id) = E_In_Parameter
9319 and then Validity_Check_In_Params
9321 Set_Is_Known_Valid (Formal_Id, True);
9323 -- Similar treatment for IN OUT parameters
9325 elsif Ekind (Formal_Id) = E_In_Out_Parameter
9326 and then Validity_Check_In_Out_Params
9328 Set_Is_Known_Valid (Formal_Id, True);
9330 end Set_Formal_Validity;
9332 ------------------------
9333 -- Subtype_Conformant --
9334 ------------------------
9336 function Subtype_Conformant
9337 (New_Id : Entity_Id;
9339 Skip_Controlling_Formals : Boolean := False) return Boolean
9343 Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result,
9344 Skip_Controlling_Formals => Skip_Controlling_Formals);
9346 end Subtype_Conformant;
9348 ---------------------
9349 -- Type_Conformant --
9350 ---------------------
9352 function Type_Conformant
9353 (New_Id : Entity_Id;
9355 Skip_Controlling_Formals : Boolean := False) return Boolean
9359 May_Hide_Profile := False;
9362 (New_Id, Old_Id, Type_Conformant, False, Result,
9363 Skip_Controlling_Formals => Skip_Controlling_Formals);
9365 end Type_Conformant;
9367 -------------------------------
9368 -- Valid_Operator_Definition --
9369 -------------------------------
9371 procedure Valid_Operator_Definition (Designator : Entity_Id) is
9374 Id : constant Name_Id := Chars (Designator);
9378 F := First_Formal (Designator);
9379 while Present (F) loop
9382 if Present (Default_Value (F)) then
9384 ("default values not allowed for operator parameters",
9391 -- Verify that user-defined operators have proper number of arguments
9392 -- First case of operators which can only be unary
9395 or else Id = Name_Op_Abs
9399 -- Case of operators which can be unary or binary
9401 elsif Id = Name_Op_Add
9402 or Id = Name_Op_Subtract
9404 N_OK := (N in 1 .. 2);
9406 -- All other operators can only be binary
9414 ("incorrect number of arguments for operator", Designator);
9418 and then Base_Type (Etype (Designator)) = Standard_Boolean
9419 and then not Is_Intrinsic_Subprogram (Designator)
9422 ("explicit definition of inequality not allowed", Designator);
9424 end Valid_Operator_Definition;