1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Expander; use Expander;
33 with Exp_Ch6; use Exp_Ch6;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Ch9; use Exp_Ch9;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Fname; use Fname;
39 with Freeze; use Freeze;
40 with Itypes; use Itypes;
41 with Lib.Xref; use Lib.Xref;
42 with Layout; use Layout;
43 with Namet; use Namet;
45 with Nlists; use Nlists;
46 with Nmake; use Nmake;
48 with Output; use Output;
49 with Rtsfind; use Rtsfind;
51 with Sem_Cat; use Sem_Cat;
52 with Sem_Ch3; use Sem_Ch3;
53 with Sem_Ch4; use Sem_Ch4;
54 with Sem_Ch5; use Sem_Ch5;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Ch10; use Sem_Ch10;
57 with Sem_Ch12; use Sem_Ch12;
58 with Sem_Disp; use Sem_Disp;
59 with Sem_Dist; use Sem_Dist;
60 with Sem_Elim; use Sem_Elim;
61 with Sem_Eval; use Sem_Eval;
62 with Sem_Mech; use Sem_Mech;
63 with Sem_Prag; use Sem_Prag;
64 with Sem_Res; use Sem_Res;
65 with Sem_Util; use Sem_Util;
66 with Sem_Type; use Sem_Type;
67 with Sem_Warn; use Sem_Warn;
68 with Sinput; use Sinput;
69 with Stand; use Stand;
70 with Sinfo; use Sinfo;
71 with Sinfo.CN; use Sinfo.CN;
72 with Snames; use Snames;
73 with Stringt; use Stringt;
75 with Stylesw; use Stylesw;
76 with Tbuild; use Tbuild;
77 with Uintp; use Uintp;
78 with Urealp; use Urealp;
79 with Validsw; use Validsw;
81 package body Sem_Ch6 is
83 May_Hide_Profile : Boolean := False;
84 -- This flag is used to indicate that two formals in two subprograms being
85 -- checked for conformance differ only in that one is an access parameter
86 -- while the other is of a general access type with the same designated
87 -- type. In this case, if the rest of the signatures match, a call to
88 -- either subprogram may be ambiguous, which is worth a warning. The flag
89 -- is set in Compatible_Types, and the warning emitted in
90 -- New_Overloaded_Entity.
92 -----------------------
93 -- Local Subprograms --
94 -----------------------
96 procedure Analyze_Return_Statement (N : Node_Id);
97 -- Common processing for simple_ and extended_return_statements
99 procedure Analyze_Function_Return (N : Node_Id);
100 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
101 -- applies to a [generic] function.
103 procedure Analyze_Return_Type (N : Node_Id);
104 -- Subsidiary to Process_Formals: analyze subtype mark in function
105 -- specification, in a context where the formals are visible and hide
108 procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id);
109 -- Analyze a generic subprogram body. N is the body to be analyzed, and
110 -- Gen_Id is the defining entity Id for the corresponding spec.
112 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id);
113 -- If a subprogram has pragma Inline and inlining is active, use generic
114 -- machinery to build an unexpanded body for the subprogram. This body is
115 -- subsequenty used for inline expansions at call sites. If subprogram can
116 -- be inlined (depending on size and nature of local declarations) this
117 -- function returns true. Otherwise subprogram body is treated normally.
118 -- If proper warnings are enabled and the subprogram contains a construct
119 -- that cannot be inlined, the offending construct is flagged accordingly.
121 procedure Check_Conformance
124 Ctype : Conformance_Type;
126 Conforms : out Boolean;
127 Err_Loc : Node_Id := Empty;
128 Get_Inst : Boolean := False;
129 Skip_Controlling_Formals : Boolean := False);
130 -- Given two entities, this procedure checks that the profiles associated
131 -- with these entities meet the conformance criterion given by the third
132 -- parameter. If they conform, Conforms is set True and control returns
133 -- to the caller. If they do not conform, Conforms is set to False, and
134 -- in addition, if Errmsg is True on the call, proper messages are output
135 -- to complain about the conformance failure. If Err_Loc is non_Empty
136 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
137 -- error messages are placed on the appropriate part of the construct
138 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
139 -- against a formal access-to-subprogram type so Get_Instance_Of must
142 procedure Check_Subprogram_Order (N : Node_Id);
143 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
144 -- the alpha ordering rule for N if this ordering requirement applicable.
146 procedure Check_Returns
150 Proc : Entity_Id := Empty);
151 -- Called to check for missing return statements in a function body, or for
152 -- returns present in a procedure body which has No_Return set. HSS is the
153 -- handled statement sequence for the subprogram body. This procedure
154 -- checks all flow paths to make sure they either have return (Mode = 'F',
155 -- used for functions) or do not have a return (Mode = 'P', used for
156 -- No_Return procedures). The flag Err is set if there are any control
157 -- paths not explicitly terminated by a return in the function case, and is
158 -- True otherwise. Proc is the entity for the procedure case and is used
159 -- in posting the warning message.
161 procedure Enter_Overloaded_Entity (S : Entity_Id);
162 -- This procedure makes S, a new overloaded entity, into the first visible
163 -- entity with that name.
165 procedure Install_Entity (E : Entity_Id);
166 -- Make single entity visible. Used for generic formals as well
168 function Is_Non_Overriding_Operation
170 New_E : Entity_Id) return Boolean;
171 -- Enforce the rule given in 12.3(18): a private operation in an instance
172 -- overrides an inherited operation only if the corresponding operation
173 -- was overriding in the generic. This can happen for primitive operations
174 -- of types derived (in the generic unit) from formal private or formal
177 procedure Make_Inequality_Operator (S : Entity_Id);
178 -- Create the declaration for an inequality operator that is implicitly
179 -- created by a user-defined equality operator that yields a boolean.
181 procedure May_Need_Actuals (Fun : Entity_Id);
182 -- Flag functions that can be called without parameters, i.e. those that
183 -- have no parameters, or those for which defaults exist for all parameters
185 procedure Process_PPCs
188 Body_Id : Entity_Id);
189 -- Called from Analyze_Body to deal with scanning post conditions for the
190 -- body and assembling and inserting the _postconditions procedure. N is
191 -- the node for the subprogram body and Body_Id/Spec_Id are the entities
192 -- for the body and separate spec (if there is no separate spec, Spec_Id
195 procedure Set_Formal_Validity (Formal_Id : Entity_Id);
196 -- Formal_Id is an formal parameter entity. This procedure deals with
197 -- setting the proper validity status for this entity, which depends
198 -- on the kind of parameter and the validity checking mode.
200 ------------------------------
201 -- Analyze_Return_Statement --
202 ------------------------------
204 procedure Analyze_Return_Statement (N : Node_Id) is
206 pragma Assert (Nkind_In (N, N_Simple_Return_Statement,
207 N_Extended_Return_Statement));
209 Returns_Object : constant Boolean :=
210 Nkind (N) = N_Extended_Return_Statement
212 (Nkind (N) = N_Simple_Return_Statement
213 and then Present (Expression (N)));
214 -- True if we're returning something; that is, "return <expression>;"
215 -- or "return Result : T [:= ...]". False for "return;". Used for error
216 -- checking: If Returns_Object is True, N should apply to a function
217 -- body; otherwise N should apply to a procedure body, entry body,
218 -- accept statement, or extended return statement.
220 function Find_What_It_Applies_To return Entity_Id;
221 -- Find the entity representing the innermost enclosing body, accept
222 -- statement, or extended return statement. If the result is a callable
223 -- construct or extended return statement, then this will be the value
224 -- of the Return_Applies_To attribute. Otherwise, the program is
225 -- illegal. See RM-6.5(4/2).
227 -----------------------------
228 -- Find_What_It_Applies_To --
229 -----------------------------
231 function Find_What_It_Applies_To return Entity_Id is
232 Result : Entity_Id := Empty;
235 -- Loop outward through the Scope_Stack, skipping blocks and loops
237 for J in reverse 0 .. Scope_Stack.Last loop
238 Result := Scope_Stack.Table (J).Entity;
239 exit when Ekind (Result) /= E_Block and then
240 Ekind (Result) /= E_Loop;
243 pragma Assert (Present (Result));
245 end Find_What_It_Applies_To;
247 -- Local declarations
249 Scope_Id : constant Entity_Id := Find_What_It_Applies_To;
250 Kind : constant Entity_Kind := Ekind (Scope_Id);
251 Loc : constant Source_Ptr := Sloc (N);
252 Stm_Entity : constant Entity_Id :=
254 (E_Return_Statement, Current_Scope, Loc, 'R');
256 -- Start of processing for Analyze_Return_Statement
259 Set_Return_Statement_Entity (N, Stm_Entity);
261 Set_Etype (Stm_Entity, Standard_Void_Type);
262 Set_Return_Applies_To (Stm_Entity, Scope_Id);
264 -- Place Return entity on scope stack, to simplify enforcement of 6.5
265 -- (4/2): an inner return statement will apply to this extended return.
267 if Nkind (N) = N_Extended_Return_Statement then
268 Push_Scope (Stm_Entity);
271 -- Check that pragma No_Return is obeyed
273 if No_Return (Scope_Id) then
274 Error_Msg_N ("RETURN statement not allowed (No_Return)", N);
277 -- Warn on any unassigned OUT parameters if in procedure
279 if Ekind (Scope_Id) = E_Procedure then
280 Warn_On_Unassigned_Out_Parameter (N, Scope_Id);
283 -- Check that functions return objects, and other things do not
285 if Kind = E_Function or else Kind = E_Generic_Function then
286 if not Returns_Object then
287 Error_Msg_N ("missing expression in return from function", N);
290 elsif Kind = E_Procedure or else Kind = E_Generic_Procedure then
291 if Returns_Object then
292 Error_Msg_N ("procedure cannot return value (use function)", N);
295 elsif Kind = E_Entry or else Kind = E_Entry_Family then
296 if Returns_Object then
297 if Is_Protected_Type (Scope (Scope_Id)) then
298 Error_Msg_N ("entry body cannot return value", N);
300 Error_Msg_N ("accept statement cannot return value", N);
304 elsif Kind = E_Return_Statement then
306 -- We are nested within another return statement, which must be an
307 -- extended_return_statement.
309 if Returns_Object then
311 ("extended_return_statement cannot return value; " &
312 "use `""RETURN;""`", N);
316 Error_Msg_N ("illegal context for return statement", N);
319 if Kind = E_Function or else Kind = E_Generic_Function then
320 Analyze_Function_Return (N);
323 if Nkind (N) = N_Extended_Return_Statement then
327 Kill_Current_Values (Last_Assignment_Only => True);
328 Check_Unreachable_Code (N);
329 end Analyze_Return_Statement;
331 ---------------------------------------------
332 -- Analyze_Abstract_Subprogram_Declaration --
333 ---------------------------------------------
335 procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id) is
336 Designator : constant Entity_Id :=
337 Analyze_Subprogram_Specification (Specification (N));
338 Scop : constant Entity_Id := Current_Scope;
341 Generate_Definition (Designator);
342 Set_Is_Abstract_Subprogram (Designator);
343 New_Overloaded_Entity (Designator);
344 Check_Delayed_Subprogram (Designator);
346 Set_Categorization_From_Scope (Designator, Scop);
348 if Ekind (Scope (Designator)) = E_Protected_Type then
350 ("abstract subprogram not allowed in protected type", N);
352 -- Issue a warning if the abstract subprogram is neither a dispatching
353 -- operation nor an operation that overrides an inherited subprogram or
354 -- predefined operator, since this most likely indicates a mistake.
356 elsif Warn_On_Redundant_Constructs
357 and then not Is_Dispatching_Operation (Designator)
358 and then not Is_Overriding_Operation (Designator)
359 and then (not Is_Operator_Symbol_Name (Chars (Designator))
360 or else Scop /= Scope (Etype (First_Formal (Designator))))
363 ("?abstract subprogram is not dispatching or overriding", N);
366 Generate_Reference_To_Formals (Designator);
367 end Analyze_Abstract_Subprogram_Declaration;
369 ----------------------------------------
370 -- Analyze_Extended_Return_Statement --
371 ----------------------------------------
373 procedure Analyze_Extended_Return_Statement (N : Node_Id) is
375 Analyze_Return_Statement (N);
376 end Analyze_Extended_Return_Statement;
378 ----------------------------
379 -- Analyze_Function_Call --
380 ----------------------------
382 procedure Analyze_Function_Call (N : Node_Id) is
383 P : constant Node_Id := Name (N);
384 L : constant List_Id := Parameter_Associations (N);
390 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
391 -- as B (A, X). If the rewriting is successful, the call has been
392 -- analyzed and we just return.
394 if Nkind (P) = N_Selected_Component
395 and then Name (N) /= P
396 and then Is_Rewrite_Substitution (N)
397 and then Present (Etype (N))
402 -- If error analyzing name, then set Any_Type as result type and return
404 if Etype (P) = Any_Type then
405 Set_Etype (N, Any_Type);
409 -- Otherwise analyze the parameters
413 while Present (Actual) loop
415 Check_Parameterless_Call (Actual);
421 end Analyze_Function_Call;
423 -----------------------------
424 -- Analyze_Function_Return --
425 -----------------------------
427 procedure Analyze_Function_Return (N : Node_Id) is
428 Loc : constant Source_Ptr := Sloc (N);
429 Stm_Entity : constant Entity_Id := Return_Statement_Entity (N);
430 Scope_Id : constant Entity_Id := Return_Applies_To (Stm_Entity);
432 R_Type : constant Entity_Id := Etype (Scope_Id);
433 -- Function result subtype
435 procedure Check_Limited_Return (Expr : Node_Id);
436 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
437 -- limited types. Used only for simple return statements.
438 -- Expr is the expression returned.
440 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id);
441 -- Check that the return_subtype_indication properly matches the result
442 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
444 --------------------------
445 -- Check_Limited_Return --
446 --------------------------
448 procedure Check_Limited_Return (Expr : Node_Id) is
450 -- Ada 2005 (AI-318-02): Return-by-reference types have been
451 -- removed and replaced by anonymous access results. This is an
452 -- incompatibility with Ada 95. Not clear whether this should be
453 -- enforced yet or perhaps controllable with special switch. ???
455 if Is_Limited_Type (R_Type)
456 and then Comes_From_Source (N)
457 and then not In_Instance_Body
458 and then not OK_For_Limited_Init_In_05 (Expr)
462 if Ada_Version >= Ada_05
463 and then not Debug_Flag_Dot_L
464 and then not GNAT_Mode
467 ("(Ada 2005) cannot copy object of a limited type " &
468 "(RM-2005 6.5(5.5/2))", Expr);
469 if Is_Inherently_Limited_Type (R_Type) then
471 ("\return by reference not permitted in Ada 2005", Expr);
474 -- Warn in Ada 95 mode, to give folks a heads up about this
477 -- In GNAT mode, this is just a warning, to allow it to be
478 -- evilly turned off. Otherwise it is a real error.
480 elsif Warn_On_Ada_2005_Compatibility or GNAT_Mode then
481 if Is_Inherently_Limited_Type (R_Type) then
483 ("return by reference not permitted in Ada 2005 " &
484 "(RM-2005 6.5(5.5/2))?", Expr);
487 ("cannot copy object of a limited type in Ada 2005 " &
488 "(RM-2005 6.5(5.5/2))?", Expr);
491 -- Ada 95 mode, compatibility warnings disabled
494 return; -- skip continuation messages below
498 ("\consider switching to return of access type", Expr);
499 Explain_Limited_Type (R_Type, Expr);
501 end Check_Limited_Return;
503 -------------------------------------
504 -- Check_Return_Subtype_Indication --
505 -------------------------------------
507 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id) is
508 Return_Obj : constant Node_Id := Defining_Identifier (Obj_Decl);
509 R_Stm_Type : constant Entity_Id := Etype (Return_Obj);
510 -- Subtype given in the extended return statement;
511 -- this must match R_Type.
513 Subtype_Ind : constant Node_Id :=
514 Object_Definition (Original_Node (Obj_Decl));
516 R_Type_Is_Anon_Access :
518 Ekind (R_Type) = E_Anonymous_Access_Subprogram_Type
520 Ekind (R_Type) = E_Anonymous_Access_Protected_Subprogram_Type
522 Ekind (R_Type) = E_Anonymous_Access_Type;
523 -- True if return type of the function is an anonymous access type
524 -- Can't we make Is_Anonymous_Access_Type in einfo ???
526 R_Stm_Type_Is_Anon_Access :
528 Ekind (R_Stm_Type) = E_Anonymous_Access_Subprogram_Type
530 Ekind (R_Stm_Type) = E_Anonymous_Access_Protected_Subprogram_Type
532 Ekind (R_Stm_Type) = E_Anonymous_Access_Type;
533 -- True if type of the return object is an anonymous access type
536 -- First, avoid cascade errors:
538 if Error_Posted (Obj_Decl) or else Error_Posted (Subtype_Ind) then
542 -- "return access T" case; check that the return statement also has
543 -- "access T", and that the subtypes statically match:
545 if R_Type_Is_Anon_Access then
546 if R_Stm_Type_Is_Anon_Access then
547 if Base_Type (Designated_Type (R_Stm_Type)) /=
548 Base_Type (Designated_Type (R_Type))
549 or else not Subtypes_Statically_Match (R_Stm_Type, R_Type)
552 ("subtype must statically match function result subtype",
553 Subtype_Mark (Subtype_Ind));
557 Error_Msg_N ("must use anonymous access type", Subtype_Ind);
560 -- Subtype_indication case; check that the types are the same, and
561 -- statically match if appropriate. A null exclusion may be present
562 -- on the return type, on the function specification, on the object
563 -- declaration or on the subtype itself.
565 elsif Base_Type (R_Stm_Type) = Base_Type (R_Type) then
566 if Is_Access_Type (R_Type)
568 (Can_Never_Be_Null (R_Type)
569 or else Null_Exclusion_Present (Parent (Scope_Id))) /=
570 Can_Never_Be_Null (R_Stm_Type)
573 ("subtype must statically match function result subtype",
577 if Is_Constrained (R_Type) then
578 if not Subtypes_Statically_Match (R_Stm_Type, R_Type) then
580 ("subtype must statically match function result subtype",
585 -- If the function's result type doesn't match the return object
586 -- entity's type, then we check for the case where the result type
587 -- is class-wide, and allow the declaration if the type of the object
588 -- definition matches the class-wide type. This prevents rejection
589 -- in the case where the object declaration is initialized by a call
590 -- to a build-in-place function with a specific result type and the
591 -- object entity had its type changed to that specific type. (Note
592 -- that the ARG believes that return objects should be allowed to
593 -- have a type covered by a class-wide result type in any case, so
594 -- once that relaxation is made (see AI05-32), the above check for
595 -- type compatibility should be changed to test Covers rather than
596 -- equality, and then the following special test will no longer be
599 elsif Is_Class_Wide_Type (R_Type)
601 R_Type = Etype (Object_Definition (Original_Node (Obj_Decl)))
607 ("wrong type for return_subtype_indication", Subtype_Ind);
609 end Check_Return_Subtype_Indication;
611 ---------------------
612 -- Local Variables --
613 ---------------------
617 -- Start of processing for Analyze_Function_Return
620 Set_Return_Present (Scope_Id);
622 if Nkind (N) = N_Simple_Return_Statement then
623 Expr := Expression (N);
624 Analyze_And_Resolve (Expr, R_Type);
625 Check_Limited_Return (Expr);
628 -- Analyze parts specific to extended_return_statement:
631 Obj_Decl : constant Node_Id :=
632 Last (Return_Object_Declarations (N));
634 HSS : constant Node_Id := Handled_Statement_Sequence (N);
637 Expr := Expression (Obj_Decl);
639 -- Note: The check for OK_For_Limited_Init will happen in
640 -- Analyze_Object_Declaration; we treat it as a normal
641 -- object declaration.
645 Set_Is_Return_Object (Defining_Identifier (Obj_Decl));
646 Check_Return_Subtype_Indication (Obj_Decl);
648 if Present (HSS) then
651 if Present (Exception_Handlers (HSS)) then
653 -- ???Has_Nested_Block_With_Handler needs to be set.
654 -- Probably by creating an actual N_Block_Statement.
655 -- Probably in Expand.
661 Check_References (Stm_Entity);
665 -- Case of Expr present
669 -- Defend against previous errors
671 and then Nkind (Expr) /= N_Empty
672 and then Present (Etype (Expr))
674 -- Apply constraint check. Note that this is done before the implicit
675 -- conversion of the expression done for anonymous access types to
676 -- ensure correct generation of the null-excluding check asssociated
677 -- with null-excluding expressions found in return statements.
679 Apply_Constraint_Check (Expr, R_Type);
681 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
682 -- type, apply an implicit conversion of the expression to that type
683 -- to force appropriate static and run-time accessibility checks.
685 if Ada_Version >= Ada_05
686 and then Ekind (R_Type) = E_Anonymous_Access_Type
688 Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr)));
689 Analyze_And_Resolve (Expr, R_Type);
692 -- If the result type is class-wide, then check that the return
693 -- expression's type is not declared at a deeper level than the
694 -- function (RM05-6.5(5.6/2)).
696 if Ada_Version >= Ada_05
697 and then Is_Class_Wide_Type (R_Type)
699 if Type_Access_Level (Etype (Expr)) >
700 Subprogram_Access_Level (Scope_Id)
703 ("level of return expression type is deeper than " &
704 "class-wide function!", Expr);
708 if (Is_Class_Wide_Type (Etype (Expr))
709 or else Is_Dynamically_Tagged (Expr))
710 and then not Is_Class_Wide_Type (R_Type)
713 ("dynamically tagged expression not allowed!", Expr);
716 -- ??? A real run-time accessibility check is needed in cases
717 -- involving dereferences of access parameters. For now we just
718 -- check the static cases.
720 if (Ada_Version < Ada_05 or else Debug_Flag_Dot_L)
721 and then Is_Inherently_Limited_Type (Etype (Scope_Id))
722 and then Object_Access_Level (Expr) >
723 Subprogram_Access_Level (Scope_Id)
726 Make_Raise_Program_Error (Loc,
727 Reason => PE_Accessibility_Check_Failed));
731 ("cannot return a local value by reference?", N);
733 ("\& will be raised at run time?",
734 N, Standard_Program_Error);
738 and then Nkind (Parent (Scope_Id)) = N_Function_Specification
739 and then Null_Exclusion_Present (Parent (Scope_Id))
741 Apply_Compile_Time_Constraint_Error
743 Msg => "(Ada 2005) null not allowed for "
744 & "null-excluding return?",
745 Reason => CE_Null_Not_Allowed);
748 end Analyze_Function_Return;
750 -------------------------------------
751 -- Analyze_Generic_Subprogram_Body --
752 -------------------------------------
754 procedure Analyze_Generic_Subprogram_Body
758 Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id);
759 Kind : constant Entity_Kind := Ekind (Gen_Id);
765 -- Copy body and disable expansion while analyzing the generic For a
766 -- stub, do not copy the stub (which would load the proper body), this
767 -- will be done when the proper body is analyzed.
769 if Nkind (N) /= N_Subprogram_Body_Stub then
770 New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
775 Spec := Specification (N);
777 -- Within the body of the generic, the subprogram is callable, and
778 -- behaves like the corresponding non-generic unit.
780 Body_Id := Defining_Entity (Spec);
782 if Kind = E_Generic_Procedure
783 and then Nkind (Spec) /= N_Procedure_Specification
785 Error_Msg_N ("invalid body for generic procedure ", Body_Id);
788 elsif Kind = E_Generic_Function
789 and then Nkind (Spec) /= N_Function_Specification
791 Error_Msg_N ("invalid body for generic function ", Body_Id);
795 Set_Corresponding_Body (Gen_Decl, Body_Id);
797 if Has_Completion (Gen_Id)
798 and then Nkind (Parent (N)) /= N_Subunit
800 Error_Msg_N ("duplicate generic body", N);
803 Set_Has_Completion (Gen_Id);
806 if Nkind (N) = N_Subprogram_Body_Stub then
807 Set_Ekind (Defining_Entity (Specification (N)), Kind);
809 Set_Corresponding_Spec (N, Gen_Id);
812 if Nkind (Parent (N)) = N_Compilation_Unit then
813 Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N));
816 -- Make generic parameters immediately visible in the body. They are
817 -- needed to process the formals declarations. Then make the formals
818 -- visible in a separate step.
824 First_Ent : Entity_Id;
827 First_Ent := First_Entity (Gen_Id);
830 while Present (E) and then not Is_Formal (E) loop
835 Set_Use (Generic_Formal_Declarations (Gen_Decl));
837 -- Now generic formals are visible, and the specification can be
838 -- analyzed, for subsequent conformance check.
840 Body_Id := Analyze_Subprogram_Specification (Spec);
842 -- Make formal parameters visible
846 -- E is the first formal parameter, we loop through the formals
847 -- installing them so that they will be visible.
849 Set_First_Entity (Gen_Id, E);
850 while Present (E) loop
856 -- Visible generic entity is callable within its own body
858 Set_Ekind (Gen_Id, Ekind (Body_Id));
859 Set_Ekind (Body_Id, E_Subprogram_Body);
860 Set_Convention (Body_Id, Convention (Gen_Id));
861 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Gen_Id));
862 Set_Scope (Body_Id, Scope (Gen_Id));
863 Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id);
865 if Nkind (N) = N_Subprogram_Body_Stub then
867 -- No body to analyze, so restore state of generic unit
869 Set_Ekind (Gen_Id, Kind);
870 Set_Ekind (Body_Id, Kind);
872 if Present (First_Ent) then
873 Set_First_Entity (Gen_Id, First_Ent);
880 -- If this is a compilation unit, it must be made visible explicitly,
881 -- because the compilation of the declaration, unlike other library
882 -- unit declarations, does not. If it is not a unit, the following
883 -- is redundant but harmless.
885 Set_Is_Immediately_Visible (Gen_Id);
886 Reference_Body_Formals (Gen_Id, Body_Id);
888 if Is_Child_Unit (Gen_Id) then
889 Generate_Reference (Gen_Id, Scope (Gen_Id), 'k', False);
892 Set_Actual_Subtypes (N, Current_Scope);
893 Analyze_Declarations (Declarations (N));
895 Analyze (Handled_Statement_Sequence (N));
897 Save_Global_References (Original_Node (N));
899 -- Prior to exiting the scope, include generic formals again (if any
900 -- are present) in the set of local entities.
902 if Present (First_Ent) then
903 Set_First_Entity (Gen_Id, First_Ent);
906 Check_References (Gen_Id);
909 Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope);
911 Check_Subprogram_Order (N);
913 -- Outside of its body, unit is generic again
915 Set_Ekind (Gen_Id, Kind);
916 Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False);
919 Style.Check_Identifier (Body_Id, Gen_Id);
922 end Analyze_Generic_Subprogram_Body;
924 -----------------------------
925 -- Analyze_Operator_Symbol --
926 -----------------------------
928 -- An operator symbol such as "+" or "and" may appear in context where the
929 -- literal denotes an entity name, such as "+"(x, y) or in context when it
930 -- is just a string, as in (conjunction = "or"). In these cases the parser
931 -- generates this node, and the semantics does the disambiguation. Other
932 -- such case are actuals in an instantiation, the generic unit in an
933 -- instantiation, and pragma arguments.
935 procedure Analyze_Operator_Symbol (N : Node_Id) is
936 Par : constant Node_Id := Parent (N);
939 if (Nkind (Par) = N_Function_Call
940 and then N = Name (Par))
941 or else Nkind (Par) = N_Function_Instantiation
942 or else (Nkind (Par) = N_Indexed_Component
943 and then N = Prefix (Par))
944 or else (Nkind (Par) = N_Pragma_Argument_Association
945 and then not Is_Pragma_String_Literal (Par))
946 or else Nkind (Par) = N_Subprogram_Renaming_Declaration
947 or else (Nkind (Par) = N_Attribute_Reference
948 and then Attribute_Name (Par) /= Name_Value)
950 Find_Direct_Name (N);
953 Change_Operator_Symbol_To_String_Literal (N);
956 end Analyze_Operator_Symbol;
958 -----------------------------------
959 -- Analyze_Parameter_Association --
960 -----------------------------------
962 procedure Analyze_Parameter_Association (N : Node_Id) is
964 Analyze (Explicit_Actual_Parameter (N));
965 end Analyze_Parameter_Association;
967 ----------------------------
968 -- Analyze_Procedure_Call --
969 ----------------------------
971 procedure Analyze_Procedure_Call (N : Node_Id) is
972 Loc : constant Source_Ptr := Sloc (N);
973 P : constant Node_Id := Name (N);
974 Actuals : constant List_Id := Parameter_Associations (N);
978 procedure Analyze_Call_And_Resolve;
979 -- Do Analyze and Resolve calls for procedure call
981 ------------------------------
982 -- Analyze_Call_And_Resolve --
983 ------------------------------
985 procedure Analyze_Call_And_Resolve is
987 if Nkind (N) = N_Procedure_Call_Statement then
989 Resolve (N, Standard_Void_Type);
993 end Analyze_Call_And_Resolve;
995 -- Start of processing for Analyze_Procedure_Call
998 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
999 -- a procedure call or an entry call. The prefix may denote an access
1000 -- to subprogram type, in which case an implicit dereference applies.
1001 -- If the prefix is an indexed component (without implicit defererence)
1002 -- then the construct denotes a call to a member of an entire family.
1003 -- If the prefix is a simple name, it may still denote a call to a
1004 -- parameterless member of an entry family. Resolution of these various
1005 -- interpretations is delicate.
1009 -- If this is a call of the form Obj.Op, the call may have been
1010 -- analyzed and possibly rewritten into a block, in which case
1013 if Analyzed (N) then
1017 -- If error analyzing prefix, then set Any_Type as result and return
1019 if Etype (P) = Any_Type then
1020 Set_Etype (N, Any_Type);
1024 -- Otherwise analyze the parameters
1026 if Present (Actuals) then
1027 Actual := First (Actuals);
1029 while Present (Actual) loop
1031 Check_Parameterless_Call (Actual);
1036 -- Special processing for Elab_Spec and Elab_Body calls
1038 if Nkind (P) = N_Attribute_Reference
1039 and then (Attribute_Name (P) = Name_Elab_Spec
1040 or else Attribute_Name (P) = Name_Elab_Body)
1042 if Present (Actuals) then
1044 ("no parameters allowed for this call", First (Actuals));
1048 Set_Etype (N, Standard_Void_Type);
1051 elsif Is_Entity_Name (P)
1052 and then Is_Record_Type (Etype (Entity (P)))
1053 and then Remote_AST_I_Dereference (P)
1057 elsif Is_Entity_Name (P)
1058 and then Ekind (Entity (P)) /= E_Entry_Family
1060 if Is_Access_Type (Etype (P))
1061 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1062 and then No (Actuals)
1063 and then Comes_From_Source (N)
1065 Error_Msg_N ("missing explicit dereference in call", N);
1068 Analyze_Call_And_Resolve;
1070 -- If the prefix is the simple name of an entry family, this is
1071 -- a parameterless call from within the task body itself.
1073 elsif Is_Entity_Name (P)
1074 and then Nkind (P) = N_Identifier
1075 and then Ekind (Entity (P)) = E_Entry_Family
1076 and then Present (Actuals)
1077 and then No (Next (First (Actuals)))
1079 -- Can be call to parameterless entry family. What appears to be the
1080 -- sole argument is in fact the entry index. Rewrite prefix of node
1081 -- accordingly. Source representation is unchanged by this
1085 Make_Indexed_Component (Loc,
1087 Make_Selected_Component (Loc,
1088 Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc),
1089 Selector_Name => New_Occurrence_Of (Entity (P), Loc)),
1090 Expressions => Actuals);
1091 Set_Name (N, New_N);
1092 Set_Etype (New_N, Standard_Void_Type);
1093 Set_Parameter_Associations (N, No_List);
1094 Analyze_Call_And_Resolve;
1096 elsif Nkind (P) = N_Explicit_Dereference then
1097 if Ekind (Etype (P)) = E_Subprogram_Type then
1098 Analyze_Call_And_Resolve;
1100 Error_Msg_N ("expect access to procedure in call", P);
1103 -- The name can be a selected component or an indexed component that
1104 -- yields an access to subprogram. Such a prefix is legal if the call
1105 -- has parameter associations.
1107 elsif Is_Access_Type (Etype (P))
1108 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1110 if Present (Actuals) then
1111 Analyze_Call_And_Resolve;
1113 Error_Msg_N ("missing explicit dereference in call ", N);
1116 -- If not an access to subprogram, then the prefix must resolve to the
1117 -- name of an entry, entry family, or protected operation.
1119 -- For the case of a simple entry call, P is a selected component where
1120 -- the prefix is the task and the selector name is the entry. A call to
1121 -- a protected procedure will have the same syntax. If the protected
1122 -- object contains overloaded operations, the entity may appear as a
1123 -- function, the context will select the operation whose type is Void.
1125 elsif Nkind (P) = N_Selected_Component
1126 and then (Ekind (Entity (Selector_Name (P))) = E_Entry
1128 Ekind (Entity (Selector_Name (P))) = E_Procedure
1130 Ekind (Entity (Selector_Name (P))) = E_Function)
1132 Analyze_Call_And_Resolve;
1134 elsif Nkind (P) = N_Selected_Component
1135 and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family
1136 and then Present (Actuals)
1137 and then No (Next (First (Actuals)))
1139 -- Can be call to parameterless entry family. What appears to be the
1140 -- sole argument is in fact the entry index. Rewrite prefix of node
1141 -- accordingly. Source representation is unchanged by this
1145 Make_Indexed_Component (Loc,
1146 Prefix => New_Copy (P),
1147 Expressions => Actuals);
1148 Set_Name (N, New_N);
1149 Set_Etype (New_N, Standard_Void_Type);
1150 Set_Parameter_Associations (N, No_List);
1151 Analyze_Call_And_Resolve;
1153 -- For the case of a reference to an element of an entry family, P is
1154 -- an indexed component whose prefix is a selected component (task and
1155 -- entry family), and whose index is the entry family index.
1157 elsif Nkind (P) = N_Indexed_Component
1158 and then Nkind (Prefix (P)) = N_Selected_Component
1159 and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family
1161 Analyze_Call_And_Resolve;
1163 -- If the prefix is the name of an entry family, it is a call from
1164 -- within the task body itself.
1166 elsif Nkind (P) = N_Indexed_Component
1167 and then Nkind (Prefix (P)) = N_Identifier
1168 and then Ekind (Entity (Prefix (P))) = E_Entry_Family
1171 Make_Selected_Component (Loc,
1172 Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc),
1173 Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc));
1174 Rewrite (Prefix (P), New_N);
1176 Analyze_Call_And_Resolve;
1178 -- Anything else is an error
1181 Error_Msg_N ("invalid procedure or entry call", N);
1183 end Analyze_Procedure_Call;
1185 -------------------------------------
1186 -- Analyze_Simple_Return_Statement --
1187 -------------------------------------
1189 procedure Analyze_Simple_Return_Statement (N : Node_Id) is
1191 if Present (Expression (N)) then
1192 Mark_Coextensions (N, Expression (N));
1195 Analyze_Return_Statement (N);
1196 end Analyze_Simple_Return_Statement;
1198 -------------------------
1199 -- Analyze_Return_Type --
1200 -------------------------
1202 procedure Analyze_Return_Type (N : Node_Id) is
1203 Designator : constant Entity_Id := Defining_Entity (N);
1204 Typ : Entity_Id := Empty;
1207 -- Normal case where result definition does not indicate an error
1209 if Result_Definition (N) /= Error then
1210 if Nkind (Result_Definition (N)) = N_Access_Definition then
1211 Typ := Access_Definition (N, Result_Definition (N));
1212 Set_Parent (Typ, Result_Definition (N));
1213 Set_Is_Local_Anonymous_Access (Typ);
1214 Set_Etype (Designator, Typ);
1216 -- Subtype_Mark case
1219 Find_Type (Result_Definition (N));
1220 Typ := Entity (Result_Definition (N));
1221 Set_Etype (Designator, Typ);
1223 if Ekind (Typ) = E_Incomplete_Type
1224 and then Is_Value_Type (Typ)
1228 elsif Ekind (Typ) = E_Incomplete_Type
1229 or else (Is_Class_Wide_Type (Typ)
1231 Ekind (Root_Type (Typ)) = E_Incomplete_Type)
1234 ("invalid use of incomplete type", Result_Definition (N));
1238 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1240 Null_Exclusion_Static_Checks (N);
1242 -- Case where result definition does indicate an error
1245 Set_Etype (Designator, Any_Type);
1247 end Analyze_Return_Type;
1249 -----------------------------
1250 -- Analyze_Subprogram_Body --
1251 -----------------------------
1253 -- This procedure is called for regular subprogram bodies, generic bodies,
1254 -- and for subprogram stubs of both kinds. In the case of stubs, only the
1255 -- specification matters, and is used to create a proper declaration for
1256 -- the subprogram, or to perform conformance checks.
1258 procedure Analyze_Subprogram_Body (N : Node_Id) is
1259 Loc : constant Source_Ptr := Sloc (N);
1260 Body_Spec : constant Node_Id := Specification (N);
1261 Body_Id : Entity_Id := Defining_Entity (Body_Spec);
1262 Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id);
1263 Body_Deleted : constant Boolean := False;
1264 Conformant : Boolean;
1266 Missing_Ret : Boolean;
1268 Prot_Typ : Entity_Id := Empty;
1269 Spec_Id : Entity_Id;
1270 Spec_Decl : Node_Id := Empty;
1272 Last_Real_Spec_Entity : Entity_Id := Empty;
1273 -- When we analyze a separate spec, the entity chain ends up containing
1274 -- the formals, as well as any itypes generated during analysis of the
1275 -- default expressions for parameters, or the arguments of associated
1276 -- precondition/postcondition pragmas (which are analyzed in the context
1277 -- of the spec since they have visibility on formals).
1279 -- These entities belong with the spec and not the body. However we do
1280 -- the analysis of the body in the context of the spec (again to obtain
1281 -- visibility to the formals), and all the entities generated during
1282 -- this analysis end up also chained to the entity chain of the spec.
1283 -- But they really belong to the body, and there is circuitry to move
1284 -- them from the spec to the body.
1286 -- However, when we do this move, we don't want to move the real spec
1287 -- entities (first para above) to the body. The Last_Real_Spec_Entity
1288 -- variable points to the last real spec entity, so we only move those
1289 -- chained beyond that point. It is initialized to Empty to deal with
1290 -- the case where there is no separate spec.
1292 procedure Check_Anonymous_Return;
1293 -- (Ada 2005): if a function returns an access type that denotes a task,
1294 -- or a type that contains tasks, we must create a master entity for
1295 -- the anonymous type, which typically will be used in an allocator
1296 -- in the body of the function.
1298 procedure Check_Inline_Pragma (Spec : in out Node_Id);
1299 -- Look ahead to recognize a pragma that may appear after the body.
1300 -- If there is a previous spec, check that it appears in the same
1301 -- declarative part. If the pragma is Inline_Always, perform inlining
1302 -- unconditionally, otherwise only if Front_End_Inlining is requested.
1303 -- If the body acts as a spec, and inlining is required, we create a
1304 -- subprogram declaration for it, in order to attach the body to inline.
1305 -- If pragma does not appear after the body, check whether there is
1306 -- an inline pragma before any local declarations.
1308 procedure Set_Trivial_Subprogram (N : Node_Id);
1309 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
1310 -- subprogram whose body is being analyzed. N is the statement node
1311 -- causing the flag to be set, if the following statement is a return
1312 -- of an entity, we mark the entity as set in source to suppress any
1313 -- warning on the stylized use of function stubs with a dummy return.
1315 procedure Verify_Overriding_Indicator;
1316 -- If there was a previous spec, the entity has been entered in the
1317 -- current scope previously. If the body itself carries an overriding
1318 -- indicator, check that it is consistent with the known status of the
1321 ----------------------------
1322 -- Check_Anonymous_Return --
1323 ----------------------------
1325 procedure Check_Anonymous_Return is
1330 if Present (Spec_Id) then
1336 if Ekind (Scop) = E_Function
1337 and then Ekind (Etype (Scop)) = E_Anonymous_Access_Type
1338 and then Has_Task (Designated_Type (Etype (Scop)))
1339 and then Expander_Active
1342 Make_Object_Declaration (Loc,
1343 Defining_Identifier =>
1344 Make_Defining_Identifier (Loc, Name_uMaster),
1345 Constant_Present => True,
1346 Object_Definition =>
1347 New_Reference_To (RTE (RE_Master_Id), Loc),
1349 Make_Explicit_Dereference (Loc,
1350 New_Reference_To (RTE (RE_Current_Master), Loc)));
1352 if Present (Declarations (N)) then
1353 Prepend (Decl, Declarations (N));
1355 Set_Declarations (N, New_List (Decl));
1358 Set_Master_Id (Etype (Scop), Defining_Identifier (Decl));
1359 Set_Has_Master_Entity (Scop);
1361 end Check_Anonymous_Return;
1363 -------------------------
1364 -- Check_Inline_Pragma --
1365 -------------------------
1367 procedure Check_Inline_Pragma (Spec : in out Node_Id) is
1371 function Is_Inline_Pragma (N : Node_Id) return Boolean;
1372 -- Simple predicate, used twice.
1374 -----------------------
1375 -- Is_Inline_Pragma --
1376 -----------------------
1378 function Is_Inline_Pragma (N : Node_Id) return Boolean is
1381 Nkind (N) = N_Pragma
1383 (Pragma_Name (N) = Name_Inline_Always
1386 and then Pragma_Name (N) = Name_Inline))
1389 (Expression (First (Pragma_Argument_Associations (N))))
1391 end Is_Inline_Pragma;
1393 -- Start of processing for Check_Inline_Pragma
1396 if not Expander_Active then
1400 if Is_List_Member (N)
1401 and then Present (Next (N))
1402 and then Is_Inline_Pragma (Next (N))
1406 elsif Nkind (N) /= N_Subprogram_Body_Stub
1407 and then Present (Declarations (N))
1408 and then Is_Inline_Pragma (First (Declarations (N)))
1410 Prag := First (Declarations (N));
1416 if Present (Prag) then
1417 if Present (Spec_Id) then
1418 if List_Containing (N) =
1419 List_Containing (Unit_Declaration_Node (Spec_Id))
1425 -- Create a subprogram declaration, to make treatment uniform
1428 Subp : constant Entity_Id :=
1429 Make_Defining_Identifier (Loc, Chars (Body_Id));
1430 Decl : constant Node_Id :=
1431 Make_Subprogram_Declaration (Loc,
1432 Specification => New_Copy_Tree (Specification (N)));
1434 Set_Defining_Unit_Name (Specification (Decl), Subp);
1436 if Present (First_Formal (Body_Id)) then
1437 Plist := Copy_Parameter_List (Body_Id);
1438 Set_Parameter_Specifications
1439 (Specification (Decl), Plist);
1442 Insert_Before (N, Decl);
1445 Set_Has_Pragma_Inline (Subp);
1447 if Pragma_Name (Prag) = Name_Inline_Always then
1448 Set_Is_Inlined (Subp);
1449 Set_Has_Pragma_Inline_Always (Subp);
1456 end Check_Inline_Pragma;
1458 ----------------------------
1459 -- Set_Trivial_Subprogram --
1460 ----------------------------
1462 procedure Set_Trivial_Subprogram (N : Node_Id) is
1463 Nxt : constant Node_Id := Next (N);
1466 Set_Is_Trivial_Subprogram (Body_Id);
1468 if Present (Spec_Id) then
1469 Set_Is_Trivial_Subprogram (Spec_Id);
1473 and then Nkind (Nxt) = N_Simple_Return_Statement
1474 and then No (Next (Nxt))
1475 and then Present (Expression (Nxt))
1476 and then Is_Entity_Name (Expression (Nxt))
1478 Set_Never_Set_In_Source (Entity (Expression (Nxt)), False);
1480 end Set_Trivial_Subprogram;
1482 ---------------------------------
1483 -- Verify_Overriding_Indicator --
1484 ---------------------------------
1486 procedure Verify_Overriding_Indicator is
1488 if Must_Override (Body_Spec) then
1489 if Nkind (Spec_Id) = N_Defining_Operator_Symbol
1490 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1494 elsif not Is_Overriding_Operation (Spec_Id) then
1496 ("subprogram& is not overriding", Body_Spec, Spec_Id);
1499 elsif Must_Not_Override (Body_Spec) then
1500 if Is_Overriding_Operation (Spec_Id) then
1502 ("subprogram& overrides inherited operation",
1503 Body_Spec, Spec_Id);
1505 elsif Nkind (Spec_Id) = N_Defining_Operator_Symbol
1506 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1509 ("subprogram & overrides predefined operator ",
1510 Body_Spec, Spec_Id);
1512 -- If this is not a primitive operation the overriding indicator
1513 -- is altogether illegal.
1515 elsif not Is_Primitive (Spec_Id) then
1516 Error_Msg_N ("overriding indicator only allowed " &
1517 "if subprogram is primitive",
1521 end Verify_Overriding_Indicator;
1523 -- Start of processing for Analyze_Subprogram_Body
1526 if Debug_Flag_C then
1527 Write_Str ("==== Compiling subprogram body ");
1528 Write_Name (Chars (Body_Id));
1529 Write_Str (" from ");
1530 Write_Location (Loc);
1534 Trace_Scope (N, Body_Id, " Analyze subprogram: ");
1536 -- Generic subprograms are handled separately. They always have a
1537 -- generic specification. Determine whether current scope has a
1538 -- previous declaration.
1540 -- If the subprogram body is defined within an instance of the same
1541 -- name, the instance appears as a package renaming, and will be hidden
1542 -- within the subprogram.
1544 if Present (Prev_Id)
1545 and then not Is_Overloadable (Prev_Id)
1546 and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
1547 or else Comes_From_Source (Prev_Id))
1549 if Is_Generic_Subprogram (Prev_Id) then
1551 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
1552 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
1554 Analyze_Generic_Subprogram_Body (N, Spec_Id);
1558 -- Previous entity conflicts with subprogram name. Attempting to
1559 -- enter name will post error.
1561 Enter_Name (Body_Id);
1565 -- Non-generic case, find the subprogram declaration, if one was seen,
1566 -- or enter new overloaded entity in the current scope. If the
1567 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
1568 -- part of the context of one of its subunits. No need to redo the
1571 elsif Prev_Id = Body_Id
1572 and then Has_Completion (Body_Id)
1577 Body_Id := Analyze_Subprogram_Specification (Body_Spec);
1579 if Nkind (N) = N_Subprogram_Body_Stub
1580 or else No (Corresponding_Spec (N))
1582 Spec_Id := Find_Corresponding_Spec (N);
1584 -- If this is a duplicate body, no point in analyzing it
1586 if Error_Posted (N) then
1590 -- A subprogram body should cause freezing of its own declaration,
1591 -- but if there was no previous explicit declaration, then the
1592 -- subprogram will get frozen too late (there may be code within
1593 -- the body that depends on the subprogram having been frozen,
1594 -- such as uses of extra formals), so we force it to be frozen
1595 -- here. Same holds if the body and spec are compilation units.
1597 if No (Spec_Id) then
1598 Freeze_Before (N, Body_Id);
1600 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1601 Freeze_Before (N, Spec_Id);
1604 Spec_Id := Corresponding_Spec (N);
1608 -- Do not inline any subprogram that contains nested subprograms, since
1609 -- the backend inlining circuit seems to generate uninitialized
1610 -- references in this case. We know this happens in the case of front
1611 -- end ZCX support, but it also appears it can happen in other cases as
1612 -- well. The backend often rejects attempts to inline in the case of
1613 -- nested procedures anyway, so little if anything is lost by this.
1614 -- Note that this is test is for the benefit of the back-end. There is
1615 -- a separate test for front-end inlining that also rejects nested
1618 -- Do not do this test if errors have been detected, because in some
1619 -- error cases, this code blows up, and we don't need it anyway if
1620 -- there have been errors, since we won't get to the linker anyway.
1622 if Comes_From_Source (Body_Id)
1623 and then Serious_Errors_Detected = 0
1627 P_Ent := Scope (P_Ent);
1628 exit when No (P_Ent) or else P_Ent = Standard_Standard;
1630 if Is_Subprogram (P_Ent) then
1631 Set_Is_Inlined (P_Ent, False);
1633 if Comes_From_Source (P_Ent)
1634 and then Has_Pragma_Inline (P_Ent)
1637 ("cannot inline& (nested subprogram)?",
1644 Check_Inline_Pragma (Spec_Id);
1646 -- Case of fully private operation in the body of the protected type.
1647 -- We must create a declaration for the subprogram, in order to attach
1648 -- the protected subprogram that will be used in internal calls.
1651 and then Comes_From_Source (N)
1652 and then Is_Protected_Type (Current_Scope)
1661 Formal := First_Formal (Body_Id);
1663 -- The protected operation always has at least one formal, namely
1664 -- the object itself, but it is only placed in the parameter list
1665 -- if expansion is enabled.
1668 or else Expander_Active
1670 Plist := Copy_Parameter_List (Body_Id);
1675 if Nkind (Body_Spec) = N_Procedure_Specification then
1677 Make_Procedure_Specification (Loc,
1678 Defining_Unit_Name =>
1679 Make_Defining_Identifier (Sloc (Body_Id),
1680 Chars => Chars (Body_Id)),
1681 Parameter_Specifications => Plist);
1684 Make_Function_Specification (Loc,
1685 Defining_Unit_Name =>
1686 Make_Defining_Identifier (Sloc (Body_Id),
1687 Chars => Chars (Body_Id)),
1688 Parameter_Specifications => Plist,
1689 Result_Definition =>
1690 New_Occurrence_Of (Etype (Body_Id), Loc));
1694 Make_Subprogram_Declaration (Loc,
1695 Specification => New_Spec);
1696 Insert_Before (N, Decl);
1697 Spec_Id := Defining_Unit_Name (New_Spec);
1699 -- Indicate that the entity comes from source, to ensure that
1700 -- cross-reference information is properly generated. The body
1701 -- itself is rewritten during expansion, and the body entity will
1702 -- not appear in calls to the operation.
1704 Set_Comes_From_Source (Spec_Id, True);
1706 Set_Has_Completion (Spec_Id);
1707 Set_Convention (Spec_Id, Convention_Protected);
1710 elsif Present (Spec_Id) then
1711 Spec_Decl := Unit_Declaration_Node (Spec_Id);
1712 Verify_Overriding_Indicator;
1714 -- In general, the spec will be frozen when we start analyzing the
1715 -- body. However, for internally generated operations, such as
1716 -- wrapper functions for inherited operations with controlling
1717 -- results, the spec may not have been frozen by the time we
1718 -- expand the freeze actions that include the bodies. In particular,
1719 -- extra formals for accessibility or for return-in-place may need
1720 -- to be generated. Freeze nodes, if any, are inserted before the
1723 if not Is_Frozen (Spec_Id)
1724 and then Expander_Active
1726 -- Force the generation of its freezing node to ensure proper
1727 -- management of access types in the backend.
1729 -- This is definitely needed for some cases, but it is not clear
1730 -- why, to be investigated further???
1732 Set_Has_Delayed_Freeze (Spec_Id);
1733 Insert_Actions (N, Freeze_Entity (Spec_Id, Loc));
1737 -- Place subprogram on scope stack, and make formals visible. If there
1738 -- is a spec, the visible entity remains that of the spec.
1740 if Present (Spec_Id) then
1741 Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
1743 if Is_Child_Unit (Spec_Id) then
1744 Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False);
1748 Style.Check_Identifier (Body_Id, Spec_Id);
1751 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
1752 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
1754 if Is_Abstract_Subprogram (Spec_Id) then
1755 Error_Msg_N ("an abstract subprogram cannot have a body", N);
1759 Set_Convention (Body_Id, Convention (Spec_Id));
1760 Set_Has_Completion (Spec_Id);
1762 if Is_Protected_Type (Scope (Spec_Id)) then
1763 Prot_Typ := Scope (Spec_Id);
1766 -- If this is a body generated for a renaming, do not check for
1767 -- full conformance. The check is redundant, because the spec of
1768 -- the body is a copy of the spec in the renaming declaration,
1769 -- and the test can lead to spurious errors on nested defaults.
1771 if Present (Spec_Decl)
1772 and then not Comes_From_Source (N)
1774 (Nkind (Original_Node (Spec_Decl)) =
1775 N_Subprogram_Renaming_Declaration
1776 or else (Present (Corresponding_Body (Spec_Decl))
1778 Nkind (Unit_Declaration_Node
1779 (Corresponding_Body (Spec_Decl))) =
1780 N_Subprogram_Renaming_Declaration))
1787 Fully_Conformant, True, Conformant, Body_Id);
1790 -- If the body is not fully conformant, we have to decide if we
1791 -- should analyze it or not. If it has a really messed up profile
1792 -- then we probably should not analyze it, since we will get too
1793 -- many bogus messages.
1795 -- Our decision is to go ahead in the non-fully conformant case
1796 -- only if it is at least mode conformant with the spec. Note
1797 -- that the call to Check_Fully_Conformant has issued the proper
1798 -- error messages to complain about the lack of conformance.
1801 and then not Mode_Conformant (Body_Id, Spec_Id)
1807 if Spec_Id /= Body_Id then
1808 Reference_Body_Formals (Spec_Id, Body_Id);
1811 if Nkind (N) /= N_Subprogram_Body_Stub then
1812 Set_Corresponding_Spec (N, Spec_Id);
1814 -- Ada 2005 (AI-345): If the operation is a primitive operation
1815 -- of a concurrent type, the type of the first parameter has been
1816 -- replaced with the corresponding record, which is the proper
1817 -- run-time structure to use. However, within the body there may
1818 -- be uses of the formals that depend on primitive operations
1819 -- of the type (in particular calls in prefixed form) for which
1820 -- we need the original concurrent type. The operation may have
1821 -- several controlling formals, so the replacement must be done
1824 if Comes_From_Source (Spec_Id)
1825 and then Present (First_Entity (Spec_Id))
1826 and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type
1827 and then Is_Tagged_Type (Etype (First_Entity (Spec_Id)))
1829 Present (Abstract_Interfaces (Etype (First_Entity (Spec_Id))))
1832 (Corresponding_Concurrent_Type
1833 (Etype (First_Entity (Spec_Id))))
1836 Typ : constant Entity_Id := Etype (First_Entity (Spec_Id));
1840 Form := First_Formal (Spec_Id);
1841 while Present (Form) loop
1842 if Etype (Form) = Typ then
1843 Set_Etype (Form, Corresponding_Concurrent_Type (Typ));
1851 -- Make the formals visible, and place subprogram on scope stack.
1852 -- This is also the point at which we set Last_Real_Spec_Entity
1853 -- to mark the entities which will not be moved to the body.
1855 Install_Formals (Spec_Id);
1856 Last_Real_Spec_Entity := Last_Entity (Spec_Id);
1857 Push_Scope (Spec_Id);
1859 -- Make sure that the subprogram is immediately visible. For
1860 -- child units that have no separate spec this is indispensable.
1861 -- Otherwise it is safe albeit redundant.
1863 Set_Is_Immediately_Visible (Spec_Id);
1866 Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id);
1867 Set_Ekind (Body_Id, E_Subprogram_Body);
1868 Set_Scope (Body_Id, Scope (Spec_Id));
1869 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Spec_Id));
1871 -- Case of subprogram body with no previous spec
1875 and then Comes_From_Source (Body_Id)
1876 and then not Suppress_Style_Checks (Body_Id)
1877 and then not In_Instance
1879 Style.Body_With_No_Spec (N);
1882 New_Overloaded_Entity (Body_Id);
1884 if Nkind (N) /= N_Subprogram_Body_Stub then
1885 Set_Acts_As_Spec (N);
1886 Generate_Definition (Body_Id);
1888 (Body_Id, Body_Id, 'b', Set_Ref => False, Force => True);
1889 Generate_Reference_To_Formals (Body_Id);
1890 Install_Formals (Body_Id);
1891 Push_Scope (Body_Id);
1895 -- If the return type is an anonymous access type whose designated type
1896 -- is the limited view of a class-wide type and the non-limited view is
1897 -- available, update the return type accordingly.
1899 if Ada_Version >= Ada_05
1900 and then Comes_From_Source (N)
1907 Rtyp := Etype (Current_Scope);
1909 if Ekind (Rtyp) = E_Anonymous_Access_Type then
1910 Etyp := Directly_Designated_Type (Rtyp);
1912 if Is_Class_Wide_Type (Etyp)
1913 and then From_With_Type (Etyp)
1915 Set_Directly_Designated_Type
1916 (Etype (Current_Scope), Available_View (Etyp));
1922 -- If this is the proper body of a stub, we must verify that the stub
1923 -- conforms to the body, and to the previous spec if one was present.
1924 -- we know already that the body conforms to that spec. This test is
1925 -- only required for subprograms that come from source.
1927 if Nkind (Parent (N)) = N_Subunit
1928 and then Comes_From_Source (N)
1929 and then not Error_Posted (Body_Id)
1930 and then Nkind (Corresponding_Stub (Parent (N))) =
1931 N_Subprogram_Body_Stub
1934 Old_Id : constant Entity_Id :=
1936 (Specification (Corresponding_Stub (Parent (N))));
1938 Conformant : Boolean := False;
1941 if No (Spec_Id) then
1942 Check_Fully_Conformant (Body_Id, Old_Id);
1946 (Body_Id, Old_Id, Fully_Conformant, False, Conformant);
1948 if not Conformant then
1950 -- The stub was taken to be a new declaration. Indicate
1951 -- that it lacks a body.
1953 Set_Has_Completion (Old_Id, False);
1959 Set_Has_Completion (Body_Id);
1960 Check_Eliminated (Body_Id);
1962 if Nkind (N) = N_Subprogram_Body_Stub then
1965 elsif Present (Spec_Id)
1966 and then Expander_Active
1968 (Has_Pragma_Inline_Always (Spec_Id)
1969 or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining))
1971 Build_Body_To_Inline (N, Spec_Id);
1974 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
1975 -- if its specification we have to install the private withed units.
1976 -- This holds for child units as well.
1978 if Is_Compilation_Unit (Body_Id)
1979 or else Nkind (Parent (N)) = N_Compilation_Unit
1981 Install_Private_With_Clauses (Body_Id);
1984 Check_Anonymous_Return;
1986 -- Set the Protected_Formal field of each extra formal of the protected
1987 -- subprogram to reference the corresponding extra formal of the
1988 -- subprogram that implements it. For regular formals this occurs when
1989 -- the protected subprogram's declaration is expanded, but the extra
1990 -- formals don't get created until the subprogram is frozen. We need to
1991 -- do this before analyzing the protected subprogram's body so that any
1992 -- references to the original subprogram's extra formals will be changed
1993 -- refer to the implementing subprogram's formals (see Expand_Formal).
1995 if Present (Spec_Id)
1996 and then Is_Protected_Type (Scope (Spec_Id))
1997 and then Present (Protected_Body_Subprogram (Spec_Id))
2000 Impl_Subp : constant Entity_Id :=
2001 Protected_Body_Subprogram (Spec_Id);
2002 Prot_Ext_Formal : Entity_Id := Extra_Formals (Spec_Id);
2003 Impl_Ext_Formal : Entity_Id := Extra_Formals (Impl_Subp);
2005 while Present (Prot_Ext_Formal) loop
2006 pragma Assert (Present (Impl_Ext_Formal));
2007 Set_Protected_Formal (Prot_Ext_Formal, Impl_Ext_Formal);
2008 Next_Formal_With_Extras (Prot_Ext_Formal);
2009 Next_Formal_With_Extras (Impl_Ext_Formal);
2014 -- Now we can go on to analyze the body
2016 HSS := Handled_Statement_Sequence (N);
2017 Set_Actual_Subtypes (N, Current_Scope);
2019 -- Deal with preconditions and postconditions
2021 Process_PPCs (N, Spec_Id, Body_Id);
2023 -- Add a declaration for the Protection objcect, renaming declarations
2024 -- for discriminals and privals and finally a declaration for the entry
2025 -- family index (if applicable). This form of early expansion is done
2026 -- when the Expander is active because Install_Private_Data_Declarations
2027 -- references entities which were created during regular expansion.
2030 and then Comes_From_Source (N)
2031 and then Present (Prot_Typ)
2032 and then Present (Spec_Id)
2033 and then not Is_Eliminated (Spec_Id)
2035 Install_Private_Data_Declarations
2036 (Sloc (N), Spec_Id, Prot_Typ, N, Declarations (N));
2039 -- Analyze the declarations (this call will analyze the precondition
2040 -- Check pragmas we prepended to the list, as well as the declaration
2041 -- of the _Postconditions procedure).
2043 Analyze_Declarations (Declarations (N));
2045 -- Check completion, and analyze the statements
2050 -- Deal with end of scope processing for the body
2052 Process_End_Label (HSS, 't', Current_Scope);
2054 Check_Subprogram_Order (N);
2055 Set_Analyzed (Body_Id);
2057 -- If we have a separate spec, then the analysis of the declarations
2058 -- caused the entities in the body to be chained to the spec id, but
2059 -- we want them chained to the body id. Only the formal parameters
2060 -- end up chained to the spec id in this case.
2062 if Present (Spec_Id) then
2064 -- We must conform to the categorization of our spec
2066 Validate_Categorization_Dependency (N, Spec_Id);
2068 -- And if this is a child unit, the parent units must conform
2070 if Is_Child_Unit (Spec_Id) then
2071 Validate_Categorization_Dependency
2072 (Unit_Declaration_Node (Spec_Id), Spec_Id);
2075 -- Here is where we move entities from the spec to the body
2077 -- Case where there are entities that stay with the spec
2079 if Present (Last_Real_Spec_Entity) then
2081 -- No body entities (happens when the only real spec entities
2082 -- come from precondition and postcondition pragmas)
2084 if No (Last_Entity (Body_Id)) then
2086 (Body_Id, Next_Entity (Last_Real_Spec_Entity));
2088 -- Body entities present (formals), so chain stuff past them
2092 (Last_Entity (Body_Id), Next_Entity (Last_Real_Spec_Entity));
2095 Set_Next_Entity (Last_Real_Spec_Entity, Empty);
2096 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2097 Set_Last_Entity (Spec_Id, Last_Real_Spec_Entity);
2099 -- Case where there are no spec entities, in this case there can
2100 -- be no body entities either, so just move everything.
2103 pragma Assert (No (Last_Entity (Body_Id)));
2104 Set_First_Entity (Body_Id, First_Entity (Spec_Id));
2105 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2106 Set_First_Entity (Spec_Id, Empty);
2107 Set_Last_Entity (Spec_Id, Empty);
2111 -- If function, check return statements
2113 if Nkind (Body_Spec) = N_Function_Specification then
2118 if Present (Spec_Id) then
2124 if Return_Present (Id) then
2125 Check_Returns (HSS, 'F', Missing_Ret);
2128 Set_Has_Missing_Return (Id);
2131 elsif not Is_Machine_Code_Subprogram (Id)
2132 and then not Body_Deleted
2134 Error_Msg_N ("missing RETURN statement in function body", N);
2138 -- If procedure with No_Return, check returns
2140 elsif Nkind (Body_Spec) = N_Procedure_Specification
2141 and then Present (Spec_Id)
2142 and then No_Return (Spec_Id)
2144 Check_Returns (HSS, 'P', Missing_Ret, Spec_Id);
2147 -- Now we are going to check for variables that are never modified in
2148 -- the body of the procedure. But first we deal with a special case
2149 -- where we want to modify this check. If the body of the subprogram
2150 -- starts with a raise statement or its equivalent, or if the body
2151 -- consists entirely of a null statement, then it is pretty obvious
2152 -- that it is OK to not reference the parameters. For example, this
2153 -- might be the following common idiom for a stubbed function:
2154 -- statement of the procedure raises an exception. In particular this
2155 -- deals with the common idiom of a stubbed function, which might
2156 -- appear as something like
2158 -- function F (A : Integer) return Some_Type;
2161 -- raise Program_Error;
2165 -- Here the purpose of X is simply to satisfy the annoying requirement
2166 -- in Ada that there be at least one return, and we certainly do not
2167 -- want to go posting warnings on X that it is not initialized! On
2168 -- the other hand, if X is entirely unreferenced that should still
2171 -- What we do is to detect these cases, and if we find them, flag the
2172 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
2173 -- suppress unwanted warnings. For the case of the function stub above
2174 -- we have a special test to set X as apparently assigned to suppress
2181 -- Skip initial labels (for one thing this occurs when we are in
2182 -- front end ZCX mode, but in any case it is irrelevant), and also
2183 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
2185 Stm := First (Statements (HSS));
2186 while Nkind (Stm) = N_Label
2187 or else Nkind (Stm) in N_Push_xxx_Label
2192 -- Do the test on the original statement before expansion
2195 Ostm : constant Node_Id := Original_Node (Stm);
2198 -- If explicit raise statement, turn on flag
2200 if Nkind (Ostm) = N_Raise_Statement then
2201 Set_Trivial_Subprogram (Stm);
2203 -- If null statement, and no following statemennts, turn on flag
2205 elsif Nkind (Stm) = N_Null_Statement
2206 and then Comes_From_Source (Stm)
2207 and then No (Next (Stm))
2209 Set_Trivial_Subprogram (Stm);
2211 -- Check for explicit call cases which likely raise an exception
2213 elsif Nkind (Ostm) = N_Procedure_Call_Statement then
2214 if Is_Entity_Name (Name (Ostm)) then
2216 Ent : constant Entity_Id := Entity (Name (Ostm));
2219 -- If the procedure is marked No_Return, then likely it
2220 -- raises an exception, but in any case it is not coming
2221 -- back here, so turn on the flag.
2223 if Ekind (Ent) = E_Procedure
2224 and then No_Return (Ent)
2226 Set_Trivial_Subprogram (Stm);
2228 -- If the procedure name is Raise_Exception, then also
2229 -- assume that it raises an exception. The main target
2230 -- here is Ada.Exceptions.Raise_Exception, but this name
2231 -- is pretty evocative in any context! Note that the
2232 -- procedure in Ada.Exceptions is not marked No_Return
2233 -- because of the annoying case of the null exception Id
2234 -- when operating in Ada 95 mode.
2236 elsif Chars (Ent) = Name_Raise_Exception then
2237 Set_Trivial_Subprogram (Stm);
2245 -- Check for variables that are never modified
2251 -- If there is a separate spec, then transfer Never_Set_In_Source
2252 -- flags from out parameters to the corresponding entities in the
2253 -- body. The reason we do that is we want to post error flags on
2254 -- the body entities, not the spec entities.
2256 if Present (Spec_Id) then
2257 E1 := First_Entity (Spec_Id);
2258 while Present (E1) loop
2259 if Ekind (E1) = E_Out_Parameter then
2260 E2 := First_Entity (Body_Id);
2261 while Present (E2) loop
2262 exit when Chars (E1) = Chars (E2);
2266 if Present (E2) then
2267 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
2275 -- Check references in body unless it was deleted. Note that the
2276 -- check of Body_Deleted here is not just for efficiency, it is
2277 -- necessary to avoid junk warnings on formal parameters.
2279 if not Body_Deleted then
2280 Check_References (Body_Id);
2283 end Analyze_Subprogram_Body;
2285 ------------------------------------
2286 -- Analyze_Subprogram_Declaration --
2287 ------------------------------------
2289 procedure Analyze_Subprogram_Declaration (N : Node_Id) is
2290 Designator : constant Entity_Id :=
2291 Analyze_Subprogram_Specification (Specification (N));
2292 Scop : constant Entity_Id := Current_Scope;
2294 -- Start of processing for Analyze_Subprogram_Declaration
2297 Generate_Definition (Designator);
2299 -- Check for RCI unit subprogram declarations for illegal inlined
2300 -- subprograms and subprograms having access parameter or limited
2301 -- parameter without Read and Write attributes (RM E.2.3(12-13)).
2303 Validate_RCI_Subprogram_Declaration (N);
2307 Defining_Entity (N),
2308 " Analyze subprogram spec: ");
2310 if Debug_Flag_C then
2311 Write_Str ("==== Compiling subprogram spec ");
2312 Write_Name (Chars (Designator));
2313 Write_Str (" from ");
2314 Write_Location (Sloc (N));
2318 New_Overloaded_Entity (Designator);
2319 Check_Delayed_Subprogram (Designator);
2321 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
2324 if Ada_Version >= Ada_05
2325 and then Comes_From_Source (N)
2326 and then Is_Dispatching_Operation (Designator)
2333 if Has_Controlling_Result (Designator) then
2334 Etyp := Etype (Designator);
2337 E := First_Entity (Designator);
2339 and then Is_Formal (E)
2340 and then not Is_Controlling_Formal (E)
2348 if Is_Access_Type (Etyp) then
2349 Etyp := Directly_Designated_Type (Etyp);
2352 if Is_Interface (Etyp)
2353 and then not Is_Abstract_Subprogram (Designator)
2354 and then not (Ekind (Designator) = E_Procedure
2355 and then Null_Present (Specification (N)))
2357 Error_Msg_Name_1 := Chars (Defining_Entity (N));
2359 ("(Ada 2005) interface subprogram % must be abstract or null",
2365 -- What is the following code for, it used to be
2367 -- ??? Set_Suppress_Elaboration_Checks
2368 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
2370 -- The following seems equivalent, but a bit dubious
2372 if Elaboration_Checks_Suppressed (Designator) then
2373 Set_Kill_Elaboration_Checks (Designator);
2376 if Scop /= Standard_Standard
2377 and then not Is_Child_Unit (Designator)
2379 Set_Categorization_From_Scope (Designator, Scop);
2381 -- For a compilation unit, check for library-unit pragmas
2383 Push_Scope (Designator);
2384 Set_Categorization_From_Pragmas (N);
2385 Validate_Categorization_Dependency (N, Designator);
2389 -- For a compilation unit, set body required. This flag will only be
2390 -- reset if a valid Import or Interface pragma is processed later on.
2392 if Nkind (Parent (N)) = N_Compilation_Unit then
2393 Set_Body_Required (Parent (N), True);
2395 if Ada_Version >= Ada_05
2396 and then Nkind (Specification (N)) = N_Procedure_Specification
2397 and then Null_Present (Specification (N))
2400 ("null procedure cannot be declared at library level", N);
2404 Generate_Reference_To_Formals (Designator);
2405 Check_Eliminated (Designator);
2407 -- Ada 2005: if procedure is declared with "is null" qualifier,
2408 -- it requires no body.
2410 if Nkind (Specification (N)) = N_Procedure_Specification
2411 and then Null_Present (Specification (N))
2413 Set_Has_Completion (Designator);
2414 Set_Is_Inlined (Designator);
2416 if Is_Protected_Type (Current_Scope) then
2418 ("protected operation cannot be a null procedure", N);
2421 end Analyze_Subprogram_Declaration;
2423 --------------------------------------
2424 -- Analyze_Subprogram_Specification --
2425 --------------------------------------
2427 -- Reminder: N here really is a subprogram specification (not a subprogram
2428 -- declaration). This procedure is called to analyze the specification in
2429 -- both subprogram bodies and subprogram declarations (specs).
2431 function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is
2432 Designator : constant Entity_Id := Defining_Entity (N);
2433 Formals : constant List_Id := Parameter_Specifications (N);
2435 Formal_Typ : Entity_Id;
2437 -- Start of processing for Analyze_Subprogram_Specification
2440 Generate_Definition (Designator);
2442 if Nkind (N) = N_Function_Specification then
2443 Set_Ekind (Designator, E_Function);
2444 Set_Mechanism (Designator, Default_Mechanism);
2447 Set_Ekind (Designator, E_Procedure);
2448 Set_Etype (Designator, Standard_Void_Type);
2451 -- Introduce new scope for analysis of the formals and the return type
2453 Set_Scope (Designator, Current_Scope);
2455 if Present (Formals) then
2456 Push_Scope (Designator);
2457 Process_Formals (Formals, N);
2459 -- Ada 2005 (AI-345): Allow the overriding of interface primitives
2460 -- by subprograms which belong to a concurrent type implementing an
2461 -- interface. Set the parameter type of each controlling formal to
2462 -- the corresponding record type.
2464 if Ada_Version >= Ada_05 then
2465 Formal := First_Formal (Designator);
2466 while Present (Formal) loop
2467 Formal_Typ := Etype (Formal);
2469 if (Ekind (Formal_Typ) = E_Protected_Type
2470 or else Ekind (Formal_Typ) = E_Task_Type)
2471 and then Present (Corresponding_Record_Type (Formal_Typ))
2472 and then Present (Abstract_Interfaces
2473 (Corresponding_Record_Type (Formal_Typ)))
2476 Corresponding_Record_Type (Formal_Typ));
2479 Formal := Next_Formal (Formal);
2485 elsif Nkind (N) = N_Function_Specification then
2486 Analyze_Return_Type (N);
2489 if Nkind (N) = N_Function_Specification then
2490 if Nkind (Designator) = N_Defining_Operator_Symbol then
2491 Valid_Operator_Definition (Designator);
2494 May_Need_Actuals (Designator);
2496 -- Ada 2005 (AI-251): In case of primitives associated with abstract
2497 -- interface types the following error message will be reported later
2498 -- (see Analyze_Subprogram_Declaration).
2500 if Is_Abstract_Type (Etype (Designator))
2501 and then not Is_Interface (Etype (Designator))
2502 and then Nkind (Parent (N)) /=
2503 N_Abstract_Subprogram_Declaration
2505 (Nkind (Parent (N))) /= N_Formal_Abstract_Subprogram_Declaration
2507 (Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2508 or else not Is_Entity_Name (Name (Parent (N)))
2509 or else not Is_Abstract_Subprogram
2510 (Entity (Name (Parent (N)))))
2513 ("function that returns abstract type must be abstract", N);
2518 end Analyze_Subprogram_Specification;
2520 --------------------------
2521 -- Build_Body_To_Inline --
2522 --------------------------
2524 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is
2525 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
2526 Original_Body : Node_Id;
2527 Body_To_Analyze : Node_Id;
2528 Max_Size : constant := 10;
2529 Stat_Count : Integer := 0;
2531 function Has_Excluded_Declaration (Decls : List_Id) return Boolean;
2532 -- Check for declarations that make inlining not worthwhile
2534 function Has_Excluded_Statement (Stats : List_Id) return Boolean;
2535 -- Check for statements that make inlining not worthwhile: any tasking
2536 -- statement, nested at any level. Keep track of total number of
2537 -- elementary statements, as a measure of acceptable size.
2539 function Has_Pending_Instantiation return Boolean;
2540 -- If some enclosing body contains instantiations that appear before the
2541 -- corresponding generic body, the enclosing body has a freeze node so
2542 -- that it can be elaborated after the generic itself. This might
2543 -- conflict with subsequent inlinings, so that it is unsafe to try to
2544 -- inline in such a case.
2546 function Has_Single_Return return Boolean;
2547 -- In general we cannot inline functions that return unconstrained type.
2548 -- However, we can handle such functions if all return statements return
2549 -- a local variable that is the only declaration in the body of the
2550 -- function. In that case the call can be replaced by that local
2551 -- variable as is done for other inlined calls.
2553 procedure Remove_Pragmas;
2554 -- A pragma Unreferenced or pragma Unmodified that mentions a formal
2555 -- parameter has no meaning when the body is inlined and the formals
2556 -- are rewritten. Remove it from body to inline. The analysis of the
2557 -- non-inlined body will handle the pragma properly.
2559 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean;
2560 -- If the body of the subprogram includes a call that returns an
2561 -- unconstrained type, the secondary stack is involved, and it
2562 -- is not worth inlining.
2564 ------------------------------
2565 -- Has_Excluded_Declaration --
2566 ------------------------------
2568 function Has_Excluded_Declaration (Decls : List_Id) return Boolean is
2571 function Is_Unchecked_Conversion (D : Node_Id) return Boolean;
2572 -- Nested subprograms make a given body ineligible for inlining, but
2573 -- we make an exception for instantiations of unchecked conversion.
2574 -- The body has not been analyzed yet, so check the name, and verify
2575 -- that the visible entity with that name is the predefined unit.
2577 -----------------------------
2578 -- Is_Unchecked_Conversion --
2579 -----------------------------
2581 function Is_Unchecked_Conversion (D : Node_Id) return Boolean is
2582 Id : constant Node_Id := Name (D);
2586 if Nkind (Id) = N_Identifier
2587 and then Chars (Id) = Name_Unchecked_Conversion
2589 Conv := Current_Entity (Id);
2591 elsif Nkind_In (Id, N_Selected_Component, N_Expanded_Name)
2592 and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion
2594 Conv := Current_Entity (Selector_Name (Id));
2599 return Present (Conv)
2600 and then Is_Predefined_File_Name
2601 (Unit_File_Name (Get_Source_Unit (Conv)))
2602 and then Is_Intrinsic_Subprogram (Conv);
2603 end Is_Unchecked_Conversion;
2605 -- Start of processing for Has_Excluded_Declaration
2609 while Present (D) loop
2610 if (Nkind (D) = N_Function_Instantiation
2611 and then not Is_Unchecked_Conversion (D))
2612 or else Nkind_In (D, N_Protected_Type_Declaration,
2613 N_Package_Declaration,
2614 N_Package_Instantiation,
2616 N_Procedure_Instantiation,
2617 N_Task_Type_Declaration)
2620 ("cannot inline & (non-allowed declaration)?", D, Subp);
2628 end Has_Excluded_Declaration;
2630 ----------------------------
2631 -- Has_Excluded_Statement --
2632 ----------------------------
2634 function Has_Excluded_Statement (Stats : List_Id) return Boolean is
2640 while Present (S) loop
2641 Stat_Count := Stat_Count + 1;
2643 if Nkind_In (S, N_Abort_Statement,
2644 N_Asynchronous_Select,
2645 N_Conditional_Entry_Call,
2646 N_Delay_Relative_Statement,
2647 N_Delay_Until_Statement,
2652 ("cannot inline & (non-allowed statement)?", S, Subp);
2655 elsif Nkind (S) = N_Block_Statement then
2656 if Present (Declarations (S))
2657 and then Has_Excluded_Declaration (Declarations (S))
2661 elsif Present (Handled_Statement_Sequence (S))
2664 (Exception_Handlers (Handled_Statement_Sequence (S)))
2666 Has_Excluded_Statement
2667 (Statements (Handled_Statement_Sequence (S))))
2672 elsif Nkind (S) = N_Case_Statement then
2673 E := First (Alternatives (S));
2674 while Present (E) loop
2675 if Has_Excluded_Statement (Statements (E)) then
2682 elsif Nkind (S) = N_If_Statement then
2683 if Has_Excluded_Statement (Then_Statements (S)) then
2687 if Present (Elsif_Parts (S)) then
2688 E := First (Elsif_Parts (S));
2689 while Present (E) loop
2690 if Has_Excluded_Statement (Then_Statements (E)) then
2697 if Present (Else_Statements (S))
2698 and then Has_Excluded_Statement (Else_Statements (S))
2703 elsif Nkind (S) = N_Loop_Statement
2704 and then Has_Excluded_Statement (Statements (S))
2713 end Has_Excluded_Statement;
2715 -------------------------------
2716 -- Has_Pending_Instantiation --
2717 -------------------------------
2719 function Has_Pending_Instantiation return Boolean is
2724 while Present (S) loop
2725 if Is_Compilation_Unit (S)
2726 or else Is_Child_Unit (S)
2729 elsif Ekind (S) = E_Package
2730 and then Has_Forward_Instantiation (S)
2739 end Has_Pending_Instantiation;
2741 ------------------------
2742 -- Has_Single_Return --
2743 ------------------------
2745 function Has_Single_Return return Boolean is
2746 Return_Statement : Node_Id := Empty;
2748 function Check_Return (N : Node_Id) return Traverse_Result;
2754 function Check_Return (N : Node_Id) return Traverse_Result is
2756 if Nkind (N) = N_Simple_Return_Statement then
2757 if Present (Expression (N))
2758 and then Is_Entity_Name (Expression (N))
2760 if No (Return_Statement) then
2761 Return_Statement := N;
2764 elsif Chars (Expression (N)) =
2765 Chars (Expression (Return_Statement))
2774 -- Expression has wrong form
2784 function Check_All_Returns is new Traverse_Func (Check_Return);
2786 -- Start of processing for Has_Single_Return
2789 return Check_All_Returns (N) = OK
2790 and then Present (Declarations (N))
2791 and then Present (First (Declarations (N)))
2792 and then Chars (Expression (Return_Statement)) =
2793 Chars (Defining_Identifier (First (Declarations (N))));
2794 end Has_Single_Return;
2796 --------------------
2797 -- Remove_Pragmas --
2798 --------------------
2800 procedure Remove_Pragmas is
2805 Decl := First (Declarations (Body_To_Analyze));
2806 while Present (Decl) loop
2809 if Nkind (Decl) = N_Pragma
2810 and then (Pragma_Name (Decl) = Name_Unreferenced
2812 Pragma_Name (Decl) = Name_Unmodified)
2821 --------------------------
2822 -- Uses_Secondary_Stack --
2823 --------------------------
2825 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is
2826 function Check_Call (N : Node_Id) return Traverse_Result;
2827 -- Look for function calls that return an unconstrained type
2833 function Check_Call (N : Node_Id) return Traverse_Result is
2835 if Nkind (N) = N_Function_Call
2836 and then Is_Entity_Name (Name (N))
2837 and then Is_Composite_Type (Etype (Entity (Name (N))))
2838 and then not Is_Constrained (Etype (Entity (Name (N))))
2841 ("cannot inline & (call returns unconstrained type)?",
2849 function Check_Calls is new Traverse_Func (Check_Call);
2852 return Check_Calls (Bod) = Abandon;
2853 end Uses_Secondary_Stack;
2855 -- Start of processing for Build_Body_To_Inline
2858 if Nkind (Decl) = N_Subprogram_Declaration
2859 and then Present (Body_To_Inline (Decl))
2861 return; -- Done already.
2863 -- Functions that return unconstrained composite types require
2864 -- secondary stack handling, and cannot currently be inlined, unless
2865 -- all return statements return a local variable that is the first
2866 -- local declaration in the body.
2868 elsif Ekind (Subp) = E_Function
2869 and then not Is_Scalar_Type (Etype (Subp))
2870 and then not Is_Access_Type (Etype (Subp))
2871 and then not Is_Constrained (Etype (Subp))
2873 if not Has_Single_Return then
2875 ("cannot inline & (unconstrained return type)?", N, Subp);
2879 -- Ditto for functions that return controlled types, where controlled
2880 -- actions interfere in complex ways with inlining.
2882 elsif Ekind (Subp) = E_Function
2883 and then Controlled_Type (Etype (Subp))
2886 ("cannot inline & (controlled return type)?", N, Subp);
2890 if Present (Declarations (N))
2891 and then Has_Excluded_Declaration (Declarations (N))
2896 if Present (Handled_Statement_Sequence (N)) then
2897 if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then
2899 ("cannot inline& (exception handler)?",
2900 First (Exception_Handlers (Handled_Statement_Sequence (N))),
2904 Has_Excluded_Statement
2905 (Statements (Handled_Statement_Sequence (N)))
2911 -- We do not inline a subprogram that is too large, unless it is
2912 -- marked Inline_Always. This pragma does not suppress the other
2913 -- checks on inlining (forbidden declarations, handlers, etc).
2915 if Stat_Count > Max_Size
2916 and then not Has_Pragma_Inline_Always (Subp)
2918 Cannot_Inline ("cannot inline& (body too large)?", N, Subp);
2922 if Has_Pending_Instantiation then
2924 ("cannot inline& (forward instance within enclosing body)?",
2929 -- Within an instance, the body to inline must be treated as a nested
2930 -- generic, so that the proper global references are preserved.
2933 Save_Env (Scope (Current_Scope), Scope (Current_Scope));
2934 Original_Body := Copy_Generic_Node (N, Empty, True);
2936 Original_Body := Copy_Separate_Tree (N);
2939 -- We need to capture references to the formals in order to substitute
2940 -- the actuals at the point of inlining, i.e. instantiation. To treat
2941 -- the formals as globals to the body to inline, we nest it within
2942 -- a dummy parameterless subprogram, declared within the real one.
2943 -- To avoid generating an internal name (which is never public, and
2944 -- which affects serial numbers of other generated names), we use
2945 -- an internal symbol that cannot conflict with user declarations.
2947 Set_Parameter_Specifications (Specification (Original_Body), No_List);
2948 Set_Defining_Unit_Name
2949 (Specification (Original_Body),
2950 Make_Defining_Identifier (Sloc (N), Name_uParent));
2951 Set_Corresponding_Spec (Original_Body, Empty);
2953 Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False);
2955 -- Set return type of function, which is also global and does not need
2958 if Ekind (Subp) = E_Function then
2959 Set_Result_Definition (Specification (Body_To_Analyze),
2960 New_Occurrence_Of (Etype (Subp), Sloc (N)));
2963 if No (Declarations (N)) then
2964 Set_Declarations (N, New_List (Body_To_Analyze));
2966 Append (Body_To_Analyze, Declarations (N));
2969 Expander_Mode_Save_And_Set (False);
2972 Analyze (Body_To_Analyze);
2973 Push_Scope (Defining_Entity (Body_To_Analyze));
2974 Save_Global_References (Original_Body);
2976 Remove (Body_To_Analyze);
2978 Expander_Mode_Restore;
2984 -- If secondary stk used there is no point in inlining. We have
2985 -- already issued the warning in this case, so nothing to do.
2987 if Uses_Secondary_Stack (Body_To_Analyze) then
2991 Set_Body_To_Inline (Decl, Original_Body);
2992 Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp));
2993 Set_Is_Inlined (Subp);
2994 end Build_Body_To_Inline;
3000 procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is
3002 -- Do not emit warning if this is a predefined unit which is not
3003 -- the main unit. With validity checks enabled, some predefined
3004 -- subprograms may contain nested subprograms and become ineligible
3007 if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp)))
3008 and then not In_Extended_Main_Source_Unit (Subp)
3012 elsif Has_Pragma_Inline_Always (Subp) then
3014 -- Remove last character (question mark) to make this into an error,
3015 -- because the Inline_Always pragma cannot be obeyed.
3017 Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp);
3019 elsif Ineffective_Inline_Warnings then
3020 Error_Msg_NE (Msg, N, Subp);
3024 -----------------------
3025 -- Check_Conformance --
3026 -----------------------
3028 procedure Check_Conformance
3029 (New_Id : Entity_Id;
3031 Ctype : Conformance_Type;
3033 Conforms : out Boolean;
3034 Err_Loc : Node_Id := Empty;
3035 Get_Inst : Boolean := False;
3036 Skip_Controlling_Formals : Boolean := False)
3038 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id);
3039 -- Post error message for conformance error on given node. Two messages
3040 -- are output. The first points to the previous declaration with a
3041 -- general "no conformance" message. The second is the detailed reason,
3042 -- supplied as Msg. The parameter N provide information for a possible
3043 -- & insertion in the message, and also provides the location for
3044 -- posting the message in the absence of a specified Err_Loc location.
3046 -----------------------
3047 -- Conformance_Error --
3048 -----------------------
3050 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is
3057 if No (Err_Loc) then
3063 Error_Msg_Sloc := Sloc (Old_Id);
3066 when Type_Conformant =>
3068 ("not type conformant with declaration#!", Enode);
3070 when Mode_Conformant =>
3071 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3073 ("not mode conformant with operation inherited#!",
3077 ("not mode conformant with declaration#!", Enode);
3080 when Subtype_Conformant =>
3081 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3083 ("not subtype conformant with operation inherited#!",
3087 ("not subtype conformant with declaration#!", Enode);
3090 when Fully_Conformant =>
3091 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3093 ("not fully conformant with operation inherited#!",
3097 ("not fully conformant with declaration#!", Enode);
3101 Error_Msg_NE (Msg, Enode, N);
3103 end Conformance_Error;
3107 Old_Type : constant Entity_Id := Etype (Old_Id);
3108 New_Type : constant Entity_Id := Etype (New_Id);
3109 Old_Formal : Entity_Id;
3110 New_Formal : Entity_Id;
3111 Access_Types_Match : Boolean;
3112 Old_Formal_Base : Entity_Id;
3113 New_Formal_Base : Entity_Id;
3115 -- Start of processing for Check_Conformance
3120 -- We need a special case for operators, since they don't appear
3123 if Ctype = Type_Conformant then
3124 if Ekind (New_Id) = E_Operator
3125 and then Operator_Matches_Spec (New_Id, Old_Id)
3131 -- If both are functions/operators, check return types conform
3133 if Old_Type /= Standard_Void_Type
3134 and then New_Type /= Standard_Void_Type
3136 if not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then
3137 Conformance_Error ("\return type does not match!", New_Id);
3141 -- Ada 2005 (AI-231): In case of anonymous access types check the
3142 -- null-exclusion and access-to-constant attributes match.
3144 if Ada_Version >= Ada_05
3145 and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type
3147 (Can_Never_Be_Null (Old_Type)
3148 /= Can_Never_Be_Null (New_Type)
3149 or else Is_Access_Constant (Etype (Old_Type))
3150 /= Is_Access_Constant (Etype (New_Type)))
3152 Conformance_Error ("\return type does not match!", New_Id);
3156 -- If either is a function/operator and the other isn't, error
3158 elsif Old_Type /= Standard_Void_Type
3159 or else New_Type /= Standard_Void_Type
3161 Conformance_Error ("\functions can only match functions!", New_Id);
3165 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
3166 -- If this is a renaming as body, refine error message to indicate that
3167 -- the conflict is with the original declaration. If the entity is not
3168 -- frozen, the conventions don't have to match, the one of the renamed
3169 -- entity is inherited.
3171 if Ctype >= Subtype_Conformant then
3172 if Convention (Old_Id) /= Convention (New_Id) then
3174 if not Is_Frozen (New_Id) then
3177 elsif Present (Err_Loc)
3178 and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration
3179 and then Present (Corresponding_Spec (Err_Loc))
3181 Error_Msg_Name_1 := Chars (New_Id);
3183 Name_Ada + Convention_Id'Pos (Convention (New_Id));
3185 Conformance_Error ("\prior declaration for% has convention %!");
3188 Conformance_Error ("\calling conventions do not match!");
3193 elsif Is_Formal_Subprogram (Old_Id)
3194 or else Is_Formal_Subprogram (New_Id)
3196 Conformance_Error ("\formal subprograms not allowed!");
3201 -- Deal with parameters
3203 -- Note: we use the entity information, rather than going directly
3204 -- to the specification in the tree. This is not only simpler, but
3205 -- absolutely necessary for some cases of conformance tests between
3206 -- operators, where the declaration tree simply does not exist!
3208 Old_Formal := First_Formal (Old_Id);
3209 New_Formal := First_Formal (New_Id);
3211 while Present (Old_Formal) and then Present (New_Formal) loop
3212 if Is_Controlling_Formal (Old_Formal)
3213 and then Is_Controlling_Formal (New_Formal)
3214 and then Skip_Controlling_Formals
3216 goto Skip_Controlling_Formal;
3219 if Ctype = Fully_Conformant then
3221 -- Names must match. Error message is more accurate if we do
3222 -- this before checking that the types of the formals match.
3224 if Chars (Old_Formal) /= Chars (New_Formal) then
3225 Conformance_Error ("\name & does not match!", New_Formal);
3227 -- Set error posted flag on new formal as well to stop
3228 -- junk cascaded messages in some cases.
3230 Set_Error_Posted (New_Formal);
3235 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
3236 -- case occurs whenever a subprogram is being renamed and one of its
3237 -- parameters imposes a null exclusion. For example:
3239 -- type T is null record;
3240 -- type Acc_T is access T;
3241 -- subtype Acc_T_Sub is Acc_T;
3243 -- procedure P (Obj : not null Acc_T_Sub); -- itype
3244 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
3247 Old_Formal_Base := Etype (Old_Formal);
3248 New_Formal_Base := Etype (New_Formal);
3251 Old_Formal_Base := Get_Instance_Of (Old_Formal_Base);
3252 New_Formal_Base := Get_Instance_Of (New_Formal_Base);
3255 Access_Types_Match := Ada_Version >= Ada_05
3257 -- Ensure that this rule is only applied when New_Id is a
3258 -- renaming of Old_Id.
3260 and then Nkind (Parent (Parent (New_Id))) =
3261 N_Subprogram_Renaming_Declaration
3262 and then Nkind (Name (Parent (Parent (New_Id)))) in N_Has_Entity
3263 and then Present (Entity (Name (Parent (Parent (New_Id)))))
3264 and then Entity (Name (Parent (Parent (New_Id)))) = Old_Id
3266 -- Now handle the allowed access-type case
3268 and then Is_Access_Type (Old_Formal_Base)
3269 and then Is_Access_Type (New_Formal_Base)
3271 -- The type kinds must match. The only exception occurs with
3272 -- multiple generics of the form:
3275 -- type F is private; type A is private;
3276 -- type F_Ptr is access F; type A_Ptr is access A;
3277 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
3278 -- package F_Pack is ... package A_Pack is
3279 -- package F_Inst is
3280 -- new F_Pack (A, A_Ptr, A_P);
3282 -- When checking for conformance between the parameters of A_P
3283 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
3284 -- because the compiler has transformed A_Ptr into a subtype of
3285 -- F_Ptr. We catch this case in the code below.
3287 and then (Ekind (Old_Formal_Base) = Ekind (New_Formal_Base)
3289 (Is_Generic_Type (Old_Formal_Base)
3290 and then Is_Generic_Type (New_Formal_Base)
3291 and then Is_Internal (New_Formal_Base)
3292 and then Etype (Etype (New_Formal_Base)) =
3294 and then Directly_Designated_Type (Old_Formal_Base) =
3295 Directly_Designated_Type (New_Formal_Base)
3296 and then ((Is_Itype (Old_Formal_Base)
3297 and then Can_Never_Be_Null (Old_Formal_Base))
3299 (Is_Itype (New_Formal_Base)
3300 and then Can_Never_Be_Null (New_Formal_Base)));
3302 -- Types must always match. In the visible part of an instance,
3303 -- usual overloading rules for dispatching operations apply, and
3304 -- we check base types (not the actual subtypes).
3306 if In_Instance_Visible_Part
3307 and then Is_Dispatching_Operation (New_Id)
3309 if not Conforming_Types
3310 (T1 => Base_Type (Etype (Old_Formal)),
3311 T2 => Base_Type (Etype (New_Formal)),
3313 Get_Inst => Get_Inst)
3314 and then not Access_Types_Match
3316 Conformance_Error ("\type of & does not match!", New_Formal);
3320 elsif not Conforming_Types
3321 (T1 => Old_Formal_Base,
3322 T2 => New_Formal_Base,
3324 Get_Inst => Get_Inst)
3325 and then not Access_Types_Match
3327 Conformance_Error ("\type of & does not match!", New_Formal);
3331 -- For mode conformance, mode must match
3333 if Ctype >= Mode_Conformant then
3334 if Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal) then
3335 Conformance_Error ("\mode of & does not match!", New_Formal);
3338 -- Part of mode conformance for access types is having the same
3339 -- constant modifier.
3341 elsif Access_Types_Match
3342 and then Is_Access_Constant (Old_Formal_Base) /=
3343 Is_Access_Constant (New_Formal_Base)
3346 ("\constant modifier does not match!", New_Formal);
3351 if Ctype >= Subtype_Conformant then
3353 -- Ada 2005 (AI-231): In case of anonymous access types check
3354 -- the null-exclusion and access-to-constant attributes must
3357 if Ada_Version >= Ada_05
3358 and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type
3359 and then Ekind (Etype (New_Formal)) = E_Anonymous_Access_Type
3361 (Can_Never_Be_Null (Old_Formal) /=
3362 Can_Never_Be_Null (New_Formal)
3364 Is_Access_Constant (Etype (Old_Formal)) /=
3365 Is_Access_Constant (Etype (New_Formal)))
3367 -- It is allowed to omit the null-exclusion in case of stream
3368 -- attribute subprograms. We recognize stream subprograms
3369 -- through their TSS-generated suffix.
3372 TSS_Name : constant TSS_Name_Type := Get_TSS_Name (New_Id);
3374 if TSS_Name /= TSS_Stream_Read
3375 and then TSS_Name /= TSS_Stream_Write
3376 and then TSS_Name /= TSS_Stream_Input
3377 and then TSS_Name /= TSS_Stream_Output
3380 ("\type of & does not match!", New_Formal);
3387 -- Full conformance checks
3389 if Ctype = Fully_Conformant then
3391 -- We have checked already that names match
3393 if Parameter_Mode (Old_Formal) = E_In_Parameter then
3395 -- Check default expressions for in parameters
3398 NewD : constant Boolean :=
3399 Present (Default_Value (New_Formal));
3400 OldD : constant Boolean :=
3401 Present (Default_Value (Old_Formal));
3403 if NewD or OldD then
3405 -- The old default value has been analyzed because the
3406 -- current full declaration will have frozen everything
3407 -- before. The new default value has not been analyzed,
3408 -- so analyze it now before we check for conformance.
3411 Push_Scope (New_Id);
3412 Preanalyze_Spec_Expression
3413 (Default_Value (New_Formal), Etype (New_Formal));
3417 if not (NewD and OldD)
3418 or else not Fully_Conformant_Expressions
3419 (Default_Value (Old_Formal),
3420 Default_Value (New_Formal))
3423 ("\default expression for & does not match!",
3432 -- A couple of special checks for Ada 83 mode. These checks are
3433 -- skipped if either entity is an operator in package Standard,
3434 -- or if either old or new instance is not from the source program.
3436 if Ada_Version = Ada_83
3437 and then Sloc (Old_Id) > Standard_Location
3438 and then Sloc (New_Id) > Standard_Location
3439 and then Comes_From_Source (Old_Id)
3440 and then Comes_From_Source (New_Id)
3443 Old_Param : constant Node_Id := Declaration_Node (Old_Formal);
3444 New_Param : constant Node_Id := Declaration_Node (New_Formal);
3447 -- Explicit IN must be present or absent in both cases. This
3448 -- test is required only in the full conformance case.
3450 if In_Present (Old_Param) /= In_Present (New_Param)
3451 and then Ctype = Fully_Conformant
3454 ("\(Ada 83) IN must appear in both declarations",
3459 -- Grouping (use of comma in param lists) must be the same
3460 -- This is where we catch a misconformance like:
3463 -- A : Integer; B : Integer
3465 -- which are represented identically in the tree except
3466 -- for the setting of the flags More_Ids and Prev_Ids.
3468 if More_Ids (Old_Param) /= More_Ids (New_Param)
3469 or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param)
3472 ("\grouping of & does not match!", New_Formal);
3478 -- This label is required when skipping controlling formals
3480 <<Skip_Controlling_Formal>>
3482 Next_Formal (Old_Formal);
3483 Next_Formal (New_Formal);
3486 if Present (Old_Formal) then
3487 Conformance_Error ("\too few parameters!");
3490 elsif Present (New_Formal) then
3491 Conformance_Error ("\too many parameters!", New_Formal);
3494 end Check_Conformance;
3496 -----------------------
3497 -- Check_Conventions --
3498 -----------------------
3500 procedure Check_Conventions (Typ : Entity_Id) is
3502 function Skip_Check (Op : Entity_Id) return Boolean;
3503 pragma Inline (Skip_Check);
3504 -- A small optimization: skip the predefined dispatching operations,
3505 -- since they always have the same convention. Also do not consider
3506 -- abstract primitives since those are left by an erroneous overriding.
3507 -- This function returns True for any operation that is thus exempted
3508 -- exempted from checking.
3510 procedure Check_Convention
3512 Search_From : Elmt_Id);
3513 -- Verify that the convention of inherited dispatching operation Op is
3514 -- consistent among all subprograms it overrides. In order to minimize
3515 -- the search, Search_From is utilized to designate a specific point in
3516 -- the list rather than iterating over the whole list once more.
3518 ----------------------
3519 -- Check_Convention --
3520 ----------------------
3522 procedure Check_Convention
3524 Search_From : Elmt_Id)
3526 procedure Error_Msg_Operation (Op : Entity_Id);
3527 -- Emit a continuation to an error message depicting the kind, name,
3528 -- convention and source location of subprogram Op.
3530 -------------------------
3531 -- Error_Msg_Operation --
3532 -------------------------
3534 procedure Error_Msg_Operation (Op : Entity_Id) is
3536 Error_Msg_Name_1 := Chars (Op);
3538 -- Error messages of primitive subprograms do not contain a
3539 -- convention attribute since the convention may have been first
3540 -- inherited from a parent subprogram, then changed by a pragma.
3542 if Comes_From_Source (Op) then
3543 Error_Msg_Sloc := Sloc (Op);
3545 ("\ primitive % defined #", Typ);
3548 Error_Msg_Name_2 := Get_Convention_Name (Convention (Op));
3550 if Present (Abstract_Interface_Alias (Op)) then
3551 Error_Msg_Sloc := Sloc (Abstract_Interface_Alias (Op));
3552 Error_Msg_N ("\\overridden operation % with " &
3553 "convention % defined #", Typ);
3555 else pragma Assert (Present (Alias (Op)));
3556 Error_Msg_Sloc := Sloc (Alias (Op));
3557 Error_Msg_N ("\\inherited operation % with " &
3558 "convention % defined #", Typ);
3561 end Error_Msg_Operation;
3565 Second_Prim_Op : Entity_Id;
3566 Second_Prim_Op_Elmt : Elmt_Id;
3568 -- Start of processing for Check_Convention
3571 Second_Prim_Op_Elmt := Next_Elmt (Search_From);
3572 while Present (Second_Prim_Op_Elmt) loop
3573 Second_Prim_Op := Node (Second_Prim_Op_Elmt);
3575 if not Skip_Check (Second_Prim_Op)
3576 and then Chars (Second_Prim_Op) = Chars (Op)
3577 and then Type_Conformant (Second_Prim_Op, Op)
3578 and then Convention (Second_Prim_Op) /= Convention (Op)
3581 ("inconsistent conventions in primitive operations", Typ);
3583 Error_Msg_Operation (Op);
3584 Error_Msg_Operation (Second_Prim_Op);
3586 -- Avoid cascading errors
3591 Next_Elmt (Second_Prim_Op_Elmt);
3593 end Check_Convention;
3599 function Skip_Check (Op : Entity_Id) return Boolean is
3601 return Is_Predefined_Dispatching_Operation (Op)
3602 or else Is_Abstract_Subprogram (Op);
3607 Prim_Op : Entity_Id;
3608 Prim_Op_Elmt : Elmt_Id;
3610 -- Start of processing for Check_Conventions
3613 -- The algorithm checks every overriding dispatching operation against
3614 -- all the corresponding overridden dispatching operations, detecting
3615 -- differences in coventions.
3617 Prim_Op_Elmt := First_Elmt (Primitive_Operations (Typ));
3618 while Present (Prim_Op_Elmt) loop
3619 Prim_Op := Node (Prim_Op_Elmt);
3621 -- A small optimization: skip the predefined dispatching operations
3622 -- since they always have the same convention. Also avoid processing
3623 -- of abstract primitives left from an erroneous overriding.
3625 if not Skip_Check (Prim_Op) then
3628 Search_From => Prim_Op_Elmt);
3631 Next_Elmt (Prim_Op_Elmt);
3633 end Check_Conventions;
3635 ------------------------------
3636 -- Check_Delayed_Subprogram --
3637 ------------------------------
3639 procedure Check_Delayed_Subprogram (Designator : Entity_Id) is
3642 procedure Possible_Freeze (T : Entity_Id);
3643 -- T is the type of either a formal parameter or of the return type.
3644 -- If T is not yet frozen and needs a delayed freeze, then the
3645 -- subprogram itself must be delayed.
3647 ---------------------
3648 -- Possible_Freeze --
3649 ---------------------
3651 procedure Possible_Freeze (T : Entity_Id) is
3653 if Has_Delayed_Freeze (T)
3654 and then not Is_Frozen (T)
3656 Set_Has_Delayed_Freeze (Designator);
3658 elsif Is_Access_Type (T)
3659 and then Has_Delayed_Freeze (Designated_Type (T))
3660 and then not Is_Frozen (Designated_Type (T))
3662 Set_Has_Delayed_Freeze (Designator);
3664 end Possible_Freeze;
3666 -- Start of processing for Check_Delayed_Subprogram
3669 -- Never need to freeze abstract subprogram
3671 if Ekind (Designator) /= E_Subprogram_Type
3672 and then Is_Abstract_Subprogram (Designator)
3676 -- Need delayed freeze if return type itself needs a delayed
3677 -- freeze and is not yet frozen.
3679 Possible_Freeze (Etype (Designator));
3680 Possible_Freeze (Base_Type (Etype (Designator))); -- needed ???
3682 -- Need delayed freeze if any of the formal types themselves need
3683 -- a delayed freeze and are not yet frozen.
3685 F := First_Formal (Designator);
3686 while Present (F) loop
3687 Possible_Freeze (Etype (F));
3688 Possible_Freeze (Base_Type (Etype (F))); -- needed ???
3693 -- Mark functions that return by reference. Note that it cannot be
3694 -- done for delayed_freeze subprograms because the underlying
3695 -- returned type may not be known yet (for private types)
3697 if not Has_Delayed_Freeze (Designator)
3698 and then Expander_Active
3701 Typ : constant Entity_Id := Etype (Designator);
3702 Utyp : constant Entity_Id := Underlying_Type (Typ);
3705 if Is_Inherently_Limited_Type (Typ) then
3706 Set_Returns_By_Ref (Designator);
3708 elsif Present (Utyp) and then CW_Or_Controlled_Type (Utyp) then
3709 Set_Returns_By_Ref (Designator);
3713 end Check_Delayed_Subprogram;
3715 ------------------------------------
3716 -- Check_Discriminant_Conformance --
3717 ------------------------------------
3719 procedure Check_Discriminant_Conformance
3724 Old_Discr : Entity_Id := First_Discriminant (Prev);
3725 New_Discr : Node_Id := First (Discriminant_Specifications (N));
3726 New_Discr_Id : Entity_Id;
3727 New_Discr_Type : Entity_Id;
3729 procedure Conformance_Error (Msg : String; N : Node_Id);
3730 -- Post error message for conformance error on given node. Two messages
3731 -- are output. The first points to the previous declaration with a
3732 -- general "no conformance" message. The second is the detailed reason,
3733 -- supplied as Msg. The parameter N provide information for a possible
3734 -- & insertion in the message.
3736 -----------------------
3737 -- Conformance_Error --
3738 -----------------------
3740 procedure Conformance_Error (Msg : String; N : Node_Id) is
3742 Error_Msg_Sloc := Sloc (Prev_Loc);
3743 Error_Msg_N ("not fully conformant with declaration#!", N);
3744 Error_Msg_NE (Msg, N, N);
3745 end Conformance_Error;
3747 -- Start of processing for Check_Discriminant_Conformance
3750 while Present (Old_Discr) and then Present (New_Discr) loop
3752 New_Discr_Id := Defining_Identifier (New_Discr);
3754 -- The subtype mark of the discriminant on the full type has not
3755 -- been analyzed so we do it here. For an access discriminant a new
3758 if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then
3760 Access_Definition (N, Discriminant_Type (New_Discr));
3763 Analyze (Discriminant_Type (New_Discr));
3764 New_Discr_Type := Etype (Discriminant_Type (New_Discr));
3767 if not Conforming_Types
3768 (Etype (Old_Discr), New_Discr_Type, Fully_Conformant)
3770 Conformance_Error ("type of & does not match!", New_Discr_Id);
3773 -- Treat the new discriminant as an occurrence of the old one,
3774 -- for navigation purposes, and fill in some semantic
3775 -- information, for completeness.
3777 Generate_Reference (Old_Discr, New_Discr_Id, 'r');
3778 Set_Etype (New_Discr_Id, Etype (Old_Discr));
3779 Set_Scope (New_Discr_Id, Scope (Old_Discr));
3784 if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then
3785 Conformance_Error ("name & does not match!", New_Discr_Id);
3789 -- Default expressions must match
3792 NewD : constant Boolean :=
3793 Present (Expression (New_Discr));
3794 OldD : constant Boolean :=
3795 Present (Expression (Parent (Old_Discr)));
3798 if NewD or OldD then
3800 -- The old default value has been analyzed and expanded,
3801 -- because the current full declaration will have frozen
3802 -- everything before. The new default values have not been
3803 -- expanded, so expand now to check conformance.
3806 Preanalyze_Spec_Expression
3807 (Expression (New_Discr), New_Discr_Type);
3810 if not (NewD and OldD)
3811 or else not Fully_Conformant_Expressions
3812 (Expression (Parent (Old_Discr)),
3813 Expression (New_Discr))
3817 ("default expression for & does not match!",
3824 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
3826 if Ada_Version = Ada_83 then
3828 Old_Disc : constant Node_Id := Declaration_Node (Old_Discr);
3831 -- Grouping (use of comma in param lists) must be the same
3832 -- This is where we catch a misconformance like:
3835 -- A : Integer; B : Integer
3837 -- which are represented identically in the tree except
3838 -- for the setting of the flags More_Ids and Prev_Ids.
3840 if More_Ids (Old_Disc) /= More_Ids (New_Discr)
3841 or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr)
3844 ("grouping of & does not match!", New_Discr_Id);
3850 Next_Discriminant (Old_Discr);
3854 if Present (Old_Discr) then
3855 Conformance_Error ("too few discriminants!", Defining_Identifier (N));
3858 elsif Present (New_Discr) then
3860 ("too many discriminants!", Defining_Identifier (New_Discr));
3863 end Check_Discriminant_Conformance;
3865 ----------------------------
3866 -- Check_Fully_Conformant --
3867 ----------------------------
3869 procedure Check_Fully_Conformant
3870 (New_Id : Entity_Id;
3872 Err_Loc : Node_Id := Empty)
3875 pragma Warnings (Off, Result);
3878 (New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc);
3879 end Check_Fully_Conformant;
3881 ---------------------------
3882 -- Check_Mode_Conformant --
3883 ---------------------------
3885 procedure Check_Mode_Conformant
3886 (New_Id : Entity_Id;
3888 Err_Loc : Node_Id := Empty;
3889 Get_Inst : Boolean := False)
3892 pragma Warnings (Off, Result);
3895 (New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst);
3896 end Check_Mode_Conformant;
3898 --------------------------------
3899 -- Check_Overriding_Indicator --
3900 --------------------------------
3902 procedure Check_Overriding_Indicator
3904 Overridden_Subp : Entity_Id;
3905 Is_Primitive : Boolean)
3911 -- No overriding indicator for literals
3913 if Ekind (Subp) = E_Enumeration_Literal then
3916 elsif Ekind (Subp) = E_Entry then
3917 Decl := Parent (Subp);
3920 Decl := Unit_Declaration_Node (Subp);
3923 if Nkind_In (Decl, N_Subprogram_Body,
3924 N_Subprogram_Body_Stub,
3925 N_Subprogram_Declaration,
3926 N_Abstract_Subprogram_Declaration,
3927 N_Subprogram_Renaming_Declaration)
3929 Spec := Specification (Decl);
3931 elsif Nkind (Decl) = N_Entry_Declaration then
3938 if Present (Overridden_Subp) then
3939 if Must_Not_Override (Spec) then
3940 Error_Msg_Sloc := Sloc (Overridden_Subp);
3942 if Ekind (Subp) = E_Entry then
3944 ("entry & overrides inherited operation #", Spec, Subp);
3947 ("subprogram & overrides inherited operation #", Spec, Subp);
3950 elsif Is_Subprogram (Subp) then
3951 Set_Is_Overriding_Operation (Subp);
3954 -- If Subp is an operator, it may override a predefined operation.
3955 -- In that case overridden_subp is empty because of our implicit
3956 -- representation for predefined operators. We have to check whether the
3957 -- signature of Subp matches that of a predefined operator. Note that
3958 -- first argument provides the name of the operator, and the second
3959 -- argument the signature that may match that of a standard operation.
3960 -- If the indicator is overriding, then the operator must match a
3961 -- predefined signature, because we know already that there is no
3962 -- explicit overridden operation.
3964 elsif Nkind (Subp) = N_Defining_Operator_Symbol then
3966 if Must_Not_Override (Spec) then
3967 if not Is_Primitive then
3969 ("overriding indicator only allowed "
3970 & "if subprogram is primitive", Subp);
3972 elsif Operator_Matches_Spec (Subp, Subp) then
3974 ("subprogram & overrides predefined operator ", Spec, Subp);
3977 elsif Is_Overriding_Operation (Subp) then
3980 elsif Must_Override (Spec) then
3981 if not Operator_Matches_Spec (Subp, Subp) then
3982 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
3985 Set_Is_Overriding_Operation (Subp);
3989 elsif Must_Override (Spec) then
3990 if Ekind (Subp) = E_Entry then
3991 Error_Msg_NE ("entry & is not overriding", Spec, Subp);
3993 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
3996 -- If the operation is marked "not overriding" and it's not primitive
3997 -- then an error is issued, unless this is an operation of a task or
3998 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
3999 -- has been specified have already been checked above.
4001 elsif Must_Not_Override (Spec)
4002 and then not Is_Primitive
4003 and then Ekind (Subp) /= E_Entry
4004 and then Ekind (Scope (Subp)) /= E_Protected_Type
4007 ("overriding indicator only allowed if subprogram is primitive",
4011 end Check_Overriding_Indicator;
4017 -- Note: this procedure needs to know far too much about how the expander
4018 -- messes with exceptions. The use of the flag Exception_Junk and the
4019 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
4020 -- works, but is not very clean. It would be better if the expansion
4021 -- routines would leave Original_Node working nicely, and we could use
4022 -- Original_Node here to ignore all the peculiar expander messing ???
4024 procedure Check_Returns
4028 Proc : Entity_Id := Empty)
4032 procedure Check_Statement_Sequence (L : List_Id);
4033 -- Internal recursive procedure to check a list of statements for proper
4034 -- termination by a return statement (or a transfer of control or a
4035 -- compound statement that is itself internally properly terminated).
4037 ------------------------------
4038 -- Check_Statement_Sequence --
4039 ------------------------------
4041 procedure Check_Statement_Sequence (L : List_Id) is
4046 Raise_Exception_Call : Boolean;
4047 -- Set True if statement sequence terminated by Raise_Exception call
4048 -- or a Reraise_Occurrence call.
4051 Raise_Exception_Call := False;
4053 -- Get last real statement
4055 Last_Stm := Last (L);
4057 -- Deal with digging out exception handler statement sequences that
4058 -- have been transformed by the local raise to goto optimization.
4059 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
4060 -- optimization has occurred, we are looking at something like:
4063 -- original stmts in block
4067 -- goto L1; | omitted if No_Exception_Propagation
4072 -- goto L3; -- skip handler when exception not raised
4074 -- <<L1>> -- target label for local exception
4088 -- and what we have to do is to dig out the estmts1 and estmts2
4089 -- sequences (which were the original sequences of statements in
4090 -- the exception handlers) and check them.
4092 if Nkind (Last_Stm) = N_Label
4093 and then Exception_Junk (Last_Stm)
4099 exit when Nkind (Stm) /= N_Block_Statement;
4100 exit when not Exception_Junk (Stm);
4103 exit when Nkind (Stm) /= N_Label;
4104 exit when not Exception_Junk (Stm);
4105 Check_Statement_Sequence
4106 (Statements (Handled_Statement_Sequence (Next (Stm))));
4111 exit when Nkind (Stm) /= N_Goto_Statement;
4112 exit when not Exception_Junk (Stm);
4116 -- Don't count pragmas
4118 while Nkind (Last_Stm) = N_Pragma
4120 -- Don't count call to SS_Release (can happen after Raise_Exception)
4123 (Nkind (Last_Stm) = N_Procedure_Call_Statement
4125 Nkind (Name (Last_Stm)) = N_Identifier
4127 Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release))
4129 -- Don't count exception junk
4132 (Nkind_In (Last_Stm, N_Goto_Statement,
4134 N_Object_Declaration)
4135 and then Exception_Junk (Last_Stm))
4136 or else Nkind (Last_Stm) in N_Push_xxx_Label
4137 or else Nkind (Last_Stm) in N_Pop_xxx_Label
4142 -- Here we have the "real" last statement
4144 Kind := Nkind (Last_Stm);
4146 -- Transfer of control, OK. Note that in the No_Return procedure
4147 -- case, we already diagnosed any explicit return statements, so
4148 -- we can treat them as OK in this context.
4150 if Is_Transfer (Last_Stm) then
4153 -- Check cases of explicit non-indirect procedure calls
4155 elsif Kind = N_Procedure_Call_Statement
4156 and then Is_Entity_Name (Name (Last_Stm))
4158 -- Check call to Raise_Exception procedure which is treated
4159 -- specially, as is a call to Reraise_Occurrence.
4161 -- We suppress the warning in these cases since it is likely that
4162 -- the programmer really does not expect to deal with the case
4163 -- of Null_Occurrence, and thus would find a warning about a
4164 -- missing return curious, and raising Program_Error does not
4165 -- seem such a bad behavior if this does occur.
4167 -- Note that in the Ada 2005 case for Raise_Exception, the actual
4168 -- behavior will be to raise Constraint_Error (see AI-329).
4170 if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception)
4172 Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence)
4174 Raise_Exception_Call := True;
4176 -- For Raise_Exception call, test first argument, if it is
4177 -- an attribute reference for a 'Identity call, then we know
4178 -- that the call cannot possibly return.
4181 Arg : constant Node_Id :=
4182 Original_Node (First_Actual (Last_Stm));
4184 if Nkind (Arg) = N_Attribute_Reference
4185 and then Attribute_Name (Arg) = Name_Identity
4192 -- If statement, need to look inside if there is an else and check
4193 -- each constituent statement sequence for proper termination.
4195 elsif Kind = N_If_Statement
4196 and then Present (Else_Statements (Last_Stm))
4198 Check_Statement_Sequence (Then_Statements (Last_Stm));
4199 Check_Statement_Sequence (Else_Statements (Last_Stm));
4201 if Present (Elsif_Parts (Last_Stm)) then
4203 Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm));
4206 while Present (Elsif_Part) loop
4207 Check_Statement_Sequence (Then_Statements (Elsif_Part));
4215 -- Case statement, check each case for proper termination
4217 elsif Kind = N_Case_Statement then
4221 Case_Alt := First_Non_Pragma (Alternatives (Last_Stm));
4222 while Present (Case_Alt) loop
4223 Check_Statement_Sequence (Statements (Case_Alt));
4224 Next_Non_Pragma (Case_Alt);
4230 -- Block statement, check its handled sequence of statements
4232 elsif Kind = N_Block_Statement then
4238 (Handled_Statement_Sequence (Last_Stm), Mode, Err1);
4247 -- Loop statement. If there is an iteration scheme, we can definitely
4248 -- fall out of the loop. Similarly if there is an exit statement, we
4249 -- can fall out. In either case we need a following return.
4251 elsif Kind = N_Loop_Statement then
4252 if Present (Iteration_Scheme (Last_Stm))
4253 or else Has_Exit (Entity (Identifier (Last_Stm)))
4257 -- A loop with no exit statement or iteration scheme if either
4258 -- an inifite loop, or it has some other exit (raise/return).
4259 -- In either case, no warning is required.
4265 -- Timed entry call, check entry call and delay alternatives
4267 -- Note: in expanded code, the timed entry call has been converted
4268 -- to a set of expanded statements on which the check will work
4269 -- correctly in any case.
4271 elsif Kind = N_Timed_Entry_Call then
4273 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
4274 DCA : constant Node_Id := Delay_Alternative (Last_Stm);
4277 -- If statement sequence of entry call alternative is missing,
4278 -- then we can definitely fall through, and we post the error
4279 -- message on the entry call alternative itself.
4281 if No (Statements (ECA)) then
4284 -- If statement sequence of delay alternative is missing, then
4285 -- we can definitely fall through, and we post the error
4286 -- message on the delay alternative itself.
4288 -- Note: if both ECA and DCA are missing the return, then we
4289 -- post only one message, should be enough to fix the bugs.
4290 -- If not we will get a message next time on the DCA when the
4293 elsif No (Statements (DCA)) then
4296 -- Else check both statement sequences
4299 Check_Statement_Sequence (Statements (ECA));
4300 Check_Statement_Sequence (Statements (DCA));
4305 -- Conditional entry call, check entry call and else part
4307 -- Note: in expanded code, the conditional entry call has been
4308 -- converted to a set of expanded statements on which the check
4309 -- will work correctly in any case.
4311 elsif Kind = N_Conditional_Entry_Call then
4313 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
4316 -- If statement sequence of entry call alternative is missing,
4317 -- then we can definitely fall through, and we post the error
4318 -- message on the entry call alternative itself.
4320 if No (Statements (ECA)) then
4323 -- Else check statement sequence and else part
4326 Check_Statement_Sequence (Statements (ECA));
4327 Check_Statement_Sequence (Else_Statements (Last_Stm));
4333 -- If we fall through, issue appropriate message
4336 if not Raise_Exception_Call then
4338 ("?RETURN statement missing following this statement!",
4341 ("\?Program_Error may be raised at run time!",
4345 -- Note: we set Err even though we have not issued a warning
4346 -- because we still have a case of a missing return. This is
4347 -- an extremely marginal case, probably will never be noticed
4348 -- but we might as well get it right.
4352 -- Otherwise we have the case of a procedure marked No_Return
4355 if not Raise_Exception_Call then
4357 ("?implied return after this statement " &
4358 "will raise Program_Error",
4361 ("\?procedure & is marked as No_Return!",
4366 RE : constant Node_Id :=
4367 Make_Raise_Program_Error (Sloc (Last_Stm),
4368 Reason => PE_Implicit_Return);
4370 Insert_After (Last_Stm, RE);
4374 end Check_Statement_Sequence;
4376 -- Start of processing for Check_Returns
4380 Check_Statement_Sequence (Statements (HSS));
4382 if Present (Exception_Handlers (HSS)) then
4383 Handler := First_Non_Pragma (Exception_Handlers (HSS));
4384 while Present (Handler) loop
4385 Check_Statement_Sequence (Statements (Handler));
4386 Next_Non_Pragma (Handler);
4391 ----------------------------
4392 -- Check_Subprogram_Order --
4393 ----------------------------
4395 procedure Check_Subprogram_Order (N : Node_Id) is
4397 function Subprogram_Name_Greater (S1, S2 : String) return Boolean;
4398 -- This is used to check if S1 > S2 in the sense required by this
4399 -- test, for example nameab < namec, but name2 < name10.
4401 -----------------------------
4402 -- Subprogram_Name_Greater --
4403 -----------------------------
4405 function Subprogram_Name_Greater (S1, S2 : String) return Boolean is
4410 -- Remove trailing numeric parts
4413 while S1 (L1) in '0' .. '9' loop
4418 while S2 (L2) in '0' .. '9' loop
4422 -- If non-numeric parts non-equal, that's decisive
4424 if S1 (S1'First .. L1) < S2 (S2'First .. L2) then
4427 elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then
4430 -- If non-numeric parts equal, compare suffixed numeric parts. Note
4431 -- that a missing suffix is treated as numeric zero in this test.
4435 while L1 < S1'Last loop
4437 N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0');
4441 while L2 < S2'Last loop
4443 N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0');
4448 end Subprogram_Name_Greater;
4450 -- Start of processing for Check_Subprogram_Order
4453 -- Check body in alpha order if this is option
4456 and then Style_Check_Order_Subprograms
4457 and then Nkind (N) = N_Subprogram_Body
4458 and then Comes_From_Source (N)
4459 and then In_Extended_Main_Source_Unit (N)
4463 renames Scope_Stack.Table
4464 (Scope_Stack.Last).Last_Subprogram_Name;
4466 Body_Id : constant Entity_Id :=
4467 Defining_Entity (Specification (N));
4470 Get_Decoded_Name_String (Chars (Body_Id));
4473 if Subprogram_Name_Greater
4474 (LSN.all, Name_Buffer (1 .. Name_Len))
4476 Style.Subprogram_Not_In_Alpha_Order (Body_Id);
4482 LSN := new String'(Name_Buffer (1 .. Name_Len));
4485 end Check_Subprogram_Order;
4487 ------------------------------
4488 -- Check_Subtype_Conformant --
4489 ------------------------------
4491 procedure Check_Subtype_Conformant
4492 (New_Id : Entity_Id;
4494 Err_Loc : Node_Id := Empty)
4497 pragma Warnings (Off, Result);
4500 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
4501 end Check_Subtype_Conformant;
4503 ---------------------------
4504 -- Check_Type_Conformant --
4505 ---------------------------
4507 procedure Check_Type_Conformant
4508 (New_Id : Entity_Id;
4510 Err_Loc : Node_Id := Empty)
4513 pragma Warnings (Off, Result);
4516 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
4517 end Check_Type_Conformant;
4519 ----------------------
4520 -- Conforming_Types --
4521 ----------------------
4523 function Conforming_Types
4526 Ctype : Conformance_Type;
4527 Get_Inst : Boolean := False) return Boolean
4529 Type_1 : Entity_Id := T1;
4530 Type_2 : Entity_Id := T2;
4531 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
4533 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
4534 -- If neither T1 nor T2 are generic actual types, or if they are in
4535 -- different scopes (e.g. parent and child instances), then verify that
4536 -- the base types are equal. Otherwise T1 and T2 must be on the same
4537 -- subtype chain. The whole purpose of this procedure is to prevent
4538 -- spurious ambiguities in an instantiation that may arise if two
4539 -- distinct generic types are instantiated with the same actual.
4541 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
4542 -- An access parameter can designate an incomplete type. If the
4543 -- incomplete type is the limited view of a type from a limited_
4544 -- with_clause, check whether the non-limited view is available. If
4545 -- it is a (non-limited) incomplete type, get the full view.
4547 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
4548 -- Returns True if and only if either T1 denotes a limited view of T2
4549 -- or T2 denotes a limited view of T1. This can arise when the limited
4550 -- with view of a type is used in a subprogram declaration and the
4551 -- subprogram body is in the scope of a regular with clause for the
4552 -- same unit. In such a case, the two type entities can be considered
4553 -- identical for purposes of conformance checking.
4555 ----------------------
4556 -- Base_Types_Match --
4557 ----------------------
4559 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
4564 elsif Base_Type (T1) = Base_Type (T2) then
4566 -- The following is too permissive. A more precise test should
4567 -- check that the generic actual is an ancestor subtype of the
4570 return not Is_Generic_Actual_Type (T1)
4571 or else not Is_Generic_Actual_Type (T2)
4572 or else Scope (T1) /= Scope (T2);
4577 end Base_Types_Match;
4579 --------------------------
4580 -- Find_Designated_Type --
4581 --------------------------
4583 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
4587 Desig := Directly_Designated_Type (T);
4589 if Ekind (Desig) = E_Incomplete_Type then
4591 -- If regular incomplete type, get full view if available
4593 if Present (Full_View (Desig)) then
4594 Desig := Full_View (Desig);
4596 -- If limited view of a type, get non-limited view if available,
4597 -- and check again for a regular incomplete type.
4599 elsif Present (Non_Limited_View (Desig)) then
4600 Desig := Get_Full_View (Non_Limited_View (Desig));
4605 end Find_Designated_Type;
4607 -------------------------------
4608 -- Matches_Limited_With_View --
4609 -------------------------------
4611 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
4613 -- In some cases a type imported through a limited_with clause, and
4614 -- its nonlimited view are both visible, for example in an anonymous
4615 -- access-to-class-wide type in a formal. Both entities designate the
4618 if From_With_Type (T1)
4619 and then T2 = Available_View (T1)
4623 elsif From_With_Type (T2)
4624 and then T1 = Available_View (T2)
4631 end Matches_Limited_With_View;
4633 -- Start of processing for Conforming_Types
4636 -- The context is an instance association for a formal
4637 -- access-to-subprogram type; the formal parameter types require
4638 -- mapping because they may denote other formal parameters of the
4642 Type_1 := Get_Instance_Of (T1);
4643 Type_2 := Get_Instance_Of (T2);
4646 -- If one of the types is a view of the other introduced by a limited
4647 -- with clause, treat these as conforming for all purposes.
4649 if Matches_Limited_With_View (T1, T2) then
4652 elsif Base_Types_Match (Type_1, Type_2) then
4653 return Ctype <= Mode_Conformant
4654 or else Subtypes_Statically_Match (Type_1, Type_2);
4656 elsif Is_Incomplete_Or_Private_Type (Type_1)
4657 and then Present (Full_View (Type_1))
4658 and then Base_Types_Match (Full_View (Type_1), Type_2)
4660 return Ctype <= Mode_Conformant
4661 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
4663 elsif Ekind (Type_2) = E_Incomplete_Type
4664 and then Present (Full_View (Type_2))
4665 and then Base_Types_Match (Type_1, Full_View (Type_2))
4667 return Ctype <= Mode_Conformant
4668 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
4670 elsif Is_Private_Type (Type_2)
4671 and then In_Instance
4672 and then Present (Full_View (Type_2))
4673 and then Base_Types_Match (Type_1, Full_View (Type_2))
4675 return Ctype <= Mode_Conformant
4676 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
4679 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
4680 -- treated recursively because they carry a signature.
4682 Are_Anonymous_Access_To_Subprogram_Types :=
4683 Ekind (Type_1) = Ekind (Type_2)
4685 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
4687 Ekind (Type_1) = E_Anonymous_Access_Protected_Subprogram_Type);
4689 -- Test anonymous access type case. For this case, static subtype
4690 -- matching is required for mode conformance (RM 6.3.1(15)). We check
4691 -- the base types because we may have built internal subtype entities
4692 -- to handle null-excluding types (see Process_Formals).
4694 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
4696 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
4697 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
4700 Desig_1 : Entity_Id;
4701 Desig_2 : Entity_Id;
4704 -- In Ada2005, access constant indicators must match for
4705 -- subtype conformance.
4707 if Ada_Version >= Ada_05
4708 and then Ctype >= Subtype_Conformant
4710 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
4715 Desig_1 := Find_Designated_Type (Type_1);
4717 Desig_2 := Find_Designated_Type (Type_2);
4719 -- If the context is an instance association for a formal
4720 -- access-to-subprogram type; formal access parameter designated
4721 -- types require mapping because they may denote other formal
4722 -- parameters of the generic unit.
4725 Desig_1 := Get_Instance_Of (Desig_1);
4726 Desig_2 := Get_Instance_Of (Desig_2);
4729 -- It is possible for a Class_Wide_Type to be introduced for an
4730 -- incomplete type, in which case there is a separate class_ wide
4731 -- type for the full view. The types conform if their Etypes
4732 -- conform, i.e. one may be the full view of the other. This can
4733 -- only happen in the context of an access parameter, other uses
4734 -- of an incomplete Class_Wide_Type are illegal.
4736 if Is_Class_Wide_Type (Desig_1)
4737 and then Is_Class_Wide_Type (Desig_2)
4741 (Etype (Base_Type (Desig_1)),
4742 Etype (Base_Type (Desig_2)), Ctype);
4744 elsif Are_Anonymous_Access_To_Subprogram_Types then
4745 if Ada_Version < Ada_05 then
4746 return Ctype = Type_Conformant
4748 Subtypes_Statically_Match (Desig_1, Desig_2);
4750 -- We must check the conformance of the signatures themselves
4754 Conformant : Boolean;
4757 (Desig_1, Desig_2, Ctype, False, Conformant);
4763 return Base_Type (Desig_1) = Base_Type (Desig_2)
4764 and then (Ctype = Type_Conformant
4766 Subtypes_Statically_Match (Desig_1, Desig_2));
4770 -- Otherwise definitely no match
4773 if ((Ekind (Type_1) = E_Anonymous_Access_Type
4774 and then Is_Access_Type (Type_2))
4775 or else (Ekind (Type_2) = E_Anonymous_Access_Type
4776 and then Is_Access_Type (Type_1)))
4779 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
4781 May_Hide_Profile := True;
4786 end Conforming_Types;
4788 --------------------------
4789 -- Create_Extra_Formals --
4790 --------------------------
4792 procedure Create_Extra_Formals (E : Entity_Id) is
4794 First_Extra : Entity_Id := Empty;
4795 Last_Extra : Entity_Id;
4796 Formal_Type : Entity_Id;
4797 P_Formal : Entity_Id := Empty;
4799 function Add_Extra_Formal
4800 (Assoc_Entity : Entity_Id;
4803 Suffix : String) return Entity_Id;
4804 -- Add an extra formal to the current list of formals and extra formals.
4805 -- The extra formal is added to the end of the list of extra formals,
4806 -- and also returned as the result. These formals are always of mode IN.
4807 -- The new formal has the type Typ, is declared in Scope, and its name
4808 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
4810 ----------------------
4811 -- Add_Extra_Formal --
4812 ----------------------
4814 function Add_Extra_Formal
4815 (Assoc_Entity : Entity_Id;
4818 Suffix : String) return Entity_Id
4820 EF : constant Entity_Id :=
4821 Make_Defining_Identifier (Sloc (Assoc_Entity),
4822 Chars => New_External_Name (Chars (Assoc_Entity),
4826 -- A little optimization. Never generate an extra formal for the
4827 -- _init operand of an initialization procedure, since it could
4830 if Chars (Formal) = Name_uInit then
4834 Set_Ekind (EF, E_In_Parameter);
4835 Set_Actual_Subtype (EF, Typ);
4836 Set_Etype (EF, Typ);
4837 Set_Scope (EF, Scope);
4838 Set_Mechanism (EF, Default_Mechanism);
4839 Set_Formal_Validity (EF);
4841 if No (First_Extra) then
4843 Set_Extra_Formals (Scope, First_Extra);
4846 if Present (Last_Extra) then
4847 Set_Extra_Formal (Last_Extra, EF);
4853 end Add_Extra_Formal;
4855 -- Start of processing for Create_Extra_Formals
4858 -- We never generate extra formals if expansion is not active
4859 -- because we don't need them unless we are generating code.
4861 if not Expander_Active then
4865 -- If this is a derived subprogram then the subtypes of the parent
4866 -- subprogram's formal parameters will be used to to determine the need
4867 -- for extra formals.
4869 if Is_Overloadable (E) and then Present (Alias (E)) then
4870 P_Formal := First_Formal (Alias (E));
4873 Last_Extra := Empty;
4874 Formal := First_Formal (E);
4875 while Present (Formal) loop
4876 Last_Extra := Formal;
4877 Next_Formal (Formal);
4880 -- If Extra_formals were already created, don't do it again. This
4881 -- situation may arise for subprogram types created as part of
4882 -- dispatching calls (see Expand_Dispatching_Call)
4884 if Present (Last_Extra) and then
4885 Present (Extra_Formal (Last_Extra))
4890 -- If the subprogram is a predefined dispatching subprogram then don't
4891 -- generate any extra constrained or accessibility level formals. In
4892 -- general we suppress these for internal subprograms (by not calling
4893 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
4894 -- generated stream attributes do get passed through because extra
4895 -- build-in-place formals are needed in some cases (limited 'Input).
4897 if Is_Predefined_Dispatching_Operation (E) then
4898 goto Test_For_BIP_Extras;
4901 Formal := First_Formal (E);
4902 while Present (Formal) loop
4904 -- Create extra formal for supporting the attribute 'Constrained.
4905 -- The case of a private type view without discriminants also
4906 -- requires the extra formal if the underlying type has defaulted
4909 if Ekind (Formal) /= E_In_Parameter then
4910 if Present (P_Formal) then
4911 Formal_Type := Etype (P_Formal);
4913 Formal_Type := Etype (Formal);
4916 -- Do not produce extra formals for Unchecked_Union parameters.
4917 -- Jump directly to the end of the loop.
4919 if Is_Unchecked_Union (Base_Type (Formal_Type)) then
4920 goto Skip_Extra_Formal_Generation;
4923 if not Has_Discriminants (Formal_Type)
4924 and then Ekind (Formal_Type) in Private_Kind
4925 and then Present (Underlying_Type (Formal_Type))
4927 Formal_Type := Underlying_Type (Formal_Type);
4930 if Has_Discriminants (Formal_Type)
4931 and then not Is_Constrained (Formal_Type)
4932 and then not Is_Indefinite_Subtype (Formal_Type)
4934 Set_Extra_Constrained
4935 (Formal, Add_Extra_Formal (Formal, Standard_Boolean, E, "F"));
4939 -- Create extra formal for supporting accessibility checking. This
4940 -- is done for both anonymous access formals and formals of named
4941 -- access types that are marked as controlling formals. The latter
4942 -- case can occur when Expand_Dispatching_Call creates a subprogram
4943 -- type and substitutes the types of access-to-class-wide actuals
4944 -- for the anonymous access-to-specific-type of controlling formals.
4945 -- Base_Type is applied because in cases where there is a null
4946 -- exclusion the formal may have an access subtype.
4948 -- This is suppressed if we specifically suppress accessibility
4949 -- checks at the package level for either the subprogram, or the
4950 -- package in which it resides. However, we do not suppress it
4951 -- simply if the scope has accessibility checks suppressed, since
4952 -- this could cause trouble when clients are compiled with a
4953 -- different suppression setting. The explicit checks at the
4954 -- package level are safe from this point of view.
4956 if (Ekind (Base_Type (Etype (Formal))) = E_Anonymous_Access_Type
4957 or else (Is_Controlling_Formal (Formal)
4958 and then Is_Access_Type (Base_Type (Etype (Formal)))))
4960 (Explicit_Suppress (E, Accessibility_Check)
4962 Explicit_Suppress (Scope (E), Accessibility_Check))
4965 or else Present (Extra_Accessibility (P_Formal)))
4967 -- Temporary kludge: for now we avoid creating the extra formal
4968 -- for access parameters of protected operations because of
4969 -- problem with the case of internal protected calls. ???
4971 if Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Definition
4972 and then Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Body
4974 Set_Extra_Accessibility
4975 (Formal, Add_Extra_Formal (Formal, Standard_Natural, E, "F"));
4979 -- This label is required when skipping extra formal generation for
4980 -- Unchecked_Union parameters.
4982 <<Skip_Extra_Formal_Generation>>
4984 if Present (P_Formal) then
4985 Next_Formal (P_Formal);
4988 Next_Formal (Formal);
4991 <<Test_For_BIP_Extras>>
4993 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
4994 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
4996 if Ada_Version >= Ada_05 and then Is_Build_In_Place_Function (E) then
4998 Result_Subt : constant Entity_Id := Etype (E);
5000 Discard : Entity_Id;
5001 pragma Warnings (Off, Discard);
5004 -- In the case of functions with unconstrained result subtypes,
5005 -- add a 3-state formal indicating whether the return object is
5006 -- allocated by the caller (0), or should be allocated by the
5007 -- callee on the secondary stack (1) or in the global heap (2).
5008 -- For the moment we just use Natural for the type of this formal.
5009 -- Note that this formal isn't usually needed in the case where
5010 -- the result subtype is constrained, but it is needed when the
5011 -- function has a tagged result, because generally such functions
5012 -- can be called in a dispatching context and such calls must be
5013 -- handled like calls to a class-wide function.
5015 if not Is_Constrained (Result_Subt)
5016 or else Is_Tagged_Type (Underlying_Type (Result_Subt))
5020 (E, Standard_Natural,
5021 E, BIP_Formal_Suffix (BIP_Alloc_Form));
5024 -- In the case of functions whose result type has controlled
5025 -- parts, we have an extra formal of type
5026 -- System.Finalization_Implementation.Finalizable_Ptr_Ptr. That
5027 -- is, we are passing a pointer to a finalization list (which is
5028 -- itself a pointer). This extra formal is then passed along to
5029 -- Move_Final_List in case of successful completion of a return
5030 -- statement. We cannot pass an 'in out' parameter, because we
5031 -- need to update the finalization list during an abort-deferred
5032 -- region, rather than using copy-back after the function
5033 -- returns. This is true even if we are able to get away with
5034 -- having 'in out' parameters, which are normally illegal for
5035 -- functions. This formal is also needed when the function has
5036 -- a tagged result, because generally such functions can be called
5037 -- in a dispatching context and such calls must be handled like
5038 -- calls to class-wide functions.
5040 if Controlled_Type (Result_Subt)
5041 or else Is_Tagged_Type (Underlying_Type (Result_Subt))
5045 (E, RTE (RE_Finalizable_Ptr_Ptr),
5046 E, BIP_Formal_Suffix (BIP_Final_List));
5049 -- If the result type contains tasks, we have two extra formals:
5050 -- the master of the tasks to be created, and the caller's
5051 -- activation chain.
5053 if Has_Task (Result_Subt) then
5056 (E, RTE (RE_Master_Id),
5057 E, BIP_Formal_Suffix (BIP_Master));
5060 (E, RTE (RE_Activation_Chain_Access),
5061 E, BIP_Formal_Suffix (BIP_Activation_Chain));
5064 -- All build-in-place functions get an extra formal that will be
5065 -- passed the address of the return object within the caller.
5068 Formal_Type : constant Entity_Id :=
5070 (E_Anonymous_Access_Type, E,
5071 Scope_Id => Scope (E));
5073 Set_Directly_Designated_Type (Formal_Type, Result_Subt);
5074 Set_Etype (Formal_Type, Formal_Type);
5075 Set_Depends_On_Private
5076 (Formal_Type, Has_Private_Component (Formal_Type));
5077 Set_Is_Public (Formal_Type, Is_Public (Scope (Formal_Type)));
5078 Set_Is_Access_Constant (Formal_Type, False);
5080 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
5081 -- the designated type comes from the limited view (for
5082 -- back-end purposes).
5084 Set_From_With_Type (Formal_Type, From_With_Type (Result_Subt));
5086 Layout_Type (Formal_Type);
5090 (E, Formal_Type, E, BIP_Formal_Suffix (BIP_Object_Access));
5094 end Create_Extra_Formals;
5096 -----------------------------
5097 -- Enter_Overloaded_Entity --
5098 -----------------------------
5100 procedure Enter_Overloaded_Entity (S : Entity_Id) is
5101 E : Entity_Id := Current_Entity_In_Scope (S);
5102 C_E : Entity_Id := Current_Entity (S);
5106 Set_Has_Homonym (E);
5107 Set_Has_Homonym (S);
5110 Set_Is_Immediately_Visible (S);
5111 Set_Scope (S, Current_Scope);
5113 -- Chain new entity if front of homonym in current scope, so that
5114 -- homonyms are contiguous.
5119 while Homonym (C_E) /= E loop
5120 C_E := Homonym (C_E);
5123 Set_Homonym (C_E, S);
5127 Set_Current_Entity (S);
5132 Append_Entity (S, Current_Scope);
5133 Set_Public_Status (S);
5135 if Debug_Flag_E then
5136 Write_Str ("New overloaded entity chain: ");
5137 Write_Name (Chars (S));
5140 while Present (E) loop
5141 Write_Str (" "); Write_Int (Int (E));
5148 -- Generate warning for hiding
5151 and then Comes_From_Source (S)
5152 and then In_Extended_Main_Source_Unit (S)
5159 -- Warn unless genuine overloading
5161 if (not Is_Overloadable (E) or else Subtype_Conformant (E, S))
5162 and then (Is_Immediately_Visible (E)
5164 Is_Potentially_Use_Visible (S))
5166 Error_Msg_Sloc := Sloc (E);
5167 Error_Msg_N ("declaration of & hides one#?", S);
5171 end Enter_Overloaded_Entity;
5173 -----------------------------
5174 -- Find_Corresponding_Spec --
5175 -----------------------------
5177 function Find_Corresponding_Spec (N : Node_Id) return Entity_Id is
5178 Spec : constant Node_Id := Specification (N);
5179 Designator : constant Entity_Id := Defining_Entity (Spec);
5184 E := Current_Entity (Designator);
5185 while Present (E) loop
5187 -- We are looking for a matching spec. It must have the same scope,
5188 -- and the same name, and either be type conformant, or be the case
5189 -- of a library procedure spec and its body (which belong to one
5190 -- another regardless of whether they are type conformant or not).
5192 if Scope (E) = Current_Scope then
5193 if Current_Scope = Standard_Standard
5194 or else (Ekind (E) = Ekind (Designator)
5195 and then Type_Conformant (E, Designator))
5197 -- Within an instantiation, we know that spec and body are
5198 -- subtype conformant, because they were subtype conformant
5199 -- in the generic. We choose the subtype-conformant entity
5200 -- here as well, to resolve spurious ambiguities in the
5201 -- instance that were not present in the generic (i.e. when
5202 -- two different types are given the same actual). If we are
5203 -- looking for a spec to match a body, full conformance is
5207 Set_Convention (Designator, Convention (E));
5209 if Nkind (N) = N_Subprogram_Body
5210 and then Present (Homonym (E))
5211 and then not Fully_Conformant (E, Designator)
5215 elsif not Subtype_Conformant (E, Designator) then
5220 if not Has_Completion (E) then
5222 if Nkind (N) /= N_Subprogram_Body_Stub then
5223 Set_Corresponding_Spec (N, E);
5226 Set_Has_Completion (E);
5229 elsif Nkind (Parent (N)) = N_Subunit then
5231 -- If this is the proper body of a subunit, the completion
5232 -- flag is set when analyzing the stub.
5236 -- If E is an internal function with a controlling result
5237 -- that was created for an operation inherited by a null
5238 -- extension, it may be overridden by a body without a previous
5239 -- spec (one more reason why these should be shunned). In that
5240 -- case remove the generated body, because the current one is
5241 -- the explicit overriding.
5243 elsif Ekind (E) = E_Function
5244 and then Ada_Version >= Ada_05
5245 and then not Comes_From_Source (E)
5246 and then Has_Controlling_Result (E)
5247 and then Is_Null_Extension (Etype (E))
5248 and then Comes_From_Source (Spec)
5250 Set_Has_Completion (E, False);
5252 if Expander_Active then
5254 (Unit_Declaration_Node
5255 (Corresponding_Body (Unit_Declaration_Node (E))));
5258 -- If expansion is disabled, the wrapper function has not
5259 -- been generated, and this is the standard case of a late
5260 -- body overriding an inherited operation.
5266 -- If body already exists, this is an error unless the
5267 -- previous declaration is the implicit declaration of
5268 -- a derived subprogram, or this is a spurious overloading
5271 elsif No (Alias (E))
5272 and then not Is_Intrinsic_Subprogram (E)
5273 and then not In_Instance
5275 Error_Msg_Sloc := Sloc (E);
5276 if Is_Imported (E) then
5278 ("body not allowed for imported subprogram & declared#",
5281 Error_Msg_NE ("duplicate body for & declared#", N, E);
5285 elsif Is_Child_Unit (E)
5287 Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body
5289 Nkind (Parent (Unit_Declaration_Node (Designator))) =
5292 -- Child units cannot be overloaded, so a conformance mismatch
5293 -- between body and a previous spec is an error.
5296 ("body of child unit does not match previous declaration", N);
5304 -- On exit, we know that no previous declaration of subprogram exists
5307 end Find_Corresponding_Spec;
5309 ----------------------
5310 -- Fully_Conformant --
5311 ----------------------
5313 function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
5316 Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result);
5318 end Fully_Conformant;
5320 ----------------------------------
5321 -- Fully_Conformant_Expressions --
5322 ----------------------------------
5324 function Fully_Conformant_Expressions
5325 (Given_E1 : Node_Id;
5326 Given_E2 : Node_Id) return Boolean
5328 E1 : constant Node_Id := Original_Node (Given_E1);
5329 E2 : constant Node_Id := Original_Node (Given_E2);
5330 -- We always test conformance on original nodes, since it is possible
5331 -- for analysis and/or expansion to make things look as though they
5332 -- conform when they do not, e.g. by converting 1+2 into 3.
5334 function FCE (Given_E1, Given_E2 : Node_Id) return Boolean
5335 renames Fully_Conformant_Expressions;
5337 function FCL (L1, L2 : List_Id) return Boolean;
5338 -- Compare elements of two lists for conformance. Elements have to
5339 -- be conformant, and actuals inserted as default parameters do not
5340 -- match explicit actuals with the same value.
5342 function FCO (Op_Node, Call_Node : Node_Id) return Boolean;
5343 -- Compare an operator node with a function call
5349 function FCL (L1, L2 : List_Id) return Boolean is
5353 if L1 = No_List then
5359 if L2 = No_List then
5365 -- Compare two lists, skipping rewrite insertions (we want to
5366 -- compare the original trees, not the expanded versions!)
5369 if Is_Rewrite_Insertion (N1) then
5371 elsif Is_Rewrite_Insertion (N2) then
5377 elsif not FCE (N1, N2) then
5390 function FCO (Op_Node, Call_Node : Node_Id) return Boolean is
5391 Actuals : constant List_Id := Parameter_Associations (Call_Node);
5396 or else Entity (Op_Node) /= Entity (Name (Call_Node))
5401 Act := First (Actuals);
5403 if Nkind (Op_Node) in N_Binary_Op then
5405 if not FCE (Left_Opnd (Op_Node), Act) then
5412 return Present (Act)
5413 and then FCE (Right_Opnd (Op_Node), Act)
5414 and then No (Next (Act));
5418 -- Start of processing for Fully_Conformant_Expressions
5421 -- Non-conformant if paren count does not match. Note: if some idiot
5422 -- complains that we don't do this right for more than 3 levels of
5423 -- parentheses, they will be treated with the respect they deserve!
5425 if Paren_Count (E1) /= Paren_Count (E2) then
5428 -- If same entities are referenced, then they are conformant even if
5429 -- they have different forms (RM 8.3.1(19-20)).
5431 elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then
5432 if Present (Entity (E1)) then
5433 return Entity (E1) = Entity (E2)
5434 or else (Chars (Entity (E1)) = Chars (Entity (E2))
5435 and then Ekind (Entity (E1)) = E_Discriminant
5436 and then Ekind (Entity (E2)) = E_In_Parameter);
5438 elsif Nkind (E1) = N_Expanded_Name
5439 and then Nkind (E2) = N_Expanded_Name
5440 and then Nkind (Selector_Name (E1)) = N_Character_Literal
5441 and then Nkind (Selector_Name (E2)) = N_Character_Literal
5443 return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2));
5446 -- Identifiers in component associations don't always have
5447 -- entities, but their names must conform.
5449 return Nkind (E1) = N_Identifier
5450 and then Nkind (E2) = N_Identifier
5451 and then Chars (E1) = Chars (E2);
5454 elsif Nkind (E1) = N_Character_Literal
5455 and then Nkind (E2) = N_Expanded_Name
5457 return Nkind (Selector_Name (E2)) = N_Character_Literal
5458 and then Chars (E1) = Chars (Selector_Name (E2));
5460 elsif Nkind (E2) = N_Character_Literal
5461 and then Nkind (E1) = N_Expanded_Name
5463 return Nkind (Selector_Name (E1)) = N_Character_Literal
5464 and then Chars (E2) = Chars (Selector_Name (E1));
5466 elsif Nkind (E1) in N_Op
5467 and then Nkind (E2) = N_Function_Call
5469 return FCO (E1, E2);
5471 elsif Nkind (E2) in N_Op
5472 and then Nkind (E1) = N_Function_Call
5474 return FCO (E2, E1);
5476 -- Otherwise we must have the same syntactic entity
5478 elsif Nkind (E1) /= Nkind (E2) then
5481 -- At this point, we specialize by node type
5488 FCL (Expressions (E1), Expressions (E2))
5489 and then FCL (Component_Associations (E1),
5490 Component_Associations (E2));
5493 if Nkind (Expression (E1)) = N_Qualified_Expression
5495 Nkind (Expression (E2)) = N_Qualified_Expression
5497 return FCE (Expression (E1), Expression (E2));
5499 -- Check that the subtype marks and any constraints
5504 Indic1 : constant Node_Id := Expression (E1);
5505 Indic2 : constant Node_Id := Expression (E2);
5510 if Nkind (Indic1) /= N_Subtype_Indication then
5512 Nkind (Indic2) /= N_Subtype_Indication
5513 and then Entity (Indic1) = Entity (Indic2);
5515 elsif Nkind (Indic2) /= N_Subtype_Indication then
5517 Nkind (Indic1) /= N_Subtype_Indication
5518 and then Entity (Indic1) = Entity (Indic2);
5521 if Entity (Subtype_Mark (Indic1)) /=
5522 Entity (Subtype_Mark (Indic2))
5527 Elt1 := First (Constraints (Constraint (Indic1)));
5528 Elt2 := First (Constraints (Constraint (Indic2)));
5530 while Present (Elt1) and then Present (Elt2) loop
5531 if not FCE (Elt1, Elt2) then
5544 when N_Attribute_Reference =>
5546 Attribute_Name (E1) = Attribute_Name (E2)
5547 and then FCL (Expressions (E1), Expressions (E2));
5551 Entity (E1) = Entity (E2)
5552 and then FCE (Left_Opnd (E1), Left_Opnd (E2))
5553 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
5555 when N_And_Then | N_Or_Else | N_Membership_Test =>
5557 FCE (Left_Opnd (E1), Left_Opnd (E2))
5559 FCE (Right_Opnd (E1), Right_Opnd (E2));
5561 when N_Character_Literal =>
5563 Char_Literal_Value (E1) = Char_Literal_Value (E2);
5565 when N_Component_Association =>
5567 FCL (Choices (E1), Choices (E2))
5568 and then FCE (Expression (E1), Expression (E2));
5570 when N_Conditional_Expression =>
5572 FCL (Expressions (E1), Expressions (E2));
5574 when N_Explicit_Dereference =>
5576 FCE (Prefix (E1), Prefix (E2));
5578 when N_Extension_Aggregate =>
5580 FCL (Expressions (E1), Expressions (E2))
5581 and then Null_Record_Present (E1) =
5582 Null_Record_Present (E2)
5583 and then FCL (Component_Associations (E1),
5584 Component_Associations (E2));
5586 when N_Function_Call =>
5588 FCE (Name (E1), Name (E2))
5589 and then FCL (Parameter_Associations (E1),
5590 Parameter_Associations (E2));
5592 when N_Indexed_Component =>
5594 FCE (Prefix (E1), Prefix (E2))
5595 and then FCL (Expressions (E1), Expressions (E2));
5597 when N_Integer_Literal =>
5598 return (Intval (E1) = Intval (E2));
5603 when N_Operator_Symbol =>
5605 Chars (E1) = Chars (E2);
5607 when N_Others_Choice =>
5610 when N_Parameter_Association =>
5612 Chars (Selector_Name (E1)) = Chars (Selector_Name (E2))
5613 and then FCE (Explicit_Actual_Parameter (E1),
5614 Explicit_Actual_Parameter (E2));
5616 when N_Qualified_Expression =>
5618 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
5619 and then FCE (Expression (E1), Expression (E2));
5623 FCE (Low_Bound (E1), Low_Bound (E2))
5624 and then FCE (High_Bound (E1), High_Bound (E2));
5626 when N_Real_Literal =>
5627 return (Realval (E1) = Realval (E2));
5629 when N_Selected_Component =>
5631 FCE (Prefix (E1), Prefix (E2))
5632 and then FCE (Selector_Name (E1), Selector_Name (E2));
5636 FCE (Prefix (E1), Prefix (E2))
5637 and then FCE (Discrete_Range (E1), Discrete_Range (E2));
5639 when N_String_Literal =>
5641 S1 : constant String_Id := Strval (E1);
5642 S2 : constant String_Id := Strval (E2);
5643 L1 : constant Nat := String_Length (S1);
5644 L2 : constant Nat := String_Length (S2);
5651 for J in 1 .. L1 loop
5652 if Get_String_Char (S1, J) /=
5653 Get_String_Char (S2, J)
5663 when N_Type_Conversion =>
5665 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
5666 and then FCE (Expression (E1), Expression (E2));
5670 Entity (E1) = Entity (E2)
5671 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
5673 when N_Unchecked_Type_Conversion =>
5675 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
5676 and then FCE (Expression (E1), Expression (E2));
5678 -- All other node types cannot appear in this context. Strictly
5679 -- we should raise a fatal internal error. Instead we just ignore
5680 -- the nodes. This means that if anyone makes a mistake in the
5681 -- expander and mucks an expression tree irretrievably, the
5682 -- result will be a failure to detect a (probably very obscure)
5683 -- case of non-conformance, which is better than bombing on some
5684 -- case where two expressions do in fact conform.
5691 end Fully_Conformant_Expressions;
5693 ----------------------------------------
5694 -- Fully_Conformant_Discrete_Subtypes --
5695 ----------------------------------------
5697 function Fully_Conformant_Discrete_Subtypes
5698 (Given_S1 : Node_Id;
5699 Given_S2 : Node_Id) return Boolean
5701 S1 : constant Node_Id := Original_Node (Given_S1);
5702 S2 : constant Node_Id := Original_Node (Given_S2);
5704 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean;
5705 -- Special-case for a bound given by a discriminant, which in the body
5706 -- is replaced with the discriminal of the enclosing type.
5708 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean;
5709 -- Check both bounds
5711 -----------------------
5712 -- Conforming_Bounds --
5713 -----------------------
5715 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is
5717 if Is_Entity_Name (B1)
5718 and then Is_Entity_Name (B2)
5719 and then Ekind (Entity (B1)) = E_Discriminant
5721 return Chars (B1) = Chars (B2);
5724 return Fully_Conformant_Expressions (B1, B2);
5726 end Conforming_Bounds;
5728 -----------------------
5729 -- Conforming_Ranges --
5730 -----------------------
5732 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is
5735 Conforming_Bounds (Low_Bound (R1), Low_Bound (R2))
5737 Conforming_Bounds (High_Bound (R1), High_Bound (R2));
5738 end Conforming_Ranges;
5740 -- Start of processing for Fully_Conformant_Discrete_Subtypes
5743 if Nkind (S1) /= Nkind (S2) then
5746 elsif Is_Entity_Name (S1) then
5747 return Entity (S1) = Entity (S2);
5749 elsif Nkind (S1) = N_Range then
5750 return Conforming_Ranges (S1, S2);
5752 elsif Nkind (S1) = N_Subtype_Indication then
5754 Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2))
5757 (Range_Expression (Constraint (S1)),
5758 Range_Expression (Constraint (S2)));
5762 end Fully_Conformant_Discrete_Subtypes;
5764 --------------------
5765 -- Install_Entity --
5766 --------------------
5768 procedure Install_Entity (E : Entity_Id) is
5769 Prev : constant Entity_Id := Current_Entity (E);
5771 Set_Is_Immediately_Visible (E);
5772 Set_Current_Entity (E);
5773 Set_Homonym (E, Prev);
5776 ---------------------
5777 -- Install_Formals --
5778 ---------------------
5780 procedure Install_Formals (Id : Entity_Id) is
5783 F := First_Formal (Id);
5784 while Present (F) loop
5788 end Install_Formals;
5790 ---------------------------------
5791 -- Is_Non_Overriding_Operation --
5792 ---------------------------------
5794 function Is_Non_Overriding_Operation
5795 (Prev_E : Entity_Id;
5796 New_E : Entity_Id) return Boolean
5800 G_Typ : Entity_Id := Empty;
5802 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id;
5803 -- If F_Type is a derived type associated with a generic actual subtype,
5804 -- then return its Generic_Parent_Type attribute, else return Empty.
5806 function Types_Correspond
5807 (P_Type : Entity_Id;
5808 N_Type : Entity_Id) return Boolean;
5809 -- Returns true if and only if the types (or designated types in the
5810 -- case of anonymous access types) are the same or N_Type is derived
5811 -- directly or indirectly from P_Type.
5813 -----------------------------
5814 -- Get_Generic_Parent_Type --
5815 -----------------------------
5817 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is
5822 if Is_Derived_Type (F_Typ)
5823 and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration
5825 -- The tree must be traversed to determine the parent subtype in
5826 -- the generic unit, which unfortunately isn't always available
5827 -- via semantic attributes. ??? (Note: The use of Original_Node
5828 -- is needed for cases where a full derived type has been
5831 Indic := Subtype_Indication
5832 (Type_Definition (Original_Node (Parent (F_Typ))));
5834 if Nkind (Indic) = N_Subtype_Indication then
5835 G_Typ := Entity (Subtype_Mark (Indic));
5837 G_Typ := Entity (Indic);
5840 if Nkind (Parent (G_Typ)) = N_Subtype_Declaration
5841 and then Present (Generic_Parent_Type (Parent (G_Typ)))
5843 return Generic_Parent_Type (Parent (G_Typ));
5848 end Get_Generic_Parent_Type;
5850 ----------------------
5851 -- Types_Correspond --
5852 ----------------------
5854 function Types_Correspond
5855 (P_Type : Entity_Id;
5856 N_Type : Entity_Id) return Boolean
5858 Prev_Type : Entity_Id := Base_Type (P_Type);
5859 New_Type : Entity_Id := Base_Type (N_Type);
5862 if Ekind (Prev_Type) = E_Anonymous_Access_Type then
5863 Prev_Type := Designated_Type (Prev_Type);
5866 if Ekind (New_Type) = E_Anonymous_Access_Type then
5867 New_Type := Designated_Type (New_Type);
5870 if Prev_Type = New_Type then
5873 elsif not Is_Class_Wide_Type (New_Type) then
5874 while Etype (New_Type) /= New_Type loop
5875 New_Type := Etype (New_Type);
5876 if New_Type = Prev_Type then
5882 end Types_Correspond;
5884 -- Start of processing for Is_Non_Overriding_Operation
5887 -- In the case where both operations are implicit derived subprograms
5888 -- then neither overrides the other. This can only occur in certain
5889 -- obscure cases (e.g., derivation from homographs created in a generic
5892 if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then
5895 elsif Ekind (Current_Scope) = E_Package
5896 and then Is_Generic_Instance (Current_Scope)
5897 and then In_Private_Part (Current_Scope)
5898 and then Comes_From_Source (New_E)
5900 -- We examine the formals and result subtype of the inherited
5901 -- operation, to determine whether their type is derived from (the
5902 -- instance of) a generic type.
5904 Formal := First_Formal (Prev_E);
5906 while Present (Formal) loop
5907 F_Typ := Base_Type (Etype (Formal));
5909 if Ekind (F_Typ) = E_Anonymous_Access_Type then
5910 F_Typ := Designated_Type (F_Typ);
5913 G_Typ := Get_Generic_Parent_Type (F_Typ);
5915 Next_Formal (Formal);
5918 if No (G_Typ) and then Ekind (Prev_E) = E_Function then
5919 G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E)));
5926 -- If the generic type is a private type, then the original
5927 -- operation was not overriding in the generic, because there was
5928 -- no primitive operation to override.
5930 if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration
5931 and then Nkind (Formal_Type_Definition (Parent (G_Typ))) =
5932 N_Formal_Private_Type_Definition
5936 -- The generic parent type is the ancestor of a formal derived
5937 -- type declaration. We need to check whether it has a primitive
5938 -- operation that should be overridden by New_E in the generic.
5942 P_Formal : Entity_Id;
5943 N_Formal : Entity_Id;
5947 Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ));
5950 while Present (Prim_Elt) loop
5951 P_Prim := Node (Prim_Elt);
5953 if Chars (P_Prim) = Chars (New_E)
5954 and then Ekind (P_Prim) = Ekind (New_E)
5956 P_Formal := First_Formal (P_Prim);
5957 N_Formal := First_Formal (New_E);
5958 while Present (P_Formal) and then Present (N_Formal) loop
5959 P_Typ := Etype (P_Formal);
5960 N_Typ := Etype (N_Formal);
5962 if not Types_Correspond (P_Typ, N_Typ) then
5966 Next_Entity (P_Formal);
5967 Next_Entity (N_Formal);
5970 -- Found a matching primitive operation belonging to the
5971 -- formal ancestor type, so the new subprogram is
5975 and then No (N_Formal)
5976 and then (Ekind (New_E) /= E_Function
5979 (Etype (P_Prim), Etype (New_E)))
5985 Next_Elmt (Prim_Elt);
5988 -- If no match found, then the new subprogram does not
5989 -- override in the generic (nor in the instance).
5997 end Is_Non_Overriding_Operation;
5999 ------------------------------
6000 -- Make_Inequality_Operator --
6001 ------------------------------
6003 -- S is the defining identifier of an equality operator. We build a
6004 -- subprogram declaration with the right signature. This operation is
6005 -- intrinsic, because it is always expanded as the negation of the
6006 -- call to the equality function.
6008 procedure Make_Inequality_Operator (S : Entity_Id) is
6009 Loc : constant Source_Ptr := Sloc (S);
6012 Op_Name : Entity_Id;
6014 FF : constant Entity_Id := First_Formal (S);
6015 NF : constant Entity_Id := Next_Formal (FF);
6018 -- Check that equality was properly defined, ignore call if not
6025 A : constant Entity_Id :=
6026 Make_Defining_Identifier (Sloc (FF),
6027 Chars => Chars (FF));
6029 B : constant Entity_Id :=
6030 Make_Defining_Identifier (Sloc (NF),
6031 Chars => Chars (NF));
6034 Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne);
6036 Formals := New_List (
6037 Make_Parameter_Specification (Loc,
6038 Defining_Identifier => A,
6040 New_Reference_To (Etype (First_Formal (S)),
6041 Sloc (Etype (First_Formal (S))))),
6043 Make_Parameter_Specification (Loc,
6044 Defining_Identifier => B,
6046 New_Reference_To (Etype (Next_Formal (First_Formal (S))),
6047 Sloc (Etype (Next_Formal (First_Formal (S)))))));
6050 Make_Subprogram_Declaration (Loc,
6052 Make_Function_Specification (Loc,
6053 Defining_Unit_Name => Op_Name,
6054 Parameter_Specifications => Formals,
6055 Result_Definition =>
6056 New_Reference_To (Standard_Boolean, Loc)));
6058 -- Insert inequality right after equality if it is explicit or after
6059 -- the derived type when implicit. These entities are created only
6060 -- for visibility purposes, and eventually replaced in the course of
6061 -- expansion, so they do not need to be attached to the tree and seen
6062 -- by the back-end. Keeping them internal also avoids spurious
6063 -- freezing problems. The declaration is inserted in the tree for
6064 -- analysis, and removed afterwards. If the equality operator comes
6065 -- from an explicit declaration, attach the inequality immediately
6066 -- after. Else the equality is inherited from a derived type
6067 -- declaration, so insert inequality after that declaration.
6069 if No (Alias (S)) then
6070 Insert_After (Unit_Declaration_Node (S), Decl);
6071 elsif Is_List_Member (Parent (S)) then
6072 Insert_After (Parent (S), Decl);
6074 Insert_After (Parent (Etype (First_Formal (S))), Decl);
6077 Mark_Rewrite_Insertion (Decl);
6078 Set_Is_Intrinsic_Subprogram (Op_Name);
6081 Set_Has_Completion (Op_Name);
6082 Set_Corresponding_Equality (Op_Name, S);
6083 Set_Is_Abstract_Subprogram (Op_Name, Is_Abstract_Subprogram (S));
6085 end Make_Inequality_Operator;
6087 ----------------------
6088 -- May_Need_Actuals --
6089 ----------------------
6091 procedure May_Need_Actuals (Fun : Entity_Id) is
6096 F := First_Formal (Fun);
6098 while Present (F) loop
6099 if No (Default_Value (F)) then
6107 Set_Needs_No_Actuals (Fun, B);
6108 end May_Need_Actuals;
6110 ---------------------
6111 -- Mode_Conformant --
6112 ---------------------
6114 function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
6117 Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result);
6119 end Mode_Conformant;
6121 ---------------------------
6122 -- New_Overloaded_Entity --
6123 ---------------------------
6125 procedure New_Overloaded_Entity
6127 Derived_Type : Entity_Id := Empty)
6129 Overridden_Subp : Entity_Id := Empty;
6130 -- Set if the current scope has an operation that is type-conformant
6131 -- with S, and becomes hidden by S.
6133 Is_Primitive_Subp : Boolean;
6134 -- Set to True if the new subprogram is primitive
6137 -- Entity that S overrides
6139 Prev_Vis : Entity_Id := Empty;
6140 -- Predecessor of E in Homonym chain
6142 procedure Check_For_Primitive_Subprogram
6143 (Is_Primitive : out Boolean;
6144 Is_Overriding : Boolean := False);
6145 -- If the subprogram being analyzed is a primitive operation of the type
6146 -- of a formal or result, set the Has_Primitive_Operations flag on the
6147 -- type, and set Is_Primitive to True (otherwise set to False). Set the
6148 -- corresponding flag on the entity itself for later use.
6150 procedure Check_Synchronized_Overriding
6151 (Def_Id : Entity_Id;
6152 First_Hom : Entity_Id;
6153 Overridden_Subp : out Entity_Id);
6154 -- First determine if Def_Id is an entry or a subprogram either defined
6155 -- in the scope of a task or protected type, or is a primitive of such
6156 -- a type. Check whether Def_Id overrides a subprogram of an interface
6157 -- implemented by the synchronized type, return the overridden entity
6160 function Is_Private_Declaration (E : Entity_Id) return Boolean;
6161 -- Check that E is declared in the private part of the current package,
6162 -- or in the package body, where it may hide a previous declaration.
6163 -- We can't use In_Private_Part by itself because this flag is also
6164 -- set when freezing entities, so we must examine the place of the
6165 -- declaration in the tree, and recognize wrapper packages as well.
6167 ------------------------------------
6168 -- Check_For_Primitive_Subprogram --
6169 ------------------------------------
6171 procedure Check_For_Primitive_Subprogram
6172 (Is_Primitive : out Boolean;
6173 Is_Overriding : Boolean := False)
6179 function Visible_Part_Type (T : Entity_Id) return Boolean;
6180 -- Returns true if T is declared in the visible part of
6181 -- the current package scope; otherwise returns false.
6182 -- Assumes that T is declared in a package.
6184 procedure Check_Private_Overriding (T : Entity_Id);
6185 -- Checks that if a primitive abstract subprogram of a visible
6186 -- abstract type is declared in a private part, then it must
6187 -- override an abstract subprogram declared in the visible part.
6188 -- Also checks that if a primitive function with a controlling
6189 -- result is declared in a private part, then it must override
6190 -- a function declared in the visible part.
6192 ------------------------------
6193 -- Check_Private_Overriding --
6194 ------------------------------
6196 procedure Check_Private_Overriding (T : Entity_Id) is
6198 if Ekind (Current_Scope) = E_Package
6199 and then In_Private_Part (Current_Scope)
6200 and then Visible_Part_Type (T)
6201 and then not In_Instance
6203 if Is_Abstract_Type (T)
6204 and then Is_Abstract_Subprogram (S)
6205 and then (not Is_Overriding
6206 or else not Is_Abstract_Subprogram (E))
6208 Error_Msg_N ("abstract subprograms must be visible "
6209 & "(RM 3.9.3(10))!", S);
6211 elsif Ekind (S) = E_Function
6212 and then Is_Tagged_Type (T)
6213 and then T = Base_Type (Etype (S))
6214 and then not Is_Overriding
6217 ("private function with tagged result must"
6218 & " override visible-part function", S);
6220 ("\move subprogram to the visible part"
6221 & " (RM 3.9.3(10))", S);
6224 end Check_Private_Overriding;
6226 -----------------------
6227 -- Visible_Part_Type --
6228 -----------------------
6230 function Visible_Part_Type (T : Entity_Id) return Boolean is
6231 P : constant Node_Id := Unit_Declaration_Node (Scope (T));
6235 -- If the entity is a private type, then it must be
6236 -- declared in a visible part.
6238 if Ekind (T) in Private_Kind then
6242 -- Otherwise, we traverse the visible part looking for its
6243 -- corresponding declaration. We cannot use the declaration
6244 -- node directly because in the private part the entity of a
6245 -- private type is the one in the full view, which does not
6246 -- indicate that it is the completion of something visible.
6248 N := First (Visible_Declarations (Specification (P)));
6249 while Present (N) loop
6250 if Nkind (N) = N_Full_Type_Declaration
6251 and then Present (Defining_Identifier (N))
6252 and then T = Defining_Identifier (N)
6256 elsif Nkind_In (N, N_Private_Type_Declaration,
6257 N_Private_Extension_Declaration)
6258 and then Present (Defining_Identifier (N))
6259 and then T = Full_View (Defining_Identifier (N))
6268 end Visible_Part_Type;
6270 -- Start of processing for Check_For_Primitive_Subprogram
6273 Is_Primitive := False;
6275 if not Comes_From_Source (S) then
6278 -- If subprogram is at library level, it is not primitive operation
6280 elsif Current_Scope = Standard_Standard then
6283 elsif ((Ekind (Current_Scope) = E_Package
6284 or else Ekind (Current_Scope) = E_Generic_Package)
6285 and then not In_Package_Body (Current_Scope))
6286 or else Is_Overriding
6288 -- For function, check return type
6290 if Ekind (S) = E_Function then
6291 if Ekind (Etype (S)) = E_Anonymous_Access_Type then
6292 F_Typ := Designated_Type (Etype (S));
6297 B_Typ := Base_Type (F_Typ);
6299 if Scope (B_Typ) = Current_Scope
6300 and then not Is_Class_Wide_Type (B_Typ)
6301 and then not Is_Generic_Type (B_Typ)
6303 Is_Primitive := True;
6304 Set_Has_Primitive_Operations (B_Typ);
6305 Set_Is_Primitive (S);
6306 Check_Private_Overriding (B_Typ);
6310 -- For all subprograms, check formals
6312 Formal := First_Formal (S);
6313 while Present (Formal) loop
6314 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
6315 F_Typ := Designated_Type (Etype (Formal));
6317 F_Typ := Etype (Formal);
6320 B_Typ := Base_Type (F_Typ);
6322 if Ekind (B_Typ) = E_Access_Subtype then
6323 B_Typ := Base_Type (B_Typ);
6326 if Scope (B_Typ) = Current_Scope
6327 and then not Is_Class_Wide_Type (B_Typ)
6328 and then not Is_Generic_Type (B_Typ)
6330 Is_Primitive := True;
6331 Set_Is_Primitive (S);
6332 Set_Has_Primitive_Operations (B_Typ);
6333 Check_Private_Overriding (B_Typ);
6336 Next_Formal (Formal);
6339 end Check_For_Primitive_Subprogram;
6341 -----------------------------------
6342 -- Check_Synchronized_Overriding --
6343 -----------------------------------
6345 procedure Check_Synchronized_Overriding
6346 (Def_Id : Entity_Id;
6347 First_Hom : Entity_Id;
6348 Overridden_Subp : out Entity_Id)
6350 Formal_Typ : Entity_Id;
6351 Ifaces_List : Elist_Id;
6356 Overridden_Subp := Empty;
6358 -- Def_Id must be an entry or a subprogram
6360 if Ekind (Def_Id) /= E_Entry
6361 and then Ekind (Def_Id) /= E_Function
6362 and then Ekind (Def_Id) /= E_Procedure
6367 -- Search for the concurrent declaration since it contains the list
6368 -- of all implemented interfaces. In this case, the subprogram is
6369 -- declared within the scope of a protected or a task type.
6371 if Present (Scope (Def_Id))
6372 and then Is_Concurrent_Type (Scope (Def_Id))
6373 and then not Is_Generic_Actual_Type (Scope (Def_Id))
6375 Typ := Scope (Def_Id);
6378 -- The subprogram may be a primitive of a concurrent type
6380 elsif Present (First_Formal (Def_Id)) then
6381 Formal_Typ := Etype (First_Formal (Def_Id));
6383 if Is_Concurrent_Type (Formal_Typ)
6384 and then not Is_Generic_Actual_Type (Formal_Typ)
6389 -- This case occurs when the concurrent type is declared within
6390 -- a generic unit. As a result the corresponding record has been
6391 -- built and used as the type of the first formal, we just have
6392 -- to retrieve the corresponding concurrent type.
6394 elsif Is_Concurrent_Record_Type (Formal_Typ)
6395 and then Present (Corresponding_Concurrent_Type (Formal_Typ))
6397 Typ := Corresponding_Concurrent_Type (Formal_Typ);
6407 -- Gather all limited, protected and task interfaces that Typ
6408 -- implements. There is no overriding to check if is an inherited
6409 -- operation in a type derivation on for a generic actual.
6411 if Nkind (Parent (Typ)) /= N_Full_Type_Declaration
6413 not Nkind_In (Parent (Def_Id), N_Subtype_Declaration,
6414 N_Task_Type_Declaration,
6415 N_Protected_Type_Declaration)
6417 Collect_Abstract_Interfaces (Typ, Ifaces_List);
6419 if not Is_Empty_Elmt_List (Ifaces_List) then
6421 Find_Overridden_Synchronized_Primitive
6422 (Def_Id, First_Hom, Ifaces_List, In_Scope);
6425 end Check_Synchronized_Overriding;
6427 ----------------------------
6428 -- Is_Private_Declaration --
6429 ----------------------------
6431 function Is_Private_Declaration (E : Entity_Id) return Boolean is
6432 Priv_Decls : List_Id;
6433 Decl : constant Node_Id := Unit_Declaration_Node (E);
6436 if Is_Package_Or_Generic_Package (Current_Scope)
6437 and then In_Private_Part (Current_Scope)
6440 Private_Declarations (
6441 Specification (Unit_Declaration_Node (Current_Scope)));
6443 return In_Package_Body (Current_Scope)
6445 (Is_List_Member (Decl)
6446 and then List_Containing (Decl) = Priv_Decls)
6447 or else (Nkind (Parent (Decl)) = N_Package_Specification
6448 and then not Is_Compilation_Unit (
6449 Defining_Entity (Parent (Decl)))
6450 and then List_Containing (Parent (Parent (Decl)))
6455 end Is_Private_Declaration;
6457 -- Start of processing for New_Overloaded_Entity
6460 -- We need to look for an entity that S may override. This must be a
6461 -- homonym in the current scope, so we look for the first homonym of
6462 -- S in the current scope as the starting point for the search.
6464 E := Current_Entity_In_Scope (S);
6466 -- If there is no homonym then this is definitely not overriding
6469 Enter_Overloaded_Entity (S);
6470 Check_Dispatching_Operation (S, Empty);
6471 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
6473 -- If subprogram has an explicit declaration, check whether it
6474 -- has an overriding indicator.
6476 if Comes_From_Source (S) then
6477 Check_Synchronized_Overriding (S, Homonym (S), Overridden_Subp);
6478 Check_Overriding_Indicator
6479 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
6482 -- If there is a homonym that is not overloadable, then we have an
6483 -- error, except for the special cases checked explicitly below.
6485 elsif not Is_Overloadable (E) then
6487 -- Check for spurious conflict produced by a subprogram that has the
6488 -- same name as that of the enclosing generic package. The conflict
6489 -- occurs within an instance, between the subprogram and the renaming
6490 -- declaration for the package. After the subprogram, the package
6491 -- renaming declaration becomes hidden.
6493 if Ekind (E) = E_Package
6494 and then Present (Renamed_Object (E))
6495 and then Renamed_Object (E) = Current_Scope
6496 and then Nkind (Parent (Renamed_Object (E))) =
6497 N_Package_Specification
6498 and then Present (Generic_Parent (Parent (Renamed_Object (E))))
6501 Set_Is_Immediately_Visible (E, False);
6502 Enter_Overloaded_Entity (S);
6503 Set_Homonym (S, Homonym (E));
6504 Check_Dispatching_Operation (S, Empty);
6505 Check_Overriding_Indicator (S, Empty, Is_Primitive => False);
6507 -- If the subprogram is implicit it is hidden by the previous
6508 -- declaration. However if it is dispatching, it must appear in the
6509 -- dispatch table anyway, because it can be dispatched to even if it
6510 -- cannot be called directly.
6512 elsif Present (Alias (S))
6513 and then not Comes_From_Source (S)
6515 Set_Scope (S, Current_Scope);
6517 if Is_Dispatching_Operation (Alias (S)) then
6518 Check_Dispatching_Operation (S, Empty);
6524 Error_Msg_Sloc := Sloc (E);
6526 -- Generate message,with useful additionalwarning if in generic
6528 if Is_Generic_Unit (E) then
6529 Error_Msg_N ("previous generic unit cannot be overloaded", S);
6530 Error_Msg_N ("\& conflicts with declaration#", S);
6532 Error_Msg_N ("& conflicts with declaration#", S);
6538 -- E exists and is overloadable
6541 -- Ada 2005 (AI-251): Derivation of abstract interface primitives
6542 -- need no check against the homonym chain. They are directly added
6543 -- to the list of primitive operations of Derived_Type.
6545 if Ada_Version >= Ada_05
6546 and then Present (Derived_Type)
6547 and then Is_Dispatching_Operation (Alias (S))
6548 and then Present (Find_Dispatching_Type (Alias (S)))
6549 and then Is_Interface (Find_Dispatching_Type (Alias (S)))
6550 and then not Is_Predefined_Dispatching_Operation (Alias (S))
6552 goto Add_New_Entity;
6555 Check_Synchronized_Overriding (S, E, Overridden_Subp);
6557 -- Loop through E and its homonyms to determine if any of them is
6558 -- the candidate for overriding by S.
6560 while Present (E) loop
6562 -- Definitely not interesting if not in the current scope
6564 if Scope (E) /= Current_Scope then
6567 -- Check if we have type conformance
6569 elsif Type_Conformant (E, S) then
6571 -- If the old and new entities have the same profile and one
6572 -- is not the body of the other, then this is an error, unless
6573 -- one of them is implicitly declared.
6575 -- There are some cases when both can be implicit, for example
6576 -- when both a literal and a function that overrides it are
6577 -- inherited in a derivation, or when an inhertited operation
6578 -- of a tagged full type overrides the inherited operation of
6579 -- a private extension. Ada 83 had a special rule for the the
6580 -- literal case. In Ada95, the later implicit operation hides
6581 -- the former, and the literal is always the former. In the
6582 -- odd case where both are derived operations declared at the
6583 -- same point, both operations should be declared, and in that
6584 -- case we bypass the following test and proceed to the next
6585 -- part (this can only occur for certain obscure cases
6586 -- involving homographs in instances and can't occur for
6587 -- dispatching operations ???). Note that the following
6588 -- condition is less than clear. For example, it's not at all
6589 -- clear why there's a test for E_Entry here. ???
6591 if Present (Alias (S))
6592 and then (No (Alias (E))
6593 or else Comes_From_Source (E)
6594 or else Is_Dispatching_Operation (E))
6596 (Ekind (E) = E_Entry
6597 or else Ekind (E) /= E_Enumeration_Literal)
6599 -- When an derived operation is overloaded it may be due to
6600 -- the fact that the full view of a private extension
6601 -- re-inherits. It has to be dealt with.
6603 if Is_Package_Or_Generic_Package (Current_Scope)
6604 and then In_Private_Part (Current_Scope)
6606 Check_Operation_From_Private_View (S, E);
6609 -- In any case the implicit operation remains hidden by
6610 -- the existing declaration, which is overriding.
6612 Set_Is_Overriding_Operation (E);
6614 if Comes_From_Source (E) then
6615 Check_Overriding_Indicator (E, S, Is_Primitive => False);
6617 -- Indicate that E overrides the operation from which
6620 if Present (Alias (S)) then
6621 Set_Overridden_Operation (E, Alias (S));
6623 Set_Overridden_Operation (E, S);
6629 -- Within an instance, the renaming declarations for
6630 -- actual subprograms may become ambiguous, but they do
6631 -- not hide each other.
6633 elsif Ekind (E) /= E_Entry
6634 and then not Comes_From_Source (E)
6635 and then not Is_Generic_Instance (E)
6636 and then (Present (Alias (E))
6637 or else Is_Intrinsic_Subprogram (E))
6638 and then (not In_Instance
6639 or else No (Parent (E))
6640 or else Nkind (Unit_Declaration_Node (E)) /=
6641 N_Subprogram_Renaming_Declaration)
6643 -- A subprogram child unit is not allowed to override
6644 -- an inherited subprogram (10.1.1(20)).
6646 if Is_Child_Unit (S) then
6648 ("child unit overrides inherited subprogram in parent",
6653 if Is_Non_Overriding_Operation (E, S) then
6654 Enter_Overloaded_Entity (S);
6655 if No (Derived_Type)
6656 or else Is_Tagged_Type (Derived_Type)
6658 Check_Dispatching_Operation (S, Empty);
6664 -- E is a derived operation or an internal operator which
6665 -- is being overridden. Remove E from further visibility.
6666 -- Furthermore, if E is a dispatching operation, it must be
6667 -- replaced in the list of primitive operations of its type
6668 -- (see Override_Dispatching_Operation).
6670 Overridden_Subp := E;
6676 Prev := First_Entity (Current_Scope);
6678 while Present (Prev)
6679 and then Next_Entity (Prev) /= E
6684 -- It is possible for E to be in the current scope and
6685 -- yet not in the entity chain. This can only occur in a
6686 -- generic context where E is an implicit concatenation
6687 -- in the formal part, because in a generic body the
6688 -- entity chain starts with the formals.
6691 (Present (Prev) or else Chars (E) = Name_Op_Concat);
6693 -- E must be removed both from the entity_list of the
6694 -- current scope, and from the visibility chain
6696 if Debug_Flag_E then
6697 Write_Str ("Override implicit operation ");
6698 Write_Int (Int (E));
6702 -- If E is a predefined concatenation, it stands for four
6703 -- different operations. As a result, a single explicit
6704 -- declaration does not hide it. In a possible ambiguous
6705 -- situation, Disambiguate chooses the user-defined op,
6706 -- so it is correct to retain the previous internal one.
6708 if Chars (E) /= Name_Op_Concat
6709 or else Ekind (E) /= E_Operator
6711 -- For nondispatching derived operations that are
6712 -- overridden by a subprogram declared in the private
6713 -- part of a package, we retain the derived
6714 -- subprogram but mark it as not immediately visible.
6715 -- If the derived operation was declared in the
6716 -- visible part then this ensures that it will still
6717 -- be visible outside the package with the proper
6718 -- signature (calls from outside must also be
6719 -- directed to this version rather than the
6720 -- overriding one, unlike the dispatching case).
6721 -- Calls from inside the package will still resolve
6722 -- to the overriding subprogram since the derived one
6723 -- is marked as not visible within the package.
6725 -- If the private operation is dispatching, we achieve
6726 -- the overriding by keeping the implicit operation
6727 -- but setting its alias to be the overriding one. In
6728 -- this fashion the proper body is executed in all
6729 -- cases, but the original signature is used outside
6732 -- If the overriding is not in the private part, we
6733 -- remove the implicit operation altogether.
6735 if Is_Private_Declaration (S) then
6737 if not Is_Dispatching_Operation (E) then
6738 Set_Is_Immediately_Visible (E, False);
6740 -- Work done in Override_Dispatching_Operation,
6741 -- so nothing else need to be done here.
6747 -- Find predecessor of E in Homonym chain
6749 if E = Current_Entity (E) then
6752 Prev_Vis := Current_Entity (E);
6753 while Homonym (Prev_Vis) /= E loop
6754 Prev_Vis := Homonym (Prev_Vis);
6758 if Prev_Vis /= Empty then
6760 -- Skip E in the visibility chain
6762 Set_Homonym (Prev_Vis, Homonym (E));
6765 Set_Name_Entity_Id (Chars (E), Homonym (E));
6768 Set_Next_Entity (Prev, Next_Entity (E));
6770 if No (Next_Entity (Prev)) then
6771 Set_Last_Entity (Current_Scope, Prev);
6777 Enter_Overloaded_Entity (S);
6778 Set_Is_Overriding_Operation (S);
6779 Check_Overriding_Indicator (S, E, Is_Primitive => True);
6781 -- Indicate that S overrides the operation from which
6784 if Comes_From_Source (S) then
6785 if Present (Alias (E)) then
6786 Set_Overridden_Operation (S, Alias (E));
6788 Set_Overridden_Operation (S, E);
6792 if Is_Dispatching_Operation (E) then
6794 -- An overriding dispatching subprogram inherits the
6795 -- convention of the overridden subprogram (by
6798 Set_Convention (S, Convention (E));
6799 Check_Dispatching_Operation (S, E);
6802 Check_Dispatching_Operation (S, Empty);
6805 Check_For_Primitive_Subprogram
6806 (Is_Primitive_Subp, Is_Overriding => True);
6807 goto Check_Inequality;
6810 -- Apparent redeclarations in instances can occur when two
6811 -- formal types get the same actual type. The subprograms in
6812 -- in the instance are legal, even if not callable from the
6813 -- outside. Calls from within are disambiguated elsewhere.
6814 -- For dispatching operations in the visible part, the usual
6815 -- rules apply, and operations with the same profile are not
6818 elsif (In_Instance_Visible_Part
6819 and then not Is_Dispatching_Operation (E))
6820 or else In_Instance_Not_Visible
6824 -- Here we have a real error (identical profile)
6827 Error_Msg_Sloc := Sloc (E);
6829 -- Avoid cascaded errors if the entity appears in
6830 -- subsequent calls.
6832 Set_Scope (S, Current_Scope);
6834 -- Generate error, with extra useful warning for the case
6835 -- of a generic instance with no completion.
6837 if Is_Generic_Instance (S)
6838 and then not Has_Completion (E)
6841 ("instantiation cannot provide body for&", S);
6842 Error_Msg_N ("\& conflicts with declaration#", S);
6844 Error_Msg_N ("& conflicts with declaration#", S);
6851 -- If one subprogram has an access parameter and the other
6852 -- a parameter of an access type, calls to either might be
6853 -- ambiguous. Verify that parameters match except for the
6854 -- access parameter.
6856 if May_Hide_Profile then
6861 F1 := First_Formal (S);
6862 F2 := First_Formal (E);
6863 while Present (F1) and then Present (F2) loop
6864 if Is_Access_Type (Etype (F1)) then
6865 if not Is_Access_Type (Etype (F2))
6866 or else not Conforming_Types
6867 (Designated_Type (Etype (F1)),
6868 Designated_Type (Etype (F2)),
6871 May_Hide_Profile := False;
6875 not Conforming_Types
6876 (Etype (F1), Etype (F2), Type_Conformant)
6878 May_Hide_Profile := False;
6889 Error_Msg_NE ("calls to& may be ambiguous?", S, S);
6900 -- On exit, we know that S is a new entity
6902 Enter_Overloaded_Entity (S);
6903 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
6904 Check_Overriding_Indicator
6905 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
6907 -- If S is a derived operation for an untagged type then by
6908 -- definition it's not a dispatching operation (even if the parent
6909 -- operation was dispatching), so we don't call
6910 -- Check_Dispatching_Operation in that case.
6912 if No (Derived_Type)
6913 or else Is_Tagged_Type (Derived_Type)
6915 Check_Dispatching_Operation (S, Empty);
6919 -- If this is a user-defined equality operator that is not a derived
6920 -- subprogram, create the corresponding inequality. If the operation is
6921 -- dispatching, the expansion is done elsewhere, and we do not create
6922 -- an explicit inequality operation.
6924 <<Check_Inequality>>
6925 if Chars (S) = Name_Op_Eq
6926 and then Etype (S) = Standard_Boolean
6927 and then Present (Parent (S))
6928 and then not Is_Dispatching_Operation (S)
6930 Make_Inequality_Operator (S);
6932 end New_Overloaded_Entity;
6934 ---------------------
6935 -- Process_Formals --
6936 ---------------------
6938 procedure Process_Formals
6940 Related_Nod : Node_Id)
6942 Param_Spec : Node_Id;
6944 Formal_Type : Entity_Id;
6948 Num_Out_Params : Nat := 0;
6949 First_Out_Param : Entity_Id := Empty;
6950 -- Used for setting Is_Only_Out_Parameter
6952 function Is_Class_Wide_Default (D : Node_Id) return Boolean;
6953 -- Check whether the default has a class-wide type. After analysis the
6954 -- default has the type of the formal, so we must also check explicitly
6955 -- for an access attribute.
6957 ---------------------------
6958 -- Is_Class_Wide_Default --
6959 ---------------------------
6961 function Is_Class_Wide_Default (D : Node_Id) return Boolean is
6963 return Is_Class_Wide_Type (Designated_Type (Etype (D)))
6964 or else (Nkind (D) = N_Attribute_Reference
6965 and then Attribute_Name (D) = Name_Access
6966 and then Is_Class_Wide_Type (Etype (Prefix (D))));
6967 end Is_Class_Wide_Default;
6969 -- Start of processing for Process_Formals
6972 -- In order to prevent premature use of the formals in the same formal
6973 -- part, the Ekind is left undefined until all default expressions are
6974 -- analyzed. The Ekind is established in a separate loop at the end.
6976 Param_Spec := First (T);
6977 while Present (Param_Spec) loop
6978 Formal := Defining_Identifier (Param_Spec);
6979 Set_Never_Set_In_Source (Formal, True);
6980 Enter_Name (Formal);
6982 -- Case of ordinary parameters
6984 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
6985 Find_Type (Parameter_Type (Param_Spec));
6986 Ptype := Parameter_Type (Param_Spec);
6988 if Ptype = Error then
6992 Formal_Type := Entity (Ptype);
6994 if Is_Incomplete_Type (Formal_Type)
6996 (Is_Class_Wide_Type (Formal_Type)
6997 and then Is_Incomplete_Type (Root_Type (Formal_Type)))
6999 -- Ada 2005 (AI-326): Tagged incomplete types allowed
7001 if Is_Tagged_Type (Formal_Type) then
7004 -- Special handling of Value_Type for CIL case
7006 elsif Is_Value_Type (Formal_Type) then
7009 elsif not Nkind_In (Parent (T), N_Access_Function_Definition,
7010 N_Access_Procedure_Definition)
7012 Error_Msg_N ("invalid use of incomplete type", Param_Spec);
7014 -- An incomplete type that is not tagged is allowed in an
7015 -- access-to-subprogram type only if it is a local declaration
7016 -- with a forthcoming completion (3.10.1 (9.2/2)).
7018 elsif Scope (Formal_Type) /= Scope (Current_Scope) then
7020 ("invalid use of limited view of type", Param_Spec);
7023 elsif Ekind (Formal_Type) = E_Void then
7024 Error_Msg_NE ("premature use of&",
7025 Parameter_Type (Param_Spec), Formal_Type);
7028 -- Ada 2005 (AI-231): Create and decorate an internal subtype
7029 -- declaration corresponding to the null-excluding type of the
7030 -- formal in the enclosing scope. Finally, replace the parameter
7031 -- type of the formal with the internal subtype.
7033 if Ada_Version >= Ada_05
7034 and then Null_Exclusion_Present (Param_Spec)
7036 if not Is_Access_Type (Formal_Type) then
7038 ("`NOT NULL` allowed only for an access type", Param_Spec);
7041 if Can_Never_Be_Null (Formal_Type)
7042 and then Comes_From_Source (Related_Nod)
7045 ("`NOT NULL` not allowed (& already excludes null)",
7051 Create_Null_Excluding_Itype
7053 Related_Nod => Related_Nod,
7054 Scope_Id => Scope (Current_Scope));
7056 -- If the designated type of the itype is an itype we
7057 -- decorate it with the Has_Delayed_Freeze attribute to
7058 -- avoid problems with the backend.
7061 -- type T is access procedure;
7062 -- procedure Op (O : not null T);
7064 if Is_Itype (Directly_Designated_Type (Formal_Type)) then
7065 Set_Has_Delayed_Freeze (Formal_Type);
7070 -- An access formal type
7074 Access_Definition (Related_Nod, Parameter_Type (Param_Spec));
7076 -- No need to continue if we already notified errors
7078 if not Present (Formal_Type) then
7082 -- Ada 2005 (AI-254)
7085 AD : constant Node_Id :=
7086 Access_To_Subprogram_Definition
7087 (Parameter_Type (Param_Spec));
7089 if Present (AD) and then Protected_Present (AD) then
7091 Replace_Anonymous_Access_To_Protected_Subprogram
7097 Set_Etype (Formal, Formal_Type);
7098 Default := Expression (Param_Spec);
7100 if Present (Default) then
7101 if Out_Present (Param_Spec) then
7103 ("default initialization only allowed for IN parameters",
7107 -- Do the special preanalysis of the expression (see section on
7108 -- "Handling of Default Expressions" in the spec of package Sem).
7110 Preanalyze_Spec_Expression (Default, Formal_Type);
7112 -- An access to constant cannot be the default for
7113 -- an access parameter that is an access to variable.
7115 if Ekind (Formal_Type) = E_Anonymous_Access_Type
7116 and then not Is_Access_Constant (Formal_Type)
7117 and then Is_Access_Type (Etype (Default))
7118 and then Is_Access_Constant (Etype (Default))
7121 ("formal that is access to variable cannot be initialized " &
7122 "with an access-to-constant expression", Default);
7125 -- Check that the designated type of an access parameter's default
7126 -- is not a class-wide type unless the parameter's designated type
7127 -- is also class-wide.
7129 if Ekind (Formal_Type) = E_Anonymous_Access_Type
7130 and then not From_With_Type (Formal_Type)
7131 and then Is_Class_Wide_Default (Default)
7132 and then not Is_Class_Wide_Type (Designated_Type (Formal_Type))
7135 ("access to class-wide expression not allowed here", Default);
7139 -- Ada 2005 (AI-231): Static checks
7141 if Ada_Version >= Ada_05
7142 and then Is_Access_Type (Etype (Formal))
7143 and then Can_Never_Be_Null (Etype (Formal))
7145 Null_Exclusion_Static_Checks (Param_Spec);
7152 -- If this is the formal part of a function specification, analyze the
7153 -- subtype mark in the context where the formals are visible but not
7154 -- yet usable, and may hide outer homographs.
7156 if Nkind (Related_Nod) = N_Function_Specification then
7157 Analyze_Return_Type (Related_Nod);
7160 -- Now set the kind (mode) of each formal
7162 Param_Spec := First (T);
7164 while Present (Param_Spec) loop
7165 Formal := Defining_Identifier (Param_Spec);
7166 Set_Formal_Mode (Formal);
7168 if Ekind (Formal) = E_In_Parameter then
7169 Set_Default_Value (Formal, Expression (Param_Spec));
7171 if Present (Expression (Param_Spec)) then
7172 Default := Expression (Param_Spec);
7174 if Is_Scalar_Type (Etype (Default)) then
7176 (Parameter_Type (Param_Spec)) /= N_Access_Definition
7178 Formal_Type := Entity (Parameter_Type (Param_Spec));
7181 Formal_Type := Access_Definition
7182 (Related_Nod, Parameter_Type (Param_Spec));
7185 Apply_Scalar_Range_Check (Default, Formal_Type);
7189 elsif Ekind (Formal) = E_Out_Parameter then
7190 Num_Out_Params := Num_Out_Params + 1;
7192 if Num_Out_Params = 1 then
7193 First_Out_Param := Formal;
7196 elsif Ekind (Formal) = E_In_Out_Parameter then
7197 Num_Out_Params := Num_Out_Params + 1;
7203 if Present (First_Out_Param) and then Num_Out_Params = 1 then
7204 Set_Is_Only_Out_Parameter (First_Out_Param);
7206 end Process_Formals;
7212 procedure Process_PPCs
7214 Spec_Id : Entity_Id;
7215 Body_Id : Entity_Id)
7217 Loc : constant Source_Ptr := Sloc (N);
7219 Plist : List_Id := No_List;
7223 function Grab_PPC (Nam : Name_Id) return Node_Id;
7224 -- Prag contains an analyzed precondition or postcondition pragma.
7225 -- This function copies the pragma, changes it to the corresponding
7226 -- Check pragma and returns the Check pragma as the result. The
7227 -- argument Nam is either Name_Precondition or Name_Postcondition.
7233 function Grab_PPC (Nam : Name_Id) return Node_Id is
7234 CP : constant Node_Id := New_Copy_Tree (Prag);
7237 -- Set Analyzed to false, since we want to reanalyze the check
7238 -- procedure. Note that it is only at the outer level that we
7239 -- do this fiddling, for the spec cases, the already preanalyzed
7240 -- parameters are not affected.
7242 Set_Analyzed (CP, False);
7244 -- Change pragma into corresponding pragma Check
7246 Prepend_To (Pragma_Argument_Associations (CP),
7247 Make_Pragma_Argument_Association (Sloc (Prag),
7249 Make_Identifier (Loc,
7251 Set_Pragma_Identifier (CP,
7252 Make_Identifier (Sloc (Prag),
7253 Chars => Name_Check));
7258 -- Start of processing for Process_PPCs
7261 -- Grab preconditions from spec
7263 if Present (Spec_Id) then
7265 -- Loop through PPC pragmas from spec. Note that preconditions from
7266 -- the body will be analyzed and converted when we scan the body
7267 -- declarations below.
7269 Prag := Spec_PPC_List (Spec_Id);
7270 while Present (Prag) loop
7271 if Pragma_Name (Prag) = Name_Precondition
7272 and then PPC_Enabled (Prag)
7274 -- Add pragma Check at the start of the declarations of N.
7275 -- Note that this processing reverses the order of the list,
7276 -- which is what we want since new entries were chained to
7277 -- the head of the list.
7279 Prepend (Grab_PPC (Name_Precondition), Declarations (N));
7282 Prag := Next_Pragma (Prag);
7286 -- Build postconditions procedure if needed and prepend the following
7287 -- declaration to the start of the declarations for the subprogram.
7289 -- procedure _postconditions [(_Result : resulttype)] is
7291 -- pragma Check (Postcondition, condition [,message]);
7292 -- pragma Check (Postcondition, condition [,message]);
7296 -- First we deal with the postconditions in the body
7298 if Is_Non_Empty_List (Declarations (N)) then
7300 -- Loop through declarations
7302 Prag := First (Declarations (N));
7303 while Present (Prag) loop
7304 if Nkind (Prag) = N_Pragma then
7306 -- If pragma, capture if enabled postcondition, else ignore
7308 if Pragma_Name (Prag) = Name_Postcondition
7309 and then Check_Enabled (Name_Postcondition)
7311 if Plist = No_List then
7312 Plist := Empty_List;
7316 Append (Grab_PPC (Name_Postcondition), Plist);
7321 -- Not a pragma, if comes from source, then end scan
7323 elsif Comes_From_Source (Prag) then
7326 -- Skip stuff not coming from source
7334 -- Now deal with any postconditions from the spec
7336 if Present (Spec_Id) then
7338 -- Loop through PPC pragmas from spec
7340 Prag := Spec_PPC_List (Spec_Id);
7341 while Present (Prag) loop
7342 if Pragma_Name (Prag) = Name_Postcondition
7343 and then PPC_Enabled (Prag)
7345 if Plist = No_List then
7346 Plist := Empty_List;
7349 Append (Grab_PPC (Name_Postcondition), Plist);
7352 Prag := Next_Pragma (Prag);
7356 -- If we had any postconditions, build the procedure
7358 if Present (Plist) then
7359 Subp := Defining_Entity (N);
7361 if Etype (Subp) /= Standard_Void_Type then
7363 Make_Parameter_Specification (Loc,
7364 Defining_Identifier =>
7365 Make_Defining_Identifier (Loc,
7366 Chars => Name_uResult),
7367 Parameter_Type => New_Occurrence_Of (Etype (Subp), Loc)));
7372 Prepend_To (Declarations (N),
7373 Make_Subprogram_Body (Loc,
7375 Make_Procedure_Specification (Loc,
7376 Defining_Unit_Name =>
7377 Make_Defining_Identifier (Loc,
7378 Chars => Name_uPostconditions),
7379 Parameter_Specifications => Parms),
7381 Declarations => Empty_List,
7383 Handled_Statement_Sequence =>
7384 Make_Handled_Sequence_Of_Statements (Loc,
7385 Statements => Plist)));
7387 if Present (Spec_Id) then
7388 Set_Has_Postconditions (Spec_Id);
7390 Set_Has_Postconditions (Body_Id);
7395 ----------------------------
7396 -- Reference_Body_Formals --
7397 ----------------------------
7399 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is
7404 if Error_Posted (Spec) then
7408 -- Iterate over both lists. They may be of different lengths if the two
7409 -- specs are not conformant.
7411 Fs := First_Formal (Spec);
7412 Fb := First_Formal (Bod);
7413 while Present (Fs) and then Present (Fb) loop
7414 Generate_Reference (Fs, Fb, 'b');
7417 Style.Check_Identifier (Fb, Fs);
7420 Set_Spec_Entity (Fb, Fs);
7421 Set_Referenced (Fs, False);
7425 end Reference_Body_Formals;
7427 -------------------------
7428 -- Set_Actual_Subtypes --
7429 -------------------------
7431 procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is
7432 Loc : constant Source_Ptr := Sloc (N);
7436 First_Stmt : Node_Id := Empty;
7437 AS_Needed : Boolean;
7440 -- If this is an emtpy initialization procedure, no need to create
7441 -- actual subtypes (small optimization).
7443 if Ekind (Subp) = E_Procedure
7444 and then Is_Null_Init_Proc (Subp)
7449 Formal := First_Formal (Subp);
7450 while Present (Formal) loop
7451 T := Etype (Formal);
7453 -- We never need an actual subtype for a constrained formal
7455 if Is_Constrained (T) then
7458 -- If we have unknown discriminants, then we do not need an actual
7459 -- subtype, or more accurately we cannot figure it out! Note that
7460 -- all class-wide types have unknown discriminants.
7462 elsif Has_Unknown_Discriminants (T) then
7465 -- At this stage we have an unconstrained type that may need an
7466 -- actual subtype. For sure the actual subtype is needed if we have
7467 -- an unconstrained array type.
7469 elsif Is_Array_Type (T) then
7472 -- The only other case needing an actual subtype is an unconstrained
7473 -- record type which is an IN parameter (we cannot generate actual
7474 -- subtypes for the OUT or IN OUT case, since an assignment can
7475 -- change the discriminant values. However we exclude the case of
7476 -- initialization procedures, since discriminants are handled very
7477 -- specially in this context, see the section entitled "Handling of
7478 -- Discriminants" in Einfo.
7480 -- We also exclude the case of Discrim_SO_Functions (functions used
7481 -- in front end layout mode for size/offset values), since in such
7482 -- functions only discriminants are referenced, and not only are such
7483 -- subtypes not needed, but they cannot always be generated, because
7484 -- of order of elaboration issues.
7486 elsif Is_Record_Type (T)
7487 and then Ekind (Formal) = E_In_Parameter
7488 and then Chars (Formal) /= Name_uInit
7489 and then not Is_Unchecked_Union (T)
7490 and then not Is_Discrim_SO_Function (Subp)
7494 -- All other cases do not need an actual subtype
7500 -- Generate actual subtypes for unconstrained arrays and
7501 -- unconstrained discriminated records.
7504 if Nkind (N) = N_Accept_Statement then
7506 -- If expansion is active, The formal is replaced by a local
7507 -- variable that renames the corresponding entry of the
7508 -- parameter block, and it is this local variable that may
7509 -- require an actual subtype.
7511 if Expander_Active then
7512 Decl := Build_Actual_Subtype (T, Renamed_Object (Formal));
7514 Decl := Build_Actual_Subtype (T, Formal);
7517 if Present (Handled_Statement_Sequence (N)) then
7519 First (Statements (Handled_Statement_Sequence (N)));
7520 Prepend (Decl, Statements (Handled_Statement_Sequence (N)));
7521 Mark_Rewrite_Insertion (Decl);
7523 -- If the accept statement has no body, there will be no
7524 -- reference to the actuals, so no need to compute actual
7531 Decl := Build_Actual_Subtype (T, Formal);
7532 Prepend (Decl, Declarations (N));
7533 Mark_Rewrite_Insertion (Decl);
7536 -- The declaration uses the bounds of an existing object, and
7537 -- therefore needs no constraint checks.
7539 Analyze (Decl, Suppress => All_Checks);
7541 -- We need to freeze manually the generated type when it is
7542 -- inserted anywhere else than in a declarative part.
7544 if Present (First_Stmt) then
7545 Insert_List_Before_And_Analyze (First_Stmt,
7546 Freeze_Entity (Defining_Identifier (Decl), Loc));
7549 if Nkind (N) = N_Accept_Statement
7550 and then Expander_Active
7552 Set_Actual_Subtype (Renamed_Object (Formal),
7553 Defining_Identifier (Decl));
7555 Set_Actual_Subtype (Formal, Defining_Identifier (Decl));
7559 Next_Formal (Formal);
7561 end Set_Actual_Subtypes;
7563 ---------------------
7564 -- Set_Formal_Mode --
7565 ---------------------
7567 procedure Set_Formal_Mode (Formal_Id : Entity_Id) is
7568 Spec : constant Node_Id := Parent (Formal_Id);
7571 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
7572 -- since we ensure that corresponding actuals are always valid at the
7573 -- point of the call.
7575 if Out_Present (Spec) then
7576 if Ekind (Scope (Formal_Id)) = E_Function
7577 or else Ekind (Scope (Formal_Id)) = E_Generic_Function
7579 Error_Msg_N ("functions can only have IN parameters", Spec);
7580 Set_Ekind (Formal_Id, E_In_Parameter);
7582 elsif In_Present (Spec) then
7583 Set_Ekind (Formal_Id, E_In_Out_Parameter);
7586 Set_Ekind (Formal_Id, E_Out_Parameter);
7587 Set_Never_Set_In_Source (Formal_Id, True);
7588 Set_Is_True_Constant (Formal_Id, False);
7589 Set_Current_Value (Formal_Id, Empty);
7593 Set_Ekind (Formal_Id, E_In_Parameter);
7596 -- Set Is_Known_Non_Null for access parameters since the language
7597 -- guarantees that access parameters are always non-null. We also set
7598 -- Can_Never_Be_Null, since there is no way to change the value.
7600 if Nkind (Parameter_Type (Spec)) = N_Access_Definition then
7602 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
7603 -- null; In Ada 2005, only if then null_exclusion is explicit.
7605 if Ada_Version < Ada_05
7606 or else Can_Never_Be_Null (Etype (Formal_Id))
7608 Set_Is_Known_Non_Null (Formal_Id);
7609 Set_Can_Never_Be_Null (Formal_Id);
7612 -- Ada 2005 (AI-231): Null-exclusion access subtype
7614 elsif Is_Access_Type (Etype (Formal_Id))
7615 and then Can_Never_Be_Null (Etype (Formal_Id))
7617 Set_Is_Known_Non_Null (Formal_Id);
7620 Set_Mechanism (Formal_Id, Default_Mechanism);
7621 Set_Formal_Validity (Formal_Id);
7622 end Set_Formal_Mode;
7624 -------------------------
7625 -- Set_Formal_Validity --
7626 -------------------------
7628 procedure Set_Formal_Validity (Formal_Id : Entity_Id) is
7630 -- If no validity checking, then we cannot assume anything about the
7631 -- validity of parameters, since we do not know there is any checking
7632 -- of the validity on the call side.
7634 if not Validity_Checks_On then
7637 -- If validity checking for parameters is enabled, this means we are
7638 -- not supposed to make any assumptions about argument values.
7640 elsif Validity_Check_Parameters then
7643 -- If we are checking in parameters, we will assume that the caller is
7644 -- also checking parameters, so we can assume the parameter is valid.
7646 elsif Ekind (Formal_Id) = E_In_Parameter
7647 and then Validity_Check_In_Params
7649 Set_Is_Known_Valid (Formal_Id, True);
7651 -- Similar treatment for IN OUT parameters
7653 elsif Ekind (Formal_Id) = E_In_Out_Parameter
7654 and then Validity_Check_In_Out_Params
7656 Set_Is_Known_Valid (Formal_Id, True);
7658 end Set_Formal_Validity;
7660 ------------------------
7661 -- Subtype_Conformant --
7662 ------------------------
7664 function Subtype_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
7667 Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result);
7669 end Subtype_Conformant;
7671 ---------------------
7672 -- Type_Conformant --
7673 ---------------------
7675 function Type_Conformant
7676 (New_Id : Entity_Id;
7678 Skip_Controlling_Formals : Boolean := False) return Boolean
7682 May_Hide_Profile := False;
7685 (New_Id, Old_Id, Type_Conformant, False, Result,
7686 Skip_Controlling_Formals => Skip_Controlling_Formals);
7688 end Type_Conformant;
7690 -------------------------------
7691 -- Valid_Operator_Definition --
7692 -------------------------------
7694 procedure Valid_Operator_Definition (Designator : Entity_Id) is
7697 Id : constant Name_Id := Chars (Designator);
7701 F := First_Formal (Designator);
7702 while Present (F) loop
7705 if Present (Default_Value (F)) then
7707 ("default values not allowed for operator parameters",
7714 -- Verify that user-defined operators have proper number of arguments
7715 -- First case of operators which can only be unary
7718 or else Id = Name_Op_Abs
7722 -- Case of operators which can be unary or binary
7724 elsif Id = Name_Op_Add
7725 or Id = Name_Op_Subtract
7727 N_OK := (N in 1 .. 2);
7729 -- All other operators can only be binary
7737 ("incorrect number of arguments for operator", Designator);
7741 and then Base_Type (Etype (Designator)) = Standard_Boolean
7742 and then not Is_Intrinsic_Subprogram (Designator)
7745 ("explicit definition of inequality not allowed", Designator);
7747 end Valid_Operator_Definition;