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_Disp; use Exp_Disp;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Itypes; use Itypes;
42 with Lib.Xref; use Lib.Xref;
43 with Layout; use Layout;
44 with Namet; use Namet;
46 with Nlists; use Nlists;
47 with Nmake; use Nmake;
49 with Output; use Output;
50 with Rtsfind; use Rtsfind;
52 with Sem_Aux; use Sem_Aux;
53 with Sem_Cat; use Sem_Cat;
54 with Sem_Ch3; use Sem_Ch3;
55 with Sem_Ch4; use Sem_Ch4;
56 with Sem_Ch5; use Sem_Ch5;
57 with Sem_Ch8; use Sem_Ch8;
58 with Sem_Ch10; use Sem_Ch10;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Disp; use Sem_Disp;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Elim; use Sem_Elim;
63 with Sem_Eval; use Sem_Eval;
64 with Sem_Mech; use Sem_Mech;
65 with Sem_Prag; use Sem_Prag;
66 with Sem_Res; use Sem_Res;
67 with Sem_Util; use Sem_Util;
68 with Sem_Type; use Sem_Type;
69 with Sem_Warn; use Sem_Warn;
70 with Sinput; use Sinput;
71 with Stand; use Stand;
72 with Sinfo; use Sinfo;
73 with Sinfo.CN; use Sinfo.CN;
74 with Snames; use Snames;
75 with Stringt; use Stringt;
77 with Stylesw; use Stylesw;
78 with Tbuild; use Tbuild;
79 with Uintp; use Uintp;
80 with Urealp; use Urealp;
81 with Validsw; use Validsw;
83 package body Sem_Ch6 is
85 May_Hide_Profile : Boolean := False;
86 -- This flag is used to indicate that two formals in two subprograms being
87 -- checked for conformance differ only in that one is an access parameter
88 -- while the other is of a general access type with the same designated
89 -- type. In this case, if the rest of the signatures match, a call to
90 -- either subprogram may be ambiguous, which is worth a warning. The flag
91 -- is set in Compatible_Types, and the warning emitted in
92 -- New_Overloaded_Entity.
94 -----------------------
95 -- Local Subprograms --
96 -----------------------
98 procedure Analyze_Return_Statement (N : Node_Id);
99 -- Common processing for simple_ and extended_return_statements
101 procedure Analyze_Function_Return (N : Node_Id);
102 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
103 -- applies to a [generic] function.
105 procedure Analyze_Return_Type (N : Node_Id);
106 -- Subsidiary to Process_Formals: analyze subtype mark in function
107 -- specification, in a context where the formals are visible and hide
110 procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id);
111 -- Analyze a generic subprogram body. N is the body to be analyzed, and
112 -- Gen_Id is the defining entity Id for the corresponding spec.
114 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id);
115 -- If a subprogram has pragma Inline and inlining is active, use generic
116 -- machinery to build an unexpanded body for the subprogram. This body is
117 -- subsequently used for inline expansions at call sites. If subprogram can
118 -- be inlined (depending on size and nature of local declarations) this
119 -- function returns true. Otherwise subprogram body is treated normally.
120 -- If proper warnings are enabled and the subprogram contains a construct
121 -- that cannot be inlined, the offending construct is flagged accordingly.
123 procedure Check_Conformance
126 Ctype : Conformance_Type;
128 Conforms : out Boolean;
129 Err_Loc : Node_Id := Empty;
130 Get_Inst : Boolean := False;
131 Skip_Controlling_Formals : Boolean := False);
132 -- Given two entities, this procedure checks that the profiles associated
133 -- with these entities meet the conformance criterion given by the third
134 -- parameter. If they conform, Conforms is set True and control returns
135 -- to the caller. If they do not conform, Conforms is set to False, and
136 -- in addition, if Errmsg is True on the call, proper messages are output
137 -- to complain about the conformance failure. If Err_Loc is non_Empty
138 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
139 -- error messages are placed on the appropriate part of the construct
140 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
141 -- against a formal access-to-subprogram type so Get_Instance_Of must
144 procedure Check_Subprogram_Order (N : Node_Id);
145 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
146 -- the alpha ordering rule for N if this ordering requirement applicable.
148 procedure Check_Returns
152 Proc : Entity_Id := Empty);
153 -- Called to check for missing return statements in a function body, or for
154 -- returns present in a procedure body which has No_Return set. HSS is the
155 -- handled statement sequence for the subprogram body. This procedure
156 -- checks all flow paths to make sure they either have return (Mode = 'F',
157 -- used for functions) or do not have a return (Mode = 'P', used for
158 -- No_Return procedures). The flag Err is set if there are any control
159 -- paths not explicitly terminated by a return in the function case, and is
160 -- True otherwise. Proc is the entity for the procedure case and is used
161 -- in posting the warning message.
163 procedure Enter_Overloaded_Entity (S : Entity_Id);
164 -- This procedure makes S, a new overloaded entity, into the first visible
165 -- entity with that name.
167 procedure Install_Entity (E : Entity_Id);
168 -- Make single entity visible. Used for generic formals as well
170 function Is_Non_Overriding_Operation
172 New_E : Entity_Id) return Boolean;
173 -- Enforce the rule given in 12.3(18): a private operation in an instance
174 -- overrides an inherited operation only if the corresponding operation
175 -- was overriding in the generic. This can happen for primitive operations
176 -- of types derived (in the generic unit) from formal private or formal
179 procedure Make_Inequality_Operator (S : Entity_Id);
180 -- Create the declaration for an inequality operator that is implicitly
181 -- created by a user-defined equality operator that yields a boolean.
183 procedure May_Need_Actuals (Fun : Entity_Id);
184 -- Flag functions that can be called without parameters, i.e. those that
185 -- have no parameters, or those for which defaults exist for all parameters
187 procedure Process_PPCs
190 Body_Id : Entity_Id);
191 -- Called from Analyze[_Generic]_Subprogram_Body to deal with scanning post
192 -- conditions for the body and assembling and inserting the _postconditions
193 -- procedure. N is the node for the subprogram body and Body_Id/Spec_Id are
194 -- the entities for the body and separate spec (if there is no separate
195 -- spec, Spec_Id is Empty).
197 procedure Set_Formal_Validity (Formal_Id : Entity_Id);
198 -- Formal_Id is an formal parameter entity. This procedure deals with
199 -- setting the proper validity status for this entity, which depends on
200 -- the kind of parameter and the validity checking mode.
202 ------------------------------
203 -- Analyze_Return_Statement --
204 ------------------------------
206 procedure Analyze_Return_Statement (N : Node_Id) is
208 pragma Assert (Nkind_In (N, N_Simple_Return_Statement,
209 N_Extended_Return_Statement));
211 Returns_Object : constant Boolean :=
212 Nkind (N) = N_Extended_Return_Statement
214 (Nkind (N) = N_Simple_Return_Statement
215 and then Present (Expression (N)));
216 -- True if we're returning something; that is, "return <expression>;"
217 -- or "return Result : T [:= ...]". False for "return;". Used for error
218 -- checking: If Returns_Object is True, N should apply to a function
219 -- body; otherwise N should apply to a procedure body, entry body,
220 -- accept statement, or extended return statement.
222 function Find_What_It_Applies_To return Entity_Id;
223 -- Find the entity representing the innermost enclosing body, accept
224 -- statement, or extended return statement. If the result is a callable
225 -- construct or extended return statement, then this will be the value
226 -- of the Return_Applies_To attribute. Otherwise, the program is
227 -- illegal. See RM-6.5(4/2).
229 -----------------------------
230 -- Find_What_It_Applies_To --
231 -----------------------------
233 function Find_What_It_Applies_To return Entity_Id is
234 Result : Entity_Id := Empty;
237 -- Loop outward through the Scope_Stack, skipping blocks and loops
239 for J in reverse 0 .. Scope_Stack.Last loop
240 Result := Scope_Stack.Table (J).Entity;
241 exit when Ekind (Result) /= E_Block and then
242 Ekind (Result) /= E_Loop;
245 pragma Assert (Present (Result));
247 end Find_What_It_Applies_To;
249 -- Local declarations
251 Scope_Id : constant Entity_Id := Find_What_It_Applies_To;
252 Kind : constant Entity_Kind := Ekind (Scope_Id);
253 Loc : constant Source_Ptr := Sloc (N);
254 Stm_Entity : constant Entity_Id :=
256 (E_Return_Statement, Current_Scope, Loc, 'R');
258 -- Start of processing for Analyze_Return_Statement
261 Set_Return_Statement_Entity (N, Stm_Entity);
263 Set_Etype (Stm_Entity, Standard_Void_Type);
264 Set_Return_Applies_To (Stm_Entity, Scope_Id);
266 -- Place Return entity on scope stack, to simplify enforcement of 6.5
267 -- (4/2): an inner return statement will apply to this extended return.
269 if Nkind (N) = N_Extended_Return_Statement then
270 Push_Scope (Stm_Entity);
273 -- Check that pragma No_Return is obeyed. Don't complain about the
274 -- implicitly-generated return that is placed at the end.
276 if No_Return (Scope_Id) and then Comes_From_Source (N) then
277 Error_Msg_N ("RETURN statement not allowed (No_Return)", N);
280 -- Warn on any unassigned OUT parameters if in procedure
282 if Ekind (Scope_Id) = E_Procedure then
283 Warn_On_Unassigned_Out_Parameter (N, Scope_Id);
286 -- Check that functions return objects, and other things do not
288 if Kind = E_Function or else Kind = E_Generic_Function then
289 if not Returns_Object then
290 Error_Msg_N ("missing expression in return from function", N);
293 elsif Kind = E_Procedure or else Kind = E_Generic_Procedure then
294 if Returns_Object then
295 Error_Msg_N ("procedure cannot return value (use function)", N);
298 elsif Kind = E_Entry or else Kind = E_Entry_Family then
299 if Returns_Object then
300 if Is_Protected_Type (Scope (Scope_Id)) then
301 Error_Msg_N ("entry body cannot return value", N);
303 Error_Msg_N ("accept statement cannot return value", N);
307 elsif Kind = E_Return_Statement then
309 -- We are nested within another return statement, which must be an
310 -- extended_return_statement.
312 if Returns_Object then
314 ("extended_return_statement cannot return value; " &
315 "use `""RETURN;""`", N);
319 Error_Msg_N ("illegal context for return statement", N);
322 if Kind = E_Function or else Kind = E_Generic_Function then
323 Analyze_Function_Return (N);
326 if Nkind (N) = N_Extended_Return_Statement then
330 Kill_Current_Values (Last_Assignment_Only => True);
331 Check_Unreachable_Code (N);
332 end Analyze_Return_Statement;
334 ---------------------------------------------
335 -- Analyze_Abstract_Subprogram_Declaration --
336 ---------------------------------------------
338 procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id) is
339 Designator : constant Entity_Id :=
340 Analyze_Subprogram_Specification (Specification (N));
341 Scop : constant Entity_Id := Current_Scope;
344 Generate_Definition (Designator);
345 Set_Is_Abstract_Subprogram (Designator);
346 New_Overloaded_Entity (Designator);
347 Check_Delayed_Subprogram (Designator);
349 Set_Categorization_From_Scope (Designator, Scop);
351 if Ekind (Scope (Designator)) = E_Protected_Type then
353 ("abstract subprogram not allowed in protected type", N);
355 -- Issue a warning if the abstract subprogram is neither a dispatching
356 -- operation nor an operation that overrides an inherited subprogram or
357 -- predefined operator, since this most likely indicates a mistake.
359 elsif Warn_On_Redundant_Constructs
360 and then not Is_Dispatching_Operation (Designator)
361 and then not Is_Overriding_Operation (Designator)
362 and then (not Is_Operator_Symbol_Name (Chars (Designator))
363 or else Scop /= Scope (Etype (First_Formal (Designator))))
366 ("?abstract subprogram is not dispatching or overriding", N);
369 Generate_Reference_To_Formals (Designator);
370 Check_Eliminated (Designator);
371 end Analyze_Abstract_Subprogram_Declaration;
373 ----------------------------------------
374 -- Analyze_Extended_Return_Statement --
375 ----------------------------------------
377 procedure Analyze_Extended_Return_Statement (N : Node_Id) is
379 Analyze_Return_Statement (N);
380 end Analyze_Extended_Return_Statement;
382 ----------------------------
383 -- Analyze_Function_Call --
384 ----------------------------
386 procedure Analyze_Function_Call (N : Node_Id) is
387 P : constant Node_Id := Name (N);
388 L : constant List_Id := Parameter_Associations (N);
394 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
395 -- as B (A, X). If the rewriting is successful, the call has been
396 -- analyzed and we just return.
398 if Nkind (P) = N_Selected_Component
399 and then Name (N) /= P
400 and then Is_Rewrite_Substitution (N)
401 and then Present (Etype (N))
406 -- If error analyzing name, then set Any_Type as result type and return
408 if Etype (P) = Any_Type then
409 Set_Etype (N, Any_Type);
413 -- Otherwise analyze the parameters
417 while Present (Actual) loop
419 Check_Parameterless_Call (Actual);
425 end Analyze_Function_Call;
427 -----------------------------
428 -- Analyze_Function_Return --
429 -----------------------------
431 procedure Analyze_Function_Return (N : Node_Id) is
432 Loc : constant Source_Ptr := Sloc (N);
433 Stm_Entity : constant Entity_Id := Return_Statement_Entity (N);
434 Scope_Id : constant Entity_Id := Return_Applies_To (Stm_Entity);
436 R_Type : constant Entity_Id := Etype (Scope_Id);
437 -- Function result subtype
439 procedure Check_Limited_Return (Expr : Node_Id);
440 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
441 -- limited types. Used only for simple return statements.
442 -- Expr is the expression returned.
444 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id);
445 -- Check that the return_subtype_indication properly matches the result
446 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
448 --------------------------
449 -- Check_Limited_Return --
450 --------------------------
452 procedure Check_Limited_Return (Expr : Node_Id) is
454 -- Ada 2005 (AI-318-02): Return-by-reference types have been
455 -- removed and replaced by anonymous access results. This is an
456 -- incompatibility with Ada 95. Not clear whether this should be
457 -- enforced yet or perhaps controllable with special switch. ???
459 if Is_Limited_Type (R_Type)
460 and then Comes_From_Source (N)
461 and then not In_Instance_Body
462 and then not OK_For_Limited_Init_In_05 (Expr)
466 if Ada_Version >= Ada_05
467 and then not Debug_Flag_Dot_L
468 and then not GNAT_Mode
471 ("(Ada 2005) cannot copy object of a limited type " &
472 "(RM-2005 6.5(5.5/2))", Expr);
473 if Is_Inherently_Limited_Type (R_Type) then
475 ("\return by reference not permitted in Ada 2005", Expr);
478 -- Warn in Ada 95 mode, to give folks a heads up about this
481 -- In GNAT mode, this is just a warning, to allow it to be
482 -- evilly turned off. Otherwise it is a real error.
484 elsif Warn_On_Ada_2005_Compatibility or GNAT_Mode then
485 if Is_Inherently_Limited_Type (R_Type) then
487 ("return by reference not permitted in Ada 2005 " &
488 "(RM-2005 6.5(5.5/2))?", Expr);
491 ("cannot copy object of a limited type in Ada 2005 " &
492 "(RM-2005 6.5(5.5/2))?", Expr);
495 -- Ada 95 mode, compatibility warnings disabled
498 return; -- skip continuation messages below
502 ("\consider switching to return of access type", Expr);
503 Explain_Limited_Type (R_Type, Expr);
505 end Check_Limited_Return;
507 -------------------------------------
508 -- Check_Return_Subtype_Indication --
509 -------------------------------------
511 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id) is
512 Return_Obj : constant Node_Id := Defining_Identifier (Obj_Decl);
513 R_Stm_Type : constant Entity_Id := Etype (Return_Obj);
514 -- Subtype given in the extended return statement;
515 -- this must match R_Type.
517 Subtype_Ind : constant Node_Id :=
518 Object_Definition (Original_Node (Obj_Decl));
520 R_Type_Is_Anon_Access :
522 Ekind (R_Type) = E_Anonymous_Access_Subprogram_Type
524 Ekind (R_Type) = E_Anonymous_Access_Protected_Subprogram_Type
526 Ekind (R_Type) = E_Anonymous_Access_Type;
527 -- True if return type of the function is an anonymous access type
528 -- Can't we make Is_Anonymous_Access_Type in einfo ???
530 R_Stm_Type_Is_Anon_Access :
532 Ekind (R_Stm_Type) = E_Anonymous_Access_Subprogram_Type
534 Ekind (R_Stm_Type) = E_Anonymous_Access_Protected_Subprogram_Type
536 Ekind (R_Stm_Type) = E_Anonymous_Access_Type;
537 -- True if type of the return object is an anonymous access type
540 -- First, avoid cascade errors:
542 if Error_Posted (Obj_Decl) or else Error_Posted (Subtype_Ind) then
546 -- "return access T" case; check that the return statement also has
547 -- "access T", and that the subtypes statically match:
548 -- if this is an access to subprogram the signatures must match.
550 if R_Type_Is_Anon_Access then
551 if R_Stm_Type_Is_Anon_Access then
553 Ekind (Designated_Type (R_Stm_Type)) /= E_Subprogram_Type
555 if Base_Type (Designated_Type (R_Stm_Type)) /=
556 Base_Type (Designated_Type (R_Type))
557 or else not Subtypes_Statically_Match (R_Stm_Type, R_Type)
560 ("subtype must statically match function result subtype",
561 Subtype_Mark (Subtype_Ind));
565 -- For two anonymous access to subprogram types, the
566 -- types themselves must be type conformant.
568 if not Conforming_Types
569 (R_Stm_Type, R_Type, Fully_Conformant)
572 ("subtype must statically match function result subtype",
578 Error_Msg_N ("must use anonymous access type", Subtype_Ind);
581 -- Subtype_indication case; check that the types are the same, and
582 -- statically match if appropriate. A null exclusion may be present
583 -- on the return type, on the function specification, on the object
584 -- declaration or on the subtype itself.
586 elsif Base_Type (R_Stm_Type) = Base_Type (R_Type) then
587 if Is_Access_Type (R_Type)
589 (Can_Never_Be_Null (R_Type)
590 or else Null_Exclusion_Present (Parent (Scope_Id))) /=
591 Can_Never_Be_Null (R_Stm_Type)
594 ("subtype must statically match function result subtype",
598 if Is_Constrained (R_Type) then
599 if not Subtypes_Statically_Match (R_Stm_Type, R_Type) then
601 ("subtype must statically match function result subtype",
606 -- If the function's result type doesn't match the return object
607 -- entity's type, then we check for the case where the result type
608 -- is class-wide, and allow the declaration if the type of the object
609 -- definition matches the class-wide type. This prevents rejection
610 -- in the case where the object declaration is initialized by a call
611 -- to a build-in-place function with a specific result type and the
612 -- object entity had its type changed to that specific type. This is
613 -- also allowed in the case where Obj_Decl does not come from source,
614 -- which can occur for an expansion of a simple return statement of
615 -- a build-in-place class-wide function when the result expression
616 -- has a specific type, because a return object with a specific type
617 -- is created. (Note that the ARG believes that return objects should
618 -- be allowed to have a type covered by a class-wide result type in
619 -- any case, so once that relaxation is made (see AI05-32), the above
620 -- check for type compatibility should be changed to test Covers
621 -- rather than equality, and the following special test will no
622 -- longer be needed. ???)
624 elsif Is_Class_Wide_Type (R_Type)
626 (R_Type = Etype (Object_Definition (Original_Node (Obj_Decl)))
627 or else not Comes_From_Source (Obj_Decl))
633 ("wrong type for return_subtype_indication", Subtype_Ind);
635 end Check_Return_Subtype_Indication;
637 ---------------------
638 -- Local Variables --
639 ---------------------
643 -- Start of processing for Analyze_Function_Return
646 Set_Return_Present (Scope_Id);
648 if Nkind (N) = N_Simple_Return_Statement then
649 Expr := Expression (N);
650 Analyze_And_Resolve (Expr, R_Type);
651 Check_Limited_Return (Expr);
654 -- Analyze parts specific to extended_return_statement:
657 Obj_Decl : constant Node_Id :=
658 Last (Return_Object_Declarations (N));
660 HSS : constant Node_Id := Handled_Statement_Sequence (N);
663 Expr := Expression (Obj_Decl);
665 -- Note: The check for OK_For_Limited_Init will happen in
666 -- Analyze_Object_Declaration; we treat it as a normal
667 -- object declaration.
669 Set_Is_Return_Object (Defining_Identifier (Obj_Decl));
672 Check_Return_Subtype_Indication (Obj_Decl);
674 if Present (HSS) then
677 if Present (Exception_Handlers (HSS)) then
679 -- ???Has_Nested_Block_With_Handler needs to be set.
680 -- Probably by creating an actual N_Block_Statement.
681 -- Probably in Expand.
687 Check_References (Stm_Entity);
691 -- Case of Expr present
695 -- Defend against previous errors
697 and then Nkind (Expr) /= N_Empty
698 and then Present (Etype (Expr))
700 -- Apply constraint check. Note that this is done before the implicit
701 -- conversion of the expression done for anonymous access types to
702 -- ensure correct generation of the null-excluding check associated
703 -- with null-excluding expressions found in return statements.
705 Apply_Constraint_Check (Expr, R_Type);
707 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
708 -- type, apply an implicit conversion of the expression to that type
709 -- to force appropriate static and run-time accessibility checks.
711 if Ada_Version >= Ada_05
712 and then Ekind (R_Type) = E_Anonymous_Access_Type
714 Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr)));
715 Analyze_And_Resolve (Expr, R_Type);
718 -- If the result type is class-wide, then check that the return
719 -- expression's type is not declared at a deeper level than the
720 -- function (RM05-6.5(5.6/2)).
722 if Ada_Version >= Ada_05
723 and then Is_Class_Wide_Type (R_Type)
725 if Type_Access_Level (Etype (Expr)) >
726 Subprogram_Access_Level (Scope_Id)
729 ("level of return expression type is deeper than " &
730 "class-wide function!", Expr);
734 if (Is_Class_Wide_Type (Etype (Expr))
735 or else Is_Dynamically_Tagged (Expr))
736 and then not Is_Class_Wide_Type (R_Type)
739 ("dynamically tagged expression not allowed!", Expr);
742 -- ??? A real run-time accessibility check is needed in cases
743 -- involving dereferences of access parameters. For now we just
744 -- check the static cases.
746 if (Ada_Version < Ada_05 or else Debug_Flag_Dot_L)
747 and then Is_Inherently_Limited_Type (Etype (Scope_Id))
748 and then Object_Access_Level (Expr) >
749 Subprogram_Access_Level (Scope_Id)
752 Make_Raise_Program_Error (Loc,
753 Reason => PE_Accessibility_Check_Failed));
757 ("cannot return a local value by reference?", N);
759 ("\& will be raised at run time?",
760 N, Standard_Program_Error);
764 and then Nkind (Parent (Scope_Id)) = N_Function_Specification
765 and then Null_Exclusion_Present (Parent (Scope_Id))
767 Apply_Compile_Time_Constraint_Error
769 Msg => "(Ada 2005) null not allowed for "
770 & "null-excluding return?",
771 Reason => CE_Null_Not_Allowed);
774 end Analyze_Function_Return;
776 -------------------------------------
777 -- Analyze_Generic_Subprogram_Body --
778 -------------------------------------
780 procedure Analyze_Generic_Subprogram_Body
784 Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id);
785 Kind : constant Entity_Kind := Ekind (Gen_Id);
791 -- Copy body and disable expansion while analyzing the generic For a
792 -- stub, do not copy the stub (which would load the proper body), this
793 -- will be done when the proper body is analyzed.
795 if Nkind (N) /= N_Subprogram_Body_Stub then
796 New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
801 Spec := Specification (N);
803 -- Within the body of the generic, the subprogram is callable, and
804 -- behaves like the corresponding non-generic unit.
806 Body_Id := Defining_Entity (Spec);
808 if Kind = E_Generic_Procedure
809 and then Nkind (Spec) /= N_Procedure_Specification
811 Error_Msg_N ("invalid body for generic procedure ", Body_Id);
814 elsif Kind = E_Generic_Function
815 and then Nkind (Spec) /= N_Function_Specification
817 Error_Msg_N ("invalid body for generic function ", Body_Id);
821 Set_Corresponding_Body (Gen_Decl, Body_Id);
823 if Has_Completion (Gen_Id)
824 and then Nkind (Parent (N)) /= N_Subunit
826 Error_Msg_N ("duplicate generic body", N);
829 Set_Has_Completion (Gen_Id);
832 if Nkind (N) = N_Subprogram_Body_Stub then
833 Set_Ekind (Defining_Entity (Specification (N)), Kind);
835 Set_Corresponding_Spec (N, Gen_Id);
838 if Nkind (Parent (N)) = N_Compilation_Unit then
839 Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N));
842 -- Make generic parameters immediately visible in the body. They are
843 -- needed to process the formals declarations. Then make the formals
844 -- visible in a separate step.
850 First_Ent : Entity_Id;
853 First_Ent := First_Entity (Gen_Id);
856 while Present (E) and then not Is_Formal (E) loop
861 Set_Use (Generic_Formal_Declarations (Gen_Decl));
863 -- Now generic formals are visible, and the specification can be
864 -- analyzed, for subsequent conformance check.
866 Body_Id := Analyze_Subprogram_Specification (Spec);
868 -- Make formal parameters visible
872 -- E is the first formal parameter, we loop through the formals
873 -- installing them so that they will be visible.
875 Set_First_Entity (Gen_Id, E);
876 while Present (E) loop
882 -- Visible generic entity is callable within its own body
884 Set_Ekind (Gen_Id, Ekind (Body_Id));
885 Set_Ekind (Body_Id, E_Subprogram_Body);
886 Set_Convention (Body_Id, Convention (Gen_Id));
887 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Gen_Id));
888 Set_Scope (Body_Id, Scope (Gen_Id));
889 Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id);
891 if Nkind (N) = N_Subprogram_Body_Stub then
893 -- No body to analyze, so restore state of generic unit
895 Set_Ekind (Gen_Id, Kind);
896 Set_Ekind (Body_Id, Kind);
898 if Present (First_Ent) then
899 Set_First_Entity (Gen_Id, First_Ent);
906 -- If this is a compilation unit, it must be made visible explicitly,
907 -- because the compilation of the declaration, unlike other library
908 -- unit declarations, does not. If it is not a unit, the following
909 -- is redundant but harmless.
911 Set_Is_Immediately_Visible (Gen_Id);
912 Reference_Body_Formals (Gen_Id, Body_Id);
914 if Is_Child_Unit (Gen_Id) then
915 Generate_Reference (Gen_Id, Scope (Gen_Id), 'k', False);
918 Set_Actual_Subtypes (N, Current_Scope);
919 Process_PPCs (N, Gen_Id, Body_Id);
921 -- If the generic unit carries pre- or post-conditions, copy them
922 -- to the original generic tree, so that they are properly added
923 -- to any instantiation.
926 Orig : constant Node_Id := Original_Node (N);
930 Cond := First (Declarations (N));
931 while Present (Cond) loop
932 if Nkind (Cond) = N_Pragma
933 and then Pragma_Name (Cond) = Name_Check
935 Prepend (New_Copy_Tree (Cond), Declarations (Orig));
937 elsif Nkind (Cond) = N_Pragma
938 and then Pragma_Name (Cond) = Name_Postcondition
940 Set_Ekind (Defining_Entity (Orig), Ekind (Gen_Id));
941 Prepend (New_Copy_Tree (Cond), Declarations (Orig));
950 Analyze_Declarations (Declarations (N));
952 Analyze (Handled_Statement_Sequence (N));
954 Save_Global_References (Original_Node (N));
956 -- Prior to exiting the scope, include generic formals again (if any
957 -- are present) in the set of local entities.
959 if Present (First_Ent) then
960 Set_First_Entity (Gen_Id, First_Ent);
963 Check_References (Gen_Id);
966 Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope);
968 Check_Subprogram_Order (N);
970 -- Outside of its body, unit is generic again
972 Set_Ekind (Gen_Id, Kind);
973 Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False);
976 Style.Check_Identifier (Body_Id, Gen_Id);
979 end Analyze_Generic_Subprogram_Body;
981 -----------------------------
982 -- Analyze_Operator_Symbol --
983 -----------------------------
985 -- An operator symbol such as "+" or "and" may appear in context where the
986 -- literal denotes an entity name, such as "+"(x, y) or in context when it
987 -- is just a string, as in (conjunction = "or"). In these cases the parser
988 -- generates this node, and the semantics does the disambiguation. Other
989 -- such case are actuals in an instantiation, the generic unit in an
990 -- instantiation, and pragma arguments.
992 procedure Analyze_Operator_Symbol (N : Node_Id) is
993 Par : constant Node_Id := Parent (N);
996 if (Nkind (Par) = N_Function_Call
997 and then N = Name (Par))
998 or else Nkind (Par) = N_Function_Instantiation
999 or else (Nkind (Par) = N_Indexed_Component
1000 and then N = Prefix (Par))
1001 or else (Nkind (Par) = N_Pragma_Argument_Association
1002 and then not Is_Pragma_String_Literal (Par))
1003 or else Nkind (Par) = N_Subprogram_Renaming_Declaration
1004 or else (Nkind (Par) = N_Attribute_Reference
1005 and then Attribute_Name (Par) /= Name_Value)
1007 Find_Direct_Name (N);
1010 Change_Operator_Symbol_To_String_Literal (N);
1013 end Analyze_Operator_Symbol;
1015 -----------------------------------
1016 -- Analyze_Parameter_Association --
1017 -----------------------------------
1019 procedure Analyze_Parameter_Association (N : Node_Id) is
1021 Analyze (Explicit_Actual_Parameter (N));
1022 end Analyze_Parameter_Association;
1024 ----------------------------
1025 -- Analyze_Procedure_Call --
1026 ----------------------------
1028 procedure Analyze_Procedure_Call (N : Node_Id) is
1029 Loc : constant Source_Ptr := Sloc (N);
1030 P : constant Node_Id := Name (N);
1031 Actuals : constant List_Id := Parameter_Associations (N);
1035 procedure Analyze_Call_And_Resolve;
1036 -- Do Analyze and Resolve calls for procedure call
1038 ------------------------------
1039 -- Analyze_Call_And_Resolve --
1040 ------------------------------
1042 procedure Analyze_Call_And_Resolve is
1044 if Nkind (N) = N_Procedure_Call_Statement then
1046 Resolve (N, Standard_Void_Type);
1050 end Analyze_Call_And_Resolve;
1052 -- Start of processing for Analyze_Procedure_Call
1055 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1056 -- a procedure call or an entry call. The prefix may denote an access
1057 -- to subprogram type, in which case an implicit dereference applies.
1058 -- If the prefix is an indexed component (without implicit dereference)
1059 -- then the construct denotes a call to a member of an entire family.
1060 -- If the prefix is a simple name, it may still denote a call to a
1061 -- parameterless member of an entry family. Resolution of these various
1062 -- interpretations is delicate.
1066 -- If this is a call of the form Obj.Op, the call may have been
1067 -- analyzed and possibly rewritten into a block, in which case
1070 if Analyzed (N) then
1074 -- If error analyzing prefix, then set Any_Type as result and return
1076 if Etype (P) = Any_Type then
1077 Set_Etype (N, Any_Type);
1081 -- Otherwise analyze the parameters
1083 if Present (Actuals) then
1084 Actual := First (Actuals);
1086 while Present (Actual) loop
1088 Check_Parameterless_Call (Actual);
1093 -- Special processing for Elab_Spec and Elab_Body calls
1095 if Nkind (P) = N_Attribute_Reference
1096 and then (Attribute_Name (P) = Name_Elab_Spec
1097 or else Attribute_Name (P) = Name_Elab_Body)
1099 if Present (Actuals) then
1101 ("no parameters allowed for this call", First (Actuals));
1105 Set_Etype (N, Standard_Void_Type);
1108 elsif Is_Entity_Name (P)
1109 and then Is_Record_Type (Etype (Entity (P)))
1110 and then Remote_AST_I_Dereference (P)
1114 elsif Is_Entity_Name (P)
1115 and then Ekind (Entity (P)) /= E_Entry_Family
1117 if Is_Access_Type (Etype (P))
1118 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1119 and then No (Actuals)
1120 and then Comes_From_Source (N)
1122 Error_Msg_N ("missing explicit dereference in call", N);
1125 Analyze_Call_And_Resolve;
1127 -- If the prefix is the simple name of an entry family, this is
1128 -- a parameterless call from within the task body itself.
1130 elsif Is_Entity_Name (P)
1131 and then Nkind (P) = N_Identifier
1132 and then Ekind (Entity (P)) = E_Entry_Family
1133 and then Present (Actuals)
1134 and then No (Next (First (Actuals)))
1136 -- Can be call to parameterless entry family. What appears to be the
1137 -- sole argument is in fact the entry index. Rewrite prefix of node
1138 -- accordingly. Source representation is unchanged by this
1142 Make_Indexed_Component (Loc,
1144 Make_Selected_Component (Loc,
1145 Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc),
1146 Selector_Name => New_Occurrence_Of (Entity (P), Loc)),
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 elsif Nkind (P) = N_Explicit_Dereference then
1154 if Ekind (Etype (P)) = E_Subprogram_Type then
1155 Analyze_Call_And_Resolve;
1157 Error_Msg_N ("expect access to procedure in call", P);
1160 -- The name can be a selected component or an indexed component that
1161 -- yields an access to subprogram. Such a prefix is legal if the call
1162 -- has parameter associations.
1164 elsif Is_Access_Type (Etype (P))
1165 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1167 if Present (Actuals) then
1168 Analyze_Call_And_Resolve;
1170 Error_Msg_N ("missing explicit dereference in call ", N);
1173 -- If not an access to subprogram, then the prefix must resolve to the
1174 -- name of an entry, entry family, or protected operation.
1176 -- For the case of a simple entry call, P is a selected component where
1177 -- the prefix is the task and the selector name is the entry. A call to
1178 -- a protected procedure will have the same syntax. If the protected
1179 -- object contains overloaded operations, the entity may appear as a
1180 -- function, the context will select the operation whose type is Void.
1182 elsif Nkind (P) = N_Selected_Component
1183 and then (Ekind (Entity (Selector_Name (P))) = E_Entry
1185 Ekind (Entity (Selector_Name (P))) = E_Procedure
1187 Ekind (Entity (Selector_Name (P))) = E_Function)
1189 Analyze_Call_And_Resolve;
1191 elsif Nkind (P) = N_Selected_Component
1192 and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family
1193 and then Present (Actuals)
1194 and then No (Next (First (Actuals)))
1196 -- Can be call to parameterless entry family. What appears to be the
1197 -- sole argument is in fact the entry index. Rewrite prefix of node
1198 -- accordingly. Source representation is unchanged by this
1202 Make_Indexed_Component (Loc,
1203 Prefix => New_Copy (P),
1204 Expressions => Actuals);
1205 Set_Name (N, New_N);
1206 Set_Etype (New_N, Standard_Void_Type);
1207 Set_Parameter_Associations (N, No_List);
1208 Analyze_Call_And_Resolve;
1210 -- For the case of a reference to an element of an entry family, P is
1211 -- an indexed component whose prefix is a selected component (task and
1212 -- entry family), and whose index is the entry family index.
1214 elsif Nkind (P) = N_Indexed_Component
1215 and then Nkind (Prefix (P)) = N_Selected_Component
1216 and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family
1218 Analyze_Call_And_Resolve;
1220 -- If the prefix is the name of an entry family, it is a call from
1221 -- within the task body itself.
1223 elsif Nkind (P) = N_Indexed_Component
1224 and then Nkind (Prefix (P)) = N_Identifier
1225 and then Ekind (Entity (Prefix (P))) = E_Entry_Family
1228 Make_Selected_Component (Loc,
1229 Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc),
1230 Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc));
1231 Rewrite (Prefix (P), New_N);
1233 Analyze_Call_And_Resolve;
1235 -- Anything else is an error
1238 Error_Msg_N ("invalid procedure or entry call", N);
1240 end Analyze_Procedure_Call;
1242 -------------------------------------
1243 -- Analyze_Simple_Return_Statement --
1244 -------------------------------------
1246 procedure Analyze_Simple_Return_Statement (N : Node_Id) is
1248 if Present (Expression (N)) then
1249 Mark_Coextensions (N, Expression (N));
1252 Analyze_Return_Statement (N);
1253 end Analyze_Simple_Return_Statement;
1255 -------------------------
1256 -- Analyze_Return_Type --
1257 -------------------------
1259 procedure Analyze_Return_Type (N : Node_Id) is
1260 Designator : constant Entity_Id := Defining_Entity (N);
1261 Typ : Entity_Id := Empty;
1264 -- Normal case where result definition does not indicate an error
1266 if Result_Definition (N) /= Error then
1267 if Nkind (Result_Definition (N)) = N_Access_Definition then
1269 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1272 AD : constant Node_Id :=
1273 Access_To_Subprogram_Definition (Result_Definition (N));
1275 if Present (AD) and then Protected_Present (AD) then
1276 Typ := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1278 Typ := Access_Definition (N, Result_Definition (N));
1282 Set_Parent (Typ, Result_Definition (N));
1283 Set_Is_Local_Anonymous_Access (Typ);
1284 Set_Etype (Designator, Typ);
1286 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1288 Null_Exclusion_Static_Checks (N);
1290 -- Subtype_Mark case
1293 Find_Type (Result_Definition (N));
1294 Typ := Entity (Result_Definition (N));
1295 Set_Etype (Designator, Typ);
1297 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1299 Null_Exclusion_Static_Checks (N);
1301 -- If a null exclusion is imposed on the result type, then create
1302 -- a null-excluding itype (an access subtype) and use it as the
1303 -- function's Etype. Note that the null exclusion checks are done
1304 -- right before this, because they don't get applied to types that
1305 -- do not come from source.
1307 if Is_Access_Type (Typ)
1308 and then Null_Exclusion_Present (N)
1310 Set_Etype (Designator,
1311 Create_Null_Excluding_Itype
1314 Scope_Id => Scope (Current_Scope)));
1316 Set_Etype (Designator, Typ);
1319 if Ekind (Typ) = E_Incomplete_Type
1320 and then Is_Value_Type (Typ)
1324 elsif Ekind (Typ) = E_Incomplete_Type
1325 or else (Is_Class_Wide_Type (Typ)
1327 Ekind (Root_Type (Typ)) = E_Incomplete_Type)
1330 ("invalid use of incomplete type&", Designator, Typ);
1334 -- Case where result definition does indicate an error
1337 Set_Etype (Designator, Any_Type);
1339 end Analyze_Return_Type;
1341 -----------------------------
1342 -- Analyze_Subprogram_Body --
1343 -----------------------------
1345 -- This procedure is called for regular subprogram bodies, generic bodies,
1346 -- and for subprogram stubs of both kinds. In the case of stubs, only the
1347 -- specification matters, and is used to create a proper declaration for
1348 -- the subprogram, or to perform conformance checks.
1350 procedure Analyze_Subprogram_Body (N : Node_Id) is
1351 Loc : constant Source_Ptr := Sloc (N);
1352 Body_Deleted : constant Boolean := False;
1353 Body_Spec : constant Node_Id := Specification (N);
1354 Body_Id : Entity_Id := Defining_Entity (Body_Spec);
1355 Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id);
1356 Conformant : Boolean;
1358 Missing_Ret : Boolean;
1360 Prot_Typ : Entity_Id := Empty;
1361 Spec_Id : Entity_Id;
1362 Spec_Decl : Node_Id := Empty;
1364 Last_Real_Spec_Entity : Entity_Id := Empty;
1365 -- When we analyze a separate spec, the entity chain ends up containing
1366 -- the formals, as well as any itypes generated during analysis of the
1367 -- default expressions for parameters, or the arguments of associated
1368 -- precondition/postcondition pragmas (which are analyzed in the context
1369 -- of the spec since they have visibility on formals).
1371 -- These entities belong with the spec and not the body. However we do
1372 -- the analysis of the body in the context of the spec (again to obtain
1373 -- visibility to the formals), and all the entities generated during
1374 -- this analysis end up also chained to the entity chain of the spec.
1375 -- But they really belong to the body, and there is circuitry to move
1376 -- them from the spec to the body.
1378 -- However, when we do this move, we don't want to move the real spec
1379 -- entities (first para above) to the body. The Last_Real_Spec_Entity
1380 -- variable points to the last real spec entity, so we only move those
1381 -- chained beyond that point. It is initialized to Empty to deal with
1382 -- the case where there is no separate spec.
1384 procedure Check_Anonymous_Return;
1385 -- Ada 2005: if a function returns an access type that denotes a task,
1386 -- or a type that contains tasks, we must create a master entity for
1387 -- the anonymous type, which typically will be used in an allocator
1388 -- in the body of the function.
1390 procedure Check_Inline_Pragma (Spec : in out Node_Id);
1391 -- Look ahead to recognize a pragma that may appear after the body.
1392 -- If there is a previous spec, check that it appears in the same
1393 -- declarative part. If the pragma is Inline_Always, perform inlining
1394 -- unconditionally, otherwise only if Front_End_Inlining is requested.
1395 -- If the body acts as a spec, and inlining is required, we create a
1396 -- subprogram declaration for it, in order to attach the body to inline.
1397 -- If pragma does not appear after the body, check whether there is
1398 -- an inline pragma before any local declarations.
1400 function Disambiguate_Spec return Entity_Id;
1401 -- When a primitive is declared between the private view and the full
1402 -- view of a concurrent type which implements an interface, a special
1403 -- mechanism is used to find the corresponding spec of the primitive
1406 function Is_Private_Concurrent_Primitive
1407 (Subp_Id : Entity_Id) return Boolean;
1408 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
1409 -- type that implements an interface and has a private view.
1411 procedure Set_Trivial_Subprogram (N : Node_Id);
1412 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
1413 -- subprogram whose body is being analyzed. N is the statement node
1414 -- causing the flag to be set, if the following statement is a return
1415 -- of an entity, we mark the entity as set in source to suppress any
1416 -- warning on the stylized use of function stubs with a dummy return.
1418 procedure Verify_Overriding_Indicator;
1419 -- If there was a previous spec, the entity has been entered in the
1420 -- current scope previously. If the body itself carries an overriding
1421 -- indicator, check that it is consistent with the known status of the
1424 ----------------------------
1425 -- Check_Anonymous_Return --
1426 ----------------------------
1428 procedure Check_Anonymous_Return is
1434 if Present (Spec_Id) then
1440 if Ekind (Scop) = E_Function
1441 and then Ekind (Etype (Scop)) = E_Anonymous_Access_Type
1442 and then not Is_Thunk (Scop)
1443 and then (Has_Task (Designated_Type (Etype (Scop)))
1445 (Is_Class_Wide_Type (Designated_Type (Etype (Scop)))
1447 Is_Limited_Record (Designated_Type (Etype (Scop)))))
1448 and then Expander_Active
1451 Make_Object_Declaration (Loc,
1452 Defining_Identifier =>
1453 Make_Defining_Identifier (Loc, Name_uMaster),
1454 Constant_Present => True,
1455 Object_Definition =>
1456 New_Reference_To (RTE (RE_Master_Id), Loc),
1458 Make_Explicit_Dereference (Loc,
1459 New_Reference_To (RTE (RE_Current_Master), Loc)));
1461 if Present (Declarations (N)) then
1462 Prepend (Decl, Declarations (N));
1464 Set_Declarations (N, New_List (Decl));
1467 Set_Master_Id (Etype (Scop), Defining_Identifier (Decl));
1468 Set_Has_Master_Entity (Scop);
1470 -- Now mark the containing scope as a task master
1473 while Nkind (Par) /= N_Compilation_Unit loop
1474 Par := Parent (Par);
1475 pragma Assert (Present (Par));
1477 -- If we fall off the top, we are at the outer level, and
1478 -- the environment task is our effective master, so nothing
1482 (Par, N_Task_Body, N_Block_Statement, N_Subprogram_Body)
1484 Set_Is_Task_Master (Par, True);
1489 end Check_Anonymous_Return;
1491 -------------------------
1492 -- Check_Inline_Pragma --
1493 -------------------------
1495 procedure Check_Inline_Pragma (Spec : in out Node_Id) is
1499 function Is_Inline_Pragma (N : Node_Id) return Boolean;
1500 -- True when N is a pragma Inline or Inline_Always that applies
1501 -- to this subprogram.
1503 -----------------------
1504 -- Is_Inline_Pragma --
1505 -----------------------
1507 function Is_Inline_Pragma (N : Node_Id) return Boolean is
1510 Nkind (N) = N_Pragma
1512 (Pragma_Name (N) = Name_Inline_Always
1515 and then Pragma_Name (N) = Name_Inline))
1518 (Expression (First (Pragma_Argument_Associations (N))))
1520 end Is_Inline_Pragma;
1522 -- Start of processing for Check_Inline_Pragma
1525 if not Expander_Active then
1529 if Is_List_Member (N)
1530 and then Present (Next (N))
1531 and then Is_Inline_Pragma (Next (N))
1535 elsif Nkind (N) /= N_Subprogram_Body_Stub
1536 and then Present (Declarations (N))
1537 and then Is_Inline_Pragma (First (Declarations (N)))
1539 Prag := First (Declarations (N));
1545 if Present (Prag) then
1546 if Present (Spec_Id) then
1547 if List_Containing (N) =
1548 List_Containing (Unit_Declaration_Node (Spec_Id))
1554 -- Create a subprogram declaration, to make treatment uniform
1557 Subp : constant Entity_Id :=
1558 Make_Defining_Identifier (Loc, Chars (Body_Id));
1559 Decl : constant Node_Id :=
1560 Make_Subprogram_Declaration (Loc,
1561 Specification => New_Copy_Tree (Specification (N)));
1563 Set_Defining_Unit_Name (Specification (Decl), Subp);
1565 if Present (First_Formal (Body_Id)) then
1566 Plist := Copy_Parameter_List (Body_Id);
1567 Set_Parameter_Specifications
1568 (Specification (Decl), Plist);
1571 Insert_Before (N, Decl);
1574 Set_Has_Pragma_Inline (Subp);
1576 if Pragma_Name (Prag) = Name_Inline_Always then
1577 Set_Is_Inlined (Subp);
1578 Set_Has_Pragma_Inline_Always (Subp);
1585 end Check_Inline_Pragma;
1587 -----------------------
1588 -- Disambiguate_Spec --
1589 -----------------------
1591 function Disambiguate_Spec return Entity_Id is
1592 Priv_Spec : Entity_Id;
1595 procedure Replace_Types (To_Corresponding : Boolean);
1596 -- Depending on the flag, replace the type of formal parameters of
1597 -- Body_Id if it is a concurrent type implementing interfaces with
1598 -- the corresponding record type or the other way around.
1600 procedure Replace_Types (To_Corresponding : Boolean) is
1602 Formal_Typ : Entity_Id;
1605 Formal := First_Formal (Body_Id);
1606 while Present (Formal) loop
1607 Formal_Typ := Etype (Formal);
1609 -- From concurrent type to corresponding record
1611 if To_Corresponding then
1612 if Is_Concurrent_Type (Formal_Typ)
1613 and then Present (Corresponding_Record_Type (Formal_Typ))
1614 and then Present (Interfaces (
1615 Corresponding_Record_Type (Formal_Typ)))
1618 Corresponding_Record_Type (Formal_Typ));
1621 -- From corresponding record to concurrent type
1624 if Is_Concurrent_Record_Type (Formal_Typ)
1625 and then Present (Interfaces (Formal_Typ))
1628 Corresponding_Concurrent_Type (Formal_Typ));
1632 Next_Formal (Formal);
1636 -- Start of processing for Disambiguate_Spec
1639 -- Try to retrieve the specification of the body as is. All error
1640 -- messages are suppressed because the body may not have a spec in
1641 -- its current state.
1643 Spec_N := Find_Corresponding_Spec (N, False);
1645 -- It is possible that this is the body of a primitive declared
1646 -- between a private and a full view of a concurrent type. The
1647 -- controlling parameter of the spec carries the concurrent type,
1648 -- not the corresponding record type as transformed by Analyze_
1649 -- Subprogram_Specification. In such cases, we undo the change
1650 -- made by the analysis of the specification and try to find the
1653 -- Note that wrappers already have their corresponding specs and
1654 -- bodies set during their creation, so if the candidate spec is
1655 -- a wrapper, then we definitely need to swap all types to their
1656 -- original concurrent status.
1659 or else Is_Primitive_Wrapper (Spec_N)
1661 -- Restore all references of corresponding record types to the
1662 -- original concurrent types.
1664 Replace_Types (To_Corresponding => False);
1665 Priv_Spec := Find_Corresponding_Spec (N, False);
1667 -- The current body truly belongs to a primitive declared between
1668 -- a private and a full view. We leave the modified body as is,
1669 -- and return the true spec.
1671 if Present (Priv_Spec)
1672 and then Is_Private_Primitive (Priv_Spec)
1677 -- In case that this is some sort of error, restore the original
1678 -- state of the body.
1680 Replace_Types (To_Corresponding => True);
1684 end Disambiguate_Spec;
1686 -------------------------------------
1687 -- Is_Private_Concurrent_Primitive --
1688 -------------------------------------
1690 function Is_Private_Concurrent_Primitive
1691 (Subp_Id : Entity_Id) return Boolean
1693 Formal_Typ : Entity_Id;
1696 if Present (First_Formal (Subp_Id)) then
1697 Formal_Typ := Etype (First_Formal (Subp_Id));
1699 if Is_Concurrent_Record_Type (Formal_Typ) then
1700 Formal_Typ := Corresponding_Concurrent_Type (Formal_Typ);
1703 -- The type of the first formal is a concurrent tagged type with
1707 Is_Concurrent_Type (Formal_Typ)
1708 and then Is_Tagged_Type (Formal_Typ)
1709 and then Has_Private_Declaration (Formal_Typ);
1713 end Is_Private_Concurrent_Primitive;
1715 ----------------------------
1716 -- Set_Trivial_Subprogram --
1717 ----------------------------
1719 procedure Set_Trivial_Subprogram (N : Node_Id) is
1720 Nxt : constant Node_Id := Next (N);
1723 Set_Is_Trivial_Subprogram (Body_Id);
1725 if Present (Spec_Id) then
1726 Set_Is_Trivial_Subprogram (Spec_Id);
1730 and then Nkind (Nxt) = N_Simple_Return_Statement
1731 and then No (Next (Nxt))
1732 and then Present (Expression (Nxt))
1733 and then Is_Entity_Name (Expression (Nxt))
1735 Set_Never_Set_In_Source (Entity (Expression (Nxt)), False);
1737 end Set_Trivial_Subprogram;
1739 ---------------------------------
1740 -- Verify_Overriding_Indicator --
1741 ---------------------------------
1743 procedure Verify_Overriding_Indicator is
1745 if Must_Override (Body_Spec) then
1746 if Nkind (Spec_Id) = N_Defining_Operator_Symbol
1747 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1751 elsif not Is_Overriding_Operation (Spec_Id) then
1753 ("subprogram& is not overriding", Body_Spec, Spec_Id);
1756 elsif Must_Not_Override (Body_Spec) then
1757 if Is_Overriding_Operation (Spec_Id) then
1759 ("subprogram& overrides inherited operation",
1760 Body_Spec, Spec_Id);
1762 elsif Nkind (Spec_Id) = N_Defining_Operator_Symbol
1763 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1766 ("subprogram & overrides predefined operator ",
1767 Body_Spec, Spec_Id);
1769 -- If this is not a primitive operation the overriding indicator
1770 -- is altogether illegal.
1772 elsif not Is_Primitive (Spec_Id) then
1773 Error_Msg_N ("overriding indicator only allowed " &
1774 "if subprogram is primitive",
1779 and then Is_Overriding_Operation (Spec_Id)
1781 pragma Assert (Unit_Declaration_Node (Body_Id) = N);
1782 Style.Missing_Overriding (N, Body_Id);
1784 end Verify_Overriding_Indicator;
1786 -- Start of processing for Analyze_Subprogram_Body
1789 if Debug_Flag_C then
1790 Write_Str ("==== Compiling subprogram body ");
1791 Write_Name (Chars (Body_Id));
1792 Write_Str (" from ");
1793 Write_Location (Loc);
1797 Trace_Scope (N, Body_Id, " Analyze subprogram: ");
1799 -- Generic subprograms are handled separately. They always have a
1800 -- generic specification. Determine whether current scope has a
1801 -- previous declaration.
1803 -- If the subprogram body is defined within an instance of the same
1804 -- name, the instance appears as a package renaming, and will be hidden
1805 -- within the subprogram.
1807 if Present (Prev_Id)
1808 and then not Is_Overloadable (Prev_Id)
1809 and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
1810 or else Comes_From_Source (Prev_Id))
1812 if Is_Generic_Subprogram (Prev_Id) then
1814 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
1815 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
1817 Analyze_Generic_Subprogram_Body (N, Spec_Id);
1821 -- Previous entity conflicts with subprogram name. Attempting to
1822 -- enter name will post error.
1824 Enter_Name (Body_Id);
1828 -- Non-generic case, find the subprogram declaration, if one was seen,
1829 -- or enter new overloaded entity in the current scope. If the
1830 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
1831 -- part of the context of one of its subunits. No need to redo the
1834 elsif Prev_Id = Body_Id
1835 and then Has_Completion (Body_Id)
1840 Body_Id := Analyze_Subprogram_Specification (Body_Spec);
1842 if Nkind (N) = N_Subprogram_Body_Stub
1843 or else No (Corresponding_Spec (N))
1845 if Is_Private_Concurrent_Primitive (Body_Id) then
1846 Spec_Id := Disambiguate_Spec;
1848 Spec_Id := Find_Corresponding_Spec (N);
1851 -- If this is a duplicate body, no point in analyzing it
1853 if Error_Posted (N) then
1857 -- A subprogram body should cause freezing of its own declaration,
1858 -- but if there was no previous explicit declaration, then the
1859 -- subprogram will get frozen too late (there may be code within
1860 -- the body that depends on the subprogram having been frozen,
1861 -- such as uses of extra formals), so we force it to be frozen
1862 -- here. Same holds if the body and spec are compilation units.
1863 -- Finally, if the return type is an anonymous access to protected
1864 -- subprogram, it must be frozen before the body because its
1865 -- expansion has generated an equivalent type that is used when
1866 -- elaborating the body.
1868 if No (Spec_Id) then
1869 Freeze_Before (N, Body_Id);
1871 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1872 Freeze_Before (N, Spec_Id);
1874 elsif Is_Access_Subprogram_Type (Etype (Body_Id)) then
1875 Freeze_Before (N, Etype (Body_Id));
1879 Spec_Id := Corresponding_Spec (N);
1883 -- Do not inline any subprogram that contains nested subprograms, since
1884 -- the backend inlining circuit seems to generate uninitialized
1885 -- references in this case. We know this happens in the case of front
1886 -- end ZCX support, but it also appears it can happen in other cases as
1887 -- well. The backend often rejects attempts to inline in the case of
1888 -- nested procedures anyway, so little if anything is lost by this.
1889 -- Note that this is test is for the benefit of the back-end. There is
1890 -- a separate test for front-end inlining that also rejects nested
1893 -- Do not do this test if errors have been detected, because in some
1894 -- error cases, this code blows up, and we don't need it anyway if
1895 -- there have been errors, since we won't get to the linker anyway.
1897 if Comes_From_Source (Body_Id)
1898 and then Serious_Errors_Detected = 0
1902 P_Ent := Scope (P_Ent);
1903 exit when No (P_Ent) or else P_Ent = Standard_Standard;
1905 if Is_Subprogram (P_Ent) then
1906 Set_Is_Inlined (P_Ent, False);
1908 if Comes_From_Source (P_Ent)
1909 and then Has_Pragma_Inline (P_Ent)
1912 ("cannot inline& (nested subprogram)?",
1919 Check_Inline_Pragma (Spec_Id);
1921 -- Deal with special case of a fully private operation in the body of
1922 -- the protected type. We must create a declaration for the subprogram,
1923 -- in order to attach the protected subprogram that will be used in
1924 -- internal calls. We exclude compiler generated bodies from the
1925 -- expander since the issue does not arise for those cases.
1928 and then Comes_From_Source (N)
1929 and then Is_Protected_Type (Current_Scope)
1938 Formal := First_Formal (Body_Id);
1940 -- The protected operation always has at least one formal, namely
1941 -- the object itself, but it is only placed in the parameter list
1942 -- if expansion is enabled.
1945 or else Expander_Active
1947 Plist := Copy_Parameter_List (Body_Id);
1952 if Nkind (Body_Spec) = N_Procedure_Specification then
1954 Make_Procedure_Specification (Loc,
1955 Defining_Unit_Name =>
1956 Make_Defining_Identifier (Sloc (Body_Id),
1957 Chars => Chars (Body_Id)),
1958 Parameter_Specifications => Plist);
1961 Make_Function_Specification (Loc,
1962 Defining_Unit_Name =>
1963 Make_Defining_Identifier (Sloc (Body_Id),
1964 Chars => Chars (Body_Id)),
1965 Parameter_Specifications => Plist,
1966 Result_Definition =>
1967 New_Occurrence_Of (Etype (Body_Id), Loc));
1971 Make_Subprogram_Declaration (Loc,
1972 Specification => New_Spec);
1973 Insert_Before (N, Decl);
1974 Spec_Id := Defining_Unit_Name (New_Spec);
1976 -- Indicate that the entity comes from source, to ensure that
1977 -- cross-reference information is properly generated. The body
1978 -- itself is rewritten during expansion, and the body entity will
1979 -- not appear in calls to the operation.
1981 Set_Comes_From_Source (Spec_Id, True);
1983 Set_Has_Completion (Spec_Id);
1984 Set_Convention (Spec_Id, Convention_Protected);
1988 -- If a separate spec is present, then deal with freezing issues
1990 if Present (Spec_Id) then
1991 Spec_Decl := Unit_Declaration_Node (Spec_Id);
1992 Verify_Overriding_Indicator;
1994 -- In general, the spec will be frozen when we start analyzing the
1995 -- body. However, for internally generated operations, such as
1996 -- wrapper functions for inherited operations with controlling
1997 -- results, the spec may not have been frozen by the time we
1998 -- expand the freeze actions that include the bodies. In particular,
1999 -- extra formals for accessibility or for return-in-place may need
2000 -- to be generated. Freeze nodes, if any, are inserted before the
2003 if not Is_Frozen (Spec_Id)
2004 and then Expander_Active
2006 -- Force the generation of its freezing node to ensure proper
2007 -- management of access types in the backend.
2009 -- This is definitely needed for some cases, but it is not clear
2010 -- why, to be investigated further???
2012 Set_Has_Delayed_Freeze (Spec_Id);
2013 Insert_Actions (N, Freeze_Entity (Spec_Id, Loc));
2017 -- Mark presence of postcondition proc in current scope
2019 if Chars (Body_Id) = Name_uPostconditions then
2020 Set_Has_Postconditions (Current_Scope);
2023 -- Place subprogram on scope stack, and make formals visible. If there
2024 -- is a spec, the visible entity remains that of the spec.
2026 if Present (Spec_Id) then
2027 Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
2029 if Is_Child_Unit (Spec_Id) then
2030 Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False);
2034 Style.Check_Identifier (Body_Id, Spec_Id);
2037 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
2038 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
2040 if Is_Abstract_Subprogram (Spec_Id) then
2041 Error_Msg_N ("an abstract subprogram cannot have a body", N);
2045 Set_Convention (Body_Id, Convention (Spec_Id));
2046 Set_Has_Completion (Spec_Id);
2048 if Is_Protected_Type (Scope (Spec_Id)) then
2049 Prot_Typ := Scope (Spec_Id);
2052 -- If this is a body generated for a renaming, do not check for
2053 -- full conformance. The check is redundant, because the spec of
2054 -- the body is a copy of the spec in the renaming declaration,
2055 -- and the test can lead to spurious errors on nested defaults.
2057 if Present (Spec_Decl)
2058 and then not Comes_From_Source (N)
2060 (Nkind (Original_Node (Spec_Decl)) =
2061 N_Subprogram_Renaming_Declaration
2062 or else (Present (Corresponding_Body (Spec_Decl))
2064 Nkind (Unit_Declaration_Node
2065 (Corresponding_Body (Spec_Decl))) =
2066 N_Subprogram_Renaming_Declaration))
2073 Fully_Conformant, True, Conformant, Body_Id);
2076 -- If the body is not fully conformant, we have to decide if we
2077 -- should analyze it or not. If it has a really messed up profile
2078 -- then we probably should not analyze it, since we will get too
2079 -- many bogus messages.
2081 -- Our decision is to go ahead in the non-fully conformant case
2082 -- only if it is at least mode conformant with the spec. Note
2083 -- that the call to Check_Fully_Conformant has issued the proper
2084 -- error messages to complain about the lack of conformance.
2087 and then not Mode_Conformant (Body_Id, Spec_Id)
2093 if Spec_Id /= Body_Id then
2094 Reference_Body_Formals (Spec_Id, Body_Id);
2097 if Nkind (N) /= N_Subprogram_Body_Stub then
2098 Set_Corresponding_Spec (N, Spec_Id);
2100 -- Ada 2005 (AI-345): If the operation is a primitive operation
2101 -- of a concurrent type, the type of the first parameter has been
2102 -- replaced with the corresponding record, which is the proper
2103 -- run-time structure to use. However, within the body there may
2104 -- be uses of the formals that depend on primitive operations
2105 -- of the type (in particular calls in prefixed form) for which
2106 -- we need the original concurrent type. The operation may have
2107 -- several controlling formals, so the replacement must be done
2110 if Comes_From_Source (Spec_Id)
2111 and then Present (First_Entity (Spec_Id))
2112 and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type
2113 and then Is_Tagged_Type (Etype (First_Entity (Spec_Id)))
2115 Present (Interfaces (Etype (First_Entity (Spec_Id))))
2118 (Corresponding_Concurrent_Type
2119 (Etype (First_Entity (Spec_Id))))
2122 Typ : constant Entity_Id := Etype (First_Entity (Spec_Id));
2126 Form := First_Formal (Spec_Id);
2127 while Present (Form) loop
2128 if Etype (Form) = Typ then
2129 Set_Etype (Form, Corresponding_Concurrent_Type (Typ));
2137 -- Make the formals visible, and place subprogram on scope stack.
2138 -- This is also the point at which we set Last_Real_Spec_Entity
2139 -- to mark the entities which will not be moved to the body.
2141 Install_Formals (Spec_Id);
2142 Last_Real_Spec_Entity := Last_Entity (Spec_Id);
2143 Push_Scope (Spec_Id);
2145 -- Make sure that the subprogram is immediately visible. For
2146 -- child units that have no separate spec this is indispensable.
2147 -- Otherwise it is safe albeit redundant.
2149 Set_Is_Immediately_Visible (Spec_Id);
2152 Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id);
2153 Set_Ekind (Body_Id, E_Subprogram_Body);
2154 Set_Scope (Body_Id, Scope (Spec_Id));
2155 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Spec_Id));
2157 -- Case of subprogram body with no previous spec
2161 and then Comes_From_Source (Body_Id)
2162 and then not Suppress_Style_Checks (Body_Id)
2163 and then not In_Instance
2165 Style.Body_With_No_Spec (N);
2168 New_Overloaded_Entity (Body_Id);
2170 if Nkind (N) /= N_Subprogram_Body_Stub then
2171 Set_Acts_As_Spec (N);
2172 Generate_Definition (Body_Id);
2174 (Body_Id, Body_Id, 'b', Set_Ref => False, Force => True);
2175 Generate_Reference_To_Formals (Body_Id);
2176 Install_Formals (Body_Id);
2177 Push_Scope (Body_Id);
2181 -- If the return type is an anonymous access type whose designated type
2182 -- is the limited view of a class-wide type and the non-limited view is
2183 -- available, update the return type accordingly.
2185 if Ada_Version >= Ada_05
2186 and then Comes_From_Source (N)
2193 Rtyp := Etype (Current_Scope);
2195 if Ekind (Rtyp) = E_Anonymous_Access_Type then
2196 Etyp := Directly_Designated_Type (Rtyp);
2198 if Is_Class_Wide_Type (Etyp)
2199 and then From_With_Type (Etyp)
2201 Set_Directly_Designated_Type
2202 (Etype (Current_Scope), Available_View (Etyp));
2208 -- If this is the proper body of a stub, we must verify that the stub
2209 -- conforms to the body, and to the previous spec if one was present.
2210 -- we know already that the body conforms to that spec. This test is
2211 -- only required for subprograms that come from source.
2213 if Nkind (Parent (N)) = N_Subunit
2214 and then Comes_From_Source (N)
2215 and then not Error_Posted (Body_Id)
2216 and then Nkind (Corresponding_Stub (Parent (N))) =
2217 N_Subprogram_Body_Stub
2220 Old_Id : constant Entity_Id :=
2222 (Specification (Corresponding_Stub (Parent (N))));
2224 Conformant : Boolean := False;
2227 if No (Spec_Id) then
2228 Check_Fully_Conformant (Body_Id, Old_Id);
2232 (Body_Id, Old_Id, Fully_Conformant, False, Conformant);
2234 if not Conformant then
2236 -- The stub was taken to be a new declaration. Indicate
2237 -- that it lacks a body.
2239 Set_Has_Completion (Old_Id, False);
2245 Set_Has_Completion (Body_Id);
2246 Check_Eliminated (Body_Id);
2248 if Nkind (N) = N_Subprogram_Body_Stub then
2251 elsif Present (Spec_Id)
2252 and then Expander_Active
2254 (Has_Pragma_Inline_Always (Spec_Id)
2255 or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining))
2257 Build_Body_To_Inline (N, Spec_Id);
2260 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
2261 -- if its specification we have to install the private withed units.
2262 -- This holds for child units as well.
2264 if Is_Compilation_Unit (Body_Id)
2265 or else Nkind (Parent (N)) = N_Compilation_Unit
2267 Install_Private_With_Clauses (Body_Id);
2270 Check_Anonymous_Return;
2272 -- Set the Protected_Formal field of each extra formal of the protected
2273 -- subprogram to reference the corresponding extra formal of the
2274 -- subprogram that implements it. For regular formals this occurs when
2275 -- the protected subprogram's declaration is expanded, but the extra
2276 -- formals don't get created until the subprogram is frozen. We need to
2277 -- do this before analyzing the protected subprogram's body so that any
2278 -- references to the original subprogram's extra formals will be changed
2279 -- refer to the implementing subprogram's formals (see Expand_Formal).
2281 if Present (Spec_Id)
2282 and then Is_Protected_Type (Scope (Spec_Id))
2283 and then Present (Protected_Body_Subprogram (Spec_Id))
2286 Impl_Subp : constant Entity_Id :=
2287 Protected_Body_Subprogram (Spec_Id);
2288 Prot_Ext_Formal : Entity_Id := Extra_Formals (Spec_Id);
2289 Impl_Ext_Formal : Entity_Id := Extra_Formals (Impl_Subp);
2291 while Present (Prot_Ext_Formal) loop
2292 pragma Assert (Present (Impl_Ext_Formal));
2293 Set_Protected_Formal (Prot_Ext_Formal, Impl_Ext_Formal);
2294 Next_Formal_With_Extras (Prot_Ext_Formal);
2295 Next_Formal_With_Extras (Impl_Ext_Formal);
2300 -- Now we can go on to analyze the body
2302 HSS := Handled_Statement_Sequence (N);
2303 Set_Actual_Subtypes (N, Current_Scope);
2305 -- Deal with preconditions and postconditions
2307 Process_PPCs (N, Spec_Id, Body_Id);
2309 -- Add a declaration for the Protection object, renaming declarations
2310 -- for discriminals and privals and finally a declaration for the entry
2311 -- family index (if applicable). This form of early expansion is done
2312 -- when the Expander is active because Install_Private_Data_Declarations
2313 -- references entities which were created during regular expansion.
2316 and then Comes_From_Source (N)
2317 and then Present (Prot_Typ)
2318 and then Present (Spec_Id)
2319 and then not Is_Eliminated (Spec_Id)
2321 Install_Private_Data_Declarations
2322 (Sloc (N), Spec_Id, Prot_Typ, N, Declarations (N));
2325 -- Analyze the declarations (this call will analyze the precondition
2326 -- Check pragmas we prepended to the list, as well as the declaration
2327 -- of the _Postconditions procedure).
2329 Analyze_Declarations (Declarations (N));
2331 -- Check completion, and analyze the statements
2334 Inspect_Deferred_Constant_Completion (Declarations (N));
2337 -- Deal with end of scope processing for the body
2339 Process_End_Label (HSS, 't', Current_Scope);
2341 Check_Subprogram_Order (N);
2342 Set_Analyzed (Body_Id);
2344 -- If we have a separate spec, then the analysis of the declarations
2345 -- caused the entities in the body to be chained to the spec id, but
2346 -- we want them chained to the body id. Only the formal parameters
2347 -- end up chained to the spec id in this case.
2349 if Present (Spec_Id) then
2351 -- We must conform to the categorization of our spec
2353 Validate_Categorization_Dependency (N, Spec_Id);
2355 -- And if this is a child unit, the parent units must conform
2357 if Is_Child_Unit (Spec_Id) then
2358 Validate_Categorization_Dependency
2359 (Unit_Declaration_Node (Spec_Id), Spec_Id);
2362 -- Here is where we move entities from the spec to the body
2364 -- Case where there are entities that stay with the spec
2366 if Present (Last_Real_Spec_Entity) then
2368 -- No body entities (happens when the only real spec entities
2369 -- come from precondition and postcondition pragmas)
2371 if No (Last_Entity (Body_Id)) then
2373 (Body_Id, Next_Entity (Last_Real_Spec_Entity));
2375 -- Body entities present (formals), so chain stuff past them
2379 (Last_Entity (Body_Id), Next_Entity (Last_Real_Spec_Entity));
2382 Set_Next_Entity (Last_Real_Spec_Entity, Empty);
2383 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2384 Set_Last_Entity (Spec_Id, Last_Real_Spec_Entity);
2386 -- Case where there are no spec entities, in this case there can
2387 -- be no body entities either, so just move everything.
2390 pragma Assert (No (Last_Entity (Body_Id)));
2391 Set_First_Entity (Body_Id, First_Entity (Spec_Id));
2392 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2393 Set_First_Entity (Spec_Id, Empty);
2394 Set_Last_Entity (Spec_Id, Empty);
2398 -- If function, check return statements
2400 if Nkind (Body_Spec) = N_Function_Specification then
2405 if Present (Spec_Id) then
2411 if Return_Present (Id) then
2412 Check_Returns (HSS, 'F', Missing_Ret);
2415 Set_Has_Missing_Return (Id);
2418 elsif not Is_Machine_Code_Subprogram (Id)
2419 and then not Body_Deleted
2421 Error_Msg_N ("missing RETURN statement in function body", N);
2425 -- If procedure with No_Return, check returns
2427 elsif Nkind (Body_Spec) = N_Procedure_Specification
2428 and then Present (Spec_Id)
2429 and then No_Return (Spec_Id)
2431 Check_Returns (HSS, 'P', Missing_Ret, Spec_Id);
2434 -- Now we are going to check for variables that are never modified in
2435 -- the body of the procedure. But first we deal with a special case
2436 -- where we want to modify this check. If the body of the subprogram
2437 -- starts with a raise statement or its equivalent, or if the body
2438 -- consists entirely of a null statement, then it is pretty obvious
2439 -- that it is OK to not reference the parameters. For example, this
2440 -- might be the following common idiom for a stubbed function:
2441 -- statement of the procedure raises an exception. In particular this
2442 -- deals with the common idiom of a stubbed function, which might
2443 -- appear as something like
2445 -- function F (A : Integer) return Some_Type;
2448 -- raise Program_Error;
2452 -- Here the purpose of X is simply to satisfy the annoying requirement
2453 -- in Ada that there be at least one return, and we certainly do not
2454 -- want to go posting warnings on X that it is not initialized! On
2455 -- the other hand, if X is entirely unreferenced that should still
2458 -- What we do is to detect these cases, and if we find them, flag the
2459 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
2460 -- suppress unwanted warnings. For the case of the function stub above
2461 -- we have a special test to set X as apparently assigned to suppress
2468 -- Skip initial labels (for one thing this occurs when we are in
2469 -- front end ZCX mode, but in any case it is irrelevant), and also
2470 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
2472 Stm := First (Statements (HSS));
2473 while Nkind (Stm) = N_Label
2474 or else Nkind (Stm) in N_Push_xxx_Label
2479 -- Do the test on the original statement before expansion
2482 Ostm : constant Node_Id := Original_Node (Stm);
2485 -- If explicit raise statement, turn on flag
2487 if Nkind (Ostm) = N_Raise_Statement then
2488 Set_Trivial_Subprogram (Stm);
2490 -- If null statement, and no following statements, turn on flag
2492 elsif Nkind (Stm) = N_Null_Statement
2493 and then Comes_From_Source (Stm)
2494 and then No (Next (Stm))
2496 Set_Trivial_Subprogram (Stm);
2498 -- Check for explicit call cases which likely raise an exception
2500 elsif Nkind (Ostm) = N_Procedure_Call_Statement then
2501 if Is_Entity_Name (Name (Ostm)) then
2503 Ent : constant Entity_Id := Entity (Name (Ostm));
2506 -- If the procedure is marked No_Return, then likely it
2507 -- raises an exception, but in any case it is not coming
2508 -- back here, so turn on the flag.
2510 if Ekind (Ent) = E_Procedure
2511 and then No_Return (Ent)
2513 Set_Trivial_Subprogram (Stm);
2521 -- Check for variables that are never modified
2527 -- If there is a separate spec, then transfer Never_Set_In_Source
2528 -- flags from out parameters to the corresponding entities in the
2529 -- body. The reason we do that is we want to post error flags on
2530 -- the body entities, not the spec entities.
2532 if Present (Spec_Id) then
2533 E1 := First_Entity (Spec_Id);
2534 while Present (E1) loop
2535 if Ekind (E1) = E_Out_Parameter then
2536 E2 := First_Entity (Body_Id);
2537 while Present (E2) loop
2538 exit when Chars (E1) = Chars (E2);
2542 if Present (E2) then
2543 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
2551 -- Check references in body unless it was deleted. Note that the
2552 -- check of Body_Deleted here is not just for efficiency, it is
2553 -- necessary to avoid junk warnings on formal parameters.
2555 if not Body_Deleted then
2556 Check_References (Body_Id);
2559 end Analyze_Subprogram_Body;
2561 ------------------------------------
2562 -- Analyze_Subprogram_Declaration --
2563 ------------------------------------
2565 procedure Analyze_Subprogram_Declaration (N : Node_Id) is
2566 Designator : constant Entity_Id :=
2567 Analyze_Subprogram_Specification (Specification (N));
2568 Scop : constant Entity_Id := Current_Scope;
2570 -- Start of processing for Analyze_Subprogram_Declaration
2573 Generate_Definition (Designator);
2575 -- Check for RCI unit subprogram declarations for illegal inlined
2576 -- subprograms and subprograms having access parameter or limited
2577 -- parameter without Read and Write attributes (RM E.2.3(12-13)).
2579 Validate_RCI_Subprogram_Declaration (N);
2583 Defining_Entity (N),
2584 " Analyze subprogram spec: ");
2586 if Debug_Flag_C then
2587 Write_Str ("==== Compiling subprogram spec ");
2588 Write_Name (Chars (Designator));
2589 Write_Str (" from ");
2590 Write_Location (Sloc (N));
2594 New_Overloaded_Entity (Designator);
2595 Check_Delayed_Subprogram (Designator);
2597 -- If the type of the first formal of the current subprogram is a non
2598 -- generic tagged private type , mark the subprogram as being a private
2601 if Present (First_Formal (Designator)) then
2603 Formal_Typ : constant Entity_Id :=
2604 Etype (First_Formal (Designator));
2606 Set_Is_Private_Primitive (Designator,
2607 Is_Tagged_Type (Formal_Typ)
2608 and then Is_Private_Type (Formal_Typ)
2609 and then not Is_Generic_Actual_Type (Formal_Typ));
2613 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
2616 if Ada_Version >= Ada_05
2617 and then Comes_From_Source (N)
2618 and then Is_Dispatching_Operation (Designator)
2625 if Has_Controlling_Result (Designator) then
2626 Etyp := Etype (Designator);
2629 E := First_Entity (Designator);
2631 and then Is_Formal (E)
2632 and then not Is_Controlling_Formal (E)
2640 if Is_Access_Type (Etyp) then
2641 Etyp := Directly_Designated_Type (Etyp);
2644 if Is_Interface (Etyp)
2645 and then not Is_Abstract_Subprogram (Designator)
2646 and then not (Ekind (Designator) = E_Procedure
2647 and then Null_Present (Specification (N)))
2649 Error_Msg_Name_1 := Chars (Defining_Entity (N));
2651 ("(Ada 2005) interface subprogram % must be abstract or null",
2657 -- What is the following code for, it used to be
2659 -- ??? Set_Suppress_Elaboration_Checks
2660 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
2662 -- The following seems equivalent, but a bit dubious
2664 if Elaboration_Checks_Suppressed (Designator) then
2665 Set_Kill_Elaboration_Checks (Designator);
2668 if Scop /= Standard_Standard
2669 and then not Is_Child_Unit (Designator)
2671 Set_Categorization_From_Scope (Designator, Scop);
2673 -- For a compilation unit, check for library-unit pragmas
2675 Push_Scope (Designator);
2676 Set_Categorization_From_Pragmas (N);
2677 Validate_Categorization_Dependency (N, Designator);
2681 -- For a compilation unit, set body required. This flag will only be
2682 -- reset if a valid Import or Interface pragma is processed later on.
2684 if Nkind (Parent (N)) = N_Compilation_Unit then
2685 Set_Body_Required (Parent (N), True);
2687 if Ada_Version >= Ada_05
2688 and then Nkind (Specification (N)) = N_Procedure_Specification
2689 and then Null_Present (Specification (N))
2692 ("null procedure cannot be declared at library level", N);
2696 Generate_Reference_To_Formals (Designator);
2697 Check_Eliminated (Designator);
2699 -- Ada 2005: if procedure is declared with "is null" qualifier,
2700 -- it requires no body.
2702 if Nkind (Specification (N)) = N_Procedure_Specification
2703 and then Null_Present (Specification (N))
2705 Set_Has_Completion (Designator);
2706 Set_Is_Inlined (Designator);
2708 if Is_Protected_Type (Current_Scope) then
2710 ("protected operation cannot be a null procedure", N);
2713 end Analyze_Subprogram_Declaration;
2715 --------------------------------------
2716 -- Analyze_Subprogram_Specification --
2717 --------------------------------------
2719 -- Reminder: N here really is a subprogram specification (not a subprogram
2720 -- declaration). This procedure is called to analyze the specification in
2721 -- both subprogram bodies and subprogram declarations (specs).
2723 function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is
2724 Designator : constant Entity_Id := Defining_Entity (N);
2725 Formals : constant List_Id := Parameter_Specifications (N);
2727 -- Start of processing for Analyze_Subprogram_Specification
2730 Generate_Definition (Designator);
2732 if Nkind (N) = N_Function_Specification then
2733 Set_Ekind (Designator, E_Function);
2734 Set_Mechanism (Designator, Default_Mechanism);
2737 Set_Ekind (Designator, E_Procedure);
2738 Set_Etype (Designator, Standard_Void_Type);
2741 -- Introduce new scope for analysis of the formals and the return type
2743 Set_Scope (Designator, Current_Scope);
2745 if Present (Formals) then
2746 Push_Scope (Designator);
2747 Process_Formals (Formals, N);
2749 -- Ada 2005 (AI-345): If this is an overriding operation of an
2750 -- inherited interface operation, and the controlling type is
2751 -- a synchronized type, replace the type with its corresponding
2752 -- record, to match the proper signature of an overriding operation.
2754 if Ada_Version >= Ada_05 then
2757 Formal_Typ : Entity_Id;
2758 Rec_Typ : Entity_Id;
2761 Formal := First_Formal (Designator);
2762 while Present (Formal) loop
2763 Formal_Typ := Etype (Formal);
2765 if Is_Concurrent_Type (Formal_Typ)
2766 and then Present (Corresponding_Record_Type (Formal_Typ))
2768 Rec_Typ := Corresponding_Record_Type (Formal_Typ);
2770 if Present (Interfaces (Rec_Typ)) then
2771 Set_Etype (Formal, Rec_Typ);
2775 Next_Formal (Formal);
2782 -- The subprogram scope is pushed and popped around the processing of
2783 -- the return type for consistency with call above to Process_Formals
2784 -- (which itself can call Analyze_Return_Type), and to ensure that any
2785 -- itype created for the return type will be associated with the proper
2788 elsif Nkind (N) = N_Function_Specification then
2789 Push_Scope (Designator);
2791 Analyze_Return_Type (N);
2796 if Nkind (N) = N_Function_Specification then
2797 if Nkind (Designator) = N_Defining_Operator_Symbol then
2798 Valid_Operator_Definition (Designator);
2801 May_Need_Actuals (Designator);
2803 -- Ada 2005 (AI-251): If the return type is abstract, verify that
2804 -- the subprogram is abstract also. This does not apply to renaming
2805 -- declarations, where abstractness is inherited.
2806 -- In case of primitives associated with abstract interface types
2807 -- the check is applied later (see Analyze_Subprogram_Declaration).
2809 if Is_Abstract_Type (Etype (Designator))
2810 and then not Is_Interface (Etype (Designator))
2811 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2812 and then Nkind (Parent (N)) /=
2813 N_Abstract_Subprogram_Declaration
2815 (Nkind (Parent (N))) /= N_Formal_Abstract_Subprogram_Declaration
2818 ("function that returns abstract type must be abstract", N);
2823 end Analyze_Subprogram_Specification;
2825 --------------------------
2826 -- Build_Body_To_Inline --
2827 --------------------------
2829 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is
2830 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
2831 Original_Body : Node_Id;
2832 Body_To_Analyze : Node_Id;
2833 Max_Size : constant := 10;
2834 Stat_Count : Integer := 0;
2836 function Has_Excluded_Declaration (Decls : List_Id) return Boolean;
2837 -- Check for declarations that make inlining not worthwhile
2839 function Has_Excluded_Statement (Stats : List_Id) return Boolean;
2840 -- Check for statements that make inlining not worthwhile: any tasking
2841 -- statement, nested at any level. Keep track of total number of
2842 -- elementary statements, as a measure of acceptable size.
2844 function Has_Pending_Instantiation return Boolean;
2845 -- If some enclosing body contains instantiations that appear before the
2846 -- corresponding generic body, the enclosing body has a freeze node so
2847 -- that it can be elaborated after the generic itself. This might
2848 -- conflict with subsequent inlinings, so that it is unsafe to try to
2849 -- inline in such a case.
2851 function Has_Single_Return return Boolean;
2852 -- In general we cannot inline functions that return unconstrained type.
2853 -- However, we can handle such functions if all return statements return
2854 -- a local variable that is the only declaration in the body of the
2855 -- function. In that case the call can be replaced by that local
2856 -- variable as is done for other inlined calls.
2858 procedure Remove_Pragmas;
2859 -- A pragma Unreferenced or pragma Unmodified that mentions a formal
2860 -- parameter has no meaning when the body is inlined and the formals
2861 -- are rewritten. Remove it from body to inline. The analysis of the
2862 -- non-inlined body will handle the pragma properly.
2864 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean;
2865 -- If the body of the subprogram includes a call that returns an
2866 -- unconstrained type, the secondary stack is involved, and it
2867 -- is not worth inlining.
2869 ------------------------------
2870 -- Has_Excluded_Declaration --
2871 ------------------------------
2873 function Has_Excluded_Declaration (Decls : List_Id) return Boolean is
2876 function Is_Unchecked_Conversion (D : Node_Id) return Boolean;
2877 -- Nested subprograms make a given body ineligible for inlining, but
2878 -- we make an exception for instantiations of unchecked conversion.
2879 -- The body has not been analyzed yet, so check the name, and verify
2880 -- that the visible entity with that name is the predefined unit.
2882 -----------------------------
2883 -- Is_Unchecked_Conversion --
2884 -----------------------------
2886 function Is_Unchecked_Conversion (D : Node_Id) return Boolean is
2887 Id : constant Node_Id := Name (D);
2891 if Nkind (Id) = N_Identifier
2892 and then Chars (Id) = Name_Unchecked_Conversion
2894 Conv := Current_Entity (Id);
2896 elsif Nkind_In (Id, N_Selected_Component, N_Expanded_Name)
2897 and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion
2899 Conv := Current_Entity (Selector_Name (Id));
2904 return Present (Conv)
2905 and then Is_Predefined_File_Name
2906 (Unit_File_Name (Get_Source_Unit (Conv)))
2907 and then Is_Intrinsic_Subprogram (Conv);
2908 end Is_Unchecked_Conversion;
2910 -- Start of processing for Has_Excluded_Declaration
2914 while Present (D) loop
2915 if (Nkind (D) = N_Function_Instantiation
2916 and then not Is_Unchecked_Conversion (D))
2917 or else Nkind_In (D, N_Protected_Type_Declaration,
2918 N_Package_Declaration,
2919 N_Package_Instantiation,
2921 N_Procedure_Instantiation,
2922 N_Task_Type_Declaration)
2925 ("cannot inline & (non-allowed declaration)?", D, Subp);
2933 end Has_Excluded_Declaration;
2935 ----------------------------
2936 -- Has_Excluded_Statement --
2937 ----------------------------
2939 function Has_Excluded_Statement (Stats : List_Id) return Boolean is
2945 while Present (S) loop
2946 Stat_Count := Stat_Count + 1;
2948 if Nkind_In (S, N_Abort_Statement,
2949 N_Asynchronous_Select,
2950 N_Conditional_Entry_Call,
2951 N_Delay_Relative_Statement,
2952 N_Delay_Until_Statement,
2957 ("cannot inline & (non-allowed statement)?", S, Subp);
2960 elsif Nkind (S) = N_Block_Statement then
2961 if Present (Declarations (S))
2962 and then Has_Excluded_Declaration (Declarations (S))
2966 elsif Present (Handled_Statement_Sequence (S))
2969 (Exception_Handlers (Handled_Statement_Sequence (S)))
2971 Has_Excluded_Statement
2972 (Statements (Handled_Statement_Sequence (S))))
2977 elsif Nkind (S) = N_Case_Statement then
2978 E := First (Alternatives (S));
2979 while Present (E) loop
2980 if Has_Excluded_Statement (Statements (E)) then
2987 elsif Nkind (S) = N_If_Statement then
2988 if Has_Excluded_Statement (Then_Statements (S)) then
2992 if Present (Elsif_Parts (S)) then
2993 E := First (Elsif_Parts (S));
2994 while Present (E) loop
2995 if Has_Excluded_Statement (Then_Statements (E)) then
3002 if Present (Else_Statements (S))
3003 and then Has_Excluded_Statement (Else_Statements (S))
3008 elsif Nkind (S) = N_Loop_Statement
3009 and then Has_Excluded_Statement (Statements (S))
3018 end Has_Excluded_Statement;
3020 -------------------------------
3021 -- Has_Pending_Instantiation --
3022 -------------------------------
3024 function Has_Pending_Instantiation return Boolean is
3029 while Present (S) loop
3030 if Is_Compilation_Unit (S)
3031 or else Is_Child_Unit (S)
3034 elsif Ekind (S) = E_Package
3035 and then Has_Forward_Instantiation (S)
3044 end Has_Pending_Instantiation;
3046 ------------------------
3047 -- Has_Single_Return --
3048 ------------------------
3050 function Has_Single_Return return Boolean is
3051 Return_Statement : Node_Id := Empty;
3053 function Check_Return (N : Node_Id) return Traverse_Result;
3059 function Check_Return (N : Node_Id) return Traverse_Result is
3061 if Nkind (N) = N_Simple_Return_Statement then
3062 if Present (Expression (N))
3063 and then Is_Entity_Name (Expression (N))
3065 if No (Return_Statement) then
3066 Return_Statement := N;
3069 elsif Chars (Expression (N)) =
3070 Chars (Expression (Return_Statement))
3079 -- Expression has wrong form
3089 function Check_All_Returns is new Traverse_Func (Check_Return);
3091 -- Start of processing for Has_Single_Return
3094 return Check_All_Returns (N) = OK
3095 and then Present (Declarations (N))
3096 and then Present (First (Declarations (N)))
3097 and then Chars (Expression (Return_Statement)) =
3098 Chars (Defining_Identifier (First (Declarations (N))));
3099 end Has_Single_Return;
3101 --------------------
3102 -- Remove_Pragmas --
3103 --------------------
3105 procedure Remove_Pragmas is
3110 Decl := First (Declarations (Body_To_Analyze));
3111 while Present (Decl) loop
3114 if Nkind (Decl) = N_Pragma
3115 and then (Pragma_Name (Decl) = Name_Unreferenced
3117 Pragma_Name (Decl) = Name_Unmodified)
3126 --------------------------
3127 -- Uses_Secondary_Stack --
3128 --------------------------
3130 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is
3131 function Check_Call (N : Node_Id) return Traverse_Result;
3132 -- Look for function calls that return an unconstrained type
3138 function Check_Call (N : Node_Id) return Traverse_Result is
3140 if Nkind (N) = N_Function_Call
3141 and then Is_Entity_Name (Name (N))
3142 and then Is_Composite_Type (Etype (Entity (Name (N))))
3143 and then not Is_Constrained (Etype (Entity (Name (N))))
3146 ("cannot inline & (call returns unconstrained type)?",
3154 function Check_Calls is new Traverse_Func (Check_Call);
3157 return Check_Calls (Bod) = Abandon;
3158 end Uses_Secondary_Stack;
3160 -- Start of processing for Build_Body_To_Inline
3163 -- Return immediately if done already
3165 if Nkind (Decl) = N_Subprogram_Declaration
3166 and then Present (Body_To_Inline (Decl))
3170 -- Functions that return unconstrained composite types require
3171 -- secondary stack handling, and cannot currently be inlined, unless
3172 -- all return statements return a local variable that is the first
3173 -- local declaration in the body.
3175 elsif Ekind (Subp) = E_Function
3176 and then not Is_Scalar_Type (Etype (Subp))
3177 and then not Is_Access_Type (Etype (Subp))
3178 and then not Is_Constrained (Etype (Subp))
3180 if not Has_Single_Return then
3182 ("cannot inline & (unconstrained return type)?", N, Subp);
3186 -- Ditto for functions that return controlled types, where controlled
3187 -- actions interfere in complex ways with inlining.
3189 elsif Ekind (Subp) = E_Function
3190 and then Needs_Finalization (Etype (Subp))
3193 ("cannot inline & (controlled return type)?", N, Subp);
3197 if Present (Declarations (N))
3198 and then Has_Excluded_Declaration (Declarations (N))
3203 if Present (Handled_Statement_Sequence (N)) then
3204 if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then
3206 ("cannot inline& (exception handler)?",
3207 First (Exception_Handlers (Handled_Statement_Sequence (N))),
3211 Has_Excluded_Statement
3212 (Statements (Handled_Statement_Sequence (N)))
3218 -- We do not inline a subprogram that is too large, unless it is
3219 -- marked Inline_Always. This pragma does not suppress the other
3220 -- checks on inlining (forbidden declarations, handlers, etc).
3222 if Stat_Count > Max_Size
3223 and then not Has_Pragma_Inline_Always (Subp)
3225 Cannot_Inline ("cannot inline& (body too large)?", N, Subp);
3229 if Has_Pending_Instantiation then
3231 ("cannot inline& (forward instance within enclosing body)?",
3236 -- Within an instance, the body to inline must be treated as a nested
3237 -- generic, so that the proper global references are preserved.
3239 -- Note that we do not do this at the library level, because it is not
3240 -- needed, and furthermore this causes trouble if front end inlining
3241 -- is activated (-gnatN).
3243 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then
3244 Save_Env (Scope (Current_Scope), Scope (Current_Scope));
3245 Original_Body := Copy_Generic_Node (N, Empty, True);
3247 Original_Body := Copy_Separate_Tree (N);
3250 -- We need to capture references to the formals in order to substitute
3251 -- the actuals at the point of inlining, i.e. instantiation. To treat
3252 -- the formals as globals to the body to inline, we nest it within
3253 -- a dummy parameterless subprogram, declared within the real one.
3254 -- To avoid generating an internal name (which is never public, and
3255 -- which affects serial numbers of other generated names), we use
3256 -- an internal symbol that cannot conflict with user declarations.
3258 Set_Parameter_Specifications (Specification (Original_Body), No_List);
3259 Set_Defining_Unit_Name
3260 (Specification (Original_Body),
3261 Make_Defining_Identifier (Sloc (N), Name_uParent));
3262 Set_Corresponding_Spec (Original_Body, Empty);
3264 Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False);
3266 -- Set return type of function, which is also global and does not need
3269 if Ekind (Subp) = E_Function then
3270 Set_Result_Definition (Specification (Body_To_Analyze),
3271 New_Occurrence_Of (Etype (Subp), Sloc (N)));
3274 if No (Declarations (N)) then
3275 Set_Declarations (N, New_List (Body_To_Analyze));
3277 Append (Body_To_Analyze, Declarations (N));
3280 Expander_Mode_Save_And_Set (False);
3283 Analyze (Body_To_Analyze);
3284 Push_Scope (Defining_Entity (Body_To_Analyze));
3285 Save_Global_References (Original_Body);
3287 Remove (Body_To_Analyze);
3289 Expander_Mode_Restore;
3291 -- Restore environment if previously saved
3293 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then
3297 -- If secondary stk used there is no point in inlining. We have
3298 -- already issued the warning in this case, so nothing to do.
3300 if Uses_Secondary_Stack (Body_To_Analyze) then
3304 Set_Body_To_Inline (Decl, Original_Body);
3305 Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp));
3306 Set_Is_Inlined (Subp);
3307 end Build_Body_To_Inline;
3313 procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is
3315 -- Do not emit warning if this is a predefined unit which is not
3316 -- the main unit. With validity checks enabled, some predefined
3317 -- subprograms may contain nested subprograms and become ineligible
3320 if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp)))
3321 and then not In_Extended_Main_Source_Unit (Subp)
3325 elsif Has_Pragma_Inline_Always (Subp) then
3327 -- Remove last character (question mark) to make this into an error,
3328 -- because the Inline_Always pragma cannot be obeyed.
3330 Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp);
3332 elsif Ineffective_Inline_Warnings then
3333 Error_Msg_NE (Msg, N, Subp);
3337 -----------------------
3338 -- Check_Conformance --
3339 -----------------------
3341 procedure Check_Conformance
3342 (New_Id : Entity_Id;
3344 Ctype : Conformance_Type;
3346 Conforms : out Boolean;
3347 Err_Loc : Node_Id := Empty;
3348 Get_Inst : Boolean := False;
3349 Skip_Controlling_Formals : Boolean := False)
3351 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id);
3352 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
3353 -- If Errmsg is True, then processing continues to post an error message
3354 -- for conformance error on given node. Two messages are output. The
3355 -- first message points to the previous declaration with a general "no
3356 -- conformance" message. The second is the detailed reason, supplied as
3357 -- Msg. The parameter N provide information for a possible & insertion
3358 -- in the message, and also provides the location for posting the
3359 -- message in the absence of a specified Err_Loc location.
3361 -----------------------
3362 -- Conformance_Error --
3363 -----------------------
3365 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is
3372 if No (Err_Loc) then
3378 Error_Msg_Sloc := Sloc (Old_Id);
3381 when Type_Conformant =>
3383 ("not type conformant with declaration#!", Enode);
3385 when Mode_Conformant =>
3386 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3388 ("not mode conformant with operation inherited#!",
3392 ("not mode conformant with declaration#!", Enode);
3395 when Subtype_Conformant =>
3396 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3398 ("not subtype conformant with operation inherited#!",
3402 ("not subtype conformant with declaration#!", Enode);
3405 when Fully_Conformant =>
3406 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3408 ("not fully conformant with operation inherited#!",
3412 ("not fully conformant with declaration#!", Enode);
3416 Error_Msg_NE (Msg, Enode, N);
3418 end Conformance_Error;
3422 Old_Type : constant Entity_Id := Etype (Old_Id);
3423 New_Type : constant Entity_Id := Etype (New_Id);
3424 Old_Formal : Entity_Id;
3425 New_Formal : Entity_Id;
3426 Access_Types_Match : Boolean;
3427 Old_Formal_Base : Entity_Id;
3428 New_Formal_Base : Entity_Id;
3430 -- Start of processing for Check_Conformance
3435 -- We need a special case for operators, since they don't appear
3438 if Ctype = Type_Conformant then
3439 if Ekind (New_Id) = E_Operator
3440 and then Operator_Matches_Spec (New_Id, Old_Id)
3446 -- If both are functions/operators, check return types conform
3448 if Old_Type /= Standard_Void_Type
3449 and then New_Type /= Standard_Void_Type
3452 -- If we are checking interface conformance we omit controlling
3453 -- arguments and result, because we are only checking the conformance
3454 -- of the remaining parameters.
3456 if Has_Controlling_Result (Old_Id)
3457 and then Has_Controlling_Result (New_Id)
3458 and then Skip_Controlling_Formals
3462 elsif not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then
3463 Conformance_Error ("\return type does not match!", New_Id);
3467 -- Ada 2005 (AI-231): In case of anonymous access types check the
3468 -- null-exclusion and access-to-constant attributes match.
3470 if Ada_Version >= Ada_05
3471 and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type
3473 (Can_Never_Be_Null (Old_Type)
3474 /= Can_Never_Be_Null (New_Type)
3475 or else Is_Access_Constant (Etype (Old_Type))
3476 /= Is_Access_Constant (Etype (New_Type)))
3478 Conformance_Error ("\return type does not match!", New_Id);
3482 -- If either is a function/operator and the other isn't, error
3484 elsif Old_Type /= Standard_Void_Type
3485 or else New_Type /= Standard_Void_Type
3487 Conformance_Error ("\functions can only match functions!", New_Id);
3491 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
3492 -- If this is a renaming as body, refine error message to indicate that
3493 -- the conflict is with the original declaration. If the entity is not
3494 -- frozen, the conventions don't have to match, the one of the renamed
3495 -- entity is inherited.
3497 if Ctype >= Subtype_Conformant then
3498 if Convention (Old_Id) /= Convention (New_Id) then
3500 if not Is_Frozen (New_Id) then
3503 elsif Present (Err_Loc)
3504 and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration
3505 and then Present (Corresponding_Spec (Err_Loc))
3507 Error_Msg_Name_1 := Chars (New_Id);
3509 Name_Ada + Convention_Id'Pos (Convention (New_Id));
3511 Conformance_Error ("\prior declaration for% has convention %!");
3514 Conformance_Error ("\calling conventions do not match!");
3519 elsif Is_Formal_Subprogram (Old_Id)
3520 or else Is_Formal_Subprogram (New_Id)
3522 Conformance_Error ("\formal subprograms not allowed!");
3527 -- Deal with parameters
3529 -- Note: we use the entity information, rather than going directly
3530 -- to the specification in the tree. This is not only simpler, but
3531 -- absolutely necessary for some cases of conformance tests between
3532 -- operators, where the declaration tree simply does not exist!
3534 Old_Formal := First_Formal (Old_Id);
3535 New_Formal := First_Formal (New_Id);
3536 while Present (Old_Formal) and then Present (New_Formal) loop
3537 if Is_Controlling_Formal (Old_Formal)
3538 and then Is_Controlling_Formal (New_Formal)
3539 and then Skip_Controlling_Formals
3541 -- The controlling formals will have different types when
3542 -- comparing an interface operation with its match, but both
3543 -- or neither must be access parameters.
3545 if Is_Access_Type (Etype (Old_Formal))
3547 Is_Access_Type (Etype (New_Formal))
3549 goto Skip_Controlling_Formal;
3552 ("\access parameter does not match!", New_Formal);
3556 if Ctype = Fully_Conformant then
3558 -- Names must match. Error message is more accurate if we do
3559 -- this before checking that the types of the formals match.
3561 if Chars (Old_Formal) /= Chars (New_Formal) then
3562 Conformance_Error ("\name & does not match!", New_Formal);
3564 -- Set error posted flag on new formal as well to stop
3565 -- junk cascaded messages in some cases.
3567 Set_Error_Posted (New_Formal);
3572 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
3573 -- case occurs whenever a subprogram is being renamed and one of its
3574 -- parameters imposes a null exclusion. For example:
3576 -- type T is null record;
3577 -- type Acc_T is access T;
3578 -- subtype Acc_T_Sub is Acc_T;
3580 -- procedure P (Obj : not null Acc_T_Sub); -- itype
3581 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
3584 Old_Formal_Base := Etype (Old_Formal);
3585 New_Formal_Base := Etype (New_Formal);
3588 Old_Formal_Base := Get_Instance_Of (Old_Formal_Base);
3589 New_Formal_Base := Get_Instance_Of (New_Formal_Base);
3592 Access_Types_Match := Ada_Version >= Ada_05
3594 -- Ensure that this rule is only applied when New_Id is a
3595 -- renaming of Old_Id.
3597 and then Nkind (Parent (Parent (New_Id))) =
3598 N_Subprogram_Renaming_Declaration
3599 and then Nkind (Name (Parent (Parent (New_Id)))) in N_Has_Entity
3600 and then Present (Entity (Name (Parent (Parent (New_Id)))))
3601 and then Entity (Name (Parent (Parent (New_Id)))) = Old_Id
3603 -- Now handle the allowed access-type case
3605 and then Is_Access_Type (Old_Formal_Base)
3606 and then Is_Access_Type (New_Formal_Base)
3608 -- The type kinds must match. The only exception occurs with
3609 -- multiple generics of the form:
3612 -- type F is private; type A is private;
3613 -- type F_Ptr is access F; type A_Ptr is access A;
3614 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
3615 -- package F_Pack is ... package A_Pack is
3616 -- package F_Inst is
3617 -- new F_Pack (A, A_Ptr, A_P);
3619 -- When checking for conformance between the parameters of A_P
3620 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
3621 -- because the compiler has transformed A_Ptr into a subtype of
3622 -- F_Ptr. We catch this case in the code below.
3624 and then (Ekind (Old_Formal_Base) = Ekind (New_Formal_Base)
3626 (Is_Generic_Type (Old_Formal_Base)
3627 and then Is_Generic_Type (New_Formal_Base)
3628 and then Is_Internal (New_Formal_Base)
3629 and then Etype (Etype (New_Formal_Base)) =
3631 and then Directly_Designated_Type (Old_Formal_Base) =
3632 Directly_Designated_Type (New_Formal_Base)
3633 and then ((Is_Itype (Old_Formal_Base)
3634 and then Can_Never_Be_Null (Old_Formal_Base))
3636 (Is_Itype (New_Formal_Base)
3637 and then Can_Never_Be_Null (New_Formal_Base)));
3639 -- Types must always match. In the visible part of an instance,
3640 -- usual overloading rules for dispatching operations apply, and
3641 -- we check base types (not the actual subtypes).
3643 if In_Instance_Visible_Part
3644 and then Is_Dispatching_Operation (New_Id)
3646 if not Conforming_Types
3647 (T1 => Base_Type (Etype (Old_Formal)),
3648 T2 => Base_Type (Etype (New_Formal)),
3650 Get_Inst => Get_Inst)
3651 and then not Access_Types_Match
3653 Conformance_Error ("\type of & does not match!", New_Formal);
3657 elsif not Conforming_Types
3658 (T1 => Old_Formal_Base,
3659 T2 => New_Formal_Base,
3661 Get_Inst => Get_Inst)
3662 and then not Access_Types_Match
3664 -- Don't give error message if old type is Any_Type. This test
3665 -- avoids some cascaded errors, e.g. in case of a bad spec.
3667 if Errmsg and then Old_Formal_Base = Any_Type then
3670 Conformance_Error ("\type of & does not match!", New_Formal);
3676 -- For mode conformance, mode must match
3678 if Ctype >= Mode_Conformant then
3679 if Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal) then
3680 Conformance_Error ("\mode of & does not match!", New_Formal);
3683 -- Part of mode conformance for access types is having the same
3684 -- constant modifier.
3686 elsif Access_Types_Match
3687 and then Is_Access_Constant (Old_Formal_Base) /=
3688 Is_Access_Constant (New_Formal_Base)
3691 ("\constant modifier does not match!", New_Formal);
3696 if Ctype >= Subtype_Conformant then
3698 -- Ada 2005 (AI-231): In case of anonymous access types check
3699 -- the null-exclusion and access-to-constant attributes must
3702 if Ada_Version >= Ada_05
3703 and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type
3704 and then Ekind (Etype (New_Formal)) = E_Anonymous_Access_Type
3706 (Can_Never_Be_Null (Old_Formal) /=
3707 Can_Never_Be_Null (New_Formal)
3709 Is_Access_Constant (Etype (Old_Formal)) /=
3710 Is_Access_Constant (Etype (New_Formal)))
3712 -- It is allowed to omit the null-exclusion in case of stream
3713 -- attribute subprograms. We recognize stream subprograms
3714 -- through their TSS-generated suffix.
3717 TSS_Name : constant TSS_Name_Type := Get_TSS_Name (New_Id);
3719 if TSS_Name /= TSS_Stream_Read
3720 and then TSS_Name /= TSS_Stream_Write
3721 and then TSS_Name /= TSS_Stream_Input
3722 and then TSS_Name /= TSS_Stream_Output
3725 ("\type of & does not match!", New_Formal);
3732 -- Full conformance checks
3734 if Ctype = Fully_Conformant then
3736 -- We have checked already that names match
3738 if Parameter_Mode (Old_Formal) = E_In_Parameter then
3740 -- Check default expressions for in parameters
3743 NewD : constant Boolean :=
3744 Present (Default_Value (New_Formal));
3745 OldD : constant Boolean :=
3746 Present (Default_Value (Old_Formal));
3748 if NewD or OldD then
3750 -- The old default value has been analyzed because the
3751 -- current full declaration will have frozen everything
3752 -- before. The new default value has not been analyzed,
3753 -- so analyze it now before we check for conformance.
3756 Push_Scope (New_Id);
3757 Preanalyze_Spec_Expression
3758 (Default_Value (New_Formal), Etype (New_Formal));
3762 if not (NewD and OldD)
3763 or else not Fully_Conformant_Expressions
3764 (Default_Value (Old_Formal),
3765 Default_Value (New_Formal))
3768 ("\default expression for & does not match!",
3777 -- A couple of special checks for Ada 83 mode. These checks are
3778 -- skipped if either entity is an operator in package Standard,
3779 -- or if either old or new instance is not from the source program.
3781 if Ada_Version = Ada_83
3782 and then Sloc (Old_Id) > Standard_Location
3783 and then Sloc (New_Id) > Standard_Location
3784 and then Comes_From_Source (Old_Id)
3785 and then Comes_From_Source (New_Id)
3788 Old_Param : constant Node_Id := Declaration_Node (Old_Formal);
3789 New_Param : constant Node_Id := Declaration_Node (New_Formal);
3792 -- Explicit IN must be present or absent in both cases. This
3793 -- test is required only in the full conformance case.
3795 if In_Present (Old_Param) /= In_Present (New_Param)
3796 and then Ctype = Fully_Conformant
3799 ("\(Ada 83) IN must appear in both declarations",
3804 -- Grouping (use of comma in param lists) must be the same
3805 -- This is where we catch a misconformance like:
3808 -- A : Integer; B : Integer
3810 -- which are represented identically in the tree except
3811 -- for the setting of the flags More_Ids and Prev_Ids.
3813 if More_Ids (Old_Param) /= More_Ids (New_Param)
3814 or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param)
3817 ("\grouping of & does not match!", New_Formal);
3823 -- This label is required when skipping controlling formals
3825 <<Skip_Controlling_Formal>>
3827 Next_Formal (Old_Formal);
3828 Next_Formal (New_Formal);
3831 if Present (Old_Formal) then
3832 Conformance_Error ("\too few parameters!");
3835 elsif Present (New_Formal) then
3836 Conformance_Error ("\too many parameters!", New_Formal);
3839 end Check_Conformance;
3841 -----------------------
3842 -- Check_Conventions --
3843 -----------------------
3845 procedure Check_Conventions (Typ : Entity_Id) is
3846 Ifaces_List : Elist_Id;
3848 procedure Check_Convention (Op : Entity_Id);
3849 -- Verify that the convention of inherited dispatching operation Op is
3850 -- consistent among all subprograms it overrides. In order to minimize
3851 -- the search, Search_From is utilized to designate a specific point in
3852 -- the list rather than iterating over the whole list once more.
3854 ----------------------
3855 -- Check_Convention --
3856 ----------------------
3858 procedure Check_Convention (Op : Entity_Id) is
3859 Iface_Elmt : Elmt_Id;
3860 Iface_Prim_Elmt : Elmt_Id;
3861 Iface_Prim : Entity_Id;
3864 Iface_Elmt := First_Elmt (Ifaces_List);
3865 while Present (Iface_Elmt) loop
3867 First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
3868 while Present (Iface_Prim_Elmt) loop
3869 Iface_Prim := Node (Iface_Prim_Elmt);
3871 if Is_Interface_Conformant (Typ, Iface_Prim, Op)
3872 and then Convention (Iface_Prim) /= Convention (Op)
3875 ("inconsistent conventions in primitive operations", Typ);
3877 Error_Msg_Name_1 := Chars (Op);
3878 Error_Msg_Name_2 := Get_Convention_Name (Convention (Op));
3879 Error_Msg_Sloc := Sloc (Op);
3881 if Comes_From_Source (Op) then
3882 if not Is_Overriding_Operation (Op) then
3883 Error_Msg_N ("\\primitive % defined #", Typ);
3885 Error_Msg_N ("\\overriding operation % with " &
3886 "convention % defined #", Typ);
3889 else pragma Assert (Present (Alias (Op)));
3890 Error_Msg_Sloc := Sloc (Alias (Op));
3891 Error_Msg_N ("\\inherited operation % with " &
3892 "convention % defined #", Typ);
3895 Error_Msg_Name_1 := Chars (Op);
3897 Get_Convention_Name (Convention (Iface_Prim));
3898 Error_Msg_Sloc := Sloc (Iface_Prim);
3899 Error_Msg_N ("\\overridden operation % with " &
3900 "convention % defined #", Typ);
3902 -- Avoid cascading errors
3907 Next_Elmt (Iface_Prim_Elmt);
3910 Next_Elmt (Iface_Elmt);
3912 end Check_Convention;
3916 Prim_Op : Entity_Id;
3917 Prim_Op_Elmt : Elmt_Id;
3919 -- Start of processing for Check_Conventions
3922 if not Has_Interfaces (Typ) then
3926 Collect_Interfaces (Typ, Ifaces_List);
3928 -- The algorithm checks every overriding dispatching operation against
3929 -- all the corresponding overridden dispatching operations, detecting
3930 -- differences in conventions.
3932 Prim_Op_Elmt := First_Elmt (Primitive_Operations (Typ));
3933 while Present (Prim_Op_Elmt) loop
3934 Prim_Op := Node (Prim_Op_Elmt);
3936 -- A small optimization: skip the predefined dispatching operations
3937 -- since they always have the same convention.
3939 if not Is_Predefined_Dispatching_Operation (Prim_Op) then
3940 Check_Convention (Prim_Op);
3943 Next_Elmt (Prim_Op_Elmt);
3945 end Check_Conventions;
3947 ------------------------------
3948 -- Check_Delayed_Subprogram --
3949 ------------------------------
3951 procedure Check_Delayed_Subprogram (Designator : Entity_Id) is
3954 procedure Possible_Freeze (T : Entity_Id);
3955 -- T is the type of either a formal parameter or of the return type.
3956 -- If T is not yet frozen and needs a delayed freeze, then the
3957 -- subprogram itself must be delayed. If T is the limited view of an
3958 -- incomplete type the subprogram must be frozen as well, because
3959 -- T may depend on local types that have not been frozen yet.
3961 ---------------------
3962 -- Possible_Freeze --
3963 ---------------------
3965 procedure Possible_Freeze (T : Entity_Id) is
3967 if Has_Delayed_Freeze (T) and then not Is_Frozen (T) then
3968 Set_Has_Delayed_Freeze (Designator);
3970 elsif Is_Access_Type (T)
3971 and then Has_Delayed_Freeze (Designated_Type (T))
3972 and then not Is_Frozen (Designated_Type (T))
3974 Set_Has_Delayed_Freeze (Designator);
3976 elsif Ekind (T) = E_Incomplete_Type and then From_With_Type (T) then
3977 Set_Has_Delayed_Freeze (Designator);
3980 end Possible_Freeze;
3982 -- Start of processing for Check_Delayed_Subprogram
3985 -- Never need to freeze abstract subprogram
3987 if Ekind (Designator) /= E_Subprogram_Type
3988 and then Is_Abstract_Subprogram (Designator)
3992 -- Need delayed freeze if return type itself needs a delayed
3993 -- freeze and is not yet frozen.
3995 Possible_Freeze (Etype (Designator));
3996 Possible_Freeze (Base_Type (Etype (Designator))); -- needed ???
3998 -- Need delayed freeze if any of the formal types themselves need
3999 -- a delayed freeze and are not yet frozen.
4001 F := First_Formal (Designator);
4002 while Present (F) loop
4003 Possible_Freeze (Etype (F));
4004 Possible_Freeze (Base_Type (Etype (F))); -- needed ???
4009 -- Mark functions that return by reference. Note that it cannot be
4010 -- done for delayed_freeze subprograms because the underlying
4011 -- returned type may not be known yet (for private types)
4013 if not Has_Delayed_Freeze (Designator)
4014 and then Expander_Active
4017 Typ : constant Entity_Id := Etype (Designator);
4018 Utyp : constant Entity_Id := Underlying_Type (Typ);
4021 if Is_Inherently_Limited_Type (Typ) then
4022 Set_Returns_By_Ref (Designator);
4024 elsif Present (Utyp) and then CW_Or_Has_Controlled_Part (Utyp) then
4025 Set_Returns_By_Ref (Designator);
4029 end Check_Delayed_Subprogram;
4031 ------------------------------------
4032 -- Check_Discriminant_Conformance --
4033 ------------------------------------
4035 procedure Check_Discriminant_Conformance
4040 Old_Discr : Entity_Id := First_Discriminant (Prev);
4041 New_Discr : Node_Id := First (Discriminant_Specifications (N));
4042 New_Discr_Id : Entity_Id;
4043 New_Discr_Type : Entity_Id;
4045 procedure Conformance_Error (Msg : String; N : Node_Id);
4046 -- Post error message for conformance error on given node. Two messages
4047 -- are output. The first points to the previous declaration with a
4048 -- general "no conformance" message. The second is the detailed reason,
4049 -- supplied as Msg. The parameter N provide information for a possible
4050 -- & insertion in the message.
4052 -----------------------
4053 -- Conformance_Error --
4054 -----------------------
4056 procedure Conformance_Error (Msg : String; N : Node_Id) is
4058 Error_Msg_Sloc := Sloc (Prev_Loc);
4059 Error_Msg_N ("not fully conformant with declaration#!", N);
4060 Error_Msg_NE (Msg, N, N);
4061 end Conformance_Error;
4063 -- Start of processing for Check_Discriminant_Conformance
4066 while Present (Old_Discr) and then Present (New_Discr) loop
4068 New_Discr_Id := Defining_Identifier (New_Discr);
4070 -- The subtype mark of the discriminant on the full type has not
4071 -- been analyzed so we do it here. For an access discriminant a new
4074 if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then
4076 Access_Definition (N, Discriminant_Type (New_Discr));
4079 Analyze (Discriminant_Type (New_Discr));
4080 New_Discr_Type := Etype (Discriminant_Type (New_Discr));
4082 -- Ada 2005: if the discriminant definition carries a null
4083 -- exclusion, create an itype to check properly for consistency
4084 -- with partial declaration.
4086 if Is_Access_Type (New_Discr_Type)
4087 and then Null_Exclusion_Present (New_Discr)
4090 Create_Null_Excluding_Itype
4091 (T => New_Discr_Type,
4092 Related_Nod => New_Discr,
4093 Scope_Id => Current_Scope);
4097 if not Conforming_Types
4098 (Etype (Old_Discr), New_Discr_Type, Fully_Conformant)
4100 Conformance_Error ("type of & does not match!", New_Discr_Id);
4103 -- Treat the new discriminant as an occurrence of the old one,
4104 -- for navigation purposes, and fill in some semantic
4105 -- information, for completeness.
4107 Generate_Reference (Old_Discr, New_Discr_Id, 'r');
4108 Set_Etype (New_Discr_Id, Etype (Old_Discr));
4109 Set_Scope (New_Discr_Id, Scope (Old_Discr));
4114 if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then
4115 Conformance_Error ("name & does not match!", New_Discr_Id);
4119 -- Default expressions must match
4122 NewD : constant Boolean :=
4123 Present (Expression (New_Discr));
4124 OldD : constant Boolean :=
4125 Present (Expression (Parent (Old_Discr)));
4128 if NewD or OldD then
4130 -- The old default value has been analyzed and expanded,
4131 -- because the current full declaration will have frozen
4132 -- everything before. The new default values have not been
4133 -- expanded, so expand now to check conformance.
4136 Preanalyze_Spec_Expression
4137 (Expression (New_Discr), New_Discr_Type);
4140 if not (NewD and OldD)
4141 or else not Fully_Conformant_Expressions
4142 (Expression (Parent (Old_Discr)),
4143 Expression (New_Discr))
4147 ("default expression for & does not match!",
4154 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
4156 if Ada_Version = Ada_83 then
4158 Old_Disc : constant Node_Id := Declaration_Node (Old_Discr);
4161 -- Grouping (use of comma in param lists) must be the same
4162 -- This is where we catch a misconformance like:
4165 -- A : Integer; B : Integer
4167 -- which are represented identically in the tree except
4168 -- for the setting of the flags More_Ids and Prev_Ids.
4170 if More_Ids (Old_Disc) /= More_Ids (New_Discr)
4171 or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr)
4174 ("grouping of & does not match!", New_Discr_Id);
4180 Next_Discriminant (Old_Discr);
4184 if Present (Old_Discr) then
4185 Conformance_Error ("too few discriminants!", Defining_Identifier (N));
4188 elsif Present (New_Discr) then
4190 ("too many discriminants!", Defining_Identifier (New_Discr));
4193 end Check_Discriminant_Conformance;
4195 ----------------------------
4196 -- Check_Fully_Conformant --
4197 ----------------------------
4199 procedure Check_Fully_Conformant
4200 (New_Id : Entity_Id;
4202 Err_Loc : Node_Id := Empty)
4205 pragma Warnings (Off, Result);
4208 (New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc);
4209 end Check_Fully_Conformant;
4211 ---------------------------
4212 -- Check_Mode_Conformant --
4213 ---------------------------
4215 procedure Check_Mode_Conformant
4216 (New_Id : Entity_Id;
4218 Err_Loc : Node_Id := Empty;
4219 Get_Inst : Boolean := False)
4222 pragma Warnings (Off, Result);
4225 (New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst);
4226 end Check_Mode_Conformant;
4228 --------------------------------
4229 -- Check_Overriding_Indicator --
4230 --------------------------------
4232 procedure Check_Overriding_Indicator
4234 Overridden_Subp : Entity_Id;
4235 Is_Primitive : Boolean)
4241 -- No overriding indicator for literals
4243 if Ekind (Subp) = E_Enumeration_Literal then
4246 elsif Ekind (Subp) = E_Entry then
4247 Decl := Parent (Subp);
4250 Decl := Unit_Declaration_Node (Subp);
4253 if Nkind_In (Decl, N_Subprogram_Body,
4254 N_Subprogram_Body_Stub,
4255 N_Subprogram_Declaration,
4256 N_Abstract_Subprogram_Declaration,
4257 N_Subprogram_Renaming_Declaration)
4259 Spec := Specification (Decl);
4261 elsif Nkind (Decl) = N_Entry_Declaration then
4268 if Present (Overridden_Subp) then
4269 if Must_Not_Override (Spec) then
4270 Error_Msg_Sloc := Sloc (Overridden_Subp);
4272 if Ekind (Subp) = E_Entry then
4274 ("entry & overrides inherited operation #", Spec, Subp);
4277 ("subprogram & overrides inherited operation #", Spec, Subp);
4280 elsif Is_Subprogram (Subp) then
4281 Set_Is_Overriding_Operation (Subp);
4284 -- If primitive flag is set, operation is overriding at the
4285 -- point of its declaration, so warn if necessary. Otherwise
4286 -- it may have been declared before the operation it overrides
4287 -- and no check is required.
4290 and then not Must_Override (Spec)
4291 and then Is_Primitive
4293 Style.Missing_Overriding (Decl, Subp);
4296 -- If Subp is an operator, it may override a predefined operation.
4297 -- In that case overridden_subp is empty because of our implicit
4298 -- representation for predefined operators. We have to check whether the
4299 -- signature of Subp matches that of a predefined operator. Note that
4300 -- first argument provides the name of the operator, and the second
4301 -- argument the signature that may match that of a standard operation.
4302 -- If the indicator is overriding, then the operator must match a
4303 -- predefined signature, because we know already that there is no
4304 -- explicit overridden operation.
4306 elsif Nkind (Subp) = N_Defining_Operator_Symbol then
4308 if Must_Not_Override (Spec) then
4309 if not Is_Primitive then
4311 ("overriding indicator only allowed "
4312 & "if subprogram is primitive", Subp);
4314 elsif Operator_Matches_Spec (Subp, Subp) then
4316 ("subprogram & overrides predefined operator ", Spec, Subp);
4319 elsif Must_Override (Spec) then
4320 if Is_Overriding_Operation (Subp) then
4321 Set_Is_Overriding_Operation (Subp);
4323 elsif not Operator_Matches_Spec (Subp, Subp) then
4324 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
4327 elsif not Error_Posted (Subp)
4328 and then Style_Check
4329 and then Operator_Matches_Spec (Subp, Subp)
4331 not Is_Predefined_File_Name
4332 (Unit_File_Name (Get_Source_Unit (Subp)))
4334 Set_Is_Overriding_Operation (Subp);
4335 Style.Missing_Overriding (Decl, Subp);
4338 elsif Must_Override (Spec) then
4339 if Ekind (Subp) = E_Entry then
4340 Error_Msg_NE ("entry & is not overriding", Spec, Subp);
4342 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
4345 -- If the operation is marked "not overriding" and it's not primitive
4346 -- then an error is issued, unless this is an operation of a task or
4347 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
4348 -- has been specified have already been checked above.
4350 elsif Must_Not_Override (Spec)
4351 and then not Is_Primitive
4352 and then Ekind (Subp) /= E_Entry
4353 and then Ekind (Scope (Subp)) /= E_Protected_Type
4356 ("overriding indicator only allowed if subprogram is primitive",
4360 end Check_Overriding_Indicator;
4366 -- Note: this procedure needs to know far too much about how the expander
4367 -- messes with exceptions. The use of the flag Exception_Junk and the
4368 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
4369 -- works, but is not very clean. It would be better if the expansion
4370 -- routines would leave Original_Node working nicely, and we could use
4371 -- Original_Node here to ignore all the peculiar expander messing ???
4373 procedure Check_Returns
4377 Proc : Entity_Id := Empty)
4381 procedure Check_Statement_Sequence (L : List_Id);
4382 -- Internal recursive procedure to check a list of statements for proper
4383 -- termination by a return statement (or a transfer of control or a
4384 -- compound statement that is itself internally properly terminated).
4386 ------------------------------
4387 -- Check_Statement_Sequence --
4388 ------------------------------
4390 procedure Check_Statement_Sequence (L : List_Id) is
4395 Raise_Exception_Call : Boolean;
4396 -- Set True if statement sequence terminated by Raise_Exception call
4397 -- or a Reraise_Occurrence call.
4400 Raise_Exception_Call := False;
4402 -- Get last real statement
4404 Last_Stm := Last (L);
4406 -- Deal with digging out exception handler statement sequences that
4407 -- have been transformed by the local raise to goto optimization.
4408 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
4409 -- optimization has occurred, we are looking at something like:
4412 -- original stmts in block
4416 -- goto L1; | omitted if No_Exception_Propagation
4421 -- goto L3; -- skip handler when exception not raised
4423 -- <<L1>> -- target label for local exception
4437 -- and what we have to do is to dig out the estmts1 and estmts2
4438 -- sequences (which were the original sequences of statements in
4439 -- the exception handlers) and check them.
4441 if Nkind (Last_Stm) = N_Label
4442 and then Exception_Junk (Last_Stm)
4448 exit when Nkind (Stm) /= N_Block_Statement;
4449 exit when not Exception_Junk (Stm);
4452 exit when Nkind (Stm) /= N_Label;
4453 exit when not Exception_Junk (Stm);
4454 Check_Statement_Sequence
4455 (Statements (Handled_Statement_Sequence (Next (Stm))));
4460 exit when Nkind (Stm) /= N_Goto_Statement;
4461 exit when not Exception_Junk (Stm);
4465 -- Don't count pragmas
4467 while Nkind (Last_Stm) = N_Pragma
4469 -- Don't count call to SS_Release (can happen after Raise_Exception)
4472 (Nkind (Last_Stm) = N_Procedure_Call_Statement
4474 Nkind (Name (Last_Stm)) = N_Identifier
4476 Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release))
4478 -- Don't count exception junk
4481 (Nkind_In (Last_Stm, N_Goto_Statement,
4483 N_Object_Declaration)
4484 and then Exception_Junk (Last_Stm))
4485 or else Nkind (Last_Stm) in N_Push_xxx_Label
4486 or else Nkind (Last_Stm) in N_Pop_xxx_Label
4491 -- Here we have the "real" last statement
4493 Kind := Nkind (Last_Stm);
4495 -- Transfer of control, OK. Note that in the No_Return procedure
4496 -- case, we already diagnosed any explicit return statements, so
4497 -- we can treat them as OK in this context.
4499 if Is_Transfer (Last_Stm) then
4502 -- Check cases of explicit non-indirect procedure calls
4504 elsif Kind = N_Procedure_Call_Statement
4505 and then Is_Entity_Name (Name (Last_Stm))
4507 -- Check call to Raise_Exception procedure which is treated
4508 -- specially, as is a call to Reraise_Occurrence.
4510 -- We suppress the warning in these cases since it is likely that
4511 -- the programmer really does not expect to deal with the case
4512 -- of Null_Occurrence, and thus would find a warning about a
4513 -- missing return curious, and raising Program_Error does not
4514 -- seem such a bad behavior if this does occur.
4516 -- Note that in the Ada 2005 case for Raise_Exception, the actual
4517 -- behavior will be to raise Constraint_Error (see AI-329).
4519 if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception)
4521 Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence)
4523 Raise_Exception_Call := True;
4525 -- For Raise_Exception call, test first argument, if it is
4526 -- an attribute reference for a 'Identity call, then we know
4527 -- that the call cannot possibly return.
4530 Arg : constant Node_Id :=
4531 Original_Node (First_Actual (Last_Stm));
4533 if Nkind (Arg) = N_Attribute_Reference
4534 and then Attribute_Name (Arg) = Name_Identity
4541 -- If statement, need to look inside if there is an else and check
4542 -- each constituent statement sequence for proper termination.
4544 elsif Kind = N_If_Statement
4545 and then Present (Else_Statements (Last_Stm))
4547 Check_Statement_Sequence (Then_Statements (Last_Stm));
4548 Check_Statement_Sequence (Else_Statements (Last_Stm));
4550 if Present (Elsif_Parts (Last_Stm)) then
4552 Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm));
4555 while Present (Elsif_Part) loop
4556 Check_Statement_Sequence (Then_Statements (Elsif_Part));
4564 -- Case statement, check each case for proper termination
4566 elsif Kind = N_Case_Statement then
4570 Case_Alt := First_Non_Pragma (Alternatives (Last_Stm));
4571 while Present (Case_Alt) loop
4572 Check_Statement_Sequence (Statements (Case_Alt));
4573 Next_Non_Pragma (Case_Alt);
4579 -- Block statement, check its handled sequence of statements
4581 elsif Kind = N_Block_Statement then
4587 (Handled_Statement_Sequence (Last_Stm), Mode, Err1);
4596 -- Loop statement. If there is an iteration scheme, we can definitely
4597 -- fall out of the loop. Similarly if there is an exit statement, we
4598 -- can fall out. In either case we need a following return.
4600 elsif Kind = N_Loop_Statement then
4601 if Present (Iteration_Scheme (Last_Stm))
4602 or else Has_Exit (Entity (Identifier (Last_Stm)))
4606 -- A loop with no exit statement or iteration scheme is either
4607 -- an infinite loop, or it has some other exit (raise/return).
4608 -- In either case, no warning is required.
4614 -- Timed entry call, check entry call and delay alternatives
4616 -- Note: in expanded code, the timed entry call has been converted
4617 -- to a set of expanded statements on which the check will work
4618 -- correctly in any case.
4620 elsif Kind = N_Timed_Entry_Call then
4622 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
4623 DCA : constant Node_Id := Delay_Alternative (Last_Stm);
4626 -- If statement sequence of entry call alternative is missing,
4627 -- then we can definitely fall through, and we post the error
4628 -- message on the entry call alternative itself.
4630 if No (Statements (ECA)) then
4633 -- If statement sequence of delay alternative is missing, then
4634 -- we can definitely fall through, and we post the error
4635 -- message on the delay alternative itself.
4637 -- Note: if both ECA and DCA are missing the return, then we
4638 -- post only one message, should be enough to fix the bugs.
4639 -- If not we will get a message next time on the DCA when the
4642 elsif No (Statements (DCA)) then
4645 -- Else check both statement sequences
4648 Check_Statement_Sequence (Statements (ECA));
4649 Check_Statement_Sequence (Statements (DCA));
4654 -- Conditional entry call, check entry call and else part
4656 -- Note: in expanded code, the conditional entry call has been
4657 -- converted to a set of expanded statements on which the check
4658 -- will work correctly in any case.
4660 elsif Kind = N_Conditional_Entry_Call then
4662 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
4665 -- If statement sequence of entry call alternative is missing,
4666 -- then we can definitely fall through, and we post the error
4667 -- message on the entry call alternative itself.
4669 if No (Statements (ECA)) then
4672 -- Else check statement sequence and else part
4675 Check_Statement_Sequence (Statements (ECA));
4676 Check_Statement_Sequence (Else_Statements (Last_Stm));
4682 -- If we fall through, issue appropriate message
4685 if not Raise_Exception_Call then
4687 ("?RETURN statement missing following this statement!",
4690 ("\?Program_Error may be raised at run time!",
4694 -- Note: we set Err even though we have not issued a warning
4695 -- because we still have a case of a missing return. This is
4696 -- an extremely marginal case, probably will never be noticed
4697 -- but we might as well get it right.
4701 -- Otherwise we have the case of a procedure marked No_Return
4704 if not Raise_Exception_Call then
4706 ("?implied return after this statement " &
4707 "will raise Program_Error",
4710 ("\?procedure & is marked as No_Return!",
4715 RE : constant Node_Id :=
4716 Make_Raise_Program_Error (Sloc (Last_Stm),
4717 Reason => PE_Implicit_Return);
4719 Insert_After (Last_Stm, RE);
4723 end Check_Statement_Sequence;
4725 -- Start of processing for Check_Returns
4729 Check_Statement_Sequence (Statements (HSS));
4731 if Present (Exception_Handlers (HSS)) then
4732 Handler := First_Non_Pragma (Exception_Handlers (HSS));
4733 while Present (Handler) loop
4734 Check_Statement_Sequence (Statements (Handler));
4735 Next_Non_Pragma (Handler);
4740 ----------------------------
4741 -- Check_Subprogram_Order --
4742 ----------------------------
4744 procedure Check_Subprogram_Order (N : Node_Id) is
4746 function Subprogram_Name_Greater (S1, S2 : String) return Boolean;
4747 -- This is used to check if S1 > S2 in the sense required by this
4748 -- test, for example nameab < namec, but name2 < name10.
4750 -----------------------------
4751 -- Subprogram_Name_Greater --
4752 -----------------------------
4754 function Subprogram_Name_Greater (S1, S2 : String) return Boolean is
4759 -- Remove trailing numeric parts
4762 while S1 (L1) in '0' .. '9' loop
4767 while S2 (L2) in '0' .. '9' loop
4771 -- If non-numeric parts non-equal, that's decisive
4773 if S1 (S1'First .. L1) < S2 (S2'First .. L2) then
4776 elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then
4779 -- If non-numeric parts equal, compare suffixed numeric parts. Note
4780 -- that a missing suffix is treated as numeric zero in this test.
4784 while L1 < S1'Last loop
4786 N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0');
4790 while L2 < S2'Last loop
4792 N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0');
4797 end Subprogram_Name_Greater;
4799 -- Start of processing for Check_Subprogram_Order
4802 -- Check body in alpha order if this is option
4805 and then Style_Check_Order_Subprograms
4806 and then Nkind (N) = N_Subprogram_Body
4807 and then Comes_From_Source (N)
4808 and then In_Extended_Main_Source_Unit (N)
4812 renames Scope_Stack.Table
4813 (Scope_Stack.Last).Last_Subprogram_Name;
4815 Body_Id : constant Entity_Id :=
4816 Defining_Entity (Specification (N));
4819 Get_Decoded_Name_String (Chars (Body_Id));
4822 if Subprogram_Name_Greater
4823 (LSN.all, Name_Buffer (1 .. Name_Len))
4825 Style.Subprogram_Not_In_Alpha_Order (Body_Id);
4831 LSN := new String'(Name_Buffer (1 .. Name_Len));
4834 end Check_Subprogram_Order;
4836 ------------------------------
4837 -- Check_Subtype_Conformant --
4838 ------------------------------
4840 procedure Check_Subtype_Conformant
4841 (New_Id : Entity_Id;
4843 Err_Loc : Node_Id := Empty;
4844 Skip_Controlling_Formals : Boolean := False)
4847 pragma Warnings (Off, Result);
4850 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
4851 Skip_Controlling_Formals => Skip_Controlling_Formals);
4852 end Check_Subtype_Conformant;
4854 ---------------------------
4855 -- Check_Type_Conformant --
4856 ---------------------------
4858 procedure Check_Type_Conformant
4859 (New_Id : Entity_Id;
4861 Err_Loc : Node_Id := Empty)
4864 pragma Warnings (Off, Result);
4867 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
4868 end Check_Type_Conformant;
4870 ----------------------
4871 -- Conforming_Types --
4872 ----------------------
4874 function Conforming_Types
4877 Ctype : Conformance_Type;
4878 Get_Inst : Boolean := False) return Boolean
4880 Type_1 : Entity_Id := T1;
4881 Type_2 : Entity_Id := T2;
4882 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
4884 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
4885 -- If neither T1 nor T2 are generic actual types, or if they are in
4886 -- different scopes (e.g. parent and child instances), then verify that
4887 -- the base types are equal. Otherwise T1 and T2 must be on the same
4888 -- subtype chain. The whole purpose of this procedure is to prevent
4889 -- spurious ambiguities in an instantiation that may arise if two
4890 -- distinct generic types are instantiated with the same actual.
4892 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
4893 -- An access parameter can designate an incomplete type. If the
4894 -- incomplete type is the limited view of a type from a limited_
4895 -- with_clause, check whether the non-limited view is available. If
4896 -- it is a (non-limited) incomplete type, get the full view.
4898 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
4899 -- Returns True if and only if either T1 denotes a limited view of T2
4900 -- or T2 denotes a limited view of T1. This can arise when the limited
4901 -- with view of a type is used in a subprogram declaration and the
4902 -- subprogram body is in the scope of a regular with clause for the
4903 -- same unit. In such a case, the two type entities can be considered
4904 -- identical for purposes of conformance checking.
4906 ----------------------
4907 -- Base_Types_Match --
4908 ----------------------
4910 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
4915 elsif Base_Type (T1) = Base_Type (T2) then
4917 -- The following is too permissive. A more precise test should
4918 -- check that the generic actual is an ancestor subtype of the
4921 return not Is_Generic_Actual_Type (T1)
4922 or else not Is_Generic_Actual_Type (T2)
4923 or else Scope (T1) /= Scope (T2);
4928 end Base_Types_Match;
4930 --------------------------
4931 -- Find_Designated_Type --
4932 --------------------------
4934 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
4938 Desig := Directly_Designated_Type (T);
4940 if Ekind (Desig) = E_Incomplete_Type then
4942 -- If regular incomplete type, get full view if available
4944 if Present (Full_View (Desig)) then
4945 Desig := Full_View (Desig);
4947 -- If limited view of a type, get non-limited view if available,
4948 -- and check again for a regular incomplete type.
4950 elsif Present (Non_Limited_View (Desig)) then
4951 Desig := Get_Full_View (Non_Limited_View (Desig));
4956 end Find_Designated_Type;
4958 -------------------------------
4959 -- Matches_Limited_With_View --
4960 -------------------------------
4962 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
4964 -- In some cases a type imported through a limited_with clause, and
4965 -- its nonlimited view are both visible, for example in an anonymous
4966 -- access-to-class-wide type in a formal. Both entities designate the
4969 if From_With_Type (T1)
4970 and then T2 = Available_View (T1)
4974 elsif From_With_Type (T2)
4975 and then T1 = Available_View (T2)
4982 end Matches_Limited_With_View;
4984 -- Start of processing for Conforming_Types
4987 -- The context is an instance association for a formal
4988 -- access-to-subprogram type; the formal parameter types require
4989 -- mapping because they may denote other formal parameters of the
4993 Type_1 := Get_Instance_Of (T1);
4994 Type_2 := Get_Instance_Of (T2);
4997 -- If one of the types is a view of the other introduced by a limited
4998 -- with clause, treat these as conforming for all purposes.
5000 if Matches_Limited_With_View (T1, T2) then
5003 elsif Base_Types_Match (Type_1, Type_2) then
5004 return Ctype <= Mode_Conformant
5005 or else Subtypes_Statically_Match (Type_1, Type_2);
5007 elsif Is_Incomplete_Or_Private_Type (Type_1)
5008 and then Present (Full_View (Type_1))
5009 and then Base_Types_Match (Full_View (Type_1), Type_2)
5011 return Ctype <= Mode_Conformant
5012 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
5014 elsif Ekind (Type_2) = E_Incomplete_Type
5015 and then Present (Full_View (Type_2))
5016 and then Base_Types_Match (Type_1, Full_View (Type_2))
5018 return Ctype <= Mode_Conformant
5019 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
5021 elsif Is_Private_Type (Type_2)
5022 and then In_Instance
5023 and then Present (Full_View (Type_2))
5024 and then Base_Types_Match (Type_1, Full_View (Type_2))
5026 return Ctype <= Mode_Conformant
5027 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
5030 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
5031 -- treated recursively because they carry a signature.
5033 Are_Anonymous_Access_To_Subprogram_Types :=
5034 Ekind (Type_1) = Ekind (Type_2)
5036 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
5038 Ekind (Type_1) = E_Anonymous_Access_Protected_Subprogram_Type);
5040 -- Test anonymous access type case. For this case, static subtype
5041 -- matching is required for mode conformance (RM 6.3.1(15)). We check
5042 -- the base types because we may have built internal subtype entities
5043 -- to handle null-excluding types (see Process_Formals).
5045 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
5047 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
5048 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
5051 Desig_1 : Entity_Id;
5052 Desig_2 : Entity_Id;
5055 -- In Ada2005, access constant indicators must match for
5056 -- subtype conformance.
5058 if Ada_Version >= Ada_05
5059 and then Ctype >= Subtype_Conformant
5061 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
5066 Desig_1 := Find_Designated_Type (Type_1);
5068 Desig_2 := Find_Designated_Type (Type_2);
5070 -- If the context is an instance association for a formal
5071 -- access-to-subprogram type; formal access parameter designated
5072 -- types require mapping because they may denote other formal
5073 -- parameters of the generic unit.
5076 Desig_1 := Get_Instance_Of (Desig_1);
5077 Desig_2 := Get_Instance_Of (Desig_2);
5080 -- It is possible for a Class_Wide_Type to be introduced for an
5081 -- incomplete type, in which case there is a separate class_ wide
5082 -- type for the full view. The types conform if their Etypes
5083 -- conform, i.e. one may be the full view of the other. This can
5084 -- only happen in the context of an access parameter, other uses
5085 -- of an incomplete Class_Wide_Type are illegal.
5087 if Is_Class_Wide_Type (Desig_1)
5088 and then Is_Class_Wide_Type (Desig_2)
5092 (Etype (Base_Type (Desig_1)),
5093 Etype (Base_Type (Desig_2)), Ctype);
5095 elsif Are_Anonymous_Access_To_Subprogram_Types then
5096 if Ada_Version < Ada_05 then
5097 return Ctype = Type_Conformant
5099 Subtypes_Statically_Match (Desig_1, Desig_2);
5101 -- We must check the conformance of the signatures themselves
5105 Conformant : Boolean;
5108 (Desig_1, Desig_2, Ctype, False, Conformant);
5114 return Base_Type (Desig_1) = Base_Type (Desig_2)
5115 and then (Ctype = Type_Conformant
5117 Subtypes_Statically_Match (Desig_1, Desig_2));
5121 -- Otherwise definitely no match
5124 if ((Ekind (Type_1) = E_Anonymous_Access_Type
5125 and then Is_Access_Type (Type_2))
5126 or else (Ekind (Type_2) = E_Anonymous_Access_Type
5127 and then Is_Access_Type (Type_1)))
5130 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
5132 May_Hide_Profile := True;
5137 end Conforming_Types;
5139 --------------------------
5140 -- Create_Extra_Formals --
5141 --------------------------
5143 procedure Create_Extra_Formals (E : Entity_Id) is
5145 First_Extra : Entity_Id := Empty;
5146 Last_Extra : Entity_Id;
5147 Formal_Type : Entity_Id;
5148 P_Formal : Entity_Id := Empty;
5150 function Add_Extra_Formal
5151 (Assoc_Entity : Entity_Id;
5154 Suffix : String) return Entity_Id;
5155 -- Add an extra formal to the current list of formals and extra formals.
5156 -- The extra formal is added to the end of the list of extra formals,
5157 -- and also returned as the result. These formals are always of mode IN.
5158 -- The new formal has the type Typ, is declared in Scope, and its name
5159 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
5161 ----------------------
5162 -- Add_Extra_Formal --
5163 ----------------------
5165 function Add_Extra_Formal
5166 (Assoc_Entity : Entity_Id;
5169 Suffix : String) return Entity_Id
5171 EF : constant Entity_Id :=
5172 Make_Defining_Identifier (Sloc (Assoc_Entity),
5173 Chars => New_External_Name (Chars (Assoc_Entity),
5177 -- A little optimization. Never generate an extra formal for the
5178 -- _init operand of an initialization procedure, since it could
5181 if Chars (Formal) = Name_uInit then
5185 Set_Ekind (EF, E_In_Parameter);
5186 Set_Actual_Subtype (EF, Typ);
5187 Set_Etype (EF, Typ);
5188 Set_Scope (EF, Scope);
5189 Set_Mechanism (EF, Default_Mechanism);
5190 Set_Formal_Validity (EF);
5192 if No (First_Extra) then
5194 Set_Extra_Formals (Scope, First_Extra);
5197 if Present (Last_Extra) then
5198 Set_Extra_Formal (Last_Extra, EF);
5204 end Add_Extra_Formal;
5206 -- Start of processing for Create_Extra_Formals
5209 -- We never generate extra formals if expansion is not active
5210 -- because we don't need them unless we are generating code.
5212 if not Expander_Active then
5216 -- If this is a derived subprogram then the subtypes of the parent
5217 -- subprogram's formal parameters will be used to determine the need
5218 -- for extra formals.
5220 if Is_Overloadable (E) and then Present (Alias (E)) then
5221 P_Formal := First_Formal (Alias (E));
5224 Last_Extra := Empty;
5225 Formal := First_Formal (E);
5226 while Present (Formal) loop
5227 Last_Extra := Formal;
5228 Next_Formal (Formal);
5231 -- If Extra_formals were already created, don't do it again. This
5232 -- situation may arise for subprogram types created as part of
5233 -- dispatching calls (see Expand_Dispatching_Call)
5235 if Present (Last_Extra) and then
5236 Present (Extra_Formal (Last_Extra))
5241 -- If the subprogram is a predefined dispatching subprogram then don't
5242 -- generate any extra constrained or accessibility level formals. In
5243 -- general we suppress these for internal subprograms (by not calling
5244 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
5245 -- generated stream attributes do get passed through because extra
5246 -- build-in-place formals are needed in some cases (limited 'Input).
5248 if Is_Predefined_Dispatching_Operation (E) then
5249 goto Test_For_BIP_Extras;
5252 Formal := First_Formal (E);
5253 while Present (Formal) loop
5255 -- Create extra formal for supporting the attribute 'Constrained.
5256 -- The case of a private type view without discriminants also
5257 -- requires the extra formal if the underlying type has defaulted
5260 if Ekind (Formal) /= E_In_Parameter then
5261 if Present (P_Formal) then
5262 Formal_Type := Etype (P_Formal);
5264 Formal_Type := Etype (Formal);
5267 -- Do not produce extra formals for Unchecked_Union parameters.
5268 -- Jump directly to the end of the loop.
5270 if Is_Unchecked_Union (Base_Type (Formal_Type)) then
5271 goto Skip_Extra_Formal_Generation;
5274 if not Has_Discriminants (Formal_Type)
5275 and then Ekind (Formal_Type) in Private_Kind
5276 and then Present (Underlying_Type (Formal_Type))
5278 Formal_Type := Underlying_Type (Formal_Type);
5281 if Has_Discriminants (Formal_Type)
5282 and then not Is_Constrained (Formal_Type)
5283 and then not Is_Indefinite_Subtype (Formal_Type)
5285 Set_Extra_Constrained
5286 (Formal, Add_Extra_Formal (Formal, Standard_Boolean, E, "F"));
5290 -- Create extra formal for supporting accessibility checking. This
5291 -- is done for both anonymous access formals and formals of named
5292 -- access types that are marked as controlling formals. The latter
5293 -- case can occur when Expand_Dispatching_Call creates a subprogram
5294 -- type and substitutes the types of access-to-class-wide actuals
5295 -- for the anonymous access-to-specific-type of controlling formals.
5296 -- Base_Type is applied because in cases where there is a null
5297 -- exclusion the formal may have an access subtype.
5299 -- This is suppressed if we specifically suppress accessibility
5300 -- checks at the package level for either the subprogram, or the
5301 -- package in which it resides. However, we do not suppress it
5302 -- simply if the scope has accessibility checks suppressed, since
5303 -- this could cause trouble when clients are compiled with a
5304 -- different suppression setting. The explicit checks at the
5305 -- package level are safe from this point of view.
5307 if (Ekind (Base_Type (Etype (Formal))) = E_Anonymous_Access_Type
5308 or else (Is_Controlling_Formal (Formal)
5309 and then Is_Access_Type (Base_Type (Etype (Formal)))))
5311 (Explicit_Suppress (E, Accessibility_Check)
5313 Explicit_Suppress (Scope (E), Accessibility_Check))
5316 or else Present (Extra_Accessibility (P_Formal)))
5318 -- Temporary kludge: for now we avoid creating the extra formal
5319 -- for access parameters of protected operations because of
5320 -- problem with the case of internal protected calls. ???
5322 if Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Definition
5323 and then Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Body
5325 Set_Extra_Accessibility
5326 (Formal, Add_Extra_Formal (Formal, Standard_Natural, E, "F"));
5330 -- This label is required when skipping extra formal generation for
5331 -- Unchecked_Union parameters.
5333 <<Skip_Extra_Formal_Generation>>
5335 if Present (P_Formal) then
5336 Next_Formal (P_Formal);
5339 Next_Formal (Formal);
5342 <<Test_For_BIP_Extras>>
5344 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
5345 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
5347 if Ada_Version >= Ada_05 and then Is_Build_In_Place_Function (E) then
5349 Result_Subt : constant Entity_Id := Etype (E);
5351 Discard : Entity_Id;
5352 pragma Warnings (Off, Discard);
5355 -- In the case of functions with unconstrained result subtypes,
5356 -- add a 3-state formal indicating whether the return object is
5357 -- allocated by the caller (0), or should be allocated by the
5358 -- callee on the secondary stack (1) or in the global heap (2).
5359 -- For the moment we just use Natural for the type of this formal.
5360 -- Note that this formal isn't usually needed in the case where
5361 -- the result subtype is constrained, but it is needed when the
5362 -- function has a tagged result, because generally such functions
5363 -- can be called in a dispatching context and such calls must be
5364 -- handled like calls to a class-wide function.
5366 if not Is_Constrained (Underlying_Type (Result_Subt))
5367 or else Is_Tagged_Type (Underlying_Type (Result_Subt))
5371 (E, Standard_Natural,
5372 E, BIP_Formal_Suffix (BIP_Alloc_Form));
5375 -- In the case of functions whose result type has controlled
5376 -- parts, we have an extra formal of type
5377 -- System.Finalization_Implementation.Finalizable_Ptr_Ptr. That
5378 -- is, we are passing a pointer to a finalization list (which is
5379 -- itself a pointer). This extra formal is then passed along to
5380 -- Move_Final_List in case of successful completion of a return
5381 -- statement. We cannot pass an 'in out' parameter, because we
5382 -- need to update the finalization list during an abort-deferred
5383 -- region, rather than using copy-back after the function
5384 -- returns. This is true even if we are able to get away with
5385 -- having 'in out' parameters, which are normally illegal for
5386 -- functions. This formal is also needed when the function has
5389 if Needs_BIP_Final_List (E) then
5392 (E, RTE (RE_Finalizable_Ptr_Ptr),
5393 E, BIP_Formal_Suffix (BIP_Final_List));
5396 -- If the result type contains tasks, we have two extra formals:
5397 -- the master of the tasks to be created, and the caller's
5398 -- activation chain.
5400 if Has_Task (Result_Subt) then
5403 (E, RTE (RE_Master_Id),
5404 E, BIP_Formal_Suffix (BIP_Master));
5407 (E, RTE (RE_Activation_Chain_Access),
5408 E, BIP_Formal_Suffix (BIP_Activation_Chain));
5411 -- All build-in-place functions get an extra formal that will be
5412 -- passed the address of the return object within the caller.
5415 Formal_Type : constant Entity_Id :=
5417 (E_Anonymous_Access_Type, E,
5418 Scope_Id => Scope (E));
5420 Set_Directly_Designated_Type (Formal_Type, Result_Subt);
5421 Set_Etype (Formal_Type, Formal_Type);
5422 Set_Depends_On_Private
5423 (Formal_Type, Has_Private_Component (Formal_Type));
5424 Set_Is_Public (Formal_Type, Is_Public (Scope (Formal_Type)));
5425 Set_Is_Access_Constant (Formal_Type, False);
5427 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
5428 -- the designated type comes from the limited view (for
5429 -- back-end purposes).
5431 Set_From_With_Type (Formal_Type, From_With_Type (Result_Subt));
5433 Layout_Type (Formal_Type);
5437 (E, Formal_Type, E, BIP_Formal_Suffix (BIP_Object_Access));
5441 end Create_Extra_Formals;
5443 -----------------------------
5444 -- Enter_Overloaded_Entity --
5445 -----------------------------
5447 procedure Enter_Overloaded_Entity (S : Entity_Id) is
5448 E : Entity_Id := Current_Entity_In_Scope (S);
5449 C_E : Entity_Id := Current_Entity (S);
5453 Set_Has_Homonym (E);
5454 Set_Has_Homonym (S);
5457 Set_Is_Immediately_Visible (S);
5458 Set_Scope (S, Current_Scope);
5460 -- Chain new entity if front of homonym in current scope, so that
5461 -- homonyms are contiguous.
5466 while Homonym (C_E) /= E loop
5467 C_E := Homonym (C_E);
5470 Set_Homonym (C_E, S);
5474 Set_Current_Entity (S);
5479 Append_Entity (S, Current_Scope);
5480 Set_Public_Status (S);
5482 if Debug_Flag_E then
5483 Write_Str ("New overloaded entity chain: ");
5484 Write_Name (Chars (S));
5487 while Present (E) loop
5488 Write_Str (" "); Write_Int (Int (E));
5495 -- Generate warning for hiding
5498 and then Comes_From_Source (S)
5499 and then In_Extended_Main_Source_Unit (S)
5506 -- Warn unless genuine overloading
5508 if (not Is_Overloadable (E) or else Subtype_Conformant (E, S))
5509 and then (Is_Immediately_Visible (E)
5511 Is_Potentially_Use_Visible (S))
5513 Error_Msg_Sloc := Sloc (E);
5514 Error_Msg_N ("declaration of & hides one#?", S);
5518 end Enter_Overloaded_Entity;
5520 -----------------------------
5521 -- Find_Corresponding_Spec --
5522 -----------------------------
5524 function Find_Corresponding_Spec
5526 Post_Error : Boolean := True) return Entity_Id
5528 Spec : constant Node_Id := Specification (N);
5529 Designator : constant Entity_Id := Defining_Entity (Spec);
5534 E := Current_Entity (Designator);
5535 while Present (E) loop
5537 -- We are looking for a matching spec. It must have the same scope,
5538 -- and the same name, and either be type conformant, or be the case
5539 -- of a library procedure spec and its body (which belong to one
5540 -- another regardless of whether they are type conformant or not).
5542 if Scope (E) = Current_Scope then
5543 if Current_Scope = Standard_Standard
5544 or else (Ekind (E) = Ekind (Designator)
5545 and then Type_Conformant (E, Designator))
5547 -- Within an instantiation, we know that spec and body are
5548 -- subtype conformant, because they were subtype conformant
5549 -- in the generic. We choose the subtype-conformant entity
5550 -- here as well, to resolve spurious ambiguities in the
5551 -- instance that were not present in the generic (i.e. when
5552 -- two different types are given the same actual). If we are
5553 -- looking for a spec to match a body, full conformance is
5557 Set_Convention (Designator, Convention (E));
5559 if Nkind (N) = N_Subprogram_Body
5560 and then Present (Homonym (E))
5561 and then not Fully_Conformant (E, Designator)
5565 elsif not Subtype_Conformant (E, Designator) then
5570 if not Has_Completion (E) then
5571 if Nkind (N) /= N_Subprogram_Body_Stub then
5572 Set_Corresponding_Spec (N, E);
5575 Set_Has_Completion (E);
5578 elsif Nkind (Parent (N)) = N_Subunit then
5580 -- If this is the proper body of a subunit, the completion
5581 -- flag is set when analyzing the stub.
5585 -- If E is an internal function with a controlling result
5586 -- that was created for an operation inherited by a null
5587 -- extension, it may be overridden by a body without a previous
5588 -- spec (one more reason why these should be shunned). In that
5589 -- case remove the generated body, because the current one is
5590 -- the explicit overriding.
5592 elsif Ekind (E) = E_Function
5593 and then Ada_Version >= Ada_05
5594 and then not Comes_From_Source (E)
5595 and then Has_Controlling_Result (E)
5596 and then Is_Null_Extension (Etype (E))
5597 and then Comes_From_Source (Spec)
5599 Set_Has_Completion (E, False);
5601 if Expander_Active then
5603 (Unit_Declaration_Node
5604 (Corresponding_Body (Unit_Declaration_Node (E))));
5607 -- If expansion is disabled, the wrapper function has not
5608 -- been generated, and this is the standard case of a late
5609 -- body overriding an inherited operation.
5615 -- If the body already exists, then this is an error unless
5616 -- the previous declaration is the implicit declaration of a
5617 -- derived subprogram, or this is a spurious overloading in an
5620 elsif No (Alias (E))
5621 and then not Is_Intrinsic_Subprogram (E)
5622 and then not In_Instance
5625 Error_Msg_Sloc := Sloc (E);
5627 if Is_Imported (E) then
5629 ("body not allowed for imported subprogram & declared#",
5632 Error_Msg_NE ("duplicate body for & declared#", N, E);
5636 -- Child units cannot be overloaded, so a conformance mismatch
5637 -- between body and a previous spec is an error.
5639 elsif Is_Child_Unit (E)
5641 Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body
5643 Nkind (Parent (Unit_Declaration_Node (Designator))) =
5648 ("body of child unit does not match previous declaration", N);
5656 -- On exit, we know that no previous declaration of subprogram exists
5659 end Find_Corresponding_Spec;
5661 ----------------------
5662 -- Fully_Conformant --
5663 ----------------------
5665 function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
5668 Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result);
5670 end Fully_Conformant;
5672 ----------------------------------
5673 -- Fully_Conformant_Expressions --
5674 ----------------------------------
5676 function Fully_Conformant_Expressions
5677 (Given_E1 : Node_Id;
5678 Given_E2 : Node_Id) return Boolean
5680 E1 : constant Node_Id := Original_Node (Given_E1);
5681 E2 : constant Node_Id := Original_Node (Given_E2);
5682 -- We always test conformance on original nodes, since it is possible
5683 -- for analysis and/or expansion to make things look as though they
5684 -- conform when they do not, e.g. by converting 1+2 into 3.
5686 function FCE (Given_E1, Given_E2 : Node_Id) return Boolean
5687 renames Fully_Conformant_Expressions;
5689 function FCL (L1, L2 : List_Id) return Boolean;
5690 -- Compare elements of two lists for conformance. Elements have to
5691 -- be conformant, and actuals inserted as default parameters do not
5692 -- match explicit actuals with the same value.
5694 function FCO (Op_Node, Call_Node : Node_Id) return Boolean;
5695 -- Compare an operator node with a function call
5701 function FCL (L1, L2 : List_Id) return Boolean is
5705 if L1 = No_List then
5711 if L2 = No_List then
5717 -- Compare two lists, skipping rewrite insertions (we want to
5718 -- compare the original trees, not the expanded versions!)
5721 if Is_Rewrite_Insertion (N1) then
5723 elsif Is_Rewrite_Insertion (N2) then
5729 elsif not FCE (N1, N2) then
5742 function FCO (Op_Node, Call_Node : Node_Id) return Boolean is
5743 Actuals : constant List_Id := Parameter_Associations (Call_Node);
5748 or else Entity (Op_Node) /= Entity (Name (Call_Node))
5753 Act := First (Actuals);
5755 if Nkind (Op_Node) in N_Binary_Op then
5756 if not FCE (Left_Opnd (Op_Node), Act) then
5763 return Present (Act)
5764 and then FCE (Right_Opnd (Op_Node), Act)
5765 and then No (Next (Act));
5769 -- Start of processing for Fully_Conformant_Expressions
5772 -- Non-conformant if paren count does not match. Note: if some idiot
5773 -- complains that we don't do this right for more than 3 levels of
5774 -- parentheses, they will be treated with the respect they deserve!
5776 if Paren_Count (E1) /= Paren_Count (E2) then
5779 -- If same entities are referenced, then they are conformant even if
5780 -- they have different forms (RM 8.3.1(19-20)).
5782 elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then
5783 if Present (Entity (E1)) then
5784 return Entity (E1) = Entity (E2)
5785 or else (Chars (Entity (E1)) = Chars (Entity (E2))
5786 and then Ekind (Entity (E1)) = E_Discriminant
5787 and then Ekind (Entity (E2)) = E_In_Parameter);
5789 elsif Nkind (E1) = N_Expanded_Name
5790 and then Nkind (E2) = N_Expanded_Name
5791 and then Nkind (Selector_Name (E1)) = N_Character_Literal
5792 and then Nkind (Selector_Name (E2)) = N_Character_Literal
5794 return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2));
5797 -- Identifiers in component associations don't always have
5798 -- entities, but their names must conform.
5800 return Nkind (E1) = N_Identifier
5801 and then Nkind (E2) = N_Identifier
5802 and then Chars (E1) = Chars (E2);
5805 elsif Nkind (E1) = N_Character_Literal
5806 and then Nkind (E2) = N_Expanded_Name
5808 return Nkind (Selector_Name (E2)) = N_Character_Literal
5809 and then Chars (E1) = Chars (Selector_Name (E2));
5811 elsif Nkind (E2) = N_Character_Literal
5812 and then Nkind (E1) = N_Expanded_Name
5814 return Nkind (Selector_Name (E1)) = N_Character_Literal
5815 and then Chars (E2) = Chars (Selector_Name (E1));
5817 elsif Nkind (E1) in N_Op
5818 and then Nkind (E2) = N_Function_Call
5820 return FCO (E1, E2);
5822 elsif Nkind (E2) in N_Op
5823 and then Nkind (E1) = N_Function_Call
5825 return FCO (E2, E1);
5827 -- Otherwise we must have the same syntactic entity
5829 elsif Nkind (E1) /= Nkind (E2) then
5832 -- At this point, we specialize by node type
5839 FCL (Expressions (E1), Expressions (E2))
5840 and then FCL (Component_Associations (E1),
5841 Component_Associations (E2));
5844 if Nkind (Expression (E1)) = N_Qualified_Expression
5846 Nkind (Expression (E2)) = N_Qualified_Expression
5848 return FCE (Expression (E1), Expression (E2));
5850 -- Check that the subtype marks and any constraints
5855 Indic1 : constant Node_Id := Expression (E1);
5856 Indic2 : constant Node_Id := Expression (E2);
5861 if Nkind (Indic1) /= N_Subtype_Indication then
5863 Nkind (Indic2) /= N_Subtype_Indication
5864 and then Entity (Indic1) = Entity (Indic2);
5866 elsif Nkind (Indic2) /= N_Subtype_Indication then
5868 Nkind (Indic1) /= N_Subtype_Indication
5869 and then Entity (Indic1) = Entity (Indic2);
5872 if Entity (Subtype_Mark (Indic1)) /=
5873 Entity (Subtype_Mark (Indic2))
5878 Elt1 := First (Constraints (Constraint (Indic1)));
5879 Elt2 := First (Constraints (Constraint (Indic2)));
5880 while Present (Elt1) and then Present (Elt2) loop
5881 if not FCE (Elt1, Elt2) then
5894 when N_Attribute_Reference =>
5896 Attribute_Name (E1) = Attribute_Name (E2)
5897 and then FCL (Expressions (E1), Expressions (E2));
5901 Entity (E1) = Entity (E2)
5902 and then FCE (Left_Opnd (E1), Left_Opnd (E2))
5903 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
5905 when N_And_Then | N_Or_Else | N_Membership_Test =>
5907 FCE (Left_Opnd (E1), Left_Opnd (E2))
5909 FCE (Right_Opnd (E1), Right_Opnd (E2));
5911 when N_Character_Literal =>
5913 Char_Literal_Value (E1) = Char_Literal_Value (E2);
5915 when N_Component_Association =>
5917 FCL (Choices (E1), Choices (E2))
5918 and then FCE (Expression (E1), Expression (E2));
5920 when N_Conditional_Expression =>
5922 FCL (Expressions (E1), Expressions (E2));
5924 when N_Explicit_Dereference =>
5926 FCE (Prefix (E1), Prefix (E2));
5928 when N_Extension_Aggregate =>
5930 FCL (Expressions (E1), Expressions (E2))
5931 and then Null_Record_Present (E1) =
5932 Null_Record_Present (E2)
5933 and then FCL (Component_Associations (E1),
5934 Component_Associations (E2));
5936 when N_Function_Call =>
5938 FCE (Name (E1), Name (E2))
5939 and then FCL (Parameter_Associations (E1),
5940 Parameter_Associations (E2));
5942 when N_Indexed_Component =>
5944 FCE (Prefix (E1), Prefix (E2))
5945 and then FCL (Expressions (E1), Expressions (E2));
5947 when N_Integer_Literal =>
5948 return (Intval (E1) = Intval (E2));
5953 when N_Operator_Symbol =>
5955 Chars (E1) = Chars (E2);
5957 when N_Others_Choice =>
5960 when N_Parameter_Association =>
5962 Chars (Selector_Name (E1)) = Chars (Selector_Name (E2))
5963 and then FCE (Explicit_Actual_Parameter (E1),
5964 Explicit_Actual_Parameter (E2));
5966 when N_Qualified_Expression =>
5968 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
5969 and then FCE (Expression (E1), Expression (E2));
5973 FCE (Low_Bound (E1), Low_Bound (E2))
5974 and then FCE (High_Bound (E1), High_Bound (E2));
5976 when N_Real_Literal =>
5977 return (Realval (E1) = Realval (E2));
5979 when N_Selected_Component =>
5981 FCE (Prefix (E1), Prefix (E2))
5982 and then FCE (Selector_Name (E1), Selector_Name (E2));
5986 FCE (Prefix (E1), Prefix (E2))
5987 and then FCE (Discrete_Range (E1), Discrete_Range (E2));
5989 when N_String_Literal =>
5991 S1 : constant String_Id := Strval (E1);
5992 S2 : constant String_Id := Strval (E2);
5993 L1 : constant Nat := String_Length (S1);
5994 L2 : constant Nat := String_Length (S2);
6001 for J in 1 .. L1 loop
6002 if Get_String_Char (S1, J) /=
6003 Get_String_Char (S2, J)
6013 when N_Type_Conversion =>
6015 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
6016 and then FCE (Expression (E1), Expression (E2));
6020 Entity (E1) = Entity (E2)
6021 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
6023 when N_Unchecked_Type_Conversion =>
6025 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
6026 and then FCE (Expression (E1), Expression (E2));
6028 -- All other node types cannot appear in this context. Strictly
6029 -- we should raise a fatal internal error. Instead we just ignore
6030 -- the nodes. This means that if anyone makes a mistake in the
6031 -- expander and mucks an expression tree irretrievably, the
6032 -- result will be a failure to detect a (probably very obscure)
6033 -- case of non-conformance, which is better than bombing on some
6034 -- case where two expressions do in fact conform.
6041 end Fully_Conformant_Expressions;
6043 ----------------------------------------
6044 -- Fully_Conformant_Discrete_Subtypes --
6045 ----------------------------------------
6047 function Fully_Conformant_Discrete_Subtypes
6048 (Given_S1 : Node_Id;
6049 Given_S2 : Node_Id) return Boolean
6051 S1 : constant Node_Id := Original_Node (Given_S1);
6052 S2 : constant Node_Id := Original_Node (Given_S2);
6054 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean;
6055 -- Special-case for a bound given by a discriminant, which in the body
6056 -- is replaced with the discriminal of the enclosing type.
6058 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean;
6059 -- Check both bounds
6061 -----------------------
6062 -- Conforming_Bounds --
6063 -----------------------
6065 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is
6067 if Is_Entity_Name (B1)
6068 and then Is_Entity_Name (B2)
6069 and then Ekind (Entity (B1)) = E_Discriminant
6071 return Chars (B1) = Chars (B2);
6074 return Fully_Conformant_Expressions (B1, B2);
6076 end Conforming_Bounds;
6078 -----------------------
6079 -- Conforming_Ranges --
6080 -----------------------
6082 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is
6085 Conforming_Bounds (Low_Bound (R1), Low_Bound (R2))
6087 Conforming_Bounds (High_Bound (R1), High_Bound (R2));
6088 end Conforming_Ranges;
6090 -- Start of processing for Fully_Conformant_Discrete_Subtypes
6093 if Nkind (S1) /= Nkind (S2) then
6096 elsif Is_Entity_Name (S1) then
6097 return Entity (S1) = Entity (S2);
6099 elsif Nkind (S1) = N_Range then
6100 return Conforming_Ranges (S1, S2);
6102 elsif Nkind (S1) = N_Subtype_Indication then
6104 Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2))
6107 (Range_Expression (Constraint (S1)),
6108 Range_Expression (Constraint (S2)));
6112 end Fully_Conformant_Discrete_Subtypes;
6114 --------------------
6115 -- Install_Entity --
6116 --------------------
6118 procedure Install_Entity (E : Entity_Id) is
6119 Prev : constant Entity_Id := Current_Entity (E);
6121 Set_Is_Immediately_Visible (E);
6122 Set_Current_Entity (E);
6123 Set_Homonym (E, Prev);
6126 ---------------------
6127 -- Install_Formals --
6128 ---------------------
6130 procedure Install_Formals (Id : Entity_Id) is
6133 F := First_Formal (Id);
6134 while Present (F) loop
6138 end Install_Formals;
6140 -----------------------------
6141 -- Is_Interface_Conformant --
6142 -----------------------------
6144 function Is_Interface_Conformant
6145 (Tagged_Type : Entity_Id;
6146 Iface_Prim : Entity_Id;
6147 Prim : Entity_Id) return Boolean
6149 Iface : constant Entity_Id := Find_Dispatching_Type (Iface_Prim);
6150 Typ : constant Entity_Id := Find_Dispatching_Type (Prim);
6153 pragma Assert (Is_Subprogram (Iface_Prim)
6154 and then Is_Subprogram (Prim)
6155 and then Is_Dispatching_Operation (Iface_Prim)
6156 and then Is_Dispatching_Operation (Prim));
6158 pragma Assert (Is_Interface (Iface)
6159 or else (Present (Alias (Iface_Prim))
6162 (Find_Dispatching_Type (Ultimate_Alias (Iface_Prim)))));
6164 if Prim = Iface_Prim
6165 or else not Is_Subprogram (Prim)
6166 or else Ekind (Prim) /= Ekind (Iface_Prim)
6167 or else not Is_Dispatching_Operation (Prim)
6168 or else Scope (Prim) /= Scope (Tagged_Type)
6170 or else Base_Type (Typ) /= Tagged_Type
6171 or else not Primitive_Names_Match (Iface_Prim, Prim)
6175 -- Case of a procedure, or a function that does not have a controlling
6176 -- result (I or access I).
6178 elsif Ekind (Iface_Prim) = E_Procedure
6179 or else Etype (Prim) = Etype (Iface_Prim)
6180 or else not Has_Controlling_Result (Prim)
6182 return Type_Conformant (Prim, Iface_Prim,
6183 Skip_Controlling_Formals => True);
6185 -- Case of a function returning an interface, or an access to one.
6186 -- Check that the return types correspond.
6188 elsif Implements_Interface (Typ, Iface) then
6189 if (Ekind (Etype (Prim)) = E_Anonymous_Access_Type)
6191 (Ekind (Etype (Iface_Prim)) = E_Anonymous_Access_Type)
6196 Type_Conformant (Prim, Iface_Prim,
6197 Skip_Controlling_Formals => True);
6203 end Is_Interface_Conformant;
6205 ---------------------------------
6206 -- Is_Non_Overriding_Operation --
6207 ---------------------------------
6209 function Is_Non_Overriding_Operation
6210 (Prev_E : Entity_Id;
6211 New_E : Entity_Id) return Boolean
6215 G_Typ : Entity_Id := Empty;
6217 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id;
6218 -- If F_Type is a derived type associated with a generic actual subtype,
6219 -- then return its Generic_Parent_Type attribute, else return Empty.
6221 function Types_Correspond
6222 (P_Type : Entity_Id;
6223 N_Type : Entity_Id) return Boolean;
6224 -- Returns true if and only if the types (or designated types in the
6225 -- case of anonymous access types) are the same or N_Type is derived
6226 -- directly or indirectly from P_Type.
6228 -----------------------------
6229 -- Get_Generic_Parent_Type --
6230 -----------------------------
6232 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is
6237 if Is_Derived_Type (F_Typ)
6238 and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration
6240 -- The tree must be traversed to determine the parent subtype in
6241 -- the generic unit, which unfortunately isn't always available
6242 -- via semantic attributes. ??? (Note: The use of Original_Node
6243 -- is needed for cases where a full derived type has been
6246 Indic := Subtype_Indication
6247 (Type_Definition (Original_Node (Parent (F_Typ))));
6249 if Nkind (Indic) = N_Subtype_Indication then
6250 G_Typ := Entity (Subtype_Mark (Indic));
6252 G_Typ := Entity (Indic);
6255 if Nkind (Parent (G_Typ)) = N_Subtype_Declaration
6256 and then Present (Generic_Parent_Type (Parent (G_Typ)))
6258 return Generic_Parent_Type (Parent (G_Typ));
6263 end Get_Generic_Parent_Type;
6265 ----------------------
6266 -- Types_Correspond --
6267 ----------------------
6269 function Types_Correspond
6270 (P_Type : Entity_Id;
6271 N_Type : Entity_Id) return Boolean
6273 Prev_Type : Entity_Id := Base_Type (P_Type);
6274 New_Type : Entity_Id := Base_Type (N_Type);
6277 if Ekind (Prev_Type) = E_Anonymous_Access_Type then
6278 Prev_Type := Designated_Type (Prev_Type);
6281 if Ekind (New_Type) = E_Anonymous_Access_Type then
6282 New_Type := Designated_Type (New_Type);
6285 if Prev_Type = New_Type then
6288 elsif not Is_Class_Wide_Type (New_Type) then
6289 while Etype (New_Type) /= New_Type loop
6290 New_Type := Etype (New_Type);
6291 if New_Type = Prev_Type then
6297 end Types_Correspond;
6299 -- Start of processing for Is_Non_Overriding_Operation
6302 -- In the case where both operations are implicit derived subprograms
6303 -- then neither overrides the other. This can only occur in certain
6304 -- obscure cases (e.g., derivation from homographs created in a generic
6307 if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then
6310 elsif Ekind (Current_Scope) = E_Package
6311 and then Is_Generic_Instance (Current_Scope)
6312 and then In_Private_Part (Current_Scope)
6313 and then Comes_From_Source (New_E)
6315 -- We examine the formals and result subtype of the inherited
6316 -- operation, to determine whether their type is derived from (the
6317 -- instance of) a generic type.
6319 Formal := First_Formal (Prev_E);
6321 while Present (Formal) loop
6322 F_Typ := Base_Type (Etype (Formal));
6324 if Ekind (F_Typ) = E_Anonymous_Access_Type then
6325 F_Typ := Designated_Type (F_Typ);
6328 G_Typ := Get_Generic_Parent_Type (F_Typ);
6330 Next_Formal (Formal);
6333 if No (G_Typ) and then Ekind (Prev_E) = E_Function then
6334 G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E)));
6341 -- If the generic type is a private type, then the original operation
6342 -- was not overriding in the generic, because there was no primitive
6343 -- operation to override.
6345 if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration
6346 and then Nkind (Formal_Type_Definition (Parent (G_Typ))) =
6347 N_Formal_Private_Type_Definition
6351 -- The generic parent type is the ancestor of a formal derived
6352 -- type declaration. We need to check whether it has a primitive
6353 -- operation that should be overridden by New_E in the generic.
6357 P_Formal : Entity_Id;
6358 N_Formal : Entity_Id;
6362 Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ));
6365 while Present (Prim_Elt) loop
6366 P_Prim := Node (Prim_Elt);
6368 if Chars (P_Prim) = Chars (New_E)
6369 and then Ekind (P_Prim) = Ekind (New_E)
6371 P_Formal := First_Formal (P_Prim);
6372 N_Formal := First_Formal (New_E);
6373 while Present (P_Formal) and then Present (N_Formal) loop
6374 P_Typ := Etype (P_Formal);
6375 N_Typ := Etype (N_Formal);
6377 if not Types_Correspond (P_Typ, N_Typ) then
6381 Next_Entity (P_Formal);
6382 Next_Entity (N_Formal);
6385 -- Found a matching primitive operation belonging to the
6386 -- formal ancestor type, so the new subprogram is
6390 and then No (N_Formal)
6391 and then (Ekind (New_E) /= E_Function
6394 (Etype (P_Prim), Etype (New_E)))
6400 Next_Elmt (Prim_Elt);
6403 -- If no match found, then the new subprogram does not
6404 -- override in the generic (nor in the instance).
6412 end Is_Non_Overriding_Operation;
6414 ------------------------------
6415 -- Make_Inequality_Operator --
6416 ------------------------------
6418 -- S is the defining identifier of an equality operator. We build a
6419 -- subprogram declaration with the right signature. This operation is
6420 -- intrinsic, because it is always expanded as the negation of the
6421 -- call to the equality function.
6423 procedure Make_Inequality_Operator (S : Entity_Id) is
6424 Loc : constant Source_Ptr := Sloc (S);
6427 Op_Name : Entity_Id;
6429 FF : constant Entity_Id := First_Formal (S);
6430 NF : constant Entity_Id := Next_Formal (FF);
6433 -- Check that equality was properly defined, ignore call if not
6440 A : constant Entity_Id :=
6441 Make_Defining_Identifier (Sloc (FF),
6442 Chars => Chars (FF));
6444 B : constant Entity_Id :=
6445 Make_Defining_Identifier (Sloc (NF),
6446 Chars => Chars (NF));
6449 Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne);
6451 Formals := New_List (
6452 Make_Parameter_Specification (Loc,
6453 Defining_Identifier => A,
6455 New_Reference_To (Etype (First_Formal (S)),
6456 Sloc (Etype (First_Formal (S))))),
6458 Make_Parameter_Specification (Loc,
6459 Defining_Identifier => B,
6461 New_Reference_To (Etype (Next_Formal (First_Formal (S))),
6462 Sloc (Etype (Next_Formal (First_Formal (S)))))));
6465 Make_Subprogram_Declaration (Loc,
6467 Make_Function_Specification (Loc,
6468 Defining_Unit_Name => Op_Name,
6469 Parameter_Specifications => Formals,
6470 Result_Definition =>
6471 New_Reference_To (Standard_Boolean, Loc)));
6473 -- Insert inequality right after equality if it is explicit or after
6474 -- the derived type when implicit. These entities are created only
6475 -- for visibility purposes, and eventually replaced in the course of
6476 -- expansion, so they do not need to be attached to the tree and seen
6477 -- by the back-end. Keeping them internal also avoids spurious
6478 -- freezing problems. The declaration is inserted in the tree for
6479 -- analysis, and removed afterwards. If the equality operator comes
6480 -- from an explicit declaration, attach the inequality immediately
6481 -- after. Else the equality is inherited from a derived type
6482 -- declaration, so insert inequality after that declaration.
6484 if No (Alias (S)) then
6485 Insert_After (Unit_Declaration_Node (S), Decl);
6486 elsif Is_List_Member (Parent (S)) then
6487 Insert_After (Parent (S), Decl);
6489 Insert_After (Parent (Etype (First_Formal (S))), Decl);
6492 Mark_Rewrite_Insertion (Decl);
6493 Set_Is_Intrinsic_Subprogram (Op_Name);
6496 Set_Has_Completion (Op_Name);
6497 Set_Corresponding_Equality (Op_Name, S);
6498 Set_Is_Abstract_Subprogram (Op_Name, Is_Abstract_Subprogram (S));
6500 end Make_Inequality_Operator;
6502 ----------------------
6503 -- May_Need_Actuals --
6504 ----------------------
6506 procedure May_Need_Actuals (Fun : Entity_Id) is
6511 F := First_Formal (Fun);
6513 while Present (F) loop
6514 if No (Default_Value (F)) then
6522 Set_Needs_No_Actuals (Fun, B);
6523 end May_Need_Actuals;
6525 ---------------------
6526 -- Mode_Conformant --
6527 ---------------------
6529 function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
6532 Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result);
6534 end Mode_Conformant;
6536 ---------------------------
6537 -- New_Overloaded_Entity --
6538 ---------------------------
6540 procedure New_Overloaded_Entity
6542 Derived_Type : Entity_Id := Empty)
6544 Overridden_Subp : Entity_Id := Empty;
6545 -- Set if the current scope has an operation that is type-conformant
6546 -- with S, and becomes hidden by S.
6548 Is_Primitive_Subp : Boolean;
6549 -- Set to True if the new subprogram is primitive
6552 -- Entity that S overrides
6554 Prev_Vis : Entity_Id := Empty;
6555 -- Predecessor of E in Homonym chain
6557 procedure Check_For_Primitive_Subprogram
6558 (Is_Primitive : out Boolean;
6559 Is_Overriding : Boolean := False);
6560 -- If the subprogram being analyzed is a primitive operation of the type
6561 -- of a formal or result, set the Has_Primitive_Operations flag on the
6562 -- type, and set Is_Primitive to True (otherwise set to False). Set the
6563 -- corresponding flag on the entity itself for later use.
6565 procedure Check_Synchronized_Overriding
6566 (Def_Id : Entity_Id;
6567 Overridden_Subp : out Entity_Id);
6568 -- First determine if Def_Id is an entry or a subprogram either defined
6569 -- in the scope of a task or protected type, or is a primitive of such
6570 -- a type. Check whether Def_Id overrides a subprogram of an interface
6571 -- implemented by the synchronized type, return the overridden entity
6574 function Is_Private_Declaration (E : Entity_Id) return Boolean;
6575 -- Check that E is declared in the private part of the current package,
6576 -- or in the package body, where it may hide a previous declaration.
6577 -- We can't use In_Private_Part by itself because this flag is also
6578 -- set when freezing entities, so we must examine the place of the
6579 -- declaration in the tree, and recognize wrapper packages as well.
6581 function Is_Overriding_Alias
6583 New_E : Entity_Id) return Boolean;
6584 -- Check whether new subprogram and old subprogram are both inherited
6585 -- from subprograms that have distinct dispatch table entries. This can
6586 -- occur with derivations from instances with accidental homonyms.
6587 -- The function is conservative given that the converse is only true
6588 -- within instances that contain accidental overloadings.
6590 ------------------------------------
6591 -- Check_For_Primitive_Subprogram --
6592 ------------------------------------
6594 procedure Check_For_Primitive_Subprogram
6595 (Is_Primitive : out Boolean;
6596 Is_Overriding : Boolean := False)
6602 function Visible_Part_Type (T : Entity_Id) return Boolean;
6603 -- Returns true if T is declared in the visible part of the current
6604 -- package scope; otherwise returns false. Assumes that T is declared
6607 procedure Check_Private_Overriding (T : Entity_Id);
6608 -- Checks that if a primitive abstract subprogram of a visible
6609 -- abstract type is declared in a private part, then it must override
6610 -- an abstract subprogram declared in the visible part. Also checks
6611 -- that if a primitive function with a controlling result is declared
6612 -- in a private part, then it must override a function declared in
6613 -- the visible part.
6615 ------------------------------
6616 -- Check_Private_Overriding --
6617 ------------------------------
6619 procedure Check_Private_Overriding (T : Entity_Id) is
6621 if Is_Package_Or_Generic_Package (Current_Scope)
6622 and then In_Private_Part (Current_Scope)
6623 and then Visible_Part_Type (T)
6624 and then not In_Instance
6626 if Is_Abstract_Type (T)
6627 and then Is_Abstract_Subprogram (S)
6628 and then (not Is_Overriding
6629 or else not Is_Abstract_Subprogram (E))
6631 Error_Msg_N ("abstract subprograms must be visible "
6632 & "(RM 3.9.3(10))!", S);
6634 elsif Ekind (S) = E_Function
6635 and then Is_Tagged_Type (T)
6636 and then T = Base_Type (Etype (S))
6637 and then not Is_Overriding
6640 ("private function with tagged result must"
6641 & " override visible-part function", S);
6643 ("\move subprogram to the visible part"
6644 & " (RM 3.9.3(10))", S);
6647 end Check_Private_Overriding;
6649 -----------------------
6650 -- Visible_Part_Type --
6651 -----------------------
6653 function Visible_Part_Type (T : Entity_Id) return Boolean is
6654 P : constant Node_Id := Unit_Declaration_Node (Scope (T));
6658 -- If the entity is a private type, then it must be declared in a
6661 if Ekind (T) in Private_Kind then
6665 -- Otherwise, we traverse the visible part looking for its
6666 -- corresponding declaration. We cannot use the declaration
6667 -- node directly because in the private part the entity of a
6668 -- private type is the one in the full view, which does not
6669 -- indicate that it is the completion of something visible.
6671 N := First (Visible_Declarations (Specification (P)));
6672 while Present (N) loop
6673 if Nkind (N) = N_Full_Type_Declaration
6674 and then Present (Defining_Identifier (N))
6675 and then T = Defining_Identifier (N)
6679 elsif Nkind_In (N, N_Private_Type_Declaration,
6680 N_Private_Extension_Declaration)
6681 and then Present (Defining_Identifier (N))
6682 and then T = Full_View (Defining_Identifier (N))
6691 end Visible_Part_Type;
6693 -- Start of processing for Check_For_Primitive_Subprogram
6696 Is_Primitive := False;
6698 if not Comes_From_Source (S) then
6701 -- If subprogram is at library level, it is not primitive operation
6703 elsif Current_Scope = Standard_Standard then
6706 elsif (Is_Package_Or_Generic_Package (Current_Scope)
6707 and then not In_Package_Body (Current_Scope))
6708 or else Is_Overriding
6710 -- For function, check return type
6712 if Ekind (S) = E_Function then
6713 if Ekind (Etype (S)) = E_Anonymous_Access_Type then
6714 F_Typ := Designated_Type (Etype (S));
6719 B_Typ := Base_Type (F_Typ);
6721 if Scope (B_Typ) = Current_Scope
6722 and then not Is_Class_Wide_Type (B_Typ)
6723 and then not Is_Generic_Type (B_Typ)
6725 Is_Primitive := True;
6726 Set_Has_Primitive_Operations (B_Typ);
6727 Set_Is_Primitive (S);
6728 Check_Private_Overriding (B_Typ);
6732 -- For all subprograms, check formals
6734 Formal := First_Formal (S);
6735 while Present (Formal) loop
6736 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
6737 F_Typ := Designated_Type (Etype (Formal));
6739 F_Typ := Etype (Formal);
6742 B_Typ := Base_Type (F_Typ);
6744 if Ekind (B_Typ) = E_Access_Subtype then
6745 B_Typ := Base_Type (B_Typ);
6748 if Scope (B_Typ) = Current_Scope
6749 and then not Is_Class_Wide_Type (B_Typ)
6750 and then not Is_Generic_Type (B_Typ)
6752 Is_Primitive := True;
6753 Set_Is_Primitive (S);
6754 Set_Has_Primitive_Operations (B_Typ);
6755 Check_Private_Overriding (B_Typ);
6758 Next_Formal (Formal);
6761 end Check_For_Primitive_Subprogram;
6763 -----------------------------------
6764 -- Check_Synchronized_Overriding --
6765 -----------------------------------
6767 procedure Check_Synchronized_Overriding
6768 (Def_Id : Entity_Id;
6769 Overridden_Subp : out Entity_Id)
6771 Ifaces_List : Elist_Id;
6775 function Matches_Prefixed_View_Profile
6776 (Prim_Params : List_Id;
6777 Iface_Params : List_Id) return Boolean;
6778 -- Determine whether a subprogram's parameter profile Prim_Params
6779 -- matches that of a potentially overridden interface subprogram
6780 -- Iface_Params. Also determine if the type of first parameter of
6781 -- Iface_Params is an implemented interface.
6783 -----------------------------------
6784 -- Matches_Prefixed_View_Profile --
6785 -----------------------------------
6787 function Matches_Prefixed_View_Profile
6788 (Prim_Params : List_Id;
6789 Iface_Params : List_Id) return Boolean
6791 Iface_Id : Entity_Id;
6792 Iface_Param : Node_Id;
6793 Iface_Typ : Entity_Id;
6794 Prim_Id : Entity_Id;
6795 Prim_Param : Node_Id;
6796 Prim_Typ : Entity_Id;
6798 function Is_Implemented
6799 (Ifaces_List : Elist_Id;
6800 Iface : Entity_Id) return Boolean;
6801 -- Determine if Iface is implemented by the current task or
6804 --------------------
6805 -- Is_Implemented --
6806 --------------------
6808 function Is_Implemented
6809 (Ifaces_List : Elist_Id;
6810 Iface : Entity_Id) return Boolean
6812 Iface_Elmt : Elmt_Id;
6815 Iface_Elmt := First_Elmt (Ifaces_List);
6816 while Present (Iface_Elmt) loop
6817 if Node (Iface_Elmt) = Iface then
6821 Next_Elmt (Iface_Elmt);
6827 -- Start of processing for Matches_Prefixed_View_Profile
6830 Iface_Param := First (Iface_Params);
6831 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
6833 if Is_Access_Type (Iface_Typ) then
6834 Iface_Typ := Designated_Type (Iface_Typ);
6837 Prim_Param := First (Prim_Params);
6839 -- The first parameter of the potentially overridden subprogram
6840 -- must be an interface implemented by Prim.
6842 if not Is_Interface (Iface_Typ)
6843 or else not Is_Implemented (Ifaces_List, Iface_Typ)
6848 -- The checks on the object parameters are done, move onto the
6849 -- rest of the parameters.
6851 if not In_Scope then
6852 Prim_Param := Next (Prim_Param);
6855 Iface_Param := Next (Iface_Param);
6856 while Present (Iface_Param) and then Present (Prim_Param) loop
6857 Iface_Id := Defining_Identifier (Iface_Param);
6858 Iface_Typ := Find_Parameter_Type (Iface_Param);
6860 Prim_Id := Defining_Identifier (Prim_Param);
6861 Prim_Typ := Find_Parameter_Type (Prim_Param);
6863 if Ekind (Iface_Typ) = E_Anonymous_Access_Type
6864 and then Ekind (Prim_Typ) = E_Anonymous_Access_Type
6865 and then Is_Concurrent_Type (Designated_Type (Prim_Typ))
6867 Iface_Typ := Designated_Type (Iface_Typ);
6868 Prim_Typ := Designated_Type (Prim_Typ);
6871 -- Case of multiple interface types inside a parameter profile
6873 -- (Obj_Param : in out Iface; ...; Param : Iface)
6875 -- If the interface type is implemented, then the matching type
6876 -- in the primitive should be the implementing record type.
6878 if Ekind (Iface_Typ) = E_Record_Type
6879 and then Is_Interface (Iface_Typ)
6880 and then Is_Implemented (Ifaces_List, Iface_Typ)
6882 if Prim_Typ /= Typ then
6886 -- The two parameters must be both mode and subtype conformant
6888 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
6890 Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
6899 -- One of the two lists contains more parameters than the other
6901 if Present (Iface_Param) or else Present (Prim_Param) then
6906 end Matches_Prefixed_View_Profile;
6908 -- Start of processing for Check_Synchronized_Overriding
6911 Overridden_Subp := Empty;
6913 -- Def_Id must be an entry or a subprogram. We should skip predefined
6914 -- primitives internally generated by the frontend; however at this
6915 -- stage predefined primitives are still not fully decorated. As a
6916 -- minor optimization we skip here internally generated subprograms.
6918 if (Ekind (Def_Id) /= E_Entry
6919 and then Ekind (Def_Id) /= E_Function
6920 and then Ekind (Def_Id) /= E_Procedure)
6921 or else not Comes_From_Source (Def_Id)
6926 -- Search for the concurrent declaration since it contains the list
6927 -- of all implemented interfaces. In this case, the subprogram is
6928 -- declared within the scope of a protected or a task type.
6930 if Present (Scope (Def_Id))
6931 and then Is_Concurrent_Type (Scope (Def_Id))
6932 and then not Is_Generic_Actual_Type (Scope (Def_Id))
6934 Typ := Scope (Def_Id);
6937 -- The enclosing scope is not a synchronized type and the subprogram
6940 elsif No (First_Formal (Def_Id)) then
6943 -- The subprogram has formals and hence it may be a primitive of a
6947 Typ := Etype (First_Formal (Def_Id));
6949 if Is_Access_Type (Typ) then
6950 Typ := Directly_Designated_Type (Typ);
6953 if Is_Concurrent_Type (Typ)
6954 and then not Is_Generic_Actual_Type (Typ)
6958 -- This case occurs when the concurrent type is declared within
6959 -- a generic unit. As a result the corresponding record has been
6960 -- built and used as the type of the first formal, we just have
6961 -- to retrieve the corresponding concurrent type.
6963 elsif Is_Concurrent_Record_Type (Typ)
6964 and then Present (Corresponding_Concurrent_Type (Typ))
6966 Typ := Corresponding_Concurrent_Type (Typ);
6974 -- There is no overriding to check if is an inherited operation in a
6975 -- type derivation on for a generic actual.
6977 Collect_Interfaces (Typ, Ifaces_List);
6979 if Is_Empty_Elmt_List (Ifaces_List) then
6983 -- Determine whether entry or subprogram Def_Id overrides a primitive
6984 -- operation that belongs to one of the interfaces in Ifaces_List.
6987 Candidate : Entity_Id := Empty;
6988 Hom : Entity_Id := Empty;
6989 Iface_Typ : Entity_Id;
6990 Subp : Entity_Id := Empty;
6993 -- Traverse the homonym chain, looking at a potentially
6994 -- overridden subprogram that belongs to an implemented
6997 Hom := Current_Entity_In_Scope (Def_Id);
6998 while Present (Hom) loop
7002 or else not Is_Overloadable (Subp)
7003 or else not Is_Primitive (Subp)
7004 or else not Is_Dispatching_Operation (Subp)
7005 or else not Is_Interface (Find_Dispatching_Type (Subp))
7009 -- Entries and procedures can override abstract or null
7010 -- interface procedures
7012 elsif (Ekind (Def_Id) = E_Procedure
7013 or else Ekind (Def_Id) = E_Entry)
7014 and then Ekind (Subp) = E_Procedure
7015 and then Matches_Prefixed_View_Profile
7016 (Parameter_Specifications (Parent (Def_Id)),
7017 Parameter_Specifications (Parent (Subp)))
7021 -- For an overridden subprogram Subp, check whether the mode
7022 -- of its first parameter is correct depending on the kind
7023 -- of synchronized type.
7026 Formal : constant Node_Id := First_Formal (Candidate);
7029 -- In order for an entry or a protected procedure to
7030 -- override, the first parameter of the overridden
7031 -- routine must be of mode "out", "in out" or
7032 -- access-to-variable.
7034 if (Ekind (Candidate) = E_Entry
7035 or else Ekind (Candidate) = E_Procedure)
7036 and then Is_Protected_Type (Typ)
7037 and then Ekind (Formal) /= E_In_Out_Parameter
7038 and then Ekind (Formal) /= E_Out_Parameter
7039 and then Nkind (Parameter_Type (Parent (Formal)))
7040 /= N_Access_Definition
7044 -- All other cases are OK since a task entry or routine
7045 -- does not have a restriction on the mode of the first
7046 -- parameter of the overridden interface routine.
7049 Overridden_Subp := Candidate;
7054 -- Functions can override abstract interface functions
7056 elsif Ekind (Def_Id) = E_Function
7057 and then Ekind (Subp) = E_Function
7058 and then Matches_Prefixed_View_Profile
7059 (Parameter_Specifications (Parent (Def_Id)),
7060 Parameter_Specifications (Parent (Subp)))
7061 and then Etype (Result_Definition (Parent (Def_Id))) =
7062 Etype (Result_Definition (Parent (Subp)))
7064 Overridden_Subp := Subp;
7068 Hom := Homonym (Hom);
7071 -- After examining all candidates for overriding, we are
7072 -- left with the best match which is a mode incompatible
7073 -- interface routine. Do not emit an error if the Expander
7074 -- is active since this error will be detected later on
7075 -- after all concurrent types are expanded and all wrappers
7076 -- are built. This check is meant for spec-only
7079 if Present (Candidate)
7080 and then not Expander_Active
7083 Find_Parameter_Type (Parent (First_Formal (Candidate)));
7085 -- Def_Id is primitive of a protected type, declared
7086 -- inside the type, and the candidate is primitive of a
7087 -- limited or synchronized interface.
7090 and then Is_Protected_Type (Typ)
7092 (Is_Limited_Interface (Iface_Typ)
7093 or else Is_Protected_Interface (Iface_Typ)
7094 or else Is_Synchronized_Interface (Iface_Typ)
7095 or else Is_Task_Interface (Iface_Typ))
7097 -- Must reword this message, comma before to in -gnatj
7101 ("first formal of & must be of mode `OUT`, `IN OUT`"
7102 & " or access-to-variable", Typ, Candidate);
7104 ("\to be overridden by protected procedure or entry "
7105 & "(RM 9.4(11.9/2))", Typ);
7109 Overridden_Subp := Candidate;
7112 end Check_Synchronized_Overriding;
7114 ----------------------------
7115 -- Is_Private_Declaration --
7116 ----------------------------
7118 function Is_Private_Declaration (E : Entity_Id) return Boolean is
7119 Priv_Decls : List_Id;
7120 Decl : constant Node_Id := Unit_Declaration_Node (E);
7123 if Is_Package_Or_Generic_Package (Current_Scope)
7124 and then In_Private_Part (Current_Scope)
7127 Private_Declarations (
7128 Specification (Unit_Declaration_Node (Current_Scope)));
7130 return In_Package_Body (Current_Scope)
7132 (Is_List_Member (Decl)
7133 and then List_Containing (Decl) = Priv_Decls)
7134 or else (Nkind (Parent (Decl)) = N_Package_Specification
7137 (Defining_Entity (Parent (Decl)))
7138 and then List_Containing (Parent (Parent (Decl)))
7143 end Is_Private_Declaration;
7145 --------------------------
7146 -- Is_Overriding_Alias --
7147 --------------------------
7149 function Is_Overriding_Alias
7151 New_E : Entity_Id) return Boolean
7153 AO : constant Entity_Id := Alias (Old_E);
7154 AN : constant Entity_Id := Alias (New_E);
7157 return Scope (AO) /= Scope (AN)
7158 or else No (DTC_Entity (AO))
7159 or else No (DTC_Entity (AN))
7160 or else DT_Position (AO) = DT_Position (AN);
7161 end Is_Overriding_Alias;
7163 -- Start of processing for New_Overloaded_Entity
7166 -- We need to look for an entity that S may override. This must be a
7167 -- homonym in the current scope, so we look for the first homonym of
7168 -- S in the current scope as the starting point for the search.
7170 E := Current_Entity_In_Scope (S);
7172 -- If there is no homonym then this is definitely not overriding
7175 Enter_Overloaded_Entity (S);
7176 Check_Dispatching_Operation (S, Empty);
7177 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
7179 -- If subprogram has an explicit declaration, check whether it
7180 -- has an overriding indicator.
7182 if Comes_From_Source (S) then
7183 Check_Synchronized_Overriding (S, Overridden_Subp);
7184 Check_Overriding_Indicator
7185 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
7188 -- If there is a homonym that is not overloadable, then we have an
7189 -- error, except for the special cases checked explicitly below.
7191 elsif not Is_Overloadable (E) then
7193 -- Check for spurious conflict produced by a subprogram that has the
7194 -- same name as that of the enclosing generic package. The conflict
7195 -- occurs within an instance, between the subprogram and the renaming
7196 -- declaration for the package. After the subprogram, the package
7197 -- renaming declaration becomes hidden.
7199 if Ekind (E) = E_Package
7200 and then Present (Renamed_Object (E))
7201 and then Renamed_Object (E) = Current_Scope
7202 and then Nkind (Parent (Renamed_Object (E))) =
7203 N_Package_Specification
7204 and then Present (Generic_Parent (Parent (Renamed_Object (E))))
7207 Set_Is_Immediately_Visible (E, False);
7208 Enter_Overloaded_Entity (S);
7209 Set_Homonym (S, Homonym (E));
7210 Check_Dispatching_Operation (S, Empty);
7211 Check_Overriding_Indicator (S, Empty, Is_Primitive => False);
7213 -- If the subprogram is implicit it is hidden by the previous
7214 -- declaration. However if it is dispatching, it must appear in the
7215 -- dispatch table anyway, because it can be dispatched to even if it
7216 -- cannot be called directly.
7218 elsif Present (Alias (S))
7219 and then not Comes_From_Source (S)
7221 Set_Scope (S, Current_Scope);
7223 if Is_Dispatching_Operation (Alias (S)) then
7224 Check_Dispatching_Operation (S, Empty);
7230 Error_Msg_Sloc := Sloc (E);
7232 -- Generate message, with useful additional warning if in generic
7234 if Is_Generic_Unit (E) then
7235 Error_Msg_N ("previous generic unit cannot be overloaded", S);
7236 Error_Msg_N ("\& conflicts with declaration#", S);
7238 Error_Msg_N ("& conflicts with declaration#", S);
7244 -- E exists and is overloadable
7247 -- Ada 2005 (AI-251): Derivation of abstract interface primitives
7248 -- need no check against the homonym chain. They are directly added
7249 -- to the list of primitive operations of Derived_Type.
7251 if Ada_Version >= Ada_05
7252 and then Present (Derived_Type)
7253 and then Is_Dispatching_Operation (Alias (S))
7254 and then Present (Find_Dispatching_Type (Alias (S)))
7255 and then Is_Interface (Find_Dispatching_Type (Alias (S)))
7257 goto Add_New_Entity;
7260 Check_Synchronized_Overriding (S, Overridden_Subp);
7262 -- Loop through E and its homonyms to determine if any of them is
7263 -- the candidate for overriding by S.
7265 while Present (E) loop
7267 -- Definitely not interesting if not in the current scope
7269 if Scope (E) /= Current_Scope then
7272 -- Check if we have type conformance
7274 elsif Type_Conformant (E, S) then
7276 -- If the old and new entities have the same profile and one
7277 -- is not the body of the other, then this is an error, unless
7278 -- one of them is implicitly declared.
7280 -- There are some cases when both can be implicit, for example
7281 -- when both a literal and a function that overrides it are
7282 -- inherited in a derivation, or when an inherited operation
7283 -- of a tagged full type overrides the inherited operation of
7284 -- a private extension. Ada 83 had a special rule for the
7285 -- literal case. In Ada95, the later implicit operation hides
7286 -- the former, and the literal is always the former. In the
7287 -- odd case where both are derived operations declared at the
7288 -- same point, both operations should be declared, and in that
7289 -- case we bypass the following test and proceed to the next
7290 -- part. This can only occur for certain obscure cases in
7291 -- instances, when an operation on a type derived from a formal
7292 -- private type does not override a homograph inherited from
7293 -- the actual. In subsequent derivations of such a type, the
7294 -- DT positions of these operations remain distinct, if they
7297 if Present (Alias (S))
7298 and then (No (Alias (E))
7299 or else Comes_From_Source (E)
7300 or else Is_Abstract_Subprogram (S)
7302 (Is_Dispatching_Operation (E)
7303 and then Is_Overriding_Alias (E, S)))
7304 and then Ekind (E) /= E_Enumeration_Literal
7306 -- When an derived operation is overloaded it may be due to
7307 -- the fact that the full view of a private extension
7308 -- re-inherits. It has to be dealt with.
7310 if Is_Package_Or_Generic_Package (Current_Scope)
7311 and then In_Private_Part (Current_Scope)
7313 Check_Operation_From_Private_View (S, E);
7316 -- In any case the implicit operation remains hidden by
7317 -- the existing declaration, which is overriding.
7319 Set_Is_Overriding_Operation (E);
7321 if Comes_From_Source (E) then
7322 Check_Overriding_Indicator (E, S, Is_Primitive => False);
7324 -- Indicate that E overrides the operation from which
7327 if Present (Alias (S)) then
7328 Set_Overridden_Operation (E, Alias (S));
7330 Set_Overridden_Operation (E, S);
7336 -- Within an instance, the renaming declarations for
7337 -- actual subprograms may become ambiguous, but they do
7338 -- not hide each other.
7340 elsif Ekind (E) /= E_Entry
7341 and then not Comes_From_Source (E)
7342 and then not Is_Generic_Instance (E)
7343 and then (Present (Alias (E))
7344 or else Is_Intrinsic_Subprogram (E))
7345 and then (not In_Instance
7346 or else No (Parent (E))
7347 or else Nkind (Unit_Declaration_Node (E)) /=
7348 N_Subprogram_Renaming_Declaration)
7350 -- A subprogram child unit is not allowed to override
7351 -- an inherited subprogram (10.1.1(20)).
7353 if Is_Child_Unit (S) then
7355 ("child unit overrides inherited subprogram in parent",
7360 if Is_Non_Overriding_Operation (E, S) then
7361 Enter_Overloaded_Entity (S);
7363 if No (Derived_Type)
7364 or else Is_Tagged_Type (Derived_Type)
7366 Check_Dispatching_Operation (S, Empty);
7372 -- E is a derived operation or an internal operator which
7373 -- is being overridden. Remove E from further visibility.
7374 -- Furthermore, if E is a dispatching operation, it must be
7375 -- replaced in the list of primitive operations of its type
7376 -- (see Override_Dispatching_Operation).
7378 Overridden_Subp := E;
7384 Prev := First_Entity (Current_Scope);
7385 while Present (Prev)
7386 and then Next_Entity (Prev) /= E
7391 -- It is possible for E to be in the current scope and
7392 -- yet not in the entity chain. This can only occur in a
7393 -- generic context where E is an implicit concatenation
7394 -- in the formal part, because in a generic body the
7395 -- entity chain starts with the formals.
7398 (Present (Prev) or else Chars (E) = Name_Op_Concat);
7400 -- E must be removed both from the entity_list of the
7401 -- current scope, and from the visibility chain
7403 if Debug_Flag_E then
7404 Write_Str ("Override implicit operation ");
7405 Write_Int (Int (E));
7409 -- If E is a predefined concatenation, it stands for four
7410 -- different operations. As a result, a single explicit
7411 -- declaration does not hide it. In a possible ambiguous
7412 -- situation, Disambiguate chooses the user-defined op,
7413 -- so it is correct to retain the previous internal one.
7415 if Chars (E) /= Name_Op_Concat
7416 or else Ekind (E) /= E_Operator
7418 -- For nondispatching derived operations that are
7419 -- overridden by a subprogram declared in the private
7420 -- part of a package, we retain the derived subprogram
7421 -- but mark it as not immediately visible. If the
7422 -- derived operation was declared in the visible part
7423 -- then this ensures that it will still be visible
7424 -- outside the package with the proper signature
7425 -- (calls from outside must also be directed to this
7426 -- version rather than the overriding one, unlike the
7427 -- dispatching case). Calls from inside the package
7428 -- will still resolve to the overriding subprogram
7429 -- since the derived one is marked as not visible
7430 -- within the package.
7432 -- If the private operation is dispatching, we achieve
7433 -- the overriding by keeping the implicit operation
7434 -- but setting its alias to be the overriding one. In
7435 -- this fashion the proper body is executed in all
7436 -- cases, but the original signature is used outside
7439 -- If the overriding is not in the private part, we
7440 -- remove the implicit operation altogether.
7442 if Is_Private_Declaration (S) then
7443 if not Is_Dispatching_Operation (E) then
7444 Set_Is_Immediately_Visible (E, False);
7446 -- Work done in Override_Dispatching_Operation,
7447 -- so nothing else need to be done here.
7453 -- Find predecessor of E in Homonym chain
7455 if E = Current_Entity (E) then
7458 Prev_Vis := Current_Entity (E);
7459 while Homonym (Prev_Vis) /= E loop
7460 Prev_Vis := Homonym (Prev_Vis);
7464 if Prev_Vis /= Empty then
7466 -- Skip E in the visibility chain
7468 Set_Homonym (Prev_Vis, Homonym (E));
7471 Set_Name_Entity_Id (Chars (E), Homonym (E));
7474 Set_Next_Entity (Prev, Next_Entity (E));
7476 if No (Next_Entity (Prev)) then
7477 Set_Last_Entity (Current_Scope, Prev);
7483 Enter_Overloaded_Entity (S);
7484 Set_Is_Overriding_Operation (S);
7485 Check_Overriding_Indicator (S, E, Is_Primitive => True);
7487 -- Indicate that S overrides the operation from which
7490 if Comes_From_Source (S) then
7491 if Present (Alias (E)) then
7492 Set_Overridden_Operation (S, Alias (E));
7494 Set_Overridden_Operation (S, E);
7498 if Is_Dispatching_Operation (E) then
7500 -- An overriding dispatching subprogram inherits the
7501 -- convention of the overridden subprogram (by
7504 Set_Convention (S, Convention (E));
7505 Check_Dispatching_Operation (S, E);
7508 Check_Dispatching_Operation (S, Empty);
7511 Check_For_Primitive_Subprogram
7512 (Is_Primitive_Subp, Is_Overriding => True);
7513 goto Check_Inequality;
7516 -- Apparent redeclarations in instances can occur when two
7517 -- formal types get the same actual type. The subprograms in
7518 -- in the instance are legal, even if not callable from the
7519 -- outside. Calls from within are disambiguated elsewhere.
7520 -- For dispatching operations in the visible part, the usual
7521 -- rules apply, and operations with the same profile are not
7524 elsif (In_Instance_Visible_Part
7525 and then not Is_Dispatching_Operation (E))
7526 or else In_Instance_Not_Visible
7530 -- Here we have a real error (identical profile)
7533 Error_Msg_Sloc := Sloc (E);
7535 -- Avoid cascaded errors if the entity appears in
7536 -- subsequent calls.
7538 Set_Scope (S, Current_Scope);
7540 -- Generate error, with extra useful warning for the case
7541 -- of a generic instance with no completion.
7543 if Is_Generic_Instance (S)
7544 and then not Has_Completion (E)
7547 ("instantiation cannot provide body for&", S);
7548 Error_Msg_N ("\& conflicts with declaration#", S);
7550 Error_Msg_N ("& conflicts with declaration#", S);
7557 -- If one subprogram has an access parameter and the other
7558 -- a parameter of an access type, calls to either might be
7559 -- ambiguous. Verify that parameters match except for the
7560 -- access parameter.
7562 if May_Hide_Profile then
7568 F1 := First_Formal (S);
7569 F2 := First_Formal (E);
7570 while Present (F1) and then Present (F2) loop
7571 if Is_Access_Type (Etype (F1)) then
7572 if not Is_Access_Type (Etype (F2))
7573 or else not Conforming_Types
7574 (Designated_Type (Etype (F1)),
7575 Designated_Type (Etype (F2)),
7578 May_Hide_Profile := False;
7582 not Conforming_Types
7583 (Etype (F1), Etype (F2), Type_Conformant)
7585 May_Hide_Profile := False;
7596 Error_Msg_NE ("calls to& may be ambiguous?", S, S);
7607 -- On exit, we know that S is a new entity
7609 Enter_Overloaded_Entity (S);
7610 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
7611 Check_Overriding_Indicator
7612 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
7614 -- If S is a derived operation for an untagged type then by
7615 -- definition it's not a dispatching operation (even if the parent
7616 -- operation was dispatching), so we don't call
7617 -- Check_Dispatching_Operation in that case.
7619 if No (Derived_Type)
7620 or else Is_Tagged_Type (Derived_Type)
7622 Check_Dispatching_Operation (S, Empty);
7626 -- If this is a user-defined equality operator that is not a derived
7627 -- subprogram, create the corresponding inequality. If the operation is
7628 -- dispatching, the expansion is done elsewhere, and we do not create
7629 -- an explicit inequality operation.
7631 <<Check_Inequality>>
7632 if Chars (S) = Name_Op_Eq
7633 and then Etype (S) = Standard_Boolean
7634 and then Present (Parent (S))
7635 and then not Is_Dispatching_Operation (S)
7637 Make_Inequality_Operator (S);
7639 end New_Overloaded_Entity;
7641 ---------------------
7642 -- Process_Formals --
7643 ---------------------
7645 procedure Process_Formals
7647 Related_Nod : Node_Id)
7649 Param_Spec : Node_Id;
7651 Formal_Type : Entity_Id;
7655 Num_Out_Params : Nat := 0;
7656 First_Out_Param : Entity_Id := Empty;
7657 -- Used for setting Is_Only_Out_Parameter
7659 function Is_Class_Wide_Default (D : Node_Id) return Boolean;
7660 -- Check whether the default has a class-wide type. After analysis the
7661 -- default has the type of the formal, so we must also check explicitly
7662 -- for an access attribute.
7664 ---------------------------
7665 -- Is_Class_Wide_Default --
7666 ---------------------------
7668 function Is_Class_Wide_Default (D : Node_Id) return Boolean is
7670 return Is_Class_Wide_Type (Designated_Type (Etype (D)))
7671 or else (Nkind (D) = N_Attribute_Reference
7672 and then Attribute_Name (D) = Name_Access
7673 and then Is_Class_Wide_Type (Etype (Prefix (D))));
7674 end Is_Class_Wide_Default;
7676 -- Start of processing for Process_Formals
7679 -- In order to prevent premature use of the formals in the same formal
7680 -- part, the Ekind is left undefined until all default expressions are
7681 -- analyzed. The Ekind is established in a separate loop at the end.
7683 Param_Spec := First (T);
7684 while Present (Param_Spec) loop
7685 Formal := Defining_Identifier (Param_Spec);
7686 Set_Never_Set_In_Source (Formal, True);
7687 Enter_Name (Formal);
7689 -- Case of ordinary parameters
7691 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
7692 Find_Type (Parameter_Type (Param_Spec));
7693 Ptype := Parameter_Type (Param_Spec);
7695 if Ptype = Error then
7699 Formal_Type := Entity (Ptype);
7701 if Is_Incomplete_Type (Formal_Type)
7703 (Is_Class_Wide_Type (Formal_Type)
7704 and then Is_Incomplete_Type (Root_Type (Formal_Type)))
7706 -- Ada 2005 (AI-326): Tagged incomplete types allowed
7708 if Is_Tagged_Type (Formal_Type) then
7711 -- Special handling of Value_Type for CIL case
7713 elsif Is_Value_Type (Formal_Type) then
7716 elsif not Nkind_In (Parent (T), N_Access_Function_Definition,
7717 N_Access_Procedure_Definition)
7720 ("invalid use of incomplete type&",
7721 Param_Spec, Formal_Type);
7723 -- Further checks on the legality of incomplete types
7724 -- in formal parts must be delayed until the freeze point
7725 -- of the enclosing subprogram or access to subprogram.
7728 elsif Ekind (Formal_Type) = E_Void then
7729 Error_Msg_NE ("premature use of&",
7730 Parameter_Type (Param_Spec), Formal_Type);
7733 -- Ada 2005 (AI-231): Create and decorate an internal subtype
7734 -- declaration corresponding to the null-excluding type of the
7735 -- formal in the enclosing scope. Finally, replace the parameter
7736 -- type of the formal with the internal subtype.
7738 if Ada_Version >= Ada_05
7739 and then Null_Exclusion_Present (Param_Spec)
7741 if not Is_Access_Type (Formal_Type) then
7743 ("`NOT NULL` allowed only for an access type", Param_Spec);
7746 if Can_Never_Be_Null (Formal_Type)
7747 and then Comes_From_Source (Related_Nod)
7750 ("`NOT NULL` not allowed (& already excludes null)",
7756 Create_Null_Excluding_Itype
7758 Related_Nod => Related_Nod,
7759 Scope_Id => Scope (Current_Scope));
7761 -- If the designated type of the itype is an itype we
7762 -- decorate it with the Has_Delayed_Freeze attribute to
7763 -- avoid problems with the backend.
7766 -- type T is access procedure;
7767 -- procedure Op (O : not null T);
7769 if Is_Itype (Directly_Designated_Type (Formal_Type)) then
7770 Set_Has_Delayed_Freeze (Formal_Type);
7775 -- An access formal type
7779 Access_Definition (Related_Nod, Parameter_Type (Param_Spec));
7781 -- No need to continue if we already notified errors
7783 if not Present (Formal_Type) then
7787 -- Ada 2005 (AI-254)
7790 AD : constant Node_Id :=
7791 Access_To_Subprogram_Definition
7792 (Parameter_Type (Param_Spec));
7794 if Present (AD) and then Protected_Present (AD) then
7796 Replace_Anonymous_Access_To_Protected_Subprogram
7802 Set_Etype (Formal, Formal_Type);
7803 Default := Expression (Param_Spec);
7805 if Present (Default) then
7806 if Out_Present (Param_Spec) then
7808 ("default initialization only allowed for IN parameters",
7812 -- Do the special preanalysis of the expression (see section on
7813 -- "Handling of Default Expressions" in the spec of package Sem).
7815 Preanalyze_Spec_Expression (Default, Formal_Type);
7817 -- An access to constant cannot be the default for
7818 -- an access parameter that is an access to variable.
7820 if Ekind (Formal_Type) = E_Anonymous_Access_Type
7821 and then not Is_Access_Constant (Formal_Type)
7822 and then Is_Access_Type (Etype (Default))
7823 and then Is_Access_Constant (Etype (Default))
7826 ("formal that is access to variable cannot be initialized " &
7827 "with an access-to-constant expression", Default);
7830 -- Check that the designated type of an access parameter's default
7831 -- is not a class-wide type unless the parameter's designated type
7832 -- is also class-wide.
7834 if Ekind (Formal_Type) = E_Anonymous_Access_Type
7835 and then not From_With_Type (Formal_Type)
7836 and then Is_Class_Wide_Default (Default)
7837 and then not Is_Class_Wide_Type (Designated_Type (Formal_Type))
7840 ("access to class-wide expression not allowed here", Default);
7844 -- Ada 2005 (AI-231): Static checks
7846 if Ada_Version >= Ada_05
7847 and then Is_Access_Type (Etype (Formal))
7848 and then Can_Never_Be_Null (Etype (Formal))
7850 Null_Exclusion_Static_Checks (Param_Spec);
7857 -- If this is the formal part of a function specification, analyze the
7858 -- subtype mark in the context where the formals are visible but not
7859 -- yet usable, and may hide outer homographs.
7861 if Nkind (Related_Nod) = N_Function_Specification then
7862 Analyze_Return_Type (Related_Nod);
7865 -- Now set the kind (mode) of each formal
7867 Param_Spec := First (T);
7869 while Present (Param_Spec) loop
7870 Formal := Defining_Identifier (Param_Spec);
7871 Set_Formal_Mode (Formal);
7873 if Ekind (Formal) = E_In_Parameter then
7874 Set_Default_Value (Formal, Expression (Param_Spec));
7876 if Present (Expression (Param_Spec)) then
7877 Default := Expression (Param_Spec);
7879 if Is_Scalar_Type (Etype (Default)) then
7881 (Parameter_Type (Param_Spec)) /= N_Access_Definition
7883 Formal_Type := Entity (Parameter_Type (Param_Spec));
7886 Formal_Type := Access_Definition
7887 (Related_Nod, Parameter_Type (Param_Spec));
7890 Apply_Scalar_Range_Check (Default, Formal_Type);
7894 elsif Ekind (Formal) = E_Out_Parameter then
7895 Num_Out_Params := Num_Out_Params + 1;
7897 if Num_Out_Params = 1 then
7898 First_Out_Param := Formal;
7901 elsif Ekind (Formal) = E_In_Out_Parameter then
7902 Num_Out_Params := Num_Out_Params + 1;
7908 if Present (First_Out_Param) and then Num_Out_Params = 1 then
7909 Set_Is_Only_Out_Parameter (First_Out_Param);
7911 end Process_Formals;
7917 procedure Process_PPCs
7919 Spec_Id : Entity_Id;
7920 Body_Id : Entity_Id)
7922 Loc : constant Source_Ptr := Sloc (N);
7924 Plist : List_Id := No_List;
7928 function Grab_PPC (Nam : Name_Id) return Node_Id;
7929 -- Prag contains an analyzed precondition or postcondition pragma.
7930 -- This function copies the pragma, changes it to the corresponding
7931 -- Check pragma and returns the Check pragma as the result. The
7932 -- argument Nam is either Name_Precondition or Name_Postcondition.
7938 function Grab_PPC (Nam : Name_Id) return Node_Id is
7939 CP : constant Node_Id := New_Copy_Tree (Prag);
7942 -- Set Analyzed to false, since we want to reanalyze the check
7943 -- procedure. Note that it is only at the outer level that we
7944 -- do this fiddling, for the spec cases, the already preanalyzed
7945 -- parameters are not affected.
7947 -- For a postcondition pragma within a generic, preserve the pragma
7948 -- for later expansion.
7950 Set_Analyzed (CP, False);
7952 if Nam = Name_Postcondition
7953 and then not Expander_Active
7958 -- Change pragma into corresponding pragma Check
7960 Prepend_To (Pragma_Argument_Associations (CP),
7961 Make_Pragma_Argument_Association (Sloc (Prag),
7963 Make_Identifier (Loc,
7965 Set_Pragma_Identifier (CP,
7966 Make_Identifier (Sloc (Prag),
7967 Chars => Name_Check));
7972 -- Start of processing for Process_PPCs
7975 -- Nothing to do if we are not generating code
7977 if Operating_Mode /= Generate_Code then
7981 -- Grab preconditions from spec
7983 if Present (Spec_Id) then
7985 -- Loop through PPC pragmas from spec. Note that preconditions from
7986 -- the body will be analyzed and converted when we scan the body
7987 -- declarations below.
7989 Prag := Spec_PPC_List (Spec_Id);
7990 while Present (Prag) loop
7991 if Pragma_Name (Prag) = Name_Precondition
7992 and then PPC_Enabled (Prag)
7994 -- Add pragma Check at the start of the declarations of N.
7995 -- Note that this processing reverses the order of the list,
7996 -- which is what we want since new entries were chained to
7997 -- the head of the list.
7999 Prepend (Grab_PPC (Name_Precondition), Declarations (N));
8002 Prag := Next_Pragma (Prag);
8006 -- Build postconditions procedure if needed and prepend the following
8007 -- declaration to the start of the declarations for the subprogram.
8009 -- procedure _postconditions [(_Result : resulttype)] is
8011 -- pragma Check (Postcondition, condition [,message]);
8012 -- pragma Check (Postcondition, condition [,message]);
8016 -- First we deal with the postconditions in the body
8018 if Is_Non_Empty_List (Declarations (N)) then
8020 -- Loop through declarations
8022 Prag := First (Declarations (N));
8023 while Present (Prag) loop
8024 if Nkind (Prag) = N_Pragma then
8026 -- If pragma, capture if enabled postcondition, else ignore
8028 if Pragma_Name (Prag) = Name_Postcondition
8029 and then Check_Enabled (Name_Postcondition)
8031 if Plist = No_List then
8032 Plist := Empty_List;
8037 -- If expansion is disabled, as in a generic unit,
8038 -- save pragma for later expansion.
8040 if not Expander_Active then
8041 Prepend (Grab_PPC (Name_Postcondition), Declarations (N));
8043 Append (Grab_PPC (Name_Postcondition), Plist);
8049 -- Not a pragma, if comes from source, then end scan
8051 elsif Comes_From_Source (Prag) then
8054 -- Skip stuff not coming from source
8062 -- Now deal with any postconditions from the spec
8064 if Present (Spec_Id) then
8066 -- Loop through PPC pragmas from spec
8068 Prag := Spec_PPC_List (Spec_Id);
8069 while Present (Prag) loop
8070 if Pragma_Name (Prag) = Name_Postcondition
8071 and then PPC_Enabled (Prag)
8073 if Plist = No_List then
8074 Plist := Empty_List;
8077 if not Expander_Active then
8078 Prepend (Grab_PPC (Name_Postcondition), Declarations (N));
8080 Append (Grab_PPC (Name_Postcondition), Plist);
8084 Prag := Next_Pragma (Prag);
8088 -- If we had any postconditions and expansion is enabled, build
8089 -- the _Postconditions procedure.
8092 and then Expander_Active
8094 Subp := Defining_Entity (N);
8096 if Etype (Subp) /= Standard_Void_Type then
8098 Make_Parameter_Specification (Loc,
8099 Defining_Identifier =>
8100 Make_Defining_Identifier (Loc,
8101 Chars => Name_uResult),
8102 Parameter_Type => New_Occurrence_Of (Etype (Subp), Loc)));
8108 Post_Proc : constant Entity_Id :=
8109 Make_Defining_Identifier (Loc,
8110 Chars => Name_uPostconditions);
8111 -- The entity for the _Postconditions procedure
8113 Prepend_To (Declarations (N),
8114 Make_Subprogram_Body (Loc,
8116 Make_Procedure_Specification (Loc,
8117 Defining_Unit_Name => Post_Proc,
8118 Parameter_Specifications => Parms),
8120 Declarations => Empty_List,
8122 Handled_Statement_Sequence =>
8123 Make_Handled_Sequence_Of_Statements (Loc,
8124 Statements => Plist)));
8126 -- If this is a procedure, set the Postcondition_Proc attribute
8128 if Etype (Subp) = Standard_Void_Type then
8129 Set_Postcondition_Proc (Spec_Id, Post_Proc);
8133 if Present (Spec_Id) then
8134 Set_Has_Postconditions (Spec_Id);
8136 Set_Has_Postconditions (Body_Id);
8141 ----------------------------
8142 -- Reference_Body_Formals --
8143 ----------------------------
8145 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is
8150 if Error_Posted (Spec) then
8154 -- Iterate over both lists. They may be of different lengths if the two
8155 -- specs are not conformant.
8157 Fs := First_Formal (Spec);
8158 Fb := First_Formal (Bod);
8159 while Present (Fs) and then Present (Fb) loop
8160 Generate_Reference (Fs, Fb, 'b');
8163 Style.Check_Identifier (Fb, Fs);
8166 Set_Spec_Entity (Fb, Fs);
8167 Set_Referenced (Fs, False);
8171 end Reference_Body_Formals;
8173 -------------------------
8174 -- Set_Actual_Subtypes --
8175 -------------------------
8177 procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is
8178 Loc : constant Source_Ptr := Sloc (N);
8182 First_Stmt : Node_Id := Empty;
8183 AS_Needed : Boolean;
8186 -- If this is an empty initialization procedure, no need to create
8187 -- actual subtypes (small optimization).
8189 if Ekind (Subp) = E_Procedure
8190 and then Is_Null_Init_Proc (Subp)
8195 Formal := First_Formal (Subp);
8196 while Present (Formal) loop
8197 T := Etype (Formal);
8199 -- We never need an actual subtype for a constrained formal
8201 if Is_Constrained (T) then
8204 -- If we have unknown discriminants, then we do not need an actual
8205 -- subtype, or more accurately we cannot figure it out! Note that
8206 -- all class-wide types have unknown discriminants.
8208 elsif Has_Unknown_Discriminants (T) then
8211 -- At this stage we have an unconstrained type that may need an
8212 -- actual subtype. For sure the actual subtype is needed if we have
8213 -- an unconstrained array type.
8215 elsif Is_Array_Type (T) then
8218 -- The only other case needing an actual subtype is an unconstrained
8219 -- record type which is an IN parameter (we cannot generate actual
8220 -- subtypes for the OUT or IN OUT case, since an assignment can
8221 -- change the discriminant values. However we exclude the case of
8222 -- initialization procedures, since discriminants are handled very
8223 -- specially in this context, see the section entitled "Handling of
8224 -- Discriminants" in Einfo.
8226 -- We also exclude the case of Discrim_SO_Functions (functions used
8227 -- in front end layout mode for size/offset values), since in such
8228 -- functions only discriminants are referenced, and not only are such
8229 -- subtypes not needed, but they cannot always be generated, because
8230 -- of order of elaboration issues.
8232 elsif Is_Record_Type (T)
8233 and then Ekind (Formal) = E_In_Parameter
8234 and then Chars (Formal) /= Name_uInit
8235 and then not Is_Unchecked_Union (T)
8236 and then not Is_Discrim_SO_Function (Subp)
8240 -- All other cases do not need an actual subtype
8246 -- Generate actual subtypes for unconstrained arrays and
8247 -- unconstrained discriminated records.
8250 if Nkind (N) = N_Accept_Statement then
8252 -- If expansion is active, The formal is replaced by a local
8253 -- variable that renames the corresponding entry of the
8254 -- parameter block, and it is this local variable that may
8255 -- require an actual subtype.
8257 if Expander_Active then
8258 Decl := Build_Actual_Subtype (T, Renamed_Object (Formal));
8260 Decl := Build_Actual_Subtype (T, Formal);
8263 if Present (Handled_Statement_Sequence (N)) then
8265 First (Statements (Handled_Statement_Sequence (N)));
8266 Prepend (Decl, Statements (Handled_Statement_Sequence (N)));
8267 Mark_Rewrite_Insertion (Decl);
8269 -- If the accept statement has no body, there will be no
8270 -- reference to the actuals, so no need to compute actual
8277 Decl := Build_Actual_Subtype (T, Formal);
8278 Prepend (Decl, Declarations (N));
8279 Mark_Rewrite_Insertion (Decl);
8282 -- The declaration uses the bounds of an existing object, and
8283 -- therefore needs no constraint checks.
8285 Analyze (Decl, Suppress => All_Checks);
8287 -- We need to freeze manually the generated type when it is
8288 -- inserted anywhere else than in a declarative part.
8290 if Present (First_Stmt) then
8291 Insert_List_Before_And_Analyze (First_Stmt,
8292 Freeze_Entity (Defining_Identifier (Decl), Loc));
8295 if Nkind (N) = N_Accept_Statement
8296 and then Expander_Active
8298 Set_Actual_Subtype (Renamed_Object (Formal),
8299 Defining_Identifier (Decl));
8301 Set_Actual_Subtype (Formal, Defining_Identifier (Decl));
8305 Next_Formal (Formal);
8307 end Set_Actual_Subtypes;
8309 ---------------------
8310 -- Set_Formal_Mode --
8311 ---------------------
8313 procedure Set_Formal_Mode (Formal_Id : Entity_Id) is
8314 Spec : constant Node_Id := Parent (Formal_Id);
8317 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
8318 -- since we ensure that corresponding actuals are always valid at the
8319 -- point of the call.
8321 if Out_Present (Spec) then
8322 if Ekind (Scope (Formal_Id)) = E_Function
8323 or else Ekind (Scope (Formal_Id)) = E_Generic_Function
8325 Error_Msg_N ("functions can only have IN parameters", Spec);
8326 Set_Ekind (Formal_Id, E_In_Parameter);
8328 elsif In_Present (Spec) then
8329 Set_Ekind (Formal_Id, E_In_Out_Parameter);
8332 Set_Ekind (Formal_Id, E_Out_Parameter);
8333 Set_Never_Set_In_Source (Formal_Id, True);
8334 Set_Is_True_Constant (Formal_Id, False);
8335 Set_Current_Value (Formal_Id, Empty);
8339 Set_Ekind (Formal_Id, E_In_Parameter);
8342 -- Set Is_Known_Non_Null for access parameters since the language
8343 -- guarantees that access parameters are always non-null. We also set
8344 -- Can_Never_Be_Null, since there is no way to change the value.
8346 if Nkind (Parameter_Type (Spec)) = N_Access_Definition then
8348 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
8349 -- null; In Ada 2005, only if then null_exclusion is explicit.
8351 if Ada_Version < Ada_05
8352 or else Can_Never_Be_Null (Etype (Formal_Id))
8354 Set_Is_Known_Non_Null (Formal_Id);
8355 Set_Can_Never_Be_Null (Formal_Id);
8358 -- Ada 2005 (AI-231): Null-exclusion access subtype
8360 elsif Is_Access_Type (Etype (Formal_Id))
8361 and then Can_Never_Be_Null (Etype (Formal_Id))
8363 Set_Is_Known_Non_Null (Formal_Id);
8366 Set_Mechanism (Formal_Id, Default_Mechanism);
8367 Set_Formal_Validity (Formal_Id);
8368 end Set_Formal_Mode;
8370 -------------------------
8371 -- Set_Formal_Validity --
8372 -------------------------
8374 procedure Set_Formal_Validity (Formal_Id : Entity_Id) is
8376 -- If no validity checking, then we cannot assume anything about the
8377 -- validity of parameters, since we do not know there is any checking
8378 -- of the validity on the call side.
8380 if not Validity_Checks_On then
8383 -- If validity checking for parameters is enabled, this means we are
8384 -- not supposed to make any assumptions about argument values.
8386 elsif Validity_Check_Parameters then
8389 -- If we are checking in parameters, we will assume that the caller is
8390 -- also checking parameters, so we can assume the parameter is valid.
8392 elsif Ekind (Formal_Id) = E_In_Parameter
8393 and then Validity_Check_In_Params
8395 Set_Is_Known_Valid (Formal_Id, True);
8397 -- Similar treatment for IN OUT parameters
8399 elsif Ekind (Formal_Id) = E_In_Out_Parameter
8400 and then Validity_Check_In_Out_Params
8402 Set_Is_Known_Valid (Formal_Id, True);
8404 end Set_Formal_Validity;
8406 ------------------------
8407 -- Subtype_Conformant --
8408 ------------------------
8410 function Subtype_Conformant
8411 (New_Id : Entity_Id;
8413 Skip_Controlling_Formals : Boolean := False) return Boolean
8417 Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result,
8418 Skip_Controlling_Formals => Skip_Controlling_Formals);
8420 end Subtype_Conformant;
8422 ---------------------
8423 -- Type_Conformant --
8424 ---------------------
8426 function Type_Conformant
8427 (New_Id : Entity_Id;
8429 Skip_Controlling_Formals : Boolean := False) return Boolean
8433 May_Hide_Profile := False;
8436 (New_Id, Old_Id, Type_Conformant, False, Result,
8437 Skip_Controlling_Formals => Skip_Controlling_Formals);
8439 end Type_Conformant;
8441 -------------------------------
8442 -- Valid_Operator_Definition --
8443 -------------------------------
8445 procedure Valid_Operator_Definition (Designator : Entity_Id) is
8448 Id : constant Name_Id := Chars (Designator);
8452 F := First_Formal (Designator);
8453 while Present (F) loop
8456 if Present (Default_Value (F)) then
8458 ("default values not allowed for operator parameters",
8465 -- Verify that user-defined operators have proper number of arguments
8466 -- First case of operators which can only be unary
8469 or else Id = Name_Op_Abs
8473 -- Case of operators which can be unary or binary
8475 elsif Id = Name_Op_Add
8476 or Id = Name_Op_Subtract
8478 N_OK := (N in 1 .. 2);
8480 -- All other operators can only be binary
8488 ("incorrect number of arguments for operator", Designator);
8492 and then Base_Type (Etype (Designator)) = Standard_Boolean
8493 and then not Is_Intrinsic_Subprogram (Designator)
8496 ("explicit definition of inequality not allowed", Designator);
8498 end Valid_Operator_Definition;