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 end Analyze_Abstract_Subprogram_Declaration;
372 ----------------------------------------
373 -- Analyze_Extended_Return_Statement --
374 ----------------------------------------
376 procedure Analyze_Extended_Return_Statement (N : Node_Id) is
378 Analyze_Return_Statement (N);
379 end Analyze_Extended_Return_Statement;
381 ----------------------------
382 -- Analyze_Function_Call --
383 ----------------------------
385 procedure Analyze_Function_Call (N : Node_Id) is
386 P : constant Node_Id := Name (N);
387 L : constant List_Id := Parameter_Associations (N);
393 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
394 -- as B (A, X). If the rewriting is successful, the call has been
395 -- analyzed and we just return.
397 if Nkind (P) = N_Selected_Component
398 and then Name (N) /= P
399 and then Is_Rewrite_Substitution (N)
400 and then Present (Etype (N))
405 -- If error analyzing name, then set Any_Type as result type and return
407 if Etype (P) = Any_Type then
408 Set_Etype (N, Any_Type);
412 -- Otherwise analyze the parameters
416 while Present (Actual) loop
418 Check_Parameterless_Call (Actual);
424 end Analyze_Function_Call;
426 -----------------------------
427 -- Analyze_Function_Return --
428 -----------------------------
430 procedure Analyze_Function_Return (N : Node_Id) is
431 Loc : constant Source_Ptr := Sloc (N);
432 Stm_Entity : constant Entity_Id := Return_Statement_Entity (N);
433 Scope_Id : constant Entity_Id := Return_Applies_To (Stm_Entity);
435 R_Type : constant Entity_Id := Etype (Scope_Id);
436 -- Function result subtype
438 procedure Check_Limited_Return (Expr : Node_Id);
439 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning
440 -- limited types. Used only for simple return statements.
441 -- Expr is the expression returned.
443 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id);
444 -- Check that the return_subtype_indication properly matches the result
445 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
447 --------------------------
448 -- Check_Limited_Return --
449 --------------------------
451 procedure Check_Limited_Return (Expr : Node_Id) is
453 -- Ada 2005 (AI-318-02): Return-by-reference types have been
454 -- removed and replaced by anonymous access results. This is an
455 -- incompatibility with Ada 95. Not clear whether this should be
456 -- enforced yet or perhaps controllable with special switch. ???
458 if Is_Limited_Type (R_Type)
459 and then Comes_From_Source (N)
460 and then not In_Instance_Body
461 and then not OK_For_Limited_Init_In_05 (Expr)
465 if Ada_Version >= Ada_05
466 and then not Debug_Flag_Dot_L
467 and then not GNAT_Mode
470 ("(Ada 2005) cannot copy object of a limited type " &
471 "(RM-2005 6.5(5.5/2))", Expr);
472 if Is_Inherently_Limited_Type (R_Type) then
474 ("\return by reference not permitted in Ada 2005", Expr);
477 -- Warn in Ada 95 mode, to give folks a heads up about this
480 -- In GNAT mode, this is just a warning, to allow it to be
481 -- evilly turned off. Otherwise it is a real error.
483 elsif Warn_On_Ada_2005_Compatibility or GNAT_Mode then
484 if Is_Inherently_Limited_Type (R_Type) then
486 ("return by reference not permitted in Ada 2005 " &
487 "(RM-2005 6.5(5.5/2))?", Expr);
490 ("cannot copy object of a limited type in Ada 2005 " &
491 "(RM-2005 6.5(5.5/2))?", Expr);
494 -- Ada 95 mode, compatibility warnings disabled
497 return; -- skip continuation messages below
501 ("\consider switching to return of access type", Expr);
502 Explain_Limited_Type (R_Type, Expr);
504 end Check_Limited_Return;
506 -------------------------------------
507 -- Check_Return_Subtype_Indication --
508 -------------------------------------
510 procedure Check_Return_Subtype_Indication (Obj_Decl : Node_Id) is
511 Return_Obj : constant Node_Id := Defining_Identifier (Obj_Decl);
512 R_Stm_Type : constant Entity_Id := Etype (Return_Obj);
513 -- Subtype given in the extended return statement;
514 -- this must match R_Type.
516 Subtype_Ind : constant Node_Id :=
517 Object_Definition (Original_Node (Obj_Decl));
519 R_Type_Is_Anon_Access :
521 Ekind (R_Type) = E_Anonymous_Access_Subprogram_Type
523 Ekind (R_Type) = E_Anonymous_Access_Protected_Subprogram_Type
525 Ekind (R_Type) = E_Anonymous_Access_Type;
526 -- True if return type of the function is an anonymous access type
527 -- Can't we make Is_Anonymous_Access_Type in einfo ???
529 R_Stm_Type_Is_Anon_Access :
531 Ekind (R_Stm_Type) = E_Anonymous_Access_Subprogram_Type
533 Ekind (R_Stm_Type) = E_Anonymous_Access_Protected_Subprogram_Type
535 Ekind (R_Stm_Type) = E_Anonymous_Access_Type;
536 -- True if type of the return object is an anonymous access type
539 -- First, avoid cascade errors:
541 if Error_Posted (Obj_Decl) or else Error_Posted (Subtype_Ind) then
545 -- "return access T" case; check that the return statement also has
546 -- "access T", and that the subtypes statically match:
547 -- if this is an access to subprogram the signatures must match.
549 if R_Type_Is_Anon_Access then
550 if R_Stm_Type_Is_Anon_Access then
552 Ekind (Designated_Type (R_Stm_Type)) /= E_Subprogram_Type
554 if Base_Type (Designated_Type (R_Stm_Type)) /=
555 Base_Type (Designated_Type (R_Type))
556 or else not Subtypes_Statically_Match (R_Stm_Type, R_Type)
559 ("subtype must statically match function result subtype",
560 Subtype_Mark (Subtype_Ind));
564 -- For two anonymous access to subprogram types, the
565 -- types themselves must be type conformant.
567 if not Conforming_Types
568 (R_Stm_Type, R_Type, Fully_Conformant)
571 ("subtype must statically match function result subtype",
577 Error_Msg_N ("must use anonymous access type", Subtype_Ind);
580 -- Subtype_indication case; check that the types are the same, and
581 -- statically match if appropriate. A null exclusion may be present
582 -- on the return type, on the function specification, on the object
583 -- declaration or on the subtype itself.
585 elsif Base_Type (R_Stm_Type) = Base_Type (R_Type) then
586 if Is_Access_Type (R_Type)
588 (Can_Never_Be_Null (R_Type)
589 or else Null_Exclusion_Present (Parent (Scope_Id))) /=
590 Can_Never_Be_Null (R_Stm_Type)
593 ("subtype must statically match function result subtype",
597 if Is_Constrained (R_Type) then
598 if not Subtypes_Statically_Match (R_Stm_Type, R_Type) then
600 ("subtype must statically match function result subtype",
605 -- If the function's result type doesn't match the return object
606 -- entity's type, then we check for the case where the result type
607 -- is class-wide, and allow the declaration if the type of the object
608 -- definition matches the class-wide type. This prevents rejection
609 -- in the case where the object declaration is initialized by a call
610 -- to a build-in-place function with a specific result type and the
611 -- object entity had its type changed to that specific type. This is
612 -- also allowed in the case where Obj_Decl does not come from source,
613 -- which can occur for an expansion of a simple return statement of
614 -- a build-in-place class-wide function when the result expression
615 -- has a specific type, because a return object with a specific type
616 -- is created. (Note that the ARG believes that return objects should
617 -- be allowed to have a type covered by a class-wide result type in
618 -- any case, so once that relaxation is made (see AI05-32), the above
619 -- check for type compatibility should be changed to test Covers
620 -- rather than equality, and the following special test will no
621 -- longer be needed. ???)
623 elsif Is_Class_Wide_Type (R_Type)
625 (R_Type = Etype (Object_Definition (Original_Node (Obj_Decl)))
626 or else not Comes_From_Source (Obj_Decl))
632 ("wrong type for return_subtype_indication", Subtype_Ind);
634 end Check_Return_Subtype_Indication;
636 ---------------------
637 -- Local Variables --
638 ---------------------
642 -- Start of processing for Analyze_Function_Return
645 Set_Return_Present (Scope_Id);
647 if Nkind (N) = N_Simple_Return_Statement then
648 Expr := Expression (N);
649 Analyze_And_Resolve (Expr, R_Type);
650 Check_Limited_Return (Expr);
653 -- Analyze parts specific to extended_return_statement:
656 Obj_Decl : constant Node_Id :=
657 Last (Return_Object_Declarations (N));
659 HSS : constant Node_Id := Handled_Statement_Sequence (N);
662 Expr := Expression (Obj_Decl);
664 -- Note: The check for OK_For_Limited_Init will happen in
665 -- Analyze_Object_Declaration; we treat it as a normal
666 -- object declaration.
668 Set_Is_Return_Object (Defining_Identifier (Obj_Decl));
671 Check_Return_Subtype_Indication (Obj_Decl);
673 if Present (HSS) then
676 if Present (Exception_Handlers (HSS)) then
678 -- ???Has_Nested_Block_With_Handler needs to be set.
679 -- Probably by creating an actual N_Block_Statement.
680 -- Probably in Expand.
686 Check_References (Stm_Entity);
690 -- Case of Expr present
694 -- Defend against previous errors
696 and then Nkind (Expr) /= N_Empty
697 and then Present (Etype (Expr))
699 -- Apply constraint check. Note that this is done before the implicit
700 -- conversion of the expression done for anonymous access types to
701 -- ensure correct generation of the null-excluding check associated
702 -- with null-excluding expressions found in return statements.
704 Apply_Constraint_Check (Expr, R_Type);
706 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
707 -- type, apply an implicit conversion of the expression to that type
708 -- to force appropriate static and run-time accessibility checks.
710 if Ada_Version >= Ada_05
711 and then Ekind (R_Type) = E_Anonymous_Access_Type
713 Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr)));
714 Analyze_And_Resolve (Expr, R_Type);
717 -- If the result type is class-wide, then check that the return
718 -- expression's type is not declared at a deeper level than the
719 -- function (RM05-6.5(5.6/2)).
721 if Ada_Version >= Ada_05
722 and then Is_Class_Wide_Type (R_Type)
724 if Type_Access_Level (Etype (Expr)) >
725 Subprogram_Access_Level (Scope_Id)
728 ("level of return expression type is deeper than " &
729 "class-wide function!", Expr);
733 if (Is_Class_Wide_Type (Etype (Expr))
734 or else Is_Dynamically_Tagged (Expr))
735 and then not Is_Class_Wide_Type (R_Type)
738 ("dynamically tagged expression not allowed!", Expr);
741 -- ??? A real run-time accessibility check is needed in cases
742 -- involving dereferences of access parameters. For now we just
743 -- check the static cases.
745 if (Ada_Version < Ada_05 or else Debug_Flag_Dot_L)
746 and then Is_Inherently_Limited_Type (Etype (Scope_Id))
747 and then Object_Access_Level (Expr) >
748 Subprogram_Access_Level (Scope_Id)
751 Make_Raise_Program_Error (Loc,
752 Reason => PE_Accessibility_Check_Failed));
756 ("cannot return a local value by reference?", N);
758 ("\& will be raised at run time?",
759 N, Standard_Program_Error);
763 and then Nkind (Parent (Scope_Id)) = N_Function_Specification
764 and then Null_Exclusion_Present (Parent (Scope_Id))
766 Apply_Compile_Time_Constraint_Error
768 Msg => "(Ada 2005) null not allowed for "
769 & "null-excluding return?",
770 Reason => CE_Null_Not_Allowed);
773 end Analyze_Function_Return;
775 -------------------------------------
776 -- Analyze_Generic_Subprogram_Body --
777 -------------------------------------
779 procedure Analyze_Generic_Subprogram_Body
783 Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id);
784 Kind : constant Entity_Kind := Ekind (Gen_Id);
790 -- Copy body and disable expansion while analyzing the generic For a
791 -- stub, do not copy the stub (which would load the proper body), this
792 -- will be done when the proper body is analyzed.
794 if Nkind (N) /= N_Subprogram_Body_Stub then
795 New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
800 Spec := Specification (N);
802 -- Within the body of the generic, the subprogram is callable, and
803 -- behaves like the corresponding non-generic unit.
805 Body_Id := Defining_Entity (Spec);
807 if Kind = E_Generic_Procedure
808 and then Nkind (Spec) /= N_Procedure_Specification
810 Error_Msg_N ("invalid body for generic procedure ", Body_Id);
813 elsif Kind = E_Generic_Function
814 and then Nkind (Spec) /= N_Function_Specification
816 Error_Msg_N ("invalid body for generic function ", Body_Id);
820 Set_Corresponding_Body (Gen_Decl, Body_Id);
822 if Has_Completion (Gen_Id)
823 and then Nkind (Parent (N)) /= N_Subunit
825 Error_Msg_N ("duplicate generic body", N);
828 Set_Has_Completion (Gen_Id);
831 if Nkind (N) = N_Subprogram_Body_Stub then
832 Set_Ekind (Defining_Entity (Specification (N)), Kind);
834 Set_Corresponding_Spec (N, Gen_Id);
837 if Nkind (Parent (N)) = N_Compilation_Unit then
838 Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N));
841 -- Make generic parameters immediately visible in the body. They are
842 -- needed to process the formals declarations. Then make the formals
843 -- visible in a separate step.
849 First_Ent : Entity_Id;
852 First_Ent := First_Entity (Gen_Id);
855 while Present (E) and then not Is_Formal (E) loop
860 Set_Use (Generic_Formal_Declarations (Gen_Decl));
862 -- Now generic formals are visible, and the specification can be
863 -- analyzed, for subsequent conformance check.
865 Body_Id := Analyze_Subprogram_Specification (Spec);
867 -- Make formal parameters visible
871 -- E is the first formal parameter, we loop through the formals
872 -- installing them so that they will be visible.
874 Set_First_Entity (Gen_Id, E);
875 while Present (E) loop
881 -- Visible generic entity is callable within its own body
883 Set_Ekind (Gen_Id, Ekind (Body_Id));
884 Set_Ekind (Body_Id, E_Subprogram_Body);
885 Set_Convention (Body_Id, Convention (Gen_Id));
886 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Gen_Id));
887 Set_Scope (Body_Id, Scope (Gen_Id));
888 Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id);
890 if Nkind (N) = N_Subprogram_Body_Stub then
892 -- No body to analyze, so restore state of generic unit
894 Set_Ekind (Gen_Id, Kind);
895 Set_Ekind (Body_Id, Kind);
897 if Present (First_Ent) then
898 Set_First_Entity (Gen_Id, First_Ent);
905 -- If this is a compilation unit, it must be made visible explicitly,
906 -- because the compilation of the declaration, unlike other library
907 -- unit declarations, does not. If it is not a unit, the following
908 -- is redundant but harmless.
910 Set_Is_Immediately_Visible (Gen_Id);
911 Reference_Body_Formals (Gen_Id, Body_Id);
913 if Is_Child_Unit (Gen_Id) then
914 Generate_Reference (Gen_Id, Scope (Gen_Id), 'k', False);
917 Set_Actual_Subtypes (N, Current_Scope);
918 Process_PPCs (N, Gen_Id, Body_Id);
920 -- If the generic unit carries pre- or post-conditions, copy them
921 -- to the original generic tree, so that they are properly added
922 -- to any instantiation.
925 Orig : constant Node_Id := Original_Node (N);
929 Cond := First (Declarations (N));
930 while Present (Cond) loop
931 if Nkind (Cond) = N_Pragma
932 and then Pragma_Name (Cond) = Name_Check
934 Prepend (New_Copy_Tree (Cond), Declarations (Orig));
936 elsif Nkind (Cond) = N_Pragma
937 and then Pragma_Name (Cond) = Name_Postcondition
939 Set_Ekind (Defining_Entity (Orig), Ekind (Gen_Id));
940 Prepend (New_Copy_Tree (Cond), Declarations (Orig));
949 Analyze_Declarations (Declarations (N));
951 Analyze (Handled_Statement_Sequence (N));
953 Save_Global_References (Original_Node (N));
955 -- Prior to exiting the scope, include generic formals again (if any
956 -- are present) in the set of local entities.
958 if Present (First_Ent) then
959 Set_First_Entity (Gen_Id, First_Ent);
962 Check_References (Gen_Id);
965 Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope);
967 Check_Subprogram_Order (N);
969 -- Outside of its body, unit is generic again
971 Set_Ekind (Gen_Id, Kind);
972 Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False);
975 Style.Check_Identifier (Body_Id, Gen_Id);
978 end Analyze_Generic_Subprogram_Body;
980 -----------------------------
981 -- Analyze_Operator_Symbol --
982 -----------------------------
984 -- An operator symbol such as "+" or "and" may appear in context where the
985 -- literal denotes an entity name, such as "+"(x, y) or in context when it
986 -- is just a string, as in (conjunction = "or"). In these cases the parser
987 -- generates this node, and the semantics does the disambiguation. Other
988 -- such case are actuals in an instantiation, the generic unit in an
989 -- instantiation, and pragma arguments.
991 procedure Analyze_Operator_Symbol (N : Node_Id) is
992 Par : constant Node_Id := Parent (N);
995 if (Nkind (Par) = N_Function_Call
996 and then N = Name (Par))
997 or else Nkind (Par) = N_Function_Instantiation
998 or else (Nkind (Par) = N_Indexed_Component
999 and then N = Prefix (Par))
1000 or else (Nkind (Par) = N_Pragma_Argument_Association
1001 and then not Is_Pragma_String_Literal (Par))
1002 or else Nkind (Par) = N_Subprogram_Renaming_Declaration
1003 or else (Nkind (Par) = N_Attribute_Reference
1004 and then Attribute_Name (Par) /= Name_Value)
1006 Find_Direct_Name (N);
1009 Change_Operator_Symbol_To_String_Literal (N);
1012 end Analyze_Operator_Symbol;
1014 -----------------------------------
1015 -- Analyze_Parameter_Association --
1016 -----------------------------------
1018 procedure Analyze_Parameter_Association (N : Node_Id) is
1020 Analyze (Explicit_Actual_Parameter (N));
1021 end Analyze_Parameter_Association;
1023 ----------------------------
1024 -- Analyze_Procedure_Call --
1025 ----------------------------
1027 procedure Analyze_Procedure_Call (N : Node_Id) is
1028 Loc : constant Source_Ptr := Sloc (N);
1029 P : constant Node_Id := Name (N);
1030 Actuals : constant List_Id := Parameter_Associations (N);
1034 procedure Analyze_Call_And_Resolve;
1035 -- Do Analyze and Resolve calls for procedure call
1037 ------------------------------
1038 -- Analyze_Call_And_Resolve --
1039 ------------------------------
1041 procedure Analyze_Call_And_Resolve is
1043 if Nkind (N) = N_Procedure_Call_Statement then
1045 Resolve (N, Standard_Void_Type);
1049 end Analyze_Call_And_Resolve;
1051 -- Start of processing for Analyze_Procedure_Call
1054 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1055 -- a procedure call or an entry call. The prefix may denote an access
1056 -- to subprogram type, in which case an implicit dereference applies.
1057 -- If the prefix is an indexed component (without implicit dereference)
1058 -- then the construct denotes a call to a member of an entire family.
1059 -- If the prefix is a simple name, it may still denote a call to a
1060 -- parameterless member of an entry family. Resolution of these various
1061 -- interpretations is delicate.
1065 -- If this is a call of the form Obj.Op, the call may have been
1066 -- analyzed and possibly rewritten into a block, in which case
1069 if Analyzed (N) then
1073 -- If error analyzing prefix, then set Any_Type as result and return
1075 if Etype (P) = Any_Type then
1076 Set_Etype (N, Any_Type);
1080 -- Otherwise analyze the parameters
1082 if Present (Actuals) then
1083 Actual := First (Actuals);
1085 while Present (Actual) loop
1087 Check_Parameterless_Call (Actual);
1092 -- Special processing for Elab_Spec and Elab_Body calls
1094 if Nkind (P) = N_Attribute_Reference
1095 and then (Attribute_Name (P) = Name_Elab_Spec
1096 or else Attribute_Name (P) = Name_Elab_Body)
1098 if Present (Actuals) then
1100 ("no parameters allowed for this call", First (Actuals));
1104 Set_Etype (N, Standard_Void_Type);
1107 elsif Is_Entity_Name (P)
1108 and then Is_Record_Type (Etype (Entity (P)))
1109 and then Remote_AST_I_Dereference (P)
1113 elsif Is_Entity_Name (P)
1114 and then Ekind (Entity (P)) /= E_Entry_Family
1116 if Is_Access_Type (Etype (P))
1117 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1118 and then No (Actuals)
1119 and then Comes_From_Source (N)
1121 Error_Msg_N ("missing explicit dereference in call", N);
1124 Analyze_Call_And_Resolve;
1126 -- If the prefix is the simple name of an entry family, this is
1127 -- a parameterless call from within the task body itself.
1129 elsif Is_Entity_Name (P)
1130 and then Nkind (P) = N_Identifier
1131 and then Ekind (Entity (P)) = E_Entry_Family
1132 and then Present (Actuals)
1133 and then No (Next (First (Actuals)))
1135 -- Can be call to parameterless entry family. What appears to be the
1136 -- sole argument is in fact the entry index. Rewrite prefix of node
1137 -- accordingly. Source representation is unchanged by this
1141 Make_Indexed_Component (Loc,
1143 Make_Selected_Component (Loc,
1144 Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc),
1145 Selector_Name => New_Occurrence_Of (Entity (P), Loc)),
1146 Expressions => Actuals);
1147 Set_Name (N, New_N);
1148 Set_Etype (New_N, Standard_Void_Type);
1149 Set_Parameter_Associations (N, No_List);
1150 Analyze_Call_And_Resolve;
1152 elsif Nkind (P) = N_Explicit_Dereference then
1153 if Ekind (Etype (P)) = E_Subprogram_Type then
1154 Analyze_Call_And_Resolve;
1156 Error_Msg_N ("expect access to procedure in call", P);
1159 -- The name can be a selected component or an indexed component that
1160 -- yields an access to subprogram. Such a prefix is legal if the call
1161 -- has parameter associations.
1163 elsif Is_Access_Type (Etype (P))
1164 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
1166 if Present (Actuals) then
1167 Analyze_Call_And_Resolve;
1169 Error_Msg_N ("missing explicit dereference in call ", N);
1172 -- If not an access to subprogram, then the prefix must resolve to the
1173 -- name of an entry, entry family, or protected operation.
1175 -- For the case of a simple entry call, P is a selected component where
1176 -- the prefix is the task and the selector name is the entry. A call to
1177 -- a protected procedure will have the same syntax. If the protected
1178 -- object contains overloaded operations, the entity may appear as a
1179 -- function, the context will select the operation whose type is Void.
1181 elsif Nkind (P) = N_Selected_Component
1182 and then (Ekind (Entity (Selector_Name (P))) = E_Entry
1184 Ekind (Entity (Selector_Name (P))) = E_Procedure
1186 Ekind (Entity (Selector_Name (P))) = E_Function)
1188 Analyze_Call_And_Resolve;
1190 elsif Nkind (P) = N_Selected_Component
1191 and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family
1192 and then Present (Actuals)
1193 and then No (Next (First (Actuals)))
1195 -- Can be call to parameterless entry family. What appears to be the
1196 -- sole argument is in fact the entry index. Rewrite prefix of node
1197 -- accordingly. Source representation is unchanged by this
1201 Make_Indexed_Component (Loc,
1202 Prefix => New_Copy (P),
1203 Expressions => Actuals);
1204 Set_Name (N, New_N);
1205 Set_Etype (New_N, Standard_Void_Type);
1206 Set_Parameter_Associations (N, No_List);
1207 Analyze_Call_And_Resolve;
1209 -- For the case of a reference to an element of an entry family, P is
1210 -- an indexed component whose prefix is a selected component (task and
1211 -- entry family), and whose index is the entry family index.
1213 elsif Nkind (P) = N_Indexed_Component
1214 and then Nkind (Prefix (P)) = N_Selected_Component
1215 and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family
1217 Analyze_Call_And_Resolve;
1219 -- If the prefix is the name of an entry family, it is a call from
1220 -- within the task body itself.
1222 elsif Nkind (P) = N_Indexed_Component
1223 and then Nkind (Prefix (P)) = N_Identifier
1224 and then Ekind (Entity (Prefix (P))) = E_Entry_Family
1227 Make_Selected_Component (Loc,
1228 Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc),
1229 Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc));
1230 Rewrite (Prefix (P), New_N);
1232 Analyze_Call_And_Resolve;
1234 -- Anything else is an error
1237 Error_Msg_N ("invalid procedure or entry call", N);
1239 end Analyze_Procedure_Call;
1241 -------------------------------------
1242 -- Analyze_Simple_Return_Statement --
1243 -------------------------------------
1245 procedure Analyze_Simple_Return_Statement (N : Node_Id) is
1247 if Present (Expression (N)) then
1248 Mark_Coextensions (N, Expression (N));
1251 Analyze_Return_Statement (N);
1252 end Analyze_Simple_Return_Statement;
1254 -------------------------
1255 -- Analyze_Return_Type --
1256 -------------------------
1258 procedure Analyze_Return_Type (N : Node_Id) is
1259 Designator : constant Entity_Id := Defining_Entity (N);
1260 Typ : Entity_Id := Empty;
1263 -- Normal case where result definition does not indicate an error
1265 if Result_Definition (N) /= Error then
1266 if Nkind (Result_Definition (N)) = N_Access_Definition then
1268 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
1271 AD : constant Node_Id :=
1272 Access_To_Subprogram_Definition (Result_Definition (N));
1274 if Present (AD) and then Protected_Present (AD) then
1275 Typ := Replace_Anonymous_Access_To_Protected_Subprogram (N);
1277 Typ := Access_Definition (N, Result_Definition (N));
1281 Set_Parent (Typ, Result_Definition (N));
1282 Set_Is_Local_Anonymous_Access (Typ);
1283 Set_Etype (Designator, Typ);
1285 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1287 Null_Exclusion_Static_Checks (N);
1289 -- Subtype_Mark case
1292 Find_Type (Result_Definition (N));
1293 Typ := Entity (Result_Definition (N));
1294 Set_Etype (Designator, Typ);
1296 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
1298 Null_Exclusion_Static_Checks (N);
1300 -- If a null exclusion is imposed on the result type, then create
1301 -- a null-excluding itype (an access subtype) and use it as the
1302 -- function's Etype. Note that the null exclusion checks are done
1303 -- right before this, because they don't get applied to types that
1304 -- do not come from source.
1306 if Is_Access_Type (Typ)
1307 and then Null_Exclusion_Present (N)
1309 Set_Etype (Designator,
1310 Create_Null_Excluding_Itype
1313 Scope_Id => Scope (Current_Scope)));
1315 Set_Etype (Designator, Typ);
1318 if Ekind (Typ) = E_Incomplete_Type
1319 and then Is_Value_Type (Typ)
1323 elsif Ekind (Typ) = E_Incomplete_Type
1324 or else (Is_Class_Wide_Type (Typ)
1326 Ekind (Root_Type (Typ)) = E_Incomplete_Type)
1329 ("invalid use of incomplete type", Result_Definition (N));
1333 -- Case where result definition does indicate an error
1336 Set_Etype (Designator, Any_Type);
1338 end Analyze_Return_Type;
1340 -----------------------------
1341 -- Analyze_Subprogram_Body --
1342 -----------------------------
1344 -- This procedure is called for regular subprogram bodies, generic bodies,
1345 -- and for subprogram stubs of both kinds. In the case of stubs, only the
1346 -- specification matters, and is used to create a proper declaration for
1347 -- the subprogram, or to perform conformance checks.
1349 procedure Analyze_Subprogram_Body (N : Node_Id) is
1350 Loc : constant Source_Ptr := Sloc (N);
1351 Body_Deleted : constant Boolean := False;
1352 Body_Spec : constant Node_Id := Specification (N);
1353 Body_Id : Entity_Id := Defining_Entity (Body_Spec);
1354 Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id);
1355 Conformant : Boolean;
1357 Missing_Ret : Boolean;
1359 Prot_Typ : Entity_Id := Empty;
1360 Spec_Id : Entity_Id;
1361 Spec_Decl : Node_Id := Empty;
1363 Last_Real_Spec_Entity : Entity_Id := Empty;
1364 -- When we analyze a separate spec, the entity chain ends up containing
1365 -- the formals, as well as any itypes generated during analysis of the
1366 -- default expressions for parameters, or the arguments of associated
1367 -- precondition/postcondition pragmas (which are analyzed in the context
1368 -- of the spec since they have visibility on formals).
1370 -- These entities belong with the spec and not the body. However we do
1371 -- the analysis of the body in the context of the spec (again to obtain
1372 -- visibility to the formals), and all the entities generated during
1373 -- this analysis end up also chained to the entity chain of the spec.
1374 -- But they really belong to the body, and there is circuitry to move
1375 -- them from the spec to the body.
1377 -- However, when we do this move, we don't want to move the real spec
1378 -- entities (first para above) to the body. The Last_Real_Spec_Entity
1379 -- variable points to the last real spec entity, so we only move those
1380 -- chained beyond that point. It is initialized to Empty to deal with
1381 -- the case where there is no separate spec.
1383 procedure Check_Anonymous_Return;
1384 -- Ada 2005: if a function returns an access type that denotes a task,
1385 -- or a type that contains tasks, we must create a master entity for
1386 -- the anonymous type, which typically will be used in an allocator
1387 -- in the body of the function.
1389 procedure Check_Inline_Pragma (Spec : in out Node_Id);
1390 -- Look ahead to recognize a pragma that may appear after the body.
1391 -- If there is a previous spec, check that it appears in the same
1392 -- declarative part. If the pragma is Inline_Always, perform inlining
1393 -- unconditionally, otherwise only if Front_End_Inlining is requested.
1394 -- If the body acts as a spec, and inlining is required, we create a
1395 -- subprogram declaration for it, in order to attach the body to inline.
1396 -- If pragma does not appear after the body, check whether there is
1397 -- an inline pragma before any local declarations.
1399 function Disambiguate_Spec return Entity_Id;
1400 -- When a primitive is declared between the private view and the full
1401 -- view of a concurrent type which implements an interface, a special
1402 -- mechanism is used to find the corresponding spec of the primitive
1405 function Is_Private_Concurrent_Primitive
1406 (Subp_Id : Entity_Id) return Boolean;
1407 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
1408 -- type that implements an interface and has a private view.
1410 procedure Set_Trivial_Subprogram (N : Node_Id);
1411 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
1412 -- subprogram whose body is being analyzed. N is the statement node
1413 -- causing the flag to be set, if the following statement is a return
1414 -- of an entity, we mark the entity as set in source to suppress any
1415 -- warning on the stylized use of function stubs with a dummy return.
1417 procedure Verify_Overriding_Indicator;
1418 -- If there was a previous spec, the entity has been entered in the
1419 -- current scope previously. If the body itself carries an overriding
1420 -- indicator, check that it is consistent with the known status of the
1423 ----------------------------
1424 -- Check_Anonymous_Return --
1425 ----------------------------
1427 procedure Check_Anonymous_Return is
1432 if Present (Spec_Id) then
1438 if Ekind (Scop) = E_Function
1439 and then Ekind (Etype (Scop)) = E_Anonymous_Access_Type
1440 and then Has_Task (Designated_Type (Etype (Scop)))
1441 and then Expander_Active
1444 Make_Object_Declaration (Loc,
1445 Defining_Identifier =>
1446 Make_Defining_Identifier (Loc, Name_uMaster),
1447 Constant_Present => True,
1448 Object_Definition =>
1449 New_Reference_To (RTE (RE_Master_Id), Loc),
1451 Make_Explicit_Dereference (Loc,
1452 New_Reference_To (RTE (RE_Current_Master), Loc)));
1454 if Present (Declarations (N)) then
1455 Prepend (Decl, Declarations (N));
1457 Set_Declarations (N, New_List (Decl));
1460 Set_Master_Id (Etype (Scop), Defining_Identifier (Decl));
1461 Set_Has_Master_Entity (Scop);
1463 end Check_Anonymous_Return;
1465 -------------------------
1466 -- Check_Inline_Pragma --
1467 -------------------------
1469 procedure Check_Inline_Pragma (Spec : in out Node_Id) is
1473 function Is_Inline_Pragma (N : Node_Id) return Boolean;
1474 -- True when N is a pragma Inline or Inline_Always that applies
1475 -- to this subprogram.
1477 -----------------------
1478 -- Is_Inline_Pragma --
1479 -----------------------
1481 function Is_Inline_Pragma (N : Node_Id) return Boolean is
1484 Nkind (N) = N_Pragma
1486 (Pragma_Name (N) = Name_Inline_Always
1489 and then Pragma_Name (N) = Name_Inline))
1492 (Expression (First (Pragma_Argument_Associations (N))))
1494 end Is_Inline_Pragma;
1496 -- Start of processing for Check_Inline_Pragma
1499 if not Expander_Active then
1503 if Is_List_Member (N)
1504 and then Present (Next (N))
1505 and then Is_Inline_Pragma (Next (N))
1509 elsif Nkind (N) /= N_Subprogram_Body_Stub
1510 and then Present (Declarations (N))
1511 and then Is_Inline_Pragma (First (Declarations (N)))
1513 Prag := First (Declarations (N));
1519 if Present (Prag) then
1520 if Present (Spec_Id) then
1521 if List_Containing (N) =
1522 List_Containing (Unit_Declaration_Node (Spec_Id))
1528 -- Create a subprogram declaration, to make treatment uniform
1531 Subp : constant Entity_Id :=
1532 Make_Defining_Identifier (Loc, Chars (Body_Id));
1533 Decl : constant Node_Id :=
1534 Make_Subprogram_Declaration (Loc,
1535 Specification => New_Copy_Tree (Specification (N)));
1537 Set_Defining_Unit_Name (Specification (Decl), Subp);
1539 if Present (First_Formal (Body_Id)) then
1540 Plist := Copy_Parameter_List (Body_Id);
1541 Set_Parameter_Specifications
1542 (Specification (Decl), Plist);
1545 Insert_Before (N, Decl);
1548 Set_Has_Pragma_Inline (Subp);
1550 if Pragma_Name (Prag) = Name_Inline_Always then
1551 Set_Is_Inlined (Subp);
1552 Set_Has_Pragma_Inline_Always (Subp);
1559 end Check_Inline_Pragma;
1561 -----------------------
1562 -- Disambiguate_Spec --
1563 -----------------------
1565 function Disambiguate_Spec return Entity_Id is
1566 Priv_Spec : Entity_Id;
1569 procedure Replace_Types (To_Corresponding : Boolean);
1570 -- Depending on the flag, replace the type of formal parameters of
1571 -- Body_Id if it is a concurrent type implementing interfaces with
1572 -- the corresponding record type or the other way around.
1574 procedure Replace_Types (To_Corresponding : Boolean) is
1576 Formal_Typ : Entity_Id;
1579 Formal := First_Formal (Body_Id);
1580 while Present (Formal) loop
1581 Formal_Typ := Etype (Formal);
1583 -- From concurrent type to corresponding record
1585 if To_Corresponding then
1586 if Is_Concurrent_Type (Formal_Typ)
1587 and then Present (Corresponding_Record_Type (Formal_Typ))
1588 and then Present (Interfaces (
1589 Corresponding_Record_Type (Formal_Typ)))
1592 Corresponding_Record_Type (Formal_Typ));
1595 -- From corresponding record to concurrent type
1598 if Is_Concurrent_Record_Type (Formal_Typ)
1599 and then Present (Interfaces (Formal_Typ))
1602 Corresponding_Concurrent_Type (Formal_Typ));
1606 Next_Formal (Formal);
1610 -- Start of processing for Disambiguate_Spec
1613 -- Try to retrieve the specification of the body as is. All error
1614 -- messages are suppressed because the body may not have a spec in
1615 -- its current state.
1617 Spec_N := Find_Corresponding_Spec (N, False);
1619 -- It is possible that this is the body of a primitive declared
1620 -- between a private and a full view of a concurrent type. The
1621 -- controlling parameter of the spec carries the concurrent type,
1622 -- not the corresponding record type as transformed by Analyze_
1623 -- Subprogram_Specification. In such cases, we undo the change
1624 -- made by the analysis of the specification and try to find the
1627 -- Note that wrappers already have their corresponding specs and
1628 -- bodies set during their creation, so if the candidate spec is
1629 -- a wrapper, then we definitely need to swap all types to their
1630 -- original concurrent status.
1633 or else Is_Primitive_Wrapper (Spec_N)
1635 -- Restore all references of corresponding record types to the
1636 -- original concurrent types.
1638 Replace_Types (To_Corresponding => False);
1639 Priv_Spec := Find_Corresponding_Spec (N, False);
1641 -- The current body truly belongs to a primitive declared between
1642 -- a private and a full view. We leave the modified body as is,
1643 -- and return the true spec.
1645 if Present (Priv_Spec)
1646 and then Is_Private_Primitive (Priv_Spec)
1651 -- In case that this is some sort of error, restore the original
1652 -- state of the body.
1654 Replace_Types (To_Corresponding => True);
1658 end Disambiguate_Spec;
1660 -------------------------------------
1661 -- Is_Private_Concurrent_Primitive --
1662 -------------------------------------
1664 function Is_Private_Concurrent_Primitive
1665 (Subp_Id : Entity_Id) return Boolean
1667 Formal_Typ : Entity_Id;
1670 if Present (First_Formal (Subp_Id)) then
1671 Formal_Typ := Etype (First_Formal (Subp_Id));
1673 if Is_Concurrent_Record_Type (Formal_Typ) then
1674 Formal_Typ := Corresponding_Concurrent_Type (Formal_Typ);
1677 -- The type of the first formal is a concurrent tagged type with
1681 Is_Concurrent_Type (Formal_Typ)
1682 and then Is_Tagged_Type (Formal_Typ)
1683 and then Has_Private_Declaration (Formal_Typ);
1687 end Is_Private_Concurrent_Primitive;
1689 ----------------------------
1690 -- Set_Trivial_Subprogram --
1691 ----------------------------
1693 procedure Set_Trivial_Subprogram (N : Node_Id) is
1694 Nxt : constant Node_Id := Next (N);
1697 Set_Is_Trivial_Subprogram (Body_Id);
1699 if Present (Spec_Id) then
1700 Set_Is_Trivial_Subprogram (Spec_Id);
1704 and then Nkind (Nxt) = N_Simple_Return_Statement
1705 and then No (Next (Nxt))
1706 and then Present (Expression (Nxt))
1707 and then Is_Entity_Name (Expression (Nxt))
1709 Set_Never_Set_In_Source (Entity (Expression (Nxt)), False);
1711 end Set_Trivial_Subprogram;
1713 ---------------------------------
1714 -- Verify_Overriding_Indicator --
1715 ---------------------------------
1717 procedure Verify_Overriding_Indicator is
1719 if Must_Override (Body_Spec) then
1720 if Nkind (Spec_Id) = N_Defining_Operator_Symbol
1721 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1725 elsif not Is_Overriding_Operation (Spec_Id) then
1727 ("subprogram& is not overriding", Body_Spec, Spec_Id);
1730 elsif Must_Not_Override (Body_Spec) then
1731 if Is_Overriding_Operation (Spec_Id) then
1733 ("subprogram& overrides inherited operation",
1734 Body_Spec, Spec_Id);
1736 elsif Nkind (Spec_Id) = N_Defining_Operator_Symbol
1737 and then Operator_Matches_Spec (Spec_Id, Spec_Id)
1740 ("subprogram & overrides predefined operator ",
1741 Body_Spec, Spec_Id);
1743 -- If this is not a primitive operation the overriding indicator
1744 -- is altogether illegal.
1746 elsif not Is_Primitive (Spec_Id) then
1747 Error_Msg_N ("overriding indicator only allowed " &
1748 "if subprogram is primitive",
1753 and then Is_Overriding_Operation (Spec_Id)
1755 pragma Assert (Unit_Declaration_Node (Body_Id) = N);
1756 Style.Missing_Overriding (N, Body_Id);
1758 end Verify_Overriding_Indicator;
1760 -- Start of processing for Analyze_Subprogram_Body
1763 if Debug_Flag_C then
1764 Write_Str ("==== Compiling subprogram body ");
1765 Write_Name (Chars (Body_Id));
1766 Write_Str (" from ");
1767 Write_Location (Loc);
1771 Trace_Scope (N, Body_Id, " Analyze subprogram: ");
1773 -- Generic subprograms are handled separately. They always have a
1774 -- generic specification. Determine whether current scope has a
1775 -- previous declaration.
1777 -- If the subprogram body is defined within an instance of the same
1778 -- name, the instance appears as a package renaming, and will be hidden
1779 -- within the subprogram.
1781 if Present (Prev_Id)
1782 and then not Is_Overloadable (Prev_Id)
1783 and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
1784 or else Comes_From_Source (Prev_Id))
1786 if Is_Generic_Subprogram (Prev_Id) then
1788 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
1789 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
1791 Analyze_Generic_Subprogram_Body (N, Spec_Id);
1795 -- Previous entity conflicts with subprogram name. Attempting to
1796 -- enter name will post error.
1798 Enter_Name (Body_Id);
1802 -- Non-generic case, find the subprogram declaration, if one was seen,
1803 -- or enter new overloaded entity in the current scope. If the
1804 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
1805 -- part of the context of one of its subunits. No need to redo the
1808 elsif Prev_Id = Body_Id
1809 and then Has_Completion (Body_Id)
1814 Body_Id := Analyze_Subprogram_Specification (Body_Spec);
1816 if Nkind (N) = N_Subprogram_Body_Stub
1817 or else No (Corresponding_Spec (N))
1819 if Is_Private_Concurrent_Primitive (Body_Id) then
1820 Spec_Id := Disambiguate_Spec;
1822 Spec_Id := Find_Corresponding_Spec (N);
1825 -- If this is a duplicate body, no point in analyzing it
1827 if Error_Posted (N) then
1831 -- A subprogram body should cause freezing of its own declaration,
1832 -- but if there was no previous explicit declaration, then the
1833 -- subprogram will get frozen too late (there may be code within
1834 -- the body that depends on the subprogram having been frozen,
1835 -- such as uses of extra formals), so we force it to be frozen
1836 -- here. Same holds if the body and spec are compilation units.
1837 -- Finally, if the return type is an anonymous access to protected
1838 -- subprogram, it must be frozen before the body because its
1839 -- expansion has generated an equivalent type that is used when
1840 -- elaborating the body.
1842 if No (Spec_Id) then
1843 Freeze_Before (N, Body_Id);
1845 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1846 Freeze_Before (N, Spec_Id);
1848 elsif Is_Access_Subprogram_Type (Etype (Body_Id)) then
1849 Freeze_Before (N, Etype (Body_Id));
1853 Spec_Id := Corresponding_Spec (N);
1857 -- Do not inline any subprogram that contains nested subprograms, since
1858 -- the backend inlining circuit seems to generate uninitialized
1859 -- references in this case. We know this happens in the case of front
1860 -- end ZCX support, but it also appears it can happen in other cases as
1861 -- well. The backend often rejects attempts to inline in the case of
1862 -- nested procedures anyway, so little if anything is lost by this.
1863 -- Note that this is test is for the benefit of the back-end. There is
1864 -- a separate test for front-end inlining that also rejects nested
1867 -- Do not do this test if errors have been detected, because in some
1868 -- error cases, this code blows up, and we don't need it anyway if
1869 -- there have been errors, since we won't get to the linker anyway.
1871 if Comes_From_Source (Body_Id)
1872 and then Serious_Errors_Detected = 0
1876 P_Ent := Scope (P_Ent);
1877 exit when No (P_Ent) or else P_Ent = Standard_Standard;
1879 if Is_Subprogram (P_Ent) then
1880 Set_Is_Inlined (P_Ent, False);
1882 if Comes_From_Source (P_Ent)
1883 and then Has_Pragma_Inline (P_Ent)
1886 ("cannot inline& (nested subprogram)?",
1893 Check_Inline_Pragma (Spec_Id);
1895 -- Deal with special case of a fully private operation in the body of
1896 -- the protected type. We must create a declaration for the subprogram,
1897 -- in order to attach the protected subprogram that will be used in
1898 -- internal calls. We exclude compiler generated bodies from the
1899 -- expander since the issue does not arise for those cases.
1902 and then Comes_From_Source (N)
1903 and then Is_Protected_Type (Current_Scope)
1912 Formal := First_Formal (Body_Id);
1914 -- The protected operation always has at least one formal, namely
1915 -- the object itself, but it is only placed in the parameter list
1916 -- if expansion is enabled.
1919 or else Expander_Active
1921 Plist := Copy_Parameter_List (Body_Id);
1926 if Nkind (Body_Spec) = N_Procedure_Specification then
1928 Make_Procedure_Specification (Loc,
1929 Defining_Unit_Name =>
1930 Make_Defining_Identifier (Sloc (Body_Id),
1931 Chars => Chars (Body_Id)),
1932 Parameter_Specifications => Plist);
1935 Make_Function_Specification (Loc,
1936 Defining_Unit_Name =>
1937 Make_Defining_Identifier (Sloc (Body_Id),
1938 Chars => Chars (Body_Id)),
1939 Parameter_Specifications => Plist,
1940 Result_Definition =>
1941 New_Occurrence_Of (Etype (Body_Id), Loc));
1945 Make_Subprogram_Declaration (Loc,
1946 Specification => New_Spec);
1947 Insert_Before (N, Decl);
1948 Spec_Id := Defining_Unit_Name (New_Spec);
1950 -- Indicate that the entity comes from source, to ensure that
1951 -- cross-reference information is properly generated. The body
1952 -- itself is rewritten during expansion, and the body entity will
1953 -- not appear in calls to the operation.
1955 Set_Comes_From_Source (Spec_Id, True);
1957 Set_Has_Completion (Spec_Id);
1958 Set_Convention (Spec_Id, Convention_Protected);
1962 -- If a separate spec is present, then deal with freezing issues
1964 if Present (Spec_Id) then
1965 Spec_Decl := Unit_Declaration_Node (Spec_Id);
1966 Verify_Overriding_Indicator;
1968 -- In general, the spec will be frozen when we start analyzing the
1969 -- body. However, for internally generated operations, such as
1970 -- wrapper functions for inherited operations with controlling
1971 -- results, the spec may not have been frozen by the time we
1972 -- expand the freeze actions that include the bodies. In particular,
1973 -- extra formals for accessibility or for return-in-place may need
1974 -- to be generated. Freeze nodes, if any, are inserted before the
1977 if not Is_Frozen (Spec_Id)
1978 and then Expander_Active
1980 -- Force the generation of its freezing node to ensure proper
1981 -- management of access types in the backend.
1983 -- This is definitely needed for some cases, but it is not clear
1984 -- why, to be investigated further???
1986 Set_Has_Delayed_Freeze (Spec_Id);
1987 Insert_Actions (N, Freeze_Entity (Spec_Id, Loc));
1991 -- Mark presence of postcondition proc in current scope
1993 if Chars (Body_Id) = Name_uPostconditions then
1994 Set_Has_Postconditions (Current_Scope);
1997 -- Place subprogram on scope stack, and make formals visible. If there
1998 -- is a spec, the visible entity remains that of the spec.
2000 if Present (Spec_Id) then
2001 Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
2003 if Is_Child_Unit (Spec_Id) then
2004 Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False);
2008 Style.Check_Identifier (Body_Id, Spec_Id);
2011 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
2012 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
2014 if Is_Abstract_Subprogram (Spec_Id) then
2015 Error_Msg_N ("an abstract subprogram cannot have a body", N);
2019 Set_Convention (Body_Id, Convention (Spec_Id));
2020 Set_Has_Completion (Spec_Id);
2022 if Is_Protected_Type (Scope (Spec_Id)) then
2023 Prot_Typ := Scope (Spec_Id);
2026 -- If this is a body generated for a renaming, do not check for
2027 -- full conformance. The check is redundant, because the spec of
2028 -- the body is a copy of the spec in the renaming declaration,
2029 -- and the test can lead to spurious errors on nested defaults.
2031 if Present (Spec_Decl)
2032 and then not Comes_From_Source (N)
2034 (Nkind (Original_Node (Spec_Decl)) =
2035 N_Subprogram_Renaming_Declaration
2036 or else (Present (Corresponding_Body (Spec_Decl))
2038 Nkind (Unit_Declaration_Node
2039 (Corresponding_Body (Spec_Decl))) =
2040 N_Subprogram_Renaming_Declaration))
2047 Fully_Conformant, True, Conformant, Body_Id);
2050 -- If the body is not fully conformant, we have to decide if we
2051 -- should analyze it or not. If it has a really messed up profile
2052 -- then we probably should not analyze it, since we will get too
2053 -- many bogus messages.
2055 -- Our decision is to go ahead in the non-fully conformant case
2056 -- only if it is at least mode conformant with the spec. Note
2057 -- that the call to Check_Fully_Conformant has issued the proper
2058 -- error messages to complain about the lack of conformance.
2061 and then not Mode_Conformant (Body_Id, Spec_Id)
2067 if Spec_Id /= Body_Id then
2068 Reference_Body_Formals (Spec_Id, Body_Id);
2071 if Nkind (N) /= N_Subprogram_Body_Stub then
2072 Set_Corresponding_Spec (N, Spec_Id);
2074 -- Ada 2005 (AI-345): If the operation is a primitive operation
2075 -- of a concurrent type, the type of the first parameter has been
2076 -- replaced with the corresponding record, which is the proper
2077 -- run-time structure to use. However, within the body there may
2078 -- be uses of the formals that depend on primitive operations
2079 -- of the type (in particular calls in prefixed form) for which
2080 -- we need the original concurrent type. The operation may have
2081 -- several controlling formals, so the replacement must be done
2084 if Comes_From_Source (Spec_Id)
2085 and then Present (First_Entity (Spec_Id))
2086 and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type
2087 and then Is_Tagged_Type (Etype (First_Entity (Spec_Id)))
2089 Present (Interfaces (Etype (First_Entity (Spec_Id))))
2092 (Corresponding_Concurrent_Type
2093 (Etype (First_Entity (Spec_Id))))
2096 Typ : constant Entity_Id := Etype (First_Entity (Spec_Id));
2100 Form := First_Formal (Spec_Id);
2101 while Present (Form) loop
2102 if Etype (Form) = Typ then
2103 Set_Etype (Form, Corresponding_Concurrent_Type (Typ));
2111 -- Make the formals visible, and place subprogram on scope stack.
2112 -- This is also the point at which we set Last_Real_Spec_Entity
2113 -- to mark the entities which will not be moved to the body.
2115 Install_Formals (Spec_Id);
2116 Last_Real_Spec_Entity := Last_Entity (Spec_Id);
2117 Push_Scope (Spec_Id);
2119 -- Make sure that the subprogram is immediately visible. For
2120 -- child units that have no separate spec this is indispensable.
2121 -- Otherwise it is safe albeit redundant.
2123 Set_Is_Immediately_Visible (Spec_Id);
2126 Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id);
2127 Set_Ekind (Body_Id, E_Subprogram_Body);
2128 Set_Scope (Body_Id, Scope (Spec_Id));
2129 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Spec_Id));
2131 -- Case of subprogram body with no previous spec
2135 and then Comes_From_Source (Body_Id)
2136 and then not Suppress_Style_Checks (Body_Id)
2137 and then not In_Instance
2139 Style.Body_With_No_Spec (N);
2142 New_Overloaded_Entity (Body_Id);
2144 if Nkind (N) /= N_Subprogram_Body_Stub then
2145 Set_Acts_As_Spec (N);
2146 Generate_Definition (Body_Id);
2148 (Body_Id, Body_Id, 'b', Set_Ref => False, Force => True);
2149 Generate_Reference_To_Formals (Body_Id);
2150 Install_Formals (Body_Id);
2151 Push_Scope (Body_Id);
2155 -- If the return type is an anonymous access type whose designated type
2156 -- is the limited view of a class-wide type and the non-limited view is
2157 -- available, update the return type accordingly.
2159 if Ada_Version >= Ada_05
2160 and then Comes_From_Source (N)
2167 Rtyp := Etype (Current_Scope);
2169 if Ekind (Rtyp) = E_Anonymous_Access_Type then
2170 Etyp := Directly_Designated_Type (Rtyp);
2172 if Is_Class_Wide_Type (Etyp)
2173 and then From_With_Type (Etyp)
2175 Set_Directly_Designated_Type
2176 (Etype (Current_Scope), Available_View (Etyp));
2182 -- If this is the proper body of a stub, we must verify that the stub
2183 -- conforms to the body, and to the previous spec if one was present.
2184 -- we know already that the body conforms to that spec. This test is
2185 -- only required for subprograms that come from source.
2187 if Nkind (Parent (N)) = N_Subunit
2188 and then Comes_From_Source (N)
2189 and then not Error_Posted (Body_Id)
2190 and then Nkind (Corresponding_Stub (Parent (N))) =
2191 N_Subprogram_Body_Stub
2194 Old_Id : constant Entity_Id :=
2196 (Specification (Corresponding_Stub (Parent (N))));
2198 Conformant : Boolean := False;
2201 if No (Spec_Id) then
2202 Check_Fully_Conformant (Body_Id, Old_Id);
2206 (Body_Id, Old_Id, Fully_Conformant, False, Conformant);
2208 if not Conformant then
2210 -- The stub was taken to be a new declaration. Indicate
2211 -- that it lacks a body.
2213 Set_Has_Completion (Old_Id, False);
2219 Set_Has_Completion (Body_Id);
2220 Check_Eliminated (Body_Id);
2222 if Nkind (N) = N_Subprogram_Body_Stub then
2225 elsif Present (Spec_Id)
2226 and then Expander_Active
2228 (Has_Pragma_Inline_Always (Spec_Id)
2229 or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining))
2231 Build_Body_To_Inline (N, Spec_Id);
2234 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
2235 -- if its specification we have to install the private withed units.
2236 -- This holds for child units as well.
2238 if Is_Compilation_Unit (Body_Id)
2239 or else Nkind (Parent (N)) = N_Compilation_Unit
2241 Install_Private_With_Clauses (Body_Id);
2244 Check_Anonymous_Return;
2246 -- Set the Protected_Formal field of each extra formal of the protected
2247 -- subprogram to reference the corresponding extra formal of the
2248 -- subprogram that implements it. For regular formals this occurs when
2249 -- the protected subprogram's declaration is expanded, but the extra
2250 -- formals don't get created until the subprogram is frozen. We need to
2251 -- do this before analyzing the protected subprogram's body so that any
2252 -- references to the original subprogram's extra formals will be changed
2253 -- refer to the implementing subprogram's formals (see Expand_Formal).
2255 if Present (Spec_Id)
2256 and then Is_Protected_Type (Scope (Spec_Id))
2257 and then Present (Protected_Body_Subprogram (Spec_Id))
2260 Impl_Subp : constant Entity_Id :=
2261 Protected_Body_Subprogram (Spec_Id);
2262 Prot_Ext_Formal : Entity_Id := Extra_Formals (Spec_Id);
2263 Impl_Ext_Formal : Entity_Id := Extra_Formals (Impl_Subp);
2265 while Present (Prot_Ext_Formal) loop
2266 pragma Assert (Present (Impl_Ext_Formal));
2267 Set_Protected_Formal (Prot_Ext_Formal, Impl_Ext_Formal);
2268 Next_Formal_With_Extras (Prot_Ext_Formal);
2269 Next_Formal_With_Extras (Impl_Ext_Formal);
2274 -- Now we can go on to analyze the body
2276 HSS := Handled_Statement_Sequence (N);
2277 Set_Actual_Subtypes (N, Current_Scope);
2279 -- Deal with preconditions and postconditions
2281 Process_PPCs (N, Spec_Id, Body_Id);
2283 -- Add a declaration for the Protection object, renaming declarations
2284 -- for discriminals and privals and finally a declaration for the entry
2285 -- family index (if applicable). This form of early expansion is done
2286 -- when the Expander is active because Install_Private_Data_Declarations
2287 -- references entities which were created during regular expansion.
2290 and then Comes_From_Source (N)
2291 and then Present (Prot_Typ)
2292 and then Present (Spec_Id)
2293 and then not Is_Eliminated (Spec_Id)
2295 Install_Private_Data_Declarations
2296 (Sloc (N), Spec_Id, Prot_Typ, N, Declarations (N));
2299 -- Analyze the declarations (this call will analyze the precondition
2300 -- Check pragmas we prepended to the list, as well as the declaration
2301 -- of the _Postconditions procedure).
2303 Analyze_Declarations (Declarations (N));
2305 -- Check completion, and analyze the statements
2308 Inspect_Deferred_Constant_Completion (Declarations (N));
2311 -- Deal with end of scope processing for the body
2313 Process_End_Label (HSS, 't', Current_Scope);
2315 Check_Subprogram_Order (N);
2316 Set_Analyzed (Body_Id);
2318 -- If we have a separate spec, then the analysis of the declarations
2319 -- caused the entities in the body to be chained to the spec id, but
2320 -- we want them chained to the body id. Only the formal parameters
2321 -- end up chained to the spec id in this case.
2323 if Present (Spec_Id) then
2325 -- We must conform to the categorization of our spec
2327 Validate_Categorization_Dependency (N, Spec_Id);
2329 -- And if this is a child unit, the parent units must conform
2331 if Is_Child_Unit (Spec_Id) then
2332 Validate_Categorization_Dependency
2333 (Unit_Declaration_Node (Spec_Id), Spec_Id);
2336 -- Here is where we move entities from the spec to the body
2338 -- Case where there are entities that stay with the spec
2340 if Present (Last_Real_Spec_Entity) then
2342 -- No body entities (happens when the only real spec entities
2343 -- come from precondition and postcondition pragmas)
2345 if No (Last_Entity (Body_Id)) then
2347 (Body_Id, Next_Entity (Last_Real_Spec_Entity));
2349 -- Body entities present (formals), so chain stuff past them
2353 (Last_Entity (Body_Id), Next_Entity (Last_Real_Spec_Entity));
2356 Set_Next_Entity (Last_Real_Spec_Entity, Empty);
2357 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2358 Set_Last_Entity (Spec_Id, Last_Real_Spec_Entity);
2360 -- Case where there are no spec entities, in this case there can
2361 -- be no body entities either, so just move everything.
2364 pragma Assert (No (Last_Entity (Body_Id)));
2365 Set_First_Entity (Body_Id, First_Entity (Spec_Id));
2366 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
2367 Set_First_Entity (Spec_Id, Empty);
2368 Set_Last_Entity (Spec_Id, Empty);
2372 -- If function, check return statements
2374 if Nkind (Body_Spec) = N_Function_Specification then
2379 if Present (Spec_Id) then
2385 if Return_Present (Id) then
2386 Check_Returns (HSS, 'F', Missing_Ret);
2389 Set_Has_Missing_Return (Id);
2392 elsif not Is_Machine_Code_Subprogram (Id)
2393 and then not Body_Deleted
2395 Error_Msg_N ("missing RETURN statement in function body", N);
2399 -- If procedure with No_Return, check returns
2401 elsif Nkind (Body_Spec) = N_Procedure_Specification
2402 and then Present (Spec_Id)
2403 and then No_Return (Spec_Id)
2405 Check_Returns (HSS, 'P', Missing_Ret, Spec_Id);
2408 -- Now we are going to check for variables that are never modified in
2409 -- the body of the procedure. But first we deal with a special case
2410 -- where we want to modify this check. If the body of the subprogram
2411 -- starts with a raise statement or its equivalent, or if the body
2412 -- consists entirely of a null statement, then it is pretty obvious
2413 -- that it is OK to not reference the parameters. For example, this
2414 -- might be the following common idiom for a stubbed function:
2415 -- statement of the procedure raises an exception. In particular this
2416 -- deals with the common idiom of a stubbed function, which might
2417 -- appear as something like
2419 -- function F (A : Integer) return Some_Type;
2422 -- raise Program_Error;
2426 -- Here the purpose of X is simply to satisfy the annoying requirement
2427 -- in Ada that there be at least one return, and we certainly do not
2428 -- want to go posting warnings on X that it is not initialized! On
2429 -- the other hand, if X is entirely unreferenced that should still
2432 -- What we do is to detect these cases, and if we find them, flag the
2433 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
2434 -- suppress unwanted warnings. For the case of the function stub above
2435 -- we have a special test to set X as apparently assigned to suppress
2442 -- Skip initial labels (for one thing this occurs when we are in
2443 -- front end ZCX mode, but in any case it is irrelevant), and also
2444 -- initial Push_xxx_Error_Label nodes, which are also irrelevant.
2446 Stm := First (Statements (HSS));
2447 while Nkind (Stm) = N_Label
2448 or else Nkind (Stm) in N_Push_xxx_Label
2453 -- Do the test on the original statement before expansion
2456 Ostm : constant Node_Id := Original_Node (Stm);
2459 -- If explicit raise statement, turn on flag
2461 if Nkind (Ostm) = N_Raise_Statement then
2462 Set_Trivial_Subprogram (Stm);
2464 -- If null statement, and no following statements, turn on flag
2466 elsif Nkind (Stm) = N_Null_Statement
2467 and then Comes_From_Source (Stm)
2468 and then No (Next (Stm))
2470 Set_Trivial_Subprogram (Stm);
2472 -- Check for explicit call cases which likely raise an exception
2474 elsif Nkind (Ostm) = N_Procedure_Call_Statement then
2475 if Is_Entity_Name (Name (Ostm)) then
2477 Ent : constant Entity_Id := Entity (Name (Ostm));
2480 -- If the procedure is marked No_Return, then likely it
2481 -- raises an exception, but in any case it is not coming
2482 -- back here, so turn on the flag.
2484 if Ekind (Ent) = E_Procedure
2485 and then No_Return (Ent)
2487 Set_Trivial_Subprogram (Stm);
2495 -- Check for variables that are never modified
2501 -- If there is a separate spec, then transfer Never_Set_In_Source
2502 -- flags from out parameters to the corresponding entities in the
2503 -- body. The reason we do that is we want to post error flags on
2504 -- the body entities, not the spec entities.
2506 if Present (Spec_Id) then
2507 E1 := First_Entity (Spec_Id);
2508 while Present (E1) loop
2509 if Ekind (E1) = E_Out_Parameter then
2510 E2 := First_Entity (Body_Id);
2511 while Present (E2) loop
2512 exit when Chars (E1) = Chars (E2);
2516 if Present (E2) then
2517 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
2525 -- Check references in body unless it was deleted. Note that the
2526 -- check of Body_Deleted here is not just for efficiency, it is
2527 -- necessary to avoid junk warnings on formal parameters.
2529 if not Body_Deleted then
2530 Check_References (Body_Id);
2533 end Analyze_Subprogram_Body;
2535 ------------------------------------
2536 -- Analyze_Subprogram_Declaration --
2537 ------------------------------------
2539 procedure Analyze_Subprogram_Declaration (N : Node_Id) is
2540 Designator : constant Entity_Id :=
2541 Analyze_Subprogram_Specification (Specification (N));
2542 Scop : constant Entity_Id := Current_Scope;
2544 -- Start of processing for Analyze_Subprogram_Declaration
2547 Generate_Definition (Designator);
2549 -- Check for RCI unit subprogram declarations for illegal inlined
2550 -- subprograms and subprograms having access parameter or limited
2551 -- parameter without Read and Write attributes (RM E.2.3(12-13)).
2553 Validate_RCI_Subprogram_Declaration (N);
2557 Defining_Entity (N),
2558 " Analyze subprogram spec: ");
2560 if Debug_Flag_C then
2561 Write_Str ("==== Compiling subprogram spec ");
2562 Write_Name (Chars (Designator));
2563 Write_Str (" from ");
2564 Write_Location (Sloc (N));
2568 New_Overloaded_Entity (Designator);
2569 Check_Delayed_Subprogram (Designator);
2571 -- If the type of the first formal of the current subprogram is a non
2572 -- generic tagged private type , mark the subprogram as being a private
2575 if Present (First_Formal (Designator)) then
2577 Formal_Typ : constant Entity_Id :=
2578 Etype (First_Formal (Designator));
2580 Set_Is_Private_Primitive (Designator,
2581 Is_Tagged_Type (Formal_Typ)
2582 and then Is_Private_Type (Formal_Typ)
2583 and then not Is_Generic_Actual_Type (Formal_Typ));
2587 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
2590 if Ada_Version >= Ada_05
2591 and then Comes_From_Source (N)
2592 and then Is_Dispatching_Operation (Designator)
2599 if Has_Controlling_Result (Designator) then
2600 Etyp := Etype (Designator);
2603 E := First_Entity (Designator);
2605 and then Is_Formal (E)
2606 and then not Is_Controlling_Formal (E)
2614 if Is_Access_Type (Etyp) then
2615 Etyp := Directly_Designated_Type (Etyp);
2618 if Is_Interface (Etyp)
2619 and then not Is_Abstract_Subprogram (Designator)
2620 and then not (Ekind (Designator) = E_Procedure
2621 and then Null_Present (Specification (N)))
2623 Error_Msg_Name_1 := Chars (Defining_Entity (N));
2625 ("(Ada 2005) interface subprogram % must be abstract or null",
2631 -- What is the following code for, it used to be
2633 -- ??? Set_Suppress_Elaboration_Checks
2634 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
2636 -- The following seems equivalent, but a bit dubious
2638 if Elaboration_Checks_Suppressed (Designator) then
2639 Set_Kill_Elaboration_Checks (Designator);
2642 if Scop /= Standard_Standard
2643 and then not Is_Child_Unit (Designator)
2645 Set_Categorization_From_Scope (Designator, Scop);
2647 -- For a compilation unit, check for library-unit pragmas
2649 Push_Scope (Designator);
2650 Set_Categorization_From_Pragmas (N);
2651 Validate_Categorization_Dependency (N, Designator);
2655 -- For a compilation unit, set body required. This flag will only be
2656 -- reset if a valid Import or Interface pragma is processed later on.
2658 if Nkind (Parent (N)) = N_Compilation_Unit then
2659 Set_Body_Required (Parent (N), True);
2661 if Ada_Version >= Ada_05
2662 and then Nkind (Specification (N)) = N_Procedure_Specification
2663 and then Null_Present (Specification (N))
2666 ("null procedure cannot be declared at library level", N);
2670 Generate_Reference_To_Formals (Designator);
2671 Check_Eliminated (Designator);
2673 -- Ada 2005: if procedure is declared with "is null" qualifier,
2674 -- it requires no body.
2676 if Nkind (Specification (N)) = N_Procedure_Specification
2677 and then Null_Present (Specification (N))
2679 Set_Has_Completion (Designator);
2680 Set_Is_Inlined (Designator);
2682 if Is_Protected_Type (Current_Scope) then
2684 ("protected operation cannot be a null procedure", N);
2687 end Analyze_Subprogram_Declaration;
2689 --------------------------------------
2690 -- Analyze_Subprogram_Specification --
2691 --------------------------------------
2693 -- Reminder: N here really is a subprogram specification (not a subprogram
2694 -- declaration). This procedure is called to analyze the specification in
2695 -- both subprogram bodies and subprogram declarations (specs).
2697 function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is
2698 Designator : constant Entity_Id := Defining_Entity (N);
2699 Formals : constant List_Id := Parameter_Specifications (N);
2701 -- Start of processing for Analyze_Subprogram_Specification
2704 Generate_Definition (Designator);
2706 if Nkind (N) = N_Function_Specification then
2707 Set_Ekind (Designator, E_Function);
2708 Set_Mechanism (Designator, Default_Mechanism);
2711 Set_Ekind (Designator, E_Procedure);
2712 Set_Etype (Designator, Standard_Void_Type);
2715 -- Introduce new scope for analysis of the formals and the return type
2717 Set_Scope (Designator, Current_Scope);
2719 if Present (Formals) then
2720 Push_Scope (Designator);
2721 Process_Formals (Formals, N);
2723 -- Ada 2005 (AI-345): If this is an overriding operation of an
2724 -- inherited interface operation, and the controlling type is
2725 -- a synchronized type, replace the type with its corresponding
2726 -- record, to match the proper signature of an overriding operation.
2728 if Ada_Version >= Ada_05 then
2731 Formal_Typ : Entity_Id;
2732 Rec_Typ : Entity_Id;
2735 Formal := First_Formal (Designator);
2736 while Present (Formal) loop
2737 Formal_Typ := Etype (Formal);
2739 if Is_Concurrent_Type (Formal_Typ)
2740 and then Present (Corresponding_Record_Type (Formal_Typ))
2742 Rec_Typ := Corresponding_Record_Type (Formal_Typ);
2744 if Present (Interfaces (Rec_Typ)) then
2745 Set_Etype (Formal, Rec_Typ);
2749 Next_Formal (Formal);
2756 -- The subprogram scope is pushed and popped around the processing of
2757 -- the return type for consistency with call above to Process_Formals
2758 -- (which itself can call Analyze_Return_Type), and to ensure that any
2759 -- itype created for the return type will be associated with the proper
2762 elsif Nkind (N) = N_Function_Specification then
2763 Push_Scope (Designator);
2765 Analyze_Return_Type (N);
2770 if Nkind (N) = N_Function_Specification then
2771 if Nkind (Designator) = N_Defining_Operator_Symbol then
2772 Valid_Operator_Definition (Designator);
2775 May_Need_Actuals (Designator);
2777 -- Ada 2005 (AI-251): If the return type is abstract, verify that
2778 -- the subprogram is abstract also. This does not apply to renaming
2779 -- declarations, where abstractness is inherited.
2780 -- In case of primitives associated with abstract interface types
2781 -- the check is applied later (see Analyze_Subprogram_Declaration).
2783 if Is_Abstract_Type (Etype (Designator))
2784 and then not Is_Interface (Etype (Designator))
2785 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
2786 and then Nkind (Parent (N)) /=
2787 N_Abstract_Subprogram_Declaration
2789 (Nkind (Parent (N))) /= N_Formal_Abstract_Subprogram_Declaration
2792 ("function that returns abstract type must be abstract", N);
2797 end Analyze_Subprogram_Specification;
2799 --------------------------
2800 -- Build_Body_To_Inline --
2801 --------------------------
2803 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is
2804 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
2805 Original_Body : Node_Id;
2806 Body_To_Analyze : Node_Id;
2807 Max_Size : constant := 10;
2808 Stat_Count : Integer := 0;
2810 function Has_Excluded_Declaration (Decls : List_Id) return Boolean;
2811 -- Check for declarations that make inlining not worthwhile
2813 function Has_Excluded_Statement (Stats : List_Id) return Boolean;
2814 -- Check for statements that make inlining not worthwhile: any tasking
2815 -- statement, nested at any level. Keep track of total number of
2816 -- elementary statements, as a measure of acceptable size.
2818 function Has_Pending_Instantiation return Boolean;
2819 -- If some enclosing body contains instantiations that appear before the
2820 -- corresponding generic body, the enclosing body has a freeze node so
2821 -- that it can be elaborated after the generic itself. This might
2822 -- conflict with subsequent inlinings, so that it is unsafe to try to
2823 -- inline in such a case.
2825 function Has_Single_Return return Boolean;
2826 -- In general we cannot inline functions that return unconstrained type.
2827 -- However, we can handle such functions if all return statements return
2828 -- a local variable that is the only declaration in the body of the
2829 -- function. In that case the call can be replaced by that local
2830 -- variable as is done for other inlined calls.
2832 procedure Remove_Pragmas;
2833 -- A pragma Unreferenced or pragma Unmodified that mentions a formal
2834 -- parameter has no meaning when the body is inlined and the formals
2835 -- are rewritten. Remove it from body to inline. The analysis of the
2836 -- non-inlined body will handle the pragma properly.
2838 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean;
2839 -- If the body of the subprogram includes a call that returns an
2840 -- unconstrained type, the secondary stack is involved, and it
2841 -- is not worth inlining.
2843 ------------------------------
2844 -- Has_Excluded_Declaration --
2845 ------------------------------
2847 function Has_Excluded_Declaration (Decls : List_Id) return Boolean is
2850 function Is_Unchecked_Conversion (D : Node_Id) return Boolean;
2851 -- Nested subprograms make a given body ineligible for inlining, but
2852 -- we make an exception for instantiations of unchecked conversion.
2853 -- The body has not been analyzed yet, so check the name, and verify
2854 -- that the visible entity with that name is the predefined unit.
2856 -----------------------------
2857 -- Is_Unchecked_Conversion --
2858 -----------------------------
2860 function Is_Unchecked_Conversion (D : Node_Id) return Boolean is
2861 Id : constant Node_Id := Name (D);
2865 if Nkind (Id) = N_Identifier
2866 and then Chars (Id) = Name_Unchecked_Conversion
2868 Conv := Current_Entity (Id);
2870 elsif Nkind_In (Id, N_Selected_Component, N_Expanded_Name)
2871 and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion
2873 Conv := Current_Entity (Selector_Name (Id));
2878 return Present (Conv)
2879 and then Is_Predefined_File_Name
2880 (Unit_File_Name (Get_Source_Unit (Conv)))
2881 and then Is_Intrinsic_Subprogram (Conv);
2882 end Is_Unchecked_Conversion;
2884 -- Start of processing for Has_Excluded_Declaration
2888 while Present (D) loop
2889 if (Nkind (D) = N_Function_Instantiation
2890 and then not Is_Unchecked_Conversion (D))
2891 or else Nkind_In (D, N_Protected_Type_Declaration,
2892 N_Package_Declaration,
2893 N_Package_Instantiation,
2895 N_Procedure_Instantiation,
2896 N_Task_Type_Declaration)
2899 ("cannot inline & (non-allowed declaration)?", D, Subp);
2907 end Has_Excluded_Declaration;
2909 ----------------------------
2910 -- Has_Excluded_Statement --
2911 ----------------------------
2913 function Has_Excluded_Statement (Stats : List_Id) return Boolean is
2919 while Present (S) loop
2920 Stat_Count := Stat_Count + 1;
2922 if Nkind_In (S, N_Abort_Statement,
2923 N_Asynchronous_Select,
2924 N_Conditional_Entry_Call,
2925 N_Delay_Relative_Statement,
2926 N_Delay_Until_Statement,
2931 ("cannot inline & (non-allowed statement)?", S, Subp);
2934 elsif Nkind (S) = N_Block_Statement then
2935 if Present (Declarations (S))
2936 and then Has_Excluded_Declaration (Declarations (S))
2940 elsif Present (Handled_Statement_Sequence (S))
2943 (Exception_Handlers (Handled_Statement_Sequence (S)))
2945 Has_Excluded_Statement
2946 (Statements (Handled_Statement_Sequence (S))))
2951 elsif Nkind (S) = N_Case_Statement then
2952 E := First (Alternatives (S));
2953 while Present (E) loop
2954 if Has_Excluded_Statement (Statements (E)) then
2961 elsif Nkind (S) = N_If_Statement then
2962 if Has_Excluded_Statement (Then_Statements (S)) then
2966 if Present (Elsif_Parts (S)) then
2967 E := First (Elsif_Parts (S));
2968 while Present (E) loop
2969 if Has_Excluded_Statement (Then_Statements (E)) then
2976 if Present (Else_Statements (S))
2977 and then Has_Excluded_Statement (Else_Statements (S))
2982 elsif Nkind (S) = N_Loop_Statement
2983 and then Has_Excluded_Statement (Statements (S))
2992 end Has_Excluded_Statement;
2994 -------------------------------
2995 -- Has_Pending_Instantiation --
2996 -------------------------------
2998 function Has_Pending_Instantiation return Boolean is
3003 while Present (S) loop
3004 if Is_Compilation_Unit (S)
3005 or else Is_Child_Unit (S)
3008 elsif Ekind (S) = E_Package
3009 and then Has_Forward_Instantiation (S)
3018 end Has_Pending_Instantiation;
3020 ------------------------
3021 -- Has_Single_Return --
3022 ------------------------
3024 function Has_Single_Return return Boolean is
3025 Return_Statement : Node_Id := Empty;
3027 function Check_Return (N : Node_Id) return Traverse_Result;
3033 function Check_Return (N : Node_Id) return Traverse_Result is
3035 if Nkind (N) = N_Simple_Return_Statement then
3036 if Present (Expression (N))
3037 and then Is_Entity_Name (Expression (N))
3039 if No (Return_Statement) then
3040 Return_Statement := N;
3043 elsif Chars (Expression (N)) =
3044 Chars (Expression (Return_Statement))
3053 -- Expression has wrong form
3063 function Check_All_Returns is new Traverse_Func (Check_Return);
3065 -- Start of processing for Has_Single_Return
3068 return Check_All_Returns (N) = OK
3069 and then Present (Declarations (N))
3070 and then Present (First (Declarations (N)))
3071 and then Chars (Expression (Return_Statement)) =
3072 Chars (Defining_Identifier (First (Declarations (N))));
3073 end Has_Single_Return;
3075 --------------------
3076 -- Remove_Pragmas --
3077 --------------------
3079 procedure Remove_Pragmas is
3084 Decl := First (Declarations (Body_To_Analyze));
3085 while Present (Decl) loop
3088 if Nkind (Decl) = N_Pragma
3089 and then (Pragma_Name (Decl) = Name_Unreferenced
3091 Pragma_Name (Decl) = Name_Unmodified)
3100 --------------------------
3101 -- Uses_Secondary_Stack --
3102 --------------------------
3104 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is
3105 function Check_Call (N : Node_Id) return Traverse_Result;
3106 -- Look for function calls that return an unconstrained type
3112 function Check_Call (N : Node_Id) return Traverse_Result is
3114 if Nkind (N) = N_Function_Call
3115 and then Is_Entity_Name (Name (N))
3116 and then Is_Composite_Type (Etype (Entity (Name (N))))
3117 and then not Is_Constrained (Etype (Entity (Name (N))))
3120 ("cannot inline & (call returns unconstrained type)?",
3128 function Check_Calls is new Traverse_Func (Check_Call);
3131 return Check_Calls (Bod) = Abandon;
3132 end Uses_Secondary_Stack;
3134 -- Start of processing for Build_Body_To_Inline
3137 -- Return immediately if done already
3139 if Nkind (Decl) = N_Subprogram_Declaration
3140 and then Present (Body_To_Inline (Decl))
3144 -- Functions that return unconstrained composite types require
3145 -- secondary stack handling, and cannot currently be inlined, unless
3146 -- all return statements return a local variable that is the first
3147 -- local declaration in the body.
3149 elsif Ekind (Subp) = E_Function
3150 and then not Is_Scalar_Type (Etype (Subp))
3151 and then not Is_Access_Type (Etype (Subp))
3152 and then not Is_Constrained (Etype (Subp))
3154 if not Has_Single_Return then
3156 ("cannot inline & (unconstrained return type)?", N, Subp);
3160 -- Ditto for functions that return controlled types, where controlled
3161 -- actions interfere in complex ways with inlining.
3163 elsif Ekind (Subp) = E_Function
3164 and then Needs_Finalization (Etype (Subp))
3167 ("cannot inline & (controlled return type)?", N, Subp);
3171 if Present (Declarations (N))
3172 and then Has_Excluded_Declaration (Declarations (N))
3177 if Present (Handled_Statement_Sequence (N)) then
3178 if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then
3180 ("cannot inline& (exception handler)?",
3181 First (Exception_Handlers (Handled_Statement_Sequence (N))),
3185 Has_Excluded_Statement
3186 (Statements (Handled_Statement_Sequence (N)))
3192 -- We do not inline a subprogram that is too large, unless it is
3193 -- marked Inline_Always. This pragma does not suppress the other
3194 -- checks on inlining (forbidden declarations, handlers, etc).
3196 if Stat_Count > Max_Size
3197 and then not Has_Pragma_Inline_Always (Subp)
3199 Cannot_Inline ("cannot inline& (body too large)?", N, Subp);
3203 if Has_Pending_Instantiation then
3205 ("cannot inline& (forward instance within enclosing body)?",
3210 -- Within an instance, the body to inline must be treated as a nested
3211 -- generic, so that the proper global references are preserved.
3213 -- Note that we do not do this at the library level, because it is not
3214 -- needed, and furthermore this causes trouble if front end inlining
3215 -- is activated (-gnatN).
3217 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then
3218 Save_Env (Scope (Current_Scope), Scope (Current_Scope));
3219 Original_Body := Copy_Generic_Node (N, Empty, True);
3221 Original_Body := Copy_Separate_Tree (N);
3224 -- We need to capture references to the formals in order to substitute
3225 -- the actuals at the point of inlining, i.e. instantiation. To treat
3226 -- the formals as globals to the body to inline, we nest it within
3227 -- a dummy parameterless subprogram, declared within the real one.
3228 -- To avoid generating an internal name (which is never public, and
3229 -- which affects serial numbers of other generated names), we use
3230 -- an internal symbol that cannot conflict with user declarations.
3232 Set_Parameter_Specifications (Specification (Original_Body), No_List);
3233 Set_Defining_Unit_Name
3234 (Specification (Original_Body),
3235 Make_Defining_Identifier (Sloc (N), Name_uParent));
3236 Set_Corresponding_Spec (Original_Body, Empty);
3238 Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False);
3240 -- Set return type of function, which is also global and does not need
3243 if Ekind (Subp) = E_Function then
3244 Set_Result_Definition (Specification (Body_To_Analyze),
3245 New_Occurrence_Of (Etype (Subp), Sloc (N)));
3248 if No (Declarations (N)) then
3249 Set_Declarations (N, New_List (Body_To_Analyze));
3251 Append (Body_To_Analyze, Declarations (N));
3254 Expander_Mode_Save_And_Set (False);
3257 Analyze (Body_To_Analyze);
3258 Push_Scope (Defining_Entity (Body_To_Analyze));
3259 Save_Global_References (Original_Body);
3261 Remove (Body_To_Analyze);
3263 Expander_Mode_Restore;
3265 -- Restore environment if previously saved
3267 if In_Instance and then Scope (Current_Scope) /= Standard_Standard then
3271 -- If secondary stk used there is no point in inlining. We have
3272 -- already issued the warning in this case, so nothing to do.
3274 if Uses_Secondary_Stack (Body_To_Analyze) then
3278 Set_Body_To_Inline (Decl, Original_Body);
3279 Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp));
3280 Set_Is_Inlined (Subp);
3281 end Build_Body_To_Inline;
3287 procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is
3289 -- Do not emit warning if this is a predefined unit which is not
3290 -- the main unit. With validity checks enabled, some predefined
3291 -- subprograms may contain nested subprograms and become ineligible
3294 if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp)))
3295 and then not In_Extended_Main_Source_Unit (Subp)
3299 elsif Has_Pragma_Inline_Always (Subp) then
3301 -- Remove last character (question mark) to make this into an error,
3302 -- because the Inline_Always pragma cannot be obeyed.
3304 Error_Msg_NE (Msg (Msg'First .. Msg'Last - 1), N, Subp);
3306 elsif Ineffective_Inline_Warnings then
3307 Error_Msg_NE (Msg, N, Subp);
3311 -----------------------
3312 -- Check_Conformance --
3313 -----------------------
3315 procedure Check_Conformance
3316 (New_Id : Entity_Id;
3318 Ctype : Conformance_Type;
3320 Conforms : out Boolean;
3321 Err_Loc : Node_Id := Empty;
3322 Get_Inst : Boolean := False;
3323 Skip_Controlling_Formals : Boolean := False)
3325 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id);
3326 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
3327 -- If Errmsg is True, then processing continues to post an error message
3328 -- for conformance error on given node. Two messages are output. The
3329 -- first message points to the previous declaration with a general "no
3330 -- conformance" message. The second is the detailed reason, supplied as
3331 -- Msg. The parameter N provide information for a possible & insertion
3332 -- in the message, and also provides the location for posting the
3333 -- message in the absence of a specified Err_Loc location.
3335 -----------------------
3336 -- Conformance_Error --
3337 -----------------------
3339 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is
3346 if No (Err_Loc) then
3352 Error_Msg_Sloc := Sloc (Old_Id);
3355 when Type_Conformant =>
3357 ("not type conformant with declaration#!", Enode);
3359 when Mode_Conformant =>
3360 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3362 ("not mode conformant with operation inherited#!",
3366 ("not mode conformant with declaration#!", Enode);
3369 when Subtype_Conformant =>
3370 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3372 ("not subtype conformant with operation inherited#!",
3376 ("not subtype conformant with declaration#!", Enode);
3379 when Fully_Conformant =>
3380 if Nkind (Parent (Old_Id)) = N_Full_Type_Declaration then
3382 ("not fully conformant with operation inherited#!",
3386 ("not fully conformant with declaration#!", Enode);
3390 Error_Msg_NE (Msg, Enode, N);
3392 end Conformance_Error;
3396 Old_Type : constant Entity_Id := Etype (Old_Id);
3397 New_Type : constant Entity_Id := Etype (New_Id);
3398 Old_Formal : Entity_Id;
3399 New_Formal : Entity_Id;
3400 Access_Types_Match : Boolean;
3401 Old_Formal_Base : Entity_Id;
3402 New_Formal_Base : Entity_Id;
3404 -- Start of processing for Check_Conformance
3409 -- We need a special case for operators, since they don't appear
3412 if Ctype = Type_Conformant then
3413 if Ekind (New_Id) = E_Operator
3414 and then Operator_Matches_Spec (New_Id, Old_Id)
3420 -- If both are functions/operators, check return types conform
3422 if Old_Type /= Standard_Void_Type
3423 and then New_Type /= Standard_Void_Type
3426 -- If we are checking interface conformance we omit controlling
3427 -- arguments and result, because we are only checking the conformance
3428 -- of the remaining parameters.
3430 if Has_Controlling_Result (Old_Id)
3431 and then Has_Controlling_Result (New_Id)
3432 and then Skip_Controlling_Formals
3436 elsif not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then
3437 Conformance_Error ("\return type does not match!", New_Id);
3441 -- Ada 2005 (AI-231): In case of anonymous access types check the
3442 -- null-exclusion and access-to-constant attributes match.
3444 if Ada_Version >= Ada_05
3445 and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type
3447 (Can_Never_Be_Null (Old_Type)
3448 /= Can_Never_Be_Null (New_Type)
3449 or else Is_Access_Constant (Etype (Old_Type))
3450 /= Is_Access_Constant (Etype (New_Type)))
3452 Conformance_Error ("\return type does not match!", New_Id);
3456 -- If either is a function/operator and the other isn't, error
3458 elsif Old_Type /= Standard_Void_Type
3459 or else New_Type /= Standard_Void_Type
3461 Conformance_Error ("\functions can only match functions!", New_Id);
3465 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
3466 -- If this is a renaming as body, refine error message to indicate that
3467 -- the conflict is with the original declaration. If the entity is not
3468 -- frozen, the conventions don't have to match, the one of the renamed
3469 -- entity is inherited.
3471 if Ctype >= Subtype_Conformant then
3472 if Convention (Old_Id) /= Convention (New_Id) then
3474 if not Is_Frozen (New_Id) then
3477 elsif Present (Err_Loc)
3478 and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration
3479 and then Present (Corresponding_Spec (Err_Loc))
3481 Error_Msg_Name_1 := Chars (New_Id);
3483 Name_Ada + Convention_Id'Pos (Convention (New_Id));
3485 Conformance_Error ("\prior declaration for% has convention %!");
3488 Conformance_Error ("\calling conventions do not match!");
3493 elsif Is_Formal_Subprogram (Old_Id)
3494 or else Is_Formal_Subprogram (New_Id)
3496 Conformance_Error ("\formal subprograms not allowed!");
3501 -- Deal with parameters
3503 -- Note: we use the entity information, rather than going directly
3504 -- to the specification in the tree. This is not only simpler, but
3505 -- absolutely necessary for some cases of conformance tests between
3506 -- operators, where the declaration tree simply does not exist!
3508 Old_Formal := First_Formal (Old_Id);
3509 New_Formal := First_Formal (New_Id);
3510 while Present (Old_Formal) and then Present (New_Formal) loop
3511 if Is_Controlling_Formal (Old_Formal)
3512 and then Is_Controlling_Formal (New_Formal)
3513 and then Skip_Controlling_Formals
3515 -- The controlling formals will have different types when
3516 -- comparing an interface operation with its match, but both
3517 -- or neither must be access parameters.
3519 if Is_Access_Type (Etype (Old_Formal))
3521 Is_Access_Type (Etype (New_Formal))
3523 goto Skip_Controlling_Formal;
3526 ("\access parameter does not match!", New_Formal);
3530 if Ctype = Fully_Conformant then
3532 -- Names must match. Error message is more accurate if we do
3533 -- this before checking that the types of the formals match.
3535 if Chars (Old_Formal) /= Chars (New_Formal) then
3536 Conformance_Error ("\name & does not match!", New_Formal);
3538 -- Set error posted flag on new formal as well to stop
3539 -- junk cascaded messages in some cases.
3541 Set_Error_Posted (New_Formal);
3546 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
3547 -- case occurs whenever a subprogram is being renamed and one of its
3548 -- parameters imposes a null exclusion. For example:
3550 -- type T is null record;
3551 -- type Acc_T is access T;
3552 -- subtype Acc_T_Sub is Acc_T;
3554 -- procedure P (Obj : not null Acc_T_Sub); -- itype
3555 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
3558 Old_Formal_Base := Etype (Old_Formal);
3559 New_Formal_Base := Etype (New_Formal);
3562 Old_Formal_Base := Get_Instance_Of (Old_Formal_Base);
3563 New_Formal_Base := Get_Instance_Of (New_Formal_Base);
3566 Access_Types_Match := Ada_Version >= Ada_05
3568 -- Ensure that this rule is only applied when New_Id is a
3569 -- renaming of Old_Id.
3571 and then Nkind (Parent (Parent (New_Id))) =
3572 N_Subprogram_Renaming_Declaration
3573 and then Nkind (Name (Parent (Parent (New_Id)))) in N_Has_Entity
3574 and then Present (Entity (Name (Parent (Parent (New_Id)))))
3575 and then Entity (Name (Parent (Parent (New_Id)))) = Old_Id
3577 -- Now handle the allowed access-type case
3579 and then Is_Access_Type (Old_Formal_Base)
3580 and then Is_Access_Type (New_Formal_Base)
3582 -- The type kinds must match. The only exception occurs with
3583 -- multiple generics of the form:
3586 -- type F is private; type A is private;
3587 -- type F_Ptr is access F; type A_Ptr is access A;
3588 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
3589 -- package F_Pack is ... package A_Pack is
3590 -- package F_Inst is
3591 -- new F_Pack (A, A_Ptr, A_P);
3593 -- When checking for conformance between the parameters of A_P
3594 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
3595 -- because the compiler has transformed A_Ptr into a subtype of
3596 -- F_Ptr. We catch this case in the code below.
3598 and then (Ekind (Old_Formal_Base) = Ekind (New_Formal_Base)
3600 (Is_Generic_Type (Old_Formal_Base)
3601 and then Is_Generic_Type (New_Formal_Base)
3602 and then Is_Internal (New_Formal_Base)
3603 and then Etype (Etype (New_Formal_Base)) =
3605 and then Directly_Designated_Type (Old_Formal_Base) =
3606 Directly_Designated_Type (New_Formal_Base)
3607 and then ((Is_Itype (Old_Formal_Base)
3608 and then Can_Never_Be_Null (Old_Formal_Base))
3610 (Is_Itype (New_Formal_Base)
3611 and then Can_Never_Be_Null (New_Formal_Base)));
3613 -- Types must always match. In the visible part of an instance,
3614 -- usual overloading rules for dispatching operations apply, and
3615 -- we check base types (not the actual subtypes).
3617 if In_Instance_Visible_Part
3618 and then Is_Dispatching_Operation (New_Id)
3620 if not Conforming_Types
3621 (T1 => Base_Type (Etype (Old_Formal)),
3622 T2 => Base_Type (Etype (New_Formal)),
3624 Get_Inst => Get_Inst)
3625 and then not Access_Types_Match
3627 Conformance_Error ("\type of & does not match!", New_Formal);
3631 elsif not Conforming_Types
3632 (T1 => Old_Formal_Base,
3633 T2 => New_Formal_Base,
3635 Get_Inst => Get_Inst)
3636 and then not Access_Types_Match
3638 -- Don't give error message if old type is Any_Type. This test
3639 -- avoids some cascaded errors, e.g. in case of a bad spec.
3641 if Errmsg and then Old_Formal_Base = Any_Type then
3644 Conformance_Error ("\type of & does not match!", New_Formal);
3650 -- For mode conformance, mode must match
3652 if Ctype >= Mode_Conformant then
3653 if Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal) then
3654 Conformance_Error ("\mode of & does not match!", New_Formal);
3657 -- Part of mode conformance for access types is having the same
3658 -- constant modifier.
3660 elsif Access_Types_Match
3661 and then Is_Access_Constant (Old_Formal_Base) /=
3662 Is_Access_Constant (New_Formal_Base)
3665 ("\constant modifier does not match!", New_Formal);
3670 if Ctype >= Subtype_Conformant then
3672 -- Ada 2005 (AI-231): In case of anonymous access types check
3673 -- the null-exclusion and access-to-constant attributes must
3676 if Ada_Version >= Ada_05
3677 and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type
3678 and then Ekind (Etype (New_Formal)) = E_Anonymous_Access_Type
3680 (Can_Never_Be_Null (Old_Formal) /=
3681 Can_Never_Be_Null (New_Formal)
3683 Is_Access_Constant (Etype (Old_Formal)) /=
3684 Is_Access_Constant (Etype (New_Formal)))
3686 -- It is allowed to omit the null-exclusion in case of stream
3687 -- attribute subprograms. We recognize stream subprograms
3688 -- through their TSS-generated suffix.
3691 TSS_Name : constant TSS_Name_Type := Get_TSS_Name (New_Id);
3693 if TSS_Name /= TSS_Stream_Read
3694 and then TSS_Name /= TSS_Stream_Write
3695 and then TSS_Name /= TSS_Stream_Input
3696 and then TSS_Name /= TSS_Stream_Output
3699 ("\type of & does not match!", New_Formal);
3706 -- Full conformance checks
3708 if Ctype = Fully_Conformant then
3710 -- We have checked already that names match
3712 if Parameter_Mode (Old_Formal) = E_In_Parameter then
3714 -- Check default expressions for in parameters
3717 NewD : constant Boolean :=
3718 Present (Default_Value (New_Formal));
3719 OldD : constant Boolean :=
3720 Present (Default_Value (Old_Formal));
3722 if NewD or OldD then
3724 -- The old default value has been analyzed because the
3725 -- current full declaration will have frozen everything
3726 -- before. The new default value has not been analyzed,
3727 -- so analyze it now before we check for conformance.
3730 Push_Scope (New_Id);
3731 Preanalyze_Spec_Expression
3732 (Default_Value (New_Formal), Etype (New_Formal));
3736 if not (NewD and OldD)
3737 or else not Fully_Conformant_Expressions
3738 (Default_Value (Old_Formal),
3739 Default_Value (New_Formal))
3742 ("\default expression for & does not match!",
3751 -- A couple of special checks for Ada 83 mode. These checks are
3752 -- skipped if either entity is an operator in package Standard,
3753 -- or if either old or new instance is not from the source program.
3755 if Ada_Version = Ada_83
3756 and then Sloc (Old_Id) > Standard_Location
3757 and then Sloc (New_Id) > Standard_Location
3758 and then Comes_From_Source (Old_Id)
3759 and then Comes_From_Source (New_Id)
3762 Old_Param : constant Node_Id := Declaration_Node (Old_Formal);
3763 New_Param : constant Node_Id := Declaration_Node (New_Formal);
3766 -- Explicit IN must be present or absent in both cases. This
3767 -- test is required only in the full conformance case.
3769 if In_Present (Old_Param) /= In_Present (New_Param)
3770 and then Ctype = Fully_Conformant
3773 ("\(Ada 83) IN must appear in both declarations",
3778 -- Grouping (use of comma in param lists) must be the same
3779 -- This is where we catch a misconformance like:
3782 -- A : Integer; B : Integer
3784 -- which are represented identically in the tree except
3785 -- for the setting of the flags More_Ids and Prev_Ids.
3787 if More_Ids (Old_Param) /= More_Ids (New_Param)
3788 or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param)
3791 ("\grouping of & does not match!", New_Formal);
3797 -- This label is required when skipping controlling formals
3799 <<Skip_Controlling_Formal>>
3801 Next_Formal (Old_Formal);
3802 Next_Formal (New_Formal);
3805 if Present (Old_Formal) then
3806 Conformance_Error ("\too few parameters!");
3809 elsif Present (New_Formal) then
3810 Conformance_Error ("\too many parameters!", New_Formal);
3813 end Check_Conformance;
3815 -----------------------
3816 -- Check_Conventions --
3817 -----------------------
3819 procedure Check_Conventions (Typ : Entity_Id) is
3820 Ifaces_List : Elist_Id;
3822 procedure Check_Convention (Op : Entity_Id);
3823 -- Verify that the convention of inherited dispatching operation Op is
3824 -- consistent among all subprograms it overrides. In order to minimize
3825 -- the search, Search_From is utilized to designate a specific point in
3826 -- the list rather than iterating over the whole list once more.
3828 ----------------------
3829 -- Check_Convention --
3830 ----------------------
3832 procedure Check_Convention (Op : Entity_Id) is
3833 Iface_Elmt : Elmt_Id;
3834 Iface_Prim_Elmt : Elmt_Id;
3835 Iface_Prim : Entity_Id;
3838 Iface_Elmt := First_Elmt (Ifaces_List);
3839 while Present (Iface_Elmt) loop
3841 First_Elmt (Primitive_Operations (Node (Iface_Elmt)));
3842 while Present (Iface_Prim_Elmt) loop
3843 Iface_Prim := Node (Iface_Prim_Elmt);
3845 if Is_Interface_Conformant (Typ, Iface_Prim, Op)
3846 and then Convention (Iface_Prim) /= Convention (Op)
3849 ("inconsistent conventions in primitive operations", Typ);
3851 Error_Msg_Name_1 := Chars (Op);
3852 Error_Msg_Name_2 := Get_Convention_Name (Convention (Op));
3853 Error_Msg_Sloc := Sloc (Op);
3855 if Comes_From_Source (Op) then
3856 if not Is_Overriding_Operation (Op) then
3857 Error_Msg_N ("\\primitive % defined #", Typ);
3859 Error_Msg_N ("\\overriding operation % with " &
3860 "convention % defined #", Typ);
3863 else pragma Assert (Present (Alias (Op)));
3864 Error_Msg_Sloc := Sloc (Alias (Op));
3865 Error_Msg_N ("\\inherited operation % with " &
3866 "convention % defined #", Typ);
3869 Error_Msg_Name_1 := Chars (Op);
3871 Get_Convention_Name (Convention (Iface_Prim));
3872 Error_Msg_Sloc := Sloc (Iface_Prim);
3873 Error_Msg_N ("\\overridden operation % with " &
3874 "convention % defined #", Typ);
3876 -- Avoid cascading errors
3881 Next_Elmt (Iface_Prim_Elmt);
3884 Next_Elmt (Iface_Elmt);
3886 end Check_Convention;
3890 Prim_Op : Entity_Id;
3891 Prim_Op_Elmt : Elmt_Id;
3893 -- Start of processing for Check_Conventions
3896 if not Has_Interfaces (Typ) then
3900 Collect_Interfaces (Typ, Ifaces_List);
3902 -- The algorithm checks every overriding dispatching operation against
3903 -- all the corresponding overridden dispatching operations, detecting
3904 -- differences in conventions.
3906 Prim_Op_Elmt := First_Elmt (Primitive_Operations (Typ));
3907 while Present (Prim_Op_Elmt) loop
3908 Prim_Op := Node (Prim_Op_Elmt);
3910 -- A small optimization: skip the predefined dispatching operations
3911 -- since they always have the same convention.
3913 if not Is_Predefined_Dispatching_Operation (Prim_Op) then
3914 Check_Convention (Prim_Op);
3917 Next_Elmt (Prim_Op_Elmt);
3919 end Check_Conventions;
3921 ------------------------------
3922 -- Check_Delayed_Subprogram --
3923 ------------------------------
3925 procedure Check_Delayed_Subprogram (Designator : Entity_Id) is
3928 procedure Possible_Freeze (T : Entity_Id);
3929 -- T is the type of either a formal parameter or of the return type.
3930 -- If T is not yet frozen and needs a delayed freeze, then the
3931 -- subprogram itself must be delayed. If T is the limited view of
3932 -- of an incomplete type the subprogram must be frozen as well,
3933 -- because T may depend on local types that have not been frozen yet.
3935 ---------------------
3936 -- Possible_Freeze --
3937 ---------------------
3939 procedure Possible_Freeze (T : Entity_Id) is
3941 if Has_Delayed_Freeze (T)
3942 and then not Is_Frozen (T)
3944 Set_Has_Delayed_Freeze (Designator);
3946 elsif Is_Access_Type (T)
3947 and then Has_Delayed_Freeze (Designated_Type (T))
3948 and then not Is_Frozen (Designated_Type (T))
3950 Set_Has_Delayed_Freeze (Designator);
3952 elsif Ekind (T) = E_Incomplete_Type
3953 and then From_With_Type (T)
3955 Set_Has_Delayed_Freeze (Designator);
3957 end Possible_Freeze;
3959 -- Start of processing for Check_Delayed_Subprogram
3962 -- Never need to freeze abstract subprogram
3964 if Ekind (Designator) /= E_Subprogram_Type
3965 and then Is_Abstract_Subprogram (Designator)
3969 -- Need delayed freeze if return type itself needs a delayed
3970 -- freeze and is not yet frozen.
3972 Possible_Freeze (Etype (Designator));
3973 Possible_Freeze (Base_Type (Etype (Designator))); -- needed ???
3975 -- Need delayed freeze if any of the formal types themselves need
3976 -- a delayed freeze and are not yet frozen.
3978 F := First_Formal (Designator);
3979 while Present (F) loop
3980 Possible_Freeze (Etype (F));
3981 Possible_Freeze (Base_Type (Etype (F))); -- needed ???
3986 -- Mark functions that return by reference. Note that it cannot be
3987 -- done for delayed_freeze subprograms because the underlying
3988 -- returned type may not be known yet (for private types)
3990 if not Has_Delayed_Freeze (Designator)
3991 and then Expander_Active
3994 Typ : constant Entity_Id := Etype (Designator);
3995 Utyp : constant Entity_Id := Underlying_Type (Typ);
3998 if Is_Inherently_Limited_Type (Typ) then
3999 Set_Returns_By_Ref (Designator);
4001 elsif Present (Utyp) and then CW_Or_Has_Controlled_Part (Utyp) then
4002 Set_Returns_By_Ref (Designator);
4006 end Check_Delayed_Subprogram;
4008 ------------------------------------
4009 -- Check_Discriminant_Conformance --
4010 ------------------------------------
4012 procedure Check_Discriminant_Conformance
4017 Old_Discr : Entity_Id := First_Discriminant (Prev);
4018 New_Discr : Node_Id := First (Discriminant_Specifications (N));
4019 New_Discr_Id : Entity_Id;
4020 New_Discr_Type : Entity_Id;
4022 procedure Conformance_Error (Msg : String; N : Node_Id);
4023 -- Post error message for conformance error on given node. Two messages
4024 -- are output. The first points to the previous declaration with a
4025 -- general "no conformance" message. The second is the detailed reason,
4026 -- supplied as Msg. The parameter N provide information for a possible
4027 -- & insertion in the message.
4029 -----------------------
4030 -- Conformance_Error --
4031 -----------------------
4033 procedure Conformance_Error (Msg : String; N : Node_Id) is
4035 Error_Msg_Sloc := Sloc (Prev_Loc);
4036 Error_Msg_N ("not fully conformant with declaration#!", N);
4037 Error_Msg_NE (Msg, N, N);
4038 end Conformance_Error;
4040 -- Start of processing for Check_Discriminant_Conformance
4043 while Present (Old_Discr) and then Present (New_Discr) loop
4045 New_Discr_Id := Defining_Identifier (New_Discr);
4047 -- The subtype mark of the discriminant on the full type has not
4048 -- been analyzed so we do it here. For an access discriminant a new
4051 if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then
4053 Access_Definition (N, Discriminant_Type (New_Discr));
4056 Analyze (Discriminant_Type (New_Discr));
4057 New_Discr_Type := Etype (Discriminant_Type (New_Discr));
4059 -- Ada 2005: if the discriminant definition carries a null
4060 -- exclusion, create an itype to check properly for consistency
4061 -- with partial declaration.
4063 if Is_Access_Type (New_Discr_Type)
4064 and then Null_Exclusion_Present (New_Discr)
4067 Create_Null_Excluding_Itype
4068 (T => New_Discr_Type,
4069 Related_Nod => New_Discr,
4070 Scope_Id => Current_Scope);
4074 if not Conforming_Types
4075 (Etype (Old_Discr), New_Discr_Type, Fully_Conformant)
4077 Conformance_Error ("type of & does not match!", New_Discr_Id);
4080 -- Treat the new discriminant as an occurrence of the old one,
4081 -- for navigation purposes, and fill in some semantic
4082 -- information, for completeness.
4084 Generate_Reference (Old_Discr, New_Discr_Id, 'r');
4085 Set_Etype (New_Discr_Id, Etype (Old_Discr));
4086 Set_Scope (New_Discr_Id, Scope (Old_Discr));
4091 if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then
4092 Conformance_Error ("name & does not match!", New_Discr_Id);
4096 -- Default expressions must match
4099 NewD : constant Boolean :=
4100 Present (Expression (New_Discr));
4101 OldD : constant Boolean :=
4102 Present (Expression (Parent (Old_Discr)));
4105 if NewD or OldD then
4107 -- The old default value has been analyzed and expanded,
4108 -- because the current full declaration will have frozen
4109 -- everything before. The new default values have not been
4110 -- expanded, so expand now to check conformance.
4113 Preanalyze_Spec_Expression
4114 (Expression (New_Discr), New_Discr_Type);
4117 if not (NewD and OldD)
4118 or else not Fully_Conformant_Expressions
4119 (Expression (Parent (Old_Discr)),
4120 Expression (New_Discr))
4124 ("default expression for & does not match!",
4131 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
4133 if Ada_Version = Ada_83 then
4135 Old_Disc : constant Node_Id := Declaration_Node (Old_Discr);
4138 -- Grouping (use of comma in param lists) must be the same
4139 -- This is where we catch a misconformance like:
4142 -- A : Integer; B : Integer
4144 -- which are represented identically in the tree except
4145 -- for the setting of the flags More_Ids and Prev_Ids.
4147 if More_Ids (Old_Disc) /= More_Ids (New_Discr)
4148 or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr)
4151 ("grouping of & does not match!", New_Discr_Id);
4157 Next_Discriminant (Old_Discr);
4161 if Present (Old_Discr) then
4162 Conformance_Error ("too few discriminants!", Defining_Identifier (N));
4165 elsif Present (New_Discr) then
4167 ("too many discriminants!", Defining_Identifier (New_Discr));
4170 end Check_Discriminant_Conformance;
4172 ----------------------------
4173 -- Check_Fully_Conformant --
4174 ----------------------------
4176 procedure Check_Fully_Conformant
4177 (New_Id : Entity_Id;
4179 Err_Loc : Node_Id := Empty)
4182 pragma Warnings (Off, Result);
4185 (New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc);
4186 end Check_Fully_Conformant;
4188 ---------------------------
4189 -- Check_Mode_Conformant --
4190 ---------------------------
4192 procedure Check_Mode_Conformant
4193 (New_Id : Entity_Id;
4195 Err_Loc : Node_Id := Empty;
4196 Get_Inst : Boolean := False)
4199 pragma Warnings (Off, Result);
4202 (New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst);
4203 end Check_Mode_Conformant;
4205 --------------------------------
4206 -- Check_Overriding_Indicator --
4207 --------------------------------
4209 procedure Check_Overriding_Indicator
4211 Overridden_Subp : Entity_Id;
4212 Is_Primitive : Boolean)
4218 -- No overriding indicator for literals
4220 if Ekind (Subp) = E_Enumeration_Literal then
4223 elsif Ekind (Subp) = E_Entry then
4224 Decl := Parent (Subp);
4227 Decl := Unit_Declaration_Node (Subp);
4230 if Nkind_In (Decl, N_Subprogram_Body,
4231 N_Subprogram_Body_Stub,
4232 N_Subprogram_Declaration,
4233 N_Abstract_Subprogram_Declaration,
4234 N_Subprogram_Renaming_Declaration)
4236 Spec := Specification (Decl);
4238 elsif Nkind (Decl) = N_Entry_Declaration then
4245 if Present (Overridden_Subp) then
4246 if Must_Not_Override (Spec) then
4247 Error_Msg_Sloc := Sloc (Overridden_Subp);
4249 if Ekind (Subp) = E_Entry then
4251 ("entry & overrides inherited operation #", Spec, Subp);
4254 ("subprogram & overrides inherited operation #", Spec, Subp);
4257 elsif Is_Subprogram (Subp) then
4258 Set_Is_Overriding_Operation (Subp);
4261 -- If primitive flag is set, operation is overriding at the
4262 -- point of its declaration, so warn if necessary. Otherwise
4263 -- it may have been declared before the operation it overrides
4264 -- and no check is required.
4267 and then not Must_Override (Spec)
4268 and then Is_Primitive
4270 Style.Missing_Overriding (Decl, Subp);
4273 -- If Subp is an operator, it may override a predefined operation.
4274 -- In that case overridden_subp is empty because of our implicit
4275 -- representation for predefined operators. We have to check whether the
4276 -- signature of Subp matches that of a predefined operator. Note that
4277 -- first argument provides the name of the operator, and the second
4278 -- argument the signature that may match that of a standard operation.
4279 -- If the indicator is overriding, then the operator must match a
4280 -- predefined signature, because we know already that there is no
4281 -- explicit overridden operation.
4283 elsif Nkind (Subp) = N_Defining_Operator_Symbol then
4285 if Must_Not_Override (Spec) then
4286 if not Is_Primitive then
4288 ("overriding indicator only allowed "
4289 & "if subprogram is primitive", Subp);
4291 elsif Operator_Matches_Spec (Subp, Subp) then
4293 ("subprogram & overrides predefined operator ", Spec, Subp);
4296 elsif Must_Override (Spec) then
4297 if Is_Overriding_Operation (Subp) then
4298 Set_Is_Overriding_Operation (Subp);
4300 elsif not Operator_Matches_Spec (Subp, Subp) then
4301 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
4304 elsif not Error_Posted (Subp)
4305 and then Style_Check
4306 and then Operator_Matches_Spec (Subp, Subp)
4308 not Is_Predefined_File_Name
4309 (Unit_File_Name (Get_Source_Unit (Subp)))
4311 Set_Is_Overriding_Operation (Subp);
4312 Style.Missing_Overriding (Decl, Subp);
4315 elsif Must_Override (Spec) then
4316 if Ekind (Subp) = E_Entry then
4317 Error_Msg_NE ("entry & is not overriding", Spec, Subp);
4319 Error_Msg_NE ("subprogram & is not overriding", Spec, Subp);
4322 -- If the operation is marked "not overriding" and it's not primitive
4323 -- then an error is issued, unless this is an operation of a task or
4324 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
4325 -- has been specified have already been checked above.
4327 elsif Must_Not_Override (Spec)
4328 and then not Is_Primitive
4329 and then Ekind (Subp) /= E_Entry
4330 and then Ekind (Scope (Subp)) /= E_Protected_Type
4333 ("overriding indicator only allowed if subprogram is primitive",
4337 end Check_Overriding_Indicator;
4343 -- Note: this procedure needs to know far too much about how the expander
4344 -- messes with exceptions. The use of the flag Exception_Junk and the
4345 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
4346 -- works, but is not very clean. It would be better if the expansion
4347 -- routines would leave Original_Node working nicely, and we could use
4348 -- Original_Node here to ignore all the peculiar expander messing ???
4350 procedure Check_Returns
4354 Proc : Entity_Id := Empty)
4358 procedure Check_Statement_Sequence (L : List_Id);
4359 -- Internal recursive procedure to check a list of statements for proper
4360 -- termination by a return statement (or a transfer of control or a
4361 -- compound statement that is itself internally properly terminated).
4363 ------------------------------
4364 -- Check_Statement_Sequence --
4365 ------------------------------
4367 procedure Check_Statement_Sequence (L : List_Id) is
4372 Raise_Exception_Call : Boolean;
4373 -- Set True if statement sequence terminated by Raise_Exception call
4374 -- or a Reraise_Occurrence call.
4377 Raise_Exception_Call := False;
4379 -- Get last real statement
4381 Last_Stm := Last (L);
4383 -- Deal with digging out exception handler statement sequences that
4384 -- have been transformed by the local raise to goto optimization.
4385 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
4386 -- optimization has occurred, we are looking at something like:
4389 -- original stmts in block
4393 -- goto L1; | omitted if No_Exception_Propagation
4398 -- goto L3; -- skip handler when exception not raised
4400 -- <<L1>> -- target label for local exception
4414 -- and what we have to do is to dig out the estmts1 and estmts2
4415 -- sequences (which were the original sequences of statements in
4416 -- the exception handlers) and check them.
4418 if Nkind (Last_Stm) = N_Label
4419 and then Exception_Junk (Last_Stm)
4425 exit when Nkind (Stm) /= N_Block_Statement;
4426 exit when not Exception_Junk (Stm);
4429 exit when Nkind (Stm) /= N_Label;
4430 exit when not Exception_Junk (Stm);
4431 Check_Statement_Sequence
4432 (Statements (Handled_Statement_Sequence (Next (Stm))));
4437 exit when Nkind (Stm) /= N_Goto_Statement;
4438 exit when not Exception_Junk (Stm);
4442 -- Don't count pragmas
4444 while Nkind (Last_Stm) = N_Pragma
4446 -- Don't count call to SS_Release (can happen after Raise_Exception)
4449 (Nkind (Last_Stm) = N_Procedure_Call_Statement
4451 Nkind (Name (Last_Stm)) = N_Identifier
4453 Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release))
4455 -- Don't count exception junk
4458 (Nkind_In (Last_Stm, N_Goto_Statement,
4460 N_Object_Declaration)
4461 and then Exception_Junk (Last_Stm))
4462 or else Nkind (Last_Stm) in N_Push_xxx_Label
4463 or else Nkind (Last_Stm) in N_Pop_xxx_Label
4468 -- Here we have the "real" last statement
4470 Kind := Nkind (Last_Stm);
4472 -- Transfer of control, OK. Note that in the No_Return procedure
4473 -- case, we already diagnosed any explicit return statements, so
4474 -- we can treat them as OK in this context.
4476 if Is_Transfer (Last_Stm) then
4479 -- Check cases of explicit non-indirect procedure calls
4481 elsif Kind = N_Procedure_Call_Statement
4482 and then Is_Entity_Name (Name (Last_Stm))
4484 -- Check call to Raise_Exception procedure which is treated
4485 -- specially, as is a call to Reraise_Occurrence.
4487 -- We suppress the warning in these cases since it is likely that
4488 -- the programmer really does not expect to deal with the case
4489 -- of Null_Occurrence, and thus would find a warning about a
4490 -- missing return curious, and raising Program_Error does not
4491 -- seem such a bad behavior if this does occur.
4493 -- Note that in the Ada 2005 case for Raise_Exception, the actual
4494 -- behavior will be to raise Constraint_Error (see AI-329).
4496 if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception)
4498 Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence)
4500 Raise_Exception_Call := True;
4502 -- For Raise_Exception call, test first argument, if it is
4503 -- an attribute reference for a 'Identity call, then we know
4504 -- that the call cannot possibly return.
4507 Arg : constant Node_Id :=
4508 Original_Node (First_Actual (Last_Stm));
4510 if Nkind (Arg) = N_Attribute_Reference
4511 and then Attribute_Name (Arg) = Name_Identity
4518 -- If statement, need to look inside if there is an else and check
4519 -- each constituent statement sequence for proper termination.
4521 elsif Kind = N_If_Statement
4522 and then Present (Else_Statements (Last_Stm))
4524 Check_Statement_Sequence (Then_Statements (Last_Stm));
4525 Check_Statement_Sequence (Else_Statements (Last_Stm));
4527 if Present (Elsif_Parts (Last_Stm)) then
4529 Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm));
4532 while Present (Elsif_Part) loop
4533 Check_Statement_Sequence (Then_Statements (Elsif_Part));
4541 -- Case statement, check each case for proper termination
4543 elsif Kind = N_Case_Statement then
4547 Case_Alt := First_Non_Pragma (Alternatives (Last_Stm));
4548 while Present (Case_Alt) loop
4549 Check_Statement_Sequence (Statements (Case_Alt));
4550 Next_Non_Pragma (Case_Alt);
4556 -- Block statement, check its handled sequence of statements
4558 elsif Kind = N_Block_Statement then
4564 (Handled_Statement_Sequence (Last_Stm), Mode, Err1);
4573 -- Loop statement. If there is an iteration scheme, we can definitely
4574 -- fall out of the loop. Similarly if there is an exit statement, we
4575 -- can fall out. In either case we need a following return.
4577 elsif Kind = N_Loop_Statement then
4578 if Present (Iteration_Scheme (Last_Stm))
4579 or else Has_Exit (Entity (Identifier (Last_Stm)))
4583 -- A loop with no exit statement or iteration scheme is either
4584 -- an infinite loop, or it has some other exit (raise/return).
4585 -- In either case, no warning is required.
4591 -- Timed entry call, check entry call and delay alternatives
4593 -- Note: in expanded code, the timed entry call has been converted
4594 -- to a set of expanded statements on which the check will work
4595 -- correctly in any case.
4597 elsif Kind = N_Timed_Entry_Call then
4599 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
4600 DCA : constant Node_Id := Delay_Alternative (Last_Stm);
4603 -- If statement sequence of entry call alternative is missing,
4604 -- then we can definitely fall through, and we post the error
4605 -- message on the entry call alternative itself.
4607 if No (Statements (ECA)) then
4610 -- If statement sequence of delay alternative is missing, then
4611 -- we can definitely fall through, and we post the error
4612 -- message on the delay alternative itself.
4614 -- Note: if both ECA and DCA are missing the return, then we
4615 -- post only one message, should be enough to fix the bugs.
4616 -- If not we will get a message next time on the DCA when the
4619 elsif No (Statements (DCA)) then
4622 -- Else check both statement sequences
4625 Check_Statement_Sequence (Statements (ECA));
4626 Check_Statement_Sequence (Statements (DCA));
4631 -- Conditional entry call, check entry call and else part
4633 -- Note: in expanded code, the conditional entry call has been
4634 -- converted to a set of expanded statements on which the check
4635 -- will work correctly in any case.
4637 elsif Kind = N_Conditional_Entry_Call then
4639 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
4642 -- If statement sequence of entry call alternative is missing,
4643 -- then we can definitely fall through, and we post the error
4644 -- message on the entry call alternative itself.
4646 if No (Statements (ECA)) then
4649 -- Else check statement sequence and else part
4652 Check_Statement_Sequence (Statements (ECA));
4653 Check_Statement_Sequence (Else_Statements (Last_Stm));
4659 -- If we fall through, issue appropriate message
4662 if not Raise_Exception_Call then
4664 ("?RETURN statement missing following this statement!",
4667 ("\?Program_Error may be raised at run time!",
4671 -- Note: we set Err even though we have not issued a warning
4672 -- because we still have a case of a missing return. This is
4673 -- an extremely marginal case, probably will never be noticed
4674 -- but we might as well get it right.
4678 -- Otherwise we have the case of a procedure marked No_Return
4681 if not Raise_Exception_Call then
4683 ("?implied return after this statement " &
4684 "will raise Program_Error",
4687 ("\?procedure & is marked as No_Return!",
4692 RE : constant Node_Id :=
4693 Make_Raise_Program_Error (Sloc (Last_Stm),
4694 Reason => PE_Implicit_Return);
4696 Insert_After (Last_Stm, RE);
4700 end Check_Statement_Sequence;
4702 -- Start of processing for Check_Returns
4706 Check_Statement_Sequence (Statements (HSS));
4708 if Present (Exception_Handlers (HSS)) then
4709 Handler := First_Non_Pragma (Exception_Handlers (HSS));
4710 while Present (Handler) loop
4711 Check_Statement_Sequence (Statements (Handler));
4712 Next_Non_Pragma (Handler);
4717 ----------------------------
4718 -- Check_Subprogram_Order --
4719 ----------------------------
4721 procedure Check_Subprogram_Order (N : Node_Id) is
4723 function Subprogram_Name_Greater (S1, S2 : String) return Boolean;
4724 -- This is used to check if S1 > S2 in the sense required by this
4725 -- test, for example nameab < namec, but name2 < name10.
4727 -----------------------------
4728 -- Subprogram_Name_Greater --
4729 -----------------------------
4731 function Subprogram_Name_Greater (S1, S2 : String) return Boolean is
4736 -- Remove trailing numeric parts
4739 while S1 (L1) in '0' .. '9' loop
4744 while S2 (L2) in '0' .. '9' loop
4748 -- If non-numeric parts non-equal, that's decisive
4750 if S1 (S1'First .. L1) < S2 (S2'First .. L2) then
4753 elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then
4756 -- If non-numeric parts equal, compare suffixed numeric parts. Note
4757 -- that a missing suffix is treated as numeric zero in this test.
4761 while L1 < S1'Last loop
4763 N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0');
4767 while L2 < S2'Last loop
4769 N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0');
4774 end Subprogram_Name_Greater;
4776 -- Start of processing for Check_Subprogram_Order
4779 -- Check body in alpha order if this is option
4782 and then Style_Check_Order_Subprograms
4783 and then Nkind (N) = N_Subprogram_Body
4784 and then Comes_From_Source (N)
4785 and then In_Extended_Main_Source_Unit (N)
4789 renames Scope_Stack.Table
4790 (Scope_Stack.Last).Last_Subprogram_Name;
4792 Body_Id : constant Entity_Id :=
4793 Defining_Entity (Specification (N));
4796 Get_Decoded_Name_String (Chars (Body_Id));
4799 if Subprogram_Name_Greater
4800 (LSN.all, Name_Buffer (1 .. Name_Len))
4802 Style.Subprogram_Not_In_Alpha_Order (Body_Id);
4808 LSN := new String'(Name_Buffer (1 .. Name_Len));
4811 end Check_Subprogram_Order;
4813 ------------------------------
4814 -- Check_Subtype_Conformant --
4815 ------------------------------
4817 procedure Check_Subtype_Conformant
4818 (New_Id : Entity_Id;
4820 Err_Loc : Node_Id := Empty;
4821 Skip_Controlling_Formals : Boolean := False)
4824 pragma Warnings (Off, Result);
4827 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
4828 Skip_Controlling_Formals => Skip_Controlling_Formals);
4829 end Check_Subtype_Conformant;
4831 ---------------------------
4832 -- Check_Type_Conformant --
4833 ---------------------------
4835 procedure Check_Type_Conformant
4836 (New_Id : Entity_Id;
4838 Err_Loc : Node_Id := Empty)
4841 pragma Warnings (Off, Result);
4844 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
4845 end Check_Type_Conformant;
4847 ----------------------
4848 -- Conforming_Types --
4849 ----------------------
4851 function Conforming_Types
4854 Ctype : Conformance_Type;
4855 Get_Inst : Boolean := False) return Boolean
4857 Type_1 : Entity_Id := T1;
4858 Type_2 : Entity_Id := T2;
4859 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
4861 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
4862 -- If neither T1 nor T2 are generic actual types, or if they are in
4863 -- different scopes (e.g. parent and child instances), then verify that
4864 -- the base types are equal. Otherwise T1 and T2 must be on the same
4865 -- subtype chain. The whole purpose of this procedure is to prevent
4866 -- spurious ambiguities in an instantiation that may arise if two
4867 -- distinct generic types are instantiated with the same actual.
4869 function Find_Designated_Type (T : Entity_Id) return Entity_Id;
4870 -- An access parameter can designate an incomplete type. If the
4871 -- incomplete type is the limited view of a type from a limited_
4872 -- with_clause, check whether the non-limited view is available. If
4873 -- it is a (non-limited) incomplete type, get the full view.
4875 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean;
4876 -- Returns True if and only if either T1 denotes a limited view of T2
4877 -- or T2 denotes a limited view of T1. This can arise when the limited
4878 -- with view of a type is used in a subprogram declaration and the
4879 -- subprogram body is in the scope of a regular with clause for the
4880 -- same unit. In such a case, the two type entities can be considered
4881 -- identical for purposes of conformance checking.
4883 ----------------------
4884 -- Base_Types_Match --
4885 ----------------------
4887 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
4892 elsif Base_Type (T1) = Base_Type (T2) then
4894 -- The following is too permissive. A more precise test should
4895 -- check that the generic actual is an ancestor subtype of the
4898 return not Is_Generic_Actual_Type (T1)
4899 or else not Is_Generic_Actual_Type (T2)
4900 or else Scope (T1) /= Scope (T2);
4905 end Base_Types_Match;
4907 --------------------------
4908 -- Find_Designated_Type --
4909 --------------------------
4911 function Find_Designated_Type (T : Entity_Id) return Entity_Id is
4915 Desig := Directly_Designated_Type (T);
4917 if Ekind (Desig) = E_Incomplete_Type then
4919 -- If regular incomplete type, get full view if available
4921 if Present (Full_View (Desig)) then
4922 Desig := Full_View (Desig);
4924 -- If limited view of a type, get non-limited view if available,
4925 -- and check again for a regular incomplete type.
4927 elsif Present (Non_Limited_View (Desig)) then
4928 Desig := Get_Full_View (Non_Limited_View (Desig));
4933 end Find_Designated_Type;
4935 -------------------------------
4936 -- Matches_Limited_With_View --
4937 -------------------------------
4939 function Matches_Limited_With_View (T1, T2 : Entity_Id) return Boolean is
4941 -- In some cases a type imported through a limited_with clause, and
4942 -- its nonlimited view are both visible, for example in an anonymous
4943 -- access-to-class-wide type in a formal. Both entities designate the
4946 if From_With_Type (T1)
4947 and then T2 = Available_View (T1)
4951 elsif From_With_Type (T2)
4952 and then T1 = Available_View (T2)
4959 end Matches_Limited_With_View;
4961 -- Start of processing for Conforming_Types
4964 -- The context is an instance association for a formal
4965 -- access-to-subprogram type; the formal parameter types require
4966 -- mapping because they may denote other formal parameters of the
4970 Type_1 := Get_Instance_Of (T1);
4971 Type_2 := Get_Instance_Of (T2);
4974 -- If one of the types is a view of the other introduced by a limited
4975 -- with clause, treat these as conforming for all purposes.
4977 if Matches_Limited_With_View (T1, T2) then
4980 elsif Base_Types_Match (Type_1, Type_2) then
4981 return Ctype <= Mode_Conformant
4982 or else Subtypes_Statically_Match (Type_1, Type_2);
4984 elsif Is_Incomplete_Or_Private_Type (Type_1)
4985 and then Present (Full_View (Type_1))
4986 and then Base_Types_Match (Full_View (Type_1), Type_2)
4988 return Ctype <= Mode_Conformant
4989 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
4991 elsif Ekind (Type_2) = E_Incomplete_Type
4992 and then Present (Full_View (Type_2))
4993 and then Base_Types_Match (Type_1, Full_View (Type_2))
4995 return Ctype <= Mode_Conformant
4996 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
4998 elsif Is_Private_Type (Type_2)
4999 and then In_Instance
5000 and then Present (Full_View (Type_2))
5001 and then Base_Types_Match (Type_1, Full_View (Type_2))
5003 return Ctype <= Mode_Conformant
5004 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
5007 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
5008 -- treated recursively because they carry a signature.
5010 Are_Anonymous_Access_To_Subprogram_Types :=
5011 Ekind (Type_1) = Ekind (Type_2)
5013 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
5015 Ekind (Type_1) = E_Anonymous_Access_Protected_Subprogram_Type);
5017 -- Test anonymous access type case. For this case, static subtype
5018 -- matching is required for mode conformance (RM 6.3.1(15)). We check
5019 -- the base types because we may have built internal subtype entities
5020 -- to handle null-excluding types (see Process_Formals).
5022 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
5024 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
5025 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
5028 Desig_1 : Entity_Id;
5029 Desig_2 : Entity_Id;
5032 -- In Ada2005, access constant indicators must match for
5033 -- subtype conformance.
5035 if Ada_Version >= Ada_05
5036 and then Ctype >= Subtype_Conformant
5038 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
5043 Desig_1 := Find_Designated_Type (Type_1);
5045 Desig_2 := Find_Designated_Type (Type_2);
5047 -- If the context is an instance association for a formal
5048 -- access-to-subprogram type; formal access parameter designated
5049 -- types require mapping because they may denote other formal
5050 -- parameters of the generic unit.
5053 Desig_1 := Get_Instance_Of (Desig_1);
5054 Desig_2 := Get_Instance_Of (Desig_2);
5057 -- It is possible for a Class_Wide_Type to be introduced for an
5058 -- incomplete type, in which case there is a separate class_ wide
5059 -- type for the full view. The types conform if their Etypes
5060 -- conform, i.e. one may be the full view of the other. This can
5061 -- only happen in the context of an access parameter, other uses
5062 -- of an incomplete Class_Wide_Type are illegal.
5064 if Is_Class_Wide_Type (Desig_1)
5065 and then Is_Class_Wide_Type (Desig_2)
5069 (Etype (Base_Type (Desig_1)),
5070 Etype (Base_Type (Desig_2)), Ctype);
5072 elsif Are_Anonymous_Access_To_Subprogram_Types then
5073 if Ada_Version < Ada_05 then
5074 return Ctype = Type_Conformant
5076 Subtypes_Statically_Match (Desig_1, Desig_2);
5078 -- We must check the conformance of the signatures themselves
5082 Conformant : Boolean;
5085 (Desig_1, Desig_2, Ctype, False, Conformant);
5091 return Base_Type (Desig_1) = Base_Type (Desig_2)
5092 and then (Ctype = Type_Conformant
5094 Subtypes_Statically_Match (Desig_1, Desig_2));
5098 -- Otherwise definitely no match
5101 if ((Ekind (Type_1) = E_Anonymous_Access_Type
5102 and then Is_Access_Type (Type_2))
5103 or else (Ekind (Type_2) = E_Anonymous_Access_Type
5104 and then Is_Access_Type (Type_1)))
5107 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
5109 May_Hide_Profile := True;
5114 end Conforming_Types;
5116 --------------------------
5117 -- Create_Extra_Formals --
5118 --------------------------
5120 procedure Create_Extra_Formals (E : Entity_Id) is
5122 First_Extra : Entity_Id := Empty;
5123 Last_Extra : Entity_Id;
5124 Formal_Type : Entity_Id;
5125 P_Formal : Entity_Id := Empty;
5127 function Add_Extra_Formal
5128 (Assoc_Entity : Entity_Id;
5131 Suffix : String) return Entity_Id;
5132 -- Add an extra formal to the current list of formals and extra formals.
5133 -- The extra formal is added to the end of the list of extra formals,
5134 -- and also returned as the result. These formals are always of mode IN.
5135 -- The new formal has the type Typ, is declared in Scope, and its name
5136 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
5138 ----------------------
5139 -- Add_Extra_Formal --
5140 ----------------------
5142 function Add_Extra_Formal
5143 (Assoc_Entity : Entity_Id;
5146 Suffix : String) return Entity_Id
5148 EF : constant Entity_Id :=
5149 Make_Defining_Identifier (Sloc (Assoc_Entity),
5150 Chars => New_External_Name (Chars (Assoc_Entity),
5154 -- A little optimization. Never generate an extra formal for the
5155 -- _init operand of an initialization procedure, since it could
5158 if Chars (Formal) = Name_uInit then
5162 Set_Ekind (EF, E_In_Parameter);
5163 Set_Actual_Subtype (EF, Typ);
5164 Set_Etype (EF, Typ);
5165 Set_Scope (EF, Scope);
5166 Set_Mechanism (EF, Default_Mechanism);
5167 Set_Formal_Validity (EF);
5169 if No (First_Extra) then
5171 Set_Extra_Formals (Scope, First_Extra);
5174 if Present (Last_Extra) then
5175 Set_Extra_Formal (Last_Extra, EF);
5181 end Add_Extra_Formal;
5183 -- Start of processing for Create_Extra_Formals
5186 -- We never generate extra formals if expansion is not active
5187 -- because we don't need them unless we are generating code.
5189 if not Expander_Active then
5193 -- If this is a derived subprogram then the subtypes of the parent
5194 -- subprogram's formal parameters will be used to determine the need
5195 -- for extra formals.
5197 if Is_Overloadable (E) and then Present (Alias (E)) then
5198 P_Formal := First_Formal (Alias (E));
5201 Last_Extra := Empty;
5202 Formal := First_Formal (E);
5203 while Present (Formal) loop
5204 Last_Extra := Formal;
5205 Next_Formal (Formal);
5208 -- If Extra_formals were already created, don't do it again. This
5209 -- situation may arise for subprogram types created as part of
5210 -- dispatching calls (see Expand_Dispatching_Call)
5212 if Present (Last_Extra) and then
5213 Present (Extra_Formal (Last_Extra))
5218 -- If the subprogram is a predefined dispatching subprogram then don't
5219 -- generate any extra constrained or accessibility level formals. In
5220 -- general we suppress these for internal subprograms (by not calling
5221 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
5222 -- generated stream attributes do get passed through because extra
5223 -- build-in-place formals are needed in some cases (limited 'Input).
5225 if Is_Predefined_Dispatching_Operation (E) then
5226 goto Test_For_BIP_Extras;
5229 Formal := First_Formal (E);
5230 while Present (Formal) loop
5232 -- Create extra formal for supporting the attribute 'Constrained.
5233 -- The case of a private type view without discriminants also
5234 -- requires the extra formal if the underlying type has defaulted
5237 if Ekind (Formal) /= E_In_Parameter then
5238 if Present (P_Formal) then
5239 Formal_Type := Etype (P_Formal);
5241 Formal_Type := Etype (Formal);
5244 -- Do not produce extra formals for Unchecked_Union parameters.
5245 -- Jump directly to the end of the loop.
5247 if Is_Unchecked_Union (Base_Type (Formal_Type)) then
5248 goto Skip_Extra_Formal_Generation;
5251 if not Has_Discriminants (Formal_Type)
5252 and then Ekind (Formal_Type) in Private_Kind
5253 and then Present (Underlying_Type (Formal_Type))
5255 Formal_Type := Underlying_Type (Formal_Type);
5258 if Has_Discriminants (Formal_Type)
5259 and then not Is_Constrained (Formal_Type)
5260 and then not Is_Indefinite_Subtype (Formal_Type)
5262 Set_Extra_Constrained
5263 (Formal, Add_Extra_Formal (Formal, Standard_Boolean, E, "F"));
5267 -- Create extra formal for supporting accessibility checking. This
5268 -- is done for both anonymous access formals and formals of named
5269 -- access types that are marked as controlling formals. The latter
5270 -- case can occur when Expand_Dispatching_Call creates a subprogram
5271 -- type and substitutes the types of access-to-class-wide actuals
5272 -- for the anonymous access-to-specific-type of controlling formals.
5273 -- Base_Type is applied because in cases where there is a null
5274 -- exclusion the formal may have an access subtype.
5276 -- This is suppressed if we specifically suppress accessibility
5277 -- checks at the package level for either the subprogram, or the
5278 -- package in which it resides. However, we do not suppress it
5279 -- simply if the scope has accessibility checks suppressed, since
5280 -- this could cause trouble when clients are compiled with a
5281 -- different suppression setting. The explicit checks at the
5282 -- package level are safe from this point of view.
5284 if (Ekind (Base_Type (Etype (Formal))) = E_Anonymous_Access_Type
5285 or else (Is_Controlling_Formal (Formal)
5286 and then Is_Access_Type (Base_Type (Etype (Formal)))))
5288 (Explicit_Suppress (E, Accessibility_Check)
5290 Explicit_Suppress (Scope (E), Accessibility_Check))
5293 or else Present (Extra_Accessibility (P_Formal)))
5295 -- Temporary kludge: for now we avoid creating the extra formal
5296 -- for access parameters of protected operations because of
5297 -- problem with the case of internal protected calls. ???
5299 if Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Definition
5300 and then Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Body
5302 Set_Extra_Accessibility
5303 (Formal, Add_Extra_Formal (Formal, Standard_Natural, E, "F"));
5307 -- This label is required when skipping extra formal generation for
5308 -- Unchecked_Union parameters.
5310 <<Skip_Extra_Formal_Generation>>
5312 if Present (P_Formal) then
5313 Next_Formal (P_Formal);
5316 Next_Formal (Formal);
5319 <<Test_For_BIP_Extras>>
5321 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
5322 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
5324 if Ada_Version >= Ada_05 and then Is_Build_In_Place_Function (E) then
5326 Result_Subt : constant Entity_Id := Etype (E);
5328 Discard : Entity_Id;
5329 pragma Warnings (Off, Discard);
5332 -- In the case of functions with unconstrained result subtypes,
5333 -- add a 3-state formal indicating whether the return object is
5334 -- allocated by the caller (0), or should be allocated by the
5335 -- callee on the secondary stack (1) or in the global heap (2).
5336 -- For the moment we just use Natural for the type of this formal.
5337 -- Note that this formal isn't usually needed in the case where
5338 -- the result subtype is constrained, but it is needed when the
5339 -- function has a tagged result, because generally such functions
5340 -- can be called in a dispatching context and such calls must be
5341 -- handled like calls to a class-wide function.
5343 if not Is_Constrained (Underlying_Type (Result_Subt))
5344 or else Is_Tagged_Type (Underlying_Type (Result_Subt))
5348 (E, Standard_Natural,
5349 E, BIP_Formal_Suffix (BIP_Alloc_Form));
5352 -- In the case of functions whose result type has controlled
5353 -- parts, we have an extra formal of type
5354 -- System.Finalization_Implementation.Finalizable_Ptr_Ptr. That
5355 -- is, we are passing a pointer to a finalization list (which is
5356 -- itself a pointer). This extra formal is then passed along to
5357 -- Move_Final_List in case of successful completion of a return
5358 -- statement. We cannot pass an 'in out' parameter, because we
5359 -- need to update the finalization list during an abort-deferred
5360 -- region, rather than using copy-back after the function
5361 -- returns. This is true even if we are able to get away with
5362 -- having 'in out' parameters, which are normally illegal for
5363 -- functions. This formal is also needed when the function has
5366 if Needs_BIP_Final_List (E) then
5369 (E, RTE (RE_Finalizable_Ptr_Ptr),
5370 E, BIP_Formal_Suffix (BIP_Final_List));
5373 -- If the result type contains tasks, we have two extra formals:
5374 -- the master of the tasks to be created, and the caller's
5375 -- activation chain.
5377 if Has_Task (Result_Subt) then
5380 (E, RTE (RE_Master_Id),
5381 E, BIP_Formal_Suffix (BIP_Master));
5384 (E, RTE (RE_Activation_Chain_Access),
5385 E, BIP_Formal_Suffix (BIP_Activation_Chain));
5388 -- All build-in-place functions get an extra formal that will be
5389 -- passed the address of the return object within the caller.
5392 Formal_Type : constant Entity_Id :=
5394 (E_Anonymous_Access_Type, E,
5395 Scope_Id => Scope (E));
5397 Set_Directly_Designated_Type (Formal_Type, Result_Subt);
5398 Set_Etype (Formal_Type, Formal_Type);
5399 Set_Depends_On_Private
5400 (Formal_Type, Has_Private_Component (Formal_Type));
5401 Set_Is_Public (Formal_Type, Is_Public (Scope (Formal_Type)));
5402 Set_Is_Access_Constant (Formal_Type, False);
5404 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
5405 -- the designated type comes from the limited view (for
5406 -- back-end purposes).
5408 Set_From_With_Type (Formal_Type, From_With_Type (Result_Subt));
5410 Layout_Type (Formal_Type);
5414 (E, Formal_Type, E, BIP_Formal_Suffix (BIP_Object_Access));
5418 end Create_Extra_Formals;
5420 -----------------------------
5421 -- Enter_Overloaded_Entity --
5422 -----------------------------
5424 procedure Enter_Overloaded_Entity (S : Entity_Id) is
5425 E : Entity_Id := Current_Entity_In_Scope (S);
5426 C_E : Entity_Id := Current_Entity (S);
5430 Set_Has_Homonym (E);
5431 Set_Has_Homonym (S);
5434 Set_Is_Immediately_Visible (S);
5435 Set_Scope (S, Current_Scope);
5437 -- Chain new entity if front of homonym in current scope, so that
5438 -- homonyms are contiguous.
5443 while Homonym (C_E) /= E loop
5444 C_E := Homonym (C_E);
5447 Set_Homonym (C_E, S);
5451 Set_Current_Entity (S);
5456 Append_Entity (S, Current_Scope);
5457 Set_Public_Status (S);
5459 if Debug_Flag_E then
5460 Write_Str ("New overloaded entity chain: ");
5461 Write_Name (Chars (S));
5464 while Present (E) loop
5465 Write_Str (" "); Write_Int (Int (E));
5472 -- Generate warning for hiding
5475 and then Comes_From_Source (S)
5476 and then In_Extended_Main_Source_Unit (S)
5483 -- Warn unless genuine overloading
5485 if (not Is_Overloadable (E) or else Subtype_Conformant (E, S))
5486 and then (Is_Immediately_Visible (E)
5488 Is_Potentially_Use_Visible (S))
5490 Error_Msg_Sloc := Sloc (E);
5491 Error_Msg_N ("declaration of & hides one#?", S);
5495 end Enter_Overloaded_Entity;
5497 -----------------------------
5498 -- Find_Corresponding_Spec --
5499 -----------------------------
5501 function Find_Corresponding_Spec
5503 Post_Error : Boolean := True) return Entity_Id
5505 Spec : constant Node_Id := Specification (N);
5506 Designator : constant Entity_Id := Defining_Entity (Spec);
5511 E := Current_Entity (Designator);
5512 while Present (E) loop
5514 -- We are looking for a matching spec. It must have the same scope,
5515 -- and the same name, and either be type conformant, or be the case
5516 -- of a library procedure spec and its body (which belong to one
5517 -- another regardless of whether they are type conformant or not).
5519 if Scope (E) = Current_Scope then
5520 if Current_Scope = Standard_Standard
5521 or else (Ekind (E) = Ekind (Designator)
5522 and then Type_Conformant (E, Designator))
5524 -- Within an instantiation, we know that spec and body are
5525 -- subtype conformant, because they were subtype conformant
5526 -- in the generic. We choose the subtype-conformant entity
5527 -- here as well, to resolve spurious ambiguities in the
5528 -- instance that were not present in the generic (i.e. when
5529 -- two different types are given the same actual). If we are
5530 -- looking for a spec to match a body, full conformance is
5534 Set_Convention (Designator, Convention (E));
5536 if Nkind (N) = N_Subprogram_Body
5537 and then Present (Homonym (E))
5538 and then not Fully_Conformant (E, Designator)
5542 elsif not Subtype_Conformant (E, Designator) then
5547 if not Has_Completion (E) then
5548 if Nkind (N) /= N_Subprogram_Body_Stub then
5549 Set_Corresponding_Spec (N, E);
5552 Set_Has_Completion (E);
5555 elsif Nkind (Parent (N)) = N_Subunit then
5557 -- If this is the proper body of a subunit, the completion
5558 -- flag is set when analyzing the stub.
5562 -- If E is an internal function with a controlling result
5563 -- that was created for an operation inherited by a null
5564 -- extension, it may be overridden by a body without a previous
5565 -- spec (one more reason why these should be shunned). In that
5566 -- case remove the generated body, because the current one is
5567 -- the explicit overriding.
5569 elsif Ekind (E) = E_Function
5570 and then Ada_Version >= Ada_05
5571 and then not Comes_From_Source (E)
5572 and then Has_Controlling_Result (E)
5573 and then Is_Null_Extension (Etype (E))
5574 and then Comes_From_Source (Spec)
5576 Set_Has_Completion (E, False);
5578 if Expander_Active then
5580 (Unit_Declaration_Node
5581 (Corresponding_Body (Unit_Declaration_Node (E))));
5584 -- If expansion is disabled, the wrapper function has not
5585 -- been generated, and this is the standard case of a late
5586 -- body overriding an inherited operation.
5592 -- If the body already exists, then this is an error unless
5593 -- the previous declaration is the implicit declaration of a
5594 -- derived subprogram, or this is a spurious overloading in an
5597 elsif No (Alias (E))
5598 and then not Is_Intrinsic_Subprogram (E)
5599 and then not In_Instance
5602 Error_Msg_Sloc := Sloc (E);
5604 if Is_Imported (E) then
5606 ("body not allowed for imported subprogram & declared#",
5609 Error_Msg_NE ("duplicate body for & declared#", N, E);
5613 -- Child units cannot be overloaded, so a conformance mismatch
5614 -- between body and a previous spec is an error.
5616 elsif Is_Child_Unit (E)
5618 Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body
5620 Nkind (Parent (Unit_Declaration_Node (Designator))) =
5625 ("body of child unit does not match previous declaration", N);
5633 -- On exit, we know that no previous declaration of subprogram exists
5636 end Find_Corresponding_Spec;
5638 ----------------------
5639 -- Fully_Conformant --
5640 ----------------------
5642 function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
5645 Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result);
5647 end Fully_Conformant;
5649 ----------------------------------
5650 -- Fully_Conformant_Expressions --
5651 ----------------------------------
5653 function Fully_Conformant_Expressions
5654 (Given_E1 : Node_Id;
5655 Given_E2 : Node_Id) return Boolean
5657 E1 : constant Node_Id := Original_Node (Given_E1);
5658 E2 : constant Node_Id := Original_Node (Given_E2);
5659 -- We always test conformance on original nodes, since it is possible
5660 -- for analysis and/or expansion to make things look as though they
5661 -- conform when they do not, e.g. by converting 1+2 into 3.
5663 function FCE (Given_E1, Given_E2 : Node_Id) return Boolean
5664 renames Fully_Conformant_Expressions;
5666 function FCL (L1, L2 : List_Id) return Boolean;
5667 -- Compare elements of two lists for conformance. Elements have to
5668 -- be conformant, and actuals inserted as default parameters do not
5669 -- match explicit actuals with the same value.
5671 function FCO (Op_Node, Call_Node : Node_Id) return Boolean;
5672 -- Compare an operator node with a function call
5678 function FCL (L1, L2 : List_Id) return Boolean is
5682 if L1 = No_List then
5688 if L2 = No_List then
5694 -- Compare two lists, skipping rewrite insertions (we want to
5695 -- compare the original trees, not the expanded versions!)
5698 if Is_Rewrite_Insertion (N1) then
5700 elsif Is_Rewrite_Insertion (N2) then
5706 elsif not FCE (N1, N2) then
5719 function FCO (Op_Node, Call_Node : Node_Id) return Boolean is
5720 Actuals : constant List_Id := Parameter_Associations (Call_Node);
5725 or else Entity (Op_Node) /= Entity (Name (Call_Node))
5730 Act := First (Actuals);
5732 if Nkind (Op_Node) in N_Binary_Op then
5733 if not FCE (Left_Opnd (Op_Node), Act) then
5740 return Present (Act)
5741 and then FCE (Right_Opnd (Op_Node), Act)
5742 and then No (Next (Act));
5746 -- Start of processing for Fully_Conformant_Expressions
5749 -- Non-conformant if paren count does not match. Note: if some idiot
5750 -- complains that we don't do this right for more than 3 levels of
5751 -- parentheses, they will be treated with the respect they deserve!
5753 if Paren_Count (E1) /= Paren_Count (E2) then
5756 -- If same entities are referenced, then they are conformant even if
5757 -- they have different forms (RM 8.3.1(19-20)).
5759 elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then
5760 if Present (Entity (E1)) then
5761 return Entity (E1) = Entity (E2)
5762 or else (Chars (Entity (E1)) = Chars (Entity (E2))
5763 and then Ekind (Entity (E1)) = E_Discriminant
5764 and then Ekind (Entity (E2)) = E_In_Parameter);
5766 elsif Nkind (E1) = N_Expanded_Name
5767 and then Nkind (E2) = N_Expanded_Name
5768 and then Nkind (Selector_Name (E1)) = N_Character_Literal
5769 and then Nkind (Selector_Name (E2)) = N_Character_Literal
5771 return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2));
5774 -- Identifiers in component associations don't always have
5775 -- entities, but their names must conform.
5777 return Nkind (E1) = N_Identifier
5778 and then Nkind (E2) = N_Identifier
5779 and then Chars (E1) = Chars (E2);
5782 elsif Nkind (E1) = N_Character_Literal
5783 and then Nkind (E2) = N_Expanded_Name
5785 return Nkind (Selector_Name (E2)) = N_Character_Literal
5786 and then Chars (E1) = Chars (Selector_Name (E2));
5788 elsif Nkind (E2) = N_Character_Literal
5789 and then Nkind (E1) = N_Expanded_Name
5791 return Nkind (Selector_Name (E1)) = N_Character_Literal
5792 and then Chars (E2) = Chars (Selector_Name (E1));
5794 elsif Nkind (E1) in N_Op
5795 and then Nkind (E2) = N_Function_Call
5797 return FCO (E1, E2);
5799 elsif Nkind (E2) in N_Op
5800 and then Nkind (E1) = N_Function_Call
5802 return FCO (E2, E1);
5804 -- Otherwise we must have the same syntactic entity
5806 elsif Nkind (E1) /= Nkind (E2) then
5809 -- At this point, we specialize by node type
5816 FCL (Expressions (E1), Expressions (E2))
5817 and then FCL (Component_Associations (E1),
5818 Component_Associations (E2));
5821 if Nkind (Expression (E1)) = N_Qualified_Expression
5823 Nkind (Expression (E2)) = N_Qualified_Expression
5825 return FCE (Expression (E1), Expression (E2));
5827 -- Check that the subtype marks and any constraints
5832 Indic1 : constant Node_Id := Expression (E1);
5833 Indic2 : constant Node_Id := Expression (E2);
5838 if Nkind (Indic1) /= N_Subtype_Indication then
5840 Nkind (Indic2) /= N_Subtype_Indication
5841 and then Entity (Indic1) = Entity (Indic2);
5843 elsif Nkind (Indic2) /= N_Subtype_Indication then
5845 Nkind (Indic1) /= N_Subtype_Indication
5846 and then Entity (Indic1) = Entity (Indic2);
5849 if Entity (Subtype_Mark (Indic1)) /=
5850 Entity (Subtype_Mark (Indic2))
5855 Elt1 := First (Constraints (Constraint (Indic1)));
5856 Elt2 := First (Constraints (Constraint (Indic2)));
5857 while Present (Elt1) and then Present (Elt2) loop
5858 if not FCE (Elt1, Elt2) then
5871 when N_Attribute_Reference =>
5873 Attribute_Name (E1) = Attribute_Name (E2)
5874 and then FCL (Expressions (E1), Expressions (E2));
5878 Entity (E1) = Entity (E2)
5879 and then FCE (Left_Opnd (E1), Left_Opnd (E2))
5880 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
5882 when N_And_Then | N_Or_Else | N_Membership_Test =>
5884 FCE (Left_Opnd (E1), Left_Opnd (E2))
5886 FCE (Right_Opnd (E1), Right_Opnd (E2));
5888 when N_Character_Literal =>
5890 Char_Literal_Value (E1) = Char_Literal_Value (E2);
5892 when N_Component_Association =>
5894 FCL (Choices (E1), Choices (E2))
5895 and then FCE (Expression (E1), Expression (E2));
5897 when N_Conditional_Expression =>
5899 FCL (Expressions (E1), Expressions (E2));
5901 when N_Explicit_Dereference =>
5903 FCE (Prefix (E1), Prefix (E2));
5905 when N_Extension_Aggregate =>
5907 FCL (Expressions (E1), Expressions (E2))
5908 and then Null_Record_Present (E1) =
5909 Null_Record_Present (E2)
5910 and then FCL (Component_Associations (E1),
5911 Component_Associations (E2));
5913 when N_Function_Call =>
5915 FCE (Name (E1), Name (E2))
5916 and then FCL (Parameter_Associations (E1),
5917 Parameter_Associations (E2));
5919 when N_Indexed_Component =>
5921 FCE (Prefix (E1), Prefix (E2))
5922 and then FCL (Expressions (E1), Expressions (E2));
5924 when N_Integer_Literal =>
5925 return (Intval (E1) = Intval (E2));
5930 when N_Operator_Symbol =>
5932 Chars (E1) = Chars (E2);
5934 when N_Others_Choice =>
5937 when N_Parameter_Association =>
5939 Chars (Selector_Name (E1)) = Chars (Selector_Name (E2))
5940 and then FCE (Explicit_Actual_Parameter (E1),
5941 Explicit_Actual_Parameter (E2));
5943 when N_Qualified_Expression =>
5945 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
5946 and then FCE (Expression (E1), Expression (E2));
5950 FCE (Low_Bound (E1), Low_Bound (E2))
5951 and then FCE (High_Bound (E1), High_Bound (E2));
5953 when N_Real_Literal =>
5954 return (Realval (E1) = Realval (E2));
5956 when N_Selected_Component =>
5958 FCE (Prefix (E1), Prefix (E2))
5959 and then FCE (Selector_Name (E1), Selector_Name (E2));
5963 FCE (Prefix (E1), Prefix (E2))
5964 and then FCE (Discrete_Range (E1), Discrete_Range (E2));
5966 when N_String_Literal =>
5968 S1 : constant String_Id := Strval (E1);
5969 S2 : constant String_Id := Strval (E2);
5970 L1 : constant Nat := String_Length (S1);
5971 L2 : constant Nat := String_Length (S2);
5978 for J in 1 .. L1 loop
5979 if Get_String_Char (S1, J) /=
5980 Get_String_Char (S2, J)
5990 when N_Type_Conversion =>
5992 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
5993 and then FCE (Expression (E1), Expression (E2));
5997 Entity (E1) = Entity (E2)
5998 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
6000 when N_Unchecked_Type_Conversion =>
6002 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
6003 and then FCE (Expression (E1), Expression (E2));
6005 -- All other node types cannot appear in this context. Strictly
6006 -- we should raise a fatal internal error. Instead we just ignore
6007 -- the nodes. This means that if anyone makes a mistake in the
6008 -- expander and mucks an expression tree irretrievably, the
6009 -- result will be a failure to detect a (probably very obscure)
6010 -- case of non-conformance, which is better than bombing on some
6011 -- case where two expressions do in fact conform.
6018 end Fully_Conformant_Expressions;
6020 ----------------------------------------
6021 -- Fully_Conformant_Discrete_Subtypes --
6022 ----------------------------------------
6024 function Fully_Conformant_Discrete_Subtypes
6025 (Given_S1 : Node_Id;
6026 Given_S2 : Node_Id) return Boolean
6028 S1 : constant Node_Id := Original_Node (Given_S1);
6029 S2 : constant Node_Id := Original_Node (Given_S2);
6031 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean;
6032 -- Special-case for a bound given by a discriminant, which in the body
6033 -- is replaced with the discriminal of the enclosing type.
6035 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean;
6036 -- Check both bounds
6038 -----------------------
6039 -- Conforming_Bounds --
6040 -----------------------
6042 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is
6044 if Is_Entity_Name (B1)
6045 and then Is_Entity_Name (B2)
6046 and then Ekind (Entity (B1)) = E_Discriminant
6048 return Chars (B1) = Chars (B2);
6051 return Fully_Conformant_Expressions (B1, B2);
6053 end Conforming_Bounds;
6055 -----------------------
6056 -- Conforming_Ranges --
6057 -----------------------
6059 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is
6062 Conforming_Bounds (Low_Bound (R1), Low_Bound (R2))
6064 Conforming_Bounds (High_Bound (R1), High_Bound (R2));
6065 end Conforming_Ranges;
6067 -- Start of processing for Fully_Conformant_Discrete_Subtypes
6070 if Nkind (S1) /= Nkind (S2) then
6073 elsif Is_Entity_Name (S1) then
6074 return Entity (S1) = Entity (S2);
6076 elsif Nkind (S1) = N_Range then
6077 return Conforming_Ranges (S1, S2);
6079 elsif Nkind (S1) = N_Subtype_Indication then
6081 Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2))
6084 (Range_Expression (Constraint (S1)),
6085 Range_Expression (Constraint (S2)));
6089 end Fully_Conformant_Discrete_Subtypes;
6091 --------------------
6092 -- Install_Entity --
6093 --------------------
6095 procedure Install_Entity (E : Entity_Id) is
6096 Prev : constant Entity_Id := Current_Entity (E);
6098 Set_Is_Immediately_Visible (E);
6099 Set_Current_Entity (E);
6100 Set_Homonym (E, Prev);
6103 ---------------------
6104 -- Install_Formals --
6105 ---------------------
6107 procedure Install_Formals (Id : Entity_Id) is
6110 F := First_Formal (Id);
6111 while Present (F) loop
6115 end Install_Formals;
6117 -----------------------------
6118 -- Is_Interface_Conformant --
6119 -----------------------------
6121 function Is_Interface_Conformant
6122 (Tagged_Type : Entity_Id;
6123 Iface_Prim : Entity_Id;
6124 Prim : Entity_Id) return Boolean
6126 Iface : constant Entity_Id := Find_Dispatching_Type (Iface_Prim);
6127 Typ : constant Entity_Id := Find_Dispatching_Type (Prim);
6130 pragma Assert (Is_Subprogram (Iface_Prim)
6131 and then Is_Subprogram (Prim)
6132 and then Is_Dispatching_Operation (Iface_Prim)
6133 and then Is_Dispatching_Operation (Prim));
6135 pragma Assert (Is_Interface (Iface)
6136 or else (Present (Alias (Iface_Prim))
6139 (Find_Dispatching_Type (Ultimate_Alias (Iface_Prim)))));
6141 if Prim = Iface_Prim
6142 or else not Is_Subprogram (Prim)
6143 or else Ekind (Prim) /= Ekind (Iface_Prim)
6144 or else not Is_Dispatching_Operation (Prim)
6145 or else Scope (Prim) /= Scope (Tagged_Type)
6147 or else Base_Type (Typ) /= Tagged_Type
6148 or else not Primitive_Names_Match (Iface_Prim, Prim)
6152 -- Case of a procedure, or a function that does not have a controlling
6153 -- result (I or access I).
6155 elsif Ekind (Iface_Prim) = E_Procedure
6156 or else Etype (Prim) = Etype (Iface_Prim)
6157 or else not Has_Controlling_Result (Prim)
6159 return Type_Conformant (Prim, Iface_Prim,
6160 Skip_Controlling_Formals => True);
6162 -- Case of a function returning an interface, or an access to one.
6163 -- Check that the return types correspond.
6165 elsif Implements_Interface (Typ, Iface) then
6166 if (Ekind (Etype (Prim)) = E_Anonymous_Access_Type)
6168 (Ekind (Etype (Iface_Prim)) = E_Anonymous_Access_Type)
6173 Type_Conformant (Prim, Iface_Prim,
6174 Skip_Controlling_Formals => True);
6180 end Is_Interface_Conformant;
6182 ---------------------------------
6183 -- Is_Non_Overriding_Operation --
6184 ---------------------------------
6186 function Is_Non_Overriding_Operation
6187 (Prev_E : Entity_Id;
6188 New_E : Entity_Id) return Boolean
6192 G_Typ : Entity_Id := Empty;
6194 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id;
6195 -- If F_Type is a derived type associated with a generic actual subtype,
6196 -- then return its Generic_Parent_Type attribute, else return Empty.
6198 function Types_Correspond
6199 (P_Type : Entity_Id;
6200 N_Type : Entity_Id) return Boolean;
6201 -- Returns true if and only if the types (or designated types in the
6202 -- case of anonymous access types) are the same or N_Type is derived
6203 -- directly or indirectly from P_Type.
6205 -----------------------------
6206 -- Get_Generic_Parent_Type --
6207 -----------------------------
6209 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is
6214 if Is_Derived_Type (F_Typ)
6215 and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration
6217 -- The tree must be traversed to determine the parent subtype in
6218 -- the generic unit, which unfortunately isn't always available
6219 -- via semantic attributes. ??? (Note: The use of Original_Node
6220 -- is needed for cases where a full derived type has been
6223 Indic := Subtype_Indication
6224 (Type_Definition (Original_Node (Parent (F_Typ))));
6226 if Nkind (Indic) = N_Subtype_Indication then
6227 G_Typ := Entity (Subtype_Mark (Indic));
6229 G_Typ := Entity (Indic);
6232 if Nkind (Parent (G_Typ)) = N_Subtype_Declaration
6233 and then Present (Generic_Parent_Type (Parent (G_Typ)))
6235 return Generic_Parent_Type (Parent (G_Typ));
6240 end Get_Generic_Parent_Type;
6242 ----------------------
6243 -- Types_Correspond --
6244 ----------------------
6246 function Types_Correspond
6247 (P_Type : Entity_Id;
6248 N_Type : Entity_Id) return Boolean
6250 Prev_Type : Entity_Id := Base_Type (P_Type);
6251 New_Type : Entity_Id := Base_Type (N_Type);
6254 if Ekind (Prev_Type) = E_Anonymous_Access_Type then
6255 Prev_Type := Designated_Type (Prev_Type);
6258 if Ekind (New_Type) = E_Anonymous_Access_Type then
6259 New_Type := Designated_Type (New_Type);
6262 if Prev_Type = New_Type then
6265 elsif not Is_Class_Wide_Type (New_Type) then
6266 while Etype (New_Type) /= New_Type loop
6267 New_Type := Etype (New_Type);
6268 if New_Type = Prev_Type then
6274 end Types_Correspond;
6276 -- Start of processing for Is_Non_Overriding_Operation
6279 -- In the case where both operations are implicit derived subprograms
6280 -- then neither overrides the other. This can only occur in certain
6281 -- obscure cases (e.g., derivation from homographs created in a generic
6284 if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then
6287 elsif Ekind (Current_Scope) = E_Package
6288 and then Is_Generic_Instance (Current_Scope)
6289 and then In_Private_Part (Current_Scope)
6290 and then Comes_From_Source (New_E)
6292 -- We examine the formals and result subtype of the inherited
6293 -- operation, to determine whether their type is derived from (the
6294 -- instance of) a generic type.
6296 Formal := First_Formal (Prev_E);
6298 while Present (Formal) loop
6299 F_Typ := Base_Type (Etype (Formal));
6301 if Ekind (F_Typ) = E_Anonymous_Access_Type then
6302 F_Typ := Designated_Type (F_Typ);
6305 G_Typ := Get_Generic_Parent_Type (F_Typ);
6307 Next_Formal (Formal);
6310 if No (G_Typ) and then Ekind (Prev_E) = E_Function then
6311 G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E)));
6318 -- If the generic type is a private type, then the original operation
6319 -- was not overriding in the generic, because there was no primitive
6320 -- operation to override.
6322 if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration
6323 and then Nkind (Formal_Type_Definition (Parent (G_Typ))) =
6324 N_Formal_Private_Type_Definition
6328 -- The generic parent type is the ancestor of a formal derived
6329 -- type declaration. We need to check whether it has a primitive
6330 -- operation that should be overridden by New_E in the generic.
6334 P_Formal : Entity_Id;
6335 N_Formal : Entity_Id;
6339 Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ));
6342 while Present (Prim_Elt) loop
6343 P_Prim := Node (Prim_Elt);
6345 if Chars (P_Prim) = Chars (New_E)
6346 and then Ekind (P_Prim) = Ekind (New_E)
6348 P_Formal := First_Formal (P_Prim);
6349 N_Formal := First_Formal (New_E);
6350 while Present (P_Formal) and then Present (N_Formal) loop
6351 P_Typ := Etype (P_Formal);
6352 N_Typ := Etype (N_Formal);
6354 if not Types_Correspond (P_Typ, N_Typ) then
6358 Next_Entity (P_Formal);
6359 Next_Entity (N_Formal);
6362 -- Found a matching primitive operation belonging to the
6363 -- formal ancestor type, so the new subprogram is
6367 and then No (N_Formal)
6368 and then (Ekind (New_E) /= E_Function
6371 (Etype (P_Prim), Etype (New_E)))
6377 Next_Elmt (Prim_Elt);
6380 -- If no match found, then the new subprogram does not
6381 -- override in the generic (nor in the instance).
6389 end Is_Non_Overriding_Operation;
6391 ------------------------------
6392 -- Make_Inequality_Operator --
6393 ------------------------------
6395 -- S is the defining identifier of an equality operator. We build a
6396 -- subprogram declaration with the right signature. This operation is
6397 -- intrinsic, because it is always expanded as the negation of the
6398 -- call to the equality function.
6400 procedure Make_Inequality_Operator (S : Entity_Id) is
6401 Loc : constant Source_Ptr := Sloc (S);
6404 Op_Name : Entity_Id;
6406 FF : constant Entity_Id := First_Formal (S);
6407 NF : constant Entity_Id := Next_Formal (FF);
6410 -- Check that equality was properly defined, ignore call if not
6417 A : constant Entity_Id :=
6418 Make_Defining_Identifier (Sloc (FF),
6419 Chars => Chars (FF));
6421 B : constant Entity_Id :=
6422 Make_Defining_Identifier (Sloc (NF),
6423 Chars => Chars (NF));
6426 Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne);
6428 Formals := New_List (
6429 Make_Parameter_Specification (Loc,
6430 Defining_Identifier => A,
6432 New_Reference_To (Etype (First_Formal (S)),
6433 Sloc (Etype (First_Formal (S))))),
6435 Make_Parameter_Specification (Loc,
6436 Defining_Identifier => B,
6438 New_Reference_To (Etype (Next_Formal (First_Formal (S))),
6439 Sloc (Etype (Next_Formal (First_Formal (S)))))));
6442 Make_Subprogram_Declaration (Loc,
6444 Make_Function_Specification (Loc,
6445 Defining_Unit_Name => Op_Name,
6446 Parameter_Specifications => Formals,
6447 Result_Definition =>
6448 New_Reference_To (Standard_Boolean, Loc)));
6450 -- Insert inequality right after equality if it is explicit or after
6451 -- the derived type when implicit. These entities are created only
6452 -- for visibility purposes, and eventually replaced in the course of
6453 -- expansion, so they do not need to be attached to the tree and seen
6454 -- by the back-end. Keeping them internal also avoids spurious
6455 -- freezing problems. The declaration is inserted in the tree for
6456 -- analysis, and removed afterwards. If the equality operator comes
6457 -- from an explicit declaration, attach the inequality immediately
6458 -- after. Else the equality is inherited from a derived type
6459 -- declaration, so insert inequality after that declaration.
6461 if No (Alias (S)) then
6462 Insert_After (Unit_Declaration_Node (S), Decl);
6463 elsif Is_List_Member (Parent (S)) then
6464 Insert_After (Parent (S), Decl);
6466 Insert_After (Parent (Etype (First_Formal (S))), Decl);
6469 Mark_Rewrite_Insertion (Decl);
6470 Set_Is_Intrinsic_Subprogram (Op_Name);
6473 Set_Has_Completion (Op_Name);
6474 Set_Corresponding_Equality (Op_Name, S);
6475 Set_Is_Abstract_Subprogram (Op_Name, Is_Abstract_Subprogram (S));
6477 end Make_Inequality_Operator;
6479 ----------------------
6480 -- May_Need_Actuals --
6481 ----------------------
6483 procedure May_Need_Actuals (Fun : Entity_Id) is
6488 F := First_Formal (Fun);
6490 while Present (F) loop
6491 if No (Default_Value (F)) then
6499 Set_Needs_No_Actuals (Fun, B);
6500 end May_Need_Actuals;
6502 ---------------------
6503 -- Mode_Conformant --
6504 ---------------------
6506 function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
6509 Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result);
6511 end Mode_Conformant;
6513 ---------------------------
6514 -- New_Overloaded_Entity --
6515 ---------------------------
6517 procedure New_Overloaded_Entity
6519 Derived_Type : Entity_Id := Empty)
6521 Overridden_Subp : Entity_Id := Empty;
6522 -- Set if the current scope has an operation that is type-conformant
6523 -- with S, and becomes hidden by S.
6525 Is_Primitive_Subp : Boolean;
6526 -- Set to True if the new subprogram is primitive
6529 -- Entity that S overrides
6531 Prev_Vis : Entity_Id := Empty;
6532 -- Predecessor of E in Homonym chain
6534 procedure Check_For_Primitive_Subprogram
6535 (Is_Primitive : out Boolean;
6536 Is_Overriding : Boolean := False);
6537 -- If the subprogram being analyzed is a primitive operation of the type
6538 -- of a formal or result, set the Has_Primitive_Operations flag on the
6539 -- type, and set Is_Primitive to True (otherwise set to False). Set the
6540 -- corresponding flag on the entity itself for later use.
6542 procedure Check_Synchronized_Overriding
6543 (Def_Id : Entity_Id;
6544 Overridden_Subp : out Entity_Id);
6545 -- First determine if Def_Id is an entry or a subprogram either defined
6546 -- in the scope of a task or protected type, or is a primitive of such
6547 -- a type. Check whether Def_Id overrides a subprogram of an interface
6548 -- implemented by the synchronized type, return the overridden entity
6551 function Is_Private_Declaration (E : Entity_Id) return Boolean;
6552 -- Check that E is declared in the private part of the current package,
6553 -- or in the package body, where it may hide a previous declaration.
6554 -- We can't use In_Private_Part by itself because this flag is also
6555 -- set when freezing entities, so we must examine the place of the
6556 -- declaration in the tree, and recognize wrapper packages as well.
6558 function Is_Overriding_Alias
6560 New_E : Entity_Id) return Boolean;
6561 -- Check whether new subprogram and old subprogram are both inherited
6562 -- from subprograms that have distinct dispatch table entries. This can
6563 -- occur with derivations from instances with accidental homonyms.
6564 -- The function is conservative given that the converse is only true
6565 -- within instances that contain accidental overloadings.
6567 ------------------------------------
6568 -- Check_For_Primitive_Subprogram --
6569 ------------------------------------
6571 procedure Check_For_Primitive_Subprogram
6572 (Is_Primitive : out Boolean;
6573 Is_Overriding : Boolean := False)
6579 function Visible_Part_Type (T : Entity_Id) return Boolean;
6580 -- Returns true if T is declared in the visible part of the current
6581 -- package scope; otherwise returns false. Assumes that T is declared
6584 procedure Check_Private_Overriding (T : Entity_Id);
6585 -- Checks that if a primitive abstract subprogram of a visible
6586 -- abstract type is declared in a private part, then it must override
6587 -- an abstract subprogram declared in the visible part. Also checks
6588 -- that if a primitive function with a controlling result is declared
6589 -- in a private part, then it must override a function declared in
6590 -- the visible part.
6592 ------------------------------
6593 -- Check_Private_Overriding --
6594 ------------------------------
6596 procedure Check_Private_Overriding (T : Entity_Id) is
6598 if Is_Package_Or_Generic_Package (Current_Scope)
6599 and then In_Private_Part (Current_Scope)
6600 and then Visible_Part_Type (T)
6601 and then not In_Instance
6603 if Is_Abstract_Type (T)
6604 and then Is_Abstract_Subprogram (S)
6605 and then (not Is_Overriding
6606 or else not Is_Abstract_Subprogram (E))
6608 Error_Msg_N ("abstract subprograms must be visible "
6609 & "(RM 3.9.3(10))!", S);
6611 elsif Ekind (S) = E_Function
6612 and then Is_Tagged_Type (T)
6613 and then T = Base_Type (Etype (S))
6614 and then not Is_Overriding
6617 ("private function with tagged result must"
6618 & " override visible-part function", S);
6620 ("\move subprogram to the visible part"
6621 & " (RM 3.9.3(10))", S);
6624 end Check_Private_Overriding;
6626 -----------------------
6627 -- Visible_Part_Type --
6628 -----------------------
6630 function Visible_Part_Type (T : Entity_Id) return Boolean is
6631 P : constant Node_Id := Unit_Declaration_Node (Scope (T));
6635 -- If the entity is a private type, then it must be declared in a
6638 if Ekind (T) in Private_Kind then
6642 -- Otherwise, we traverse the visible part looking for its
6643 -- corresponding declaration. We cannot use the declaration
6644 -- node directly because in the private part the entity of a
6645 -- private type is the one in the full view, which does not
6646 -- indicate that it is the completion of something visible.
6648 N := First (Visible_Declarations (Specification (P)));
6649 while Present (N) loop
6650 if Nkind (N) = N_Full_Type_Declaration
6651 and then Present (Defining_Identifier (N))
6652 and then T = Defining_Identifier (N)
6656 elsif Nkind_In (N, N_Private_Type_Declaration,
6657 N_Private_Extension_Declaration)
6658 and then Present (Defining_Identifier (N))
6659 and then T = Full_View (Defining_Identifier (N))
6668 end Visible_Part_Type;
6670 -- Start of processing for Check_For_Primitive_Subprogram
6673 Is_Primitive := False;
6675 if not Comes_From_Source (S) then
6678 -- If subprogram is at library level, it is not primitive operation
6680 elsif Current_Scope = Standard_Standard then
6683 elsif (Is_Package_Or_Generic_Package (Current_Scope)
6684 and then not In_Package_Body (Current_Scope))
6685 or else Is_Overriding
6687 -- For function, check return type
6689 if Ekind (S) = E_Function then
6690 if Ekind (Etype (S)) = E_Anonymous_Access_Type then
6691 F_Typ := Designated_Type (Etype (S));
6696 B_Typ := Base_Type (F_Typ);
6698 if Scope (B_Typ) = Current_Scope
6699 and then not Is_Class_Wide_Type (B_Typ)
6700 and then not Is_Generic_Type (B_Typ)
6702 Is_Primitive := True;
6703 Set_Has_Primitive_Operations (B_Typ);
6704 Set_Is_Primitive (S);
6705 Check_Private_Overriding (B_Typ);
6709 -- For all subprograms, check formals
6711 Formal := First_Formal (S);
6712 while Present (Formal) loop
6713 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
6714 F_Typ := Designated_Type (Etype (Formal));
6716 F_Typ := Etype (Formal);
6719 B_Typ := Base_Type (F_Typ);
6721 if Ekind (B_Typ) = E_Access_Subtype then
6722 B_Typ := Base_Type (B_Typ);
6725 if Scope (B_Typ) = Current_Scope
6726 and then not Is_Class_Wide_Type (B_Typ)
6727 and then not Is_Generic_Type (B_Typ)
6729 Is_Primitive := True;
6730 Set_Is_Primitive (S);
6731 Set_Has_Primitive_Operations (B_Typ);
6732 Check_Private_Overriding (B_Typ);
6735 Next_Formal (Formal);
6738 end Check_For_Primitive_Subprogram;
6740 -----------------------------------
6741 -- Check_Synchronized_Overriding --
6742 -----------------------------------
6744 procedure Check_Synchronized_Overriding
6745 (Def_Id : Entity_Id;
6746 Overridden_Subp : out Entity_Id)
6748 Ifaces_List : Elist_Id;
6752 function Matches_Prefixed_View_Profile
6753 (Prim_Params : List_Id;
6754 Iface_Params : List_Id) return Boolean;
6755 -- Determine whether a subprogram's parameter profile Prim_Params
6756 -- matches that of a potentially overridden interface subprogram
6757 -- Iface_Params. Also determine if the type of first parameter of
6758 -- Iface_Params is an implemented interface.
6760 -----------------------------------
6761 -- Matches_Prefixed_View_Profile --
6762 -----------------------------------
6764 function Matches_Prefixed_View_Profile
6765 (Prim_Params : List_Id;
6766 Iface_Params : List_Id) return Boolean
6768 Iface_Id : Entity_Id;
6769 Iface_Param : Node_Id;
6770 Iface_Typ : Entity_Id;
6771 Prim_Id : Entity_Id;
6772 Prim_Param : Node_Id;
6773 Prim_Typ : Entity_Id;
6775 function Is_Implemented
6776 (Ifaces_List : Elist_Id;
6777 Iface : Entity_Id) return Boolean;
6778 -- Determine if Iface is implemented by the current task or
6781 --------------------
6782 -- Is_Implemented --
6783 --------------------
6785 function Is_Implemented
6786 (Ifaces_List : Elist_Id;
6787 Iface : Entity_Id) return Boolean
6789 Iface_Elmt : Elmt_Id;
6792 Iface_Elmt := First_Elmt (Ifaces_List);
6793 while Present (Iface_Elmt) loop
6794 if Node (Iface_Elmt) = Iface then
6798 Next_Elmt (Iface_Elmt);
6804 -- Start of processing for Matches_Prefixed_View_Profile
6807 Iface_Param := First (Iface_Params);
6808 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
6810 if Is_Access_Type (Iface_Typ) then
6811 Iface_Typ := Designated_Type (Iface_Typ);
6814 Prim_Param := First (Prim_Params);
6816 -- The first parameter of the potentially overridden subprogram
6817 -- must be an interface implemented by Prim.
6819 if not Is_Interface (Iface_Typ)
6820 or else not Is_Implemented (Ifaces_List, Iface_Typ)
6825 -- The checks on the object parameters are done, move onto the
6826 -- rest of the parameters.
6828 if not In_Scope then
6829 Prim_Param := Next (Prim_Param);
6832 Iface_Param := Next (Iface_Param);
6833 while Present (Iface_Param) and then Present (Prim_Param) loop
6834 Iface_Id := Defining_Identifier (Iface_Param);
6835 Iface_Typ := Find_Parameter_Type (Iface_Param);
6837 Prim_Id := Defining_Identifier (Prim_Param);
6838 Prim_Typ := Find_Parameter_Type (Prim_Param);
6840 if Ekind (Iface_Typ) = E_Anonymous_Access_Type
6841 and then Ekind (Prim_Typ) = E_Anonymous_Access_Type
6842 and then Is_Concurrent_Type (Designated_Type (Prim_Typ))
6844 Iface_Typ := Designated_Type (Iface_Typ);
6845 Prim_Typ := Designated_Type (Prim_Typ);
6848 -- Case of multiple interface types inside a parameter profile
6850 -- (Obj_Param : in out Iface; ...; Param : Iface)
6852 -- If the interface type is implemented, then the matching type
6853 -- in the primitive should be the implementing record type.
6855 if Ekind (Iface_Typ) = E_Record_Type
6856 and then Is_Interface (Iface_Typ)
6857 and then Is_Implemented (Ifaces_List, Iface_Typ)
6859 if Prim_Typ /= Typ then
6863 -- The two parameters must be both mode and subtype conformant
6865 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
6867 Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
6876 -- One of the two lists contains more parameters than the other
6878 if Present (Iface_Param) or else Present (Prim_Param) then
6883 end Matches_Prefixed_View_Profile;
6885 -- Start of processing for Check_Synchronized_Overriding
6888 Overridden_Subp := Empty;
6890 -- Def_Id must be an entry or a subprogram. We should skip predefined
6891 -- primitives internally generated by the frontend; however at this
6892 -- stage predefined primitives are still not fully decorated. As a
6893 -- minor optimization we skip here internally generated subprograms.
6895 if (Ekind (Def_Id) /= E_Entry
6896 and then Ekind (Def_Id) /= E_Function
6897 and then Ekind (Def_Id) /= E_Procedure)
6898 or else not Comes_From_Source (Def_Id)
6903 -- Search for the concurrent declaration since it contains the list
6904 -- of all implemented interfaces. In this case, the subprogram is
6905 -- declared within the scope of a protected or a task type.
6907 if Present (Scope (Def_Id))
6908 and then Is_Concurrent_Type (Scope (Def_Id))
6909 and then not Is_Generic_Actual_Type (Scope (Def_Id))
6911 Typ := Scope (Def_Id);
6914 -- The enclosing scope is not a synchronized type and the subprogram
6917 elsif No (First_Formal (Def_Id)) then
6920 -- The subprogram has formals and hence it may be a primitive of a
6924 Typ := Etype (First_Formal (Def_Id));
6926 if Is_Access_Type (Typ) then
6927 Typ := Directly_Designated_Type (Typ);
6930 if Is_Concurrent_Type (Typ)
6931 and then not Is_Generic_Actual_Type (Typ)
6935 -- This case occurs when the concurrent type is declared within
6936 -- a generic unit. As a result the corresponding record has been
6937 -- built and used as the type of the first formal, we just have
6938 -- to retrieve the corresponding concurrent type.
6940 elsif Is_Concurrent_Record_Type (Typ)
6941 and then Present (Corresponding_Concurrent_Type (Typ))
6943 Typ := Corresponding_Concurrent_Type (Typ);
6951 -- There is no overriding to check if is an inherited operation in a
6952 -- type derivation on for a generic actual.
6954 Collect_Interfaces (Typ, Ifaces_List);
6956 if Is_Empty_Elmt_List (Ifaces_List) then
6960 -- Determine whether entry or subprogram Def_Id overrides a primitive
6961 -- operation that belongs to one of the interfaces in Ifaces_List.
6964 Candidate : Entity_Id := Empty;
6965 Hom : Entity_Id := Empty;
6966 Iface_Typ : Entity_Id;
6967 Subp : Entity_Id := Empty;
6970 -- Traverse the homonym chain, looking at a potentially
6971 -- overridden subprogram that belongs to an implemented
6974 Hom := Current_Entity_In_Scope (Def_Id);
6975 while Present (Hom) loop
6979 or else not Is_Overloadable (Subp)
6980 or else not Is_Primitive (Subp)
6981 or else not Is_Dispatching_Operation (Subp)
6982 or else not Is_Interface (Find_Dispatching_Type (Subp))
6986 -- Entries and procedures can override abstract or null
6987 -- interface procedures
6989 elsif (Ekind (Def_Id) = E_Procedure
6990 or else Ekind (Def_Id) = E_Entry)
6991 and then Ekind (Subp) = E_Procedure
6992 and then Matches_Prefixed_View_Profile
6993 (Parameter_Specifications (Parent (Def_Id)),
6994 Parameter_Specifications (Parent (Subp)))
6998 -- For an overridden subprogram Subp, check whether the mode
6999 -- of its first parameter is correct depending on the kind
7000 -- of synchronized type.
7003 Formal : constant Node_Id := First_Formal (Candidate);
7006 -- In order for an entry or a protected procedure to
7007 -- override, the first parameter of the overridden
7008 -- routine must be of mode "out", "in out" or
7009 -- access-to-variable.
7011 if (Ekind (Candidate) = E_Entry
7012 or else Ekind (Candidate) = E_Procedure)
7013 and then Is_Protected_Type (Typ)
7014 and then Ekind (Formal) /= E_In_Out_Parameter
7015 and then Ekind (Formal) /= E_Out_Parameter
7016 and then Nkind (Parameter_Type (Parent (Formal)))
7017 /= N_Access_Definition
7021 -- All other cases are OK since a task entry or routine
7022 -- does not have a restriction on the mode of the first
7023 -- parameter of the overridden interface routine.
7026 Overridden_Subp := Candidate;
7031 -- Functions can override abstract interface functions
7033 elsif Ekind (Def_Id) = E_Function
7034 and then Ekind (Subp) = E_Function
7035 and then Matches_Prefixed_View_Profile
7036 (Parameter_Specifications (Parent (Def_Id)),
7037 Parameter_Specifications (Parent (Subp)))
7038 and then Etype (Result_Definition (Parent (Def_Id))) =
7039 Etype (Result_Definition (Parent (Subp)))
7041 Overridden_Subp := Subp;
7045 Hom := Homonym (Hom);
7048 -- After examining all candidates for overriding, we are
7049 -- left with the best match which is a mode incompatible
7050 -- interface routine. Do not emit an error if the Expander
7051 -- is active since this error will be detected later on
7052 -- after all concurrent types are expanded and all wrappers
7053 -- are built. This check is meant for spec-only
7056 if Present (Candidate)
7057 and then not Expander_Active
7060 Find_Parameter_Type (Parent (First_Formal (Candidate)));
7062 -- Def_Id is primitive of a protected type, declared
7063 -- inside the type, and the candidate is primitive of a
7064 -- limited or synchronized interface.
7067 and then Is_Protected_Type (Typ)
7069 (Is_Limited_Interface (Iface_Typ)
7070 or else Is_Protected_Interface (Iface_Typ)
7071 or else Is_Synchronized_Interface (Iface_Typ)
7072 or else Is_Task_Interface (Iface_Typ))
7074 -- Must reword this message, comma before to in -gnatj
7078 ("first formal of & must be of mode `OUT`, `IN OUT`"
7079 & " or access-to-variable", Typ, Candidate);
7081 ("\to be overridden by protected procedure or entry "
7082 & "(RM 9.4(11.9/2))", Typ);
7086 Overridden_Subp := Candidate;
7089 end Check_Synchronized_Overriding;
7091 ----------------------------
7092 -- Is_Private_Declaration --
7093 ----------------------------
7095 function Is_Private_Declaration (E : Entity_Id) return Boolean is
7096 Priv_Decls : List_Id;
7097 Decl : constant Node_Id := Unit_Declaration_Node (E);
7100 if Is_Package_Or_Generic_Package (Current_Scope)
7101 and then In_Private_Part (Current_Scope)
7104 Private_Declarations (
7105 Specification (Unit_Declaration_Node (Current_Scope)));
7107 return In_Package_Body (Current_Scope)
7109 (Is_List_Member (Decl)
7110 and then List_Containing (Decl) = Priv_Decls)
7111 or else (Nkind (Parent (Decl)) = N_Package_Specification
7114 (Defining_Entity (Parent (Decl)))
7115 and then List_Containing (Parent (Parent (Decl)))
7120 end Is_Private_Declaration;
7122 --------------------------
7123 -- Is_Overriding_Alias --
7124 --------------------------
7126 function Is_Overriding_Alias
7128 New_E : Entity_Id) return Boolean
7130 AO : constant Entity_Id := Alias (Old_E);
7131 AN : constant Entity_Id := Alias (New_E);
7134 return Scope (AO) /= Scope (AN)
7135 or else No (DTC_Entity (AO))
7136 or else No (DTC_Entity (AN))
7137 or else DT_Position (AO) = DT_Position (AN);
7138 end Is_Overriding_Alias;
7140 -- Start of processing for New_Overloaded_Entity
7143 -- We need to look for an entity that S may override. This must be a
7144 -- homonym in the current scope, so we look for the first homonym of
7145 -- S in the current scope as the starting point for the search.
7147 E := Current_Entity_In_Scope (S);
7149 -- If there is no homonym then this is definitely not overriding
7152 Enter_Overloaded_Entity (S);
7153 Check_Dispatching_Operation (S, Empty);
7154 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
7156 -- If subprogram has an explicit declaration, check whether it
7157 -- has an overriding indicator.
7159 if Comes_From_Source (S) then
7160 Check_Synchronized_Overriding (S, Overridden_Subp);
7161 Check_Overriding_Indicator
7162 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
7165 -- If there is a homonym that is not overloadable, then we have an
7166 -- error, except for the special cases checked explicitly below.
7168 elsif not Is_Overloadable (E) then
7170 -- Check for spurious conflict produced by a subprogram that has the
7171 -- same name as that of the enclosing generic package. The conflict
7172 -- occurs within an instance, between the subprogram and the renaming
7173 -- declaration for the package. After the subprogram, the package
7174 -- renaming declaration becomes hidden.
7176 if Ekind (E) = E_Package
7177 and then Present (Renamed_Object (E))
7178 and then Renamed_Object (E) = Current_Scope
7179 and then Nkind (Parent (Renamed_Object (E))) =
7180 N_Package_Specification
7181 and then Present (Generic_Parent (Parent (Renamed_Object (E))))
7184 Set_Is_Immediately_Visible (E, False);
7185 Enter_Overloaded_Entity (S);
7186 Set_Homonym (S, Homonym (E));
7187 Check_Dispatching_Operation (S, Empty);
7188 Check_Overriding_Indicator (S, Empty, Is_Primitive => False);
7190 -- If the subprogram is implicit it is hidden by the previous
7191 -- declaration. However if it is dispatching, it must appear in the
7192 -- dispatch table anyway, because it can be dispatched to even if it
7193 -- cannot be called directly.
7195 elsif Present (Alias (S))
7196 and then not Comes_From_Source (S)
7198 Set_Scope (S, Current_Scope);
7200 if Is_Dispatching_Operation (Alias (S)) then
7201 Check_Dispatching_Operation (S, Empty);
7207 Error_Msg_Sloc := Sloc (E);
7209 -- Generate message, with useful additional warning if in generic
7211 if Is_Generic_Unit (E) then
7212 Error_Msg_N ("previous generic unit cannot be overloaded", S);
7213 Error_Msg_N ("\& conflicts with declaration#", S);
7215 Error_Msg_N ("& conflicts with declaration#", S);
7221 -- E exists and is overloadable
7224 -- Ada 2005 (AI-251): Derivation of abstract interface primitives
7225 -- need no check against the homonym chain. They are directly added
7226 -- to the list of primitive operations of Derived_Type.
7228 if Ada_Version >= Ada_05
7229 and then Present (Derived_Type)
7230 and then Is_Dispatching_Operation (Alias (S))
7231 and then Present (Find_Dispatching_Type (Alias (S)))
7232 and then Is_Interface (Find_Dispatching_Type (Alias (S)))
7234 goto Add_New_Entity;
7237 Check_Synchronized_Overriding (S, Overridden_Subp);
7239 -- Loop through E and its homonyms to determine if any of them is
7240 -- the candidate for overriding by S.
7242 while Present (E) loop
7244 -- Definitely not interesting if not in the current scope
7246 if Scope (E) /= Current_Scope then
7249 -- Check if we have type conformance
7251 elsif Type_Conformant (E, S) then
7253 -- If the old and new entities have the same profile and one
7254 -- is not the body of the other, then this is an error, unless
7255 -- one of them is implicitly declared.
7257 -- There are some cases when both can be implicit, for example
7258 -- when both a literal and a function that overrides it are
7259 -- inherited in a derivation, or when an inherited operation
7260 -- of a tagged full type overrides the inherited operation of
7261 -- a private extension. Ada 83 had a special rule for the
7262 -- literal case. In Ada95, the later implicit operation hides
7263 -- the former, and the literal is always the former. In the
7264 -- odd case where both are derived operations declared at the
7265 -- same point, both operations should be declared, and in that
7266 -- case we bypass the following test and proceed to the next
7267 -- part. This can only occur for certain obscure cases in
7268 -- instances, when an operation on a type derived from a formal
7269 -- private type does not override a homograph inherited from
7270 -- the actual. In subsequent derivations of such a type, the
7271 -- DT positions of these operations remain distinct, if they
7274 if Present (Alias (S))
7275 and then (No (Alias (E))
7276 or else Comes_From_Source (E)
7277 or else Is_Abstract_Subprogram (S)
7279 (Is_Dispatching_Operation (E)
7280 and then Is_Overriding_Alias (E, S)))
7281 and then Ekind (E) /= E_Enumeration_Literal
7283 -- When an derived operation is overloaded it may be due to
7284 -- the fact that the full view of a private extension
7285 -- re-inherits. It has to be dealt with.
7287 if Is_Package_Or_Generic_Package (Current_Scope)
7288 and then In_Private_Part (Current_Scope)
7290 Check_Operation_From_Private_View (S, E);
7293 -- In any case the implicit operation remains hidden by
7294 -- the existing declaration, which is overriding.
7296 Set_Is_Overriding_Operation (E);
7298 if Comes_From_Source (E) then
7299 Check_Overriding_Indicator (E, S, Is_Primitive => False);
7301 -- Indicate that E overrides the operation from which
7304 if Present (Alias (S)) then
7305 Set_Overridden_Operation (E, Alias (S));
7307 Set_Overridden_Operation (E, S);
7313 -- Within an instance, the renaming declarations for
7314 -- actual subprograms may become ambiguous, but they do
7315 -- not hide each other.
7317 elsif Ekind (E) /= E_Entry
7318 and then not Comes_From_Source (E)
7319 and then not Is_Generic_Instance (E)
7320 and then (Present (Alias (E))
7321 or else Is_Intrinsic_Subprogram (E))
7322 and then (not In_Instance
7323 or else No (Parent (E))
7324 or else Nkind (Unit_Declaration_Node (E)) /=
7325 N_Subprogram_Renaming_Declaration)
7327 -- A subprogram child unit is not allowed to override
7328 -- an inherited subprogram (10.1.1(20)).
7330 if Is_Child_Unit (S) then
7332 ("child unit overrides inherited subprogram in parent",
7337 if Is_Non_Overriding_Operation (E, S) then
7338 Enter_Overloaded_Entity (S);
7340 if No (Derived_Type)
7341 or else Is_Tagged_Type (Derived_Type)
7343 Check_Dispatching_Operation (S, Empty);
7349 -- E is a derived operation or an internal operator which
7350 -- is being overridden. Remove E from further visibility.
7351 -- Furthermore, if E is a dispatching operation, it must be
7352 -- replaced in the list of primitive operations of its type
7353 -- (see Override_Dispatching_Operation).
7355 Overridden_Subp := E;
7361 Prev := First_Entity (Current_Scope);
7362 while Present (Prev)
7363 and then Next_Entity (Prev) /= E
7368 -- It is possible for E to be in the current scope and
7369 -- yet not in the entity chain. This can only occur in a
7370 -- generic context where E is an implicit concatenation
7371 -- in the formal part, because in a generic body the
7372 -- entity chain starts with the formals.
7375 (Present (Prev) or else Chars (E) = Name_Op_Concat);
7377 -- E must be removed both from the entity_list of the
7378 -- current scope, and from the visibility chain
7380 if Debug_Flag_E then
7381 Write_Str ("Override implicit operation ");
7382 Write_Int (Int (E));
7386 -- If E is a predefined concatenation, it stands for four
7387 -- different operations. As a result, a single explicit
7388 -- declaration does not hide it. In a possible ambiguous
7389 -- situation, Disambiguate chooses the user-defined op,
7390 -- so it is correct to retain the previous internal one.
7392 if Chars (E) /= Name_Op_Concat
7393 or else Ekind (E) /= E_Operator
7395 -- For nondispatching derived operations that are
7396 -- overridden by a subprogram declared in the private
7397 -- part of a package, we retain the derived subprogram
7398 -- but mark it as not immediately visible. If the
7399 -- derived operation was declared in the visible part
7400 -- then this ensures that it will still be visible
7401 -- outside the package with the proper signature
7402 -- (calls from outside must also be directed to this
7403 -- version rather than the overriding one, unlike the
7404 -- dispatching case). Calls from inside the package
7405 -- will still resolve to the overriding subprogram
7406 -- since the derived one is marked as not visible
7407 -- within the package.
7409 -- If the private operation is dispatching, we achieve
7410 -- the overriding by keeping the implicit operation
7411 -- but setting its alias to be the overriding one. In
7412 -- this fashion the proper body is executed in all
7413 -- cases, but the original signature is used outside
7416 -- If the overriding is not in the private part, we
7417 -- remove the implicit operation altogether.
7419 if Is_Private_Declaration (S) then
7420 if not Is_Dispatching_Operation (E) then
7421 Set_Is_Immediately_Visible (E, False);
7423 -- Work done in Override_Dispatching_Operation,
7424 -- so nothing else need to be done here.
7430 -- Find predecessor of E in Homonym chain
7432 if E = Current_Entity (E) then
7435 Prev_Vis := Current_Entity (E);
7436 while Homonym (Prev_Vis) /= E loop
7437 Prev_Vis := Homonym (Prev_Vis);
7441 if Prev_Vis /= Empty then
7443 -- Skip E in the visibility chain
7445 Set_Homonym (Prev_Vis, Homonym (E));
7448 Set_Name_Entity_Id (Chars (E), Homonym (E));
7451 Set_Next_Entity (Prev, Next_Entity (E));
7453 if No (Next_Entity (Prev)) then
7454 Set_Last_Entity (Current_Scope, Prev);
7460 Enter_Overloaded_Entity (S);
7461 Set_Is_Overriding_Operation (S);
7462 Check_Overriding_Indicator (S, E, Is_Primitive => True);
7464 -- Indicate that S overrides the operation from which
7467 if Comes_From_Source (S) then
7468 if Present (Alias (E)) then
7469 Set_Overridden_Operation (S, Alias (E));
7471 Set_Overridden_Operation (S, E);
7475 if Is_Dispatching_Operation (E) then
7477 -- An overriding dispatching subprogram inherits the
7478 -- convention of the overridden subprogram (by
7481 Set_Convention (S, Convention (E));
7482 Check_Dispatching_Operation (S, E);
7485 Check_Dispatching_Operation (S, Empty);
7488 Check_For_Primitive_Subprogram
7489 (Is_Primitive_Subp, Is_Overriding => True);
7490 goto Check_Inequality;
7493 -- Apparent redeclarations in instances can occur when two
7494 -- formal types get the same actual type. The subprograms in
7495 -- in the instance are legal, even if not callable from the
7496 -- outside. Calls from within are disambiguated elsewhere.
7497 -- For dispatching operations in the visible part, the usual
7498 -- rules apply, and operations with the same profile are not
7501 elsif (In_Instance_Visible_Part
7502 and then not Is_Dispatching_Operation (E))
7503 or else In_Instance_Not_Visible
7507 -- Here we have a real error (identical profile)
7510 Error_Msg_Sloc := Sloc (E);
7512 -- Avoid cascaded errors if the entity appears in
7513 -- subsequent calls.
7515 Set_Scope (S, Current_Scope);
7517 -- Generate error, with extra useful warning for the case
7518 -- of a generic instance with no completion.
7520 if Is_Generic_Instance (S)
7521 and then not Has_Completion (E)
7524 ("instantiation cannot provide body for&", S);
7525 Error_Msg_N ("\& conflicts with declaration#", S);
7527 Error_Msg_N ("& conflicts with declaration#", S);
7534 -- If one subprogram has an access parameter and the other
7535 -- a parameter of an access type, calls to either might be
7536 -- ambiguous. Verify that parameters match except for the
7537 -- access parameter.
7539 if May_Hide_Profile then
7545 F1 := First_Formal (S);
7546 F2 := First_Formal (E);
7547 while Present (F1) and then Present (F2) loop
7548 if Is_Access_Type (Etype (F1)) then
7549 if not Is_Access_Type (Etype (F2))
7550 or else not Conforming_Types
7551 (Designated_Type (Etype (F1)),
7552 Designated_Type (Etype (F2)),
7555 May_Hide_Profile := False;
7559 not Conforming_Types
7560 (Etype (F1), Etype (F2), Type_Conformant)
7562 May_Hide_Profile := False;
7573 Error_Msg_NE ("calls to& may be ambiguous?", S, S);
7584 -- On exit, we know that S is a new entity
7586 Enter_Overloaded_Entity (S);
7587 Check_For_Primitive_Subprogram (Is_Primitive_Subp);
7588 Check_Overriding_Indicator
7589 (S, Overridden_Subp, Is_Primitive => Is_Primitive_Subp);
7591 -- If S is a derived operation for an untagged type then by
7592 -- definition it's not a dispatching operation (even if the parent
7593 -- operation was dispatching), so we don't call
7594 -- Check_Dispatching_Operation in that case.
7596 if No (Derived_Type)
7597 or else Is_Tagged_Type (Derived_Type)
7599 Check_Dispatching_Operation (S, Empty);
7603 -- If this is a user-defined equality operator that is not a derived
7604 -- subprogram, create the corresponding inequality. If the operation is
7605 -- dispatching, the expansion is done elsewhere, and we do not create
7606 -- an explicit inequality operation.
7608 <<Check_Inequality>>
7609 if Chars (S) = Name_Op_Eq
7610 and then Etype (S) = Standard_Boolean
7611 and then Present (Parent (S))
7612 and then not Is_Dispatching_Operation (S)
7614 Make_Inequality_Operator (S);
7616 end New_Overloaded_Entity;
7618 ---------------------
7619 -- Process_Formals --
7620 ---------------------
7622 procedure Process_Formals
7624 Related_Nod : Node_Id)
7626 Param_Spec : Node_Id;
7628 Formal_Type : Entity_Id;
7632 Num_Out_Params : Nat := 0;
7633 First_Out_Param : Entity_Id := Empty;
7634 -- Used for setting Is_Only_Out_Parameter
7636 function Is_Class_Wide_Default (D : Node_Id) return Boolean;
7637 -- Check whether the default has a class-wide type. After analysis the
7638 -- default has the type of the formal, so we must also check explicitly
7639 -- for an access attribute.
7641 ---------------------------
7642 -- Is_Class_Wide_Default --
7643 ---------------------------
7645 function Is_Class_Wide_Default (D : Node_Id) return Boolean is
7647 return Is_Class_Wide_Type (Designated_Type (Etype (D)))
7648 or else (Nkind (D) = N_Attribute_Reference
7649 and then Attribute_Name (D) = Name_Access
7650 and then Is_Class_Wide_Type (Etype (Prefix (D))));
7651 end Is_Class_Wide_Default;
7653 -- Start of processing for Process_Formals
7656 -- In order to prevent premature use of the formals in the same formal
7657 -- part, the Ekind is left undefined until all default expressions are
7658 -- analyzed. The Ekind is established in a separate loop at the end.
7660 Param_Spec := First (T);
7661 while Present (Param_Spec) loop
7662 Formal := Defining_Identifier (Param_Spec);
7663 Set_Never_Set_In_Source (Formal, True);
7664 Enter_Name (Formal);
7666 -- Case of ordinary parameters
7668 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
7669 Find_Type (Parameter_Type (Param_Spec));
7670 Ptype := Parameter_Type (Param_Spec);
7672 if Ptype = Error then
7676 Formal_Type := Entity (Ptype);
7678 if Is_Incomplete_Type (Formal_Type)
7680 (Is_Class_Wide_Type (Formal_Type)
7681 and then Is_Incomplete_Type (Root_Type (Formal_Type)))
7683 -- Ada 2005 (AI-326): Tagged incomplete types allowed
7685 if Is_Tagged_Type (Formal_Type) then
7688 -- Special handling of Value_Type for CIL case
7690 elsif Is_Value_Type (Formal_Type) then
7693 elsif not Nkind_In (Parent (T), N_Access_Function_Definition,
7694 N_Access_Procedure_Definition)
7696 Error_Msg_N ("invalid use of incomplete type", Param_Spec);
7698 -- An incomplete type that is not tagged is allowed in an
7699 -- access-to-subprogram type only if it is a local declaration
7700 -- with a forthcoming completion (3.10.1 (9.2/2)).
7702 elsif Scope (Formal_Type) /= Scope (Current_Scope) then
7704 ("invalid use of limited view of type", Param_Spec);
7707 elsif Ekind (Formal_Type) = E_Void then
7708 Error_Msg_NE ("premature use of&",
7709 Parameter_Type (Param_Spec), Formal_Type);
7712 -- Ada 2005 (AI-231): Create and decorate an internal subtype
7713 -- declaration corresponding to the null-excluding type of the
7714 -- formal in the enclosing scope. Finally, replace the parameter
7715 -- type of the formal with the internal subtype.
7717 if Ada_Version >= Ada_05
7718 and then Null_Exclusion_Present (Param_Spec)
7720 if not Is_Access_Type (Formal_Type) then
7722 ("`NOT NULL` allowed only for an access type", Param_Spec);
7725 if Can_Never_Be_Null (Formal_Type)
7726 and then Comes_From_Source (Related_Nod)
7729 ("`NOT NULL` not allowed (& already excludes null)",
7735 Create_Null_Excluding_Itype
7737 Related_Nod => Related_Nod,
7738 Scope_Id => Scope (Current_Scope));
7740 -- If the designated type of the itype is an itype we
7741 -- decorate it with the Has_Delayed_Freeze attribute to
7742 -- avoid problems with the backend.
7745 -- type T is access procedure;
7746 -- procedure Op (O : not null T);
7748 if Is_Itype (Directly_Designated_Type (Formal_Type)) then
7749 Set_Has_Delayed_Freeze (Formal_Type);
7754 -- An access formal type
7758 Access_Definition (Related_Nod, Parameter_Type (Param_Spec));
7760 -- No need to continue if we already notified errors
7762 if not Present (Formal_Type) then
7766 -- Ada 2005 (AI-254)
7769 AD : constant Node_Id :=
7770 Access_To_Subprogram_Definition
7771 (Parameter_Type (Param_Spec));
7773 if Present (AD) and then Protected_Present (AD) then
7775 Replace_Anonymous_Access_To_Protected_Subprogram
7781 Set_Etype (Formal, Formal_Type);
7782 Default := Expression (Param_Spec);
7784 if Present (Default) then
7785 if Out_Present (Param_Spec) then
7787 ("default initialization only allowed for IN parameters",
7791 -- Do the special preanalysis of the expression (see section on
7792 -- "Handling of Default Expressions" in the spec of package Sem).
7794 Preanalyze_Spec_Expression (Default, Formal_Type);
7796 -- An access to constant cannot be the default for
7797 -- an access parameter that is an access to variable.
7799 if Ekind (Formal_Type) = E_Anonymous_Access_Type
7800 and then not Is_Access_Constant (Formal_Type)
7801 and then Is_Access_Type (Etype (Default))
7802 and then Is_Access_Constant (Etype (Default))
7805 ("formal that is access to variable cannot be initialized " &
7806 "with an access-to-constant expression", Default);
7809 -- Check that the designated type of an access parameter's default
7810 -- is not a class-wide type unless the parameter's designated type
7811 -- is also class-wide.
7813 if Ekind (Formal_Type) = E_Anonymous_Access_Type
7814 and then not From_With_Type (Formal_Type)
7815 and then Is_Class_Wide_Default (Default)
7816 and then not Is_Class_Wide_Type (Designated_Type (Formal_Type))
7819 ("access to class-wide expression not allowed here", Default);
7823 -- Ada 2005 (AI-231): Static checks
7825 if Ada_Version >= Ada_05
7826 and then Is_Access_Type (Etype (Formal))
7827 and then Can_Never_Be_Null (Etype (Formal))
7829 Null_Exclusion_Static_Checks (Param_Spec);
7836 -- If this is the formal part of a function specification, analyze the
7837 -- subtype mark in the context where the formals are visible but not
7838 -- yet usable, and may hide outer homographs.
7840 if Nkind (Related_Nod) = N_Function_Specification then
7841 Analyze_Return_Type (Related_Nod);
7844 -- Now set the kind (mode) of each formal
7846 Param_Spec := First (T);
7848 while Present (Param_Spec) loop
7849 Formal := Defining_Identifier (Param_Spec);
7850 Set_Formal_Mode (Formal);
7852 if Ekind (Formal) = E_In_Parameter then
7853 Set_Default_Value (Formal, Expression (Param_Spec));
7855 if Present (Expression (Param_Spec)) then
7856 Default := Expression (Param_Spec);
7858 if Is_Scalar_Type (Etype (Default)) then
7860 (Parameter_Type (Param_Spec)) /= N_Access_Definition
7862 Formal_Type := Entity (Parameter_Type (Param_Spec));
7865 Formal_Type := Access_Definition
7866 (Related_Nod, Parameter_Type (Param_Spec));
7869 Apply_Scalar_Range_Check (Default, Formal_Type);
7873 elsif Ekind (Formal) = E_Out_Parameter then
7874 Num_Out_Params := Num_Out_Params + 1;
7876 if Num_Out_Params = 1 then
7877 First_Out_Param := Formal;
7880 elsif Ekind (Formal) = E_In_Out_Parameter then
7881 Num_Out_Params := Num_Out_Params + 1;
7887 if Present (First_Out_Param) and then Num_Out_Params = 1 then
7888 Set_Is_Only_Out_Parameter (First_Out_Param);
7890 end Process_Formals;
7896 procedure Process_PPCs
7898 Spec_Id : Entity_Id;
7899 Body_Id : Entity_Id)
7901 Loc : constant Source_Ptr := Sloc (N);
7903 Plist : List_Id := No_List;
7907 function Grab_PPC (Nam : Name_Id) return Node_Id;
7908 -- Prag contains an analyzed precondition or postcondition pragma.
7909 -- This function copies the pragma, changes it to the corresponding
7910 -- Check pragma and returns the Check pragma as the result. The
7911 -- argument Nam is either Name_Precondition or Name_Postcondition.
7917 function Grab_PPC (Nam : Name_Id) return Node_Id is
7918 CP : constant Node_Id := New_Copy_Tree (Prag);
7921 -- Set Analyzed to false, since we want to reanalyze the check
7922 -- procedure. Note that it is only at the outer level that we
7923 -- do this fiddling, for the spec cases, the already preanalyzed
7924 -- parameters are not affected.
7926 -- For a postcondition pragma within a generic, preserve the pragma
7927 -- for later expansion.
7929 Set_Analyzed (CP, False);
7931 if Nam = Name_Postcondition
7932 and then not Expander_Active
7937 -- Change pragma into corresponding pragma Check
7939 Prepend_To (Pragma_Argument_Associations (CP),
7940 Make_Pragma_Argument_Association (Sloc (Prag),
7942 Make_Identifier (Loc,
7944 Set_Pragma_Identifier (CP,
7945 Make_Identifier (Sloc (Prag),
7946 Chars => Name_Check));
7951 -- Start of processing for Process_PPCs
7954 -- Nothing to do if we are not generating code
7956 if Operating_Mode /= Generate_Code then
7960 -- Grab preconditions from spec
7962 if Present (Spec_Id) then
7964 -- Loop through PPC pragmas from spec. Note that preconditions from
7965 -- the body will be analyzed and converted when we scan the body
7966 -- declarations below.
7968 Prag := Spec_PPC_List (Spec_Id);
7969 while Present (Prag) loop
7970 if Pragma_Name (Prag) = Name_Precondition
7971 and then PPC_Enabled (Prag)
7973 -- Add pragma Check at the start of the declarations of N.
7974 -- Note that this processing reverses the order of the list,
7975 -- which is what we want since new entries were chained to
7976 -- the head of the list.
7978 Prepend (Grab_PPC (Name_Precondition), Declarations (N));
7981 Prag := Next_Pragma (Prag);
7985 -- Build postconditions procedure if needed and prepend the following
7986 -- declaration to the start of the declarations for the subprogram.
7988 -- procedure _postconditions [(_Result : resulttype)] is
7990 -- pragma Check (Postcondition, condition [,message]);
7991 -- pragma Check (Postcondition, condition [,message]);
7995 -- First we deal with the postconditions in the body
7997 if Is_Non_Empty_List (Declarations (N)) then
7999 -- Loop through declarations
8001 Prag := First (Declarations (N));
8002 while Present (Prag) loop
8003 if Nkind (Prag) = N_Pragma then
8005 -- If pragma, capture if enabled postcondition, else ignore
8007 if Pragma_Name (Prag) = Name_Postcondition
8008 and then Check_Enabled (Name_Postcondition)
8010 if Plist = No_List then
8011 Plist := Empty_List;
8016 -- If expansion is disabled, as in a generic unit,
8017 -- save pragma for later expansion.
8019 if not Expander_Active then
8020 Prepend (Grab_PPC (Name_Postcondition), Declarations (N));
8022 Append (Grab_PPC (Name_Postcondition), Plist);
8028 -- Not a pragma, if comes from source, then end scan
8030 elsif Comes_From_Source (Prag) then
8033 -- Skip stuff not coming from source
8041 -- Now deal with any postconditions from the spec
8043 if Present (Spec_Id) then
8045 -- Loop through PPC pragmas from spec
8047 Prag := Spec_PPC_List (Spec_Id);
8048 while Present (Prag) loop
8049 if Pragma_Name (Prag) = Name_Postcondition
8050 and then PPC_Enabled (Prag)
8052 if Plist = No_List then
8053 Plist := Empty_List;
8056 if not Expander_Active then
8057 Prepend (Grab_PPC (Name_Postcondition), Declarations (N));
8059 Append (Grab_PPC (Name_Postcondition), Plist);
8063 Prag := Next_Pragma (Prag);
8067 -- If we had any postconditions and expansion is enabled, build
8068 -- the _Postconditions procedure.
8071 and then Expander_Active
8073 Subp := Defining_Entity (N);
8075 if Etype (Subp) /= Standard_Void_Type then
8077 Make_Parameter_Specification (Loc,
8078 Defining_Identifier =>
8079 Make_Defining_Identifier (Loc,
8080 Chars => Name_uResult),
8081 Parameter_Type => New_Occurrence_Of (Etype (Subp), Loc)));
8087 Post_Proc : constant Entity_Id :=
8088 Make_Defining_Identifier (Loc,
8089 Chars => Name_uPostconditions);
8090 -- The entity for the _Postconditions procedure
8092 Prepend_To (Declarations (N),
8093 Make_Subprogram_Body (Loc,
8095 Make_Procedure_Specification (Loc,
8096 Defining_Unit_Name => Post_Proc,
8097 Parameter_Specifications => Parms),
8099 Declarations => Empty_List,
8101 Handled_Statement_Sequence =>
8102 Make_Handled_Sequence_Of_Statements (Loc,
8103 Statements => Plist)));
8105 -- If this is a procedure, set the Postcondition_Proc attribute
8107 if Etype (Subp) = Standard_Void_Type then
8108 Set_Postcondition_Proc (Spec_Id, Post_Proc);
8112 if Present (Spec_Id) then
8113 Set_Has_Postconditions (Spec_Id);
8115 Set_Has_Postconditions (Body_Id);
8120 ----------------------------
8121 -- Reference_Body_Formals --
8122 ----------------------------
8124 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is
8129 if Error_Posted (Spec) then
8133 -- Iterate over both lists. They may be of different lengths if the two
8134 -- specs are not conformant.
8136 Fs := First_Formal (Spec);
8137 Fb := First_Formal (Bod);
8138 while Present (Fs) and then Present (Fb) loop
8139 Generate_Reference (Fs, Fb, 'b');
8142 Style.Check_Identifier (Fb, Fs);
8145 Set_Spec_Entity (Fb, Fs);
8146 Set_Referenced (Fs, False);
8150 end Reference_Body_Formals;
8152 -------------------------
8153 -- Set_Actual_Subtypes --
8154 -------------------------
8156 procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is
8157 Loc : constant Source_Ptr := Sloc (N);
8161 First_Stmt : Node_Id := Empty;
8162 AS_Needed : Boolean;
8165 -- If this is an empty initialization procedure, no need to create
8166 -- actual subtypes (small optimization).
8168 if Ekind (Subp) = E_Procedure
8169 and then Is_Null_Init_Proc (Subp)
8174 Formal := First_Formal (Subp);
8175 while Present (Formal) loop
8176 T := Etype (Formal);
8178 -- We never need an actual subtype for a constrained formal
8180 if Is_Constrained (T) then
8183 -- If we have unknown discriminants, then we do not need an actual
8184 -- subtype, or more accurately we cannot figure it out! Note that
8185 -- all class-wide types have unknown discriminants.
8187 elsif Has_Unknown_Discriminants (T) then
8190 -- At this stage we have an unconstrained type that may need an
8191 -- actual subtype. For sure the actual subtype is needed if we have
8192 -- an unconstrained array type.
8194 elsif Is_Array_Type (T) then
8197 -- The only other case needing an actual subtype is an unconstrained
8198 -- record type which is an IN parameter (we cannot generate actual
8199 -- subtypes for the OUT or IN OUT case, since an assignment can
8200 -- change the discriminant values. However we exclude the case of
8201 -- initialization procedures, since discriminants are handled very
8202 -- specially in this context, see the section entitled "Handling of
8203 -- Discriminants" in Einfo.
8205 -- We also exclude the case of Discrim_SO_Functions (functions used
8206 -- in front end layout mode for size/offset values), since in such
8207 -- functions only discriminants are referenced, and not only are such
8208 -- subtypes not needed, but they cannot always be generated, because
8209 -- of order of elaboration issues.
8211 elsif Is_Record_Type (T)
8212 and then Ekind (Formal) = E_In_Parameter
8213 and then Chars (Formal) /= Name_uInit
8214 and then not Is_Unchecked_Union (T)
8215 and then not Is_Discrim_SO_Function (Subp)
8219 -- All other cases do not need an actual subtype
8225 -- Generate actual subtypes for unconstrained arrays and
8226 -- unconstrained discriminated records.
8229 if Nkind (N) = N_Accept_Statement then
8231 -- If expansion is active, The formal is replaced by a local
8232 -- variable that renames the corresponding entry of the
8233 -- parameter block, and it is this local variable that may
8234 -- require an actual subtype.
8236 if Expander_Active then
8237 Decl := Build_Actual_Subtype (T, Renamed_Object (Formal));
8239 Decl := Build_Actual_Subtype (T, Formal);
8242 if Present (Handled_Statement_Sequence (N)) then
8244 First (Statements (Handled_Statement_Sequence (N)));
8245 Prepend (Decl, Statements (Handled_Statement_Sequence (N)));
8246 Mark_Rewrite_Insertion (Decl);
8248 -- If the accept statement has no body, there will be no
8249 -- reference to the actuals, so no need to compute actual
8256 Decl := Build_Actual_Subtype (T, Formal);
8257 Prepend (Decl, Declarations (N));
8258 Mark_Rewrite_Insertion (Decl);
8261 -- The declaration uses the bounds of an existing object, and
8262 -- therefore needs no constraint checks.
8264 Analyze (Decl, Suppress => All_Checks);
8266 -- We need to freeze manually the generated type when it is
8267 -- inserted anywhere else than in a declarative part.
8269 if Present (First_Stmt) then
8270 Insert_List_Before_And_Analyze (First_Stmt,
8271 Freeze_Entity (Defining_Identifier (Decl), Loc));
8274 if Nkind (N) = N_Accept_Statement
8275 and then Expander_Active
8277 Set_Actual_Subtype (Renamed_Object (Formal),
8278 Defining_Identifier (Decl));
8280 Set_Actual_Subtype (Formal, Defining_Identifier (Decl));
8284 Next_Formal (Formal);
8286 end Set_Actual_Subtypes;
8288 ---------------------
8289 -- Set_Formal_Mode --
8290 ---------------------
8292 procedure Set_Formal_Mode (Formal_Id : Entity_Id) is
8293 Spec : constant Node_Id := Parent (Formal_Id);
8296 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
8297 -- since we ensure that corresponding actuals are always valid at the
8298 -- point of the call.
8300 if Out_Present (Spec) then
8301 if Ekind (Scope (Formal_Id)) = E_Function
8302 or else Ekind (Scope (Formal_Id)) = E_Generic_Function
8304 Error_Msg_N ("functions can only have IN parameters", Spec);
8305 Set_Ekind (Formal_Id, E_In_Parameter);
8307 elsif In_Present (Spec) then
8308 Set_Ekind (Formal_Id, E_In_Out_Parameter);
8311 Set_Ekind (Formal_Id, E_Out_Parameter);
8312 Set_Never_Set_In_Source (Formal_Id, True);
8313 Set_Is_True_Constant (Formal_Id, False);
8314 Set_Current_Value (Formal_Id, Empty);
8318 Set_Ekind (Formal_Id, E_In_Parameter);
8321 -- Set Is_Known_Non_Null for access parameters since the language
8322 -- guarantees that access parameters are always non-null. We also set
8323 -- Can_Never_Be_Null, since there is no way to change the value.
8325 if Nkind (Parameter_Type (Spec)) = N_Access_Definition then
8327 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
8328 -- null; In Ada 2005, only if then null_exclusion is explicit.
8330 if Ada_Version < Ada_05
8331 or else Can_Never_Be_Null (Etype (Formal_Id))
8333 Set_Is_Known_Non_Null (Formal_Id);
8334 Set_Can_Never_Be_Null (Formal_Id);
8337 -- Ada 2005 (AI-231): Null-exclusion access subtype
8339 elsif Is_Access_Type (Etype (Formal_Id))
8340 and then Can_Never_Be_Null (Etype (Formal_Id))
8342 Set_Is_Known_Non_Null (Formal_Id);
8345 Set_Mechanism (Formal_Id, Default_Mechanism);
8346 Set_Formal_Validity (Formal_Id);
8347 end Set_Formal_Mode;
8349 -------------------------
8350 -- Set_Formal_Validity --
8351 -------------------------
8353 procedure Set_Formal_Validity (Formal_Id : Entity_Id) is
8355 -- If no validity checking, then we cannot assume anything about the
8356 -- validity of parameters, since we do not know there is any checking
8357 -- of the validity on the call side.
8359 if not Validity_Checks_On then
8362 -- If validity checking for parameters is enabled, this means we are
8363 -- not supposed to make any assumptions about argument values.
8365 elsif Validity_Check_Parameters then
8368 -- If we are checking in parameters, we will assume that the caller is
8369 -- also checking parameters, so we can assume the parameter is valid.
8371 elsif Ekind (Formal_Id) = E_In_Parameter
8372 and then Validity_Check_In_Params
8374 Set_Is_Known_Valid (Formal_Id, True);
8376 -- Similar treatment for IN OUT parameters
8378 elsif Ekind (Formal_Id) = E_In_Out_Parameter
8379 and then Validity_Check_In_Out_Params
8381 Set_Is_Known_Valid (Formal_Id, True);
8383 end Set_Formal_Validity;
8385 ------------------------
8386 -- Subtype_Conformant --
8387 ------------------------
8389 function Subtype_Conformant
8390 (New_Id : Entity_Id;
8392 Skip_Controlling_Formals : Boolean := False) return Boolean
8396 Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result,
8397 Skip_Controlling_Formals => Skip_Controlling_Formals);
8399 end Subtype_Conformant;
8401 ---------------------
8402 -- Type_Conformant --
8403 ---------------------
8405 function Type_Conformant
8406 (New_Id : Entity_Id;
8408 Skip_Controlling_Formals : Boolean := False) return Boolean
8412 May_Hide_Profile := False;
8415 (New_Id, Old_Id, Type_Conformant, False, Result,
8416 Skip_Controlling_Formals => Skip_Controlling_Formals);
8418 end Type_Conformant;
8420 -------------------------------
8421 -- Valid_Operator_Definition --
8422 -------------------------------
8424 procedure Valid_Operator_Definition (Designator : Entity_Id) is
8427 Id : constant Name_Id := Chars (Designator);
8431 F := First_Formal (Designator);
8432 while Present (F) loop
8435 if Present (Default_Value (F)) then
8437 ("default values not allowed for operator parameters",
8444 -- Verify that user-defined operators have proper number of arguments
8445 -- First case of operators which can only be unary
8448 or else Id = Name_Op_Abs
8452 -- Case of operators which can be unary or binary
8454 elsif Id = Name_Op_Add
8455 or Id = Name_Op_Subtract
8457 N_OK := (N in 1 .. 2);
8459 -- All other operators can only be binary
8467 ("incorrect number of arguments for operator", Designator);
8471 and then Base_Type (Etype (Designator)) = Standard_Boolean
8472 and then not Is_Intrinsic_Subprogram (Designator)
8475 ("explicit definition of inequality not allowed", Designator);
8477 end Valid_Operator_Definition;