1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Tss; use Exp_Tss;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
38 with Itypes; use Itypes;
39 with Lib.Xref; use Lib.Xref;
40 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
45 with Output; use Output;
46 with Rtsfind; use Rtsfind;
48 with Sem_Cat; use Sem_Cat;
49 with Sem_Ch3; use Sem_Ch3;
50 with Sem_Ch4; use Sem_Ch4;
51 with Sem_Ch5; use Sem_Ch5;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Ch10; use Sem_Ch10;
54 with Sem_Ch12; use Sem_Ch12;
55 with Sem_Disp; use Sem_Disp;
56 with Sem_Dist; use Sem_Dist;
57 with Sem_Elim; use Sem_Elim;
58 with Sem_Eval; use Sem_Eval;
59 with Sem_Mech; use Sem_Mech;
60 with Sem_Prag; use Sem_Prag;
61 with Sem_Res; use Sem_Res;
62 with Sem_Util; use Sem_Util;
63 with Sem_Type; use Sem_Type;
64 with Sem_Warn; use Sem_Warn;
65 with Sinput; use Sinput;
66 with Stand; use Stand;
67 with Sinfo; use Sinfo;
68 with Sinfo.CN; use Sinfo.CN;
69 with Snames; use Snames;
70 with Stringt; use Stringt;
72 with Stylesw; use Stylesw;
73 with Tbuild; use Tbuild;
74 with Uintp; use Uintp;
75 with Urealp; use Urealp;
76 with Validsw; use Validsw;
78 package body Sem_Ch6 is
80 -- The following flag is used to indicate that two formals in two
81 -- subprograms being checked for conformance differ only in that one is
82 -- an access parameter while the other is of a general access type with
83 -- the same designated type. In this case, if the rest of the signatures
84 -- match, a call to either subprogram may be ambiguous, which is worth
85 -- a warning. The flag is set in Compatible_Types, and the warning emitted
86 -- in New_Overloaded_Entity.
88 May_Hide_Profile : Boolean := False;
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Analyze_Return_Type (N : Node_Id);
95 -- Subsidiary to Process_Formals: analyze subtype mark in function
96 -- specification, in a context where the formals are visible and hide
99 procedure Analyze_Generic_Subprogram_Body (N : Node_Id; Gen_Id : Entity_Id);
100 -- Analyze a generic subprogram body. N is the body to be analyzed, and
101 -- Gen_Id is the defining entity Id for the corresponding spec.
103 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id);
104 -- If a subprogram has pragma Inline and inlining is active, use generic
105 -- machinery to build an unexpanded body for the subprogram. This body is
106 -- subsequenty used for inline expansions at call sites. If subprogram can
107 -- be inlined (depending on size and nature of local declarations) this
108 -- function returns true. Otherwise subprogram body is treated normally.
109 -- If proper warnings are enabled and the subprogram contains a construct
110 -- that cannot be inlined, the offending construct is flagged accordingly.
112 type Conformance_Type is
113 (Type_Conformant, Mode_Conformant, Subtype_Conformant, Fully_Conformant);
114 -- Conformance type used for following call, meaning matches the
115 -- RM definitions of the corresponding terms.
117 procedure Check_Conformance
120 Ctype : Conformance_Type;
122 Conforms : out Boolean;
123 Err_Loc : Node_Id := Empty;
124 Get_Inst : Boolean := False;
125 Skip_Controlling_Formals : Boolean := False);
126 -- Given two entities, this procedure checks that the profiles associated
127 -- with these entities meet the conformance criterion given by the third
128 -- parameter. If they conform, Conforms is set True and control returns
129 -- to the caller. If they do not conform, Conforms is set to False, and
130 -- in addition, if Errmsg is True on the call, proper messages are output
131 -- to complain about the conformance failure. If Err_Loc is non_Empty
132 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
133 -- error messages are placed on the appropriate part of the construct
134 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
135 -- against a formal access-to-subprogram type so Get_Instance_Of must
138 procedure Check_Overriding_Indicator
140 Does_Override : Boolean);
141 -- Verify the consistency of an overriding_indicator given for subprogram
142 -- declaration, body, renaming, or instantiation. The flag Does_Override
143 -- is set if the scope into which we are introducing the subprogram
144 -- contains a type-conformant subprogram that becomes hidden by the new
147 procedure Check_Subprogram_Order (N : Node_Id);
148 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
149 -- the alpha ordering rule for N if this ordering requirement applicable.
151 procedure Check_Returns
155 Proc : Entity_Id := Empty);
156 -- Called to check for missing return statements in a function body, or for
157 -- returns present in a procedure body which has No_Return set. L is the
158 -- handled statement sequence for the subprogram body. This procedure
159 -- checks all flow paths to make sure they either have return (Mode = 'F',
160 -- used for functions) or do not have a return (Mode = 'P', used for
161 -- No_Return procedures). The flag Err is set if there are any control
162 -- paths not explicitly terminated by a return in the function case, and is
163 -- True otherwise. Proc is the entity for the procedure case and is used
164 -- in posting the warning message.
166 function Conforming_Types
169 Ctype : Conformance_Type;
170 Get_Inst : Boolean := False) return Boolean;
171 -- Check that two formal parameter types conform, checking both for
172 -- equality of base types, and where required statically matching
173 -- subtypes, depending on the setting of Ctype.
175 procedure Enter_Overloaded_Entity (S : Entity_Id);
176 -- This procedure makes S, a new overloaded entity, into the first visible
177 -- entity with that name.
179 procedure Install_Entity (E : Entity_Id);
180 -- Make single entity visible. Used for generic formals as well
182 procedure Install_Formals (Id : Entity_Id);
183 -- On entry to a subprogram body, make the formals visible. Note that
184 -- simply placing the subprogram on the scope stack is not sufficient:
185 -- the formals must become the current entities for their names.
187 function Is_Non_Overriding_Operation
189 New_E : Entity_Id) return Boolean;
190 -- Enforce the rule given in 12.3(18): a private operation in an instance
191 -- overrides an inherited operation only if the corresponding operation
192 -- was overriding in the generic. This can happen for primitive operations
193 -- of types derived (in the generic unit) from formal private or formal
196 procedure Make_Inequality_Operator (S : Entity_Id);
197 -- Create the declaration for an inequality operator that is implicitly
198 -- created by a user-defined equality operator that yields a boolean.
200 procedure May_Need_Actuals (Fun : Entity_Id);
201 -- Flag functions that can be called without parameters, i.e. those that
202 -- have no parameters, or those for which defaults exist for all parameters
204 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id);
205 -- If there is a separate spec for a subprogram or generic subprogram, the
206 -- formals of the body are treated as references to the corresponding
207 -- formals of the spec. This reference does not count as an actual use of
208 -- the formal, in order to diagnose formals that are unused in the body.
210 procedure Set_Formal_Validity (Formal_Id : Entity_Id);
211 -- Formal_Id is an formal parameter entity. This procedure deals with
212 -- setting the proper validity status for this entity, which depends
213 -- on the kind of parameter and the validity checking mode.
215 ---------------------------------------------
216 -- Analyze_Abstract_Subprogram_Declaration --
217 ---------------------------------------------
219 procedure Analyze_Abstract_Subprogram_Declaration (N : Node_Id) is
220 Designator : constant Entity_Id :=
221 Analyze_Subprogram_Specification (Specification (N));
222 Scop : constant Entity_Id := Current_Scope;
225 Generate_Definition (Designator);
226 Set_Is_Abstract (Designator);
227 New_Overloaded_Entity (Designator);
228 Check_Delayed_Subprogram (Designator);
230 Set_Categorization_From_Scope (Designator, Scop);
232 if Ekind (Scope (Designator)) = E_Protected_Type then
234 ("abstract subprogram not allowed in protected type", N);
237 Generate_Reference_To_Formals (Designator);
238 end Analyze_Abstract_Subprogram_Declaration;
240 ----------------------------
241 -- Analyze_Function_Call --
242 ----------------------------
244 procedure Analyze_Function_Call (N : Node_Id) is
245 P : constant Node_Id := Name (N);
246 L : constant List_Id := Parameter_Associations (N);
252 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
253 -- as B (A, X). If the rewriting is successful, the call has been
254 -- analyzed and we just return.
256 if Nkind (P) = N_Selected_Component
257 and then Name (N) /= P
258 and then Is_Rewrite_Substitution (N)
259 and then Present (Etype (N))
264 -- If error analyzing name, then set Any_Type as result type and return
266 if Etype (P) = Any_Type then
267 Set_Etype (N, Any_Type);
271 -- Otherwise analyze the parameters
275 while Present (Actual) loop
277 Check_Parameterless_Call (Actual);
283 end Analyze_Function_Call;
285 -------------------------------------
286 -- Analyze_Generic_Subprogram_Body --
287 -------------------------------------
289 procedure Analyze_Generic_Subprogram_Body
293 Gen_Decl : constant Node_Id := Unit_Declaration_Node (Gen_Id);
294 Kind : constant Entity_Kind := Ekind (Gen_Id);
300 -- Copy body and disable expansion while analyzing the generic For a
301 -- stub, do not copy the stub (which would load the proper body), this
302 -- will be done when the proper body is analyzed.
304 if Nkind (N) /= N_Subprogram_Body_Stub then
305 New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
310 Spec := Specification (N);
312 -- Within the body of the generic, the subprogram is callable, and
313 -- behaves like the corresponding non-generic unit.
315 Body_Id := Defining_Entity (Spec);
317 if Kind = E_Generic_Procedure
318 and then Nkind (Spec) /= N_Procedure_Specification
320 Error_Msg_N ("invalid body for generic procedure ", Body_Id);
323 elsif Kind = E_Generic_Function
324 and then Nkind (Spec) /= N_Function_Specification
326 Error_Msg_N ("invalid body for generic function ", Body_Id);
330 Set_Corresponding_Body (Gen_Decl, Body_Id);
332 if Has_Completion (Gen_Id)
333 and then Nkind (Parent (N)) /= N_Subunit
335 Error_Msg_N ("duplicate generic body", N);
338 Set_Has_Completion (Gen_Id);
341 if Nkind (N) = N_Subprogram_Body_Stub then
342 Set_Ekind (Defining_Entity (Specification (N)), Kind);
344 Set_Corresponding_Spec (N, Gen_Id);
347 if Nkind (Parent (N)) = N_Compilation_Unit then
348 Set_Cunit_Entity (Current_Sem_Unit, Defining_Entity (N));
351 -- Make generic parameters immediately visible in the body. They are
352 -- needed to process the formals declarations. Then make the formals
353 -- visible in a separate step.
359 First_Ent : Entity_Id;
362 First_Ent := First_Entity (Gen_Id);
365 while Present (E) and then not Is_Formal (E) loop
370 Set_Use (Generic_Formal_Declarations (Gen_Decl));
372 -- Now generic formals are visible, and the specification can be
373 -- analyzed, for subsequent conformance check.
375 Body_Id := Analyze_Subprogram_Specification (Spec);
377 -- Make formal parameters visible
381 -- E is the first formal parameter, we loop through the formals
382 -- installing them so that they will be visible.
384 Set_First_Entity (Gen_Id, E);
385 while Present (E) loop
391 -- Visible generic entity is callable within its own body
393 Set_Ekind (Gen_Id, Ekind (Body_Id));
394 Set_Ekind (Body_Id, E_Subprogram_Body);
395 Set_Convention (Body_Id, Convention (Gen_Id));
396 Set_Scope (Body_Id, Scope (Gen_Id));
397 Check_Fully_Conformant (Body_Id, Gen_Id, Body_Id);
399 if Nkind (N) = N_Subprogram_Body_Stub then
401 -- No body to analyze, so restore state of generic unit
403 Set_Ekind (Gen_Id, Kind);
404 Set_Ekind (Body_Id, Kind);
406 if Present (First_Ent) then
407 Set_First_Entity (Gen_Id, First_Ent);
414 -- If this is a compilation unit, it must be made visible explicitly,
415 -- because the compilation of the declaration, unlike other library
416 -- unit declarations, does not. If it is not a unit, the following
417 -- is redundant but harmless.
419 Set_Is_Immediately_Visible (Gen_Id);
420 Reference_Body_Formals (Gen_Id, Body_Id);
422 Set_Actual_Subtypes (N, Current_Scope);
423 Analyze_Declarations (Declarations (N));
425 Analyze (Handled_Statement_Sequence (N));
427 Save_Global_References (Original_Node (N));
429 -- Prior to exiting the scope, include generic formals again (if any
430 -- are present) in the set of local entities.
432 if Present (First_Ent) then
433 Set_First_Entity (Gen_Id, First_Ent);
436 Check_References (Gen_Id);
439 Process_End_Label (Handled_Statement_Sequence (N), 't', Current_Scope);
441 Check_Subprogram_Order (N);
443 -- Outside of its body, unit is generic again
445 Set_Ekind (Gen_Id, Kind);
446 Generate_Reference (Gen_Id, Body_Id, 'b', Set_Ref => False);
447 Style.Check_Identifier (Body_Id, Gen_Id);
449 end Analyze_Generic_Subprogram_Body;
451 -----------------------------
452 -- Analyze_Operator_Symbol --
453 -----------------------------
455 -- An operator symbol such as "+" or "and" may appear in context where the
456 -- literal denotes an entity name, such as "+"(x, y) or in context when it
457 -- is just a string, as in (conjunction = "or"). In these cases the parser
458 -- generates this node, and the semantics does the disambiguation. Other
459 -- such case are actuals in an instantiation, the generic unit in an
460 -- instantiation, and pragma arguments.
462 procedure Analyze_Operator_Symbol (N : Node_Id) is
463 Par : constant Node_Id := Parent (N);
466 if (Nkind (Par) = N_Function_Call and then N = Name (Par))
467 or else Nkind (Par) = N_Function_Instantiation
468 or else (Nkind (Par) = N_Indexed_Component and then N = Prefix (Par))
469 or else (Nkind (Par) = N_Pragma_Argument_Association
470 and then not Is_Pragma_String_Literal (Par))
471 or else Nkind (Par) = N_Subprogram_Renaming_Declaration
472 or else (Nkind (Par) = N_Attribute_Reference
473 and then Attribute_Name (Par) /= Name_Value)
475 Find_Direct_Name (N);
478 Change_Operator_Symbol_To_String_Literal (N);
481 end Analyze_Operator_Symbol;
483 -----------------------------------
484 -- Analyze_Parameter_Association --
485 -----------------------------------
487 procedure Analyze_Parameter_Association (N : Node_Id) is
489 Analyze (Explicit_Actual_Parameter (N));
490 end Analyze_Parameter_Association;
492 ----------------------------
493 -- Analyze_Procedure_Call --
494 ----------------------------
496 procedure Analyze_Procedure_Call (N : Node_Id) is
497 Loc : constant Source_Ptr := Sloc (N);
498 P : constant Node_Id := Name (N);
499 Actuals : constant List_Id := Parameter_Associations (N);
503 procedure Analyze_Call_And_Resolve;
504 -- Do Analyze and Resolve calls for procedure call
506 ------------------------------
507 -- Analyze_Call_And_Resolve --
508 ------------------------------
510 procedure Analyze_Call_And_Resolve is
512 if Nkind (N) = N_Procedure_Call_Statement then
514 Resolve (N, Standard_Void_Type);
518 end Analyze_Call_And_Resolve;
520 -- Start of processing for Analyze_Procedure_Call
523 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
524 -- a procedure call or an entry call. The prefix may denote an access
525 -- to subprogram type, in which case an implicit dereference applies.
526 -- If the prefix is an indexed component (without implicit defererence)
527 -- then the construct denotes a call to a member of an entire family.
528 -- If the prefix is a simple name, it may still denote a call to a
529 -- parameterless member of an entry family. Resolution of these various
530 -- interpretations is delicate.
534 -- If this is a call of the form Obj.Op, the call may have been
535 -- analyzed and possibly rewritten into a block, in which case
542 -- If error analyzing prefix, then set Any_Type as result and return
544 if Etype (P) = Any_Type then
545 Set_Etype (N, Any_Type);
549 -- Otherwise analyze the parameters
551 if Present (Actuals) then
552 Actual := First (Actuals);
554 while Present (Actual) loop
556 Check_Parameterless_Call (Actual);
561 -- Special processing for Elab_Spec and Elab_Body calls
563 if Nkind (P) = N_Attribute_Reference
564 and then (Attribute_Name (P) = Name_Elab_Spec
565 or else Attribute_Name (P) = Name_Elab_Body)
567 if Present (Actuals) then
569 ("no parameters allowed for this call", First (Actuals));
573 Set_Etype (N, Standard_Void_Type);
576 elsif Is_Entity_Name (P)
577 and then Is_Record_Type (Etype (Entity (P)))
578 and then Remote_AST_I_Dereference (P)
582 elsif Is_Entity_Name (P)
583 and then Ekind (Entity (P)) /= E_Entry_Family
585 if Is_Access_Type (Etype (P))
586 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
587 and then No (Actuals)
588 and then Comes_From_Source (N)
590 Error_Msg_N ("missing explicit dereference in call", N);
593 Analyze_Call_And_Resolve;
595 -- If the prefix is the simple name of an entry family, this is
596 -- a parameterless call from within the task body itself.
598 elsif Is_Entity_Name (P)
599 and then Nkind (P) = N_Identifier
600 and then Ekind (Entity (P)) = E_Entry_Family
601 and then Present (Actuals)
602 and then No (Next (First (Actuals)))
604 -- Can be call to parameterless entry family. What appears to be the
605 -- sole argument is in fact the entry index. Rewrite prefix of node
606 -- accordingly. Source representation is unchanged by this
610 Make_Indexed_Component (Loc,
612 Make_Selected_Component (Loc,
613 Prefix => New_Occurrence_Of (Scope (Entity (P)), Loc),
614 Selector_Name => New_Occurrence_Of (Entity (P), Loc)),
615 Expressions => Actuals);
617 Set_Etype (New_N, Standard_Void_Type);
618 Set_Parameter_Associations (N, No_List);
619 Analyze_Call_And_Resolve;
621 elsif Nkind (P) = N_Explicit_Dereference then
622 if Ekind (Etype (P)) = E_Subprogram_Type then
623 Analyze_Call_And_Resolve;
625 Error_Msg_N ("expect access to procedure in call", P);
628 -- The name can be a selected component or an indexed component that
629 -- yields an access to subprogram. Such a prefix is legal if the call
630 -- has parameter associations.
632 elsif Is_Access_Type (Etype (P))
633 and then Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type
635 if Present (Actuals) then
636 Analyze_Call_And_Resolve;
638 Error_Msg_N ("missing explicit dereference in call ", N);
641 -- If not an access to subprogram, then the prefix must resolve to the
642 -- name of an entry, entry family, or protected operation.
644 -- For the case of a simple entry call, P is a selected component where
645 -- the prefix is the task and the selector name is the entry. A call to
646 -- a protected procedure will have the same syntax. If the protected
647 -- object contains overloaded operations, the entity may appear as a
648 -- function, the context will select the operation whose type is Void.
650 elsif Nkind (P) = N_Selected_Component
651 and then (Ekind (Entity (Selector_Name (P))) = E_Entry
653 Ekind (Entity (Selector_Name (P))) = E_Procedure
655 Ekind (Entity (Selector_Name (P))) = E_Function)
657 Analyze_Call_And_Resolve;
659 elsif Nkind (P) = N_Selected_Component
660 and then Ekind (Entity (Selector_Name (P))) = E_Entry_Family
661 and then Present (Actuals)
662 and then No (Next (First (Actuals)))
664 -- Can be call to parameterless entry family. What appears to be the
665 -- sole argument is in fact the entry index. Rewrite prefix of node
666 -- accordingly. Source representation is unchanged by this
670 Make_Indexed_Component (Loc,
671 Prefix => New_Copy (P),
672 Expressions => Actuals);
674 Set_Etype (New_N, Standard_Void_Type);
675 Set_Parameter_Associations (N, No_List);
676 Analyze_Call_And_Resolve;
678 -- For the case of a reference to an element of an entry family, P is
679 -- an indexed component whose prefix is a selected component (task and
680 -- entry family), and whose index is the entry family index.
682 elsif Nkind (P) = N_Indexed_Component
683 and then Nkind (Prefix (P)) = N_Selected_Component
684 and then Ekind (Entity (Selector_Name (Prefix (P)))) = E_Entry_Family
686 Analyze_Call_And_Resolve;
688 -- If the prefix is the name of an entry family, it is a call from
689 -- within the task body itself.
691 elsif Nkind (P) = N_Indexed_Component
692 and then Nkind (Prefix (P)) = N_Identifier
693 and then Ekind (Entity (Prefix (P))) = E_Entry_Family
696 Make_Selected_Component (Loc,
697 Prefix => New_Occurrence_Of (Scope (Entity (Prefix (P))), Loc),
698 Selector_Name => New_Occurrence_Of (Entity (Prefix (P)), Loc));
699 Rewrite (Prefix (P), New_N);
701 Analyze_Call_And_Resolve;
703 -- Anything else is an error
706 Error_Msg_N ("invalid procedure or entry call", N);
708 end Analyze_Procedure_Call;
710 ------------------------------
711 -- Analyze_Return_Statement --
712 ------------------------------
714 procedure Analyze_Return_Statement (N : Node_Id) is
715 Loc : constant Source_Ptr := Sloc (N);
717 Scope_Id : Entity_Id;
722 -- Find subprogram or accept statement enclosing the return statement
725 for J in reverse 0 .. Scope_Stack.Last loop
726 Scope_Id := Scope_Stack.Table (J).Entity;
727 exit when Ekind (Scope_Id) /= E_Block and then
728 Ekind (Scope_Id) /= E_Loop;
731 pragma Assert (Present (Scope_Id));
733 Kind := Ekind (Scope_Id);
734 Expr := Expression (N);
736 if Kind /= E_Function
737 and then Kind /= E_Generic_Function
738 and then Kind /= E_Procedure
739 and then Kind /= E_Generic_Procedure
740 and then Kind /= E_Entry
741 and then Kind /= E_Entry_Family
743 Error_Msg_N ("illegal context for return statement", N);
745 elsif Present (Expr) then
746 if Kind = E_Function or else Kind = E_Generic_Function then
747 Set_Return_Present (Scope_Id);
748 R_Type := Etype (Scope_Id);
749 Set_Return_Type (N, R_Type);
750 Analyze_And_Resolve (Expr, R_Type);
752 -- Ada 2005 (AI-318-02): When the result type is an anonymous
753 -- access type, apply an implicit conversion of the expression
754 -- to that type to force appropriate static and run-time
755 -- accessibility checks.
757 if Ada_Version >= Ada_05
758 and then Ekind (R_Type) = E_Anonymous_Access_Type
760 Rewrite (Expr, Convert_To (R_Type, Relocate_Node (Expr)));
761 Analyze_And_Resolve (Expr, R_Type);
764 if (Is_Class_Wide_Type (Etype (Expr))
765 or else Is_Dynamically_Tagged (Expr))
766 and then not Is_Class_Wide_Type (R_Type)
769 ("dynamically tagged expression not allowed!", Expr);
772 Apply_Constraint_Check (Expr, R_Type);
774 -- Ada 2005 (AI-318-02): Return-by-reference types have been
775 -- removed and replaced by anonymous access results. This is
776 -- an incompatibility with Ada 95. Not clear whether this
777 -- should be enforced yet or perhaps controllable with a
778 -- special switch. ???
780 -- if Ada_Version >= Ada_05
781 -- and then Is_Limited_Type (R_Type)
782 -- and then Nkind (Expr) /= N_Aggregate
783 -- and then Nkind (Expr) /= N_Extension_Aggregate
784 -- and then Nkind (Expr) /= N_Function_Call
787 -- ("(Ada 2005) illegal operand for limited return", N);
790 -- ??? A real run-time accessibility check is needed in cases
791 -- involving dereferences of access parameters. For now we just
792 -- check the static cases.
794 if Is_Return_By_Reference_Type (Etype (Scope_Id))
795 and then Object_Access_Level (Expr)
796 > Subprogram_Access_Level (Scope_Id)
799 Make_Raise_Program_Error (Loc,
800 Reason => PE_Accessibility_Check_Failed));
804 ("cannot return a local value by reference?", N);
806 ("\& will be raised at run time?",
807 N, Standard_Program_Error);
810 elsif Kind = E_Procedure or else Kind = E_Generic_Procedure then
811 Error_Msg_N ("procedure cannot return value (use function)", N);
814 Error_Msg_N ("accept statement cannot return value", N);
817 -- No expression present
820 if Kind = E_Function or Kind = E_Generic_Function then
821 Error_Msg_N ("missing expression in return from function", N);
824 if (Ekind (Scope_Id) = E_Procedure
825 or else Ekind (Scope_Id) = E_Generic_Procedure)
826 and then No_Return (Scope_Id)
829 ("RETURN statement not allowed (No_Return)", N);
833 Check_Unreachable_Code (N);
834 end Analyze_Return_Statement;
836 -------------------------
837 -- Analyze_Return_Type --
838 -------------------------
840 procedure Analyze_Return_Type (N : Node_Id) is
841 Designator : constant Entity_Id := Defining_Entity (N);
842 Typ : Entity_Id := Empty;
845 if Result_Definition (N) /= Error then
846 if Nkind (Result_Definition (N)) = N_Access_Definition then
847 Typ := Access_Definition (N, Result_Definition (N));
848 Set_Parent (Typ, Result_Definition (N));
849 Set_Is_Local_Anonymous_Access (Typ);
850 Set_Etype (Designator, Typ);
852 -- Ada 2005 (AI-231): Static checks
854 -- Null_Exclusion_Static_Checks needs to be extended to handle
855 -- null exclusion checks for function specifications. ???
857 -- if Null_Exclusion_Present (N) then
858 -- Null_Exclusion_Static_Checks (Param_Spec);
864 Find_Type (Result_Definition (N));
865 Typ := Entity (Result_Definition (N));
866 Set_Etype (Designator, Typ);
868 if Ekind (Typ) = E_Incomplete_Type
869 or else (Is_Class_Wide_Type (Typ)
871 Ekind (Root_Type (Typ)) = E_Incomplete_Type)
874 ("invalid use of incomplete type", Result_Definition (N));
879 Set_Etype (Designator, Any_Type);
881 end Analyze_Return_Type;
883 -----------------------------
884 -- Analyze_Subprogram_Body --
885 -----------------------------
887 -- This procedure is called for regular subprogram bodies, generic bodies,
888 -- and for subprogram stubs of both kinds. In the case of stubs, only the
889 -- specification matters, and is used to create a proper declaration for
890 -- the subprogram, or to perform conformance checks.
892 procedure Analyze_Subprogram_Body (N : Node_Id) is
893 Loc : constant Source_Ptr := Sloc (N);
894 Body_Spec : constant Node_Id := Specification (N);
895 Body_Id : Entity_Id := Defining_Entity (Body_Spec);
896 Prev_Id : constant Entity_Id := Current_Entity_In_Scope (Body_Id);
897 Body_Deleted : constant Boolean := False;
901 Spec_Decl : Node_Id := Empty;
902 Last_Formal : Entity_Id := Empty;
903 Conformant : Boolean;
904 Missing_Ret : Boolean;
907 procedure Check_Inline_Pragma (Spec : in out Node_Id);
908 -- Look ahead to recognize a pragma that may appear after the body.
909 -- If there is a previous spec, check that it appears in the same
910 -- declarative part. If the pragma is Inline_Always, perform inlining
911 -- unconditionally, otherwise only if Front_End_Inlining is requested.
912 -- If the body acts as a spec, and inlining is required, we create a
913 -- subprogram declaration for it, in order to attach the body to inline.
915 procedure Copy_Parameter_List (Plist : List_Id);
916 -- Comment required ???
918 procedure Verify_Overriding_Indicator;
919 -- If there was a previous spec, the entity has been entered in the
920 -- current scope previously. If the body itself carries an overriding
921 -- indicator, check that it is consistent with the known status of the
924 -------------------------
925 -- Check_Inline_Pragma --
926 -------------------------
928 procedure Check_Inline_Pragma (Spec : in out Node_Id) is
933 if not Expander_Active then
937 if Is_List_Member (N)
938 and then Present (Next (N))
939 and then Nkind (Next (N)) = N_Pragma
943 if Nkind (Prag) = N_Pragma
945 (Get_Pragma_Id (Chars (Prag)) = Pragma_Inline_Always
948 and then Get_Pragma_Id (Chars (Prag)) = Pragma_Inline))
951 (Expression (First (Pragma_Argument_Associations (Prag))))
962 if Present (Prag) then
963 if Present (Spec_Id) then
964 if List_Containing (N) =
965 List_Containing (Unit_Declaration_Node (Spec_Id))
971 -- Create a subprogram declaration, to make treatment uniform
974 Subp : constant Entity_Id :=
975 Make_Defining_Identifier (Loc, Chars (Body_Id));
976 Decl : constant Node_Id :=
977 Make_Subprogram_Declaration (Loc,
978 Specification => New_Copy_Tree (Specification (N)));
980 Set_Defining_Unit_Name (Specification (Decl), Subp);
982 if Present (First_Formal (Body_Id)) then
984 Copy_Parameter_List (Plist);
985 Set_Parameter_Specifications
986 (Specification (Decl), Plist);
989 Insert_Before (N, Decl);
992 Set_Has_Pragma_Inline (Subp);
994 if Get_Pragma_Id (Chars (Prag)) = Pragma_Inline_Always then
995 Set_Is_Inlined (Subp);
996 Set_Next_Rep_Item (Prag, First_Rep_Item (Subp));
997 Set_First_Rep_Item (Subp, Prag);
1004 end Check_Inline_Pragma;
1006 -------------------------
1007 -- Copy_Parameter_List --
1008 -------------------------
1010 procedure Copy_Parameter_List (Plist : List_Id) is
1014 Formal := First_Formal (Body_Id);
1016 while Present (Formal) loop
1018 (Make_Parameter_Specification (Loc,
1019 Defining_Identifier =>
1020 Make_Defining_Identifier (Sloc (Formal),
1021 Chars => Chars (Formal)),
1022 In_Present => In_Present (Parent (Formal)),
1023 Out_Present => Out_Present (Parent (Formal)),
1025 New_Reference_To (Etype (Formal), Loc),
1027 New_Copy_Tree (Expression (Parent (Formal)))),
1030 Next_Formal (Formal);
1032 end Copy_Parameter_List;
1034 ---------------------------------
1035 -- Verify_Overriding_Indicator --
1036 ---------------------------------
1038 procedure Verify_Overriding_Indicator is
1040 if Must_Override (Body_Spec)
1041 and then not Is_Overriding_Operation (Spec_Id)
1044 ("subprogram& is not overriding", Body_Spec, Spec_Id);
1046 elsif Must_Not_Override (Body_Spec)
1047 and then Is_Overriding_Operation (Spec_Id)
1050 ("subprogram& overrides inherited operation",
1051 Body_Spec, Spec_Id);
1053 end Verify_Overriding_Indicator;
1055 -- Start of processing for Analyze_Subprogram_Body
1058 if Debug_Flag_C then
1059 Write_Str ("==== Compiling subprogram body ");
1060 Write_Name (Chars (Body_Id));
1061 Write_Str (" from ");
1062 Write_Location (Loc);
1066 Trace_Scope (N, Body_Id, " Analyze subprogram");
1068 -- Generic subprograms are handled separately. They always have a
1069 -- generic specification. Determine whether current scope has a
1070 -- previous declaration.
1072 -- If the subprogram body is defined within an instance of the same
1073 -- name, the instance appears as a package renaming, and will be hidden
1074 -- within the subprogram.
1076 if Present (Prev_Id)
1077 and then not Is_Overloadable (Prev_Id)
1078 and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
1079 or else Comes_From_Source (Prev_Id))
1081 if Is_Generic_Subprogram (Prev_Id) then
1083 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
1084 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
1086 Analyze_Generic_Subprogram_Body (N, Spec_Id);
1090 -- Previous entity conflicts with subprogram name. Attempting to
1091 -- enter name will post error.
1093 Enter_Name (Body_Id);
1097 -- Non-generic case, find the subprogram declaration, if one was seen,
1098 -- or enter new overloaded entity in the current scope. If the
1099 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
1100 -- part of the context of one of its subunits. No need to redo the
1103 elsif Prev_Id = Body_Id
1104 and then Has_Completion (Body_Id)
1109 Body_Id := Analyze_Subprogram_Specification (Body_Spec);
1111 if Nkind (N) = N_Subprogram_Body_Stub
1112 or else No (Corresponding_Spec (N))
1114 Spec_Id := Find_Corresponding_Spec (N);
1116 -- If this is a duplicate body, no point in analyzing it
1118 if Error_Posted (N) then
1122 -- A subprogram body should cause freezing of its own declaration,
1123 -- but if there was no previous explicit declaration, then the
1124 -- subprogram will get frozen too late (there may be code within
1125 -- the body that depends on the subprogram having been frozen,
1126 -- such as uses of extra formals), so we force it to be frozen
1127 -- here. Same holds if the body and the spec are compilation
1130 if No (Spec_Id) then
1131 Freeze_Before (N, Body_Id);
1133 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1134 Freeze_Before (N, Spec_Id);
1137 Spec_Id := Corresponding_Spec (N);
1141 -- Do not inline any subprogram that contains nested subprograms, since
1142 -- the backend inlining circuit seems to generate uninitialized
1143 -- references in this case. We know this happens in the case of front
1144 -- end ZCX support, but it also appears it can happen in other cases as
1145 -- well. The backend often rejects attempts to inline in the case of
1146 -- nested procedures anyway, so little if anything is lost by this.
1147 -- Note that this is test is for the benefit of the back-end. There is
1148 -- a separate test for front-end inlining that also rejects nested
1151 -- Do not do this test if errors have been detected, because in some
1152 -- error cases, this code blows up, and we don't need it anyway if
1153 -- there have been errors, since we won't get to the linker anyway.
1155 if Comes_From_Source (Body_Id)
1156 and then Serious_Errors_Detected = 0
1160 P_Ent := Scope (P_Ent);
1161 exit when No (P_Ent) or else P_Ent = Standard_Standard;
1163 if Is_Subprogram (P_Ent) then
1164 Set_Is_Inlined (P_Ent, False);
1166 if Comes_From_Source (P_Ent)
1167 and then Has_Pragma_Inline (P_Ent)
1170 ("cannot inline& (nested subprogram)?",
1177 Check_Inline_Pragma (Spec_Id);
1179 -- Case of fully private operation in the body of the protected type.
1180 -- We must create a declaration for the subprogram, in order to attach
1181 -- the protected subprogram that will be used in internal calls.
1184 and then Comes_From_Source (N)
1185 and then Is_Protected_Type (Current_Scope)
1194 Formal := First_Formal (Body_Id);
1196 -- The protected operation always has at least one formal, namely
1197 -- the object itself, but it is only placed in the parameter list
1198 -- if expansion is enabled.
1201 or else Expander_Active
1209 Copy_Parameter_List (Plist);
1211 if Nkind (Body_Spec) = N_Procedure_Specification then
1213 Make_Procedure_Specification (Loc,
1214 Defining_Unit_Name =>
1215 Make_Defining_Identifier (Sloc (Body_Id),
1216 Chars => Chars (Body_Id)),
1217 Parameter_Specifications => Plist);
1220 Make_Function_Specification (Loc,
1221 Defining_Unit_Name =>
1222 Make_Defining_Identifier (Sloc (Body_Id),
1223 Chars => Chars (Body_Id)),
1224 Parameter_Specifications => Plist,
1225 Result_Definition =>
1226 New_Occurrence_Of (Etype (Body_Id), Loc));
1230 Make_Subprogram_Declaration (Loc,
1231 Specification => New_Spec);
1232 Insert_Before (N, Decl);
1233 Spec_Id := Defining_Unit_Name (New_Spec);
1235 -- Indicate that the entity comes from source, to ensure that
1236 -- cross-reference information is properly generated. The body
1237 -- itself is rewritten during expansion, and the body entity will
1238 -- not appear in calls to the operation.
1240 Set_Comes_From_Source (Spec_Id, True);
1242 Set_Has_Completion (Spec_Id);
1243 Set_Convention (Spec_Id, Convention_Protected);
1246 elsif Present (Spec_Id) then
1247 Spec_Decl := Unit_Declaration_Node (Spec_Id);
1248 Verify_Overriding_Indicator;
1251 -- Place subprogram on scope stack, and make formals visible. If there
1252 -- is a spec, the visible entity remains that of the spec.
1254 if Present (Spec_Id) then
1255 Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
1257 if Is_Child_Unit (Spec_Id) then
1258 Generate_Reference (Spec_Id, Scope (Spec_Id), 'k', False);
1262 Style.Check_Identifier (Body_Id, Spec_Id);
1265 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
1266 Set_Is_Child_Unit (Body_Id, Is_Child_Unit (Spec_Id));
1268 if Is_Abstract (Spec_Id) then
1269 Error_Msg_N ("an abstract subprogram cannot have a body", N);
1272 Set_Convention (Body_Id, Convention (Spec_Id));
1273 Set_Has_Completion (Spec_Id);
1275 if Is_Protected_Type (Scope (Spec_Id)) then
1276 Set_Privals_Chain (Spec_Id, New_Elmt_List);
1279 -- If this is a body generated for a renaming, do not check for
1280 -- full conformance. The check is redundant, because the spec of
1281 -- the body is a copy of the spec in the renaming declaration,
1282 -- and the test can lead to spurious errors on nested defaults.
1284 if Present (Spec_Decl)
1285 and then not Comes_From_Source (N)
1287 (Nkind (Original_Node (Spec_Decl)) =
1288 N_Subprogram_Renaming_Declaration
1289 or else (Present (Corresponding_Body (Spec_Decl))
1291 Nkind (Unit_Declaration_Node
1292 (Corresponding_Body (Spec_Decl))) =
1293 N_Subprogram_Renaming_Declaration))
1299 Fully_Conformant, True, Conformant, Body_Id);
1302 -- If the body is not fully conformant, we have to decide if we
1303 -- should analyze it or not. If it has a really messed up profile
1304 -- then we probably should not analyze it, since we will get too
1305 -- many bogus messages.
1307 -- Our decision is to go ahead in the non-fully conformant case
1308 -- only if it is at least mode conformant with the spec. Note
1309 -- that the call to Check_Fully_Conformant has issued the proper
1310 -- error messages to complain about the lack of conformance.
1313 and then not Mode_Conformant (Body_Id, Spec_Id)
1319 if Spec_Id /= Body_Id then
1320 Reference_Body_Formals (Spec_Id, Body_Id);
1323 if Nkind (N) /= N_Subprogram_Body_Stub then
1324 Set_Corresponding_Spec (N, Spec_Id);
1326 -- Ada 2005 (AI-345): Restore the correct Etype: here we undo the
1327 -- work done by Analyze_Subprogram_Specification to allow the
1328 -- overriding of task, protected and interface primitives.
1330 if Comes_From_Source (Spec_Id)
1331 and then Present (First_Entity (Spec_Id))
1332 and then Ekind (Etype (First_Entity (Spec_Id))) = E_Record_Type
1333 and then Is_Tagged_Type (Etype (First_Entity (Spec_Id)))
1334 and then Present (Abstract_Interfaces
1335 (Etype (First_Entity (Spec_Id))))
1336 and then Present (Corresponding_Concurrent_Type
1337 (Etype (First_Entity (Spec_Id))))
1339 Set_Etype (First_Entity (Spec_Id),
1340 Corresponding_Concurrent_Type
1341 (Etype (First_Entity (Spec_Id))));
1344 -- Ada 2005: A formal that is an access parameter may have a
1345 -- designated type imported through a limited_with clause, while
1346 -- the body has a regular with clause. Update the types of the
1347 -- formals accordingly, so that the non-limited view of each type
1348 -- is available in the body. We have already verified that the
1349 -- declarations are type-conformant.
1351 if Ada_Version >= Ada_05 then
1357 F_Spec := First_Formal (Spec_Id);
1358 F_Body := First_Formal (Body_Id);
1360 while Present (F_Spec) loop
1361 if Ekind (Etype (F_Spec)) = E_Anonymous_Access_Type
1363 From_With_Type (Designated_Type (Etype (F_Spec)))
1365 Set_Etype (F_Spec, Etype (F_Body));
1368 Next_Formal (F_Spec);
1369 Next_Formal (F_Body);
1374 -- Now make the formals visible, and place subprogram
1377 Install_Formals (Spec_Id);
1378 Last_Formal := Last_Entity (Spec_Id);
1379 New_Scope (Spec_Id);
1381 -- Make sure that the subprogram is immediately visible. For
1382 -- child units that have no separate spec this is indispensable.
1383 -- Otherwise it is safe albeit redundant.
1385 Set_Is_Immediately_Visible (Spec_Id);
1388 Set_Corresponding_Body (Unit_Declaration_Node (Spec_Id), Body_Id);
1389 Set_Ekind (Body_Id, E_Subprogram_Body);
1390 Set_Scope (Body_Id, Scope (Spec_Id));
1392 -- Case of subprogram body with no previous spec
1396 and then Comes_From_Source (Body_Id)
1397 and then not Suppress_Style_Checks (Body_Id)
1398 and then not In_Instance
1400 Style.Body_With_No_Spec (N);
1403 New_Overloaded_Entity (Body_Id);
1405 if Nkind (N) /= N_Subprogram_Body_Stub then
1406 Set_Acts_As_Spec (N);
1407 Generate_Definition (Body_Id);
1409 (Body_Id, Body_Id, 'b', Set_Ref => False, Force => True);
1410 Generate_Reference_To_Formals (Body_Id);
1411 Install_Formals (Body_Id);
1412 New_Scope (Body_Id);
1416 -- If this is the proper body of a stub, we must verify that the stub
1417 -- conforms to the body, and to the previous spec if one was present.
1418 -- we know already that the body conforms to that spec. This test is
1419 -- only required for subprograms that come from source.
1421 if Nkind (Parent (N)) = N_Subunit
1422 and then Comes_From_Source (N)
1423 and then not Error_Posted (Body_Id)
1424 and then Nkind (Corresponding_Stub (Parent (N))) =
1425 N_Subprogram_Body_Stub
1428 Old_Id : constant Entity_Id :=
1430 (Specification (Corresponding_Stub (Parent (N))));
1432 Conformant : Boolean := False;
1435 if No (Spec_Id) then
1436 Check_Fully_Conformant (Body_Id, Old_Id);
1440 (Body_Id, Old_Id, Fully_Conformant, False, Conformant);
1442 if not Conformant then
1444 -- The stub was taken to be a new declaration. Indicate
1445 -- that it lacks a body.
1447 Set_Has_Completion (Old_Id, False);
1453 Set_Has_Completion (Body_Id);
1454 Check_Eliminated (Body_Id);
1456 if Nkind (N) = N_Subprogram_Body_Stub then
1459 elsif Present (Spec_Id)
1460 and then Expander_Active
1462 (Is_Always_Inlined (Spec_Id)
1463 or else (Has_Pragma_Inline (Spec_Id) and Front_End_Inlining))
1465 Build_Body_To_Inline (N, Spec_Id);
1468 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
1469 -- if its specification we have to install the private withed units.
1471 if Is_Compilation_Unit (Body_Id)
1472 and then Scope (Body_Id) = Standard_Standard
1474 Install_Private_With_Clauses (Body_Id);
1477 -- Now we can go on to analyze the body
1479 HSS := Handled_Statement_Sequence (N);
1480 Set_Actual_Subtypes (N, Current_Scope);
1481 Analyze_Declarations (Declarations (N));
1484 Process_End_Label (HSS, 't', Current_Scope);
1486 Check_Subprogram_Order (N);
1487 Set_Analyzed (Body_Id);
1489 -- If we have a separate spec, then the analysis of the declarations
1490 -- caused the entities in the body to be chained to the spec id, but
1491 -- we want them chained to the body id. Only the formal parameters
1492 -- end up chained to the spec id in this case.
1494 if Present (Spec_Id) then
1496 -- We must conform to the categorization of our spec
1498 Validate_Categorization_Dependency (N, Spec_Id);
1500 -- And if this is a child unit, the parent units must conform
1502 if Is_Child_Unit (Spec_Id) then
1503 Validate_Categorization_Dependency
1504 (Unit_Declaration_Node (Spec_Id), Spec_Id);
1507 if Present (Last_Formal) then
1509 (Last_Entity (Body_Id), Next_Entity (Last_Formal));
1510 Set_Next_Entity (Last_Formal, Empty);
1511 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
1512 Set_Last_Entity (Spec_Id, Last_Formal);
1515 Set_First_Entity (Body_Id, First_Entity (Spec_Id));
1516 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
1517 Set_First_Entity (Spec_Id, Empty);
1518 Set_Last_Entity (Spec_Id, Empty);
1522 -- If function, check return statements
1524 if Nkind (Body_Spec) = N_Function_Specification then
1529 if Present (Spec_Id) then
1535 if Return_Present (Id) then
1536 Check_Returns (HSS, 'F', Missing_Ret);
1539 Set_Has_Missing_Return (Id);
1542 elsif not Is_Machine_Code_Subprogram (Id)
1543 and then not Body_Deleted
1545 Error_Msg_N ("missing RETURN statement in function body", N);
1549 -- If procedure with No_Return, check returns
1551 elsif Nkind (Body_Spec) = N_Procedure_Specification
1552 and then Present (Spec_Id)
1553 and then No_Return (Spec_Id)
1555 Check_Returns (HSS, 'P', Missing_Ret, Spec_Id);
1558 -- Now we are going to check for variables that are never modified in
1559 -- the body of the procedure. We omit these checks if the first
1560 -- statement of the procedure raises an exception. In particular this
1561 -- deals with the common idiom of a stubbed function, which might
1562 -- appear as something like
1564 -- function F (A : Integer) return Some_Type;
1567 -- raise Program_Error;
1571 -- Here the purpose of X is simply to satisfy the (annoying)
1572 -- requirement in Ada that there be at least one return, and we
1573 -- certainly do not want to go posting warnings on X that it is not
1577 Stm : Node_Id := First (Statements (HSS));
1580 -- Skip an initial label (for one thing this occurs when we are in
1581 -- front end ZCX mode, but in any case it is irrelevant).
1583 if Nkind (Stm) = N_Label then
1587 -- Do the test on the original statement before expansion
1590 Ostm : constant Node_Id := Original_Node (Stm);
1593 -- If explicit raise statement, return with no checks
1595 if Nkind (Ostm) = N_Raise_Statement then
1598 -- Check for explicit call cases which likely raise an exception
1600 elsif Nkind (Ostm) = N_Procedure_Call_Statement then
1601 if Is_Entity_Name (Name (Ostm)) then
1603 Ent : constant Entity_Id := Entity (Name (Ostm));
1606 -- If the procedure is marked No_Return, then likely it
1607 -- raises an exception, but in any case it is not coming
1608 -- back here, so no need to check beyond the call.
1610 if Ekind (Ent) = E_Procedure
1611 and then No_Return (Ent)
1615 -- If the procedure name is Raise_Exception, then also
1616 -- assume that it raises an exception. The main target
1617 -- here is Ada.Exceptions.Raise_Exception, but this name
1618 -- is pretty evocative in any context! Note that the
1619 -- procedure in Ada.Exceptions is not marked No_Return
1620 -- because of the annoying case of the null exception Id.
1622 elsif Chars (Ent) = Name_Raise_Exception then
1631 -- Check for variables that are never modified
1637 -- If there is a separate spec, then transfer Never_Set_In_Source
1638 -- flags from out parameters to the corresponding entities in the
1639 -- body. The reason we do that is we want to post error flags on
1640 -- the body entities, not the spec entities.
1642 if Present (Spec_Id) then
1643 E1 := First_Entity (Spec_Id);
1645 while Present (E1) loop
1646 if Ekind (E1) = E_Out_Parameter then
1647 E2 := First_Entity (Body_Id);
1648 while Present (E2) loop
1649 exit when Chars (E1) = Chars (E2);
1653 if Present (E2) then
1654 Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
1662 -- Check references in body unless it was deleted. Note that the
1663 -- check of Body_Deleted here is not just for efficiency, it is
1664 -- necessary to avoid junk warnings on formal parameters.
1666 if not Body_Deleted then
1667 Check_References (Body_Id);
1670 end Analyze_Subprogram_Body;
1672 ------------------------------------
1673 -- Analyze_Subprogram_Declaration --
1674 ------------------------------------
1676 procedure Analyze_Subprogram_Declaration (N : Node_Id) is
1677 Designator : constant Entity_Id :=
1678 Analyze_Subprogram_Specification (Specification (N));
1679 Scop : constant Entity_Id := Current_Scope;
1681 -- Start of processing for Analyze_Subprogram_Declaration
1684 Generate_Definition (Designator);
1686 -- Check for RCI unit subprogram declarations against in-lined
1687 -- subprograms and subprograms having access parameter or limited
1688 -- parameter without Read and Write (RM E.2.3(12-13)).
1690 Validate_RCI_Subprogram_Declaration (N);
1694 Defining_Entity (N),
1695 " Analyze subprogram spec. ");
1697 if Debug_Flag_C then
1698 Write_Str ("==== Compiling subprogram spec ");
1699 Write_Name (Chars (Designator));
1700 Write_Str (" from ");
1701 Write_Location (Sloc (N));
1705 New_Overloaded_Entity (Designator);
1706 Check_Delayed_Subprogram (Designator);
1708 -- What is the following code for, it used to be
1710 -- ??? Set_Suppress_Elaboration_Checks
1711 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
1713 -- The following seems equivalent, but a bit dubious
1715 if Elaboration_Checks_Suppressed (Designator) then
1716 Set_Kill_Elaboration_Checks (Designator);
1719 if Scop /= Standard_Standard
1720 and then not Is_Child_Unit (Designator)
1722 Set_Categorization_From_Scope (Designator, Scop);
1724 -- For a compilation unit, check for library-unit pragmas
1726 New_Scope (Designator);
1727 Set_Categorization_From_Pragmas (N);
1728 Validate_Categorization_Dependency (N, Designator);
1732 -- For a compilation unit, set body required. This flag will only be
1733 -- reset if a valid Import or Interface pragma is processed later on.
1735 if Nkind (Parent (N)) = N_Compilation_Unit then
1736 Set_Body_Required (Parent (N), True);
1738 if Ada_Version >= Ada_05
1739 and then Nkind (Specification (N)) = N_Procedure_Specification
1740 and then Null_Present (Specification (N))
1743 ("null procedure cannot be declared at library level", N);
1747 Generate_Reference_To_Formals (Designator);
1748 Check_Eliminated (Designator);
1750 -- Ada 2005: if procedure is declared with "is null" qualifier,
1751 -- it requires no body.
1753 if Nkind (Specification (N)) = N_Procedure_Specification
1754 and then Null_Present (Specification (N))
1756 Set_Has_Completion (Designator);
1757 Set_Is_Inlined (Designator);
1759 end Analyze_Subprogram_Declaration;
1761 --------------------------------------
1762 -- Analyze_Subprogram_Specification --
1763 --------------------------------------
1765 -- Reminder: N here really is a subprogram specification (not a subprogram
1766 -- declaration). This procedure is called to analyze the specification in
1767 -- both subprogram bodies and subprogram declarations (specs).
1769 function Analyze_Subprogram_Specification (N : Node_Id) return Entity_Id is
1770 Designator : constant Entity_Id := Defining_Entity (N);
1771 Formals : constant List_Id := Parameter_Specifications (N);
1773 function Has_Interface_Formals (T : List_Id) return Boolean;
1774 -- Ada 2005 (AI-251): Returns true if some non class-wide interface
1777 ---------------------------
1778 -- Has_Interface_Formals --
1779 ---------------------------
1781 function Has_Interface_Formals (T : List_Id) return Boolean is
1782 Param_Spec : Node_Id;
1786 Param_Spec := First (T);
1788 while Present (Param_Spec) loop
1789 Formal := Defining_Identifier (Param_Spec);
1791 if Is_Class_Wide_Type (Etype (Formal)) then
1794 elsif Is_Interface (Etype (Formal)) then
1802 end Has_Interface_Formals;
1804 -- Start of processing for Analyze_Subprogram_Specification
1807 Generate_Definition (Designator);
1809 if Nkind (N) = N_Function_Specification then
1810 Set_Ekind (Designator, E_Function);
1811 Set_Mechanism (Designator, Default_Mechanism);
1814 Set_Ekind (Designator, E_Procedure);
1815 Set_Etype (Designator, Standard_Void_Type);
1818 -- Introduce new scope for analysis of the formals and of the
1821 Set_Scope (Designator, Current_Scope);
1823 if Present (Formals) then
1824 New_Scope (Designator);
1825 Process_Formals (Formals, N);
1827 -- Ada 2005 (AI-345): Allow overriding primitives of protected
1828 -- interfaces by means of normal subprograms. For this purpose
1829 -- temporarily use the corresponding record type as the etype
1830 -- of the first formal.
1832 if Ada_Version >= Ada_05
1833 and then Comes_From_Source (Designator)
1834 and then Present (First_Entity (Designator))
1835 and then (Ekind (Etype (First_Entity (Designator)))
1838 Ekind (Etype (First_Entity (Designator)))
1840 and then Present (Corresponding_Record_Type
1841 (Etype (First_Entity (Designator))))
1842 and then Present (Abstract_Interfaces
1843 (Corresponding_Record_Type
1844 (Etype (First_Entity (Designator)))))
1846 Set_Etype (First_Entity (Designator),
1847 Corresponding_Record_Type (Etype (First_Entity (Designator))));
1852 elsif Nkind (N) = N_Function_Specification then
1853 Analyze_Return_Type (N);
1856 if Nkind (N) = N_Function_Specification then
1857 if Nkind (Designator) = N_Defining_Operator_Symbol then
1858 Valid_Operator_Definition (Designator);
1861 May_Need_Actuals (Designator);
1863 if Is_Abstract (Etype (Designator))
1864 and then Nkind (Parent (N))
1865 /= N_Abstract_Subprogram_Declaration
1866 and then (Nkind (Parent (N)))
1867 /= N_Formal_Abstract_Subprogram_Declaration
1868 and then (Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1869 or else not Is_Entity_Name (Name (Parent (N)))
1870 or else not Is_Abstract (Entity (Name (Parent (N)))))
1873 ("function that returns abstract type must be abstract", N);
1877 if Ada_Version >= Ada_05
1878 and then Comes_From_Source (N)
1879 and then Nkind (Parent (N)) /= N_Abstract_Subprogram_Declaration
1880 and then (Nkind (N) /= N_Procedure_Specification
1882 not Null_Present (N))
1883 and then Has_Interface_Formals (Formals)
1885 Error_Msg_Name_1 := Chars (Defining_Unit_Name
1886 (Specification (Parent (N))));
1888 ("(Ada 2005) interface subprogram % must be abstract or null", N);
1892 end Analyze_Subprogram_Specification;
1894 --------------------------
1895 -- Build_Body_To_Inline --
1896 --------------------------
1898 procedure Build_Body_To_Inline (N : Node_Id; Subp : Entity_Id) is
1899 Decl : constant Node_Id := Unit_Declaration_Node (Subp);
1900 Original_Body : Node_Id;
1901 Body_To_Analyze : Node_Id;
1902 Max_Size : constant := 10;
1903 Stat_Count : Integer := 0;
1905 function Has_Excluded_Declaration (Decls : List_Id) return Boolean;
1906 -- Check for declarations that make inlining not worthwhile
1908 function Has_Excluded_Statement (Stats : List_Id) return Boolean;
1909 -- Check for statements that make inlining not worthwhile: any tasking
1910 -- statement, nested at any level. Keep track of total number of
1911 -- elementary statements, as a measure of acceptable size.
1913 function Has_Pending_Instantiation return Boolean;
1914 -- If some enclosing body contains instantiations that appear before
1915 -- the corresponding generic body, the enclosing body has a freeze node
1916 -- so that it can be elaborated after the generic itself. This might
1917 -- conflict with subsequent inlinings, so that it is unsafe to try to
1918 -- inline in such a case.
1920 function Has_Single_Return return Boolean;
1921 -- In general we cannot inline functions that return unconstrained
1922 -- type. However, we can handle such functions if all return statements
1923 -- return a local variable that is the only declaration in the body
1924 -- of the function. In that case the call can be replaced by that
1925 -- local variable as is done for other inlined calls.
1927 procedure Remove_Pragmas;
1928 -- A pragma Unreferenced that mentions a formal parameter has no
1929 -- meaning when the body is inlined and the formals are rewritten.
1930 -- Remove it from body to inline. The analysis of the non-inlined body
1931 -- will handle the pragma properly.
1933 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean;
1934 -- If the body of the subprogram includes a call that returns an
1935 -- unconstrained type, the secondary stack is involved, and it
1936 -- is not worth inlining.
1938 ------------------------------
1939 -- Has_Excluded_Declaration --
1940 ------------------------------
1942 function Has_Excluded_Declaration (Decls : List_Id) return Boolean is
1945 function Is_Unchecked_Conversion (D : Node_Id) return Boolean;
1946 -- Nested subprograms make a given body ineligible for inlining, but
1947 -- we make an exception for instantiations of unchecked conversion.
1948 -- The body has not been analyzed yet, so check the name, and verify
1949 -- that the visible entity with that name is the predefined unit.
1951 -----------------------------
1952 -- Is_Unchecked_Conversion --
1953 -----------------------------
1955 function Is_Unchecked_Conversion (D : Node_Id) return Boolean is
1956 Id : constant Node_Id := Name (D);
1960 if Nkind (Id) = N_Identifier
1961 and then Chars (Id) = Name_Unchecked_Conversion
1963 Conv := Current_Entity (Id);
1965 elsif (Nkind (Id) = N_Selected_Component
1966 or else Nkind (Id) = N_Expanded_Name)
1967 and then Chars (Selector_Name (Id)) = Name_Unchecked_Conversion
1969 Conv := Current_Entity (Selector_Name (Id));
1975 return Present (Conv)
1976 and then Is_Predefined_File_Name
1977 (Unit_File_Name (Get_Source_Unit (Conv)))
1978 and then Is_Intrinsic_Subprogram (Conv);
1979 end Is_Unchecked_Conversion;
1981 -- Start of processing for Has_Excluded_Declaration
1986 while Present (D) loop
1987 if (Nkind (D) = N_Function_Instantiation
1988 and then not Is_Unchecked_Conversion (D))
1989 or else Nkind (D) = N_Protected_Type_Declaration
1990 or else Nkind (D) = N_Package_Declaration
1991 or else Nkind (D) = N_Package_Instantiation
1992 or else Nkind (D) = N_Subprogram_Body
1993 or else Nkind (D) = N_Procedure_Instantiation
1994 or else Nkind (D) = N_Task_Type_Declaration
1997 ("cannot inline & (non-allowed declaration)?", D, Subp);
2005 end Has_Excluded_Declaration;
2007 ----------------------------
2008 -- Has_Excluded_Statement --
2009 ----------------------------
2011 function Has_Excluded_Statement (Stats : List_Id) return Boolean is
2018 while Present (S) loop
2019 Stat_Count := Stat_Count + 1;
2021 if Nkind (S) = N_Abort_Statement
2022 or else Nkind (S) = N_Asynchronous_Select
2023 or else Nkind (S) = N_Conditional_Entry_Call
2024 or else Nkind (S) = N_Delay_Relative_Statement
2025 or else Nkind (S) = N_Delay_Until_Statement
2026 or else Nkind (S) = N_Selective_Accept
2027 or else Nkind (S) = N_Timed_Entry_Call
2030 ("cannot inline & (non-allowed statement)?", S, Subp);
2033 elsif Nkind (S) = N_Block_Statement then
2034 if Present (Declarations (S))
2035 and then Has_Excluded_Declaration (Declarations (S))
2039 elsif Present (Handled_Statement_Sequence (S))
2042 (Exception_Handlers (Handled_Statement_Sequence (S)))
2044 Has_Excluded_Statement
2045 (Statements (Handled_Statement_Sequence (S))))
2050 elsif Nkind (S) = N_Case_Statement then
2051 E := First (Alternatives (S));
2052 while Present (E) loop
2053 if Has_Excluded_Statement (Statements (E)) then
2060 elsif Nkind (S) = N_If_Statement then
2061 if Has_Excluded_Statement (Then_Statements (S)) then
2065 if Present (Elsif_Parts (S)) then
2066 E := First (Elsif_Parts (S));
2067 while Present (E) loop
2068 if Has_Excluded_Statement (Then_Statements (E)) then
2075 if Present (Else_Statements (S))
2076 and then Has_Excluded_Statement (Else_Statements (S))
2081 elsif Nkind (S) = N_Loop_Statement
2082 and then Has_Excluded_Statement (Statements (S))
2091 end Has_Excluded_Statement;
2093 -------------------------------
2094 -- Has_Pending_Instantiation --
2095 -------------------------------
2097 function Has_Pending_Instantiation return Boolean is
2098 S : Entity_Id := Current_Scope;
2101 while Present (S) loop
2102 if Is_Compilation_Unit (S)
2103 or else Is_Child_Unit (S)
2106 elsif Ekind (S) = E_Package
2107 and then Has_Forward_Instantiation (S)
2116 end Has_Pending_Instantiation;
2118 ------------------------
2119 -- Has_Single_Return --
2120 ------------------------
2122 function Has_Single_Return return Boolean is
2123 Return_Statement : Node_Id := Empty;
2125 function Check_Return (N : Node_Id) return Traverse_Result;
2131 function Check_Return (N : Node_Id) return Traverse_Result is
2133 if Nkind (N) = N_Return_Statement then
2134 if Present (Expression (N))
2135 and then Is_Entity_Name (Expression (N))
2137 if No (Return_Statement) then
2138 Return_Statement := N;
2141 elsif Chars (Expression (N)) =
2142 Chars (Expression (Return_Statement))
2151 -- Expression has wrong form
2161 function Check_All_Returns is new Traverse_Func (Check_Return);
2163 -- Start of processing for Has_Single_Return
2166 return Check_All_Returns (N) = OK;
2167 end Has_Single_Return;
2169 --------------------
2170 -- Remove_Pragmas --
2171 --------------------
2173 procedure Remove_Pragmas is
2178 Decl := First (Declarations (Body_To_Analyze));
2179 while Present (Decl) loop
2182 if Nkind (Decl) = N_Pragma
2183 and then Chars (Decl) = Name_Unreferenced
2192 --------------------------
2193 -- Uses_Secondary_Stack --
2194 --------------------------
2196 function Uses_Secondary_Stack (Bod : Node_Id) return Boolean is
2197 function Check_Call (N : Node_Id) return Traverse_Result;
2198 -- Look for function calls that return an unconstrained type
2204 function Check_Call (N : Node_Id) return Traverse_Result is
2206 if Nkind (N) = N_Function_Call
2207 and then Is_Entity_Name (Name (N))
2208 and then Is_Composite_Type (Etype (Entity (Name (N))))
2209 and then not Is_Constrained (Etype (Entity (Name (N))))
2212 ("cannot inline & (call returns unconstrained type)?",
2220 function Check_Calls is new Traverse_Func (Check_Call);
2223 return Check_Calls (Bod) = Abandon;
2224 end Uses_Secondary_Stack;
2226 -- Start of processing for Build_Body_To_Inline
2229 if Nkind (Decl) = N_Subprogram_Declaration
2230 and then Present (Body_To_Inline (Decl))
2232 return; -- Done already.
2234 -- Functions that return unconstrained composite types will require
2235 -- secondary stack handling, and cannot currently be inlined.
2236 -- Ditto for functions that return controlled types, where controlled
2237 -- actions interfere in complex ways with inlining.
2239 elsif Ekind (Subp) = E_Function
2240 and then not Is_Scalar_Type (Etype (Subp))
2241 and then not Is_Access_Type (Etype (Subp))
2242 and then not Is_Constrained (Etype (Subp))
2243 and then not Has_Single_Return
2246 ("cannot inline & (unconstrained return type)?", N, Subp);
2249 elsif Ekind (Subp) = E_Function
2250 and then Controlled_Type (Etype (Subp))
2253 ("cannot inline & (controlled return type)?", N, Subp);
2257 if Present (Declarations (N))
2258 and then Has_Excluded_Declaration (Declarations (N))
2263 if Present (Handled_Statement_Sequence (N)) then
2264 if Present (Exception_Handlers (Handled_Statement_Sequence (N))) then
2266 ("cannot inline& (exception handler)?",
2267 First (Exception_Handlers (Handled_Statement_Sequence (N))),
2271 Has_Excluded_Statement
2272 (Statements (Handled_Statement_Sequence (N)))
2278 -- We do not inline a subprogram that is too large, unless it is
2279 -- marked Inline_Always. This pragma does not suppress the other
2280 -- checks on inlining (forbidden declarations, handlers, etc).
2282 if Stat_Count > Max_Size
2283 and then not Is_Always_Inlined (Subp)
2285 Cannot_Inline ("cannot inline& (body too large)?", N, Subp);
2289 if Has_Pending_Instantiation then
2291 ("cannot inline& (forward instance within enclosing body)?",
2296 -- Within an instance, the body to inline must be treated as a nested
2297 -- generic, so that the proper global references are preserved.
2300 Save_Env (Scope (Current_Scope), Scope (Current_Scope));
2301 Original_Body := Copy_Generic_Node (N, Empty, True);
2303 Original_Body := Copy_Separate_Tree (N);
2306 -- We need to capture references to the formals in order to substitute
2307 -- the actuals at the point of inlining, i.e. instantiation. To treat
2308 -- the formals as globals to the body to inline, we nest it within
2309 -- a dummy parameterless subprogram, declared within the real one.
2310 -- To avoid generating an internal name (which is never public, and
2311 -- which affects serial numbers of other generated names), we use
2312 -- an internal symbol that cannot conflict with user declarations.
2314 Set_Parameter_Specifications (Specification (Original_Body), No_List);
2315 Set_Defining_Unit_Name
2316 (Specification (Original_Body),
2317 Make_Defining_Identifier (Sloc (N), Name_uParent));
2318 Set_Corresponding_Spec (Original_Body, Empty);
2320 Body_To_Analyze := Copy_Generic_Node (Original_Body, Empty, False);
2322 -- Set return type of function, which is also global and does not need
2325 if Ekind (Subp) = E_Function then
2326 Set_Result_Definition (Specification (Body_To_Analyze),
2327 New_Occurrence_Of (Etype (Subp), Sloc (N)));
2330 if No (Declarations (N)) then
2331 Set_Declarations (N, New_List (Body_To_Analyze));
2333 Append (Body_To_Analyze, Declarations (N));
2336 Expander_Mode_Save_And_Set (False);
2339 Analyze (Body_To_Analyze);
2340 New_Scope (Defining_Entity (Body_To_Analyze));
2341 Save_Global_References (Original_Body);
2343 Remove (Body_To_Analyze);
2345 Expander_Mode_Restore;
2351 -- If secondary stk used there is no point in inlining. We have
2352 -- already issued the warning in this case, so nothing to do.
2354 if Uses_Secondary_Stack (Body_To_Analyze) then
2358 Set_Body_To_Inline (Decl, Original_Body);
2359 Set_Ekind (Defining_Entity (Original_Body), Ekind (Subp));
2360 Set_Is_Inlined (Subp);
2361 end Build_Body_To_Inline;
2367 procedure Cannot_Inline (Msg : String; N : Node_Id; Subp : Entity_Id) is
2369 -- Do not emit warning if this is a predefined unit which is not
2370 -- the main unit. With validity checks enabled, some predefined
2371 -- subprograms may contain nested subprograms and become ineligible
2374 if Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Subp)))
2375 and then not In_Extended_Main_Source_Unit (Subp)
2379 elsif Is_Always_Inlined (Subp) then
2381 -- Remove last character (question mark) to make this into an error,
2382 -- because the Inline_Always pragma cannot be obeyed.
2384 Error_Msg_NE (Msg (1 .. Msg'Length - 1), N, Subp);
2386 elsif Ineffective_Inline_Warnings then
2387 Error_Msg_NE (Msg, N, Subp);
2391 -----------------------
2392 -- Check_Conformance --
2393 -----------------------
2395 procedure Check_Conformance
2396 (New_Id : Entity_Id;
2398 Ctype : Conformance_Type;
2400 Conforms : out Boolean;
2401 Err_Loc : Node_Id := Empty;
2402 Get_Inst : Boolean := False;
2403 Skip_Controlling_Formals : Boolean := False)
2405 Old_Type : constant Entity_Id := Etype (Old_Id);
2406 New_Type : constant Entity_Id := Etype (New_Id);
2407 Old_Formal : Entity_Id;
2408 New_Formal : Entity_Id;
2410 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id);
2411 -- Post error message for conformance error on given node. Two messages
2412 -- are output. The first points to the previous declaration with a
2413 -- general "no conformance" message. The second is the detailed reason,
2414 -- supplied as Msg. The parameter N provide information for a possible
2415 -- & insertion in the message, and also provides the location for
2416 -- posting the message in the absence of a specified Err_Loc location.
2418 -----------------------
2419 -- Conformance_Error --
2420 -----------------------
2422 procedure Conformance_Error (Msg : String; N : Node_Id := New_Id) is
2429 if No (Err_Loc) then
2435 Error_Msg_Sloc := Sloc (Old_Id);
2438 when Type_Conformant =>
2440 ("not type conformant with declaration#!", Enode);
2442 when Mode_Conformant =>
2444 ("not mode conformant with declaration#!", Enode);
2446 when Subtype_Conformant =>
2448 ("not subtype conformant with declaration#!", Enode);
2450 when Fully_Conformant =>
2452 ("not fully conformant with declaration#!", Enode);
2455 Error_Msg_NE (Msg, Enode, N);
2457 end Conformance_Error;
2459 -- Start of processing for Check_Conformance
2464 -- We need a special case for operators, since they don't appear
2467 if Ctype = Type_Conformant then
2468 if Ekind (New_Id) = E_Operator
2469 and then Operator_Matches_Spec (New_Id, Old_Id)
2475 -- If both are functions/operators, check return types conform
2477 if Old_Type /= Standard_Void_Type
2478 and then New_Type /= Standard_Void_Type
2480 if not Conforming_Types (Old_Type, New_Type, Ctype, Get_Inst) then
2481 Conformance_Error ("return type does not match!", New_Id);
2485 -- Ada 2005 (AI-231): In case of anonymous access types check the
2486 -- null-exclusion and access-to-constant attributes must match.
2488 if Ada_Version >= Ada_05
2489 and then Ekind (Etype (Old_Type)) = E_Anonymous_Access_Type
2491 (Can_Never_Be_Null (Old_Type)
2492 /= Can_Never_Be_Null (New_Type)
2493 or else Is_Access_Constant (Etype (Old_Type))
2494 /= Is_Access_Constant (Etype (New_Type)))
2496 Conformance_Error ("return type does not match!", New_Id);
2500 -- If either is a function/operator and the other isn't, error
2502 elsif Old_Type /= Standard_Void_Type
2503 or else New_Type /= Standard_Void_Type
2505 Conformance_Error ("functions can only match functions!", New_Id);
2509 -- In subtype conformant case, conventions must match (RM 6.3.1(16))
2510 -- If this is a renaming as body, refine error message to indicate that
2511 -- the conflict is with the original declaration. If the entity is not
2512 -- frozen, the conventions don't have to match, the one of the renamed
2513 -- entity is inherited.
2515 if Ctype >= Subtype_Conformant then
2516 if Convention (Old_Id) /= Convention (New_Id) then
2518 if not Is_Frozen (New_Id) then
2521 elsif Present (Err_Loc)
2522 and then Nkind (Err_Loc) = N_Subprogram_Renaming_Declaration
2523 and then Present (Corresponding_Spec (Err_Loc))
2525 Error_Msg_Name_1 := Chars (New_Id);
2527 Name_Ada + Convention_Id'Pos (Convention (New_Id));
2529 Conformance_Error ("prior declaration for% has convention %!");
2532 Conformance_Error ("calling conventions do not match!");
2537 elsif Is_Formal_Subprogram (Old_Id)
2538 or else Is_Formal_Subprogram (New_Id)
2540 Conformance_Error ("formal subprograms not allowed!");
2545 -- Deal with parameters
2547 -- Note: we use the entity information, rather than going directly
2548 -- to the specification in the tree. This is not only simpler, but
2549 -- absolutely necessary for some cases of conformance tests between
2550 -- operators, where the declaration tree simply does not exist!
2552 Old_Formal := First_Formal (Old_Id);
2553 New_Formal := First_Formal (New_Id);
2555 while Present (Old_Formal) and then Present (New_Formal) loop
2556 if Is_Controlling_Formal (Old_Formal)
2557 and then Is_Controlling_Formal (New_Formal)
2558 and then Skip_Controlling_Formals
2560 goto Skip_Controlling_Formal;
2563 if Ctype = Fully_Conformant then
2565 -- Names must match. Error message is more accurate if we do
2566 -- this before checking that the types of the formals match.
2568 if Chars (Old_Formal) /= Chars (New_Formal) then
2569 Conformance_Error ("name & does not match!", New_Formal);
2571 -- Set error posted flag on new formal as well to stop
2572 -- junk cascaded messages in some cases.
2574 Set_Error_Posted (New_Formal);
2579 -- Types must always match. In the visible part of an instance,
2580 -- usual overloading rules for dispatching operations apply, and
2581 -- we check base types (not the actual subtypes).
2583 if In_Instance_Visible_Part
2584 and then Is_Dispatching_Operation (New_Id)
2586 if not Conforming_Types
2587 (Base_Type (Etype (Old_Formal)),
2588 Base_Type (Etype (New_Formal)), Ctype, Get_Inst)
2590 Conformance_Error ("type of & does not match!", New_Formal);
2594 elsif not Conforming_Types
2595 (Etype (Old_Formal), Etype (New_Formal), Ctype, Get_Inst)
2597 Conformance_Error ("type of & does not match!", New_Formal);
2601 -- For mode conformance, mode must match
2603 if Ctype >= Mode_Conformant
2604 and then Parameter_Mode (Old_Formal) /= Parameter_Mode (New_Formal)
2606 Conformance_Error ("mode of & does not match!", New_Formal);
2610 -- Full conformance checks
2612 if Ctype = Fully_Conformant then
2614 -- We have checked already that names match
2616 if Parameter_Mode (Old_Formal) = E_In_Parameter then
2618 -- Ada 2005 (AI-231): In case of anonymous access types check
2619 -- the null-exclusion and access-to-constant attributes must
2622 if Ada_Version >= Ada_05
2623 and then Ekind (Etype (Old_Formal)) = E_Anonymous_Access_Type
2625 (Can_Never_Be_Null (Old_Formal)
2626 /= Can_Never_Be_Null (New_Formal)
2627 or else Is_Access_Constant (Etype (Old_Formal))
2628 /= Is_Access_Constant (Etype (New_Formal)))
2630 -- It is allowed to omit the null-exclusion in case of
2631 -- stream attribute subprograms
2634 TSS_Name : TSS_Name_Type;
2637 Get_Name_String (Chars (New_Id));
2641 (Name_Len - TSS_Name'Length + 1 .. Name_Len));
2643 if TSS_Name /= TSS_Stream_Read
2644 and then TSS_Name /= TSS_Stream_Write
2645 and then TSS_Name /= TSS_Stream_Input
2646 and then TSS_Name /= TSS_Stream_Output
2649 ("type of & does not match!", New_Formal);
2655 -- Check default expressions for in parameters
2658 NewD : constant Boolean :=
2659 Present (Default_Value (New_Formal));
2660 OldD : constant Boolean :=
2661 Present (Default_Value (Old_Formal));
2663 if NewD or OldD then
2665 -- The old default value has been analyzed because the
2666 -- current full declaration will have frozen everything
2667 -- before. The new default values have not been
2668 -- analyzed, so analyze them now before we check for
2673 Analyze_Per_Use_Expression
2674 (Default_Value (New_Formal), Etype (New_Formal));
2678 if not (NewD and OldD)
2679 or else not Fully_Conformant_Expressions
2680 (Default_Value (Old_Formal),
2681 Default_Value (New_Formal))
2684 ("default expression for & does not match!",
2693 -- A couple of special checks for Ada 83 mode. These checks are
2694 -- skipped if either entity is an operator in package Standard.
2695 -- or if either old or new instance is not from the source program.
2697 if Ada_Version = Ada_83
2698 and then Sloc (Old_Id) > Standard_Location
2699 and then Sloc (New_Id) > Standard_Location
2700 and then Comes_From_Source (Old_Id)
2701 and then Comes_From_Source (New_Id)
2704 Old_Param : constant Node_Id := Declaration_Node (Old_Formal);
2705 New_Param : constant Node_Id := Declaration_Node (New_Formal);
2708 -- Explicit IN must be present or absent in both cases. This
2709 -- test is required only in the full conformance case.
2711 if In_Present (Old_Param) /= In_Present (New_Param)
2712 and then Ctype = Fully_Conformant
2715 ("(Ada 83) IN must appear in both declarations",
2720 -- Grouping (use of comma in param lists) must be the same
2721 -- This is where we catch a misconformance like:
2724 -- A : Integer; B : Integer
2726 -- which are represented identically in the tree except
2727 -- for the setting of the flags More_Ids and Prev_Ids.
2729 if More_Ids (Old_Param) /= More_Ids (New_Param)
2730 or else Prev_Ids (Old_Param) /= Prev_Ids (New_Param)
2733 ("grouping of & does not match!", New_Formal);
2739 -- This label is required when skipping controlling formals
2741 <<Skip_Controlling_Formal>>
2743 Next_Formal (Old_Formal);
2744 Next_Formal (New_Formal);
2747 if Present (Old_Formal) then
2748 Conformance_Error ("too few parameters!");
2751 elsif Present (New_Formal) then
2752 Conformance_Error ("too many parameters!", New_Formal);
2755 end Check_Conformance;
2757 ------------------------------
2758 -- Check_Delayed_Subprogram --
2759 ------------------------------
2761 procedure Check_Delayed_Subprogram (Designator : Entity_Id) is
2764 procedure Possible_Freeze (T : Entity_Id);
2765 -- T is the type of either a formal parameter or of the return type.
2766 -- If T is not yet frozen and needs a delayed freeze, then the
2767 -- subprogram itself must be delayed.
2769 ---------------------
2770 -- Possible_Freeze --
2771 ---------------------
2773 procedure Possible_Freeze (T : Entity_Id) is
2775 if Has_Delayed_Freeze (T)
2776 and then not Is_Frozen (T)
2778 Set_Has_Delayed_Freeze (Designator);
2780 elsif Is_Access_Type (T)
2781 and then Has_Delayed_Freeze (Designated_Type (T))
2782 and then not Is_Frozen (Designated_Type (T))
2784 Set_Has_Delayed_Freeze (Designator);
2786 end Possible_Freeze;
2788 -- Start of processing for Check_Delayed_Subprogram
2791 -- Never need to freeze abstract subprogram
2793 if Is_Abstract (Designator) then
2796 -- Need delayed freeze if return type itself needs a delayed
2797 -- freeze and is not yet frozen.
2799 Possible_Freeze (Etype (Designator));
2800 Possible_Freeze (Base_Type (Etype (Designator))); -- needed ???
2802 -- Need delayed freeze if any of the formal types themselves need
2803 -- a delayed freeze and are not yet frozen.
2805 F := First_Formal (Designator);
2806 while Present (F) loop
2807 Possible_Freeze (Etype (F));
2808 Possible_Freeze (Base_Type (Etype (F))); -- needed ???
2813 -- Mark functions that return by reference. Note that it cannot be
2814 -- done for delayed_freeze subprograms because the underlying
2815 -- returned type may not be known yet (for private types)
2817 if not Has_Delayed_Freeze (Designator)
2818 and then Expander_Active
2821 Typ : constant Entity_Id := Etype (Designator);
2822 Utyp : constant Entity_Id := Underlying_Type (Typ);
2825 if Is_Return_By_Reference_Type (Typ) then
2826 Set_Returns_By_Ref (Designator);
2828 elsif Present (Utyp) and then Controlled_Type (Utyp) then
2829 Set_Returns_By_Ref (Designator);
2833 end Check_Delayed_Subprogram;
2835 ------------------------------------
2836 -- Check_Discriminant_Conformance --
2837 ------------------------------------
2839 procedure Check_Discriminant_Conformance
2844 Old_Discr : Entity_Id := First_Discriminant (Prev);
2845 New_Discr : Node_Id := First (Discriminant_Specifications (N));
2846 New_Discr_Id : Entity_Id;
2847 New_Discr_Type : Entity_Id;
2849 procedure Conformance_Error (Msg : String; N : Node_Id);
2850 -- Post error message for conformance error on given node. Two messages
2851 -- are output. The first points to the previous declaration with a
2852 -- general "no conformance" message. The second is the detailed reason,
2853 -- supplied as Msg. The parameter N provide information for a possible
2854 -- & insertion in the message.
2856 -----------------------
2857 -- Conformance_Error --
2858 -----------------------
2860 procedure Conformance_Error (Msg : String; N : Node_Id) is
2862 Error_Msg_Sloc := Sloc (Prev_Loc);
2863 Error_Msg_N ("not fully conformant with declaration#!", N);
2864 Error_Msg_NE (Msg, N, N);
2865 end Conformance_Error;
2867 -- Start of processing for Check_Discriminant_Conformance
2870 while Present (Old_Discr) and then Present (New_Discr) loop
2872 New_Discr_Id := Defining_Identifier (New_Discr);
2874 -- The subtype mark of the discriminant on the full type has not
2875 -- been analyzed so we do it here. For an access discriminant a new
2878 if Nkind (Discriminant_Type (New_Discr)) = N_Access_Definition then
2880 Access_Definition (N, Discriminant_Type (New_Discr));
2883 Analyze (Discriminant_Type (New_Discr));
2884 New_Discr_Type := Etype (Discriminant_Type (New_Discr));
2887 if not Conforming_Types
2888 (Etype (Old_Discr), New_Discr_Type, Fully_Conformant)
2890 Conformance_Error ("type of & does not match!", New_Discr_Id);
2893 -- Treat the new discriminant as an occurrence of the old one,
2894 -- for navigation purposes, and fill in some semantic
2895 -- information, for completeness.
2897 Generate_Reference (Old_Discr, New_Discr_Id, 'r');
2898 Set_Etype (New_Discr_Id, Etype (Old_Discr));
2899 Set_Scope (New_Discr_Id, Scope (Old_Discr));
2904 if Chars (Old_Discr) /= Chars (Defining_Identifier (New_Discr)) then
2905 Conformance_Error ("name & does not match!", New_Discr_Id);
2909 -- Default expressions must match
2912 NewD : constant Boolean :=
2913 Present (Expression (New_Discr));
2914 OldD : constant Boolean :=
2915 Present (Expression (Parent (Old_Discr)));
2918 if NewD or OldD then
2920 -- The old default value has been analyzed and expanded,
2921 -- because the current full declaration will have frozen
2922 -- everything before. The new default values have not been
2923 -- expanded, so expand now to check conformance.
2926 Analyze_Per_Use_Expression
2927 (Expression (New_Discr), New_Discr_Type);
2930 if not (NewD and OldD)
2931 or else not Fully_Conformant_Expressions
2932 (Expression (Parent (Old_Discr)),
2933 Expression (New_Discr))
2937 ("default expression for & does not match!",
2944 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
2946 if Ada_Version = Ada_83 then
2948 Old_Disc : constant Node_Id := Declaration_Node (Old_Discr);
2951 -- Grouping (use of comma in param lists) must be the same
2952 -- This is where we catch a misconformance like:
2955 -- A : Integer; B : Integer
2957 -- which are represented identically in the tree except
2958 -- for the setting of the flags More_Ids and Prev_Ids.
2960 if More_Ids (Old_Disc) /= More_Ids (New_Discr)
2961 or else Prev_Ids (Old_Disc) /= Prev_Ids (New_Discr)
2964 ("grouping of & does not match!", New_Discr_Id);
2970 Next_Discriminant (Old_Discr);
2974 if Present (Old_Discr) then
2975 Conformance_Error ("too few discriminants!", Defining_Identifier (N));
2978 elsif Present (New_Discr) then
2980 ("too many discriminants!", Defining_Identifier (New_Discr));
2983 end Check_Discriminant_Conformance;
2985 ----------------------------
2986 -- Check_Fully_Conformant --
2987 ----------------------------
2989 procedure Check_Fully_Conformant
2990 (New_Id : Entity_Id;
2992 Err_Loc : Node_Id := Empty)
2997 (New_Id, Old_Id, Fully_Conformant, True, Result, Err_Loc);
2998 end Check_Fully_Conformant;
3000 ---------------------------
3001 -- Check_Mode_Conformant --
3002 ---------------------------
3004 procedure Check_Mode_Conformant
3005 (New_Id : Entity_Id;
3007 Err_Loc : Node_Id := Empty;
3008 Get_Inst : Boolean := False)
3014 (New_Id, Old_Id, Mode_Conformant, True, Result, Err_Loc, Get_Inst);
3015 end Check_Mode_Conformant;
3017 --------------------------------
3018 -- Check_Overriding_Indicator --
3019 --------------------------------
3021 procedure Check_Overriding_Indicator
3023 Does_Override : Boolean)
3029 if Ekind (Subp) = E_Enumeration_Literal then
3031 -- No overriding indicator for literals
3036 Decl := Unit_Declaration_Node (Subp);
3039 if Nkind (Decl) = N_Subprogram_Declaration
3040 or else Nkind (Decl) = N_Subprogram_Body
3041 or else Nkind (Decl) = N_Subprogram_Renaming_Declaration
3042 or else Nkind (Decl) = N_Subprogram_Body_Stub
3044 Spec := Specification (Decl);
3049 if not Does_Override then
3050 if Must_Override (Spec) then
3051 Error_Msg_NE ("subprogram& is not overriding", Spec, Subp);
3055 if Must_Not_Override (Spec) then
3057 ("subprogram& overrides inherited operation", Spec, Subp);
3060 end Check_Overriding_Indicator;
3066 procedure Check_Returns
3070 Proc : Entity_Id := Empty)
3074 procedure Check_Statement_Sequence (L : List_Id);
3075 -- Internal recursive procedure to check a list of statements for proper
3076 -- termination by a return statement (or a transfer of control or a
3077 -- compound statement that is itself internally properly terminated).
3079 ------------------------------
3080 -- Check_Statement_Sequence --
3081 ------------------------------
3083 procedure Check_Statement_Sequence (L : List_Id) is
3087 Raise_Exception_Call : Boolean;
3088 -- Set True if statement sequence terminated by Raise_Exception call
3089 -- or a Reraise_Occurrence call.
3092 Raise_Exception_Call := False;
3094 -- Get last real statement
3096 Last_Stm := Last (L);
3098 -- Don't count pragmas
3100 while Nkind (Last_Stm) = N_Pragma
3102 -- Don't count call to SS_Release (can happen after Raise_Exception)
3105 (Nkind (Last_Stm) = N_Procedure_Call_Statement
3107 Nkind (Name (Last_Stm)) = N_Identifier
3109 Is_RTE (Entity (Name (Last_Stm)), RE_SS_Release))
3111 -- Don't count exception junk
3114 ((Nkind (Last_Stm) = N_Goto_Statement
3115 or else Nkind (Last_Stm) = N_Label
3116 or else Nkind (Last_Stm) = N_Object_Declaration)
3117 and then Exception_Junk (Last_Stm))
3122 -- Here we have the "real" last statement
3124 Kind := Nkind (Last_Stm);
3126 -- Transfer of control, OK. Note that in the No_Return procedure
3127 -- case, we already diagnosed any explicit return statements, so
3128 -- we can treat them as OK in this context.
3130 if Is_Transfer (Last_Stm) then
3133 -- Check cases of explicit non-indirect procedure calls
3135 elsif Kind = N_Procedure_Call_Statement
3136 and then Is_Entity_Name (Name (Last_Stm))
3138 -- Check call to Raise_Exception procedure which is treated
3139 -- specially, as is a call to Reraise_Occurrence.
3141 -- We suppress the warning in these cases since it is likely that
3142 -- the programmer really does not expect to deal with the case
3143 -- of Null_Occurrence, and thus would find a warning about a
3144 -- missing return curious, and raising Program_Error does not
3145 -- seem such a bad behavior if this does occur.
3147 -- Note that in the Ada 2005 case for Raise_Exception, the actual
3148 -- behavior will be to raise Constraint_Error (see AI-329).
3150 if Is_RTE (Entity (Name (Last_Stm)), RE_Raise_Exception)
3152 Is_RTE (Entity (Name (Last_Stm)), RE_Reraise_Occurrence)
3154 Raise_Exception_Call := True;
3156 -- For Raise_Exception call, test first argument, if it is
3157 -- an attribute reference for a 'Identity call, then we know
3158 -- that the call cannot possibly return.
3161 Arg : constant Node_Id :=
3162 Original_Node (First_Actual (Last_Stm));
3165 if Nkind (Arg) = N_Attribute_Reference
3166 and then Attribute_Name (Arg) = Name_Identity
3173 -- If statement, need to look inside if there is an else and check
3174 -- each constituent statement sequence for proper termination.
3176 elsif Kind = N_If_Statement
3177 and then Present (Else_Statements (Last_Stm))
3179 Check_Statement_Sequence (Then_Statements (Last_Stm));
3180 Check_Statement_Sequence (Else_Statements (Last_Stm));
3182 if Present (Elsif_Parts (Last_Stm)) then
3184 Elsif_Part : Node_Id := First (Elsif_Parts (Last_Stm));
3187 while Present (Elsif_Part) loop
3188 Check_Statement_Sequence (Then_Statements (Elsif_Part));
3196 -- Case statement, check each case for proper termination
3198 elsif Kind = N_Case_Statement then
3203 Case_Alt := First_Non_Pragma (Alternatives (Last_Stm));
3204 while Present (Case_Alt) loop
3205 Check_Statement_Sequence (Statements (Case_Alt));
3206 Next_Non_Pragma (Case_Alt);
3212 -- Block statement, check its handled sequence of statements
3214 elsif Kind = N_Block_Statement then
3220 (Handled_Statement_Sequence (Last_Stm), Mode, Err1);
3229 -- Loop statement. If there is an iteration scheme, we can definitely
3230 -- fall out of the loop. Similarly if there is an exit statement, we
3231 -- can fall out. In either case we need a following return.
3233 elsif Kind = N_Loop_Statement then
3234 if Present (Iteration_Scheme (Last_Stm))
3235 or else Has_Exit (Entity (Identifier (Last_Stm)))
3239 -- A loop with no exit statement or iteration scheme if either
3240 -- an inifite loop, or it has some other exit (raise/return).
3241 -- In either case, no warning is required.
3247 -- Timed entry call, check entry call and delay alternatives
3249 -- Note: in expanded code, the timed entry call has been converted
3250 -- to a set of expanded statements on which the check will work
3251 -- correctly in any case.
3253 elsif Kind = N_Timed_Entry_Call then
3255 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
3256 DCA : constant Node_Id := Delay_Alternative (Last_Stm);
3259 -- If statement sequence of entry call alternative is missing,
3260 -- then we can definitely fall through, and we post the error
3261 -- message on the entry call alternative itself.
3263 if No (Statements (ECA)) then
3266 -- If statement sequence of delay alternative is missing, then
3267 -- we can definitely fall through, and we post the error
3268 -- message on the delay alternative itself.
3270 -- Note: if both ECA and DCA are missing the return, then we
3271 -- post only one message, should be enough to fix the bugs.
3272 -- If not we will get a message next time on the DCA when the
3275 elsif No (Statements (DCA)) then
3278 -- Else check both statement sequences
3281 Check_Statement_Sequence (Statements (ECA));
3282 Check_Statement_Sequence (Statements (DCA));
3287 -- Conditional entry call, check entry call and else part
3289 -- Note: in expanded code, the conditional entry call has been
3290 -- converted to a set of expanded statements on which the check
3291 -- will work correctly in any case.
3293 elsif Kind = N_Conditional_Entry_Call then
3295 ECA : constant Node_Id := Entry_Call_Alternative (Last_Stm);
3298 -- If statement sequence of entry call alternative is missing,
3299 -- then we can definitely fall through, and we post the error
3300 -- message on the entry call alternative itself.
3302 if No (Statements (ECA)) then
3305 -- Else check statement sequence and else part
3308 Check_Statement_Sequence (Statements (ECA));
3309 Check_Statement_Sequence (Else_Statements (Last_Stm));
3315 -- If we fall through, issue appropriate message
3318 if not Raise_Exception_Call then
3320 ("?RETURN statement missing following this statement",
3323 ("\?Program_Error may be raised at run time",
3327 -- Note: we set Err even though we have not issued a warning
3328 -- because we still have a case of a missing return. This is
3329 -- an extremely marginal case, probably will never be noticed
3330 -- but we might as well get it right.
3334 -- Otherwise we have the case of a procedure marked No_Return
3338 ("?implied return after this statement will raise Program_Error",
3341 ("?procedure & is marked as No_Return",
3345 RE : constant Node_Id :=
3346 Make_Raise_Program_Error (Sloc (Last_Stm),
3347 Reason => PE_Implicit_Return);
3349 Insert_After (Last_Stm, RE);
3353 end Check_Statement_Sequence;
3355 -- Start of processing for Check_Returns
3359 Check_Statement_Sequence (Statements (HSS));
3361 if Present (Exception_Handlers (HSS)) then
3362 Handler := First_Non_Pragma (Exception_Handlers (HSS));
3363 while Present (Handler) loop
3364 Check_Statement_Sequence (Statements (Handler));
3365 Next_Non_Pragma (Handler);
3370 ----------------------------
3371 -- Check_Subprogram_Order --
3372 ----------------------------
3374 procedure Check_Subprogram_Order (N : Node_Id) is
3376 function Subprogram_Name_Greater (S1, S2 : String) return Boolean;
3377 -- This is used to check if S1 > S2 in the sense required by this
3378 -- test, for example nameab < namec, but name2 < name10.
3380 -----------------------------
3381 -- Subprogram_Name_Greater --
3382 -----------------------------
3384 function Subprogram_Name_Greater (S1, S2 : String) return Boolean is
3389 -- Remove trailing numeric parts
3392 while S1 (L1) in '0' .. '9' loop
3397 while S2 (L2) in '0' .. '9' loop
3401 -- If non-numeric parts non-equal, that's decisive
3403 if S1 (S1'First .. L1) < S2 (S2'First .. L2) then
3406 elsif S1 (S1'First .. L1) > S2 (S2'First .. L2) then
3409 -- If non-numeric parts equal, compare suffixed numeric parts. Note
3410 -- that a missing suffix is treated as numeric zero in this test.
3414 while L1 < S1'Last loop
3416 N1 := N1 * 10 + Character'Pos (S1 (L1)) - Character'Pos ('0');
3420 while L2 < S2'Last loop
3422 N2 := N2 * 10 + Character'Pos (S2 (L2)) - Character'Pos ('0');
3427 end Subprogram_Name_Greater;
3429 -- Start of processing for Check_Subprogram_Order
3432 -- Check body in alpha order if this is option
3435 and then Style_Check_Order_Subprograms
3436 and then Nkind (N) = N_Subprogram_Body
3437 and then Comes_From_Source (N)
3438 and then In_Extended_Main_Source_Unit (N)
3442 renames Scope_Stack.Table
3443 (Scope_Stack.Last).Last_Subprogram_Name;
3445 Body_Id : constant Entity_Id :=
3446 Defining_Entity (Specification (N));
3449 Get_Decoded_Name_String (Chars (Body_Id));
3452 if Subprogram_Name_Greater
3453 (LSN.all, Name_Buffer (1 .. Name_Len))
3455 Style.Subprogram_Not_In_Alpha_Order (Body_Id);
3461 LSN := new String'(Name_Buffer (1 .. Name_Len));
3464 end Check_Subprogram_Order;
3466 ------------------------------
3467 -- Check_Subtype_Conformant --
3468 ------------------------------
3470 procedure Check_Subtype_Conformant
3471 (New_Id : Entity_Id;
3473 Err_Loc : Node_Id := Empty)
3478 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
3479 end Check_Subtype_Conformant;
3481 ---------------------------
3482 -- Check_Type_Conformant --
3483 ---------------------------
3485 procedure Check_Type_Conformant
3486 (New_Id : Entity_Id;
3488 Err_Loc : Node_Id := Empty)
3493 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
3494 end Check_Type_Conformant;
3496 ----------------------
3497 -- Conforming_Types --
3498 ----------------------
3500 function Conforming_Types
3503 Ctype : Conformance_Type;
3504 Get_Inst : Boolean := False) return Boolean
3506 Type_1 : Entity_Id := T1;
3507 Type_2 : Entity_Id := T2;
3508 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
3510 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
3511 -- If neither T1 nor T2 are generic actual types, or if they are
3512 -- in different scopes (e.g. parent and child instances), then verify
3513 -- that the base types are equal. Otherwise T1 and T2 must be
3514 -- on the same subtype chain. The whole purpose of this procedure
3515 -- is to prevent spurious ambiguities in an instantiation that may
3516 -- arise if two distinct generic types are instantiated with the
3519 ----------------------
3520 -- Base_Types_Match --
3521 ----------------------
3523 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
3528 elsif Base_Type (T1) = Base_Type (T2) then
3530 -- The following is too permissive. A more precise test must
3531 -- check that the generic actual is an ancestor subtype of the
3534 return not Is_Generic_Actual_Type (T1)
3535 or else not Is_Generic_Actual_Type (T2)
3536 or else Scope (T1) /= Scope (T2);
3538 -- In some cases a type imported through a limited_with clause,
3539 -- and its non-limited view are both visible, for example in an
3540 -- anonymous access_to_classwide type in a formal. Both entities
3541 -- designate the same type.
3543 elsif From_With_Type (T1)
3544 and then Ekind (T1) = E_Incomplete_Type
3545 and then T2 = Non_Limited_View (T1)
3549 elsif From_With_Type (T2)
3550 and then Ekind (T2) = E_Incomplete_Type
3551 and then T1 = Non_Limited_View (T2)
3558 end Base_Types_Match;
3560 -- Start of processing for Conforming_Types
3563 -- The context is an instance association for a formal
3564 -- access-to-subprogram type; the formal parameter types require
3565 -- mapping because they may denote other formal parameters of the
3569 Type_1 := Get_Instance_Of (T1);
3570 Type_2 := Get_Instance_Of (T2);
3573 -- First see if base types match
3575 if Base_Types_Match (Type_1, Type_2) then
3576 return Ctype <= Mode_Conformant
3577 or else Subtypes_Statically_Match (Type_1, Type_2);
3579 elsif Is_Incomplete_Or_Private_Type (Type_1)
3580 and then Present (Full_View (Type_1))
3581 and then Base_Types_Match (Full_View (Type_1), Type_2)
3583 return Ctype <= Mode_Conformant
3584 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
3586 elsif Ekind (Type_2) = E_Incomplete_Type
3587 and then Present (Full_View (Type_2))
3588 and then Base_Types_Match (Type_1, Full_View (Type_2))
3590 return Ctype <= Mode_Conformant
3591 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
3593 elsif Is_Private_Type (Type_2)
3594 and then In_Instance
3595 and then Present (Full_View (Type_2))
3596 and then Base_Types_Match (Type_1, Full_View (Type_2))
3598 return Ctype <= Mode_Conformant
3599 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
3602 -- Ada 2005 (AI-254): Anonymous access to subprogram types must be
3603 -- treated recursively because they carry a signature.
3605 Are_Anonymous_Access_To_Subprogram_Types :=
3607 -- Case 1: Anonymous access to subprogram types
3609 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
3610 and then Ekind (Type_2) = E_Anonymous_Access_Subprogram_Type)
3612 -- Case 2: Anonymous access to PROTECTED subprogram types. In this
3613 -- case the anonymous type_declaration has been replaced by an
3614 -- occurrence of an internal access to subprogram type declaration
3615 -- available through the Original_Access_Type attribute
3618 (Ekind (Type_1) = E_Access_Protected_Subprogram_Type
3619 and then Ekind (Type_2) = E_Access_Protected_Subprogram_Type
3620 and then not Comes_From_Source (Type_1)
3621 and then not Comes_From_Source (Type_2)
3622 and then Present (Original_Access_Type (Type_1))
3623 and then Present (Original_Access_Type (Type_2))
3624 and then Ekind (Original_Access_Type (Type_1)) =
3625 E_Anonymous_Access_Protected_Subprogram_Type
3626 and then Ekind (Original_Access_Type (Type_2)) =
3627 E_Anonymous_Access_Protected_Subprogram_Type);
3629 -- Test anonymous access type case. For this case, static subtype
3630 -- matching is required for mode conformance (RM 6.3.1(15))
3632 if (Ekind (Type_1) = E_Anonymous_Access_Type
3633 and then Ekind (Type_2) = E_Anonymous_Access_Type)
3634 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
3637 Desig_1 : Entity_Id;
3638 Desig_2 : Entity_Id;
3641 Desig_1 := Directly_Designated_Type (Type_1);
3643 -- An access parameter can designate an incomplete type
3644 -- If the incomplete type is the limited view of a type
3645 -- from a limited_with_clause, check whether the non-limited
3646 -- view is available.
3648 if Ekind (Desig_1) = E_Incomplete_Type then
3649 if Present (Full_View (Desig_1)) then
3650 Desig_1 := Full_View (Desig_1);
3652 elsif Present (Non_Limited_View (Desig_1)) then
3653 Desig_1 := Non_Limited_View (Desig_1);
3657 Desig_2 := Directly_Designated_Type (Type_2);
3659 if Ekind (Desig_2) = E_Incomplete_Type then
3660 if Present (Full_View (Desig_2)) then
3661 Desig_2 := Full_View (Desig_2);
3662 elsif Present (Non_Limited_View (Desig_2)) then
3663 Desig_2 := Non_Limited_View (Desig_2);
3667 -- The context is an instance association for a formal
3668 -- access-to-subprogram type; formal access parameter designated
3669 -- types require mapping because they may denote other formal
3670 -- parameters of the generic unit.
3673 Desig_1 := Get_Instance_Of (Desig_1);
3674 Desig_2 := Get_Instance_Of (Desig_2);
3677 -- It is possible for a Class_Wide_Type to be introduced for an
3678 -- incomplete type, in which case there is a separate class_ wide
3679 -- type for the full view. The types conform if their Etypes
3680 -- conform, i.e. one may be the full view of the other. This can
3681 -- only happen in the context of an access parameter, other uses
3682 -- of an incomplete Class_Wide_Type are illegal.
3684 if Is_Class_Wide_Type (Desig_1)
3685 and then Is_Class_Wide_Type (Desig_2)
3689 (Etype (Base_Type (Desig_1)),
3690 Etype (Base_Type (Desig_2)), Ctype);
3692 elsif Are_Anonymous_Access_To_Subprogram_Types then
3693 if Ada_Version < Ada_05 then
3694 return Ctype = Type_Conformant
3696 Subtypes_Statically_Match (Desig_1, Desig_2);
3698 -- We must check the conformance of the signatures themselves
3702 Conformant : Boolean;
3705 (Desig_1, Desig_2, Ctype, False, Conformant);
3711 return Base_Type (Desig_1) = Base_Type (Desig_2)
3712 and then (Ctype = Type_Conformant
3714 Subtypes_Statically_Match (Desig_1, Desig_2));
3718 -- Otherwise definitely no match
3721 if ((Ekind (Type_1) = E_Anonymous_Access_Type
3722 and then Is_Access_Type (Type_2))
3723 or else (Ekind (Type_2) = E_Anonymous_Access_Type
3724 and then Is_Access_Type (Type_1)))
3727 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
3729 May_Hide_Profile := True;
3734 end Conforming_Types;
3736 --------------------------
3737 -- Create_Extra_Formals --
3738 --------------------------
3740 procedure Create_Extra_Formals (E : Entity_Id) is
3742 Last_Extra : Entity_Id;
3743 Formal_Type : Entity_Id;
3744 P_Formal : Entity_Id := Empty;
3746 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id;
3747 -- Add an extra formal, associated with the current Formal. The extra
3748 -- formal is added to the list of extra formals, and also returned as
3749 -- the result. These formals are always of mode IN.
3751 ----------------------
3752 -- Add_Extra_Formal --
3753 ----------------------
3755 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is
3756 EF : constant Entity_Id :=
3757 Make_Defining_Identifier (Sloc (Formal),
3758 Chars => New_External_Name (Chars (Formal), 'F'));
3761 -- We never generate extra formals if expansion is not active
3762 -- because we don't need them unless we are generating code.
3764 if not Expander_Active then
3768 -- A little optimization. Never generate an extra formal for the
3769 -- _init operand of an initialization procedure, since it could
3772 if Chars (Formal) = Name_uInit then
3776 Set_Ekind (EF, E_In_Parameter);
3777 Set_Actual_Subtype (EF, Typ);
3778 Set_Etype (EF, Typ);
3779 Set_Scope (EF, Scope (Formal));
3780 Set_Mechanism (EF, Default_Mechanism);
3781 Set_Formal_Validity (EF);
3783 Set_Extra_Formal (Last_Extra, EF);
3786 end Add_Extra_Formal;
3788 -- Start of processing for Create_Extra_Formals
3791 -- If this is a derived subprogram then the subtypes of the parent
3792 -- subprogram's formal parameters will be used to to determine the need
3793 -- for extra formals.
3795 if Is_Overloadable (E) and then Present (Alias (E)) then
3796 P_Formal := First_Formal (Alias (E));
3799 Last_Extra := Empty;
3800 Formal := First_Formal (E);
3801 while Present (Formal) loop
3802 Last_Extra := Formal;
3803 Next_Formal (Formal);
3806 -- If Extra_formals where already created, don't do it again. This
3807 -- situation may arise for subprogram types created as part of
3808 -- dispatching calls (see Expand_Dispatching_Call)
3810 if Present (Last_Extra) and then
3811 Present (Extra_Formal (Last_Extra))
3816 Formal := First_Formal (E);
3818 while Present (Formal) loop
3820 -- Create extra formal for supporting the attribute 'Constrained.
3821 -- The case of a private type view without discriminants also
3822 -- requires the extra formal if the underlying type has defaulted
3825 if Ekind (Formal) /= E_In_Parameter then
3826 if Present (P_Formal) then
3827 Formal_Type := Etype (P_Formal);
3829 Formal_Type := Etype (Formal);
3832 -- Do not produce extra formals for Unchecked_Union parameters.
3833 -- Jump directly to the end of the loop.
3835 if Is_Unchecked_Union (Base_Type (Formal_Type)) then
3836 goto Skip_Extra_Formal_Generation;
3839 if not Has_Discriminants (Formal_Type)
3840 and then Ekind (Formal_Type) in Private_Kind
3841 and then Present (Underlying_Type (Formal_Type))
3843 Formal_Type := Underlying_Type (Formal_Type);
3846 if Has_Discriminants (Formal_Type)
3848 ((not Is_Constrained (Formal_Type)
3849 and then not Is_Indefinite_Subtype (Formal_Type))
3850 or else Present (Extra_Formal (Formal)))
3852 Set_Extra_Constrained
3853 (Formal, Add_Extra_Formal (Standard_Boolean));
3857 -- Create extra formal for supporting accessibility checking
3859 -- This is suppressed if we specifically suppress accessibility
3860 -- checks at the pacage level for either the subprogram, or the
3861 -- package in which it resides. However, we do not suppress it
3862 -- simply if the scope has accessibility checks suppressed, since
3863 -- this could cause trouble when clients are compiled with a
3864 -- different suppression setting. The explicit checks at the
3865 -- package level are safe from this point of view.
3867 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type
3869 (Explicit_Suppress (E, Accessibility_Check)
3871 Explicit_Suppress (Scope (E), Accessibility_Check))
3874 or else Present (Extra_Accessibility (P_Formal)))
3876 -- Temporary kludge: for now we avoid creating the extra formal
3877 -- for access parameters of protected operations because of
3878 -- problem with the case of internal protected calls. ???
3880 if Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Definition
3881 and then Nkind (Parent (Parent (Parent (E)))) /= N_Protected_Body
3883 Set_Extra_Accessibility
3884 (Formal, Add_Extra_Formal (Standard_Natural));
3888 if Present (P_Formal) then
3889 Next_Formal (P_Formal);
3892 -- This label is required when skipping extra formal generation for
3893 -- Unchecked_Union parameters.
3895 <<Skip_Extra_Formal_Generation>>
3897 Next_Formal (Formal);
3899 end Create_Extra_Formals;
3901 -----------------------------
3902 -- Enter_Overloaded_Entity --
3903 -----------------------------
3905 procedure Enter_Overloaded_Entity (S : Entity_Id) is
3906 E : Entity_Id := Current_Entity_In_Scope (S);
3907 C_E : Entity_Id := Current_Entity (S);
3911 Set_Has_Homonym (E);
3912 Set_Has_Homonym (S);
3915 Set_Is_Immediately_Visible (S);
3916 Set_Scope (S, Current_Scope);
3918 -- Chain new entity if front of homonym in current scope, so that
3919 -- homonyms are contiguous.
3924 while Homonym (C_E) /= E loop
3925 C_E := Homonym (C_E);
3928 Set_Homonym (C_E, S);
3932 Set_Current_Entity (S);
3937 Append_Entity (S, Current_Scope);
3938 Set_Public_Status (S);
3940 if Debug_Flag_E then
3941 Write_Str ("New overloaded entity chain: ");
3942 Write_Name (Chars (S));
3945 while Present (E) loop
3946 Write_Str (" "); Write_Int (Int (E));
3953 -- Generate warning for hiding
3956 and then Comes_From_Source (S)
3957 and then In_Extended_Main_Source_Unit (S)
3964 -- Warn unless genuine overloading
3966 if (not Is_Overloadable (E))
3967 or else Subtype_Conformant (E, S)
3969 Error_Msg_Sloc := Sloc (E);
3970 Error_Msg_N ("declaration of & hides one#?", S);
3974 end Enter_Overloaded_Entity;
3976 -----------------------------
3977 -- Find_Corresponding_Spec --
3978 -----------------------------
3980 function Find_Corresponding_Spec (N : Node_Id) return Entity_Id is
3981 Spec : constant Node_Id := Specification (N);
3982 Designator : constant Entity_Id := Defining_Entity (Spec);
3987 E := Current_Entity (Designator);
3989 while Present (E) loop
3991 -- We are looking for a matching spec. It must have the same scope,
3992 -- and the same name, and either be type conformant, or be the case
3993 -- of a library procedure spec and its body (which belong to one
3994 -- another regardless of whether they are type conformant or not).
3996 if Scope (E) = Current_Scope then
3997 if Current_Scope = Standard_Standard
3998 or else (Ekind (E) = Ekind (Designator)
3999 and then Type_Conformant (E, Designator))
4001 -- Within an instantiation, we know that spec and body are
4002 -- subtype conformant, because they were subtype conformant
4003 -- in the generic. We choose the subtype-conformant entity
4004 -- here as well, to resolve spurious ambiguities in the
4005 -- instance that were not present in the generic (i.e. when
4006 -- two different types are given the same actual). If we are
4007 -- looking for a spec to match a body, full conformance is
4011 Set_Convention (Designator, Convention (E));
4013 if Nkind (N) = N_Subprogram_Body
4014 and then Present (Homonym (E))
4015 and then not Fully_Conformant (E, Designator)
4019 elsif not Subtype_Conformant (E, Designator) then
4024 if not Has_Completion (E) then
4026 if Nkind (N) /= N_Subprogram_Body_Stub then
4027 Set_Corresponding_Spec (N, E);
4030 Set_Has_Completion (E);
4033 elsif Nkind (Parent (N)) = N_Subunit then
4035 -- If this is the proper body of a subunit, the completion
4036 -- flag is set when analyzing the stub.
4040 -- If body already exists, this is an error unless the
4041 -- previous declaration is the implicit declaration of
4042 -- a derived subprogram, or this is a spurious overloading
4045 elsif No (Alias (E))
4046 and then not Is_Intrinsic_Subprogram (E)
4047 and then not In_Instance
4049 Error_Msg_Sloc := Sloc (E);
4050 if Is_Imported (E) then
4052 ("body not allowed for imported subprogram & declared#",
4055 Error_Msg_NE ("duplicate body for & declared#", N, E);
4059 elsif Is_Child_Unit (E)
4061 Nkind (Unit_Declaration_Node (Designator)) = N_Subprogram_Body
4063 Nkind (Parent (Unit_Declaration_Node (Designator)))
4064 = N_Compilation_Unit
4067 -- Child units cannot be overloaded, so a conformance mismatch
4068 -- between body and a previous spec is an error.
4071 ("body of child unit does not match previous declaration", N);
4079 -- On exit, we know that no previous declaration of subprogram exists
4082 end Find_Corresponding_Spec;
4084 ----------------------
4085 -- Fully_Conformant --
4086 ----------------------
4088 function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
4091 Check_Conformance (New_Id, Old_Id, Fully_Conformant, False, Result);
4093 end Fully_Conformant;
4095 ----------------------------------
4096 -- Fully_Conformant_Expressions --
4097 ----------------------------------
4099 function Fully_Conformant_Expressions
4100 (Given_E1 : Node_Id;
4101 Given_E2 : Node_Id) return Boolean
4103 E1 : constant Node_Id := Original_Node (Given_E1);
4104 E2 : constant Node_Id := Original_Node (Given_E2);
4105 -- We always test conformance on original nodes, since it is possible
4106 -- for analysis and/or expansion to make things look as though they
4107 -- conform when they do not, e.g. by converting 1+2 into 3.
4109 function FCE (Given_E1, Given_E2 : Node_Id) return Boolean
4110 renames Fully_Conformant_Expressions;
4112 function FCL (L1, L2 : List_Id) return Boolean;
4113 -- Compare elements of two lists for conformance. Elements have to
4114 -- be conformant, and actuals inserted as default parameters do not
4115 -- match explicit actuals with the same value.
4117 function FCO (Op_Node, Call_Node : Node_Id) return Boolean;
4118 -- Compare an operator node with a function call
4124 function FCL (L1, L2 : List_Id) return Boolean is
4128 if L1 = No_List then
4134 if L2 = No_List then
4140 -- Compare two lists, skipping rewrite insertions (we want to
4141 -- compare the original trees, not the expanded versions!)
4144 if Is_Rewrite_Insertion (N1) then
4146 elsif Is_Rewrite_Insertion (N2) then
4152 elsif not FCE (N1, N2) then
4165 function FCO (Op_Node, Call_Node : Node_Id) return Boolean is
4166 Actuals : constant List_Id := Parameter_Associations (Call_Node);
4171 or else Entity (Op_Node) /= Entity (Name (Call_Node))
4176 Act := First (Actuals);
4178 if Nkind (Op_Node) in N_Binary_Op then
4180 if not FCE (Left_Opnd (Op_Node), Act) then
4187 return Present (Act)
4188 and then FCE (Right_Opnd (Op_Node), Act)
4189 and then No (Next (Act));
4193 -- Start of processing for Fully_Conformant_Expressions
4196 -- Non-conformant if paren count does not match. Note: if some idiot
4197 -- complains that we don't do this right for more than 3 levels of
4198 -- parentheses, they will be treated with the respect they deserve :-)
4200 if Paren_Count (E1) /= Paren_Count (E2) then
4203 -- If same entities are referenced, then they are conformant even if
4204 -- they have different forms (RM 8.3.1(19-20)).
4206 elsif Is_Entity_Name (E1) and then Is_Entity_Name (E2) then
4207 if Present (Entity (E1)) then
4208 return Entity (E1) = Entity (E2)
4209 or else (Chars (Entity (E1)) = Chars (Entity (E2))
4210 and then Ekind (Entity (E1)) = E_Discriminant
4211 and then Ekind (Entity (E2)) = E_In_Parameter);
4213 elsif Nkind (E1) = N_Expanded_Name
4214 and then Nkind (E2) = N_Expanded_Name
4215 and then Nkind (Selector_Name (E1)) = N_Character_Literal
4216 and then Nkind (Selector_Name (E2)) = N_Character_Literal
4218 return Chars (Selector_Name (E1)) = Chars (Selector_Name (E2));
4221 -- Identifiers in component associations don't always have
4222 -- entities, but their names must conform.
4224 return Nkind (E1) = N_Identifier
4225 and then Nkind (E2) = N_Identifier
4226 and then Chars (E1) = Chars (E2);
4229 elsif Nkind (E1) = N_Character_Literal
4230 and then Nkind (E2) = N_Expanded_Name
4232 return Nkind (Selector_Name (E2)) = N_Character_Literal
4233 and then Chars (E1) = Chars (Selector_Name (E2));
4235 elsif Nkind (E2) = N_Character_Literal
4236 and then Nkind (E1) = N_Expanded_Name
4238 return Nkind (Selector_Name (E1)) = N_Character_Literal
4239 and then Chars (E2) = Chars (Selector_Name (E1));
4241 elsif Nkind (E1) in N_Op
4242 and then Nkind (E2) = N_Function_Call
4244 return FCO (E1, E2);
4246 elsif Nkind (E2) in N_Op
4247 and then Nkind (E1) = N_Function_Call
4249 return FCO (E2, E1);
4251 -- Otherwise we must have the same syntactic entity
4253 elsif Nkind (E1) /= Nkind (E2) then
4256 -- At this point, we specialize by node type
4263 FCL (Expressions (E1), Expressions (E2))
4264 and then FCL (Component_Associations (E1),
4265 Component_Associations (E2));
4268 if Nkind (Expression (E1)) = N_Qualified_Expression
4270 Nkind (Expression (E2)) = N_Qualified_Expression
4272 return FCE (Expression (E1), Expression (E2));
4274 -- Check that the subtype marks and any constraints
4279 Indic1 : constant Node_Id := Expression (E1);
4280 Indic2 : constant Node_Id := Expression (E2);
4285 if Nkind (Indic1) /= N_Subtype_Indication then
4287 Nkind (Indic2) /= N_Subtype_Indication
4288 and then Entity (Indic1) = Entity (Indic2);
4290 elsif Nkind (Indic2) /= N_Subtype_Indication then
4292 Nkind (Indic1) /= N_Subtype_Indication
4293 and then Entity (Indic1) = Entity (Indic2);
4296 if Entity (Subtype_Mark (Indic1)) /=
4297 Entity (Subtype_Mark (Indic2))
4302 Elt1 := First (Constraints (Constraint (Indic1)));
4303 Elt2 := First (Constraints (Constraint (Indic2)));
4305 while Present (Elt1) and then Present (Elt2) loop
4306 if not FCE (Elt1, Elt2) then
4319 when N_Attribute_Reference =>
4321 Attribute_Name (E1) = Attribute_Name (E2)
4322 and then FCL (Expressions (E1), Expressions (E2));
4326 Entity (E1) = Entity (E2)
4327 and then FCE (Left_Opnd (E1), Left_Opnd (E2))
4328 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
4330 when N_And_Then | N_Or_Else | N_In | N_Not_In =>
4332 FCE (Left_Opnd (E1), Left_Opnd (E2))
4334 FCE (Right_Opnd (E1), Right_Opnd (E2));
4336 when N_Character_Literal =>
4338 Char_Literal_Value (E1) = Char_Literal_Value (E2);
4340 when N_Component_Association =>
4342 FCL (Choices (E1), Choices (E2))
4343 and then FCE (Expression (E1), Expression (E2));
4345 when N_Conditional_Expression =>
4347 FCL (Expressions (E1), Expressions (E2));
4349 when N_Explicit_Dereference =>
4351 FCE (Prefix (E1), Prefix (E2));
4353 when N_Extension_Aggregate =>
4355 FCL (Expressions (E1), Expressions (E2))
4356 and then Null_Record_Present (E1) =
4357 Null_Record_Present (E2)
4358 and then FCL (Component_Associations (E1),
4359 Component_Associations (E2));
4361 when N_Function_Call =>
4363 FCE (Name (E1), Name (E2))
4364 and then FCL (Parameter_Associations (E1),
4365 Parameter_Associations (E2));
4367 when N_Indexed_Component =>
4369 FCE (Prefix (E1), Prefix (E2))
4370 and then FCL (Expressions (E1), Expressions (E2));
4372 when N_Integer_Literal =>
4373 return (Intval (E1) = Intval (E2));
4378 when N_Operator_Symbol =>
4380 Chars (E1) = Chars (E2);
4382 when N_Others_Choice =>
4385 when N_Parameter_Association =>
4387 Chars (Selector_Name (E1)) = Chars (Selector_Name (E2))
4388 and then FCE (Explicit_Actual_Parameter (E1),
4389 Explicit_Actual_Parameter (E2));
4391 when N_Qualified_Expression =>
4393 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
4394 and then FCE (Expression (E1), Expression (E2));
4398 FCE (Low_Bound (E1), Low_Bound (E2))
4399 and then FCE (High_Bound (E1), High_Bound (E2));
4401 when N_Real_Literal =>
4402 return (Realval (E1) = Realval (E2));
4404 when N_Selected_Component =>
4406 FCE (Prefix (E1), Prefix (E2))
4407 and then FCE (Selector_Name (E1), Selector_Name (E2));
4411 FCE (Prefix (E1), Prefix (E2))
4412 and then FCE (Discrete_Range (E1), Discrete_Range (E2));
4414 when N_String_Literal =>
4416 S1 : constant String_Id := Strval (E1);
4417 S2 : constant String_Id := Strval (E2);
4418 L1 : constant Nat := String_Length (S1);
4419 L2 : constant Nat := String_Length (S2);
4426 for J in 1 .. L1 loop
4427 if Get_String_Char (S1, J) /=
4428 Get_String_Char (S2, J)
4438 when N_Type_Conversion =>
4440 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
4441 and then FCE (Expression (E1), Expression (E2));
4445 Entity (E1) = Entity (E2)
4446 and then FCE (Right_Opnd (E1), Right_Opnd (E2));
4448 when N_Unchecked_Type_Conversion =>
4450 FCE (Subtype_Mark (E1), Subtype_Mark (E2))
4451 and then FCE (Expression (E1), Expression (E2));
4453 -- All other node types cannot appear in this context. Strictly
4454 -- we should raise a fatal internal error. Instead we just ignore
4455 -- the nodes. This means that if anyone makes a mistake in the
4456 -- expander and mucks an expression tree irretrievably, the
4457 -- result will be a failure to detect a (probably very obscure)
4458 -- case of non-conformance, which is better than bombing on some
4459 -- case where two expressions do in fact conform.
4466 end Fully_Conformant_Expressions;
4468 ----------------------------------------
4469 -- Fully_Conformant_Discrete_Subtypes --
4470 ----------------------------------------
4472 function Fully_Conformant_Discrete_Subtypes
4473 (Given_S1 : Node_Id;
4474 Given_S2 : Node_Id) return Boolean
4476 S1 : constant Node_Id := Original_Node (Given_S1);
4477 S2 : constant Node_Id := Original_Node (Given_S2);
4479 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean;
4480 -- Special-case for a bound given by a discriminant, which in the body
4481 -- is replaced with the discriminal of the enclosing type.
4483 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean;
4484 -- Check both bounds
4486 function Conforming_Bounds (B1, B2 : Node_Id) return Boolean is
4488 if Is_Entity_Name (B1)
4489 and then Is_Entity_Name (B2)
4490 and then Ekind (Entity (B1)) = E_Discriminant
4492 return Chars (B1) = Chars (B2);
4495 return Fully_Conformant_Expressions (B1, B2);
4497 end Conforming_Bounds;
4499 function Conforming_Ranges (R1, R2 : Node_Id) return Boolean is
4502 Conforming_Bounds (Low_Bound (R1), Low_Bound (R2))
4504 Conforming_Bounds (High_Bound (R1), High_Bound (R2));
4505 end Conforming_Ranges;
4507 -- Start of processing for Fully_Conformant_Discrete_Subtypes
4510 if Nkind (S1) /= Nkind (S2) then
4513 elsif Is_Entity_Name (S1) then
4514 return Entity (S1) = Entity (S2);
4516 elsif Nkind (S1) = N_Range then
4517 return Conforming_Ranges (S1, S2);
4519 elsif Nkind (S1) = N_Subtype_Indication then
4521 Entity (Subtype_Mark (S1)) = Entity (Subtype_Mark (S2))
4524 (Range_Expression (Constraint (S1)),
4525 Range_Expression (Constraint (S2)));
4529 end Fully_Conformant_Discrete_Subtypes;
4531 --------------------
4532 -- Install_Entity --
4533 --------------------
4535 procedure Install_Entity (E : Entity_Id) is
4536 Prev : constant Entity_Id := Current_Entity (E);
4538 Set_Is_Immediately_Visible (E);
4539 Set_Current_Entity (E);
4540 Set_Homonym (E, Prev);
4543 ---------------------
4544 -- Install_Formals --
4545 ---------------------
4547 procedure Install_Formals (Id : Entity_Id) is
4550 F := First_Formal (Id);
4551 while Present (F) loop
4555 end Install_Formals;
4557 ---------------------------------
4558 -- Is_Non_Overriding_Operation --
4559 ---------------------------------
4561 function Is_Non_Overriding_Operation
4562 (Prev_E : Entity_Id;
4563 New_E : Entity_Id) return Boolean
4567 G_Typ : Entity_Id := Empty;
4569 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id;
4570 -- If F_Type is a derived type associated with a generic actual
4571 -- subtype, then return its Generic_Parent_Type attribute, else return
4574 function Types_Correspond
4575 (P_Type : Entity_Id;
4576 N_Type : Entity_Id) return Boolean;
4577 -- Returns true if and only if the types (or designated types in the
4578 -- case of anonymous access types) are the same or N_Type is derived
4579 -- directly or indirectly from P_Type.
4581 -----------------------------
4582 -- Get_Generic_Parent_Type --
4583 -----------------------------
4585 function Get_Generic_Parent_Type (F_Typ : Entity_Id) return Entity_Id is
4590 if Is_Derived_Type (F_Typ)
4591 and then Nkind (Parent (F_Typ)) = N_Full_Type_Declaration
4593 -- The tree must be traversed to determine the parent subtype in
4594 -- the generic unit, which unfortunately isn't always available
4595 -- via semantic attributes. ??? (Note: The use of Original_Node
4596 -- is needed for cases where a full derived type has been
4599 Indic := Subtype_Indication
4600 (Type_Definition (Original_Node (Parent (F_Typ))));
4602 if Nkind (Indic) = N_Subtype_Indication then
4603 G_Typ := Entity (Subtype_Mark (Indic));
4605 G_Typ := Entity (Indic);
4608 if Nkind (Parent (G_Typ)) = N_Subtype_Declaration
4609 and then Present (Generic_Parent_Type (Parent (G_Typ)))
4611 return Generic_Parent_Type (Parent (G_Typ));
4616 end Get_Generic_Parent_Type;
4618 ----------------------
4619 -- Types_Correspond --
4620 ----------------------
4622 function Types_Correspond
4623 (P_Type : Entity_Id;
4624 N_Type : Entity_Id) return Boolean
4626 Prev_Type : Entity_Id := Base_Type (P_Type);
4627 New_Type : Entity_Id := Base_Type (N_Type);
4630 if Ekind (Prev_Type) = E_Anonymous_Access_Type then
4631 Prev_Type := Designated_Type (Prev_Type);
4634 if Ekind (New_Type) = E_Anonymous_Access_Type then
4635 New_Type := Designated_Type (New_Type);
4638 if Prev_Type = New_Type then
4641 elsif not Is_Class_Wide_Type (New_Type) then
4642 while Etype (New_Type) /= New_Type loop
4643 New_Type := Etype (New_Type);
4644 if New_Type = Prev_Type then
4650 end Types_Correspond;
4652 -- Start of processing for Is_Non_Overriding_Operation
4655 -- In the case where both operations are implicit derived subprograms
4656 -- then neither overrides the other. This can only occur in certain
4657 -- obscure cases (e.g., derivation from homographs created in a generic
4660 if Present (Alias (Prev_E)) and then Present (Alias (New_E)) then
4663 elsif Ekind (Current_Scope) = E_Package
4664 and then Is_Generic_Instance (Current_Scope)
4665 and then In_Private_Part (Current_Scope)
4666 and then Comes_From_Source (New_E)
4668 -- We examine the formals and result subtype of the inherited
4669 -- operation, to determine whether their type is derived from (the
4670 -- instance of) a generic type.
4672 Formal := First_Formal (Prev_E);
4674 while Present (Formal) loop
4675 F_Typ := Base_Type (Etype (Formal));
4677 if Ekind (F_Typ) = E_Anonymous_Access_Type then
4678 F_Typ := Designated_Type (F_Typ);
4681 G_Typ := Get_Generic_Parent_Type (F_Typ);
4683 Next_Formal (Formal);
4686 if No (G_Typ) and then Ekind (Prev_E) = E_Function then
4687 G_Typ := Get_Generic_Parent_Type (Base_Type (Etype (Prev_E)));
4694 -- If the generic type is a private type, then the original
4695 -- operation was not overriding in the generic, because there was
4696 -- no primitive operation to override.
4698 if Nkind (Parent (G_Typ)) = N_Formal_Type_Declaration
4699 and then Nkind (Formal_Type_Definition (Parent (G_Typ))) =
4700 N_Formal_Private_Type_Definition
4704 -- The generic parent type is the ancestor of a formal derived
4705 -- type declaration. We need to check whether it has a primitive
4706 -- operation that should be overridden by New_E in the generic.
4710 P_Formal : Entity_Id;
4711 N_Formal : Entity_Id;
4715 Prim_Elt : Elmt_Id := First_Elmt (Primitive_Operations (G_Typ));
4718 while Present (Prim_Elt) loop
4719 P_Prim := Node (Prim_Elt);
4721 if Chars (P_Prim) = Chars (New_E)
4722 and then Ekind (P_Prim) = Ekind (New_E)
4724 P_Formal := First_Formal (P_Prim);
4725 N_Formal := First_Formal (New_E);
4726 while Present (P_Formal) and then Present (N_Formal) loop
4727 P_Typ := Etype (P_Formal);
4728 N_Typ := Etype (N_Formal);
4730 if not Types_Correspond (P_Typ, N_Typ) then
4734 Next_Entity (P_Formal);
4735 Next_Entity (N_Formal);
4738 -- Found a matching primitive operation belonging to the
4739 -- formal ancestor type, so the new subprogram is
4743 and then No (N_Formal)
4744 and then (Ekind (New_E) /= E_Function
4747 (Etype (P_Prim), Etype (New_E)))
4753 Next_Elmt (Prim_Elt);
4756 -- If no match found, then the new subprogram does not
4757 -- override in the generic (nor in the instance).
4765 end Is_Non_Overriding_Operation;
4767 ------------------------------
4768 -- Make_Inequality_Operator --
4769 ------------------------------
4771 -- S is the defining identifier of an equality operator. We build a
4772 -- subprogram declaration with the right signature. This operation is
4773 -- intrinsic, because it is always expanded as the negation of the
4774 -- call to the equality function.
4776 procedure Make_Inequality_Operator (S : Entity_Id) is
4777 Loc : constant Source_Ptr := Sloc (S);
4780 Op_Name : Entity_Id;
4782 FF : constant Entity_Id := First_Formal (S);
4783 NF : constant Entity_Id := Next_Formal (FF);
4786 -- Check that equality was properly defined, ignore call if not
4793 A : constant Entity_Id :=
4794 Make_Defining_Identifier (Sloc (FF),
4795 Chars => Chars (FF));
4797 B : constant Entity_Id :=
4798 Make_Defining_Identifier (Sloc (NF),
4799 Chars => Chars (NF));
4802 Op_Name := Make_Defining_Operator_Symbol (Loc, Name_Op_Ne);
4804 Formals := New_List (
4805 Make_Parameter_Specification (Loc,
4806 Defining_Identifier => A,
4808 New_Reference_To (Etype (First_Formal (S)),
4809 Sloc (Etype (First_Formal (S))))),
4811 Make_Parameter_Specification (Loc,
4812 Defining_Identifier => B,
4814 New_Reference_To (Etype (Next_Formal (First_Formal (S))),
4815 Sloc (Etype (Next_Formal (First_Formal (S)))))));
4818 Make_Subprogram_Declaration (Loc,
4820 Make_Function_Specification (Loc,
4821 Defining_Unit_Name => Op_Name,
4822 Parameter_Specifications => Formals,
4823 Result_Definition =>
4824 New_Reference_To (Standard_Boolean, Loc)));
4826 -- Insert inequality right after equality if it is explicit or after
4827 -- the derived type when implicit. These entities are created only
4828 -- for visibility purposes, and eventually replaced in the course of
4829 -- expansion, so they do not need to be attached to the tree and seen
4830 -- by the back-end. Keeping them internal also avoids spurious
4831 -- freezing problems. The declaration is inserted in the tree for
4832 -- analysis, and removed afterwards. If the equality operator comes
4833 -- from an explicit declaration, attach the inequality immediately
4834 -- after. Else the equality is inherited from a derived type
4835 -- declaration, so insert inequality after that declaration.
4837 if No (Alias (S)) then
4838 Insert_After (Unit_Declaration_Node (S), Decl);
4839 elsif Is_List_Member (Parent (S)) then
4840 Insert_After (Parent (S), Decl);
4842 Insert_After (Parent (Etype (First_Formal (S))), Decl);
4845 Mark_Rewrite_Insertion (Decl);
4846 Set_Is_Intrinsic_Subprogram (Op_Name);
4849 Set_Has_Completion (Op_Name);
4850 Set_Corresponding_Equality (Op_Name, S);
4851 Set_Is_Abstract (Op_Name, Is_Abstract (S));
4853 end Make_Inequality_Operator;
4855 ----------------------
4856 -- May_Need_Actuals --
4857 ----------------------
4859 procedure May_Need_Actuals (Fun : Entity_Id) is
4864 F := First_Formal (Fun);
4867 while Present (F) loop
4868 if No (Default_Value (F)) then
4876 Set_Needs_No_Actuals (Fun, B);
4877 end May_Need_Actuals;
4879 ---------------------
4880 -- Mode_Conformant --
4881 ---------------------
4883 function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
4886 Check_Conformance (New_Id, Old_Id, Mode_Conformant, False, Result);
4888 end Mode_Conformant;
4890 ---------------------------
4891 -- New_Overloaded_Entity --
4892 ---------------------------
4894 procedure New_Overloaded_Entity
4896 Derived_Type : Entity_Id := Empty)
4898 Does_Override : Boolean := False;
4899 -- Set if the current scope has an operation that is type-conformant
4900 -- with S, and becomes hidden by S.
4903 -- Entity that S overrides
4905 Prev_Vis : Entity_Id := Empty;
4906 -- Needs comment ???
4908 Is_Alias_Interface : Boolean := False;
4910 function Is_Private_Declaration (E : Entity_Id) return Boolean;
4911 -- Check that E is declared in the private part of the current package,
4912 -- or in the package body, where it may hide a previous declaration.
4913 -- We can't use In_Private_Part by itself because this flag is also
4914 -- set when freezing entities, so we must examine the place of the
4915 -- declaration in the tree, and recognize wrapper packages as well.
4917 procedure Maybe_Primitive_Operation (Is_Overriding : Boolean := False);
4918 -- If the subprogram being analyzed is a primitive operation of
4919 -- the type of one of its formals, set the corresponding flag.
4921 ----------------------------
4922 -- Is_Private_Declaration --
4923 ----------------------------
4925 function Is_Private_Declaration (E : Entity_Id) return Boolean is
4926 Priv_Decls : List_Id;
4927 Decl : constant Node_Id := Unit_Declaration_Node (E);
4930 if Is_Package_Or_Generic_Package (Current_Scope)
4931 and then In_Private_Part (Current_Scope)
4934 Private_Declarations (
4935 Specification (Unit_Declaration_Node (Current_Scope)));
4937 return In_Package_Body (Current_Scope)
4939 (Is_List_Member (Decl)
4940 and then List_Containing (Decl) = Priv_Decls)
4941 or else (Nkind (Parent (Decl)) = N_Package_Specification
4942 and then not Is_Compilation_Unit (
4943 Defining_Entity (Parent (Decl)))
4944 and then List_Containing (Parent (Parent (Decl)))
4949 end Is_Private_Declaration;
4951 -------------------------------
4952 -- Maybe_Primitive_Operation --
4953 -------------------------------
4955 procedure Maybe_Primitive_Operation (Is_Overriding : Boolean := False) is
4960 function Visible_Part_Type (T : Entity_Id) return Boolean;
4961 -- Returns true if T is declared in the visible part of
4962 -- the current package scope; otherwise returns false.
4963 -- Assumes that T is declared in a package.
4965 procedure Check_Private_Overriding (T : Entity_Id);
4966 -- Checks that if a primitive abstract subprogram of a visible
4967 -- abstract type is declared in a private part, then it must
4968 -- override an abstract subprogram declared in the visible part.
4969 -- Also checks that if a primitive function with a controlling
4970 -- result is declared in a private part, then it must override
4971 -- a function declared in the visible part.
4973 ------------------------------
4974 -- Check_Private_Overriding --
4975 ------------------------------
4977 procedure Check_Private_Overriding (T : Entity_Id) is
4979 if Ekind (Current_Scope) = E_Package
4980 and then In_Private_Part (Current_Scope)
4981 and then Visible_Part_Type (T)
4982 and then not In_Instance
4985 and then Is_Abstract (S)
4986 and then (not Is_Overriding or else not Is_Abstract (E))
4988 if not Is_Interface (T) then
4989 Error_Msg_N ("abstract subprograms must be visible "
4990 & "('R'M 3.9.3(10))!", S);
4992 -- Ada 2005 (AI-251)
4995 Error_Msg_N ("primitive subprograms of interface types "
4996 & "declared in a visible part, must be declared in "
4997 & "the visible part ('R'M 3.9.4)!", S);
5000 elsif Ekind (S) = E_Function
5001 and then Is_Tagged_Type (T)
5002 and then T = Base_Type (Etype (S))
5003 and then not Is_Overriding
5006 ("private function with tagged result must"
5007 & " override visible-part function", S);
5009 ("\move subprogram to the visible part"
5010 & " ('R'M 3.9.3(10))", S);
5013 end Check_Private_Overriding;
5015 -----------------------
5016 -- Visible_Part_Type --
5017 -----------------------
5019 function Visible_Part_Type (T : Entity_Id) return Boolean is
5020 P : constant Node_Id := Unit_Declaration_Node (Scope (T));
5024 -- If the entity is a private type, then it must be
5025 -- declared in a visible part.
5027 if Ekind (T) in Private_Kind then
5031 -- Otherwise, we traverse the visible part looking for its
5032 -- corresponding declaration. We cannot use the declaration
5033 -- node directly because in the private part the entity of a
5034 -- private type is the one in the full view, which does not
5035 -- indicate that it is the completion of something visible.
5037 N := First (Visible_Declarations (Specification (P)));
5038 while Present (N) loop
5039 if Nkind (N) = N_Full_Type_Declaration
5040 and then Present (Defining_Identifier (N))
5041 and then T = Defining_Identifier (N)
5045 elsif (Nkind (N) = N_Private_Type_Declaration
5047 Nkind (N) = N_Private_Extension_Declaration)
5048 and then Present (Defining_Identifier (N))
5049 and then T = Full_View (Defining_Identifier (N))
5058 end Visible_Part_Type;
5060 -- Start of processing for Maybe_Primitive_Operation
5063 if not Comes_From_Source (S) then
5066 -- If the subprogram is at library level, it is not primitive
5069 elsif Current_Scope = Standard_Standard then
5072 elsif (Ekind (Current_Scope) = E_Package
5073 and then not In_Package_Body (Current_Scope))
5074 or else Is_Overriding
5076 -- For function, check return type
5078 if Ekind (S) = E_Function then
5079 B_Typ := Base_Type (Etype (S));
5081 if Scope (B_Typ) = Current_Scope then
5082 Set_Has_Primitive_Operations (B_Typ);
5083 Check_Private_Overriding (B_Typ);
5087 -- For all subprograms, check formals
5089 Formal := First_Formal (S);
5090 while Present (Formal) loop
5091 if Ekind (Etype (Formal)) = E_Anonymous_Access_Type then
5092 F_Typ := Designated_Type (Etype (Formal));
5094 F_Typ := Etype (Formal);
5097 B_Typ := Base_Type (F_Typ);
5099 if Scope (B_Typ) = Current_Scope then
5100 Set_Has_Primitive_Operations (B_Typ);
5101 Check_Private_Overriding (B_Typ);
5104 Next_Formal (Formal);
5107 end Maybe_Primitive_Operation;
5109 -- Start of processing for New_Overloaded_Entity
5112 -- We need to look for an entity that S may override. This must be a
5113 -- homonym in the current scope, so we look for the first homonym of
5114 -- S in the current scope as the starting point for the search.
5116 E := Current_Entity_In_Scope (S);
5118 -- If there is no homonym then this is definitely not overriding
5121 Enter_Overloaded_Entity (S);
5122 Check_Dispatching_Operation (S, Empty);
5123 Maybe_Primitive_Operation;
5125 -- Ada 2005 (AI-397): Subprograms in the context of protected
5126 -- types have their overriding indicators checked in Sem_Ch9.
5128 if Ekind (S) not in Subprogram_Kind
5129 or else Ekind (Scope (S)) /= E_Protected_Type
5131 Check_Overriding_Indicator (S, False);
5134 -- If there is a homonym that is not overloadable, then we have an
5135 -- error, except for the special cases checked explicitly below.
5137 elsif not Is_Overloadable (E) then
5139 -- Check for spurious conflict produced by a subprogram that has the
5140 -- same name as that of the enclosing generic package. The conflict
5141 -- occurs within an instance, between the subprogram and the renaming
5142 -- declaration for the package. After the subprogram, the package
5143 -- renaming declaration becomes hidden.
5145 if Ekind (E) = E_Package
5146 and then Present (Renamed_Object (E))
5147 and then Renamed_Object (E) = Current_Scope
5148 and then Nkind (Parent (Renamed_Object (E))) =
5149 N_Package_Specification
5150 and then Present (Generic_Parent (Parent (Renamed_Object (E))))
5153 Set_Is_Immediately_Visible (E, False);
5154 Enter_Overloaded_Entity (S);
5155 Set_Homonym (S, Homonym (E));
5156 Check_Dispatching_Operation (S, Empty);
5157 Check_Overriding_Indicator (S, False);
5159 -- If the subprogram is implicit it is hidden by the previous
5160 -- declaration. However if it is dispatching, it must appear in the
5161 -- dispatch table anyway, because it can be dispatched to even if it
5162 -- cannot be called directly.
5164 elsif Present (Alias (S))
5165 and then not Comes_From_Source (S)
5167 Set_Scope (S, Current_Scope);
5169 if Is_Dispatching_Operation (Alias (S)) then
5170 Check_Dispatching_Operation (S, Empty);
5176 Error_Msg_Sloc := Sloc (E);
5177 Error_Msg_N ("& conflicts with declaration#", S);
5179 -- Useful additional warning
5181 if Is_Generic_Unit (E) then
5182 Error_Msg_N ("\previous generic unit cannot be overloaded", S);
5188 -- E exists and is overloadable
5191 Is_Alias_Interface :=
5193 and then Is_Dispatching_Operation (Alias (S))
5194 and then Present (DTC_Entity (Alias (S)))
5195 and then Is_Interface (Scope (DTC_Entity (Alias (S))));
5197 -- Loop through E and its homonyms to determine if any of them is
5198 -- the candidate for overriding by S.
5200 while Present (E) loop
5202 -- Definitely not interesting if not in the current scope
5204 if Scope (E) /= Current_Scope then
5207 -- Check if we have type conformance
5209 -- Ada 2005 (AI-251): In case of overriding an interface
5210 -- subprogram it is not an error that the old and new entities
5211 -- have the same profile, and hence we skip this code.
5213 elsif not Is_Alias_Interface
5214 and then Type_Conformant (E, S)
5216 -- Ada 2005 (AI-251): Do not consider here entities that cover
5217 -- abstract interface primitives. They will be handled after
5218 -- the overriden entity is found (see comments bellow inside
5219 -- this subprogram).
5221 and then not (Is_Subprogram (E)
5222 and then Present (Abstract_Interface_Alias (E)))
5224 -- If the old and new entities have the same profile and one
5225 -- is not the body of the other, then this is an error, unless
5226 -- one of them is implicitly declared.
5228 -- There are some cases when both can be implicit, for example
5229 -- when both a literal and a function that overrides it are
5230 -- inherited in a derivation, or when an inhertited operation
5231 -- of a tagged full type overrides the ineherited operation of
5232 -- a private extension. Ada 83 had a special rule for the the
5233 -- literal case. In Ada95, the later implicit operation hides
5234 -- the former, and the literal is always the former. In the
5235 -- odd case where both are derived operations declared at the
5236 -- same point, both operations should be declared, and in that
5237 -- case we bypass the following test and proceed to the next
5238 -- part (this can only occur for certain obscure cases
5239 -- involving homographs in instances and can't occur for
5240 -- dispatching operations ???). Note that the following
5241 -- condition is less than clear. For example, it's not at all
5242 -- clear why there's a test for E_Entry here. ???
5244 if Present (Alias (S))
5245 and then (No (Alias (E))
5246 or else Comes_From_Source (E)
5247 or else Is_Dispatching_Operation (E))
5249 (Ekind (E) = E_Entry
5250 or else Ekind (E) /= E_Enumeration_Literal)
5252 -- When an derived operation is overloaded it may be due to
5253 -- the fact that the full view of a private extension
5254 -- re-inherits. It has to be dealt with.
5256 if Is_Package_Or_Generic_Package (Current_Scope)
5257 and then In_Private_Part (Current_Scope)
5259 Check_Operation_From_Private_View (S, E);
5262 -- In any case the implicit operation remains hidden by
5263 -- the existing declaration, which is overriding.
5265 Set_Is_Overriding_Operation (E);
5267 if Comes_From_Source (E) then
5268 Check_Overriding_Indicator (E, True);
5270 -- Indicate that E overrides the operation from which
5273 if Present (Alias (S)) then
5274 Set_Overridden_Operation (E, Alias (S));
5276 Set_Overridden_Operation (E, S);
5282 -- Within an instance, the renaming declarations for
5283 -- actual subprograms may become ambiguous, but they do
5284 -- not hide each other.
5286 elsif Ekind (E) /= E_Entry
5287 and then not Comes_From_Source (E)
5288 and then not Is_Generic_Instance (E)
5289 and then (Present (Alias (E))
5290 or else Is_Intrinsic_Subprogram (E))
5291 and then (not In_Instance
5292 or else No (Parent (E))
5293 or else Nkind (Unit_Declaration_Node (E)) /=
5294 N_Subprogram_Renaming_Declaration)
5296 -- A subprogram child unit is not allowed to override
5297 -- an inherited subprogram (10.1.1(20)).
5299 if Is_Child_Unit (S) then
5301 ("child unit overrides inherited subprogram in parent",
5306 if Is_Non_Overriding_Operation (E, S) then
5307 Enter_Overloaded_Entity (S);
5308 if No (Derived_Type)
5309 or else Is_Tagged_Type (Derived_Type)
5311 Check_Dispatching_Operation (S, Empty);
5317 -- E is a derived operation or an internal operator which
5318 -- is being overridden. Remove E from further visibility.
5319 -- Furthermore, if E is a dispatching operation, it must be
5320 -- replaced in the list of primitive operations of its type
5321 -- (see Override_Dispatching_Operation).
5323 Does_Override := True;
5329 Prev := First_Entity (Current_Scope);
5331 while Present (Prev)
5332 and then Next_Entity (Prev) /= E
5337 -- It is possible for E to be in the current scope and
5338 -- yet not in the entity chain. This can only occur in a
5339 -- generic context where E is an implicit concatenation
5340 -- in the formal part, because in a generic body the
5341 -- entity chain starts with the formals.
5344 (Present (Prev) or else Chars (E) = Name_Op_Concat);
5346 -- E must be removed both from the entity_list of the
5347 -- current scope, and from the visibility chain
5349 if Debug_Flag_E then
5350 Write_Str ("Override implicit operation ");
5351 Write_Int (Int (E));
5355 -- If E is a predefined concatenation, it stands for four
5356 -- different operations. As a result, a single explicit
5357 -- declaration does not hide it. In a possible ambiguous
5358 -- situation, Disambiguate chooses the user-defined op,
5359 -- so it is correct to retain the previous internal one.
5361 if Chars (E) /= Name_Op_Concat
5362 or else Ekind (E) /= E_Operator
5364 -- For nondispatching derived operations that are
5365 -- overridden by a subprogram declared in the private
5366 -- part of a package, we retain the derived
5367 -- subprogram but mark it as not immediately visible.
5368 -- If the derived operation was declared in the
5369 -- visible part then this ensures that it will still
5370 -- be visible outside the package with the proper
5371 -- signature (calls from outside must also be
5372 -- directed to this version rather than the
5373 -- overriding one, unlike the dispatching case).
5374 -- Calls from inside the package will still resolve
5375 -- to the overriding subprogram since the derived one
5376 -- is marked as not visible within the package.
5378 -- If the private operation is dispatching, we achieve
5379 -- the overriding by keeping the implicit operation
5380 -- but setting its alias to be the overriding one. In
5381 -- this fashion the proper body is executed in all
5382 -- cases, but the original signature is used outside
5385 -- If the overriding is not in the private part, we
5386 -- remove the implicit operation altogether.
5388 if Is_Private_Declaration (S) then
5390 if not Is_Dispatching_Operation (E) then
5391 Set_Is_Immediately_Visible (E, False);
5393 -- Work done in Override_Dispatching_Operation,
5394 -- so nothing else need to be done here.
5400 -- Find predecessor of E in Homonym chain
5402 if E = Current_Entity (E) then
5405 Prev_Vis := Current_Entity (E);
5406 while Homonym (Prev_Vis) /= E loop
5407 Prev_Vis := Homonym (Prev_Vis);
5411 if Prev_Vis /= Empty then
5413 -- Skip E in the visibility chain
5415 Set_Homonym (Prev_Vis, Homonym (E));
5418 Set_Name_Entity_Id (Chars (E), Homonym (E));
5421 Set_Next_Entity (Prev, Next_Entity (E));
5423 if No (Next_Entity (Prev)) then
5424 Set_Last_Entity (Current_Scope, Prev);
5430 Enter_Overloaded_Entity (S);
5431 Set_Is_Overriding_Operation (S);
5432 Check_Overriding_Indicator (S, True);
5434 -- Indicate that S overrides the operation from which
5437 if Comes_From_Source (S) then
5438 if Present (Alias (E)) then
5439 Set_Overridden_Operation (S, Alias (E));
5441 Set_Overridden_Operation (S, E);
5445 if Is_Dispatching_Operation (E) then
5447 -- An overriding dispatching subprogram inherits the
5448 -- convention of the overridden subprogram (by
5451 Set_Convention (S, Convention (E));
5453 -- AI-251: For an entity overriding an interface
5454 -- primitive check if the entity also covers other
5455 -- abstract subprograms in the same scope. This is
5456 -- required to handle the general case, that is,
5457 -- 1) overriding other interface primitives, and
5458 -- 2) overriding abstract subprograms inherited from
5459 -- some abstract ancestor type.
5462 and then Present (Alias (E))
5463 and then Ekind (Alias (E)) /= E_Operator
5464 and then Present (DTC_Entity (Alias (E)))
5465 and then Is_Interface (Scope (DTC_Entity
5473 while Present (E1) loop
5474 if (Is_Overloadable (E1)
5475 or else Ekind (E1) = E_Subprogram_Type)
5476 and then Present (Alias (E1))
5477 and then Ekind (Alias (E1)) /= E_Operator
5478 and then Present (DTC_Entity (Alias (E1)))
5479 and then Is_Abstract
5480 (Scope (DTC_Entity (Alias (E1))))
5481 and then Type_Conformant (E1, S)
5483 Check_Dispatching_Operation (S, E1);
5491 Check_Dispatching_Operation (S, E);
5493 -- AI-251: Handle the case in which the entity
5494 -- overrides a primitive operation that covered
5495 -- several abstract interface primitives.
5500 E1 := Current_Entity_In_Scope (S);
5501 while Present (E1) loop
5502 if Is_Subprogram (E1)
5504 (Abstract_Interface_Alias (E1))
5505 and then Alias (E1) = E
5515 Check_Dispatching_Operation (S, Empty);
5518 Maybe_Primitive_Operation (Is_Overriding => True);
5519 goto Check_Inequality;
5522 -- Apparent redeclarations in instances can occur when two
5523 -- formal types get the same actual type. The subprograms in
5524 -- in the instance are legal, even if not callable from the
5525 -- outside. Calls from within are disambiguated elsewhere.
5526 -- For dispatching operations in the visible part, the usual
5527 -- rules apply, and operations with the same profile are not
5530 elsif (In_Instance_Visible_Part
5531 and then not Is_Dispatching_Operation (E))
5532 or else In_Instance_Not_Visible
5536 -- Here we have a real error (identical profile)
5539 Error_Msg_Sloc := Sloc (E);
5541 -- Avoid cascaded errors if the entity appears in
5542 -- subsequent calls.
5544 Set_Scope (S, Current_Scope);
5546 Error_Msg_N ("& conflicts with declaration#", S);
5548 if Is_Generic_Instance (S)
5549 and then not Has_Completion (E)
5552 ("\instantiation cannot provide body for it", S);
5559 -- If one subprogram has an access parameter and the other
5560 -- a parameter of an access type, calls to either might be
5561 -- ambiguous. Verify that parameters match except for the
5562 -- access parameter.
5564 if May_Hide_Profile then
5569 F1 := First_Formal (S);
5570 F2 := First_Formal (E);
5571 while Present (F1) and then Present (F2) loop
5572 if Is_Access_Type (Etype (F1)) then
5573 if not Is_Access_Type (Etype (F2))
5574 or else not Conforming_Types
5575 (Designated_Type (Etype (F1)),
5576 Designated_Type (Etype (F2)),
5579 May_Hide_Profile := False;
5583 not Conforming_Types
5584 (Etype (F1), Etype (F2), Type_Conformant)
5586 May_Hide_Profile := False;
5597 Error_Msg_NE ("calls to& may be ambiguous?", S, S);
5607 -- On exit, we know that S is a new entity
5609 Enter_Overloaded_Entity (S);
5610 Maybe_Primitive_Operation;
5611 Check_Overriding_Indicator (S, Does_Override);
5613 -- If S is a derived operation for an untagged type then by
5614 -- definition it's not a dispatching operation (even if the parent
5615 -- operation was dispatching), so we don't call
5616 -- Check_Dispatching_Operation in that case.
5618 if No (Derived_Type)
5619 or else Is_Tagged_Type (Derived_Type)
5621 Check_Dispatching_Operation (S, Empty);
5625 -- If this is a user-defined equality operator that is not a derived
5626 -- subprogram, create the corresponding inequality. If the operation is
5627 -- dispatching, the expansion is done elsewhere, and we do not create
5628 -- an explicit inequality operation.
5630 <<Check_Inequality>>
5631 if Chars (S) = Name_Op_Eq
5632 and then Etype (S) = Standard_Boolean
5633 and then Present (Parent (S))
5634 and then not Is_Dispatching_Operation (S)
5636 Make_Inequality_Operator (S);
5638 end New_Overloaded_Entity;
5640 ---------------------
5641 -- Process_Formals --
5642 ---------------------
5644 procedure Process_Formals
5646 Related_Nod : Node_Id)
5648 Param_Spec : Node_Id;
5650 Formal_Type : Entity_Id;
5654 function Is_Class_Wide_Default (D : Node_Id) return Boolean;
5655 -- Check whether the default has a class-wide type. After analysis the
5656 -- default has the type of the formal, so we must also check explicitly
5657 -- for an access attribute.
5659 ---------------------------
5660 -- Is_Class_Wide_Default --
5661 ---------------------------
5663 function Is_Class_Wide_Default (D : Node_Id) return Boolean is
5665 return Is_Class_Wide_Type (Designated_Type (Etype (D)))
5666 or else (Nkind (D) = N_Attribute_Reference
5667 and then Attribute_Name (D) = Name_Access
5668 and then Is_Class_Wide_Type (Etype (Prefix (D))));
5669 end Is_Class_Wide_Default;
5671 -- Start of processing for Process_Formals
5674 -- In order to prevent premature use of the formals in the same formal
5675 -- part, the Ekind is left undefined until all default expressions are
5676 -- analyzed. The Ekind is established in a separate loop at the end.
5678 Param_Spec := First (T);
5680 while Present (Param_Spec) loop
5682 Formal := Defining_Identifier (Param_Spec);
5683 Enter_Name (Formal);
5685 -- Case of ordinary parameters
5687 if Nkind (Parameter_Type (Param_Spec)) /= N_Access_Definition then
5688 Find_Type (Parameter_Type (Param_Spec));
5689 Ptype := Parameter_Type (Param_Spec);
5691 if Ptype = Error then
5695 Formal_Type := Entity (Ptype);
5697 if Ekind (Formal_Type) = E_Incomplete_Type
5698 or else (Is_Class_Wide_Type (Formal_Type)
5699 and then Ekind (Root_Type (Formal_Type)) =
5702 -- Ada 2005 (AI-326): Tagged incomplete types allowed
5704 if Is_Tagged_Type (Formal_Type) then
5707 elsif Nkind (Parent (T)) /= N_Access_Function_Definition
5708 and then Nkind (Parent (T)) /= N_Access_Procedure_Definition
5710 Error_Msg_N ("invalid use of incomplete type", Param_Spec);
5713 elsif Ekind (Formal_Type) = E_Void then
5714 Error_Msg_NE ("premature use of&",
5715 Parameter_Type (Param_Spec), Formal_Type);
5718 -- Ada 2005 (AI-231): Create and decorate an internal subtype
5719 -- declaration corresponding to the null-excluding type of the
5720 -- formal in the enclosing scope. Finally, replace the parameter
5721 -- type of the formal with the internal subtype.
5723 if Ada_Version >= Ada_05
5724 and then Is_Access_Type (Formal_Type)
5725 and then Null_Exclusion_Present (Param_Spec)
5727 if Can_Never_Be_Null (Formal_Type)
5728 and then Comes_From_Source (Related_Nod)
5731 ("null exclusion must apply to a type that does not "
5732 & "exclude null ('R'M 3.10 (14)", Related_Nod);
5736 Create_Null_Excluding_Itype
5738 Related_Nod => Related_Nod,
5739 Scope_Id => Scope (Current_Scope));
5742 -- An access formal type
5746 Access_Definition (Related_Nod, Parameter_Type (Param_Spec));
5748 -- Ada 2005 (AI-254)
5751 AD : constant Node_Id :=
5752 Access_To_Subprogram_Definition
5753 (Parameter_Type (Param_Spec));
5755 if Present (AD) and then Protected_Present (AD) then
5757 Replace_Anonymous_Access_To_Protected_Subprogram
5758 (Param_Spec, Formal_Type);
5763 Set_Etype (Formal, Formal_Type);
5764 Default := Expression (Param_Spec);
5766 if Present (Default) then
5767 if Out_Present (Param_Spec) then
5769 ("default initialization only allowed for IN parameters",
5773 -- Do the special preanalysis of the expression (see section on
5774 -- "Handling of Default Expressions" in the spec of package Sem).
5776 Analyze_Per_Use_Expression (Default, Formal_Type);
5778 -- Check that the designated type of an access parameter's default
5779 -- is not a class-wide type unless the parameter's designated type
5780 -- is also class-wide.
5782 if Ekind (Formal_Type) = E_Anonymous_Access_Type
5783 and then not From_With_Type (Formal_Type)
5784 and then Is_Class_Wide_Default (Default)
5785 and then not Is_Class_Wide_Type (Designated_Type (Formal_Type))
5788 ("access to class-wide expression not allowed here", Default);
5792 -- Ada 2005 (AI-231): Static checks
5794 if Ada_Version >= Ada_05
5795 and then Is_Access_Type (Etype (Formal))
5796 and then Can_Never_Be_Null (Etype (Formal))
5798 Null_Exclusion_Static_Checks (Param_Spec);
5805 -- If this is the formal part of a function specification, analyze the
5806 -- subtype mark in the context where the formals are visible but not
5807 -- yet usable, and may hide outer homographs.
5809 if Nkind (Related_Nod) = N_Function_Specification then
5810 Analyze_Return_Type (Related_Nod);
5813 -- Now set the kind (mode) of each formal
5815 Param_Spec := First (T);
5817 while Present (Param_Spec) loop
5818 Formal := Defining_Identifier (Param_Spec);
5819 Set_Formal_Mode (Formal);
5821 if Ekind (Formal) = E_In_Parameter then
5822 Set_Default_Value (Formal, Expression (Param_Spec));
5824 if Present (Expression (Param_Spec)) then
5825 Default := Expression (Param_Spec);
5827 if Is_Scalar_Type (Etype (Default)) then
5829 (Parameter_Type (Param_Spec)) /= N_Access_Definition
5831 Formal_Type := Entity (Parameter_Type (Param_Spec));
5834 Formal_Type := Access_Definition
5835 (Related_Nod, Parameter_Type (Param_Spec));
5838 Apply_Scalar_Range_Check (Default, Formal_Type);
5846 end Process_Formals;
5848 ----------------------------
5849 -- Reference_Body_Formals --
5850 ----------------------------
5852 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id) is
5857 if Error_Posted (Spec) then
5861 Fs := First_Formal (Spec);
5862 Fb := First_Formal (Bod);
5864 while Present (Fs) loop
5865 Generate_Reference (Fs, Fb, 'b');
5868 Style.Check_Identifier (Fb, Fs);
5871 Set_Spec_Entity (Fb, Fs);
5872 Set_Referenced (Fs, False);
5876 end Reference_Body_Formals;
5878 -------------------------
5879 -- Set_Actual_Subtypes --
5880 -------------------------
5882 procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id) is
5883 Loc : constant Source_Ptr := Sloc (N);
5887 First_Stmt : Node_Id := Empty;
5888 AS_Needed : Boolean;
5891 -- If this is an emtpy initialization procedure, no need to create
5892 -- actual subtypes (small optimization).
5894 if Ekind (Subp) = E_Procedure
5895 and then Is_Null_Init_Proc (Subp)
5900 Formal := First_Formal (Subp);
5901 while Present (Formal) loop
5902 T := Etype (Formal);
5904 -- We never need an actual subtype for a constrained formal
5906 if Is_Constrained (T) then
5909 -- If we have unknown discriminants, then we do not need an actual
5910 -- subtype, or more accurately we cannot figure it out! Note that
5911 -- all class-wide types have unknown discriminants.
5913 elsif Has_Unknown_Discriminants (T) then
5916 -- At this stage we have an unconstrained type that may need an
5917 -- actual subtype. For sure the actual subtype is needed if we have
5918 -- an unconstrained array type.
5920 elsif Is_Array_Type (T) then
5923 -- The only other case needing an actual subtype is an unconstrained
5924 -- record type which is an IN parameter (we cannot generate actual
5925 -- subtypes for the OUT or IN OUT case, since an assignment can
5926 -- change the discriminant values. However we exclude the case of
5927 -- initialization procedures, since discriminants are handled very
5928 -- specially in this context, see the section entitled "Handling of
5929 -- Discriminants" in Einfo.
5931 -- We also exclude the case of Discrim_SO_Functions (functions used
5932 -- in front end layout mode for size/offset values), since in such
5933 -- functions only discriminants are referenced, and not only are such
5934 -- subtypes not needed, but they cannot always be generated, because
5935 -- of order of elaboration issues.
5937 elsif Is_Record_Type (T)
5938 and then Ekind (Formal) = E_In_Parameter
5939 and then Chars (Formal) /= Name_uInit
5940 and then not Is_Unchecked_Union (T)
5941 and then not Is_Discrim_SO_Function (Subp)
5945 -- All other cases do not need an actual subtype
5951 -- Generate actual subtypes for unconstrained arrays and
5952 -- unconstrained discriminated records.
5955 if Nkind (N) = N_Accept_Statement then
5957 -- If expansion is active, The formal is replaced by a local
5958 -- variable that renames the corresponding entry of the
5959 -- parameter block, and it is this local variable that may
5960 -- require an actual subtype.
5962 if Expander_Active then
5963 Decl := Build_Actual_Subtype (T, Renamed_Object (Formal));
5965 Decl := Build_Actual_Subtype (T, Formal);
5968 if Present (Handled_Statement_Sequence (N)) then
5970 First (Statements (Handled_Statement_Sequence (N)));
5971 Prepend (Decl, Statements (Handled_Statement_Sequence (N)));
5972 Mark_Rewrite_Insertion (Decl);
5974 -- If the accept statement has no body, there will be no
5975 -- reference to the actuals, so no need to compute actual
5982 Decl := Build_Actual_Subtype (T, Formal);
5983 Prepend (Decl, Declarations (N));
5984 Mark_Rewrite_Insertion (Decl);
5987 -- The declaration uses the bounds of an existing object, and
5988 -- therefore needs no constraint checks.
5990 Analyze (Decl, Suppress => All_Checks);
5992 -- We need to freeze manually the generated type when it is
5993 -- inserted anywhere else than in a declarative part.
5995 if Present (First_Stmt) then
5996 Insert_List_Before_And_Analyze (First_Stmt,
5997 Freeze_Entity (Defining_Identifier (Decl), Loc));
6000 if Nkind (N) = N_Accept_Statement
6001 and then Expander_Active
6003 Set_Actual_Subtype (Renamed_Object (Formal),
6004 Defining_Identifier (Decl));
6006 Set_Actual_Subtype (Formal, Defining_Identifier (Decl));
6010 Next_Formal (Formal);
6012 end Set_Actual_Subtypes;
6014 ---------------------
6015 -- Set_Formal_Mode --
6016 ---------------------
6018 procedure Set_Formal_Mode (Formal_Id : Entity_Id) is
6019 Spec : constant Node_Id := Parent (Formal_Id);
6022 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
6023 -- since we ensure that corresponding actuals are always valid at the
6024 -- point of the call.
6026 if Out_Present (Spec) then
6027 if Ekind (Scope (Formal_Id)) = E_Function
6028 or else Ekind (Scope (Formal_Id)) = E_Generic_Function
6030 Error_Msg_N ("functions can only have IN parameters", Spec);
6031 Set_Ekind (Formal_Id, E_In_Parameter);
6033 elsif In_Present (Spec) then
6034 Set_Ekind (Formal_Id, E_In_Out_Parameter);
6037 Set_Ekind (Formal_Id, E_Out_Parameter);
6038 Set_Never_Set_In_Source (Formal_Id, True);
6039 Set_Is_True_Constant (Formal_Id, False);
6040 Set_Current_Value (Formal_Id, Empty);
6044 Set_Ekind (Formal_Id, E_In_Parameter);
6047 -- Set Is_Known_Non_Null for access parameters since the language
6048 -- guarantees that access parameters are always non-null. We also set
6049 -- Can_Never_Be_Null, since there is no way to change the value.
6051 if Nkind (Parameter_Type (Spec)) = N_Access_Definition then
6053 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
6054 -- null; In Ada 2005, only if then null_exclusion is explicit.
6056 if Ada_Version < Ada_05
6057 or else Can_Never_Be_Null (Etype (Formal_Id))
6059 Set_Is_Known_Non_Null (Formal_Id);
6060 Set_Can_Never_Be_Null (Formal_Id);
6063 -- Ada 2005 (AI-231): Null-exclusion access subtype
6065 elsif Is_Access_Type (Etype (Formal_Id))
6066 and then Can_Never_Be_Null (Etype (Formal_Id))
6068 Set_Is_Known_Non_Null (Formal_Id);
6071 Set_Mechanism (Formal_Id, Default_Mechanism);
6072 Set_Formal_Validity (Formal_Id);
6073 end Set_Formal_Mode;
6075 -------------------------
6076 -- Set_Formal_Validity --
6077 -------------------------
6079 procedure Set_Formal_Validity (Formal_Id : Entity_Id) is
6081 -- If no validity checking, then we cannot assume anything about the
6082 -- validity of parameters, since we do not know there is any checking
6083 -- of the validity on the call side.
6085 if not Validity_Checks_On then
6088 -- If validity checking for parameters is enabled, this means we are
6089 -- not supposed to make any assumptions about argument values.
6091 elsif Validity_Check_Parameters then
6094 -- If we are checking in parameters, we will assume that the caller is
6095 -- also checking parameters, so we can assume the parameter is valid.
6097 elsif Ekind (Formal_Id) = E_In_Parameter
6098 and then Validity_Check_In_Params
6100 Set_Is_Known_Valid (Formal_Id, True);
6102 -- Similar treatment for IN OUT parameters
6104 elsif Ekind (Formal_Id) = E_In_Out_Parameter
6105 and then Validity_Check_In_Out_Params
6107 Set_Is_Known_Valid (Formal_Id, True);
6109 end Set_Formal_Validity;
6111 ------------------------
6112 -- Subtype_Conformant --
6113 ------------------------
6115 function Subtype_Conformant (New_Id, Old_Id : Entity_Id) return Boolean is
6118 Check_Conformance (New_Id, Old_Id, Subtype_Conformant, False, Result);
6120 end Subtype_Conformant;
6122 ---------------------
6123 -- Type_Conformant --
6124 ---------------------
6126 function Type_Conformant
6127 (New_Id : Entity_Id;
6129 Skip_Controlling_Formals : Boolean := False) return Boolean
6133 May_Hide_Profile := False;
6136 (New_Id, Old_Id, Type_Conformant, False, Result,
6137 Skip_Controlling_Formals => Skip_Controlling_Formals);
6139 end Type_Conformant;
6141 -------------------------------
6142 -- Valid_Operator_Definition --
6143 -------------------------------
6145 procedure Valid_Operator_Definition (Designator : Entity_Id) is
6148 Id : constant Name_Id := Chars (Designator);
6152 F := First_Formal (Designator);
6153 while Present (F) loop
6156 if Present (Default_Value (F)) then
6158 ("default values not allowed for operator parameters",
6165 -- Verify that user-defined operators have proper number of arguments
6166 -- First case of operators which can only be unary
6169 or else Id = Name_Op_Abs
6173 -- Case of operators which can be unary or binary
6175 elsif Id = Name_Op_Add
6176 or Id = Name_Op_Subtract
6178 N_OK := (N in 1 .. 2);
6180 -- All other operators can only be binary
6188 ("incorrect number of arguments for operator", Designator);
6192 and then Base_Type (Etype (Designator)) = Standard_Boolean
6193 and then not Is_Intrinsic_Subprogram (Designator)
6196 ("explicit definition of inequality not allowed", Designator);
6198 end Valid_Operator_Definition;