1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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 -----------------------
81 -- Local Subprograms --
82 -----------------------
84 procedure Analyze_Return_Type
(N
: Node_Id
);
85 -- Subsidiary to Process_Formals: analyze subtype mark in function
86 -- specification, in a context where the formals are visible and hide
89 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
90 -- Analyze a generic subprogram body. N is the body to be analyzed, and
91 -- Gen_Id is the defining entity Id for the corresponding spec.
93 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
);
94 -- If a subprogram has pragma Inline and inlining is active, use generic
95 -- machinery to build an unexpanded body for the subprogram. This body is
96 -- subsequenty used for inline expansions at call sites. If subprogram can
97 -- be inlined (depending on size and nature of local declarations) this
98 -- function returns true. Otherwise subprogram body is treated normally.
99 -- If proper warnings are enabled and the subprogram contains a construct
100 -- that cannot be inlined, the offending construct is flagged accordingly.
102 type Conformance_Type
is
103 (Type_Conformant
, Mode_Conformant
, Subtype_Conformant
, Fully_Conformant
);
104 -- Conformance type used for following call, meaning matches the
105 -- RM definitions of the corresponding terms.
107 procedure Check_Conformance
110 Ctype
: Conformance_Type
;
112 Conforms
: out Boolean;
113 Err_Loc
: Node_Id
:= Empty
;
114 Get_Inst
: Boolean := False;
115 Skip_Controlling_Formals
: Boolean := False);
116 -- Given two entities, this procedure checks that the profiles associated
117 -- with these entities meet the conformance criterion given by the third
118 -- parameter. If they conform, Conforms is set True and control returns
119 -- to the caller. If they do not conform, Conforms is set to False, and
120 -- in addition, if Errmsg is True on the call, proper messages are output
121 -- to complain about the conformance failure. If Err_Loc is non_Empty
122 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
123 -- error messages are placed on the appropriate part of the construct
124 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
125 -- against a formal access-to-subprogram type so Get_Instance_Of must
128 procedure Check_Overriding_Indicator
130 Does_Override
: Boolean);
131 -- Verify the consistency of an overriding_indicator given for subprogram
132 -- declaration, body, renaming, or instantiation. The flag Does_Override
133 -- is set if the scope into which we are introducing the subprogram
134 -- contains a type-conformant subprogram that becomes hidden by the new
137 procedure Check_Subprogram_Order
(N
: Node_Id
);
138 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
139 -- the alpha ordering rule for N if this ordering requirement applicable.
141 procedure Check_Returns
145 -- Called to check for missing return statements in a function body, or
146 -- for returns present in a procedure body which has No_Return set. L is
147 -- the handled statement sequence for the subprogram body. This procedure
148 -- checks all flow paths to make sure they either have return (Mode = 'F')
149 -- or do not have a return (Mode = 'P'). The flag Err is set if there are
150 -- any control paths not explicitly terminated by a return in the function
151 -- case, and is True otherwise.
153 function Conforming_Types
156 Ctype
: Conformance_Type
;
157 Get_Inst
: Boolean := False) return Boolean;
158 -- Check that two formal parameter types conform, checking both for
159 -- equality of base types, and where required statically matching
160 -- subtypes, depending on the setting of Ctype.
162 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
163 -- This procedure makes S, a new overloaded entity, into the first visible
164 -- entity with that name.
166 procedure Install_Entity
(E
: Entity_Id
);
167 -- Make single entity visible. Used for generic formals as well
169 procedure Install_Formals
(Id
: Entity_Id
);
170 -- On entry to a subprogram body, make the formals visible. Note that
171 -- simply placing the subprogram on the scope stack is not sufficient:
172 -- the formals must become the current entities for their names.
174 function Is_Non_Overriding_Operation
176 New_E
: Entity_Id
) return Boolean;
177 -- Enforce the rule given in 12.3(18): a private operation in an instance
178 -- overrides an inherited operation only if the corresponding operation
179 -- was overriding in the generic. This can happen for primitive operations
180 -- of types derived (in the generic unit) from formal private or formal
183 procedure Make_Inequality_Operator
(S
: Entity_Id
);
184 -- Create the declaration for an inequality operator that is implicitly
185 -- created by a user-defined equality operator that yields a boolean.
187 procedure May_Need_Actuals
(Fun
: Entity_Id
);
188 -- Flag functions that can be called without parameters, i.e. those that
189 -- have no parameters, or those for which defaults exist for all parameters
191 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
);
192 -- If there is a separate spec for a subprogram or generic subprogram, the
193 -- formals of the body are treated as references to the corresponding
194 -- formals of the spec. This reference does not count as an actual use of
195 -- the formal, in order to diagnose formals that are unused in the body.
197 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
198 -- Formal_Id is an formal parameter entity. This procedure deals with
199 -- setting the proper validity status for this entity, which depends
200 -- on the kind of parameter and the validity checking mode.
202 ---------------------------------------------
203 -- Analyze_Abstract_Subprogram_Declaration --
204 ---------------------------------------------
206 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
207 Designator
: constant Entity_Id
:=
208 Analyze_Subprogram_Specification
(Specification
(N
));
209 Scop
: constant Entity_Id
:= Current_Scope
;
212 Generate_Definition
(Designator
);
213 Set_Is_Abstract
(Designator
);
214 New_Overloaded_Entity
(Designator
);
215 Check_Delayed_Subprogram
(Designator
);
217 Set_Categorization_From_Scope
(Designator
, Scop
);
219 if Ekind
(Scope
(Designator
)) = E_Protected_Type
then
221 ("abstract subprogram not allowed in protected type", N
);
224 Generate_Reference_To_Formals
(Designator
);
225 end Analyze_Abstract_Subprogram_Declaration
;
227 ----------------------------
228 -- Analyze_Function_Call --
229 ----------------------------
231 procedure Analyze_Function_Call
(N
: Node_Id
) is
232 P
: constant Node_Id
:= Name
(N
);
233 L
: constant List_Id
:= Parameter_Associations
(N
);
239 -- A call of the form A.B (X) may be an Ada05 call, which is rewritten
240 -- as B (A, X). If the rewriting is successful, the call has been
241 -- analyzed and we just return.
243 if Nkind
(P
) = N_Selected_Component
244 and then Name
(N
) /= P
245 and then Is_Rewrite_Substitution
(N
)
246 and then Present
(Etype
(N
))
251 -- If error analyzing name, then set Any_Type as result type and return
253 if Etype
(P
) = Any_Type
then
254 Set_Etype
(N
, Any_Type
);
258 -- Otherwise analyze the parameters
262 while Present
(Actual
) loop
264 Check_Parameterless_Call
(Actual
);
270 end Analyze_Function_Call
;
272 -------------------------------------
273 -- Analyze_Generic_Subprogram_Body --
274 -------------------------------------
276 procedure Analyze_Generic_Subprogram_Body
280 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
281 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
287 -- Copy body and disable expansion while analyzing the generic For a
288 -- stub, do not copy the stub (which would load the proper body), this
289 -- will be done when the proper body is analyzed.
291 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
292 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
297 Spec
:= Specification
(N
);
299 -- Within the body of the generic, the subprogram is callable, and
300 -- behaves like the corresponding non-generic unit.
302 Body_Id
:= Defining_Entity
(Spec
);
304 if Kind
= E_Generic_Procedure
305 and then Nkind
(Spec
) /= N_Procedure_Specification
307 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
310 elsif Kind
= E_Generic_Function
311 and then Nkind
(Spec
) /= N_Function_Specification
313 Error_Msg_N
("invalid body for generic function ", Body_Id
);
317 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
319 if Has_Completion
(Gen_Id
)
320 and then Nkind
(Parent
(N
)) /= N_Subunit
322 Error_Msg_N
("duplicate generic body", N
);
325 Set_Has_Completion
(Gen_Id
);
328 if Nkind
(N
) = N_Subprogram_Body_Stub
then
329 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
331 Set_Corresponding_Spec
(N
, Gen_Id
);
334 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
335 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
338 -- Make generic parameters immediately visible in the body. They are
339 -- needed to process the formals declarations. Then make the formals
340 -- visible in a separate step.
346 First_Ent
: Entity_Id
;
349 First_Ent
:= First_Entity
(Gen_Id
);
352 while Present
(E
) and then not Is_Formal
(E
) loop
357 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
359 -- Now generic formals are visible, and the specification can be
360 -- analyzed, for subsequent conformance check.
362 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
364 -- Make formal parameters visible
368 -- E is the first formal parameter, we loop through the formals
369 -- installing them so that they will be visible.
371 Set_First_Entity
(Gen_Id
, E
);
372 while Present
(E
) loop
378 -- Visible generic entity is callable within its own body
380 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
381 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
382 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
383 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
384 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
386 if Nkind
(N
) = N_Subprogram_Body_Stub
then
388 -- No body to analyze, so restore state of generic unit
390 Set_Ekind
(Gen_Id
, Kind
);
391 Set_Ekind
(Body_Id
, Kind
);
393 if Present
(First_Ent
) then
394 Set_First_Entity
(Gen_Id
, First_Ent
);
401 -- If this is a compilation unit, it must be made visible explicitly,
402 -- because the compilation of the declaration, unlike other library
403 -- unit declarations, does not. If it is not a unit, the following
404 -- is redundant but harmless.
406 Set_Is_Immediately_Visible
(Gen_Id
);
407 Reference_Body_Formals
(Gen_Id
, Body_Id
);
409 Set_Actual_Subtypes
(N
, Current_Scope
);
410 Analyze_Declarations
(Declarations
(N
));
412 Analyze
(Handled_Statement_Sequence
(N
));
414 Save_Global_References
(Original_Node
(N
));
416 -- Prior to exiting the scope, include generic formals again (if any
417 -- are present) in the set of local entities.
419 if Present
(First_Ent
) then
420 Set_First_Entity
(Gen_Id
, First_Ent
);
423 Check_References
(Gen_Id
);
426 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
428 Check_Subprogram_Order
(N
);
430 -- Outside of its body, unit is generic again
432 Set_Ekind
(Gen_Id
, Kind
);
433 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
434 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
436 end Analyze_Generic_Subprogram_Body
;
438 -----------------------------
439 -- Analyze_Operator_Symbol --
440 -----------------------------
442 -- An operator symbol such as "+" or "and" may appear in context where the
443 -- literal denotes an entity name, such as "+"(x, y) or in context when it
444 -- is just a string, as in (conjunction = "or"). In these cases the parser
445 -- generates this node, and the semantics does the disambiguation. Other
446 -- such case are actuals in an instantiation, the generic unit in an
447 -- instantiation, and pragma arguments.
449 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
450 Par
: constant Node_Id
:= Parent
(N
);
453 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
454 or else Nkind
(Par
) = N_Function_Instantiation
455 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
456 or else (Nkind
(Par
) = N_Pragma_Argument_Association
457 and then not Is_Pragma_String_Literal
(Par
))
458 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
459 or else (Nkind
(Par
) = N_Attribute_Reference
460 and then Attribute_Name
(Par
) /= Name_Value
)
462 Find_Direct_Name
(N
);
465 Change_Operator_Symbol_To_String_Literal
(N
);
468 end Analyze_Operator_Symbol
;
470 -----------------------------------
471 -- Analyze_Parameter_Association --
472 -----------------------------------
474 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
476 Analyze
(Explicit_Actual_Parameter
(N
));
477 end Analyze_Parameter_Association
;
479 ----------------------------
480 -- Analyze_Procedure_Call --
481 ----------------------------
483 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
484 Loc
: constant Source_Ptr
:= Sloc
(N
);
485 P
: constant Node_Id
:= Name
(N
);
486 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
490 procedure Analyze_Call_And_Resolve
;
491 -- Do Analyze and Resolve calls for procedure call
493 ------------------------------
494 -- Analyze_Call_And_Resolve --
495 ------------------------------
497 procedure Analyze_Call_And_Resolve
is
499 if Nkind
(N
) = N_Procedure_Call_Statement
then
501 Resolve
(N
, Standard_Void_Type
);
505 end Analyze_Call_And_Resolve
;
507 -- Start of processing for Analyze_Procedure_Call
510 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
511 -- a procedure call or an entry call. The prefix may denote an access
512 -- to subprogram type, in which case an implicit dereference applies.
513 -- If the prefix is an indexed component (without implicit defererence)
514 -- then the construct denotes a call to a member of an entire family.
515 -- If the prefix is a simple name, it may still denote a call to a
516 -- parameterless member of an entry family. Resolution of these various
517 -- interpretations is delicate.
521 -- If this is a call of the form Obj.Op, the call may have been
522 -- analyzed and possibly rewritten into a block, in which case
529 -- If error analyzing prefix, then set Any_Type as result and return
531 if Etype
(P
) = Any_Type
then
532 Set_Etype
(N
, Any_Type
);
536 -- Otherwise analyze the parameters
538 if Present
(Actuals
) then
539 Actual
:= First
(Actuals
);
541 while Present
(Actual
) loop
543 Check_Parameterless_Call
(Actual
);
548 -- Special processing for Elab_Spec and Elab_Body calls
550 if Nkind
(P
) = N_Attribute_Reference
551 and then (Attribute_Name
(P
) = Name_Elab_Spec
552 or else Attribute_Name
(P
) = Name_Elab_Body
)
554 if Present
(Actuals
) then
556 ("no parameters allowed for this call", First
(Actuals
));
560 Set_Etype
(N
, Standard_Void_Type
);
563 elsif Is_Entity_Name
(P
)
564 and then Is_Record_Type
(Etype
(Entity
(P
)))
565 and then Remote_AST_I_Dereference
(P
)
569 elsif Is_Entity_Name
(P
)
570 and then Ekind
(Entity
(P
)) /= E_Entry_Family
572 if Is_Access_Type
(Etype
(P
))
573 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
574 and then No
(Actuals
)
575 and then Comes_From_Source
(N
)
577 Error_Msg_N
("missing explicit dereference in call", N
);
580 Analyze_Call_And_Resolve
;
582 -- If the prefix is the simple name of an entry family, this is
583 -- a parameterless call from within the task body itself.
585 elsif Is_Entity_Name
(P
)
586 and then Nkind
(P
) = N_Identifier
587 and then Ekind
(Entity
(P
)) = E_Entry_Family
588 and then Present
(Actuals
)
589 and then No
(Next
(First
(Actuals
)))
591 -- Can be call to parameterless entry family. What appears to be the
592 -- sole argument is in fact the entry index. Rewrite prefix of node
593 -- accordingly. Source representation is unchanged by this
597 Make_Indexed_Component
(Loc
,
599 Make_Selected_Component
(Loc
,
600 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
601 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
602 Expressions
=> Actuals
);
604 Set_Etype
(New_N
, Standard_Void_Type
);
605 Set_Parameter_Associations
(N
, No_List
);
606 Analyze_Call_And_Resolve
;
608 elsif Nkind
(P
) = N_Explicit_Dereference
then
609 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
610 Analyze_Call_And_Resolve
;
612 Error_Msg_N
("expect access to procedure in call", P
);
615 -- The name can be a selected component or an indexed component that
616 -- yields an access to subprogram. Such a prefix is legal if the call
617 -- has parameter associations.
619 elsif Is_Access_Type
(Etype
(P
))
620 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
622 if Present
(Actuals
) then
623 Analyze_Call_And_Resolve
;
625 Error_Msg_N
("missing explicit dereference in call ", N
);
628 -- If not an access to subprogram, then the prefix must resolve to the
629 -- name of an entry, entry family, or protected operation.
631 -- For the case of a simple entry call, P is a selected component where
632 -- the prefix is the task and the selector name is the entry. A call to
633 -- a protected procedure will have the same syntax. If the protected
634 -- object contains overloaded operations, the entity may appear as a
635 -- function, the context will select the operation whose type is Void.
637 elsif Nkind
(P
) = N_Selected_Component
638 and then (Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
640 Ekind
(Entity
(Selector_Name
(P
))) = E_Procedure
642 Ekind
(Entity
(Selector_Name
(P
))) = E_Function
)
644 Analyze_Call_And_Resolve
;
646 elsif Nkind
(P
) = N_Selected_Component
647 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
648 and then Present
(Actuals
)
649 and then No
(Next
(First
(Actuals
)))
651 -- Can be call to parameterless entry family. What appears to be the
652 -- sole argument is in fact the entry index. Rewrite prefix of node
653 -- accordingly. Source representation is unchanged by this
657 Make_Indexed_Component
(Loc
,
658 Prefix
=> New_Copy
(P
),
659 Expressions
=> Actuals
);
661 Set_Etype
(New_N
, Standard_Void_Type
);
662 Set_Parameter_Associations
(N
, No_List
);
663 Analyze_Call_And_Resolve
;
665 -- For the case of a reference to an element of an entry family, P is
666 -- an indexed component whose prefix is a selected component (task and
667 -- entry family), and whose index is the entry family index.
669 elsif Nkind
(P
) = N_Indexed_Component
670 and then Nkind
(Prefix
(P
)) = N_Selected_Component
671 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
673 Analyze_Call_And_Resolve
;
675 -- If the prefix is the name of an entry family, it is a call from
676 -- within the task body itself.
678 elsif Nkind
(P
) = N_Indexed_Component
679 and then Nkind
(Prefix
(P
)) = N_Identifier
680 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
683 Make_Selected_Component
(Loc
,
684 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
685 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
686 Rewrite
(Prefix
(P
), New_N
);
688 Analyze_Call_And_Resolve
;
690 -- Anything else is an error
693 Error_Msg_N
("invalid procedure or entry call", N
);
695 end Analyze_Procedure_Call
;
697 ------------------------------
698 -- Analyze_Return_Statement --
699 ------------------------------
701 procedure Analyze_Return_Statement
(N
: Node_Id
) is
702 Loc
: constant Source_Ptr
:= Sloc
(N
);
704 Scope_Id
: Entity_Id
;
709 -- Find subprogram or accept statement enclosing the return statement
712 for J
in reverse 0 .. Scope_Stack
.Last
loop
713 Scope_Id
:= Scope_Stack
.Table
(J
).Entity
;
714 exit when Ekind
(Scope_Id
) /= E_Block
and then
715 Ekind
(Scope_Id
) /= E_Loop
;
718 pragma Assert
(Present
(Scope_Id
));
720 Kind
:= Ekind
(Scope_Id
);
721 Expr
:= Expression
(N
);
723 if Kind
/= E_Function
724 and then Kind
/= E_Generic_Function
725 and then Kind
/= E_Procedure
726 and then Kind
/= E_Generic_Procedure
727 and then Kind
/= E_Entry
728 and then Kind
/= E_Entry_Family
730 Error_Msg_N
("illegal context for return statement", N
);
732 elsif Present
(Expr
) then
733 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
734 Set_Return_Present
(Scope_Id
);
735 R_Type
:= Etype
(Scope_Id
);
736 Set_Return_Type
(N
, R_Type
);
737 Analyze_And_Resolve
(Expr
, R_Type
);
739 -- Ada 2005 (AI-318-02): When the result type is an anonymous
740 -- access type, apply an implicit conversion of the expression
741 -- to that type to force appropriate static and run-time
742 -- accessibility checks.
744 if Ada_Version
>= Ada_05
745 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
747 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
748 Analyze_And_Resolve
(Expr
, R_Type
);
751 if (Is_Class_Wide_Type
(Etype
(Expr
))
752 or else Is_Dynamically_Tagged
(Expr
))
753 and then not Is_Class_Wide_Type
(R_Type
)
756 ("dynamically tagged expression not allowed!", Expr
);
759 Apply_Constraint_Check
(Expr
, R_Type
);
761 -- Ada 2005 (AI-318-02): Return-by-reference types have been
762 -- removed and replaced by anonymous access results. This is
763 -- an incompatibility with Ada 95. Not clear whether this
764 -- should be enforced yet or perhaps controllable with a
765 -- special switch. ???
767 -- if Ada_Version >= Ada_05
768 -- and then Is_Limited_Type (R_Type)
769 -- and then Nkind (Expr) /= N_Aggregate
770 -- and then Nkind (Expr) /= N_Extension_Aggregate
771 -- and then Nkind (Expr) /= N_Function_Call
774 -- ("(Ada 2005) illegal operand for limited return", N);
777 -- ??? A real run-time accessibility check is needed in cases
778 -- involving dereferences of access parameters. For now we just
779 -- check the static cases.
781 if Is_Return_By_Reference_Type
(Etype
(Scope_Id
))
782 and then Object_Access_Level
(Expr
)
783 > Subprogram_Access_Level
(Scope_Id
)
786 Make_Raise_Program_Error
(Loc
,
787 Reason
=> PE_Accessibility_Check_Failed
));
791 ("cannot return a local value by reference?", N
);
793 ("& will be raised at run time?!",
794 N
, Standard_Program_Error
);
797 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
798 Error_Msg_N
("procedure cannot return value (use function)", N
);
801 Error_Msg_N
("accept statement cannot return value", N
);
804 -- No expression present
807 if Kind
= E_Function
or Kind
= E_Generic_Function
then
808 Error_Msg_N
("missing expression in return from function", N
);
811 if (Ekind
(Scope_Id
) = E_Procedure
812 or else Ekind
(Scope_Id
) = E_Generic_Procedure
)
813 and then No_Return
(Scope_Id
)
816 ("RETURN statement not allowed (No_Return)", N
);
820 Check_Unreachable_Code
(N
);
821 end Analyze_Return_Statement
;
823 -------------------------
824 -- Analyze_Return_Type --
825 -------------------------
827 procedure Analyze_Return_Type
(N
: Node_Id
) is
828 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
829 Typ
: Entity_Id
:= Empty
;
832 if Result_Definition
(N
) /= Error
then
833 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
834 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
835 Set_Parent
(Typ
, Result_Definition
(N
));
836 Set_Is_Local_Anonymous_Access
(Typ
);
837 Set_Etype
(Designator
, Typ
);
839 -- Ada 2005 (AI-231): Static checks
841 -- Null_Exclusion_Static_Checks needs to be extended to handle
842 -- null exclusion checks for function specifications. ???
844 -- if Null_Exclusion_Present (N) then
845 -- Null_Exclusion_Static_Checks (Param_Spec);
851 Find_Type
(Result_Definition
(N
));
852 Typ
:= Entity
(Result_Definition
(N
));
853 Set_Etype
(Designator
, Typ
);
855 if Ekind
(Typ
) = E_Incomplete_Type
856 or else (Is_Class_Wide_Type
(Typ
)
858 Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
861 ("invalid use of incomplete type", Result_Definition
(N
));
866 Set_Etype
(Designator
, Any_Type
);
868 end Analyze_Return_Type
;
870 -----------------------------
871 -- Analyze_Subprogram_Body --
872 -----------------------------
874 -- This procedure is called for regular subprogram bodies, generic bodies,
875 -- and for subprogram stubs of both kinds. In the case of stubs, only the
876 -- specification matters, and is used to create a proper declaration for
877 -- the subprogram, or to perform conformance checks.
879 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
880 Loc
: constant Source_Ptr
:= Sloc
(N
);
881 Body_Spec
: constant Node_Id
:= Specification
(N
);
882 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
883 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
884 Body_Deleted
: constant Boolean := False;
888 Spec_Decl
: Node_Id
:= Empty
;
889 Last_Formal
: Entity_Id
:= Empty
;
890 Conformant
: Boolean;
891 Missing_Ret
: Boolean;
894 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
895 -- Look ahead to recognize a pragma that may appear after the body.
896 -- If there is a previous spec, check that it appears in the same
897 -- declarative part. If the pragma is Inline_Always, perform inlining
898 -- unconditionally, otherwise only if Front_End_Inlining is requested.
899 -- If the body acts as a spec, and inlining is required, we create a
900 -- subprogram declaration for it, in order to attach the body to inline.
902 procedure Copy_Parameter_List
(Plist
: List_Id
);
903 -- Comment required ???
905 procedure Verify_Overriding_Indicator
;
906 -- If there was a previous spec, the entity has been entered in the
907 -- current scope previously. If the body itself carries an overriding
908 -- indicator, check that it is consistent with the known status of the
911 -------------------------
912 -- Check_Inline_Pragma --
913 -------------------------
915 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
920 if not Expander_Active
then
924 if Is_List_Member
(N
)
925 and then Present
(Next
(N
))
926 and then Nkind
(Next
(N
)) = N_Pragma
930 if Nkind
(Prag
) = N_Pragma
932 (Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline_Always
935 and then Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline
))
938 (Expression
(First
(Pragma_Argument_Associations
(Prag
))))
949 if Present
(Prag
) then
950 if Present
(Spec_Id
) then
951 if List_Containing
(N
) =
952 List_Containing
(Unit_Declaration_Node
(Spec_Id
))
958 -- Create a subprogram declaration, to make treatment uniform
961 Subp
: constant Entity_Id
:=
962 Make_Defining_Identifier
(Loc
, Chars
(Body_Id
));
963 Decl
: constant Node_Id
:=
964 Make_Subprogram_Declaration
(Loc
,
965 Specification
=> New_Copy_Tree
(Specification
(N
)));
967 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
969 if Present
(First_Formal
(Body_Id
)) then
971 Copy_Parameter_List
(Plist
);
972 Set_Parameter_Specifications
973 (Specification
(Decl
), Plist
);
976 Insert_Before
(N
, Decl
);
979 Set_Has_Pragma_Inline
(Subp
);
981 if Get_Pragma_Id
(Chars
(Prag
)) = Pragma_Inline_Always
then
982 Set_Is_Inlined
(Subp
);
983 Set_Next_Rep_Item
(Prag
, First_Rep_Item
(Subp
));
984 Set_First_Rep_Item
(Subp
, Prag
);
991 end Check_Inline_Pragma
;
993 -------------------------
994 -- Copy_Parameter_List --
995 -------------------------
997 procedure Copy_Parameter_List
(Plist
: List_Id
) is
1001 Formal
:= First_Formal
(Body_Id
);
1003 while Present
(Formal
) loop
1005 (Make_Parameter_Specification
(Loc
,
1006 Defining_Identifier
=>
1007 Make_Defining_Identifier
(Sloc
(Formal
),
1008 Chars
=> Chars
(Formal
)),
1009 In_Present
=> In_Present
(Parent
(Formal
)),
1010 Out_Present
=> Out_Present
(Parent
(Formal
)),
1012 New_Reference_To
(Etype
(Formal
), Loc
),
1014 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
1017 Next_Formal
(Formal
);
1019 end Copy_Parameter_List
;
1021 ---------------------------------
1022 -- Verify_Overriding_Indicator --
1023 ---------------------------------
1025 procedure Verify_Overriding_Indicator
is
1027 if Must_Override
(Body_Spec
)
1028 and then not Is_Overriding_Operation
(Spec_Id
)
1031 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
1033 elsif Must_Not_Override
(Body_Spec
)
1034 and then Is_Overriding_Operation
(Spec_Id
)
1037 ("subprogram& overrides inherited operation",
1038 Body_Spec
, Spec_Id
);
1040 end Verify_Overriding_Indicator
;
1042 -- Start of processing for Analyze_Subprogram_Body
1045 if Debug_Flag_C
then
1046 Write_Str
("==== Compiling subprogram body ");
1047 Write_Name
(Chars
(Body_Id
));
1048 Write_Str
(" from ");
1049 Write_Location
(Loc
);
1053 Trace_Scope
(N
, Body_Id
, " Analyze subprogram");
1055 -- Generic subprograms are handled separately. They always have a
1056 -- generic specification. Determine whether current scope has a
1057 -- previous declaration.
1059 -- If the subprogram body is defined within an instance of the same
1060 -- name, the instance appears as a package renaming, and will be hidden
1061 -- within the subprogram.
1063 if Present
(Prev_Id
)
1064 and then not Is_Overloadable
(Prev_Id
)
1065 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
1066 or else Comes_From_Source
(Prev_Id
))
1068 if Is_Generic_Subprogram
(Prev_Id
) then
1070 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1071 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1073 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
1077 -- Previous entity conflicts with subprogram name. Attempting to
1078 -- enter name will post error.
1080 Enter_Name
(Body_Id
);
1084 -- Non-generic case, find the subprogram declaration, if one was seen,
1085 -- or enter new overloaded entity in the current scope. If the
1086 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
1087 -- part of the context of one of its subunits. No need to redo the
1090 elsif Prev_Id
= Body_Id
1091 and then Has_Completion
(Body_Id
)
1096 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
1098 if Nkind
(N
) = N_Subprogram_Body_Stub
1099 or else No
(Corresponding_Spec
(N
))
1101 Spec_Id
:= Find_Corresponding_Spec
(N
);
1103 -- If this is a duplicate body, no point in analyzing it
1105 if Error_Posted
(N
) then
1109 -- A subprogram body should cause freezing of its own declaration,
1110 -- but if there was no previous explicit declaration, then the
1111 -- subprogram will get frozen too late (there may be code within
1112 -- the body that depends on the subprogram having been frozen,
1113 -- such as uses of extra formals), so we force it to be frozen
1114 -- here. Same holds if the body and the spec are compilation
1117 if No
(Spec_Id
) then
1118 Freeze_Before
(N
, Body_Id
);
1120 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1121 Freeze_Before
(N
, Spec_Id
);
1124 Spec_Id
:= Corresponding_Spec
(N
);
1128 -- Do not inline any subprogram that contains nested subprograms, since
1129 -- the backend inlining circuit seems to generate uninitialized
1130 -- references in this case. We know this happens in the case of front
1131 -- end ZCX support, but it also appears it can happen in other cases as
1132 -- well. The backend often rejects attempts to inline in the case of
1133 -- nested procedures anyway, so little if anything is lost by this.
1134 -- Note that this is test is for the benefit of the back-end. There is
1135 -- a separate test for front-end inlining that also rejects nested
1138 -- Do not do this test if errors have been detected, because in some
1139 -- error cases, this code blows up, and we don't need it anyway if
1140 -- there have been errors, since we won't get to the linker anyway.
1142 if Comes_From_Source
(Body_Id
)
1143 and then Serious_Errors_Detected
= 0
1147 P_Ent
:= Scope
(P_Ent
);
1148 exit when No
(P_Ent
) or else P_Ent
= Standard_Standard
;
1150 if Is_Subprogram
(P_Ent
) then
1151 Set_Is_Inlined
(P_Ent
, False);
1153 if Comes_From_Source
(P_Ent
)
1154 and then Has_Pragma_Inline
(P_Ent
)
1157 ("cannot inline& (nested subprogram)?",
1164 Check_Inline_Pragma
(Spec_Id
);
1166 -- Case of fully private operation in the body of the protected type.
1167 -- We must create a declaration for the subprogram, in order to attach
1168 -- the protected subprogram that will be used in internal calls.
1171 and then Comes_From_Source
(N
)
1172 and then Is_Protected_Type
(Current_Scope
)
1181 Formal
:= First_Formal
(Body_Id
);
1183 -- The protected operation always has at least one formal, namely
1184 -- the object itself, but it is only placed in the parameter list
1185 -- if expansion is enabled.
1188 or else Expander_Active
1196 Copy_Parameter_List
(Plist
);
1198 if Nkind
(Body_Spec
) = N_Procedure_Specification
then
1200 Make_Procedure_Specification
(Loc
,
1201 Defining_Unit_Name
=>
1202 Make_Defining_Identifier
(Sloc
(Body_Id
),
1203 Chars
=> Chars
(Body_Id
)),
1204 Parameter_Specifications
=> Plist
);
1207 Make_Function_Specification
(Loc
,
1208 Defining_Unit_Name
=>
1209 Make_Defining_Identifier
(Sloc
(Body_Id
),
1210 Chars
=> Chars
(Body_Id
)),
1211 Parameter_Specifications
=> Plist
,
1212 Result_Definition
=>
1213 New_Occurrence_Of
(Etype
(Body_Id
), Loc
));
1217 Make_Subprogram_Declaration
(Loc
,
1218 Specification
=> New_Spec
);
1219 Insert_Before
(N
, Decl
);
1220 Spec_Id
:= Defining_Unit_Name
(New_Spec
);
1222 -- Indicate that the entity comes from source, to ensure that
1223 -- cross-reference information is properly generated. The body
1224 -- itself is rewritten during expansion, and the body entity will
1225 -- not appear in calls to the operation.
1227 Set_Comes_From_Source
(Spec_Id
, True);
1229 Set_Has_Completion
(Spec_Id
);
1230 Set_Convention
(Spec_Id
, Convention_Protected
);
1233 elsif Present
(Spec_Id
) then
1234 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
1235 Verify_Overriding_Indicator
;
1238 -- Place subprogram on scope stack, and make formals visible. If there
1239 -- is a spec, the visible entity remains that of the spec.
1241 if Present
(Spec_Id
) then
1242 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
1244 if Is_Child_Unit
(Spec_Id
) then
1245 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
1249 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
1252 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
1253 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
1255 if Is_Abstract
(Spec_Id
) then
1256 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
1259 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
1260 Set_Has_Completion
(Spec_Id
);
1262 if Is_Protected_Type
(Scope
(Spec_Id
)) then
1263 Set_Privals_Chain
(Spec_Id
, New_Elmt_List
);
1266 -- If this is a body generated for a renaming, do not check for
1267 -- full conformance. The check is redundant, because the spec of
1268 -- the body is a copy of the spec in the renaming declaration,
1269 -- and the test can lead to spurious errors on nested defaults.
1271 if Present
(Spec_Decl
)
1272 and then not Comes_From_Source
(N
)
1274 (Nkind
(Original_Node
(Spec_Decl
)) =
1275 N_Subprogram_Renaming_Declaration
1276 or else (Present
(Corresponding_Body
(Spec_Decl
))
1278 Nkind
(Unit_Declaration_Node
1279 (Corresponding_Body
(Spec_Decl
))) =
1280 N_Subprogram_Renaming_Declaration
))
1286 Fully_Conformant
, True, Conformant
, Body_Id
);
1289 -- If the body is not fully conformant, we have to decide if we
1290 -- should analyze it or not. If it has a really messed up profile
1291 -- then we probably should not analyze it, since we will get too
1292 -- many bogus messages.
1294 -- Our decision is to go ahead in the non-fully conformant case
1295 -- only if it is at least mode conformant with the spec. Note
1296 -- that the call to Check_Fully_Conformant has issued the proper
1297 -- error messages to complain about the lack of conformance.
1300 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
1306 if Spec_Id
/= Body_Id
then
1307 Reference_Body_Formals
(Spec_Id
, Body_Id
);
1310 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1311 Set_Corresponding_Spec
(N
, Spec_Id
);
1313 -- Ada 2005 (AI-345): Restore the correct Etype: here we undo the
1314 -- work done by Analyze_Subprogram_Specification to allow the
1315 -- overriding of task, protected and interface primitives.
1317 if Comes_From_Source
(Spec_Id
)
1318 and then Present
(First_Entity
(Spec_Id
))
1319 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
1320 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
1321 and then Present
(Abstract_Interfaces
1322 (Etype
(First_Entity
(Spec_Id
))))
1323 and then Present
(Corresponding_Concurrent_Type
1324 (Etype
(First_Entity
(Spec_Id
))))
1326 Set_Etype
(First_Entity
(Spec_Id
),
1327 Corresponding_Concurrent_Type
1328 (Etype
(First_Entity
(Spec_Id
))));
1331 -- Comment needed here, since this is not Ada 2005 stuff! ???
1333 Install_Formals
(Spec_Id
);
1334 Last_Formal
:= Last_Entity
(Spec_Id
);
1335 New_Scope
(Spec_Id
);
1337 -- Make sure that the subprogram is immediately visible. For
1338 -- child units that have no separate spec this is indispensable.
1339 -- Otherwise it is safe albeit redundant.
1341 Set_Is_Immediately_Visible
(Spec_Id
);
1344 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
1345 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1346 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
1348 -- Case of subprogram body with no previous spec
1352 and then Comes_From_Source
(Body_Id
)
1353 and then not Suppress_Style_Checks
(Body_Id
)
1354 and then not In_Instance
1356 Style
.Body_With_No_Spec
(N
);
1359 New_Overloaded_Entity
(Body_Id
);
1361 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1362 Set_Acts_As_Spec
(N
);
1363 Generate_Definition
(Body_Id
);
1365 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
1366 Generate_Reference_To_Formals
(Body_Id
);
1367 Install_Formals
(Body_Id
);
1368 New_Scope
(Body_Id
);
1372 -- If this is the proper body of a stub, we must verify that the stub
1373 -- conforms to the body, and to the previous spec if one was present.
1374 -- we know already that the body conforms to that spec. This test is
1375 -- only required for subprograms that come from source.
1377 if Nkind
(Parent
(N
)) = N_Subunit
1378 and then Comes_From_Source
(N
)
1379 and then not Error_Posted
(Body_Id
)
1380 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
1381 N_Subprogram_Body_Stub
1384 Old_Id
: constant Entity_Id
:=
1386 (Specification
(Corresponding_Stub
(Parent
(N
))));
1388 Conformant
: Boolean := False;
1391 if No
(Spec_Id
) then
1392 Check_Fully_Conformant
(Body_Id
, Old_Id
);
1396 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
1398 if not Conformant
then
1400 -- The stub was taken to be a new declaration. Indicate
1401 -- that it lacks a body.
1403 Set_Has_Completion
(Old_Id
, False);
1409 Set_Has_Completion
(Body_Id
);
1410 Check_Eliminated
(Body_Id
);
1412 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1415 elsif Present
(Spec_Id
)
1416 and then Expander_Active
1418 (Is_Always_Inlined
(Spec_Id
)
1419 or else (Has_Pragma_Inline
(Spec_Id
) and Front_End_Inlining
))
1421 Build_Body_To_Inline
(N
, Spec_Id
);
1424 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
1425 -- if its specification we have to install the private withed units.
1427 if Is_Compilation_Unit
(Body_Id
)
1428 and then Scope
(Body_Id
) = Standard_Standard
1430 Install_Private_With_Clauses
(Body_Id
);
1433 -- Now we can go on to analyze the body
1435 HSS
:= Handled_Statement_Sequence
(N
);
1436 Set_Actual_Subtypes
(N
, Current_Scope
);
1437 Analyze_Declarations
(Declarations
(N
));
1440 Process_End_Label
(HSS
, 't', Current_Scope
);
1442 Check_Subprogram_Order
(N
);
1443 Set_Analyzed
(Body_Id
);
1445 -- If we have a separate spec, then the analysis of the declarations
1446 -- caused the entities in the body to be chained to the spec id, but
1447 -- we want them chained to the body id. Only the formal parameters
1448 -- end up chained to the spec id in this case.
1450 if Present
(Spec_Id
) then
1452 -- We must conform to the categorization of our spec
1454 Validate_Categorization_Dependency
(N
, Spec_Id
);
1456 -- And if this is a child unit, the parent units must conform
1458 if Is_Child_Unit
(Spec_Id
) then
1459 Validate_Categorization_Dependency
1460 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
1463 if Present
(Last_Formal
) then
1465 (Last_Entity
(Body_Id
), Next_Entity
(Last_Formal
));
1466 Set_Next_Entity
(Last_Formal
, Empty
);
1467 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1468 Set_Last_Entity
(Spec_Id
, Last_Formal
);
1471 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
1472 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
1473 Set_First_Entity
(Spec_Id
, Empty
);
1474 Set_Last_Entity
(Spec_Id
, Empty
);
1478 -- If function, check return statements
1480 if Nkind
(Body_Spec
) = N_Function_Specification
then
1485 if Present
(Spec_Id
) then
1491 if Return_Present
(Id
) then
1492 Check_Returns
(HSS
, 'F', Missing_Ret
);
1495 Set_Has_Missing_Return
(Id
);
1498 elsif not Is_Machine_Code_Subprogram
(Id
)
1499 and then not Body_Deleted
1501 Error_Msg_N
("missing RETURN statement in function body", N
);
1505 -- If procedure with No_Return, check returns
1507 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
1508 and then Present
(Spec_Id
)
1509 and then No_Return
(Spec_Id
)
1511 Check_Returns
(HSS
, 'P', Missing_Ret
);
1514 -- Now we are going to check for variables that are never modified in
1515 -- the body of the procedure. We omit these checks if the first
1516 -- statement of the procedure raises an exception. In particular this
1517 -- deals with the common idiom of a stubbed function, which might
1518 -- appear as something like
1520 -- function F (A : Integer) return Some_Type;
1523 -- raise Program_Error;
1527 -- Here the purpose of X is simply to satisfy the (annoying)
1528 -- requirement in Ada that there be at least one return, and we
1529 -- certainly do not want to go posting warnings on X that it is not
1533 Stm
: Node_Id
:= First
(Statements
(HSS
));
1536 -- Skip an initial label (for one thing this occurs when we are in
1537 -- front end ZCX mode, but in any case it is irrelevant).
1539 if Nkind
(Stm
) = N_Label
then
1543 -- Do the test on the original statement before expansion
1546 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
1549 -- If explicit raise statement, return with no checks
1551 if Nkind
(Ostm
) = N_Raise_Statement
then
1554 -- Check for explicit call cases which likely raise an exception
1556 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
1557 if Is_Entity_Name
(Name
(Ostm
)) then
1559 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
1562 -- If the procedure is marked No_Return, then likely it
1563 -- raises an exception, but in any case it is not coming
1564 -- back here, so no need to check beyond the call.
1566 if Ekind
(Ent
) = E_Procedure
1567 and then No_Return
(Ent
)
1571 -- If the procedure name is Raise_Exception, then also
1572 -- assume that it raises an exception. The main target
1573 -- here is Ada.Exceptions.Raise_Exception, but this name
1574 -- is pretty evocative in any context! Note that the
1575 -- procedure in Ada.Exceptions is not marked No_Return
1576 -- because of the annoying case of the null exception Id.
1578 elsif Chars
(Ent
) = Name_Raise_Exception
then
1587 -- Check for variables that are never modified
1593 -- If there is a separate spec, then transfer Never_Set_In_Source
1594 -- flags from out parameters to the corresponding entities in the
1595 -- body. The reason we do that is we want to post error flags on
1596 -- the body entities, not the spec entities.
1598 if Present
(Spec_Id
) then
1599 E1
:= First_Entity
(Spec_Id
);
1601 while Present
(E1
) loop
1602 if Ekind
(E1
) = E_Out_Parameter
then
1603 E2
:= First_Entity
(Body_Id
);
1604 while Present
(E2
) loop
1605 exit when Chars
(E1
) = Chars
(E2
);
1609 if Present
(E2
) then
1610 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
1618 -- Check references in body unless it was deleted. Note that the
1619 -- check of Body_Deleted here is not just for efficiency, it is
1620 -- necessary to avoid junk warnings on formal parameters.
1622 if not Body_Deleted
then
1623 Check_References
(Body_Id
);
1626 end Analyze_Subprogram_Body
;
1628 ------------------------------------
1629 -- Analyze_Subprogram_Declaration --
1630 ------------------------------------
1632 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
1633 Designator
: constant Entity_Id
:=
1634 Analyze_Subprogram_Specification
(Specification
(N
));
1635 Scop
: constant Entity_Id
:= Current_Scope
;
1637 -- Start of processing for Analyze_Subprogram_Declaration
1640 Generate_Definition
(Designator
);
1642 -- Check for RCI unit subprogram declarations against in-lined
1643 -- subprograms and subprograms having access parameter or limited
1644 -- parameter without Read and Write (RM E.2.3(12-13)).
1646 Validate_RCI_Subprogram_Declaration
(N
);
1650 Defining_Entity
(N
),
1651 " Analyze subprogram spec. ");
1653 if Debug_Flag_C
then
1654 Write_Str
("==== Compiling subprogram spec ");
1655 Write_Name
(Chars
(Designator
));
1656 Write_Str
(" from ");
1657 Write_Location
(Sloc
(N
));
1661 New_Overloaded_Entity
(Designator
);
1662 Check_Delayed_Subprogram
(Designator
);
1664 -- What is the following code for, it used to be
1666 -- ??? Set_Suppress_Elaboration_Checks
1667 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
1669 -- The following seems equivalent, but a bit dubious
1671 if Elaboration_Checks_Suppressed
(Designator
) then
1672 Set_Kill_Elaboration_Checks
(Designator
);
1675 if Scop
/= Standard_Standard
1676 and then not Is_Child_Unit
(Designator
)
1678 Set_Categorization_From_Scope
(Designator
, Scop
);
1680 -- For a compilation unit, check for library-unit pragmas
1682 New_Scope
(Designator
);
1683 Set_Categorization_From_Pragmas
(N
);
1684 Validate_Categorization_Dependency
(N
, Designator
);
1688 -- For a compilation unit, set body required. This flag will only be
1689 -- reset if a valid Import or Interface pragma is processed later on.
1691 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1692 Set_Body_Required
(Parent
(N
), True);
1694 if Ada_Version
>= Ada_05
1695 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
1696 and then Null_Present
(Specification
(N
))
1699 ("null procedure cannot be declared at library level", N
);
1703 Generate_Reference_To_Formals
(Designator
);
1704 Check_Eliminated
(Designator
);
1706 -- Ada 2005: if procedure is declared with "is null" qualifier,
1707 -- it requires no body.
1709 if Nkind
(Specification
(N
)) = N_Procedure_Specification
1710 and then Null_Present
(Specification
(N
))
1712 Set_Has_Completion
(Designator
);
1713 Set_Is_Inlined
(Designator
);
1715 end Analyze_Subprogram_Declaration
;
1717 --------------------------------------
1718 -- Analyze_Subprogram_Specification --
1719 --------------------------------------
1721 -- Reminder: N here really is a subprogram specification (not a subprogram
1722 -- declaration). This procedure is called to analyze the specification in
1723 -- both subprogram bodies and subprogram declarations (specs).
1725 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
1726 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
1727 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
1729 function Has_Interface_Formals
(T
: List_Id
) return Boolean;
1730 -- Ada 2005 (AI-251): Returns true if some non class-wide interface
1733 ---------------------------
1734 -- Has_Interface_Formals --
1735 ---------------------------
1737 function Has_Interface_Formals
(T
: List_Id
) return Boolean is
1738 Param_Spec
: Node_Id
;
1742 Param_Spec
:= First
(T
);
1744 while Present
(Param_Spec
) loop
1745 Formal
:= Defining_Identifier
(Param_Spec
);
1747 if Is_Class_Wide_Type
(Etype
(Formal
)) then
1750 elsif Is_Interface
(Etype
(Formal
)) then
1758 end Has_Interface_Formals
;
1760 -- Start of processing for Analyze_Subprogram_Specification
1763 Generate_Definition
(Designator
);
1765 if Nkind
(N
) = N_Function_Specification
then
1766 Set_Ekind
(Designator
, E_Function
);
1767 Set_Mechanism
(Designator
, Default_Mechanism
);
1770 Set_Ekind
(Designator
, E_Procedure
);
1771 Set_Etype
(Designator
, Standard_Void_Type
);
1774 -- Introduce new scope for analysis of the formals and of the
1777 Set_Scope
(Designator
, Current_Scope
);
1779 if Present
(Formals
) then
1780 New_Scope
(Designator
);
1781 Process_Formals
(Formals
, N
);
1783 -- Ada 2005 (AI-345): Allow overriding primitives of protected
1784 -- interfaces by means of normal subprograms. For this purpose
1785 -- temporarily use the corresponding record type as the etype
1786 -- of the first formal.
1788 if Ada_Version
>= Ada_05
1789 and then Comes_From_Source
(Designator
)
1790 and then Present
(First_Entity
(Designator
))
1791 and then (Ekind
(Etype
(First_Entity
(Designator
)))
1794 Ekind
(Etype
(First_Entity
(Designator
)))
1796 and then Present
(Corresponding_Record_Type
1797 (Etype
(First_Entity
(Designator
))))
1798 and then Present
(Abstract_Interfaces
1799 (Corresponding_Record_Type
1800 (Etype
(First_Entity
(Designator
)))))
1802 Set_Etype
(First_Entity
(Designator
),
1803 Corresponding_Record_Type
(Etype
(First_Entity
(Designator
))));
1808 elsif Nkind
(N
) = N_Function_Specification
then
1809 Analyze_Return_Type
(N
);
1812 if Nkind
(N
) = N_Function_Specification
then
1813 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
1814 Valid_Operator_Definition
(Designator
);
1817 May_Need_Actuals
(Designator
);
1819 if Is_Abstract
(Etype
(Designator
))
1820 and then Nkind
(Parent
(N
))
1821 /= N_Abstract_Subprogram_Declaration
1822 and then (Nkind
(Parent
(N
)))
1823 /= N_Formal_Abstract_Subprogram_Declaration
1824 and then (Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
1825 or else not Is_Entity_Name
(Name
(Parent
(N
)))
1826 or else not Is_Abstract
(Entity
(Name
(Parent
(N
)))))
1829 ("function that returns abstract type must be abstract", N
);
1833 if Ada_Version
>= Ada_05
1834 and then Comes_From_Source
(N
)
1835 and then Nkind
(Parent
(N
)) /= N_Abstract_Subprogram_Declaration
1836 and then (Nkind
(N
) /= N_Procedure_Specification
1838 not Null_Present
(N
))
1839 and then Has_Interface_Formals
(Formals
)
1841 Error_Msg_Name_1
:= Chars
(Defining_Unit_Name
1842 (Specification
(Parent
(N
))));
1844 ("(Ada 2005) interface subprogram % must be abstract or null", N
);
1848 end Analyze_Subprogram_Specification
;
1850 --------------------------
1851 -- Build_Body_To_Inline --
1852 --------------------------
1854 procedure Build_Body_To_Inline
(N
: Node_Id
; Subp
: Entity_Id
) is
1855 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
1856 Original_Body
: Node_Id
;
1857 Body_To_Analyze
: Node_Id
;
1858 Max_Size
: constant := 10;
1859 Stat_Count
: Integer := 0;
1861 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean;
1862 -- Check for declarations that make inlining not worthwhile
1864 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean;
1865 -- Check for statements that make inlining not worthwhile: any tasking
1866 -- statement, nested at any level. Keep track of total number of
1867 -- elementary statements, as a measure of acceptable size.
1869 function Has_Pending_Instantiation
return Boolean;
1870 -- If some enclosing body contains instantiations that appear before
1871 -- the corresponding generic body, the enclosing body has a freeze node
1872 -- so that it can be elaborated after the generic itself. This might
1873 -- conflict with subsequent inlinings, so that it is unsafe to try to
1874 -- inline in such a case.
1876 procedure Remove_Pragmas
;
1877 -- A pragma Unreferenced that mentions a formal parameter has no
1878 -- meaning when the body is inlined and the formals are rewritten.
1879 -- Remove it from body to inline. The analysis of the non-inlined body
1880 -- will handle the pragma properly.
1882 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean;
1883 -- If the body of the subprogram includes a call that returns an
1884 -- unconstrained type, the secondary stack is involved, and it
1885 -- is not worth inlining.
1887 ------------------------------
1888 -- Has_Excluded_Declaration --
1889 ------------------------------
1891 function Has_Excluded_Declaration
(Decls
: List_Id
) return Boolean is
1894 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean;
1895 -- Nested subprograms make a given body ineligible for inlining, but
1896 -- we make an exception for instantiations of unchecked conversion.
1897 -- The body has not been analyzed yet, so check the name, and verify
1898 -- that the visible entity with that name is the predefined unit.
1900 -----------------------------
1901 -- Is_Unchecked_Conversion --
1902 -----------------------------
1904 function Is_Unchecked_Conversion
(D
: Node_Id
) return Boolean is
1905 Id
: constant Node_Id
:= Name
(D
);
1909 if Nkind
(Id
) = N_Identifier
1910 and then Chars
(Id
) = Name_Unchecked_Conversion
1912 Conv
:= Current_Entity
(Id
);
1914 elsif (Nkind
(Id
) = N_Selected_Component
1915 or else Nkind
(Id
) = N_Expanded_Name
)
1916 and then Chars
(Selector_Name
(Id
)) = Name_Unchecked_Conversion
1918 Conv
:= Current_Entity
(Selector_Name
(Id
));
1924 return Present
(Conv
)
1925 and then Is_Predefined_File_Name
1926 (Unit_File_Name
(Get_Source_Unit
(Conv
)))
1927 and then Is_Intrinsic_Subprogram
(Conv
);
1928 end Is_Unchecked_Conversion
;
1930 -- Start of processing for Has_Excluded_Declaration
1935 while Present
(D
) loop
1936 if (Nkind
(D
) = N_Function_Instantiation
1937 and then not Is_Unchecked_Conversion
(D
))
1938 or else Nkind
(D
) = N_Protected_Type_Declaration
1939 or else Nkind
(D
) = N_Package_Declaration
1940 or else Nkind
(D
) = N_Package_Instantiation
1941 or else Nkind
(D
) = N_Subprogram_Body
1942 or else Nkind
(D
) = N_Procedure_Instantiation
1943 or else Nkind
(D
) = N_Task_Type_Declaration
1946 ("cannot inline & (non-allowed declaration)?", D
, Subp
);
1954 end Has_Excluded_Declaration
;
1956 ----------------------------
1957 -- Has_Excluded_Statement --
1958 ----------------------------
1960 function Has_Excluded_Statement
(Stats
: List_Id
) return Boolean is
1967 while Present
(S
) loop
1968 Stat_Count
:= Stat_Count
+ 1;
1970 if Nkind
(S
) = N_Abort_Statement
1971 or else Nkind
(S
) = N_Asynchronous_Select
1972 or else Nkind
(S
) = N_Conditional_Entry_Call
1973 or else Nkind
(S
) = N_Delay_Relative_Statement
1974 or else Nkind
(S
) = N_Delay_Until_Statement
1975 or else Nkind
(S
) = N_Selective_Accept
1976 or else Nkind
(S
) = N_Timed_Entry_Call
1979 ("cannot inline & (non-allowed statement)?", S
, Subp
);
1982 elsif Nkind
(S
) = N_Block_Statement
then
1983 if Present
(Declarations
(S
))
1984 and then Has_Excluded_Declaration
(Declarations
(S
))
1988 elsif Present
(Handled_Statement_Sequence
(S
))
1991 (Exception_Handlers
(Handled_Statement_Sequence
(S
)))
1993 Has_Excluded_Statement
1994 (Statements
(Handled_Statement_Sequence
(S
))))
1999 elsif Nkind
(S
) = N_Case_Statement
then
2000 E
:= First
(Alternatives
(S
));
2001 while Present
(E
) loop
2002 if Has_Excluded_Statement
(Statements
(E
)) then
2009 elsif Nkind
(S
) = N_If_Statement
then
2010 if Has_Excluded_Statement
(Then_Statements
(S
)) then
2014 if Present
(Elsif_Parts
(S
)) then
2015 E
:= First
(Elsif_Parts
(S
));
2016 while Present
(E
) loop
2017 if Has_Excluded_Statement
(Then_Statements
(E
)) then
2024 if Present
(Else_Statements
(S
))
2025 and then Has_Excluded_Statement
(Else_Statements
(S
))
2030 elsif Nkind
(S
) = N_Loop_Statement
2031 and then Has_Excluded_Statement
(Statements
(S
))
2040 end Has_Excluded_Statement
;
2042 -------------------------------
2043 -- Has_Pending_Instantiation --
2044 -------------------------------
2046 function Has_Pending_Instantiation
return Boolean is
2047 S
: Entity_Id
:= Current_Scope
;
2050 while Present
(S
) loop
2051 if Is_Compilation_Unit
(S
)
2052 or else Is_Child_Unit
(S
)
2055 elsif Ekind
(S
) = E_Package
2056 and then Has_Forward_Instantiation
(S
)
2065 end Has_Pending_Instantiation
;
2067 --------------------
2068 -- Remove_Pragmas --
2069 --------------------
2071 procedure Remove_Pragmas
is
2076 Decl
:= First
(Declarations
(Body_To_Analyze
));
2077 while Present
(Decl
) loop
2080 if Nkind
(Decl
) = N_Pragma
2081 and then Chars
(Decl
) = Name_Unreferenced
2090 --------------------------
2091 -- Uses_Secondary_Stack --
2092 --------------------------
2094 function Uses_Secondary_Stack
(Bod
: Node_Id
) return Boolean is
2095 function Check_Call
(N
: Node_Id
) return Traverse_Result
;
2096 -- Look for function calls that return an unconstrained type
2102 function Check_Call
(N
: Node_Id
) return Traverse_Result
is
2104 if Nkind
(N
) = N_Function_Call
2105 and then Is_Entity_Name
(Name
(N
))
2106 and then Is_Composite_Type
(Etype
(Entity
(Name
(N
))))
2107 and then not Is_Constrained
(Etype
(Entity
(Name
(N
))))
2110 ("cannot inline & (call returns unconstrained type)?",
2118 function Check_Calls
is new Traverse_Func
(Check_Call
);
2121 return Check_Calls
(Bod
) = Abandon
;
2122 end Uses_Secondary_Stack
;
2124 -- Start of processing for Build_Body_To_Inline
2127 if Nkind
(Decl
) = N_Subprogram_Declaration
2128 and then Present
(Body_To_Inline
(Decl
))
2130 return; -- Done already.
2132 -- Functions that return unconstrained composite types will require
2133 -- secondary stack handling, and cannot currently be inlined.
2134 -- Ditto for functions that return controlled types, where controlled
2135 -- actions interfere in complex ways with inlining.
2137 elsif Ekind
(Subp
) = E_Function
2138 and then not Is_Scalar_Type
(Etype
(Subp
))
2139 and then not Is_Access_Type
(Etype
(Subp
))
2140 and then not Is_Constrained
(Etype
(Subp
))
2143 ("cannot inline & (unconstrained return type)?", N
, Subp
);
2146 elsif Ekind
(Subp
) = E_Function
2147 and then Controlled_Type
(Etype
(Subp
))
2150 ("cannot inline & (controlled return type)?", N
, Subp
);
2154 if Present
(Declarations
(N
))
2155 and then Has_Excluded_Declaration
(Declarations
(N
))
2160 if Present
(Handled_Statement_Sequence
(N
)) then
2161 if Present
(Exception_Handlers
(Handled_Statement_Sequence
(N
))) then
2163 ("cannot inline& (exception handler)?",
2164 First
(Exception_Handlers
(Handled_Statement_Sequence
(N
))),
2168 Has_Excluded_Statement
2169 (Statements
(Handled_Statement_Sequence
(N
)))
2175 -- We do not inline a subprogram that is too large, unless it is
2176 -- marked Inline_Always. This pragma does not suppress the other
2177 -- checks on inlining (forbidden declarations, handlers, etc).
2179 if Stat_Count
> Max_Size
2180 and then not Is_Always_Inlined
(Subp
)
2182 Cannot_Inline
("cannot inline& (body too large)?", N
, Subp
);
2186 if Has_Pending_Instantiation
then
2188 ("cannot inline& (forward instance within enclosing body)?",
2193 -- Within an instance, the body to inline must be treated as a nested
2194 -- generic, so that the proper global references are preserved.
2197 Save_Env
(Scope
(Current_Scope
), Scope
(Current_Scope
));
2198 Original_Body
:= Copy_Generic_Node
(N
, Empty
, True);
2200 Original_Body
:= Copy_Separate_Tree
(N
);
2203 -- We need to capture references to the formals in order to substitute
2204 -- the actuals at the point of inlining, i.e. instantiation. To treat
2205 -- the formals as globals to the body to inline, we nest it within
2206 -- a dummy parameterless subprogram, declared within the real one.
2207 -- To avoid generating an internal name (which is never public, and
2208 -- which affects serial numbers of other generated names), we use
2209 -- an internal symbol that cannot conflict with user declarations.
2211 Set_Parameter_Specifications
(Specification
(Original_Body
), No_List
);
2212 Set_Defining_Unit_Name
2213 (Specification
(Original_Body
),
2214 Make_Defining_Identifier
(Sloc
(N
), Name_uParent
));
2215 Set_Corresponding_Spec
(Original_Body
, Empty
);
2217 Body_To_Analyze
:= Copy_Generic_Node
(Original_Body
, Empty
, False);
2219 -- Set return type of function, which is also global and does not need
2222 if Ekind
(Subp
) = E_Function
then
2223 Set_Result_Definition
(Specification
(Body_To_Analyze
),
2224 New_Occurrence_Of
(Etype
(Subp
), Sloc
(N
)));
2227 if No
(Declarations
(N
)) then
2228 Set_Declarations
(N
, New_List
(Body_To_Analyze
));
2230 Append
(Body_To_Analyze
, Declarations
(N
));
2233 Expander_Mode_Save_And_Set
(False);
2236 Analyze
(Body_To_Analyze
);
2237 New_Scope
(Defining_Entity
(Body_To_Analyze
));
2238 Save_Global_References
(Original_Body
);
2240 Remove
(Body_To_Analyze
);
2242 Expander_Mode_Restore
;
2248 -- If secondary stk used there is no point in inlining. We have
2249 -- already issued the warning in this case, so nothing to do.
2251 if Uses_Secondary_Stack
(Body_To_Analyze
) then
2255 Set_Body_To_Inline
(Decl
, Original_Body
);
2256 Set_Ekind
(Defining_Entity
(Original_Body
), Ekind
(Subp
));
2257 Set_Is_Inlined
(Subp
);
2258 end Build_Body_To_Inline
;
2264 procedure Cannot_Inline
(Msg
: String; N
: Node_Id
; Subp
: Entity_Id
) is
2266 -- Do not emit warning if this is a predefined unit which is not
2267 -- the main unit. With validity checks enabled, some predefined
2268 -- subprograms may contain nested subprograms and become ineligible
2271 if Is_Predefined_File_Name
(Unit_File_Name
(Get_Source_Unit
(Subp
)))
2272 and then not In_Extended_Main_Source_Unit
(Subp
)
2276 elsif Is_Always_Inlined
(Subp
) then
2278 -- Remove last character (question mark) to make this into an error,
2279 -- because the Inline_Always pragma cannot be obeyed.
2281 Error_Msg_NE
(Msg
(1 .. Msg
'Length - 1), N
, Subp
);
2283 elsif Ineffective_Inline_Warnings
then
2284 Error_Msg_NE
(Msg
, N
, Subp
);
2288 -----------------------
2289 -- Check_Conformance --
2290 -----------------------
2292 procedure Check_Conformance
2293 (New_Id
: Entity_Id
;
2295 Ctype
: Conformance_Type
;
2297 Conforms
: out Boolean;
2298 Err_Loc
: Node_Id
:= Empty
;
2299 Get_Inst
: Boolean := False;
2300 Skip_Controlling_Formals
: Boolean := False)
2302 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
2303 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
2304 Old_Formal
: Entity_Id
;
2305 New_Formal
: Entity_Id
;
2307 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
2308 -- Post error message for conformance error on given node. Two messages
2309 -- are output. The first points to the previous declaration with a
2310 -- general "no conformance" message. The second is the detailed reason,
2311 -- supplied as Msg. The parameter N provide information for a possible
2312 -- & insertion in the message, and also provides the location for
2313 -- posting the message in the absence of a specified Err_Loc location.
2315 -----------------------
2316 -- Conformance_Error --
2317 -----------------------
2319 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
2326 if No
(Err_Loc
) then
2332 Error_Msg_Sloc
:= Sloc
(Old_Id
);
2335 when Type_Conformant
=>
2337 ("not type conformant with declaration#!", Enode
);
2339 when Mode_Conformant
=>
2341 ("not mode conformant with declaration#!", Enode
);
2343 when Subtype_Conformant
=>
2345 ("not subtype conformant with declaration#!", Enode
);
2347 when Fully_Conformant
=>
2349 ("not fully conformant with declaration#!", Enode
);
2352 Error_Msg_NE
(Msg
, Enode
, N
);
2354 end Conformance_Error
;
2356 -- Start of processing for Check_Conformance
2361 -- We need a special case for operators, since they don't appear
2364 if Ctype
= Type_Conformant
then
2365 if Ekind
(New_Id
) = E_Operator
2366 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
2372 -- If both are functions/operators, check return types conform
2374 if Old_Type
/= Standard_Void_Type
2375 and then New_Type
/= Standard_Void_Type
2377 if not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
2378 Conformance_Error
("return type does not match!", New_Id
);
2382 -- Ada 2005 (AI-231): In case of anonymous access types check the
2383 -- null-exclusion and access-to-constant attributes must match.
2385 if Ada_Version
>= Ada_05
2386 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
2388 (Can_Never_Be_Null
(Old_Type
)
2389 /= Can_Never_Be_Null
(New_Type
)
2390 or else Is_Access_Constant
(Etype
(Old_Type
))
2391 /= Is_Access_Constant
(Etype
(New_Type
)))
2393 Conformance_Error
("return type does not match!", New_Id
);
2397 -- If either is a function/operator and the other isn't, error
2399 elsif Old_Type
/= Standard_Void_Type
2400 or else New_Type
/= Standard_Void_Type
2402 Conformance_Error
("functions can only match functions!", New_Id
);
2406 -- In subtype conformant case, conventions must match (RM 6.3.1(16))
2407 -- If this is a renaming as body, refine error message to indicate that
2408 -- the conflict is with the original declaration. If the entity is not
2409 -- frozen, the conventions don't have to match, the one of the renamed
2410 -- entity is inherited.
2412 if Ctype
>= Subtype_Conformant
then
2413 if Convention
(Old_Id
) /= Convention
(New_Id
) then
2415 if not Is_Frozen
(New_Id
) then
2418 elsif Present
(Err_Loc
)
2419 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
2420 and then Present
(Corresponding_Spec
(Err_Loc
))
2422 Error_Msg_Name_1
:= Chars
(New_Id
);
2424 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
2426 Conformance_Error
("prior declaration for% has convention %!");
2429 Conformance_Error
("calling conventions do not match!");
2434 elsif Is_Formal_Subprogram
(Old_Id
)
2435 or else Is_Formal_Subprogram
(New_Id
)
2437 Conformance_Error
("formal subprograms not allowed!");
2442 -- Deal with parameters
2444 -- Note: we use the entity information, rather than going directly
2445 -- to the specification in the tree. This is not only simpler, but
2446 -- absolutely necessary for some cases of conformance tests between
2447 -- operators, where the declaration tree simply does not exist!
2449 Old_Formal
:= First_Formal
(Old_Id
);
2450 New_Formal
:= First_Formal
(New_Id
);
2452 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
2453 if Is_Controlling_Formal
(Old_Formal
)
2454 and then Is_Controlling_Formal
(New_Formal
)
2455 and then Skip_Controlling_Formals
2457 goto Skip_Controlling_Formal
;
2460 if Ctype
= Fully_Conformant
then
2462 -- Names must match. Error message is more accurate if we do
2463 -- this before checking that the types of the formals match.
2465 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
2466 Conformance_Error
("name & does not match!", New_Formal
);
2468 -- Set error posted flag on new formal as well to stop
2469 -- junk cascaded messages in some cases.
2471 Set_Error_Posted
(New_Formal
);
2476 -- Types must always match. In the visible part of an instance,
2477 -- usual overloading rules for dispatching operations apply, and
2478 -- we check base types (not the actual subtypes).
2480 if In_Instance_Visible_Part
2481 and then Is_Dispatching_Operation
(New_Id
)
2483 if not Conforming_Types
2484 (Base_Type
(Etype
(Old_Formal
)),
2485 Base_Type
(Etype
(New_Formal
)), Ctype
, Get_Inst
)
2487 Conformance_Error
("type of & does not match!", New_Formal
);
2491 elsif not Conforming_Types
2492 (Etype
(Old_Formal
), Etype
(New_Formal
), Ctype
, Get_Inst
)
2494 Conformance_Error
("type of & does not match!", New_Formal
);
2498 -- For mode conformance, mode must match
2500 if Ctype
>= Mode_Conformant
2501 and then Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
)
2503 Conformance_Error
("mode of & does not match!", New_Formal
);
2507 -- Full conformance checks
2509 if Ctype
= Fully_Conformant
then
2511 -- We have checked already that names match
2513 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
2515 -- Ada 2005 (AI-231): In case of anonymous access types check
2516 -- the null-exclusion and access-to-constant attributes must
2519 if Ada_Version
>= Ada_05
2520 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
2522 (Can_Never_Be_Null
(Old_Formal
)
2523 /= Can_Never_Be_Null
(New_Formal
)
2524 or else Is_Access_Constant
(Etype
(Old_Formal
))
2525 /= Is_Access_Constant
(Etype
(New_Formal
)))
2527 -- It is allowed to omit the null-exclusion in case of
2528 -- stream attribute subprograms
2531 TSS_Name
: TSS_Name_Type
;
2534 Get_Name_String
(Chars
(New_Id
));
2538 (Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2540 if TSS_Name
/= TSS_Stream_Read
2541 and then TSS_Name
/= TSS_Stream_Write
2542 and then TSS_Name
/= TSS_Stream_Input
2543 and then TSS_Name
/= TSS_Stream_Output
2546 ("type of & does not match!", New_Formal
);
2552 -- Check default expressions for in parameters
2555 NewD
: constant Boolean :=
2556 Present
(Default_Value
(New_Formal
));
2557 OldD
: constant Boolean :=
2558 Present
(Default_Value
(Old_Formal
));
2560 if NewD
or OldD
then
2562 -- The old default value has been analyzed because the
2563 -- current full declaration will have frozen everything
2564 -- before. The new default values have not been
2565 -- analyzed, so analyze them now before we check for
2570 Analyze_Per_Use_Expression
2571 (Default_Value
(New_Formal
), Etype
(New_Formal
));
2575 if not (NewD
and OldD
)
2576 or else not Fully_Conformant_Expressions
2577 (Default_Value
(Old_Formal
),
2578 Default_Value
(New_Formal
))
2581 ("default expression for & does not match!",
2590 -- A couple of special checks for Ada 83 mode. These checks are
2591 -- skipped if either entity is an operator in package Standard.
2592 -- or if either old or new instance is not from the source program.
2594 if Ada_Version
= Ada_83
2595 and then Sloc
(Old_Id
) > Standard_Location
2596 and then Sloc
(New_Id
) > Standard_Location
2597 and then Comes_From_Source
(Old_Id
)
2598 and then Comes_From_Source
(New_Id
)
2601 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
2602 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
2605 -- Explicit IN must be present or absent in both cases. This
2606 -- test is required only in the full conformance case.
2608 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
2609 and then Ctype
= Fully_Conformant
2612 ("(Ada 83) IN must appear in both declarations",
2617 -- Grouping (use of comma in param lists) must be the same
2618 -- This is where we catch a misconformance like:
2621 -- A : Integer; B : Integer
2623 -- which are represented identically in the tree except
2624 -- for the setting of the flags More_Ids and Prev_Ids.
2626 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
2627 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
2630 ("grouping of & does not match!", New_Formal
);
2636 -- This label is required when skipping controlling formals
2638 <<Skip_Controlling_Formal
>>
2640 Next_Formal
(Old_Formal
);
2641 Next_Formal
(New_Formal
);
2644 if Present
(Old_Formal
) then
2645 Conformance_Error
("too few parameters!");
2648 elsif Present
(New_Formal
) then
2649 Conformance_Error
("too many parameters!", New_Formal
);
2652 end Check_Conformance
;
2654 ------------------------------
2655 -- Check_Delayed_Subprogram --
2656 ------------------------------
2658 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
2661 procedure Possible_Freeze
(T
: Entity_Id
);
2662 -- T is the type of either a formal parameter or of the return type.
2663 -- If T is not yet frozen and needs a delayed freeze, then the
2664 -- subprogram itself must be delayed.
2666 ---------------------
2667 -- Possible_Freeze --
2668 ---------------------
2670 procedure Possible_Freeze
(T
: Entity_Id
) is
2672 if Has_Delayed_Freeze
(T
)
2673 and then not Is_Frozen
(T
)
2675 Set_Has_Delayed_Freeze
(Designator
);
2677 elsif Is_Access_Type
(T
)
2678 and then Has_Delayed_Freeze
(Designated_Type
(T
))
2679 and then not Is_Frozen
(Designated_Type
(T
))
2681 Set_Has_Delayed_Freeze
(Designator
);
2683 end Possible_Freeze
;
2685 -- Start of processing for Check_Delayed_Subprogram
2688 -- Never need to freeze abstract subprogram
2690 if Is_Abstract
(Designator
) then
2693 -- Need delayed freeze if return type itself needs a delayed
2694 -- freeze and is not yet frozen.
2696 Possible_Freeze
(Etype
(Designator
));
2697 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
2699 -- Need delayed freeze if any of the formal types themselves need
2700 -- a delayed freeze and are not yet frozen.
2702 F
:= First_Formal
(Designator
);
2703 while Present
(F
) loop
2704 Possible_Freeze
(Etype
(F
));
2705 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
2710 -- Mark functions that return by reference. Note that it cannot be
2711 -- done for delayed_freeze subprograms because the underlying
2712 -- returned type may not be known yet (for private types)
2714 if not Has_Delayed_Freeze
(Designator
)
2715 and then Expander_Active
2718 Typ
: constant Entity_Id
:= Etype
(Designator
);
2719 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
2722 if Is_Return_By_Reference_Type
(Typ
) then
2723 Set_Returns_By_Ref
(Designator
);
2725 elsif Present
(Utyp
) and then Controlled_Type
(Utyp
) then
2726 Set_Returns_By_Ref
(Designator
);
2730 end Check_Delayed_Subprogram
;
2732 ------------------------------------
2733 -- Check_Discriminant_Conformance --
2734 ------------------------------------
2736 procedure Check_Discriminant_Conformance
2741 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
2742 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
2743 New_Discr_Id
: Entity_Id
;
2744 New_Discr_Type
: Entity_Id
;
2746 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
2747 -- Post error message for conformance error on given node. Two messages
2748 -- are output. The first points to the previous declaration with a
2749 -- general "no conformance" message. The second is the detailed reason,
2750 -- supplied as Msg. The parameter N provide information for a possible
2751 -- & insertion in the message.
2753 -----------------------
2754 -- Conformance_Error --
2755 -----------------------
2757 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
2759 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
2760 Error_Msg_N
("not fully conformant with declaration#!", N
);
2761 Error_Msg_NE
(Msg
, N
, N
);
2762 end Conformance_Error
;
2764 -- Start of processing for Check_Discriminant_Conformance
2767 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
2769 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
2771 -- The subtype mark of the discriminant on the full type has not
2772 -- been analyzed so we do it here. For an access discriminant a new
2775 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
2777 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
2780 Analyze
(Discriminant_Type
(New_Discr
));
2781 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
2784 if not Conforming_Types
2785 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
2787 Conformance_Error
("type of & does not match!", New_Discr_Id
);
2790 -- Treat the new discriminant as an occurrence of the old one,
2791 -- for navigation purposes, and fill in some semantic
2792 -- information, for completeness.
2794 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
2795 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
2796 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
2801 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
2802 Conformance_Error
("name & does not match!", New_Discr_Id
);
2806 -- Default expressions must match
2809 NewD
: constant Boolean :=
2810 Present
(Expression
(New_Discr
));
2811 OldD
: constant Boolean :=
2812 Present
(Expression
(Parent
(Old_Discr
)));
2815 if NewD
or OldD
then
2817 -- The old default value has been analyzed and expanded,
2818 -- because the current full declaration will have frozen
2819 -- everything before. The new default values have not been
2820 -- expanded, so expand now to check conformance.
2823 Analyze_Per_Use_Expression
2824 (Expression
(New_Discr
), New_Discr_Type
);
2827 if not (NewD
and OldD
)
2828 or else not Fully_Conformant_Expressions
2829 (Expression
(Parent
(Old_Discr
)),
2830 Expression
(New_Discr
))
2834 ("default expression for & does not match!",
2841 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
2843 if Ada_Version
= Ada_83
then
2845 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
2848 -- Grouping (use of comma in param lists) must be the same
2849 -- This is where we catch a misconformance like:
2852 -- A : Integer; B : Integer
2854 -- which are represented identically in the tree except
2855 -- for the setting of the flags More_Ids and Prev_Ids.
2857 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
2858 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
2861 ("grouping of & does not match!", New_Discr_Id
);
2867 Next_Discriminant
(Old_Discr
);
2871 if Present
(Old_Discr
) then
2872 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
2875 elsif Present
(New_Discr
) then
2877 ("too many discriminants!", Defining_Identifier
(New_Discr
));
2880 end Check_Discriminant_Conformance
;
2882 ----------------------------
2883 -- Check_Fully_Conformant --
2884 ----------------------------
2886 procedure Check_Fully_Conformant
2887 (New_Id
: Entity_Id
;
2889 Err_Loc
: Node_Id
:= Empty
)
2894 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
2895 end Check_Fully_Conformant
;
2897 ---------------------------
2898 -- Check_Mode_Conformant --
2899 ---------------------------
2901 procedure Check_Mode_Conformant
2902 (New_Id
: Entity_Id
;
2904 Err_Loc
: Node_Id
:= Empty
;
2905 Get_Inst
: Boolean := False)
2911 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
2912 end Check_Mode_Conformant
;
2914 --------------------------------
2915 -- Check_Overriding_Indicator --
2916 --------------------------------
2918 procedure Check_Overriding_Indicator
2920 Does_Override
: Boolean)
2926 if Ekind
(Subp
) = E_Enumeration_Literal
then
2928 -- No overriding indicator for literals
2933 Decl
:= Unit_Declaration_Node
(Subp
);
2936 if Nkind
(Decl
) = N_Subprogram_Declaration
2937 or else Nkind
(Decl
) = N_Subprogram_Body
2938 or else Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
2939 or else Nkind
(Decl
) = N_Subprogram_Body_Stub
2941 Spec
:= Specification
(Decl
);
2946 if not Does_Override
then
2947 if Must_Override
(Spec
) then
2948 Error_Msg_NE
("subprogram& is not overriding", Spec
, Subp
);
2952 if Must_Not_Override
(Spec
) then
2954 ("subprogram& overrides inherited operation", Spec
, Subp
);
2957 end Check_Overriding_Indicator
;
2963 procedure Check_Returns
2970 procedure Check_Statement_Sequence
(L
: List_Id
);
2971 -- Internal recursive procedure to check a list of statements for proper
2972 -- termination by a return statement (or a transfer of control or a
2973 -- compound statement that is itself internally properly terminated).
2975 ------------------------------
2976 -- Check_Statement_Sequence --
2977 ------------------------------
2979 procedure Check_Statement_Sequence
(L
: List_Id
) is
2983 Raise_Exception_Call
: Boolean;
2984 -- Set True if statement sequence terminated by Raise_Exception call
2985 -- or a Reraise_Occurrence call.
2988 Raise_Exception_Call
:= False;
2990 -- Get last real statement
2992 Last_Stm
:= Last
(L
);
2994 -- Don't count pragmas
2996 while Nkind
(Last_Stm
) = N_Pragma
2998 -- Don't count call to SS_Release (can happen after Raise_Exception)
3001 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
3003 Nkind
(Name
(Last_Stm
)) = N_Identifier
3005 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
3007 -- Don't count exception junk
3010 ((Nkind
(Last_Stm
) = N_Goto_Statement
3011 or else Nkind
(Last_Stm
) = N_Label
3012 or else Nkind
(Last_Stm
) = N_Object_Declaration
)
3013 and then Exception_Junk
(Last_Stm
))
3018 -- Here we have the "real" last statement
3020 Kind
:= Nkind
(Last_Stm
);
3022 -- Transfer of control, OK. Note that in the No_Return procedure
3023 -- case, we already diagnosed any explicit return statements, so
3024 -- we can treat them as OK in this context.
3026 if Is_Transfer
(Last_Stm
) then
3029 -- Check cases of explicit non-indirect procedure calls
3031 elsif Kind
= N_Procedure_Call_Statement
3032 and then Is_Entity_Name
(Name
(Last_Stm
))
3034 -- Check call to Raise_Exception procedure which is treated
3035 -- specially, as is a call to Reraise_Occurrence.
3037 -- We suppress the warning in these cases since it is likely that
3038 -- the programmer really does not expect to deal with the case
3039 -- of Null_Occurrence, and thus would find a warning about a
3040 -- missing return curious, and raising Program_Error does not
3041 -- seem such a bad behavior if this does occur.
3043 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
3045 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
3047 Raise_Exception_Call
:= True;
3049 -- For Raise_Exception call, test first argument, if it is
3050 -- an attribute reference for a 'Identity call, then we know
3051 -- that the call cannot possibly return.
3054 Arg
: constant Node_Id
:=
3055 Original_Node
(First_Actual
(Last_Stm
));
3058 if Nkind
(Arg
) = N_Attribute_Reference
3059 and then Attribute_Name
(Arg
) = Name_Identity
3066 -- If statement, need to look inside if there is an else and check
3067 -- each constituent statement sequence for proper termination.
3069 elsif Kind
= N_If_Statement
3070 and then Present
(Else_Statements
(Last_Stm
))
3072 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
3073 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
3075 if Present
(Elsif_Parts
(Last_Stm
)) then
3077 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
3080 while Present
(Elsif_Part
) loop
3081 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
3089 -- Case statement, check each case for proper termination
3091 elsif Kind
= N_Case_Statement
then
3096 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
3097 while Present
(Case_Alt
) loop
3098 Check_Statement_Sequence
(Statements
(Case_Alt
));
3099 Next_Non_Pragma
(Case_Alt
);
3105 -- Block statement, check its handled sequence of statements
3107 elsif Kind
= N_Block_Statement
then
3113 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
3122 -- Loop statement. If there is an iteration scheme, we can definitely
3123 -- fall out of the loop. Similarly if there is an exit statement, we
3124 -- can fall out. In either case we need a following return.
3126 elsif Kind
= N_Loop_Statement
then
3127 if Present
(Iteration_Scheme
(Last_Stm
))
3128 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
3132 -- A loop with no exit statement or iteration scheme if either
3133 -- an inifite loop, or it has some other exit (raise/return).
3134 -- In either case, no warning is required.
3140 -- Timed entry call, check entry call and delay alternatives
3142 -- Note: in expanded code, the timed entry call has been converted
3143 -- to a set of expanded statements on which the check will work
3144 -- correctly in any case.
3146 elsif Kind
= N_Timed_Entry_Call
then
3148 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
3149 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
3152 -- If statement sequence of entry call alternative is missing,
3153 -- then we can definitely fall through, and we post the error
3154 -- message on the entry call alternative itself.
3156 if No
(Statements
(ECA
)) then
3159 -- If statement sequence of delay alternative is missing, then
3160 -- we can definitely fall through, and we post the error
3161 -- message on the delay alternative itself.
3163 -- Note: if both ECA and DCA are missing the return, then we
3164 -- post only one message, should be enough to fix the bugs.
3165 -- If not we will get a message next time on the DCA when the
3168 elsif No
(Statements
(DCA
)) then
3171 -- Else check both statement sequences
3174 Check_Statement_Sequence
(Statements
(ECA
));
3175 Check_Statement_Sequence
(Statements
(DCA
));
3180 -- Conditional entry call, check entry call and else part
3182 -- Note: in expanded code, the conditional entry call has been
3183 -- converted to a set of expanded statements on which the check
3184 -- will work correctly in any case.
3186 elsif Kind
= N_Conditional_Entry_Call
then
3188 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
3191 -- If statement sequence of entry call alternative is missing,
3192 -- then we can definitely fall through, and we post the error
3193 -- message on the entry call alternative itself.
3195 if No
(Statements
(ECA
)) then
3198 -- Else check statement sequence and else part
3201 Check_Statement_Sequence
(Statements
(ECA
));
3202 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
3208 -- If we fall through, issue appropriate message
3212 if not Raise_Exception_Call
then
3214 ("?RETURN statement missing following this statement!",
3217 ("\?Program_Error may be raised at run time",
3221 -- Note: we set Err even though we have not issued a warning
3222 -- because we still have a case of a missing return. This is
3223 -- an extremely marginal case, probably will never be noticed
3224 -- but we might as well get it right.
3230 ("implied return after this statement not allowed (No_Return)",
3233 end Check_Statement_Sequence
;
3235 -- Start of processing for Check_Returns
3239 Check_Statement_Sequence
(Statements
(HSS
));
3241 if Present
(Exception_Handlers
(HSS
)) then
3242 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
3243 while Present
(Handler
) loop
3244 Check_Statement_Sequence
(Statements
(Handler
));
3245 Next_Non_Pragma
(Handler
);
3250 ----------------------------
3251 -- Check_Subprogram_Order --
3252 ----------------------------
3254 procedure Check_Subprogram_Order
(N
: Node_Id
) is
3256 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
3257 -- This is used to check if S1 > S2 in the sense required by this
3258 -- test, for example nameab < namec, but name2 < name10.
3260 -----------------------------
3261 -- Subprogram_Name_Greater --
3262 -----------------------------
3264 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
3269 -- Remove trailing numeric parts
3272 while S1
(L1
) in '0' .. '9' loop
3277 while S2
(L2
) in '0' .. '9' loop
3281 -- If non-numeric parts non-equal, that's decisive
3283 if S1
(S1
'First .. L1
) < S2
(S2
'First .. L2
) then
3286 elsif S1
(S1
'First .. L1
) > S2
(S2
'First .. L2
) then
3289 -- If non-numeric parts equal, compare suffixed numeric parts. Note
3290 -- that a missing suffix is treated as numeric zero in this test.
3294 while L1
< S1
'Last loop
3296 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
3300 while L2
< S2
'Last loop
3302 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
3307 end Subprogram_Name_Greater
;
3309 -- Start of processing for Check_Subprogram_Order
3312 -- Check body in alpha order if this is option
3315 and then Style_Check_Order_Subprograms
3316 and then Nkind
(N
) = N_Subprogram_Body
3317 and then Comes_From_Source
(N
)
3318 and then In_Extended_Main_Source_Unit
(N
)
3322 renames Scope_Stack
.Table
3323 (Scope_Stack
.Last
).Last_Subprogram_Name
;
3325 Body_Id
: constant Entity_Id
:=
3326 Defining_Entity
(Specification
(N
));
3329 Get_Decoded_Name_String
(Chars
(Body_Id
));
3332 if Subprogram_Name_Greater
3333 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
3335 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
3341 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
3344 end Check_Subprogram_Order;
3346 ------------------------------
3347 -- Check_Subtype_Conformant --
3348 ------------------------------
3350 procedure Check_Subtype_Conformant
3351 (New_Id : Entity_Id;
3353 Err_Loc : Node_Id := Empty)
3358 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc);
3359 end Check_Subtype_Conformant;
3361 ---------------------------
3362 -- Check_Type_Conformant --
3363 ---------------------------
3365 procedure Check_Type_Conformant
3366 (New_Id : Entity_Id;
3368 Err_Loc : Node_Id := Empty)
3373 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
3374 end Check_Type_Conformant;
3376 ----------------------
3377 -- Conforming_Types --
3378 ----------------------
3380 function Conforming_Types
3383 Ctype : Conformance_Type;
3384 Get_Inst : Boolean := False) return Boolean
3386 Type_1 : Entity_Id := T1;
3387 Type_2 : Entity_Id := T2;
3388 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
3390 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean;
3391 -- If neither T1 nor T2 are generic actual types, or if they are
3392 -- in different scopes (e.g. parent and child instances), then verify
3393 -- that the base types are equal. Otherwise T1 and T2 must be
3394 -- on the same subtype chain. The whole purpose of this procedure
3395 -- is to prevent spurious ambiguities in an instantiation that may
3396 -- arise if two distinct generic types are instantiated with the
3399 ----------------------
3400 -- Base_Types_Match --
3401 ----------------------
3403 function Base_Types_Match (T1, T2 : Entity_Id) return Boolean is
3408 elsif Base_Type (T1) = Base_Type (T2) then
3410 -- The following is too permissive. A more precise test must
3411 -- check that the generic actual is an ancestor subtype of the
3414 return not Is_Generic_Actual_Type (T1)
3415 or else not Is_Generic_Actual_Type (T2)
3416 or else Scope (T1) /= Scope (T2);
3418 -- In some cases a type imported through a limited_with clause,
3419 -- and its non-limited view are both visible, for example in an
3420 -- anonymous access_to_classwide type in a formal. Both entities
3421 -- designate the same type.
3423 elsif From_With_Type (T1)
3424 and then Ekind (T1) = E_Incomplete_Type
3425 and then T2 = Non_Limited_View (T1)
3429 elsif From_With_Type (T2)
3430 and then Ekind (T2) = E_Incomplete_Type
3431 and then T1 = Non_Limited_View (T2)
3438 end Base_Types_Match;
3440 -- Start of processing for Conforming_Types
3443 -- The context is an instance association for a formal
3444 -- access-to-subprogram type; the formal parameter types require
3445 -- mapping because they may denote other formal parameters of the
3449 Type_1 := Get_Instance_Of (T1);
3450 Type_2 := Get_Instance_Of (T2);
3453 -- First see if base types match
3455 if Base_Types_Match (Type_1, Type_2) then
3456 return Ctype <= Mode_Conformant
3457 or else Subtypes_Statically_Match (Type_1, Type_2);
3459 elsif Is_Incomplete_Or_Private_Type (Type_1)
3460 and then Present (Full_View (Type_1))
3461 and then Base_Types_Match (Full_View (Type_1), Type_2)
3463 return Ctype <= Mode_Conformant
3464 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
3466 elsif Ekind (Type_2) = E_Incomplete_Type
3467 and then Present (Full_View (Type_2))
3468 and then Base_Types_Match (Type_1, Full_View (Type_2))
3470 return Ctype <= Mode_Conformant
3471 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
3473 elsif Is_Private_Type (Type_2)
3474 and then In_Instance
3475 and then Present (Full_View (Type_2))
3476 and then Base_Types_Match (Type_1, Full_View (Type_2))
3478 return Ctype <= Mode_Conformant
3479 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
3482 -- Ada 2005 (AI-254): Anonymous access to subprogram types must be
3483 -- treated recursively because they carry a signature.
3485 Are_Anonymous_Access_To_Subprogram_Types :=
3487 -- Case 1: Anonymous access to subprogram types
3489 (Ekind (Type_1) = E_Anonymous_Access_Subprogram_Type
3490 and then Ekind (Type_2) = E_Anonymous_Access_Subprogram_Type)
3492 -- Case 2: Anonymous access to PROTECTED subprogram types. In this
3493 -- case the anonymous type_declaration has been replaced by an
3494 -- occurrence of an internal access to subprogram type declaration
3495 -- available through the Original_Access_Type attribute
3498 (Ekind (Type_1) = E_Access_Protected_Subprogram_Type
3499 and then Ekind (Type_2) = E_Access_Protected_Subprogram_Type
3500 and then not Comes_From_Source (Type_1)
3501 and then not Comes_From_Source (Type_2)
3502 and then Present (Original_Access_Type (Type_1))
3503 and then Present (Original_Access_Type (Type_2))
3504 and then Ekind (Original_Access_Type (Type_1)) =
3505 E_Anonymous_Access_Protected_Subprogram_Type
3506 and then Ekind (Original_Access_Type (Type_2)) =
3507 E_Anonymous_Access_Protected_Subprogram_Type);
3509 -- Test anonymous access type case. For this case, static subtype
3510 -- matching is required for mode conformance (RM 6.3.1(15))
3512 if (Ekind (Type_1) = E_Anonymous_Access_Type
3513 and then Ekind (Type_2) = E_Anonymous_Access_Type)
3514 or else Are_Anonymous_Access_To_Subprogram_Types -- Ada 2005 (AI-254)
3517 Desig_1 : Entity_Id;
3518 Desig_2 : Entity_Id;
3521 Desig_1 := Directly_Designated_Type (Type_1);
3523 -- An access parameter can designate an incomplete type
3524 -- If the incomplete type is the limited view of a type
3525 -- from a limited_with_clause, check whether the non-limited
3526 -- view is available.
3528 if Ekind (Desig_1) = E_Incomplete_Type then
3529 if Present (Full_View (Desig_1)) then
3530 Desig_1 := Full_View (Desig_1);
3532 elsif Present (Non_Limited_View (Desig_1)) then
3533 Desig_1 := Non_Limited_View (Desig_1);
3537 Desig_2 := Directly_Designated_Type (Type_2);
3539 if Ekind (Desig_2) = E_Incomplete_Type then
3540 if Present (Full_View (Desig_2)) then
3541 Desig_2 := Full_View (Desig_2);
3542 elsif Present (Non_Limited_View (Desig_2)) then
3543 Desig_2 := Non_Limited_View (Desig_2);
3547 -- The context is an instance association for a formal
3548 -- access-to-subprogram type; formal access parameter designated
3549 -- types require mapping because they may denote other formal
3550 -- parameters of the generic unit.
3553 Desig_1 := Get_Instance_Of (Desig_1);
3554 Desig_2 := Get_Instance_Of (Desig_2);
3557 -- It is possible for a Class_Wide_Type to be introduced for an
3558 -- incomplete type, in which case there is a separate class_ wide
3559 -- type for the full view. The types conform if their Etypes
3560 -- conform, i.e. one may be the full view of the other. This can
3561 -- only happen in the context of an access parameter, other uses
3562 -- of an incomplete Class_Wide_Type are illegal.
3564 if Is_Class_Wide_Type (Desig_1)
3565 and then Is_Class_Wide_Type (Desig_2)
3569 (Etype (Base_Type (Desig_1)),
3570 Etype (Base_Type (Desig_2)), Ctype);
3572 elsif Are_Anonymous_Access_To_Subprogram_Types then
3573 if Ada_Version < Ada_05 then
3574 return Ctype = Type_Conformant
3576 Subtypes_Statically_Match (Desig_1, Desig_2);
3578 -- We must check the conformance of the signatures themselves
3582 Conformant : Boolean;
3585 (Desig_1, Desig_2, Ctype, False, Conformant);
3591 return Base_Type (Desig_1) = Base_Type (Desig_2)
3592 and then (Ctype = Type_Conformant
3594 Subtypes_Statically_Match (Desig_1, Desig_2));
3598 -- Otherwise definitely no match
3603 end Conforming_Types;
3605 --------------------------
3606 -- Create_Extra_Formals --
3607 --------------------------
3609 procedure Create_Extra_Formals (E : Entity_Id) is
3611 Last_Extra : Entity_Id;
3612 Formal_Type : Entity_Id;
3613 P_Formal : Entity_Id := Empty;
3615 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id;
3616 -- Add an extra formal, associated with the current Formal. The extra
3617 -- formal is added to the list of extra formals, and also returned as
3618 -- the result. These formals are always of mode IN.
3620 ----------------------
3621 -- Add_Extra_Formal --
3622 ----------------------
3624 function Add_Extra_Formal (Typ : Entity_Id) return Entity_Id is
3625 EF : constant Entity_Id :=
3626 Make_Defining_Identifier (Sloc (Formal),
3627 Chars => New_External_Name (Chars (Formal), 'F
'));
3630 -- We never generate extra formals if expansion is not active
3631 -- because we don't need them unless we are generating code.
3633 if not Expander_Active then
3637 -- A little optimization. Never generate an extra formal for the
3638 -- _init operand of an initialization procedure, since it could
3641 if Chars (Formal) = Name_uInit then
3645 Set_Ekind (EF, E_In_Parameter);
3646 Set_Actual_Subtype (EF, Typ);
3647 Set_Etype (EF, Typ);
3648 Set_Scope (EF, Scope (Formal));
3649 Set_Mechanism (EF, Default_Mechanism);
3650 Set_Formal_Validity (EF);
3652 Set_Extra_Formal (Last_Extra, EF);
3655 end Add_Extra_Formal;
3657 -- Start of processing for Create_Extra_Formals
3660 -- If this is a derived subprogram then the subtypes of the parent
3661 -- subprogram's formal parameters will be used to to determine the need
3662 -- for extra formals.
3664 if Is_Overloadable (E) and then Present (Alias (E)) then
3665 P_Formal := First_Formal (Alias (E));
3668 Last_Extra := Empty;
3669 Formal := First_Formal (E);
3670 while Present (Formal) loop
3671 Last_Extra := Formal;
3672 Next_Formal (Formal);
3675 -- If Extra_formals where already created, don't do it again. This
3676 -- situation may arise for subprogram types created as part of
3677 -- dispatching calls (see Expand_Dispatching_Call)
3679 if Present (Last_Extra) and then
3680 Present (Extra_Formal (Last_Extra))
3685 Formal := First_Formal (E);
3687 while Present (Formal) loop
3689 -- Create extra formal for supporting the attribute 'Constrained
.
3690 -- The case of a private type view without discriminants also
3691 -- requires the extra formal if the underlying type has defaulted
3694 if Ekind
(Formal
) /= E_In_Parameter
then
3695 if Present
(P_Formal
) then
3696 Formal_Type
:= Etype
(P_Formal
);
3698 Formal_Type
:= Etype
(Formal
);
3701 -- Do not produce extra formals for Unchecked_Union parameters.
3702 -- Jump directly to the end of the loop.
3704 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
3705 goto Skip_Extra_Formal_Generation
;
3708 if not Has_Discriminants
(Formal_Type
)
3709 and then Ekind
(Formal_Type
) in Private_Kind
3710 and then Present
(Underlying_Type
(Formal_Type
))
3712 Formal_Type
:= Underlying_Type
(Formal_Type
);
3715 if Has_Discriminants
(Formal_Type
)
3717 ((not Is_Constrained
(Formal_Type
)
3718 and then not Is_Indefinite_Subtype
(Formal_Type
))
3719 or else Present
(Extra_Formal
(Formal
)))
3721 Set_Extra_Constrained
3722 (Formal
, Add_Extra_Formal
(Standard_Boolean
));
3726 -- Create extra formal for supporting accessibility checking
3728 -- This is suppressed if we specifically suppress accessibility
3729 -- checks at the pacage level for either the subprogram, or the
3730 -- package in which it resides. However, we do not suppress it
3731 -- simply if the scope has accessibility checks suppressed, since
3732 -- this could cause trouble when clients are compiled with a
3733 -- different suppression setting. The explicit checks at the
3734 -- package level are safe from this point of view.
3736 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
3738 (Explicit_Suppress
(E
, Accessibility_Check
)
3740 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
3742 (not Present
(P_Formal
)
3743 or else Present
(Extra_Accessibility
(P_Formal
)))
3745 -- Temporary kludge: for now we avoid creating the extra formal
3746 -- for access parameters of protected operations because of
3747 -- problem with the case of internal protected calls. ???
3749 if Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Definition
3750 and then Nkind
(Parent
(Parent
(Parent
(E
)))) /= N_Protected_Body
3752 Set_Extra_Accessibility
3753 (Formal
, Add_Extra_Formal
(Standard_Natural
));
3757 if Present
(P_Formal
) then
3758 Next_Formal
(P_Formal
);
3761 -- This label is required when skipping extra formal generation for
3762 -- Unchecked_Union parameters.
3764 <<Skip_Extra_Formal_Generation
>>
3766 Next_Formal
(Formal
);
3768 end Create_Extra_Formals
;
3770 -----------------------------
3771 -- Enter_Overloaded_Entity --
3772 -----------------------------
3774 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
3775 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
3776 C_E
: Entity_Id
:= Current_Entity
(S
);
3780 Set_Has_Homonym
(E
);
3781 Set_Has_Homonym
(S
);
3784 Set_Is_Immediately_Visible
(S
);
3785 Set_Scope
(S
, Current_Scope
);
3787 -- Chain new entity if front of homonym in current scope, so that
3788 -- homonyms are contiguous.
3793 while Homonym
(C_E
) /= E
loop
3794 C_E
:= Homonym
(C_E
);
3797 Set_Homonym
(C_E
, S
);
3801 Set_Current_Entity
(S
);
3806 Append_Entity
(S
, Current_Scope
);
3807 Set_Public_Status
(S
);
3809 if Debug_Flag_E
then
3810 Write_Str
("New overloaded entity chain: ");
3811 Write_Name
(Chars
(S
));
3814 while Present
(E
) loop
3815 Write_Str
(" "); Write_Int
(Int
(E
));
3822 -- Generate warning for hiding
3825 and then Comes_From_Source
(S
)
3826 and then In_Extended_Main_Source_Unit
(S
)
3833 -- Warn unless genuine overloading
3835 if (not Is_Overloadable
(E
))
3836 or else Subtype_Conformant
(E
, S
)
3838 Error_Msg_Sloc
:= Sloc
(E
);
3839 Error_Msg_N
("declaration of & hides one#?", S
);
3843 end Enter_Overloaded_Entity
;
3845 -----------------------------
3846 -- Find_Corresponding_Spec --
3847 -----------------------------
3849 function Find_Corresponding_Spec
(N
: Node_Id
) return Entity_Id
is
3850 Spec
: constant Node_Id
:= Specification
(N
);
3851 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
3856 E
:= Current_Entity
(Designator
);
3858 while Present
(E
) loop
3860 -- We are looking for a matching spec. It must have the same scope,
3861 -- and the same name, and either be type conformant, or be the case
3862 -- of a library procedure spec and its body (which belong to one
3863 -- another regardless of whether they are type conformant or not).
3865 if Scope
(E
) = Current_Scope
then
3866 if Current_Scope
= Standard_Standard
3867 or else (Ekind
(E
) = Ekind
(Designator
)
3868 and then Type_Conformant
(E
, Designator
))
3870 -- Within an instantiation, we know that spec and body are
3871 -- subtype conformant, because they were subtype conformant
3872 -- in the generic. We choose the subtype-conformant entity
3873 -- here as well, to resolve spurious ambiguities in the
3874 -- instance that were not present in the generic (i.e. when
3875 -- two different types are given the same actual). If we are
3876 -- looking for a spec to match a body, full conformance is
3880 Set_Convention
(Designator
, Convention
(E
));
3882 if Nkind
(N
) = N_Subprogram_Body
3883 and then Present
(Homonym
(E
))
3884 and then not Fully_Conformant
(E
, Designator
)
3888 elsif not Subtype_Conformant
(E
, Designator
) then
3893 if not Has_Completion
(E
) then
3895 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3896 Set_Corresponding_Spec
(N
, E
);
3899 Set_Has_Completion
(E
);
3902 elsif Nkind
(Parent
(N
)) = N_Subunit
then
3904 -- If this is the proper body of a subunit, the completion
3905 -- flag is set when analyzing the stub.
3909 -- If body already exists, this is an error unless the
3910 -- previous declaration is the implicit declaration of
3911 -- a derived subprogram, or this is a spurious overloading
3914 elsif No
(Alias
(E
))
3915 and then not Is_Intrinsic_Subprogram
(E
)
3916 and then not In_Instance
3918 Error_Msg_Sloc
:= Sloc
(E
);
3919 if Is_Imported
(E
) then
3921 ("body not allowed for imported subprogram & declared#",
3924 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
3928 elsif Is_Child_Unit
(E
)
3930 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
3932 Nkind
(Parent
(Unit_Declaration_Node
(Designator
)))
3933 = N_Compilation_Unit
3936 -- Child units cannot be overloaded, so a conformance mismatch
3937 -- between body and a previous spec is an error.
3940 ("body of child unit does not match previous declaration", N
);
3948 -- On exit, we know that no previous declaration of subprogram exists
3951 end Find_Corresponding_Spec
;
3953 ----------------------
3954 -- Fully_Conformant --
3955 ----------------------
3957 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
3960 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
3962 end Fully_Conformant
;
3964 ----------------------------------
3965 -- Fully_Conformant_Expressions --
3966 ----------------------------------
3968 function Fully_Conformant_Expressions
3969 (Given_E1
: Node_Id
;
3970 Given_E2
: Node_Id
) return Boolean
3972 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
3973 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
3974 -- We always test conformance on original nodes, since it is possible
3975 -- for analysis and/or expansion to make things look as though they
3976 -- conform when they do not, e.g. by converting 1+2 into 3.
3978 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
3979 renames Fully_Conformant_Expressions
;
3981 function FCL
(L1
, L2
: List_Id
) return Boolean;
3982 -- Compare elements of two lists for conformance. Elements have to
3983 -- be conformant, and actuals inserted as default parameters do not
3984 -- match explicit actuals with the same value.
3986 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
3987 -- Compare an operator node with a function call
3993 function FCL
(L1
, L2
: List_Id
) return Boolean is
3997 if L1
= No_List
then
4003 if L2
= No_List
then
4009 -- Compare two lists, skipping rewrite insertions (we want to
4010 -- compare the original trees, not the expanded versions!)
4013 if Is_Rewrite_Insertion
(N1
) then
4015 elsif Is_Rewrite_Insertion
(N2
) then
4021 elsif not FCE
(N1
, N2
) then
4034 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
4035 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
4040 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
4045 Act
:= First
(Actuals
);
4047 if Nkind
(Op_Node
) in N_Binary_Op
then
4049 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
4056 return Present
(Act
)
4057 and then FCE
(Right_Opnd
(Op_Node
), Act
)
4058 and then No
(Next
(Act
));
4062 -- Start of processing for Fully_Conformant_Expressions
4065 -- Non-conformant if paren count does not match. Note: if some idiot
4066 -- complains that we don't do this right for more than 3 levels of
4067 -- parentheses, they will be treated with the respect they deserve :-)
4069 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
4072 -- If same entities are referenced, then they are conformant even if
4073 -- they have different forms (RM 8.3.1(19-20)).
4075 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
4076 if Present
(Entity
(E1
)) then
4077 return Entity
(E1
) = Entity
(E2
)
4078 or else (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
4079 and then Ekind
(Entity
(E1
)) = E_Discriminant
4080 and then Ekind
(Entity
(E2
)) = E_In_Parameter
);
4082 elsif Nkind
(E1
) = N_Expanded_Name
4083 and then Nkind
(E2
) = N_Expanded_Name
4084 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
4085 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
4087 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
4090 -- Identifiers in component associations don't always have
4091 -- entities, but their names must conform.
4093 return Nkind
(E1
) = N_Identifier
4094 and then Nkind
(E2
) = N_Identifier
4095 and then Chars
(E1
) = Chars
(E2
);
4098 elsif Nkind
(E1
) = N_Character_Literal
4099 and then Nkind
(E2
) = N_Expanded_Name
4101 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
4102 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
4104 elsif Nkind
(E2
) = N_Character_Literal
4105 and then Nkind
(E1
) = N_Expanded_Name
4107 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
4108 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
4110 elsif Nkind
(E1
) in N_Op
4111 and then Nkind
(E2
) = N_Function_Call
4113 return FCO
(E1
, E2
);
4115 elsif Nkind
(E2
) in N_Op
4116 and then Nkind
(E1
) = N_Function_Call
4118 return FCO
(E2
, E1
);
4120 -- Otherwise we must have the same syntactic entity
4122 elsif Nkind
(E1
) /= Nkind
(E2
) then
4125 -- At this point, we specialize by node type
4132 FCL
(Expressions
(E1
), Expressions
(E2
))
4133 and then FCL
(Component_Associations
(E1
),
4134 Component_Associations
(E2
));
4137 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
4139 Nkind
(Expression
(E2
)) = N_Qualified_Expression
4141 return FCE
(Expression
(E1
), Expression
(E2
));
4143 -- Check that the subtype marks and any constraints
4148 Indic1
: constant Node_Id
:= Expression
(E1
);
4149 Indic2
: constant Node_Id
:= Expression
(E2
);
4154 if Nkind
(Indic1
) /= N_Subtype_Indication
then
4156 Nkind
(Indic2
) /= N_Subtype_Indication
4157 and then Entity
(Indic1
) = Entity
(Indic2
);
4159 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
4161 Nkind
(Indic1
) /= N_Subtype_Indication
4162 and then Entity
(Indic1
) = Entity
(Indic2
);
4165 if Entity
(Subtype_Mark
(Indic1
)) /=
4166 Entity
(Subtype_Mark
(Indic2
))
4171 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
4172 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
4174 while Present
(Elt1
) and then Present
(Elt2
) loop
4175 if not FCE
(Elt1
, Elt2
) then
4188 when N_Attribute_Reference
=>
4190 Attribute_Name
(E1
) = Attribute_Name
(E2
)
4191 and then FCL
(Expressions
(E1
), Expressions
(E2
));
4195 Entity
(E1
) = Entity
(E2
)
4196 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
4197 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
4199 when N_And_Then | N_Or_Else | N_In | N_Not_In
=>
4201 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
4203 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
4205 when N_Character_Literal
=>
4207 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
4209 when N_Component_Association
=>
4211 FCL
(Choices
(E1
), Choices
(E2
))
4212 and then FCE
(Expression
(E1
), Expression
(E2
));
4214 when N_Conditional_Expression
=>
4216 FCL
(Expressions
(E1
), Expressions
(E2
));
4218 when N_Explicit_Dereference
=>
4220 FCE
(Prefix
(E1
), Prefix
(E2
));
4222 when N_Extension_Aggregate
=>
4224 FCL
(Expressions
(E1
), Expressions
(E2
))
4225 and then Null_Record_Present
(E1
) =
4226 Null_Record_Present
(E2
)
4227 and then FCL
(Component_Associations
(E1
),
4228 Component_Associations
(E2
));
4230 when N_Function_Call
=>
4232 FCE
(Name
(E1
), Name
(E2
))
4233 and then FCL
(Parameter_Associations
(E1
),
4234 Parameter_Associations
(E2
));
4236 when N_Indexed_Component
=>
4238 FCE
(Prefix
(E1
), Prefix
(E2
))
4239 and then FCL
(Expressions
(E1
), Expressions
(E2
));
4241 when N_Integer_Literal
=>
4242 return (Intval
(E1
) = Intval
(E2
));
4247 when N_Operator_Symbol
=>
4249 Chars
(E1
) = Chars
(E2
);
4251 when N_Others_Choice
=>
4254 when N_Parameter_Association
=>
4256 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
4257 and then FCE
(Explicit_Actual_Parameter
(E1
),
4258 Explicit_Actual_Parameter
(E2
));
4260 when N_Qualified_Expression
=>
4262 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
4263 and then FCE
(Expression
(E1
), Expression
(E2
));
4267 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
4268 and then FCE
(High_Bound
(E1
), High_Bound
(E2
));
4270 when N_Real_Literal
=>
4271 return (Realval
(E1
) = Realval
(E2
));
4273 when N_Selected_Component
=>
4275 FCE
(Prefix
(E1
), Prefix
(E2
))
4276 and then FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
4280 FCE
(Prefix
(E1
), Prefix
(E2
))
4281 and then FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
4283 when N_String_Literal
=>
4285 S1
: constant String_Id
:= Strval
(E1
);
4286 S2
: constant String_Id
:= Strval
(E2
);
4287 L1
: constant Nat
:= String_Length
(S1
);
4288 L2
: constant Nat
:= String_Length
(S2
);
4295 for J
in 1 .. L1
loop
4296 if Get_String_Char
(S1
, J
) /=
4297 Get_String_Char
(S2
, J
)
4307 when N_Type_Conversion
=>
4309 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
4310 and then FCE
(Expression
(E1
), Expression
(E2
));
4314 Entity
(E1
) = Entity
(E2
)
4315 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
4317 when N_Unchecked_Type_Conversion
=>
4319 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
4320 and then FCE
(Expression
(E1
), Expression
(E2
));
4322 -- All other node types cannot appear in this context. Strictly
4323 -- we should raise a fatal internal error. Instead we just ignore
4324 -- the nodes. This means that if anyone makes a mistake in the
4325 -- expander and mucks an expression tree irretrievably, the
4326 -- result will be a failure to detect a (probably very obscure)
4327 -- case of non-conformance, which is better than bombing on some
4328 -- case where two expressions do in fact conform.
4335 end Fully_Conformant_Expressions
;
4337 ----------------------------------------
4338 -- Fully_Conformant_Discrete_Subtypes --
4339 ----------------------------------------
4341 function Fully_Conformant_Discrete_Subtypes
4342 (Given_S1
: Node_Id
;
4343 Given_S2
: Node_Id
) return Boolean
4345 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
4346 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
4348 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
4349 -- Special-case for a bound given by a discriminant, which in the body
4350 -- is replaced with the discriminal of the enclosing type.
4352 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
4353 -- Check both bounds
4355 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
4357 if Is_Entity_Name
(B1
)
4358 and then Is_Entity_Name
(B2
)
4359 and then Ekind
(Entity
(B1
)) = E_Discriminant
4361 return Chars
(B1
) = Chars
(B2
);
4364 return Fully_Conformant_Expressions
(B1
, B2
);
4366 end Conforming_Bounds
;
4368 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
4371 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
4373 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
4374 end Conforming_Ranges
;
4376 -- Start of processing for Fully_Conformant_Discrete_Subtypes
4379 if Nkind
(S1
) /= Nkind
(S2
) then
4382 elsif Is_Entity_Name
(S1
) then
4383 return Entity
(S1
) = Entity
(S2
);
4385 elsif Nkind
(S1
) = N_Range
then
4386 return Conforming_Ranges
(S1
, S2
);
4388 elsif Nkind
(S1
) = N_Subtype_Indication
then
4390 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
4393 (Range_Expression
(Constraint
(S1
)),
4394 Range_Expression
(Constraint
(S2
)));
4398 end Fully_Conformant_Discrete_Subtypes
;
4400 --------------------
4401 -- Install_Entity --
4402 --------------------
4404 procedure Install_Entity
(E
: Entity_Id
) is
4405 Prev
: constant Entity_Id
:= Current_Entity
(E
);
4408 Set_Is_Immediately_Visible
(E
);
4409 Set_Current_Entity
(E
);
4410 Set_Homonym
(E
, Prev
);
4413 ---------------------
4414 -- Install_Formals --
4415 ---------------------
4417 procedure Install_Formals
(Id
: Entity_Id
) is
4421 F
:= First_Formal
(Id
);
4423 while Present
(F
) loop
4427 end Install_Formals
;
4429 ---------------------------------
4430 -- Is_Non_Overriding_Operation --
4431 ---------------------------------
4433 function Is_Non_Overriding_Operation
4434 (Prev_E
: Entity_Id
;
4435 New_E
: Entity_Id
) return Boolean
4439 G_Typ
: Entity_Id
:= Empty
;
4441 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
4442 -- If F_Type is a derived type associated with a generic actual
4443 -- subtype, then return its Generic_Parent_Type attribute, else return
4446 function Types_Correspond
4447 (P_Type
: Entity_Id
;
4448 N_Type
: Entity_Id
) return Boolean;
4449 -- Returns true if and only if the types (or designated types in the
4450 -- case of anonymous access types) are the same or N_Type is derived
4451 -- directly or indirectly from P_Type.
4453 -----------------------------
4454 -- Get_Generic_Parent_Type --
4455 -----------------------------
4457 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
4462 if Is_Derived_Type
(F_Typ
)
4463 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
4465 -- The tree must be traversed to determine the parent subtype in
4466 -- the generic unit, which unfortunately isn't always available
4467 -- via semantic attributes. ??? (Note: The use of Original_Node
4468 -- is needed for cases where a full derived type has been
4471 Indic
:= Subtype_Indication
4472 (Type_Definition
(Original_Node
(Parent
(F_Typ
))));
4474 if Nkind
(Indic
) = N_Subtype_Indication
then
4475 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
4477 G_Typ
:= Entity
(Indic
);
4480 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
4481 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
4483 return Generic_Parent_Type
(Parent
(G_Typ
));
4488 end Get_Generic_Parent_Type
;
4490 ----------------------
4491 -- Types_Correspond --
4492 ----------------------
4494 function Types_Correspond
4495 (P_Type
: Entity_Id
;
4496 N_Type
: Entity_Id
) return Boolean
4498 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
4499 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
4502 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
4503 Prev_Type
:= Designated_Type
(Prev_Type
);
4506 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
4507 New_Type
:= Designated_Type
(New_Type
);
4510 if Prev_Type
= New_Type
then
4513 elsif not Is_Class_Wide_Type
(New_Type
) then
4514 while Etype
(New_Type
) /= New_Type
loop
4515 New_Type
:= Etype
(New_Type
);
4516 if New_Type
= Prev_Type
then
4522 end Types_Correspond
;
4524 -- Start of processing for Is_Non_Overriding_Operation
4527 -- In the case where both operations are implicit derived subprograms
4528 -- then neither overrides the other. This can only occur in certain
4529 -- obscure cases (e.g., derivation from homographs created in a generic
4532 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
4535 elsif Ekind
(Current_Scope
) = E_Package
4536 and then Is_Generic_Instance
(Current_Scope
)
4537 and then In_Private_Part
(Current_Scope
)
4538 and then Comes_From_Source
(New_E
)
4540 -- We examine the formals and result subtype of the inherited
4541 -- operation, to determine whether their type is derived from (the
4542 -- instance of) a generic type.
4544 Formal
:= First_Formal
(Prev_E
);
4546 while Present
(Formal
) loop
4547 F_Typ
:= Base_Type
(Etype
(Formal
));
4549 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4550 F_Typ
:= Designated_Type
(F_Typ
);
4553 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
4555 Next_Formal
(Formal
);
4558 if not Present
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
4559 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
4566 -- If the generic type is a private type, then the original
4567 -- operation was not overriding in the generic, because there was
4568 -- no primitive operation to override.
4570 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
4571 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
4572 N_Formal_Private_Type_Definition
4576 -- The generic parent type is the ancestor of a formal derived
4577 -- type declaration. We need to check whether it has a primitive
4578 -- operation that should be overridden by New_E in the generic.
4582 P_Formal
: Entity_Id
;
4583 N_Formal
: Entity_Id
;
4587 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
4590 while Present
(Prim_Elt
) loop
4591 P_Prim
:= Node
(Prim_Elt
);
4593 if Chars
(P_Prim
) = Chars
(New_E
)
4594 and then Ekind
(P_Prim
) = Ekind
(New_E
)
4596 P_Formal
:= First_Formal
(P_Prim
);
4597 N_Formal
:= First_Formal
(New_E
);
4598 while Present
(P_Formal
) and then Present
(N_Formal
) loop
4599 P_Typ
:= Etype
(P_Formal
);
4600 N_Typ
:= Etype
(N_Formal
);
4602 if not Types_Correspond
(P_Typ
, N_Typ
) then
4606 Next_Entity
(P_Formal
);
4607 Next_Entity
(N_Formal
);
4610 -- Found a matching primitive operation belonging to the
4611 -- formal ancestor type, so the new subprogram is
4614 if not Present
(P_Formal
)
4615 and then not Present
(N_Formal
)
4616 and then (Ekind
(New_E
) /= E_Function
4619 (Etype
(P_Prim
), Etype
(New_E
)))
4625 Next_Elmt
(Prim_Elt
);
4628 -- If no match found, then the new subprogram does not
4629 -- override in the generic (nor in the instance).
4637 end Is_Non_Overriding_Operation
;
4639 ------------------------------
4640 -- Make_Inequality_Operator --
4641 ------------------------------
4643 -- S is the defining identifier of an equality operator. We build a
4644 -- subprogram declaration with the right signature. This operation is
4645 -- intrinsic, because it is always expanded as the negation of the
4646 -- call to the equality function.
4648 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
4649 Loc
: constant Source_Ptr
:= Sloc
(S
);
4652 Op_Name
: Entity_Id
;
4658 -- Check that equality was properly defined
4660 if No
(Next_Formal
(First_Formal
(S
))) then
4664 A
:= Make_Defining_Identifier
(Loc
, Chars
(First_Formal
(S
)));
4665 B
:= Make_Defining_Identifier
(Loc
,
4666 Chars
(Next_Formal
(First_Formal
(S
))));
4668 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
4670 Formals
:= New_List
(
4671 Make_Parameter_Specification
(Loc
,
4672 Defining_Identifier
=> A
,
4674 New_Reference_To
(Etype
(First_Formal
(S
)), Loc
)),
4676 Make_Parameter_Specification
(Loc
,
4677 Defining_Identifier
=> B
,
4679 New_Reference_To
(Etype
(Next_Formal
(First_Formal
(S
))), Loc
)));
4682 Make_Subprogram_Declaration
(Loc
,
4684 Make_Function_Specification
(Loc
,
4685 Defining_Unit_Name
=> Op_Name
,
4686 Parameter_Specifications
=> Formals
,
4687 Result_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
)));
4689 -- Insert inequality right after equality if it is explicit or after
4690 -- the derived type when implicit. These entities are created only for
4691 -- visibility purposes, and eventually replaced in the course of
4692 -- expansion, so they do not need to be attached to the tree and seen
4693 -- by the back-end. Keeping them internal also avoids spurious freezing
4694 -- problems. The declaration is inserted in the tree for analysis, and
4695 -- removed afterwards. If the equality operator comes from an explicit
4696 -- declaration, attach the inequality immediately after. Else the
4697 -- equality is inherited from a derived type declaration, so insert
4698 -- inequality after that declaration.
4700 if No
(Alias
(S
)) then
4701 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
4702 elsif Is_List_Member
(Parent
(S
)) then
4703 Insert_After
(Parent
(S
), Decl
);
4705 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
4708 Mark_Rewrite_Insertion
(Decl
);
4709 Set_Is_Intrinsic_Subprogram
(Op_Name
);
4712 Set_Has_Completion
(Op_Name
);
4713 Set_Corresponding_Equality
(Op_Name
, S
);
4714 Set_Is_Abstract
(Op_Name
, Is_Abstract
(S
));
4715 end Make_Inequality_Operator
;
4717 ----------------------
4718 -- May_Need_Actuals --
4719 ----------------------
4721 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
4726 F
:= First_Formal
(Fun
);
4729 while Present
(F
) loop
4730 if No
(Default_Value
(F
)) then
4738 Set_Needs_No_Actuals
(Fun
, B
);
4739 end May_Need_Actuals
;
4741 ---------------------
4742 -- Mode_Conformant --
4743 ---------------------
4745 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
4748 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
4750 end Mode_Conformant
;
4752 ---------------------------
4753 -- New_Overloaded_Entity --
4754 ---------------------------
4756 procedure New_Overloaded_Entity
4758 Derived_Type
: Entity_Id
:= Empty
)
4760 Does_Override
: Boolean := False;
4761 -- Set if the current scope has an operation that is type-conformant
4762 -- with S, and becomes hidden by S.
4765 -- Entity that S overrides
4767 Prev_Vis
: Entity_Id
:= Empty
;
4768 -- Needs comment ???
4770 Is_Alias_Interface
: Boolean := False;
4772 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
4773 -- Check that E is declared in the private part of the current package,
4774 -- or in the package body, where it may hide a previous declaration.
4775 -- We can't use In_Private_Part by itself because this flag is also
4776 -- set when freezing entities, so we must examine the place of the
4777 -- declaration in the tree, and recognize wrapper packages as well.
4779 procedure Maybe_Primitive_Operation
(Is_Overriding
: Boolean := False);
4780 -- If the subprogram being analyzed is a primitive operation of
4781 -- the type of one of its formals, set the corresponding flag.
4783 ----------------------------
4784 -- Is_Private_Declaration --
4785 ----------------------------
4787 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
4788 Priv_Decls
: List_Id
;
4789 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
4792 if Is_Package_Or_Generic_Package
(Current_Scope
)
4793 and then In_Private_Part
(Current_Scope
)
4796 Private_Declarations
(
4797 Specification
(Unit_Declaration_Node
(Current_Scope
)));
4799 return In_Package_Body
(Current_Scope
)
4801 (Is_List_Member
(Decl
)
4802 and then List_Containing
(Decl
) = Priv_Decls
)
4803 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
4804 and then not Is_Compilation_Unit
(
4805 Defining_Entity
(Parent
(Decl
)))
4806 and then List_Containing
(Parent
(Parent
(Decl
)))
4811 end Is_Private_Declaration
;
4813 -------------------------------
4814 -- Maybe_Primitive_Operation --
4815 -------------------------------
4817 procedure Maybe_Primitive_Operation
(Is_Overriding
: Boolean := False) is
4822 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
4823 -- Returns true if T is declared in the visible part of
4824 -- the current package scope; otherwise returns false.
4825 -- Assumes that T is declared in a package.
4827 procedure Check_Private_Overriding
(T
: Entity_Id
);
4828 -- Checks that if a primitive abstract subprogram of a visible
4829 -- abstract type is declared in a private part, then it must
4830 -- override an abstract subprogram declared in the visible part.
4831 -- Also checks that if a primitive function with a controlling
4832 -- result is declared in a private part, then it must override
4833 -- a function declared in the visible part.
4835 ------------------------------
4836 -- Check_Private_Overriding --
4837 ------------------------------
4839 procedure Check_Private_Overriding
(T
: Entity_Id
) is
4841 if Ekind
(Current_Scope
) = E_Package
4842 and then In_Private_Part
(Current_Scope
)
4843 and then Visible_Part_Type
(T
)
4844 and then not In_Instance
4847 and then Is_Abstract
(S
)
4848 and then (not Is_Overriding
or else not Is_Abstract
(E
))
4850 if not Is_Interface
(T
) then
4851 Error_Msg_N
("abstract subprograms must be visible "
4852 & "('R'M 3.9.3(10))!", S
);
4854 -- Ada 2005 (AI-251)
4857 Error_Msg_N
("primitive subprograms of interface types "
4858 & "declared in a visible part, must be declared in "
4859 & "the visible part ('R'M 3.9.4)!", S
);
4862 elsif Ekind
(S
) = E_Function
4863 and then Is_Tagged_Type
(T
)
4864 and then T
= Base_Type
(Etype
(S
))
4865 and then not Is_Overriding
4868 ("private function with tagged result must"
4869 & " override visible-part function", S
);
4871 ("\move subprogram to the visible part"
4872 & " ('R'M 3.9.3(10))", S
);
4875 end Check_Private_Overriding
;
4877 -----------------------
4878 -- Visible_Part_Type --
4879 -----------------------
4881 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
4882 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
4886 -- If the entity is a private type, then it must be
4887 -- declared in a visible part.
4889 if Ekind
(T
) in Private_Kind
then
4893 -- Otherwise, we traverse the visible part looking for its
4894 -- corresponding declaration. We cannot use the declaration
4895 -- node directly because in the private part the entity of a
4896 -- private type is the one in the full view, which does not
4897 -- indicate that it is the completion of something visible.
4899 N
:= First
(Visible_Declarations
(Specification
(P
)));
4900 while Present
(N
) loop
4901 if Nkind
(N
) = N_Full_Type_Declaration
4902 and then Present
(Defining_Identifier
(N
))
4903 and then T
= Defining_Identifier
(N
)
4907 elsif (Nkind
(N
) = N_Private_Type_Declaration
4909 Nkind
(N
) = N_Private_Extension_Declaration
)
4910 and then Present
(Defining_Identifier
(N
))
4911 and then T
= Full_View
(Defining_Identifier
(N
))
4920 end Visible_Part_Type
;
4922 -- Start of processing for Maybe_Primitive_Operation
4925 if not Comes_From_Source
(S
) then
4928 -- If the subprogram is at library level, it is not primitive
4931 elsif Current_Scope
= Standard_Standard
then
4934 elsif (Ekind
(Current_Scope
) = E_Package
4935 and then not In_Package_Body
(Current_Scope
))
4936 or else Is_Overriding
4938 -- For function, check return type
4940 if Ekind
(S
) = E_Function
then
4941 B_Typ
:= Base_Type
(Etype
(S
));
4943 if Scope
(B_Typ
) = Current_Scope
then
4944 Set_Has_Primitive_Operations
(B_Typ
);
4945 Check_Private_Overriding
(B_Typ
);
4949 -- For all subprograms, check formals
4951 Formal
:= First_Formal
(S
);
4952 while Present
(Formal
) loop
4953 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
4954 F_Typ
:= Designated_Type
(Etype
(Formal
));
4956 F_Typ
:= Etype
(Formal
);
4959 B_Typ
:= Base_Type
(F_Typ
);
4961 if Scope
(B_Typ
) = Current_Scope
then
4962 Set_Has_Primitive_Operations
(B_Typ
);
4963 Check_Private_Overriding
(B_Typ
);
4966 Next_Formal
(Formal
);
4969 end Maybe_Primitive_Operation
;
4971 -- Start of processing for New_Overloaded_Entity
4974 -- We need to look for an entity that S may override. This must be a
4975 -- homonym in the current scope, so we look for the first homonym of
4976 -- S in the current scope as the starting point for the search.
4978 E
:= Current_Entity_In_Scope
(S
);
4980 -- If there is no homonym then this is definitely not overriding
4983 Enter_Overloaded_Entity
(S
);
4984 Check_Dispatching_Operation
(S
, Empty
);
4985 Maybe_Primitive_Operation
;
4987 -- Ada 2005 (AI-397): Subprograms in the context of protected
4988 -- types have their overriding indicators checked in Sem_Ch9.
4990 if Ekind
(S
) not in Subprogram_Kind
4991 or else Ekind
(Scope
(S
)) /= E_Protected_Type
4993 Check_Overriding_Indicator
(S
, False);
4996 -- If there is a homonym that is not overloadable, then we have an
4997 -- error, except for the special cases checked explicitly below.
4999 elsif not Is_Overloadable
(E
) then
5001 -- Check for spurious conflict produced by a subprogram that has the
5002 -- same name as that of the enclosing generic package. The conflict
5003 -- occurs within an instance, between the subprogram and the renaming
5004 -- declaration for the package. After the subprogram, the package
5005 -- renaming declaration becomes hidden.
5007 if Ekind
(E
) = E_Package
5008 and then Present
(Renamed_Object
(E
))
5009 and then Renamed_Object
(E
) = Current_Scope
5010 and then Nkind
(Parent
(Renamed_Object
(E
))) =
5011 N_Package_Specification
5012 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
5015 Set_Is_Immediately_Visible
(E
, False);
5016 Enter_Overloaded_Entity
(S
);
5017 Set_Homonym
(S
, Homonym
(E
));
5018 Check_Dispatching_Operation
(S
, Empty
);
5019 Check_Overriding_Indicator
(S
, False);
5021 -- If the subprogram is implicit it is hidden by the previous
5022 -- declaration. However if it is dispatching, it must appear in the
5023 -- dispatch table anyway, because it can be dispatched to even if it
5024 -- cannot be called directly.
5026 elsif Present
(Alias
(S
))
5027 and then not Comes_From_Source
(S
)
5029 Set_Scope
(S
, Current_Scope
);
5031 if Is_Dispatching_Operation
(Alias
(S
)) then
5032 Check_Dispatching_Operation
(S
, Empty
);
5038 Error_Msg_Sloc
:= Sloc
(E
);
5039 Error_Msg_N
("& conflicts with declaration#", S
);
5041 -- Useful additional warning
5043 if Is_Generic_Unit
(E
) then
5044 Error_Msg_N
("\previous generic unit cannot be overloaded", S
);
5050 -- E exists and is overloadable
5053 Is_Alias_Interface
:=
5055 and then Is_Dispatching_Operation
(Alias
(S
))
5056 and then Present
(DTC_Entity
(Alias
(S
)))
5057 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(S
))));
5059 -- Loop through E and its homonyms to determine if any of them is
5060 -- the candidate for overriding by S.
5062 while Present
(E
) loop
5064 -- Definitely not interesting if not in the current scope
5066 if Scope
(E
) /= Current_Scope
then
5069 -- Check if we have type conformance
5071 -- Ada 2005 (AI-251): In case of overriding an interface
5072 -- subprogram it is not an error that the old and new entities
5073 -- have the same profile, and hence we skip this code.
5075 elsif not Is_Alias_Interface
5076 and then Type_Conformant
(E
, S
)
5078 -- If the old and new entities have the same profile and one
5079 -- is not the body of the other, then this is an error, unless
5080 -- one of them is implicitly declared.
5082 -- There are some cases when both can be implicit, for example
5083 -- when both a literal and a function that overrides it are
5084 -- inherited in a derivation, or when an inhertited operation
5085 -- of a tagged full type overrides the ineherited operation of
5086 -- a private extension. Ada 83 had a special rule for the the
5087 -- literal case. In Ada95, the later implicit operation hides
5088 -- the former, and the literal is always the former. In the
5089 -- odd case where both are derived operations declared at the
5090 -- same point, both operations should be declared, and in that
5091 -- case we bypass the following test and proceed to the next
5092 -- part (this can only occur for certain obscure cases
5093 -- involving homographs in instances and can't occur for
5094 -- dispatching operations ???). Note that the following
5095 -- condition is less than clear. For example, it's not at all
5096 -- clear why there's a test for E_Entry here. ???
5098 if Present
(Alias
(S
))
5099 and then (No
(Alias
(E
))
5100 or else Comes_From_Source
(E
)
5101 or else Is_Dispatching_Operation
(E
))
5103 (Ekind
(E
) = E_Entry
5104 or else Ekind
(E
) /= E_Enumeration_Literal
)
5106 -- When an derived operation is overloaded it may be due to
5107 -- the fact that the full view of a private extension
5108 -- re-inherits. It has to be dealt with.
5110 if Is_Package_Or_Generic_Package
(Current_Scope
)
5111 and then In_Private_Part
(Current_Scope
)
5113 Check_Operation_From_Private_View
(S
, E
);
5116 -- In any case the implicit operation remains hidden by
5117 -- the existing declaration, which is overriding.
5119 Set_Is_Overriding_Operation
(E
);
5121 if Comes_From_Source
(E
) then
5122 Check_Overriding_Indicator
(E
, True);
5124 -- Indicate that E overrides the operation from which
5127 if Present
(Alias
(S
)) then
5128 Set_Overridden_Operation
(E
, Alias
(S
));
5130 Set_Overridden_Operation
(E
, S
);
5136 -- Within an instance, the renaming declarations for
5137 -- actual subprograms may become ambiguous, but they do
5138 -- not hide each other.
5140 elsif Ekind
(E
) /= E_Entry
5141 and then not Comes_From_Source
(E
)
5142 and then not Is_Generic_Instance
(E
)
5143 and then (Present
(Alias
(E
))
5144 or else Is_Intrinsic_Subprogram
(E
))
5145 and then (not In_Instance
5146 or else No
(Parent
(E
))
5147 or else Nkind
(Unit_Declaration_Node
(E
)) /=
5148 N_Subprogram_Renaming_Declaration
)
5150 -- A subprogram child unit is not allowed to override
5151 -- an inherited subprogram (10.1.1(20)).
5153 if Is_Child_Unit
(S
) then
5155 ("child unit overrides inherited subprogram in parent",
5160 if Is_Non_Overriding_Operation
(E
, S
) then
5161 Enter_Overloaded_Entity
(S
);
5162 if not Present
(Derived_Type
)
5163 or else Is_Tagged_Type
(Derived_Type
)
5165 Check_Dispatching_Operation
(S
, Empty
);
5171 -- E is a derived operation or an internal operator which
5172 -- is being overridden. Remove E from further visibility.
5173 -- Furthermore, if E is a dispatching operation, it must be
5174 -- replaced in the list of primitive operations of its type
5175 -- (see Override_Dispatching_Operation).
5177 Does_Override
:= True;
5183 Prev
:= First_Entity
(Current_Scope
);
5185 while Present
(Prev
)
5186 and then Next_Entity
(Prev
) /= E
5191 -- It is possible for E to be in the current scope and
5192 -- yet not in the entity chain. This can only occur in a
5193 -- generic context where E is an implicit concatenation
5194 -- in the formal part, because in a generic body the
5195 -- entity chain starts with the formals.
5198 (Present
(Prev
) or else Chars
(E
) = Name_Op_Concat
);
5200 -- E must be removed both from the entity_list of the
5201 -- current scope, and from the visibility chain
5203 if Debug_Flag_E
then
5204 Write_Str
("Override implicit operation ");
5205 Write_Int
(Int
(E
));
5209 -- If E is a predefined concatenation, it stands for four
5210 -- different operations. As a result, a single explicit
5211 -- declaration does not hide it. In a possible ambiguous
5212 -- situation, Disambiguate chooses the user-defined op,
5213 -- so it is correct to retain the previous internal one.
5215 if Chars
(E
) /= Name_Op_Concat
5216 or else Ekind
(E
) /= E_Operator
5218 -- For nondispatching derived operations that are
5219 -- overridden by a subprogram declared in the private
5220 -- part of a package, we retain the derived
5221 -- subprogram but mark it as not immediately visible.
5222 -- If the derived operation was declared in the
5223 -- visible part then this ensures that it will still
5224 -- be visible outside the package with the proper
5225 -- signature (calls from outside must also be
5226 -- directed to this version rather than the
5227 -- overriding one, unlike the dispatching case).
5228 -- Calls from inside the package will still resolve
5229 -- to the overriding subprogram since the derived one
5230 -- is marked as not visible within the package.
5232 -- If the private operation is dispatching, we achieve
5233 -- the overriding by keeping the implicit operation
5234 -- but setting its alias to be the overriding one. In
5235 -- this fashion the proper body is executed in all
5236 -- cases, but the original signature is used outside
5239 -- If the overriding is not in the private part, we
5240 -- remove the implicit operation altogether.
5242 if Is_Private_Declaration
(S
) then
5244 if not Is_Dispatching_Operation
(E
) then
5245 Set_Is_Immediately_Visible
(E
, False);
5247 -- Work done in Override_Dispatching_Operation,
5248 -- so nothing else need to be done here.
5254 -- Find predecessor of E in Homonym chain
5256 if E
= Current_Entity
(E
) then
5259 Prev_Vis
:= Current_Entity
(E
);
5260 while Homonym
(Prev_Vis
) /= E
loop
5261 Prev_Vis
:= Homonym
(Prev_Vis
);
5265 if Prev_Vis
/= Empty
then
5267 -- Skip E in the visibility chain
5269 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5272 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5275 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5277 if No
(Next_Entity
(Prev
)) then
5278 Set_Last_Entity
(Current_Scope
, Prev
);
5284 Enter_Overloaded_Entity
(S
);
5285 Set_Is_Overriding_Operation
(S
);
5286 Check_Overriding_Indicator
(S
, True);
5288 -- Indicate that S overrides the operation from which
5291 if Comes_From_Source
(S
) then
5292 if Present
(Alias
(E
)) then
5293 Set_Overridden_Operation
(S
, Alias
(E
));
5295 Set_Overridden_Operation
(S
, E
);
5299 if Is_Dispatching_Operation
(E
) then
5301 -- An overriding dispatching subprogram inherits the
5302 -- convention of the overridden subprogram (by
5305 Set_Convention
(S
, Convention
(E
));
5307 -- AI-251: For an entity overriding an interface
5308 -- primitive check if the entity also covers other
5309 -- abstract subprograms in the same scope. This is
5310 -- required to handle the general case, that is,
5311 -- 1) overriding other interface primitives, and
5312 -- 2) overriding abstract subprograms inherited from
5313 -- some abstract ancestor type.
5316 and then Present
(Alias
(E
))
5317 and then Ekind
(Alias
(E
)) /= E_Operator
5318 and then Present
(DTC_Entity
(Alias
(E
)))
5319 and then Is_Interface
(Scope
(DTC_Entity
5327 while Present
(E1
) loop
5328 if (Is_Overloadable
(E1
)
5329 or else Ekind
(E1
) = E_Subprogram_Type
)
5330 and then Present
(Alias
(E1
))
5331 and then Ekind
(Alias
(E1
)) /= E_Operator
5332 and then Present
(DTC_Entity
(Alias
(E1
)))
5333 and then Is_Abstract
5334 (Scope
(DTC_Entity
(Alias
(E1
))))
5335 and then Type_Conformant
(E1
, S
)
5337 Check_Dispatching_Operation
(S
, E1
);
5345 Check_Dispatching_Operation
(S
, E
);
5348 Check_Dispatching_Operation
(S
, Empty
);
5351 Maybe_Primitive_Operation
(Is_Overriding
=> True);
5352 goto Check_Inequality
;
5355 -- Apparent redeclarations in instances can occur when two
5356 -- formal types get the same actual type. The subprograms in
5357 -- in the instance are legal, even if not callable from the
5358 -- outside. Calls from within are disambiguated elsewhere.
5359 -- For dispatching operations in the visible part, the usual
5360 -- rules apply, and operations with the same profile are not
5363 elsif (In_Instance_Visible_Part
5364 and then not Is_Dispatching_Operation
(E
))
5365 or else In_Instance_Not_Visible
5369 -- Here we have a real error (identical profile)
5372 Error_Msg_Sloc
:= Sloc
(E
);
5374 -- Avoid cascaded errors if the entity appears in
5375 -- subsequent calls.
5377 Set_Scope
(S
, Current_Scope
);
5379 Error_Msg_N
("& conflicts with declaration#", S
);
5381 if Is_Generic_Instance
(S
)
5382 and then not Has_Completion
(E
)
5385 ("\instantiation cannot provide body for it", S
);
5399 -- On exit, we know that S is a new entity
5401 Enter_Overloaded_Entity
(S
);
5402 Maybe_Primitive_Operation
;
5403 Check_Overriding_Indicator
(S
, Does_Override
);
5405 -- If S is a derived operation for an untagged type then by
5406 -- definition it's not a dispatching operation (even if the parent
5407 -- operation was dispatching), so we don't call
5408 -- Check_Dispatching_Operation in that case.
5410 if not Present
(Derived_Type
)
5411 or else Is_Tagged_Type
(Derived_Type
)
5413 Check_Dispatching_Operation
(S
, Empty
);
5417 -- If this is a user-defined equality operator that is not a derived
5418 -- subprogram, create the corresponding inequality. If the operation is
5419 -- dispatching, the expansion is done elsewhere, and we do not create
5420 -- an explicit inequality operation.
5422 <<Check_Inequality
>>
5423 if Chars
(S
) = Name_Op_Eq
5424 and then Etype
(S
) = Standard_Boolean
5425 and then Present
(Parent
(S
))
5426 and then not Is_Dispatching_Operation
(S
)
5428 Make_Inequality_Operator
(S
);
5430 end New_Overloaded_Entity
;
5432 ---------------------
5433 -- Process_Formals --
5434 ---------------------
5436 procedure Process_Formals
5438 Related_Nod
: Node_Id
)
5440 Param_Spec
: Node_Id
;
5442 Formal_Type
: Entity_Id
;
5446 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
5447 -- Check whether the default has a class-wide type. After analysis the
5448 -- default has the type of the formal, so we must also check explicitly
5449 -- for an access attribute.
5451 ---------------------------
5452 -- Is_Class_Wide_Default --
5453 ---------------------------
5455 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
5457 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
5458 or else (Nkind
(D
) = N_Attribute_Reference
5459 and then Attribute_Name
(D
) = Name_Access
5460 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
5461 end Is_Class_Wide_Default
;
5463 -- Start of processing for Process_Formals
5466 -- In order to prevent premature use of the formals in the same formal
5467 -- part, the Ekind is left undefined until all default expressions are
5468 -- analyzed. The Ekind is established in a separate loop at the end.
5470 Param_Spec
:= First
(T
);
5472 while Present
(Param_Spec
) loop
5474 Formal
:= Defining_Identifier
(Param_Spec
);
5475 Enter_Name
(Formal
);
5477 -- Case of ordinary parameters
5479 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
5480 Find_Type
(Parameter_Type
(Param_Spec
));
5481 Ptype
:= Parameter_Type
(Param_Spec
);
5483 if Ptype
= Error
then
5487 Formal_Type
:= Entity
(Ptype
);
5489 if Ekind
(Formal_Type
) = E_Incomplete_Type
5490 or else (Is_Class_Wide_Type
(Formal_Type
)
5491 and then Ekind
(Root_Type
(Formal_Type
)) =
5494 -- Ada 2005 (AI-326): Tagged incomplete types allowed
5496 if Is_Tagged_Type
(Formal_Type
) then
5499 elsif Nkind
(Parent
(T
)) /= N_Access_Function_Definition
5500 and then Nkind
(Parent
(T
)) /= N_Access_Procedure_Definition
5502 Error_Msg_N
("invalid use of incomplete type", Param_Spec
);
5505 elsif Ekind
(Formal_Type
) = E_Void
then
5506 Error_Msg_NE
("premature use of&",
5507 Parameter_Type
(Param_Spec
), Formal_Type
);
5510 -- Ada 2005 (AI-231): Create and decorate an internal subtype
5511 -- declaration corresponding to the null-excluding type of the
5512 -- formal in the enclosing scope. Finally, replace the parameter
5513 -- type of the formal with the internal subtype.
5515 if Ada_Version
>= Ada_05
5516 and then Is_Access_Type
(Formal_Type
)
5517 and then Null_Exclusion_Present
(Param_Spec
)
5519 if Can_Never_Be_Null
(Formal_Type
)
5520 and then Comes_From_Source
(Related_Nod
)
5523 ("null exclusion must apply to a type that does not "
5524 & "exclude null ('R'M 3.10 (14)", Related_Nod
);
5528 Create_Null_Excluding_Itype
5530 Related_Nod
=> Related_Nod
,
5531 Scope_Id
=> Scope
(Current_Scope
));
5534 -- An access formal type
5538 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
5540 -- Ada 2005 (AI-254)
5543 AD
: constant Node_Id
:=
5544 Access_To_Subprogram_Definition
5545 (Parameter_Type
(Param_Spec
));
5547 if Present
(AD
) and then Protected_Present
(AD
) then
5549 Replace_Anonymous_Access_To_Protected_Subprogram
5550 (Param_Spec
, Formal_Type
);
5555 Set_Etype
(Formal
, Formal_Type
);
5556 Default
:= Expression
(Param_Spec
);
5558 if Present
(Default
) then
5559 if Out_Present
(Param_Spec
) then
5561 ("default initialization only allowed for IN parameters",
5565 -- Do the special preanalysis of the expression (see section on
5566 -- "Handling of Default Expressions" in the spec of package Sem).
5568 Analyze_Per_Use_Expression
(Default
, Formal_Type
);
5570 -- Check that the designated type of an access parameter's default
5571 -- is not a class-wide type unless the parameter's designated type
5572 -- is also class-wide.
5574 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
5575 and then not From_With_Type
(Formal_Type
)
5576 and then Is_Class_Wide_Default
(Default
)
5577 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
5580 ("access to class-wide expression not allowed here", Default
);
5584 -- Ada 2005 (AI-231): Static checks
5586 if Ada_Version
>= Ada_05
5587 and then Is_Access_Type
(Etype
(Formal
))
5588 and then Can_Never_Be_Null
(Etype
(Formal
))
5590 Null_Exclusion_Static_Checks
(Param_Spec
);
5597 -- If this is the formal part of a function specification, analyze the
5598 -- subtype mark in the context where the formals are visible but not
5599 -- yet usable, and may hide outer homographs.
5601 if Nkind
(Related_Nod
) = N_Function_Specification
then
5602 Analyze_Return_Type
(Related_Nod
);
5605 -- Now set the kind (mode) of each formal
5607 Param_Spec
:= First
(T
);
5609 while Present
(Param_Spec
) loop
5610 Formal
:= Defining_Identifier
(Param_Spec
);
5611 Set_Formal_Mode
(Formal
);
5613 if Ekind
(Formal
) = E_In_Parameter
then
5614 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
5616 if Present
(Expression
(Param_Spec
)) then
5617 Default
:= Expression
(Param_Spec
);
5619 if Is_Scalar_Type
(Etype
(Default
)) then
5621 (Parameter_Type
(Param_Spec
)) /= N_Access_Definition
5623 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
5626 Formal_Type
:= Access_Definition
5627 (Related_Nod
, Parameter_Type
(Param_Spec
));
5630 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
5638 end Process_Formals
;
5640 ----------------------------
5641 -- Reference_Body_Formals --
5642 ----------------------------
5644 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
5649 if Error_Posted
(Spec
) then
5653 Fs
:= First_Formal
(Spec
);
5654 Fb
:= First_Formal
(Bod
);
5656 while Present
(Fs
) loop
5657 Generate_Reference
(Fs
, Fb
, 'b');
5660 Style
.Check_Identifier
(Fb
, Fs
);
5663 Set_Spec_Entity
(Fb
, Fs
);
5664 Set_Referenced
(Fs
, False);
5668 end Reference_Body_Formals
;
5670 -------------------------
5671 -- Set_Actual_Subtypes --
5672 -------------------------
5674 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
5675 Loc
: constant Source_Ptr
:= Sloc
(N
);
5679 First_Stmt
: Node_Id
:= Empty
;
5680 AS_Needed
: Boolean;
5683 -- If this is an emtpy initialization procedure, no need to create
5684 -- actual subtypes (small optimization).
5686 if Ekind
(Subp
) = E_Procedure
5687 and then Is_Null_Init_Proc
(Subp
)
5692 Formal
:= First_Formal
(Subp
);
5693 while Present
(Formal
) loop
5694 T
:= Etype
(Formal
);
5696 -- We never need an actual subtype for a constrained formal
5698 if Is_Constrained
(T
) then
5701 -- If we have unknown discriminants, then we do not need an actual
5702 -- subtype, or more accurately we cannot figure it out! Note that
5703 -- all class-wide types have unknown discriminants.
5705 elsif Has_Unknown_Discriminants
(T
) then
5708 -- At this stage we have an unconstrained type that may need an
5709 -- actual subtype. For sure the actual subtype is needed if we have
5710 -- an unconstrained array type.
5712 elsif Is_Array_Type
(T
) then
5715 -- The only other case needing an actual subtype is an unconstrained
5716 -- record type which is an IN parameter (we cannot generate actual
5717 -- subtypes for the OUT or IN OUT case, since an assignment can
5718 -- change the discriminant values. However we exclude the case of
5719 -- initialization procedures, since discriminants are handled very
5720 -- specially in this context, see the section entitled "Handling of
5721 -- Discriminants" in Einfo.
5723 -- We also exclude the case of Discrim_SO_Functions (functions used
5724 -- in front end layout mode for size/offset values), since in such
5725 -- functions only discriminants are referenced, and not only are such
5726 -- subtypes not needed, but they cannot always be generated, because
5727 -- of order of elaboration issues.
5729 elsif Is_Record_Type
(T
)
5730 and then Ekind
(Formal
) = E_In_Parameter
5731 and then Chars
(Formal
) /= Name_uInit
5732 and then not Is_Unchecked_Union
(T
)
5733 and then not Is_Discrim_SO_Function
(Subp
)
5737 -- All other cases do not need an actual subtype
5743 -- Generate actual subtypes for unconstrained arrays and
5744 -- unconstrained discriminated records.
5747 if Nkind
(N
) = N_Accept_Statement
then
5749 -- If expansion is active, The formal is replaced by a local
5750 -- variable that renames the corresponding entry of the
5751 -- parameter block, and it is this local variable that may
5752 -- require an actual subtype.
5754 if Expander_Active
then
5755 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
5757 Decl
:= Build_Actual_Subtype
(T
, Formal
);
5760 if Present
(Handled_Statement_Sequence
(N
)) then
5762 First
(Statements
(Handled_Statement_Sequence
(N
)));
5763 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
5764 Mark_Rewrite_Insertion
(Decl
);
5766 -- If the accept statement has no body, there will be no
5767 -- reference to the actuals, so no need to compute actual
5774 Decl
:= Build_Actual_Subtype
(T
, Formal
);
5775 Prepend
(Decl
, Declarations
(N
));
5776 Mark_Rewrite_Insertion
(Decl
);
5779 -- The declaration uses the bounds of an existing object, and
5780 -- therefore needs no constraint checks.
5782 Analyze
(Decl
, Suppress
=> All_Checks
);
5784 -- We need to freeze manually the generated type when it is
5785 -- inserted anywhere else than in a declarative part.
5787 if Present
(First_Stmt
) then
5788 Insert_List_Before_And_Analyze
(First_Stmt
,
5789 Freeze_Entity
(Defining_Identifier
(Decl
), Loc
));
5792 if Nkind
(N
) = N_Accept_Statement
5793 and then Expander_Active
5795 Set_Actual_Subtype
(Renamed_Object
(Formal
),
5796 Defining_Identifier
(Decl
));
5798 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
5802 Next_Formal
(Formal
);
5804 end Set_Actual_Subtypes
;
5806 ---------------------
5807 -- Set_Formal_Mode --
5808 ---------------------
5810 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
5811 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
5814 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
5815 -- since we ensure that corresponding actuals are always valid at the
5816 -- point of the call.
5818 if Out_Present
(Spec
) then
5819 if Ekind
(Scope
(Formal_Id
)) = E_Function
5820 or else Ekind
(Scope
(Formal_Id
)) = E_Generic_Function
5822 Error_Msg_N
("functions can only have IN parameters", Spec
);
5823 Set_Ekind
(Formal_Id
, E_In_Parameter
);
5825 elsif In_Present
(Spec
) then
5826 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
5829 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
5830 Set_Never_Set_In_Source
(Formal_Id
, True);
5831 Set_Is_True_Constant
(Formal_Id
, False);
5832 Set_Current_Value
(Formal_Id
, Empty
);
5836 Set_Ekind
(Formal_Id
, E_In_Parameter
);
5839 -- Set Is_Known_Non_Null for access parameters since the language
5840 -- guarantees that access parameters are always non-null. We also set
5841 -- Can_Never_Be_Null, since there is no way to change the value.
5843 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
5845 -- Ada 2005 (AI-231): In Ada95, access parameters are always non-
5846 -- null; In Ada 2005, only if then null_exclusion is explicit.
5848 if Ada_Version
< Ada_05
5849 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
5851 Set_Is_Known_Non_Null
(Formal_Id
);
5852 Set_Can_Never_Be_Null
(Formal_Id
);
5855 -- Ada 2005 (AI-231): Null-exclusion access subtype
5857 elsif Is_Access_Type
(Etype
(Formal_Id
))
5858 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
5860 Set_Is_Known_Non_Null
(Formal_Id
);
5863 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
5864 Set_Formal_Validity
(Formal_Id
);
5865 end Set_Formal_Mode
;
5867 -------------------------
5868 -- Set_Formal_Validity --
5869 -------------------------
5871 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
5873 -- If no validity checking, then we cannot assume anything about the
5874 -- validity of parameters, since we do not know there is any checking
5875 -- of the validity on the call side.
5877 if not Validity_Checks_On
then
5880 -- If validity checking for parameters is enabled, this means we are
5881 -- not supposed to make any assumptions about argument values.
5883 elsif Validity_Check_Parameters
then
5886 -- If we are checking in parameters, we will assume that the caller is
5887 -- also checking parameters, so we can assume the parameter is valid.
5889 elsif Ekind
(Formal_Id
) = E_In_Parameter
5890 and then Validity_Check_In_Params
5892 Set_Is_Known_Valid
(Formal_Id
, True);
5894 -- Similar treatment for IN OUT parameters
5896 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
5897 and then Validity_Check_In_Out_Params
5899 Set_Is_Known_Valid
(Formal_Id
, True);
5901 end Set_Formal_Validity
;
5903 ------------------------
5904 -- Subtype_Conformant --
5905 ------------------------
5907 function Subtype_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
5910 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
);
5912 end Subtype_Conformant
;
5914 ---------------------
5915 -- Type_Conformant --
5916 ---------------------
5918 function Type_Conformant
5919 (New_Id
: Entity_Id
;
5921 Skip_Controlling_Formals
: Boolean := False) return Boolean
5926 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
5927 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
5929 end Type_Conformant
;
5931 -------------------------------
5932 -- Valid_Operator_Definition --
5933 -------------------------------
5935 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
5938 Id
: constant Name_Id
:= Chars
(Designator
);
5942 F
:= First_Formal
(Designator
);
5943 while Present
(F
) loop
5946 if Present
(Default_Value
(F
)) then
5948 ("default values not allowed for operator parameters",
5955 -- Verify that user-defined operators have proper number of arguments
5956 -- First case of operators which can only be unary
5959 or else Id
= Name_Op_Abs
5963 -- Case of operators which can be unary or binary
5965 elsif Id
= Name_Op_Add
5966 or Id
= Name_Op_Subtract
5968 N_OK
:= (N
in 1 .. 2);
5970 -- All other operators can only be binary
5978 ("incorrect number of arguments for operator", Designator
);
5982 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
5983 and then not Is_Intrinsic_Subprogram
(Designator
)
5986 ("explicit definition of inequality not allowed", Designator
);
5988 end Valid_Operator_Definition
;