1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Contracts
; use Contracts
;
30 with Debug
; use Debug
;
31 with Einfo
; use Einfo
;
32 with Elists
; use Elists
;
33 with Errout
; use Errout
;
34 with Expander
; use Expander
;
35 with Exp_Ch6
; use Exp_Ch6
;
36 with Exp_Ch7
; use Exp_Ch7
;
37 with Exp_Ch9
; use Exp_Ch9
;
38 with Exp_Dbug
; use Exp_Dbug
;
39 with Exp_Disp
; use Exp_Disp
;
40 with Exp_Tss
; use Exp_Tss
;
41 with Exp_Util
; use Exp_Util
;
42 with Freeze
; use Freeze
;
43 with Ghost
; use Ghost
;
44 with Inline
; use Inline
;
45 with Itypes
; use Itypes
;
46 with Lib
.Xref
; use Lib
.Xref
;
47 with Layout
; use Layout
;
48 with Namet
; use Namet
;
50 with Nlists
; use Nlists
;
51 with Nmake
; use Nmake
;
53 with Output
; use Output
;
54 with Restrict
; use Restrict
;
55 with Rident
; use Rident
;
56 with Rtsfind
; use Rtsfind
;
58 with Sem_Aux
; use Sem_Aux
;
59 with Sem_Cat
; use Sem_Cat
;
60 with Sem_Ch3
; use Sem_Ch3
;
61 with Sem_Ch4
; use Sem_Ch4
;
62 with Sem_Ch5
; use Sem_Ch5
;
63 with Sem_Ch8
; use Sem_Ch8
;
64 with Sem_Ch9
; use Sem_Ch9
;
65 with Sem_Ch10
; use Sem_Ch10
;
66 with Sem_Ch12
; use Sem_Ch12
;
67 with Sem_Ch13
; use Sem_Ch13
;
68 with Sem_Dim
; use Sem_Dim
;
69 with Sem_Disp
; use Sem_Disp
;
70 with Sem_Dist
; use Sem_Dist
;
71 with Sem_Elim
; use Sem_Elim
;
72 with Sem_Eval
; use Sem_Eval
;
73 with Sem_Mech
; use Sem_Mech
;
74 with Sem_Prag
; use Sem_Prag
;
75 with Sem_Res
; use Sem_Res
;
76 with Sem_Util
; use Sem_Util
;
77 with Sem_Type
; use Sem_Type
;
78 with Sem_Warn
; use Sem_Warn
;
79 with Sinput
; use Sinput
;
80 with Stand
; use Stand
;
81 with Sinfo
; use Sinfo
;
82 with Sinfo
.CN
; use Sinfo
.CN
;
83 with Snames
; use Snames
;
84 with Stringt
; use Stringt
;
86 with Stylesw
; use Stylesw
;
87 with Tbuild
; use Tbuild
;
88 with Uintp
; use Uintp
;
89 with Urealp
; use Urealp
;
90 with Validsw
; use Validsw
;
92 package body Sem_Ch6
is
94 May_Hide_Profile
: Boolean := False;
95 -- This flag is used to indicate that two formals in two subprograms being
96 -- checked for conformance differ only in that one is an access parameter
97 -- while the other is of a general access type with the same designated
98 -- type. In this case, if the rest of the signatures match, a call to
99 -- either subprogram may be ambiguous, which is worth a warning. The flag
100 -- is set in Compatible_Types, and the warning emitted in
101 -- New_Overloaded_Entity.
103 -----------------------
104 -- Local Subprograms --
105 -----------------------
107 procedure Analyze_Function_Return
(N
: Node_Id
);
108 -- Subsidiary to Analyze_Return_Statement. Called when the return statement
109 -- applies to a [generic] function.
111 procedure Analyze_Generic_Subprogram_Body
(N
: Node_Id
; Gen_Id
: Entity_Id
);
112 -- Analyze a generic subprogram body. N is the body to be analyzed, and
113 -- Gen_Id is the defining entity Id for the corresponding spec.
115 procedure Analyze_Null_Procedure
117 Is_Completion
: out Boolean);
118 -- A null procedure can be a declaration or (Ada 2012) a completion
120 procedure Analyze_Return_Statement
(N
: Node_Id
);
121 -- Common processing for simple and extended return statements
123 procedure Analyze_Return_Type
(N
: Node_Id
);
124 -- Subsidiary to Process_Formals: analyze subtype mark in function
125 -- specification in a context where the formals are visible and hide
128 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
);
129 -- Does all the real work of Analyze_Subprogram_Body. This is split out so
130 -- that we can use RETURN but not skip the debug output at the end.
132 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
133 -- Returns true if Subp can override a predefined operator.
135 procedure Check_Conformance
138 Ctype
: Conformance_Type
;
140 Conforms
: out Boolean;
141 Err_Loc
: Node_Id
:= Empty
;
142 Get_Inst
: Boolean := False;
143 Skip_Controlling_Formals
: Boolean := False);
144 -- Given two entities, this procedure checks that the profiles associated
145 -- with these entities meet the conformance criterion given by the third
146 -- parameter. If they conform, Conforms is set True and control returns
147 -- to the caller. If they do not conform, Conforms is set to False, and
148 -- in addition, if Errmsg is True on the call, proper messages are output
149 -- to complain about the conformance failure. If Err_Loc is non_Empty
150 -- the error messages are placed on Err_Loc, if Err_Loc is empty, then
151 -- error messages are placed on the appropriate part of the construct
152 -- denoted by New_Id. If Get_Inst is true, then this is a mode conformance
153 -- against a formal access-to-subprogram type so Get_Instance_Of must
156 procedure Check_Limited_Return
160 -- Check the appropriate (Ada 95 or Ada 2005) rules for returning limited
161 -- types. Used only for simple return statements. Expr is the expression
164 procedure Check_Subprogram_Order
(N
: Node_Id
);
165 -- N is the N_Subprogram_Body node for a subprogram. This routine applies
166 -- the alpha ordering rule for N if this ordering requirement applicable.
168 procedure Check_Returns
172 Proc
: Entity_Id
:= Empty
);
173 -- Called to check for missing return statements in a function body, or for
174 -- returns present in a procedure body which has No_Return set. HSS is the
175 -- handled statement sequence for the subprogram body. This procedure
176 -- checks all flow paths to make sure they either have return (Mode = 'F',
177 -- used for functions) or do not have a return (Mode = 'P', used for
178 -- No_Return procedures). The flag Err is set if there are any control
179 -- paths not explicitly terminated by a return in the function case, and is
180 -- True otherwise. Proc is the entity for the procedure case and is used
181 -- in posting the warning message.
183 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
);
184 -- In Ada 2012, a primitive equality operator on an untagged record type
185 -- must appear before the type is frozen, and have the same visibility as
186 -- that of the type. This procedure checks that this rule is met, and
187 -- otherwise emits an error on the subprogram declaration and a warning
188 -- on the earlier freeze point if it is easy to locate. In Ada 2012 mode,
189 -- this routine outputs errors (or warnings if -gnatd.E is set). In earlier
190 -- versions of Ada, warnings are output if Warn_On_Ada_2012_Incompatibility
191 -- is set, otherwise the call has no effect.
193 procedure Enter_Overloaded_Entity
(S
: Entity_Id
);
194 -- This procedure makes S, a new overloaded entity, into the first visible
195 -- entity with that name.
197 function Is_Non_Overriding_Operation
199 New_E
: Entity_Id
) return Boolean;
200 -- Enforce the rule given in 12.3(18): a private operation in an instance
201 -- overrides an inherited operation only if the corresponding operation
202 -- was overriding in the generic. This needs to be checked for primitive
203 -- operations of types derived (in the generic unit) from formal private
204 -- or formal derived types.
206 procedure Make_Inequality_Operator
(S
: Entity_Id
);
207 -- Create the declaration for an inequality operator that is implicitly
208 -- created by a user-defined equality operator that yields a boolean.
210 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
);
211 -- Formal_Id is an formal parameter entity. This procedure deals with
212 -- setting the proper validity status for this entity, which depends on
213 -- the kind of parameter and the validity checking mode.
215 ---------------------------------------------
216 -- Analyze_Abstract_Subprogram_Declaration --
217 ---------------------------------------------
219 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
) is
220 Scop
: constant Entity_Id
:= Current_Scope
;
221 Subp_Id
: constant Entity_Id
:=
222 Analyze_Subprogram_Specification
(Specification
(N
));
225 Check_SPARK_05_Restriction
("abstract subprogram is not allowed", N
);
227 Generate_Definition
(Subp_Id
);
229 -- Set the SPARK mode from the current context (may be overwritten later
230 -- with explicit pragma).
232 Set_SPARK_Pragma
(Subp_Id
, SPARK_Mode_Pragma
);
233 Set_SPARK_Pragma_Inherited
(Subp_Id
);
235 -- Preserve relevant elaboration-related attributes of the context which
236 -- are no longer available or very expensive to recompute once analysis,
237 -- resolution, and expansion are over.
239 Mark_Elaboration_Attributes
243 Set_Is_Abstract_Subprogram
(Subp_Id
);
244 New_Overloaded_Entity
(Subp_Id
);
245 Check_Delayed_Subprogram
(Subp_Id
);
247 Set_Categorization_From_Scope
(Subp_Id
, Scop
);
249 if Ekind
(Scope
(Subp_Id
)) = E_Protected_Type
then
250 Error_Msg_N
("abstract subprogram not allowed in protected type", N
);
252 -- Issue a warning if the abstract subprogram is neither a dispatching
253 -- operation nor an operation that overrides an inherited subprogram or
254 -- predefined operator, since this most likely indicates a mistake.
256 elsif Warn_On_Redundant_Constructs
257 and then not Is_Dispatching_Operation
(Subp_Id
)
258 and then not Present
(Overridden_Operation
(Subp_Id
))
259 and then (not Is_Operator_Symbol_Name
(Chars
(Subp_Id
))
260 or else Scop
/= Scope
(Etype
(First_Formal
(Subp_Id
))))
263 ("abstract subprogram is not dispatching or overriding?r?", N
);
266 Generate_Reference_To_Formals
(Subp_Id
);
267 Check_Eliminated
(Subp_Id
);
269 if Has_Aspects
(N
) then
270 Analyze_Aspect_Specifications
(N
, Subp_Id
);
272 end Analyze_Abstract_Subprogram_Declaration
;
274 ---------------------------------
275 -- Analyze_Expression_Function --
276 ---------------------------------
278 procedure Analyze_Expression_Function
(N
: Node_Id
) is
279 Expr
: constant Node_Id
:= Expression
(N
);
280 Loc
: constant Source_Ptr
:= Sloc
(N
);
281 LocX
: constant Source_Ptr
:= Sloc
(Expr
);
282 Spec
: constant Node_Id
:= Specification
(N
);
284 procedure Freeze_Expr_Types
(Def_Id
: Entity_Id
);
285 -- N is an expression function that is a completion and Def_Id its
286 -- defining entity. Freeze before N all the types referenced by the
287 -- expression of the function.
289 -----------------------
290 -- Freeze_Expr_Types --
291 -----------------------
293 procedure Freeze_Expr_Types
(Def_Id
: Entity_Id
) is
294 function Cloned_Expression
return Node_Id
;
295 -- Build a duplicate of the expression of the return statement that
296 -- has no defining entities shared with the original expression.
298 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
299 -- Freeze all types referenced in the subtree rooted at Node
301 -----------------------
302 -- Cloned_Expression --
303 -----------------------
305 function Cloned_Expression
return Node_Id
is
306 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
;
307 -- Tree traversal routine that clones the defining identifier of
308 -- iterator and loop parameter specification nodes.
314 function Clone_Id
(Node
: Node_Id
) return Traverse_Result
is
316 if Nkind_In
(Node
, N_Iterator_Specification
,
317 N_Loop_Parameter_Specification
)
319 Set_Defining_Identifier
(Node
,
320 New_Copy
(Defining_Identifier
(Node
)));
326 procedure Clone_Def_Ids
is new Traverse_Proc
(Clone_Id
);
330 Dup_Expr
: constant Node_Id
:= New_Copy_Tree
(Expr
);
332 -- Start of processing for Cloned_Expression
335 -- We must duplicate the expression with semantic information to
336 -- inherit the decoration of global entities in generic instances.
337 -- Set the parent of the new node to be the parent of the original
338 -- to get the proper context, which is needed for complete error
339 -- reporting and for semantic analysis.
341 Set_Parent
(Dup_Expr
, Parent
(Expr
));
343 -- Replace the defining identifier of iterators and loop param
344 -- specifications by a clone to ensure that the cloned expression
345 -- and the original expression don't have shared identifiers;
346 -- otherwise, as part of the preanalysis of the expression, these
347 -- shared identifiers may be left decorated with itypes which
348 -- will not be available in the tree passed to the backend.
350 Clone_Def_Ids
(Dup_Expr
);
353 end Cloned_Expression
;
355 ----------------------
356 -- Freeze_Type_Refs --
357 ----------------------
359 function Freeze_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
360 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
);
361 -- Check that Typ is fully declared and freeze it if so
363 ---------------------------
364 -- Check_And_Freeze_Type --
365 ---------------------------
367 procedure Check_And_Freeze_Type
(Typ
: Entity_Id
) is
369 -- Skip Itypes created by the preanalysis, and itypes whose
370 -- scope is another type (i.e. component subtypes that depend
371 -- on a discriminant),
374 and then (Scope_Within_Or_Same
(Scope
(Typ
), Def_Id
)
375 or else Is_Type
(Scope
(Typ
)))
380 -- This provides a better error message than generating
381 -- primitives whose compilation fails much later. Refine
382 -- the error message if possible.
384 Check_Fully_Declared
(Typ
, Node
);
386 if Error_Posted
(Node
) then
387 if Has_Private_Component
(Typ
)
388 and then not Is_Private_Type
(Typ
)
390 Error_Msg_NE
("\type& has private component", Node
, Typ
);
394 Freeze_Before
(N
, Typ
);
396 end Check_And_Freeze_Type
;
398 -- Start of processing for Freeze_Type_Refs
401 -- Check that a type referenced by an entity can be frozen
403 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
404 Check_And_Freeze_Type
(Etype
(Entity
(Node
)));
406 -- Check that the enclosing record type can be frozen
408 if Ekind_In
(Entity
(Node
), E_Component
, E_Discriminant
) then
409 Check_And_Freeze_Type
(Scope
(Entity
(Node
)));
412 -- Freezing an access type does not freeze the designated type,
413 -- but freezing conversions between access to interfaces requires
414 -- that the interface types themselves be frozen, so that dispatch
415 -- table entities are properly created.
417 -- Unclear whether a more general rule is needed ???
419 elsif Nkind
(Node
) = N_Type_Conversion
420 and then Is_Access_Type
(Etype
(Node
))
421 and then Is_Interface
(Designated_Type
(Etype
(Node
)))
423 Check_And_Freeze_Type
(Designated_Type
(Etype
(Node
)));
426 -- No point in posting several errors on the same expression
428 if Serious_Errors_Detected
> 0 then
433 end Freeze_Type_Refs
;
435 procedure Freeze_References
is new Traverse_Proc
(Freeze_Type_Refs
);
439 Saved_First_Entity
: constant Entity_Id
:= First_Entity
(Def_Id
);
440 Saved_Last_Entity
: constant Entity_Id
:= Last_Entity
(Def_Id
);
441 Dup_Expr
: constant Node_Id
:= Cloned_Expression
;
443 -- Start of processing for Freeze_Expr_Types
446 -- Preanalyze a duplicate of the expression to have available the
447 -- minimum decoration needed to locate referenced unfrozen types
448 -- without adding any decoration to the function expression.
451 Install_Formals
(Def_Id
);
453 Preanalyze_Spec_Expression
(Dup_Expr
, Etype
(Def_Id
));
456 -- Restore certain attributes of Def_Id since the preanalysis may
457 -- have introduced itypes to this scope, thus modifying attributes
458 -- First_Entity and Last_Entity.
460 Set_First_Entity
(Def_Id
, Saved_First_Entity
);
461 Set_Last_Entity
(Def_Id
, Saved_Last_Entity
);
463 if Present
(Last_Entity
(Def_Id
)) then
464 Set_Next_Entity
(Last_Entity
(Def_Id
), Empty
);
467 -- Freeze all types referenced in the expression
469 Freeze_References
(Dup_Expr
);
470 end Freeze_Expr_Types
;
480 Def_Id
: Entity_Id
:= Empty
;
482 -- If the expression is a completion, Prev is the entity whose
483 -- declaration is completed. Def_Id is needed to analyze the spec.
485 -- Start of processing for Analyze_Expression_Function
488 -- This is one of the occasions on which we transform the tree during
489 -- semantic analysis. If this is a completion, transform the expression
490 -- function into an equivalent subprogram body, and analyze it.
492 -- Expression functions are inlined unconditionally. The back-end will
493 -- determine whether this is possible.
495 Inline_Processing_Required
:= True;
497 -- Create a specification for the generated body. This must be done
498 -- prior to the analysis of the initial declaration.
500 New_Spec
:= Copy_Subprogram_Spec
(Spec
);
501 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
503 -- If there are previous overloadable entities with the same name,
504 -- check whether any of them is completed by the expression function.
505 -- In a generic context a formal subprogram has no completion.
508 and then Is_Overloadable
(Prev
)
509 and then not Is_Formal_Subprogram
(Prev
)
511 Def_Id
:= Analyze_Subprogram_Specification
(Spec
);
512 Prev
:= Find_Corresponding_Spec
(N
);
514 -- The previous entity may be an expression function as well, in
515 -- which case the redeclaration is illegal.
518 and then Nkind
(Original_Node
(Unit_Declaration_Node
(Prev
))) =
519 N_Expression_Function
521 Error_Msg_Sloc
:= Sloc
(Prev
);
522 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
527 Ret
:= Make_Simple_Return_Statement
(LocX
, Expr
);
530 Make_Subprogram_Body
(Loc
,
531 Specification
=> New_Spec
,
532 Declarations
=> Empty_List
,
533 Handled_Statement_Sequence
=>
534 Make_Handled_Sequence_Of_Statements
(LocX
,
535 Statements
=> New_List
(Ret
)));
536 Set_Was_Expression_Function
(New_Body
);
538 -- If the expression completes a generic subprogram, we must create a
539 -- separate node for the body, because at instantiation the original
540 -- node of the generic copy must be a generic subprogram body, and
541 -- cannot be a expression function. Otherwise we just rewrite the
542 -- expression with the non-generic body.
544 if Present
(Prev
) and then Ekind
(Prev
) = E_Generic_Function
then
545 Insert_After
(N
, New_Body
);
547 -- Propagate any aspects or pragmas that apply to the expression
548 -- function to the proper body when the expression function acts
551 if Has_Aspects
(N
) then
552 Move_Aspects
(N
, To
=> New_Body
);
555 Relocate_Pragmas_To_Body
(New_Body
);
557 Rewrite
(N
, Make_Null_Statement
(Loc
));
558 Set_Has_Completion
(Prev
, False);
561 Set_Is_Inlined
(Prev
);
563 -- If the expression function is a completion, the previous declaration
564 -- must come from source. We know already that it appears in the current
565 -- scope. The entity itself may be internally created if within a body
569 and then Is_Overloadable
(Prev
)
570 and then not Is_Formal_Subprogram
(Prev
)
571 and then Comes_From_Source
(Parent
(Prev
))
573 Set_Has_Completion
(Prev
, False);
574 Set_Is_Inlined
(Prev
);
576 -- AI12-0103: Expression functions that are a completion freeze their
577 -- expression but don't freeze anything else (unlike regular bodies).
579 -- Note that we cannot defer this freezing to the analysis of the
580 -- expression itself, because a freeze node might appear in a nested
581 -- scope, leading to an elaboration order issue in gigi.
582 -- As elsewhere, we do not emit freeze nodes within a generic unit.
584 if not Inside_A_Generic
then
585 Freeze_Expr_Types
(Def_Id
);
588 -- For navigation purposes, indicate that the function is a body
590 Generate_Reference
(Prev
, Defining_Entity
(N
), 'b', Force
=> True);
591 Rewrite
(N
, New_Body
);
593 -- Remove any existing aspects from the original node because the act
594 -- of rewriting causes the list to be shared between the two nodes.
596 Orig_N
:= Original_Node
(N
);
597 Remove_Aspects
(Orig_N
);
599 -- Propagate any pragmas that apply to expression function to the
600 -- proper body when the expression function acts as a completion.
601 -- Aspects are automatically transfered because of node rewriting.
603 Relocate_Pragmas_To_Body
(N
);
606 -- Once the aspects of the generated body have been analyzed, create
607 -- a copy for ASIS purposes and associate it with the original node.
609 if Has_Aspects
(N
) then
610 Set_Aspect_Specifications
(Orig_N
,
611 New_Copy_List_Tree
(Aspect_Specifications
(N
)));
614 -- Prev is the previous entity with the same name, but it is can
615 -- be an unrelated spec that is not completed by the expression
616 -- function. In that case the relevant entity is the one in the body.
617 -- Not clear that the backend can inline it in this case ???
619 if Has_Completion
(Prev
) then
621 -- The formals of the expression function are body formals,
622 -- and do not appear in the ali file, which will only contain
623 -- references to the formals of the original subprogram spec.
630 F1
:= First_Formal
(Def_Id
);
631 F2
:= First_Formal
(Prev
);
633 while Present
(F1
) loop
634 Set_Spec_Entity
(F1
, F2
);
641 Set_Is_Inlined
(Defining_Entity
(New_Body
));
644 -- If this is not a completion, create both a declaration and a body, so
645 -- that the expression can be inlined whenever possible.
648 -- An expression function that is not a completion is not a
649 -- subprogram declaration, and thus cannot appear in a protected
652 if Nkind
(Parent
(N
)) = N_Protected_Definition
then
654 ("an expression function is not a legal protected operation", N
);
657 Rewrite
(N
, Make_Subprogram_Declaration
(Loc
, Specification
=> Spec
));
659 -- Remove any existing aspects from the original node because the act
660 -- of rewriting causes the list to be shared between the two nodes.
662 Orig_N
:= Original_Node
(N
);
663 Remove_Aspects
(Orig_N
);
667 -- Once the aspects of the generated spec have been analyzed, create
668 -- a copy for ASIS purposes and associate it with the original node.
670 if Has_Aspects
(N
) then
671 Set_Aspect_Specifications
(Orig_N
,
672 New_Copy_List_Tree
(Aspect_Specifications
(N
)));
675 -- If aspect SPARK_Mode was specified on the body, it needs to be
676 -- repeated both on the generated spec and the body.
678 Asp
:= Find_Aspect
(Defining_Unit_Name
(Spec
), Aspect_SPARK_Mode
);
680 if Present
(Asp
) then
681 Asp
:= New_Copy_Tree
(Asp
);
682 Set_Analyzed
(Asp
, False);
683 Set_Aspect_Specifications
(New_Body
, New_List
(Asp
));
686 Def_Id
:= Defining_Entity
(N
);
687 Set_Is_Inlined
(Def_Id
);
689 -- Establish the linkages between the spec and the body. These are
690 -- used when the expression function acts as the prefix of attribute
691 -- 'Access in order to freeze the original expression which has been
692 -- moved to the generated body.
694 Set_Corresponding_Body
(N
, Defining_Entity
(New_Body
));
695 Set_Corresponding_Spec
(New_Body
, Def_Id
);
697 -- Within a generic pre-analyze the original expression for name
698 -- capture. The body is also generated but plays no role in
699 -- this because it is not part of the original source.
701 if Inside_A_Generic
then
702 Set_Has_Completion
(Def_Id
);
704 Install_Formals
(Def_Id
);
705 Preanalyze_Spec_Expression
(Expr
, Etype
(Def_Id
));
709 -- To prevent premature freeze action, insert the new body at the end
710 -- of the current declarations, or at the end of the package spec.
711 -- However, resolve usage names now, to prevent spurious visibility
712 -- on later entities. Note that the function can now be called in
713 -- the current declarative part, which will appear to be prior to
714 -- the presence of the body in the code. There are nevertheless no
715 -- order of elaboration issues because all name resolution has taken
716 -- place at the point of declaration.
719 Decls
: List_Id
:= List_Containing
(N
);
720 Expr
: constant Node_Id
:= Expression
(Ret
);
721 Par
: constant Node_Id
:= Parent
(Decls
);
722 Typ
: constant Entity_Id
:= Etype
(Def_Id
);
725 -- If this is a wrapper created for in an instance for a formal
726 -- subprogram, insert body after declaration, to be analyzed when
727 -- the enclosing instance is analyzed.
730 and then Is_Generic_Actual_Subprogram
(Def_Id
)
732 Insert_After
(N
, New_Body
);
735 if Nkind
(Par
) = N_Package_Specification
736 and then Decls
= Visible_Declarations
(Par
)
737 and then Present
(Private_Declarations
(Par
))
738 and then not Is_Empty_List
(Private_Declarations
(Par
))
740 Decls
:= Private_Declarations
(Par
);
743 Insert_After
(Last
(Decls
), New_Body
);
745 -- Preanalyze the expression if not already done above
747 if not Inside_A_Generic
then
749 Install_Formals
(Def_Id
);
750 Preanalyze_Spec_Expression
(Expr
, Typ
);
751 Check_Limited_Return
(Original_Node
(N
), Expr
, Typ
);
758 -- Check incorrect use of dynamically tagged expression. This doesn't
759 -- fall out automatically when analyzing the generated function body,
760 -- because Check_Dynamically_Tagged_Expression deliberately ignores
761 -- nodes that don't come from source.
764 and then Nkind
(Def_Id
) in N_Has_Etype
765 and then Is_Tagged_Type
(Etype
(Def_Id
))
767 Check_Dynamically_Tagged_Expression
769 Typ
=> Etype
(Def_Id
),
770 Related_Nod
=> Original_Node
(N
));
773 -- If the return expression is a static constant, we suppress warning
774 -- messages on unused formals, which in most cases will be noise.
776 Set_Is_Trivial_Subprogram
777 (Defining_Entity
(New_Body
), Is_OK_Static_Expression
(Expr
));
778 end Analyze_Expression_Function
;
780 ----------------------------------------
781 -- Analyze_Extended_Return_Statement --
782 ----------------------------------------
784 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
) is
786 Check_Compiler_Unit
("extended return statement", N
);
787 Analyze_Return_Statement
(N
);
788 end Analyze_Extended_Return_Statement
;
790 ----------------------------
791 -- Analyze_Function_Call --
792 ----------------------------
794 procedure Analyze_Function_Call
(N
: Node_Id
) is
795 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
796 Func_Nam
: constant Node_Id
:= Name
(N
);
802 -- A call of the form A.B (X) may be an Ada 2005 call, which is
803 -- rewritten as B (A, X). If the rewriting is successful, the call
804 -- has been analyzed and we just return.
806 if Nkind
(Func_Nam
) = N_Selected_Component
807 and then Name
(N
) /= Func_Nam
808 and then Is_Rewrite_Substitution
(N
)
809 and then Present
(Etype
(N
))
814 -- If error analyzing name, then set Any_Type as result type and return
816 if Etype
(Func_Nam
) = Any_Type
then
817 Set_Etype
(N
, Any_Type
);
821 -- Otherwise analyze the parameters
823 if Present
(Actuals
) then
824 Actual
:= First
(Actuals
);
825 while Present
(Actual
) loop
827 Check_Parameterless_Call
(Actual
);
833 end Analyze_Function_Call
;
835 -----------------------------
836 -- Analyze_Function_Return --
837 -----------------------------
839 procedure Analyze_Function_Return
(N
: Node_Id
) is
840 Loc
: constant Source_Ptr
:= Sloc
(N
);
841 Stm_Entity
: constant Entity_Id
:= Return_Statement_Entity
(N
);
842 Scope_Id
: constant Entity_Id
:= Return_Applies_To
(Stm_Entity
);
844 R_Type
: constant Entity_Id
:= Etype
(Scope_Id
);
845 -- Function result subtype
847 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
);
848 -- Apply legality rule of 6.5 (5.8) to the access discriminants of an
849 -- aggregate in a return statement.
851 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
);
852 -- Check that the return_subtype_indication properly matches the result
853 -- subtype of the function, as required by RM-6.5(5.1/2-5.3/2).
855 -----------------------------------
856 -- Check_Aggregate_Accessibility --
857 -----------------------------------
859 procedure Check_Aggregate_Accessibility
(Aggr
: Node_Id
) is
860 Typ
: constant Entity_Id
:= Etype
(Aggr
);
867 if Is_Record_Type
(Typ
) and then Has_Discriminants
(Typ
) then
868 Discr
:= First_Discriminant
(Typ
);
869 Assoc
:= First
(Component_Associations
(Aggr
));
870 while Present
(Discr
) loop
871 if Ekind
(Etype
(Discr
)) = E_Anonymous_Access_Type
then
872 Expr
:= Expression
(Assoc
);
874 if Nkind
(Expr
) = N_Attribute_Reference
875 and then Attribute_Name
(Expr
) /= Name_Unrestricted_Access
877 Obj
:= Prefix
(Expr
);
878 while Nkind_In
(Obj
, N_Indexed_Component
,
879 N_Selected_Component
)
884 -- Do not check aliased formals or function calls. A
885 -- run-time check may still be needed ???
887 if Is_Entity_Name
(Obj
)
888 and then Comes_From_Source
(Obj
)
890 if Is_Formal
(Entity
(Obj
))
891 and then Is_Aliased
(Entity
(Obj
))
895 elsif Object_Access_Level
(Obj
) >
896 Scope_Depth
(Scope
(Scope_Id
))
899 ("access discriminant in return aggregate would "
900 & "be a dangling reference", Obj
);
906 Next_Discriminant
(Discr
);
909 end Check_Aggregate_Accessibility
;
911 -------------------------------------
912 -- Check_Return_Subtype_Indication --
913 -------------------------------------
915 procedure Check_Return_Subtype_Indication
(Obj_Decl
: Node_Id
) is
916 Return_Obj
: constant Node_Id
:= Defining_Identifier
(Obj_Decl
);
918 R_Stm_Type
: constant Entity_Id
:= Etype
(Return_Obj
);
919 -- Subtype given in the extended return statement (must match R_Type)
921 Subtype_Ind
: constant Node_Id
:=
922 Object_Definition
(Original_Node
(Obj_Decl
));
924 procedure Error_No_Match
(N
: Node_Id
);
925 -- Output error messages for case where types do not statically
926 -- match. N is the location for the messages.
932 procedure Error_No_Match
(N
: Node_Id
) is
935 ("subtype must statically match function result subtype", N
);
937 if not Predicates_Match
(R_Stm_Type
, R_Type
) then
938 Error_Msg_Node_2
:= R_Type
;
940 ("\predicate of& does not match predicate of&",
945 -- Start of processing for Check_Return_Subtype_Indication
948 -- First, avoid cascaded errors
950 if Error_Posted
(Obj_Decl
) or else Error_Posted
(Subtype_Ind
) then
954 -- "return access T" case; check that the return statement also has
955 -- "access T", and that the subtypes statically match:
956 -- if this is an access to subprogram the signatures must match.
958 if Is_Anonymous_Access_Type
(R_Type
) then
959 if Is_Anonymous_Access_Type
(R_Stm_Type
) then
960 if Ekind
(Designated_Type
(R_Stm_Type
)) /= E_Subprogram_Type
962 if Base_Type
(Designated_Type
(R_Stm_Type
)) /=
963 Base_Type
(Designated_Type
(R_Type
))
964 or else not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
)
966 Error_No_Match
(Subtype_Mark
(Subtype_Ind
));
970 -- For two anonymous access to subprogram types, the types
971 -- themselves must be type conformant.
973 if not Conforming_Types
974 (R_Stm_Type
, R_Type
, Fully_Conformant
)
976 Error_No_Match
(Subtype_Ind
);
981 Error_Msg_N
("must use anonymous access type", Subtype_Ind
);
984 -- If the return object is of an anonymous access type, then report
985 -- an error if the function's result type is not also anonymous.
987 elsif Is_Anonymous_Access_Type
(R_Stm_Type
) then
988 pragma Assert
(not Is_Anonymous_Access_Type
(R_Type
));
990 ("anonymous access not allowed for function with named access "
991 & "result", Subtype_Ind
);
993 -- Subtype indication case: check that the return object's type is
994 -- covered by the result type, and that the subtypes statically match
995 -- when the result subtype is constrained. Also handle record types
996 -- with unknown discriminants for which we have built the underlying
997 -- record view. Coverage is needed to allow specific-type return
998 -- objects when the result type is class-wide (see AI05-32).
1000 elsif Covers
(Base_Type
(R_Type
), Base_Type
(R_Stm_Type
))
1001 or else (Is_Underlying_Record_View
(Base_Type
(R_Stm_Type
))
1004 (Base_Type
(R_Type
),
1005 Underlying_Record_View
(Base_Type
(R_Stm_Type
))))
1007 -- A null exclusion may be present on the return type, on the
1008 -- function specification, on the object declaration or on the
1011 if Is_Access_Type
(R_Type
)
1013 (Can_Never_Be_Null
(R_Type
)
1014 or else Null_Exclusion_Present
(Parent
(Scope_Id
))) /=
1015 Can_Never_Be_Null
(R_Stm_Type
)
1017 Error_No_Match
(Subtype_Ind
);
1020 -- AI05-103: for elementary types, subtypes must statically match
1022 if Is_Constrained
(R_Type
) or else Is_Access_Type
(R_Type
) then
1023 if not Subtypes_Statically_Match
(R_Stm_Type
, R_Type
) then
1024 Error_No_Match
(Subtype_Ind
);
1028 -- All remaining cases are illegal
1030 -- Note: previous versions of this subprogram allowed the return
1031 -- value to be the ancestor of the return type if the return type
1032 -- was a null extension. This was plainly incorrect.
1036 ("wrong type for return_subtype_indication", Subtype_Ind
);
1038 end Check_Return_Subtype_Indication
;
1040 ---------------------
1041 -- Local Variables --
1042 ---------------------
1045 Obj_Decl
: Node_Id
:= Empty
;
1047 -- Start of processing for Analyze_Function_Return
1050 Set_Return_Present
(Scope_Id
);
1052 if Nkind
(N
) = N_Simple_Return_Statement
then
1053 Expr
:= Expression
(N
);
1055 -- Guard against a malformed expression. The parser may have tried to
1056 -- recover but the node is not analyzable.
1058 if Nkind
(Expr
) = N_Error
then
1059 Set_Etype
(Expr
, Any_Type
);
1060 Expander_Mode_Save_And_Set
(False);
1064 -- The resolution of a controlled [extension] aggregate associated
1065 -- with a return statement creates a temporary which needs to be
1066 -- finalized on function exit. Wrap the return statement inside a
1067 -- block so that the finalization machinery can detect this case.
1068 -- This early expansion is done only when the return statement is
1069 -- not part of a handled sequence of statements.
1071 if Nkind_In
(Expr
, N_Aggregate
,
1072 N_Extension_Aggregate
)
1073 and then Needs_Finalization
(R_Type
)
1074 and then Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
1077 Make_Block_Statement
(Loc
,
1078 Handled_Statement_Sequence
=>
1079 Make_Handled_Sequence_Of_Statements
(Loc
,
1080 Statements
=> New_List
(Relocate_Node
(N
)))));
1088 -- Ada 2005 (AI-251): If the type of the returned object is
1089 -- an access to an interface type then we add an implicit type
1090 -- conversion to force the displacement of the "this" pointer to
1091 -- reference the secondary dispatch table. We cannot delay the
1092 -- generation of this implicit conversion until the expansion
1093 -- because in this case the type resolution changes the decoration
1094 -- of the expression node to match R_Type; by contrast, if the
1095 -- returned object is a class-wide interface type then it is too
1096 -- early to generate here the implicit conversion since the return
1097 -- statement may be rewritten by the expander into an extended
1098 -- return statement whose expansion takes care of adding the
1099 -- implicit type conversion to displace the pointer to the object.
1102 and then Serious_Errors_Detected
= 0
1103 and then Is_Access_Type
(R_Type
)
1104 and then not Nkind_In
(Expr
, N_Null
, N_Raise_Expression
)
1105 and then Is_Interface
(Designated_Type
(R_Type
))
1106 and then Is_Progenitor
(Designated_Type
(R_Type
),
1107 Designated_Type
(Etype
(Expr
)))
1109 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1113 Resolve
(Expr
, R_Type
);
1114 Check_Limited_Return
(N
, Expr
, R_Type
);
1116 if Present
(Expr
) and then Nkind
(Expr
) = N_Aggregate
then
1117 Check_Aggregate_Accessibility
(Expr
);
1121 -- RETURN only allowed in SPARK as the last statement in function
1123 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
1125 (Nkind
(Parent
(Parent
(N
))) /= N_Subprogram_Body
1126 or else Present
(Next
(N
)))
1128 Check_SPARK_05_Restriction
1129 ("RETURN should be the last statement in function", N
);
1133 Check_SPARK_05_Restriction
("extended RETURN is not allowed", N
);
1134 Obj_Decl
:= Last
(Return_Object_Declarations
(N
));
1136 -- Analyze parts specific to extended_return_statement:
1139 Has_Aliased
: constant Boolean := Aliased_Present
(Obj_Decl
);
1140 HSS
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
1143 Expr
:= Expression
(Obj_Decl
);
1145 -- Note: The check for OK_For_Limited_Init will happen in
1146 -- Analyze_Object_Declaration; we treat it as a normal
1147 -- object declaration.
1149 Set_Is_Return_Object
(Defining_Identifier
(Obj_Decl
));
1152 Check_Return_Subtype_Indication
(Obj_Decl
);
1154 if Present
(HSS
) then
1157 if Present
(Exception_Handlers
(HSS
)) then
1159 -- ???Has_Nested_Block_With_Handler needs to be set.
1160 -- Probably by creating an actual N_Block_Statement.
1161 -- Probably in Expand.
1167 -- Mark the return object as referenced, since the return is an
1168 -- implicit reference of the object.
1170 Set_Referenced
(Defining_Identifier
(Obj_Decl
));
1172 Check_References
(Stm_Entity
);
1174 -- Check RM 6.5 (5.9/3)
1177 if Ada_Version
< Ada_2012
then
1179 -- Shouldn't this test Warn_On_Ada_2012_Compatibility ???
1180 -- Can it really happen (extended return???)
1183 ("aliased only allowed for limited return objects "
1184 & "in Ada 2012??", N
);
1186 elsif not Is_Limited_View
(R_Type
) then
1188 ("aliased only allowed for limited return objects", N
);
1194 -- Case of Expr present
1196 if Present
(Expr
) then
1198 -- Defend against previous errors
1200 if Nkind
(Expr
) = N_Empty
1201 or else No
(Etype
(Expr
))
1206 -- Apply constraint check. Note that this is done before the implicit
1207 -- conversion of the expression done for anonymous access types to
1208 -- ensure correct generation of the null-excluding check associated
1209 -- with null-excluding expressions found in return statements.
1211 Apply_Constraint_Check
(Expr
, R_Type
);
1213 -- Ada 2005 (AI-318-02): When the result type is an anonymous access
1214 -- type, apply an implicit conversion of the expression to that type
1215 -- to force appropriate static and run-time accessibility checks.
1217 if Ada_Version
>= Ada_2005
1218 and then Ekind
(R_Type
) = E_Anonymous_Access_Type
1220 Rewrite
(Expr
, Convert_To
(R_Type
, Relocate_Node
(Expr
)));
1221 Analyze_And_Resolve
(Expr
, R_Type
);
1223 -- If this is a local anonymous access to subprogram, the
1224 -- accessibility check can be applied statically. The return is
1225 -- illegal if the access type of the return expression is declared
1226 -- inside of the subprogram (except if it is the subtype indication
1227 -- of an extended return statement).
1229 elsif Ekind
(R_Type
) = E_Anonymous_Access_Subprogram_Type
then
1230 if not Comes_From_Source
(Current_Scope
)
1231 or else Ekind
(Current_Scope
) = E_Return_Statement
1236 Scope_Depth
(Scope
(Etype
(Expr
))) >= Scope_Depth
(Scope_Id
)
1238 Error_Msg_N
("cannot return local access to subprogram", N
);
1241 -- The expression cannot be of a formal incomplete type
1243 elsif Ekind
(Etype
(Expr
)) = E_Incomplete_Type
1244 and then Is_Generic_Type
(Etype
(Expr
))
1247 ("cannot return expression of a formal incomplete type", N
);
1250 -- If the result type is class-wide, then check that the return
1251 -- expression's type is not declared at a deeper level than the
1252 -- function (RM05-6.5(5.6/2)).
1254 if Ada_Version
>= Ada_2005
1255 and then Is_Class_Wide_Type
(R_Type
)
1257 if Type_Access_Level
(Etype
(Expr
)) >
1258 Subprogram_Access_Level
(Scope_Id
)
1261 ("level of return expression type is deeper than "
1262 & "class-wide function!", Expr
);
1266 -- Check incorrect use of dynamically tagged expression
1268 if Is_Tagged_Type
(R_Type
) then
1269 Check_Dynamically_Tagged_Expression
1275 -- ??? A real run-time accessibility check is needed in cases
1276 -- involving dereferences of access parameters. For now we just
1277 -- check the static cases.
1279 if (Ada_Version
< Ada_2005
or else Debug_Flag_Dot_L
)
1280 and then Is_Limited_View
(Etype
(Scope_Id
))
1281 and then Object_Access_Level
(Expr
) >
1282 Subprogram_Access_Level
(Scope_Id
)
1284 -- Suppress the message in a generic, where the rewriting
1287 if Inside_A_Generic
then
1292 Make_Raise_Program_Error
(Loc
,
1293 Reason
=> PE_Accessibility_Check_Failed
));
1296 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1297 Error_Msg_N
("cannot return a local value by reference<<", N
);
1298 Error_Msg_NE
("\& [<<", N
, Standard_Program_Error
);
1302 if Known_Null
(Expr
)
1303 and then Nkind
(Parent
(Scope_Id
)) = N_Function_Specification
1304 and then Null_Exclusion_Present
(Parent
(Scope_Id
))
1306 Apply_Compile_Time_Constraint_Error
1308 Msg
=> "(Ada 2005) null not allowed for "
1309 & "null-excluding return??",
1310 Reason
=> CE_Null_Not_Allowed
);
1313 -- RM 6.5 (5.4/3): accessibility checks also apply if the return object
1314 -- has no initializing expression.
1316 elsif Ada_Version
> Ada_2005
and then Is_Class_Wide_Type
(R_Type
) then
1317 if Type_Access_Level
(Etype
(Defining_Identifier
(Obj_Decl
))) >
1318 Subprogram_Access_Level
(Scope_Id
)
1321 ("level of return expression type is deeper than "
1322 & "class-wide function!", Obj_Decl
);
1325 end Analyze_Function_Return
;
1327 -------------------------------------
1328 -- Analyze_Generic_Subprogram_Body --
1329 -------------------------------------
1331 procedure Analyze_Generic_Subprogram_Body
1335 Gen_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Gen_Id
);
1336 Kind
: constant Entity_Kind
:= Ekind
(Gen_Id
);
1337 Body_Id
: Entity_Id
;
1342 -- Copy body and disable expansion while analyzing the generic For a
1343 -- stub, do not copy the stub (which would load the proper body), this
1344 -- will be done when the proper body is analyzed.
1346 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
1347 New_N
:= Copy_Generic_Node
(N
, Empty
, Instantiating
=> False);
1350 -- Once the contents of the generic copy and the template are
1351 -- swapped, do the same for their respective aspect specifications.
1353 Exchange_Aspects
(N
, New_N
);
1355 -- Collect all contract-related source pragmas found within the
1356 -- template and attach them to the contract of the subprogram body.
1357 -- This contract is used in the capture of global references within
1360 Create_Generic_Contract
(N
);
1365 Spec
:= Specification
(N
);
1367 -- Within the body of the generic, the subprogram is callable, and
1368 -- behaves like the corresponding non-generic unit.
1370 Body_Id
:= Defining_Entity
(Spec
);
1372 if Kind
= E_Generic_Procedure
1373 and then Nkind
(Spec
) /= N_Procedure_Specification
1375 Error_Msg_N
("invalid body for generic procedure ", Body_Id
);
1378 elsif Kind
= E_Generic_Function
1379 and then Nkind
(Spec
) /= N_Function_Specification
1381 Error_Msg_N
("invalid body for generic function ", Body_Id
);
1385 Set_Corresponding_Body
(Gen_Decl
, Body_Id
);
1387 if Has_Completion
(Gen_Id
)
1388 and then Nkind
(Parent
(N
)) /= N_Subunit
1390 Error_Msg_N
("duplicate generic body", N
);
1393 Set_Has_Completion
(Gen_Id
);
1396 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1397 Set_Ekind
(Defining_Entity
(Specification
(N
)), Kind
);
1399 Set_Corresponding_Spec
(N
, Gen_Id
);
1402 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
1403 Set_Cunit_Entity
(Current_Sem_Unit
, Defining_Entity
(N
));
1406 -- Make generic parameters immediately visible in the body. They are
1407 -- needed to process the formals declarations. Then make the formals
1408 -- visible in a separate step.
1410 Push_Scope
(Gen_Id
);
1414 First_Ent
: Entity_Id
;
1417 First_Ent
:= First_Entity
(Gen_Id
);
1420 while Present
(E
) and then not Is_Formal
(E
) loop
1425 Set_Use
(Generic_Formal_Declarations
(Gen_Decl
));
1427 -- Now generic formals are visible, and the specification can be
1428 -- analyzed, for subsequent conformance check.
1430 Body_Id
:= Analyze_Subprogram_Specification
(Spec
);
1432 -- Make formal parameters visible
1436 -- E is the first formal parameter, we loop through the formals
1437 -- installing them so that they will be visible.
1439 Set_First_Entity
(Gen_Id
, E
);
1440 while Present
(E
) loop
1446 -- Visible generic entity is callable within its own body
1448 Set_Ekind
(Gen_Id
, Ekind
(Body_Id
));
1449 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
1450 Set_Convention
(Body_Id
, Convention
(Gen_Id
));
1451 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Gen_Id
));
1452 Set_Scope
(Body_Id
, Scope
(Gen_Id
));
1454 Check_Fully_Conformant
(Body_Id
, Gen_Id
, Body_Id
);
1456 if Nkind
(N
) = N_Subprogram_Body_Stub
then
1458 -- No body to analyze, so restore state of generic unit
1460 Set_Ekind
(Gen_Id
, Kind
);
1461 Set_Ekind
(Body_Id
, Kind
);
1463 if Present
(First_Ent
) then
1464 Set_First_Entity
(Gen_Id
, First_Ent
);
1471 -- If this is a compilation unit, it must be made visible explicitly,
1472 -- because the compilation of the declaration, unlike other library
1473 -- unit declarations, does not. If it is not a unit, the following
1474 -- is redundant but harmless.
1476 Set_Is_Immediately_Visible
(Gen_Id
);
1477 Reference_Body_Formals
(Gen_Id
, Body_Id
);
1479 if Is_Child_Unit
(Gen_Id
) then
1480 Generate_Reference
(Gen_Id
, Scope
(Gen_Id
), 'k', False);
1483 Set_Actual_Subtypes
(N
, Current_Scope
);
1485 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
1486 Set_SPARK_Pragma_Inherited
(Body_Id
);
1488 -- Analyze any aspect specifications that appear on the generic
1491 if Has_Aspects
(N
) then
1492 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
1495 Analyze_Declarations
(Declarations
(N
));
1498 -- Process the contract of the subprogram body after all declarations
1499 -- have been analyzed. This ensures that any contract-related pragmas
1500 -- are available through the N_Contract node of the body.
1502 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
1504 Analyze
(Handled_Statement_Sequence
(N
));
1505 Save_Global_References
(Original_Node
(N
));
1507 -- Prior to exiting the scope, include generic formals again (if any
1508 -- are present) in the set of local entities.
1510 if Present
(First_Ent
) then
1511 Set_First_Entity
(Gen_Id
, First_Ent
);
1514 Check_References
(Gen_Id
);
1517 Process_End_Label
(Handled_Statement_Sequence
(N
), 't', Current_Scope
);
1518 Update_Use_Clause_Chain
;
1519 Validate_Categorization_Dependency
(N
, Gen_Id
);
1521 Check_Subprogram_Order
(N
);
1523 -- Outside of its body, unit is generic again
1525 Set_Ekind
(Gen_Id
, Kind
);
1526 Generate_Reference
(Gen_Id
, Body_Id
, 'b', Set_Ref
=> False);
1529 Style
.Check_Identifier
(Body_Id
, Gen_Id
);
1533 end Analyze_Generic_Subprogram_Body
;
1535 ----------------------------
1536 -- Analyze_Null_Procedure --
1537 ----------------------------
1539 procedure Analyze_Null_Procedure
1541 Is_Completion
: out Boolean)
1543 Loc
: constant Source_Ptr
:= Sloc
(N
);
1544 Spec
: constant Node_Id
:= Specification
(N
);
1545 Designator
: Entity_Id
;
1547 Null_Body
: Node_Id
:= Empty
;
1548 Null_Stmt
: Node_Id
:= Null_Statement
(Spec
);
1552 -- Capture the profile of the null procedure before analysis, for
1553 -- expansion at the freeze point and at each point of call. The body is
1554 -- used if the procedure has preconditions, or if it is a completion. In
1555 -- the first case the body is analyzed at the freeze point, in the other
1556 -- it replaces the null procedure declaration.
1558 -- For a null procedure that comes from source, a NULL statement is
1559 -- provided by the parser, which carries the source location of the
1560 -- NULL keyword, and has Comes_From_Source set. For a null procedure
1561 -- from expansion, create one now.
1563 if No
(Null_Stmt
) then
1564 Null_Stmt
:= Make_Null_Statement
(Loc
);
1568 Make_Subprogram_Body
(Loc
,
1569 Specification
=> New_Copy_Tree
(Spec
),
1570 Declarations
=> New_List
,
1571 Handled_Statement_Sequence
=>
1572 Make_Handled_Sequence_Of_Statements
(Loc
,
1573 Statements
=> New_List
(Null_Stmt
)));
1575 -- Create new entities for body and formals
1577 Set_Defining_Unit_Name
(Specification
(Null_Body
),
1578 Make_Defining_Identifier
1579 (Sloc
(Defining_Entity
(N
)),
1580 Chars
(Defining_Entity
(N
))));
1582 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1583 while Present
(Form
) loop
1584 Set_Defining_Identifier
(Form
,
1585 Make_Defining_Identifier
1586 (Sloc
(Defining_Identifier
(Form
)),
1587 Chars
(Defining_Identifier
(Form
))));
1591 -- Determine whether the null procedure may be a completion of a generic
1592 -- suprogram, in which case we use the new null body as the completion
1593 -- and set minimal semantic information on the original declaration,
1594 -- which is rewritten as a null statement.
1596 Prev
:= Current_Entity_In_Scope
(Defining_Entity
(Spec
));
1598 if Present
(Prev
) and then Is_Generic_Subprogram
(Prev
) then
1599 Insert_Before
(N
, Null_Body
);
1600 Set_Ekind
(Defining_Entity
(N
), Ekind
(Prev
));
1602 Rewrite
(N
, Make_Null_Statement
(Loc
));
1603 Analyze_Generic_Subprogram_Body
(Null_Body
, Prev
);
1604 Is_Completion
:= True;
1608 -- Resolve the types of the formals now, because the freeze point may
1609 -- appear in a different context, e.g. an instantiation.
1611 Form
:= First
(Parameter_Specifications
(Specification
(Null_Body
)));
1612 while Present
(Form
) loop
1613 if Nkind
(Parameter_Type
(Form
)) /= N_Access_Definition
then
1614 Find_Type
(Parameter_Type
(Form
));
1616 elsif No
(Access_To_Subprogram_Definition
1617 (Parameter_Type
(Form
)))
1619 Find_Type
(Subtype_Mark
(Parameter_Type
(Form
)));
1621 -- The case of a null procedure with a formal that is an
1622 -- access-to-subprogram type, and that is used as an actual
1623 -- in an instantiation is left to the enthusiastic reader.
1633 -- If there are previous overloadable entities with the same name, check
1634 -- whether any of them is completed by the null procedure.
1636 if Present
(Prev
) and then Is_Overloadable
(Prev
) then
1637 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1638 Prev
:= Find_Corresponding_Spec
(N
);
1641 if No
(Prev
) or else not Comes_From_Source
(Prev
) then
1642 Designator
:= Analyze_Subprogram_Specification
(Spec
);
1643 Set_Has_Completion
(Designator
);
1645 -- Signal to caller that this is a procedure declaration
1647 Is_Completion
:= False;
1649 -- Null procedures are always inlined, but generic formal subprograms
1650 -- which appear as such in the internal instance of formal packages,
1651 -- need no completion and are not marked Inline.
1654 and then Nkind
(N
) /= N_Formal_Concrete_Subprogram_Declaration
1656 Set_Corresponding_Body
(N
, Defining_Entity
(Null_Body
));
1657 Set_Body_To_Inline
(N
, Null_Body
);
1658 Set_Is_Inlined
(Designator
);
1662 -- The null procedure is a completion. We unconditionally rewrite
1663 -- this as a null body (even if expansion is not active), because
1664 -- there are various error checks that are applied on this body
1665 -- when it is analyzed (e.g. correct aspect placement).
1667 if Has_Completion
(Prev
) then
1668 Error_Msg_Sloc
:= Sloc
(Prev
);
1669 Error_Msg_NE
("duplicate body for & declared#", N
, Prev
);
1672 Check_Previous_Null_Procedure
(N
, Prev
);
1674 Is_Completion
:= True;
1675 Rewrite
(N
, Null_Body
);
1678 end Analyze_Null_Procedure
;
1680 -----------------------------
1681 -- Analyze_Operator_Symbol --
1682 -----------------------------
1684 -- An operator symbol such as "+" or "and" may appear in context where the
1685 -- literal denotes an entity name, such as "+"(x, y) or in context when it
1686 -- is just a string, as in (conjunction = "or"). In these cases the parser
1687 -- generates this node, and the semantics does the disambiguation. Other
1688 -- such case are actuals in an instantiation, the generic unit in an
1689 -- instantiation, and pragma arguments.
1691 procedure Analyze_Operator_Symbol
(N
: Node_Id
) is
1692 Par
: constant Node_Id
:= Parent
(N
);
1695 if (Nkind
(Par
) = N_Function_Call
and then N
= Name
(Par
))
1696 or else Nkind
(Par
) = N_Function_Instantiation
1697 or else (Nkind
(Par
) = N_Indexed_Component
and then N
= Prefix
(Par
))
1698 or else (Nkind
(Par
) = N_Pragma_Argument_Association
1699 and then not Is_Pragma_String_Literal
(Par
))
1700 or else Nkind
(Par
) = N_Subprogram_Renaming_Declaration
1701 or else (Nkind
(Par
) = N_Attribute_Reference
1702 and then Attribute_Name
(Par
) /= Name_Value
)
1704 Find_Direct_Name
(N
);
1707 Change_Operator_Symbol_To_String_Literal
(N
);
1710 end Analyze_Operator_Symbol
;
1712 -----------------------------------
1713 -- Analyze_Parameter_Association --
1714 -----------------------------------
1716 procedure Analyze_Parameter_Association
(N
: Node_Id
) is
1718 Analyze
(Explicit_Actual_Parameter
(N
));
1719 end Analyze_Parameter_Association
;
1721 ----------------------------
1722 -- Analyze_Procedure_Call --
1723 ----------------------------
1725 -- WARNING: This routine manages Ghost regions. Return statements must be
1726 -- replaced by gotos which jump to the end of the routine and restore the
1729 procedure Analyze_Procedure_Call
(N
: Node_Id
) is
1730 procedure Analyze_Call_And_Resolve
;
1731 -- Do Analyze and Resolve calls for procedure call. At the end, check
1732 -- for illegal order dependence.
1733 -- ??? where is the check for illegal order dependencies?
1735 ------------------------------
1736 -- Analyze_Call_And_Resolve --
1737 ------------------------------
1739 procedure Analyze_Call_And_Resolve
is
1741 if Nkind
(N
) = N_Procedure_Call_Statement
then
1743 Resolve
(N
, Standard_Void_Type
);
1747 end Analyze_Call_And_Resolve
;
1751 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
1752 Loc
: constant Source_Ptr
:= Sloc
(N
);
1753 P
: constant Node_Id
:= Name
(N
);
1755 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1756 -- Save the Ghost mode to restore on exit
1761 -- Start of processing for Analyze_Procedure_Call
1764 -- The syntactic construct: PREFIX ACTUAL_PARAMETER_PART can denote
1765 -- a procedure call or an entry call. The prefix may denote an access
1766 -- to subprogram type, in which case an implicit dereference applies.
1767 -- If the prefix is an indexed component (without implicit dereference)
1768 -- then the construct denotes a call to a member of an entire family.
1769 -- If the prefix is a simple name, it may still denote a call to a
1770 -- parameterless member of an entry family. Resolution of these various
1771 -- interpretations is delicate.
1773 -- Do not analyze machine code statements to avoid rejecting them in
1776 if CodePeer_Mode
and then Nkind
(P
) = N_Qualified_Expression
then
1777 Set_Etype
(P
, Standard_Void_Type
);
1782 -- If this is a call of the form Obj.Op, the call may have been analyzed
1783 -- and possibly rewritten into a block, in which case we are done.
1785 if Analyzed
(N
) then
1788 -- If there is an error analyzing the name (which may have been
1789 -- rewritten if the original call was in prefix notation) then error
1790 -- has been emitted already, mark node and return.
1792 elsif Error_Posted
(N
) or else Etype
(Name
(N
)) = Any_Type
then
1793 Set_Etype
(N
, Any_Type
);
1797 -- A procedure call is Ghost when its name denotes a Ghost procedure.
1798 -- Set the mode now to ensure that any nodes generated during analysis
1799 -- and expansion are properly marked as Ghost.
1801 Mark_And_Set_Ghost_Procedure_Call
(N
);
1803 -- Otherwise analyze the parameters
1805 if Present
(Actuals
) then
1806 Actual
:= First
(Actuals
);
1808 while Present
(Actual
) loop
1810 Check_Parameterless_Call
(Actual
);
1815 -- Special processing for Elab_Spec, Elab_Body and Elab_Subp_Body calls
1817 if Nkind
(P
) = N_Attribute_Reference
1818 and then Nam_In
(Attribute_Name
(P
), Name_Elab_Spec
,
1820 Name_Elab_Subp_Body
)
1822 if Present
(Actuals
) then
1824 ("no parameters allowed for this call", First
(Actuals
));
1828 Set_Etype
(N
, Standard_Void_Type
);
1831 elsif Is_Entity_Name
(P
)
1832 and then Is_Record_Type
(Etype
(Entity
(P
)))
1833 and then Remote_AST_I_Dereference
(P
)
1837 elsif Is_Entity_Name
(P
)
1838 and then Ekind
(Entity
(P
)) /= E_Entry_Family
1840 if Is_Access_Type
(Etype
(P
))
1841 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1842 and then No
(Actuals
)
1843 and then Comes_From_Source
(N
)
1845 Error_Msg_N
("missing explicit dereference in call", N
);
1848 Analyze_Call_And_Resolve
;
1850 -- If the prefix is the simple name of an entry family, this is a
1851 -- parameterless call from within the task body itself.
1853 elsif Is_Entity_Name
(P
)
1854 and then Nkind
(P
) = N_Identifier
1855 and then Ekind
(Entity
(P
)) = E_Entry_Family
1856 and then Present
(Actuals
)
1857 and then No
(Next
(First
(Actuals
)))
1859 -- Can be call to parameterless entry family. What appears to be the
1860 -- sole argument is in fact the entry index. Rewrite prefix of node
1861 -- accordingly. Source representation is unchanged by this
1865 Make_Indexed_Component
(Loc
,
1867 Make_Selected_Component
(Loc
,
1868 Prefix
=> New_Occurrence_Of
(Scope
(Entity
(P
)), Loc
),
1869 Selector_Name
=> New_Occurrence_Of
(Entity
(P
), Loc
)),
1870 Expressions
=> Actuals
);
1871 Set_Name
(N
, New_N
);
1872 Set_Etype
(New_N
, Standard_Void_Type
);
1873 Set_Parameter_Associations
(N
, No_List
);
1874 Analyze_Call_And_Resolve
;
1876 elsif Nkind
(P
) = N_Explicit_Dereference
then
1877 if Ekind
(Etype
(P
)) = E_Subprogram_Type
then
1878 Analyze_Call_And_Resolve
;
1880 Error_Msg_N
("expect access to procedure in call", P
);
1883 -- The name can be a selected component or an indexed component that
1884 -- yields an access to subprogram. Such a prefix is legal if the call
1885 -- has parameter associations.
1887 elsif Is_Access_Type
(Etype
(P
))
1888 and then Ekind
(Designated_Type
(Etype
(P
))) = E_Subprogram_Type
1890 if Present
(Actuals
) then
1891 Analyze_Call_And_Resolve
;
1893 Error_Msg_N
("missing explicit dereference in call ", N
);
1896 -- If not an access to subprogram, then the prefix must resolve to the
1897 -- name of an entry, entry family, or protected operation.
1899 -- For the case of a simple entry call, P is a selected component where
1900 -- the prefix is the task and the selector name is the entry. A call to
1901 -- a protected procedure will have the same syntax. If the protected
1902 -- object contains overloaded operations, the entity may appear as a
1903 -- function, the context will select the operation whose type is Void.
1905 elsif Nkind
(P
) = N_Selected_Component
1906 and then Ekind_In
(Entity
(Selector_Name
(P
)), E_Entry
,
1910 -- When front-end inlining is enabled, as with SPARK_Mode, a call
1911 -- in prefix notation may still be missing its controlling argument,
1912 -- so perform the transformation now.
1914 if SPARK_Mode
= On
and then In_Inlined_Body
then
1916 Subp
: constant Entity_Id
:= Entity
(Selector_Name
(P
));
1917 Typ
: constant Entity_Id
:= Etype
(Prefix
(P
));
1920 if Is_Tagged_Type
(Typ
)
1921 and then Present
(First_Formal
(Subp
))
1922 and then Etype
(First_Formal
(Subp
)) = Typ
1923 and then Try_Object_Operation
(P
)
1928 Analyze_Call_And_Resolve
;
1933 Analyze_Call_And_Resolve
;
1936 elsif Nkind
(P
) = N_Selected_Component
1937 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry_Family
1938 and then Present
(Actuals
)
1939 and then No
(Next
(First
(Actuals
)))
1941 -- Can be call to parameterless entry family. What appears to be the
1942 -- sole argument is in fact the entry index. Rewrite prefix of node
1943 -- accordingly. Source representation is unchanged by this
1947 Make_Indexed_Component
(Loc
,
1948 Prefix
=> New_Copy
(P
),
1949 Expressions
=> Actuals
);
1950 Set_Name
(N
, New_N
);
1951 Set_Etype
(New_N
, Standard_Void_Type
);
1952 Set_Parameter_Associations
(N
, No_List
);
1953 Analyze_Call_And_Resolve
;
1955 -- For the case of a reference to an element of an entry family, P is
1956 -- an indexed component whose prefix is a selected component (task and
1957 -- entry family), and whose index is the entry family index.
1959 elsif Nkind
(P
) = N_Indexed_Component
1960 and then Nkind
(Prefix
(P
)) = N_Selected_Component
1961 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) = E_Entry_Family
1963 Analyze_Call_And_Resolve
;
1965 -- If the prefix is the name of an entry family, it is a call from
1966 -- within the task body itself.
1968 elsif Nkind
(P
) = N_Indexed_Component
1969 and then Nkind
(Prefix
(P
)) = N_Identifier
1970 and then Ekind
(Entity
(Prefix
(P
))) = E_Entry_Family
1973 Make_Selected_Component
(Loc
,
1975 New_Occurrence_Of
(Scope
(Entity
(Prefix
(P
))), Loc
),
1976 Selector_Name
=> New_Occurrence_Of
(Entity
(Prefix
(P
)), Loc
));
1977 Rewrite
(Prefix
(P
), New_N
);
1979 Analyze_Call_And_Resolve
;
1981 -- In Ada 2012. a qualified expression is a name, but it cannot be a
1982 -- procedure name, so the construct can only be a qualified expression.
1984 elsif Nkind
(P
) = N_Qualified_Expression
1985 and then Ada_Version
>= Ada_2012
1987 Rewrite
(N
, Make_Code_Statement
(Loc
, Expression
=> P
));
1990 -- Anything else is an error
1993 Error_Msg_N
("invalid procedure or entry call", N
);
1997 Restore_Ghost_Mode
(Saved_GM
);
1998 end Analyze_Procedure_Call
;
2000 ------------------------------
2001 -- Analyze_Return_Statement --
2002 ------------------------------
2004 procedure Analyze_Return_Statement
(N
: Node_Id
) is
2005 pragma Assert
(Nkind_In
(N
, N_Extended_Return_Statement
,
2006 N_Simple_Return_Statement
));
2008 Returns_Object
: constant Boolean :=
2009 Nkind
(N
) = N_Extended_Return_Statement
2011 (Nkind
(N
) = N_Simple_Return_Statement
2012 and then Present
(Expression
(N
)));
2013 -- True if we're returning something; that is, "return <expression>;"
2014 -- or "return Result : T [:= ...]". False for "return;". Used for error
2015 -- checking: If Returns_Object is True, N should apply to a function
2016 -- body; otherwise N should apply to a procedure body, entry body,
2017 -- accept statement, or extended return statement.
2019 function Find_What_It_Applies_To
return Entity_Id
;
2020 -- Find the entity representing the innermost enclosing body, accept
2021 -- statement, or extended return statement. If the result is a callable
2022 -- construct or extended return statement, then this will be the value
2023 -- of the Return_Applies_To attribute. Otherwise, the program is
2024 -- illegal. See RM-6.5(4/2).
2026 -----------------------------
2027 -- Find_What_It_Applies_To --
2028 -----------------------------
2030 function Find_What_It_Applies_To
return Entity_Id
is
2031 Result
: Entity_Id
:= Empty
;
2034 -- Loop outward through the Scope_Stack, skipping blocks, loops,
2035 -- and postconditions.
2037 for J
in reverse 0 .. Scope_Stack
.Last
loop
2038 Result
:= Scope_Stack
.Table
(J
).Entity
;
2039 exit when not Ekind_In
(Result
, E_Block
, E_Loop
)
2040 and then Chars
(Result
) /= Name_uPostconditions
;
2043 pragma Assert
(Present
(Result
));
2045 end Find_What_It_Applies_To
;
2047 -- Local declarations
2049 Scope_Id
: constant Entity_Id
:= Find_What_It_Applies_To
;
2050 Kind
: constant Entity_Kind
:= Ekind
(Scope_Id
);
2051 Loc
: constant Source_Ptr
:= Sloc
(N
);
2052 Stm_Entity
: constant Entity_Id
:=
2054 (E_Return_Statement
, Current_Scope
, Loc
, 'R');
2056 -- Start of processing for Analyze_Return_Statement
2059 Set_Return_Statement_Entity
(N
, Stm_Entity
);
2061 Set_Etype
(Stm_Entity
, Standard_Void_Type
);
2062 Set_Return_Applies_To
(Stm_Entity
, Scope_Id
);
2064 -- Place Return entity on scope stack, to simplify enforcement of 6.5
2065 -- (4/2): an inner return statement will apply to this extended return.
2067 if Nkind
(N
) = N_Extended_Return_Statement
then
2068 Push_Scope
(Stm_Entity
);
2071 -- Check that pragma No_Return is obeyed. Don't complain about the
2072 -- implicitly-generated return that is placed at the end.
2074 if No_Return
(Scope_Id
) and then Comes_From_Source
(N
) then
2075 Error_Msg_N
("RETURN statement not allowed (No_Return)", N
);
2078 -- Warn on any unassigned OUT parameters if in procedure
2080 if Ekind
(Scope_Id
) = E_Procedure
then
2081 Warn_On_Unassigned_Out_Parameter
(N
, Scope_Id
);
2084 -- Check that functions return objects, and other things do not
2086 if Kind
= E_Function
or else Kind
= E_Generic_Function
then
2087 if not Returns_Object
then
2088 Error_Msg_N
("missing expression in return from function", N
);
2091 elsif Kind
= E_Procedure
or else Kind
= E_Generic_Procedure
then
2092 if Returns_Object
then
2093 Error_Msg_N
("procedure cannot return value (use function)", N
);
2096 elsif Kind
= E_Entry
or else Kind
= E_Entry_Family
then
2097 if Returns_Object
then
2098 if Is_Protected_Type
(Scope
(Scope_Id
)) then
2099 Error_Msg_N
("entry body cannot return value", N
);
2101 Error_Msg_N
("accept statement cannot return value", N
);
2105 elsif Kind
= E_Return_Statement
then
2107 -- We are nested within another return statement, which must be an
2108 -- extended_return_statement.
2110 if Returns_Object
then
2111 if Nkind
(N
) = N_Extended_Return_Statement
then
2113 ("extended return statement cannot be nested (use `RETURN;`)",
2116 -- Case of a simple return statement with a value inside extended
2117 -- return statement.
2121 ("return nested in extended return statement cannot return "
2122 & "value (use `RETURN;`)", N
);
2127 Error_Msg_N
("illegal context for return statement", N
);
2130 if Ekind_In
(Kind
, E_Function
, E_Generic_Function
) then
2131 Analyze_Function_Return
(N
);
2133 elsif Ekind_In
(Kind
, E_Procedure
, E_Generic_Procedure
) then
2134 Set_Return_Present
(Scope_Id
);
2137 if Nkind
(N
) = N_Extended_Return_Statement
then
2141 Kill_Current_Values
(Last_Assignment_Only
=> True);
2142 Check_Unreachable_Code
(N
);
2144 Analyze_Dimension
(N
);
2145 end Analyze_Return_Statement
;
2147 -------------------------------------
2148 -- Analyze_Simple_Return_Statement --
2149 -------------------------------------
2151 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
) is
2153 if Present
(Expression
(N
)) then
2154 Mark_Coextensions
(N
, Expression
(N
));
2157 Analyze_Return_Statement
(N
);
2158 end Analyze_Simple_Return_Statement
;
2160 -------------------------
2161 -- Analyze_Return_Type --
2162 -------------------------
2164 procedure Analyze_Return_Type
(N
: Node_Id
) is
2165 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
2166 Typ
: Entity_Id
:= Empty
;
2169 -- Normal case where result definition does not indicate an error
2171 if Result_Definition
(N
) /= Error
then
2172 if Nkind
(Result_Definition
(N
)) = N_Access_Definition
then
2173 Check_SPARK_05_Restriction
2174 ("access result is not allowed", Result_Definition
(N
));
2176 -- Ada 2005 (AI-254): Handle anonymous access to subprograms
2179 AD
: constant Node_Id
:=
2180 Access_To_Subprogram_Definition
(Result_Definition
(N
));
2182 if Present
(AD
) and then Protected_Present
(AD
) then
2183 Typ
:= Replace_Anonymous_Access_To_Protected_Subprogram
(N
);
2185 Typ
:= Access_Definition
(N
, Result_Definition
(N
));
2189 Set_Parent
(Typ
, Result_Definition
(N
));
2190 Set_Is_Local_Anonymous_Access
(Typ
);
2191 Set_Etype
(Designator
, Typ
);
2193 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2195 Null_Exclusion_Static_Checks
(N
);
2197 -- Subtype_Mark case
2200 Find_Type
(Result_Definition
(N
));
2201 Typ
:= Entity
(Result_Definition
(N
));
2202 Set_Etype
(Designator
, Typ
);
2204 -- Unconstrained array as result is not allowed in SPARK
2206 if Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
2207 Check_SPARK_05_Restriction
2208 ("returning an unconstrained array is not allowed",
2209 Result_Definition
(N
));
2212 -- Ada 2005 (AI-231): Ensure proper usage of null exclusion
2214 Null_Exclusion_Static_Checks
(N
);
2216 -- If a null exclusion is imposed on the result type, then create
2217 -- a null-excluding itype (an access subtype) and use it as the
2218 -- function's Etype. Note that the null exclusion checks are done
2219 -- right before this, because they don't get applied to types that
2220 -- do not come from source.
2222 if Is_Access_Type
(Typ
) and then Null_Exclusion_Present
(N
) then
2223 Set_Etype
(Designator
,
2224 Create_Null_Excluding_Itype
2227 Scope_Id
=> Scope
(Current_Scope
)));
2229 -- The new subtype must be elaborated before use because
2230 -- it is visible outside of the function. However its base
2231 -- type may not be frozen yet, so the reference that will
2232 -- force elaboration must be attached to the freezing of
2235 -- If the return specification appears on a proper body,
2236 -- the subtype will have been created already on the spec.
2238 if Is_Frozen
(Typ
) then
2239 if Nkind
(Parent
(N
)) = N_Subprogram_Body
2240 and then Nkind
(Parent
(Parent
(N
))) = N_Subunit
2244 Build_Itype_Reference
(Etype
(Designator
), Parent
(N
));
2248 Ensure_Freeze_Node
(Typ
);
2251 IR
: constant Node_Id
:= Make_Itype_Reference
(Sloc
(N
));
2253 Set_Itype
(IR
, Etype
(Designator
));
2254 Append_Freeze_Actions
(Typ
, New_List
(IR
));
2259 Set_Etype
(Designator
, Typ
);
2262 if Ekind
(Typ
) = E_Incomplete_Type
2263 or else (Is_Class_Wide_Type
(Typ
)
2264 and then Ekind
(Root_Type
(Typ
)) = E_Incomplete_Type
)
2266 -- AI05-0151: Tagged incomplete types are allowed in all formal
2267 -- parts. Untagged incomplete types are not allowed in bodies.
2268 -- As a consequence, limited views cannot appear in a basic
2269 -- declaration that is itself within a body, because there is
2270 -- no point at which the non-limited view will become visible.
2272 if Ada_Version
>= Ada_2012
then
2273 if From_Limited_With
(Typ
) and then In_Package_Body
then
2275 ("invalid use of incomplete type&",
2276 Result_Definition
(N
), Typ
);
2278 -- The return type of a subprogram body cannot be of a
2279 -- formal incomplete type.
2281 elsif Is_Generic_Type
(Typ
)
2282 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2285 ("return type cannot be a formal incomplete type",
2286 Result_Definition
(N
));
2288 elsif Is_Class_Wide_Type
(Typ
)
2289 and then Is_Generic_Type
(Root_Type
(Typ
))
2290 and then Nkind
(Parent
(N
)) = N_Subprogram_Body
2293 ("return type cannot be a formal incomplete type",
2294 Result_Definition
(N
));
2296 elsif Is_Tagged_Type
(Typ
) then
2299 -- Use is legal in a thunk generated for an operation
2300 -- inherited from a progenitor.
2302 elsif Is_Thunk
(Designator
)
2303 and then Present
(Non_Limited_View
(Typ
))
2307 elsif Nkind
(Parent
(N
)) = N_Subprogram_Body
2308 or else Nkind_In
(Parent
(Parent
(N
)), N_Accept_Statement
,
2312 ("invalid use of untagged incomplete type&",
2316 -- The type must be completed in the current package. This
2317 -- is checked at the end of the package declaration when
2318 -- Taft-amendment types are identified. If the return type
2319 -- is class-wide, there is no required check, the type can
2320 -- be a bona fide TAT.
2322 if Ekind
(Scope
(Current_Scope
)) = E_Package
2323 and then In_Private_Part
(Scope
(Current_Scope
))
2324 and then not Is_Class_Wide_Type
(Typ
)
2326 Append_Elmt
(Designator
, Private_Dependents
(Typ
));
2331 ("invalid use of incomplete type&", Designator
, Typ
);
2336 -- Case where result definition does indicate an error
2339 Set_Etype
(Designator
, Any_Type
);
2341 end Analyze_Return_Type
;
2343 -----------------------------
2344 -- Analyze_Subprogram_Body --
2345 -----------------------------
2347 procedure Analyze_Subprogram_Body
(N
: Node_Id
) is
2348 Loc
: constant Source_Ptr
:= Sloc
(N
);
2349 Body_Spec
: constant Node_Id
:= Specification
(N
);
2350 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Spec
);
2353 if Debug_Flag_C
then
2354 Write_Str
("==> subprogram body ");
2355 Write_Name
(Chars
(Body_Id
));
2356 Write_Str
(" from ");
2357 Write_Location
(Loc
);
2362 Trace_Scope
(N
, Body_Id
, " Analyze subprogram: ");
2364 -- The real work is split out into the helper, so it can do "return;"
2365 -- without skipping the debug output:
2367 Analyze_Subprogram_Body_Helper
(N
);
2369 if Debug_Flag_C
then
2371 Write_Str
("<== subprogram body ");
2372 Write_Name
(Chars
(Body_Id
));
2373 Write_Str
(" from ");
2374 Write_Location
(Loc
);
2377 end Analyze_Subprogram_Body
;
2379 ------------------------------------
2380 -- Analyze_Subprogram_Body_Helper --
2381 ------------------------------------
2383 -- This procedure is called for regular subprogram bodies, generic bodies,
2384 -- and for subprogram stubs of both kinds. In the case of stubs, only the
2385 -- specification matters, and is used to create a proper declaration for
2386 -- the subprogram, or to perform conformance checks.
2388 -- WARNING: This routine manages Ghost regions. Return statements must be
2389 -- replaced by gotos which jump to the end of the routine and restore the
2392 procedure Analyze_Subprogram_Body_Helper
(N
: Node_Id
) is
2393 Body_Spec
: Node_Id
:= Specification
(N
);
2394 Body_Id
: Entity_Id
:= Defining_Entity
(Body_Spec
);
2395 Loc
: constant Source_Ptr
:= Sloc
(N
);
2396 Prev_Id
: constant Entity_Id
:= Current_Entity_In_Scope
(Body_Id
);
2398 Conformant
: Boolean;
2399 Desig_View
: Entity_Id
:= Empty
;
2400 Exch_Views
: Elist_Id
:= No_Elist
;
2402 Mask_Types
: Elist_Id
:= No_Elist
;
2403 Prot_Typ
: Entity_Id
:= Empty
;
2404 Spec_Decl
: Node_Id
:= Empty
;
2405 Spec_Id
: Entity_Id
;
2407 Last_Real_Spec_Entity
: Entity_Id
:= Empty
;
2408 -- When we analyze a separate spec, the entity chain ends up containing
2409 -- the formals, as well as any itypes generated during analysis of the
2410 -- default expressions for parameters, or the arguments of associated
2411 -- precondition/postcondition pragmas (which are analyzed in the context
2412 -- of the spec since they have visibility on formals).
2414 -- These entities belong with the spec and not the body. However we do
2415 -- the analysis of the body in the context of the spec (again to obtain
2416 -- visibility to the formals), and all the entities generated during
2417 -- this analysis end up also chained to the entity chain of the spec.
2418 -- But they really belong to the body, and there is circuitry to move
2419 -- them from the spec to the body.
2421 -- However, when we do this move, we don't want to move the real spec
2422 -- entities (first para above) to the body. The Last_Real_Spec_Entity
2423 -- variable points to the last real spec entity, so we only move those
2424 -- chained beyond that point. It is initialized to Empty to deal with
2425 -- the case where there is no separate spec.
2427 function Body_Has_Contract
return Boolean;
2428 -- Check whether unanalyzed body has an aspect or pragma that may
2429 -- generate a SPARK contract.
2431 function Body_Has_SPARK_Mode_On
return Boolean;
2432 -- Check whether SPARK_Mode On applies to the subprogram body, either
2433 -- because it is specified directly on the body, or because it is
2434 -- inherited from the enclosing subprogram or package.
2436 procedure Build_Subprogram_Declaration
;
2437 -- Create a matching subprogram declaration for subprogram body N
2439 procedure Check_Anonymous_Return
;
2440 -- Ada 2005: if a function returns an access type that denotes a task,
2441 -- or a type that contains tasks, we must create a master entity for
2442 -- the anonymous type, which typically will be used in an allocator
2443 -- in the body of the function.
2445 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
);
2446 -- Look ahead to recognize a pragma that may appear after the body.
2447 -- If there is a previous spec, check that it appears in the same
2448 -- declarative part. If the pragma is Inline_Always, perform inlining
2449 -- unconditionally, otherwise only if Front_End_Inlining is requested.
2450 -- If the body acts as a spec, and inlining is required, we create a
2451 -- subprogram declaration for it, in order to attach the body to inline.
2452 -- If pragma does not appear after the body, check whether there is
2453 -- an inline pragma before any local declarations.
2455 procedure Check_Missing_Return
;
2456 -- Checks for a function with a no return statements, and also performs
2457 -- the warning checks implemented by Check_Returns. In formal mode, also
2458 -- verify that a function ends with a RETURN and that a procedure does
2459 -- not contain any RETURN.
2461 function Disambiguate_Spec
return Entity_Id
;
2462 -- When a primitive is declared between the private view and the full
2463 -- view of a concurrent type which implements an interface, a special
2464 -- mechanism is used to find the corresponding spec of the primitive
2467 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
;
2468 -- Ada 2012 (AI05-0151): Detect whether the profile of Subp_Id contains
2469 -- incomplete types coming from a limited context and replace their
2470 -- limited views with the non-limited ones. Return the list of changes
2471 -- to be used to undo the transformation.
2473 function Is_Private_Concurrent_Primitive
2474 (Subp_Id
: Entity_Id
) return Boolean;
2475 -- Determine whether subprogram Subp_Id is a primitive of a concurrent
2476 -- type that implements an interface and has a private view.
2478 function Mask_Unfrozen_Types
(Spec_Id
: Entity_Id
) return Elist_Id
;
2479 -- N is the body generated for an expression function that is not a
2480 -- completion and Spec_Id the defining entity of its spec. Mark all
2481 -- the not-yet-frozen types referenced by the simple return statement
2482 -- of the function as formally frozen.
2484 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
);
2485 -- Undo the transformation done by Exchange_Limited_Views.
2487 procedure Set_Trivial_Subprogram
(N
: Node_Id
);
2488 -- Sets the Is_Trivial_Subprogram flag in both spec and body of the
2489 -- subprogram whose body is being analyzed. N is the statement node
2490 -- causing the flag to be set, if the following statement is a return
2491 -- of an entity, we mark the entity as set in source to suppress any
2492 -- warning on the stylized use of function stubs with a dummy return.
2494 procedure Unmask_Unfrozen_Types
(Unmask_List
: Elist_Id
);
2495 -- Undo the transformation done by Mask_Unfrozen_Types
2497 procedure Verify_Overriding_Indicator
;
2498 -- If there was a previous spec, the entity has been entered in the
2499 -- current scope previously. If the body itself carries an overriding
2500 -- indicator, check that it is consistent with the known status of the
2503 -----------------------
2504 -- Body_Has_Contract --
2505 -----------------------
2507 function Body_Has_Contract
return Boolean is
2508 Decls
: constant List_Id
:= Declarations
(N
);
2512 -- Check for aspects that may generate a contract
2514 if Present
(Aspect_Specifications
(N
)) then
2515 Item
:= First
(Aspect_Specifications
(N
));
2516 while Present
(Item
) loop
2517 if Is_Subprogram_Contract_Annotation
(Item
) then
2525 -- Check for pragmas that may generate a contract
2527 if Present
(Decls
) then
2528 Item
:= First
(Decls
);
2529 while Present
(Item
) loop
2530 if Nkind
(Item
) = N_Pragma
2531 and then Is_Subprogram_Contract_Annotation
(Item
)
2541 end Body_Has_Contract
;
2543 ----------------------------
2544 -- Body_Has_SPARK_Mode_On --
2545 ----------------------------
2547 function Body_Has_SPARK_Mode_On
return Boolean is
2548 Decls
: constant List_Id
:= Declarations
(N
);
2552 -- Check for SPARK_Mode aspect
2554 if Present
(Aspect_Specifications
(N
)) then
2555 Item
:= First
(Aspect_Specifications
(N
));
2556 while Present
(Item
) loop
2557 if Get_Aspect_Id
(Item
) = Aspect_SPARK_Mode
then
2558 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2565 -- Check for SPARK_Mode pragma
2567 if Present
(Decls
) then
2568 Item
:= First
(Decls
);
2569 while Present
(Item
) loop
2571 -- Pragmas that apply to a subprogram body are usually grouped
2572 -- together. Look for a potential pragma SPARK_Mode among them.
2574 if Nkind
(Item
) = N_Pragma
then
2575 if Get_Pragma_Id
(Item
) = Pragma_SPARK_Mode
then
2576 return Get_SPARK_Mode_From_Annotation
(Item
) = On
;
2579 -- Otherwise the first non-pragma declarative item terminates
2580 -- the region where pragma SPARK_Mode may appear.
2590 -- Otherwise, the applicable SPARK_Mode is inherited from the
2591 -- enclosing subprogram or package.
2593 return SPARK_Mode
= On
;
2594 end Body_Has_SPARK_Mode_On
;
2596 ----------------------------------
2597 -- Build_Subprogram_Declaration --
2598 ----------------------------------
2600 procedure Build_Subprogram_Declaration
is
2601 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
);
2602 -- Relocate certain categorization pragmas from the declarative list
2603 -- of subprogram body From and insert them after node To. The pragmas
2606 -- Volatile_Function
2607 -- Also copy pragma SPARK_Mode if present in the declarative list
2608 -- of subprogram body From and insert it after node To. This pragma
2609 -- should not be moved, as it applies to the body too.
2615 procedure Move_Pragmas
(From
: Node_Id
; To
: Node_Id
) is
2617 Next_Decl
: Node_Id
;
2620 pragma Assert
(Nkind
(From
) = N_Subprogram_Body
);
2622 -- The destination node must be part of a list, as the pragmas are
2623 -- inserted after it.
2625 pragma Assert
(Is_List_Member
(To
));
2627 -- Inspect the declarations of the subprogram body looking for
2628 -- specific pragmas.
2630 Decl
:= First
(Declarations
(N
));
2631 while Present
(Decl
) loop
2632 Next_Decl
:= Next
(Decl
);
2634 if Nkind
(Decl
) = N_Pragma
then
2635 if Pragma_Name_Unmapped
(Decl
) = Name_SPARK_Mode
then
2636 Insert_After
(To
, New_Copy_Tree
(Decl
));
2638 elsif Nam_In
(Pragma_Name_Unmapped
(Decl
),
2640 Name_Volatile_Function
)
2643 Insert_After
(To
, Decl
);
2654 Subp_Decl
: Node_Id
;
2656 -- Start of processing for Build_Subprogram_Declaration
2659 -- Create a matching subprogram spec using the profile of the body.
2660 -- The structure of the tree is identical, but has new entities for
2661 -- the defining unit name and formal parameters.
2664 Make_Subprogram_Declaration
(Loc
,
2665 Specification
=> Copy_Subprogram_Spec
(Body_Spec
));
2666 Set_Comes_From_Source
(Subp_Decl
, True);
2668 -- Relocate the aspects and relevant pragmas from the subprogram body
2669 -- to the generated spec because it acts as the initial declaration.
2671 Insert_Before
(N
, Subp_Decl
);
2672 Move_Aspects
(N
, To
=> Subp_Decl
);
2673 Move_Pragmas
(N
, To
=> Subp_Decl
);
2675 -- Ensure that the generated corresponding spec and original body
2676 -- share the same SPARK_Mode pragma or aspect. As a result, both have
2677 -- the same SPARK_Mode attributes, and the global SPARK_Mode value is
2678 -- correctly set for local subprograms.
2680 Copy_SPARK_Mode_Aspect
(Subp_Decl
, To
=> N
);
2682 Analyze
(Subp_Decl
);
2684 -- Propagate the attributes Rewritten_For_C and Corresponding_Proc to
2685 -- the body since the expander may generate calls using that entity.
2686 -- Required to ensure that Expand_Call rewrites calls to this
2687 -- function by calls to the built procedure.
2689 if Modify_Tree_For_C
2690 and then Nkind
(Body_Spec
) = N_Function_Specification
2692 Rewritten_For_C
(Defining_Entity
(Specification
(Subp_Decl
)))
2694 Set_Rewritten_For_C
(Defining_Entity
(Body_Spec
));
2695 Set_Corresponding_Procedure
(Defining_Entity
(Body_Spec
),
2696 Corresponding_Procedure
2697 (Defining_Entity
(Specification
(Subp_Decl
))));
2700 -- Analyze any relocated source pragmas or pragmas created for aspect
2703 Decl
:= Next
(Subp_Decl
);
2704 while Present
(Decl
) loop
2706 -- Stop the search for pragmas once the body has been reached as
2707 -- this terminates the region where pragmas may appear.
2712 elsif Nkind
(Decl
) = N_Pragma
then
2719 Spec_Id
:= Defining_Entity
(Subp_Decl
);
2720 Set_Corresponding_Spec
(N
, Spec_Id
);
2722 -- Mark the generated spec as a source construct to ensure that all
2723 -- calls to it are properly registered in ALI files for GNATprove.
2725 Set_Comes_From_Source
(Spec_Id
, True);
2727 -- Ensure that the specs of the subprogram declaration and its body
2728 -- are identical, otherwise they will appear non-conformant due to
2729 -- rewritings in the default values of formal parameters.
2731 Body_Spec
:= Copy_Subprogram_Spec
(Body_Spec
);
2732 Set_Specification
(N
, Body_Spec
);
2733 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
2734 end Build_Subprogram_Declaration
;
2736 ----------------------------
2737 -- Check_Anonymous_Return --
2738 ----------------------------
2740 procedure Check_Anonymous_Return
is
2746 if Present
(Spec_Id
) then
2752 if Ekind
(Scop
) = E_Function
2753 and then Ekind
(Etype
(Scop
)) = E_Anonymous_Access_Type
2754 and then not Is_Thunk
(Scop
)
2756 -- Skip internally built functions which handle the case of
2757 -- a null access (see Expand_Interface_Conversion)
2759 and then not (Is_Interface
(Designated_Type
(Etype
(Scop
)))
2760 and then not Comes_From_Source
(Parent
(Scop
)))
2762 and then (Has_Task
(Designated_Type
(Etype
(Scop
)))
2764 (Is_Class_Wide_Type
(Designated_Type
(Etype
(Scop
)))
2766 Is_Limited_Record
(Designated_Type
(Etype
(Scop
)))))
2767 and then Expander_Active
2769 -- Avoid cases with no tasking support
2771 and then RTE_Available
(RE_Current_Master
)
2772 and then not Restriction_Active
(No_Task_Hierarchy
)
2775 Make_Object_Declaration
(Loc
,
2776 Defining_Identifier
=>
2777 Make_Defining_Identifier
(Loc
, Name_uMaster
),
2778 Constant_Present
=> True,
2779 Object_Definition
=>
2780 New_Occurrence_Of
(RTE
(RE_Master_Id
), Loc
),
2782 Make_Explicit_Dereference
(Loc
,
2783 New_Occurrence_Of
(RTE
(RE_Current_Master
), Loc
)));
2785 if Present
(Declarations
(N
)) then
2786 Prepend
(Decl
, Declarations
(N
));
2788 Set_Declarations
(N
, New_List
(Decl
));
2791 Set_Master_Id
(Etype
(Scop
), Defining_Identifier
(Decl
));
2792 Set_Has_Master_Entity
(Scop
);
2794 -- Now mark the containing scope as a task master
2797 while Nkind
(Par
) /= N_Compilation_Unit
loop
2798 Par
:= Parent
(Par
);
2799 pragma Assert
(Present
(Par
));
2801 -- If we fall off the top, we are at the outer level, and
2802 -- the environment task is our effective master, so nothing
2806 (Par
, N_Task_Body
, N_Block_Statement
, N_Subprogram_Body
)
2808 Set_Is_Task_Master
(Par
, True);
2813 end Check_Anonymous_Return
;
2815 -------------------------
2816 -- Check_Inline_Pragma --
2817 -------------------------
2819 procedure Check_Inline_Pragma
(Spec
: in out Node_Id
) is
2823 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean;
2824 -- True when N is a pragma Inline or Inline_Always that applies
2825 -- to this subprogram.
2827 -----------------------
2828 -- Is_Inline_Pragma --
2829 -----------------------
2831 function Is_Inline_Pragma
(N
: Node_Id
) return Boolean is
2833 if Nkind
(N
) = N_Pragma
2835 (Pragma_Name_Unmapped
(N
) = Name_Inline_Always
2836 or else (Pragma_Name_Unmapped
(N
) = Name_Inline
2838 (Front_End_Inlining
or else Optimization_Level
> 0)))
2839 and then Present
(Pragma_Argument_Associations
(N
))
2842 Pragma_Arg
: Node_Id
:=
2843 Expression
(First
(Pragma_Argument_Associations
(N
)));
2845 if Nkind
(Pragma_Arg
) = N_Selected_Component
then
2846 Pragma_Arg
:= Selector_Name
(Pragma_Arg
);
2849 return Chars
(Pragma_Arg
) = Chars
(Body_Id
);
2855 end Is_Inline_Pragma
;
2857 -- Start of processing for Check_Inline_Pragma
2860 if not Expander_Active
then
2864 if Is_List_Member
(N
)
2865 and then Present
(Next
(N
))
2866 and then Is_Inline_Pragma
(Next
(N
))
2870 elsif Nkind
(N
) /= N_Subprogram_Body_Stub
2871 and then Present
(Declarations
(N
))
2872 and then Is_Inline_Pragma
(First
(Declarations
(N
)))
2874 Prag
:= First
(Declarations
(N
));
2880 if Present
(Prag
) then
2881 if Present
(Spec_Id
) then
2882 if Is_List_Member
(N
)
2883 and then Is_List_Member
(Unit_Declaration_Node
(Spec_Id
))
2884 and then In_Same_List
(N
, Unit_Declaration_Node
(Spec_Id
))
2890 -- Create a subprogram declaration, to make treatment uniform.
2891 -- Make the sloc of the subprogram name that of the entity in
2892 -- the body, so that style checks find identical strings.
2895 Subp
: constant Entity_Id
:=
2896 Make_Defining_Identifier
2897 (Sloc
(Body_Id
), Chars
(Body_Id
));
2898 Decl
: constant Node_Id
:=
2899 Make_Subprogram_Declaration
(Loc
,
2901 New_Copy_Tree
(Specification
(N
)));
2904 -- Link the body and the generated spec
2906 Set_Corresponding_Body
(Decl
, Body_Id
);
2907 Set_Corresponding_Spec
(N
, Subp
);
2909 Set_Defining_Unit_Name
(Specification
(Decl
), Subp
);
2911 -- To ensure proper coverage when body is inlined, indicate
2912 -- whether the subprogram comes from source.
2914 Set_Comes_From_Source
(Subp
, Comes_From_Source
(N
));
2916 if Present
(First_Formal
(Body_Id
)) then
2917 Plist
:= Copy_Parameter_List
(Body_Id
);
2918 Set_Parameter_Specifications
2919 (Specification
(Decl
), Plist
);
2922 -- Move aspects to the new spec
2924 if Has_Aspects
(N
) then
2925 Move_Aspects
(N
, To
=> Decl
);
2928 Insert_Before
(N
, Decl
);
2931 Set_Has_Pragma_Inline
(Subp
);
2933 if Pragma_Name
(Prag
) = Name_Inline_Always
then
2934 Set_Is_Inlined
(Subp
);
2935 Set_Has_Pragma_Inline_Always
(Subp
);
2938 -- Prior to copying the subprogram body to create a template
2939 -- for it for subsequent inlining, remove the pragma from
2940 -- the current body so that the copy that will produce the
2941 -- new body will start from a completely unanalyzed tree.
2943 if Nkind
(Parent
(Prag
)) = N_Subprogram_Body
then
2944 Rewrite
(Prag
, Make_Null_Statement
(Sloc
(Prag
)));
2951 end Check_Inline_Pragma
;
2953 --------------------------
2954 -- Check_Missing_Return --
2955 --------------------------
2957 procedure Check_Missing_Return
is
2959 Missing_Ret
: Boolean;
2962 if Nkind
(Body_Spec
) = N_Function_Specification
then
2963 if Present
(Spec_Id
) then
2969 if Return_Present
(Id
) then
2970 Check_Returns
(HSS
, 'F', Missing_Ret
);
2973 Set_Has_Missing_Return
(Id
);
2976 -- Within a premature instantiation of a package with no body, we
2977 -- build completions of the functions therein, with a Raise
2978 -- statement. No point in complaining about a missing return in
2981 elsif Ekind
(Id
) = E_Function
2982 and then In_Instance
2983 and then Present
(Statements
(HSS
))
2984 and then Nkind
(First
(Statements
(HSS
))) = N_Raise_Program_Error
2988 elsif Is_Generic_Subprogram
(Id
)
2989 or else not Is_Machine_Code_Subprogram
(Id
)
2991 Error_Msg_N
("missing RETURN statement in function body", N
);
2994 -- If procedure with No_Return, check returns
2996 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
2997 and then Present
(Spec_Id
)
2998 and then No_Return
(Spec_Id
)
3000 Check_Returns
(HSS
, 'P', Missing_Ret
, Spec_Id
);
3003 -- Special checks in SPARK mode
3005 if Nkind
(Body_Spec
) = N_Function_Specification
then
3007 -- In SPARK mode, last statement of a function should be a return
3010 Stat
: constant Node_Id
:= Last_Source_Statement
(HSS
);
3013 and then not Nkind_In
(Stat
, N_Simple_Return_Statement
,
3014 N_Extended_Return_Statement
)
3016 Check_SPARK_05_Restriction
3017 ("last statement in function should be RETURN", Stat
);
3021 -- In SPARK mode, verify that a procedure has no return
3023 elsif Nkind
(Body_Spec
) = N_Procedure_Specification
then
3024 if Present
(Spec_Id
) then
3030 -- Would be nice to point to return statement here, can we
3031 -- borrow the Check_Returns procedure here ???
3033 if Return_Present
(Id
) then
3034 Check_SPARK_05_Restriction
3035 ("procedure should not have RETURN", N
);
3038 end Check_Missing_Return
;
3040 -----------------------
3041 -- Disambiguate_Spec --
3042 -----------------------
3044 function Disambiguate_Spec
return Entity_Id
is
3045 Priv_Spec
: Entity_Id
;
3048 procedure Replace_Types
(To_Corresponding
: Boolean);
3049 -- Depending on the flag, replace the type of formal parameters of
3050 -- Body_Id if it is a concurrent type implementing interfaces with
3051 -- the corresponding record type or the other way around.
3053 procedure Replace_Types
(To_Corresponding
: Boolean) is
3055 Formal_Typ
: Entity_Id
;
3058 Formal
:= First_Formal
(Body_Id
);
3059 while Present
(Formal
) loop
3060 Formal_Typ
:= Etype
(Formal
);
3062 if Is_Class_Wide_Type
(Formal_Typ
) then
3063 Formal_Typ
:= Root_Type
(Formal_Typ
);
3066 -- From concurrent type to corresponding record
3068 if To_Corresponding
then
3069 if Is_Concurrent_Type
(Formal_Typ
)
3070 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
3073 (Corresponding_Record_Type
(Formal_Typ
)))
3076 Corresponding_Record_Type
(Formal_Typ
));
3079 -- From corresponding record to concurrent type
3082 if Is_Concurrent_Record_Type
(Formal_Typ
)
3083 and then Present
(Interfaces
(Formal_Typ
))
3086 Corresponding_Concurrent_Type
(Formal_Typ
));
3090 Next_Formal
(Formal
);
3094 -- Start of processing for Disambiguate_Spec
3097 -- Try to retrieve the specification of the body as is. All error
3098 -- messages are suppressed because the body may not have a spec in
3099 -- its current state.
3101 Spec_N
:= Find_Corresponding_Spec
(N
, False);
3103 -- It is possible that this is the body of a primitive declared
3104 -- between a private and a full view of a concurrent type. The
3105 -- controlling parameter of the spec carries the concurrent type,
3106 -- not the corresponding record type as transformed by Analyze_
3107 -- Subprogram_Specification. In such cases, we undo the change
3108 -- made by the analysis of the specification and try to find the
3111 -- Note that wrappers already have their corresponding specs and
3112 -- bodies set during their creation, so if the candidate spec is
3113 -- a wrapper, then we definitely need to swap all types to their
3114 -- original concurrent status.
3117 or else Is_Primitive_Wrapper
(Spec_N
)
3119 -- Restore all references of corresponding record types to the
3120 -- original concurrent types.
3122 Replace_Types
(To_Corresponding
=> False);
3123 Priv_Spec
:= Find_Corresponding_Spec
(N
, False);
3125 -- The current body truly belongs to a primitive declared between
3126 -- a private and a full view. We leave the modified body as is,
3127 -- and return the true spec.
3129 if Present
(Priv_Spec
)
3130 and then Is_Private_Primitive
(Priv_Spec
)
3135 -- In case that this is some sort of error, restore the original
3136 -- state of the body.
3138 Replace_Types
(To_Corresponding
=> True);
3142 end Disambiguate_Spec
;
3144 ----------------------------
3145 -- Exchange_Limited_Views --
3146 ----------------------------
3148 function Exchange_Limited_Views
(Subp_Id
: Entity_Id
) return Elist_Id
is
3149 Result
: Elist_Id
:= No_Elist
;
3151 procedure Detect_And_Exchange
(Id
: Entity_Id
);
3152 -- Determine whether Id's type denotes an incomplete type associated
3153 -- with a limited with clause and exchange the limited view with the
3154 -- non-limited one when available. Note that the non-limited view
3155 -- may exist because of a with_clause in another unit in the context,
3156 -- but cannot be used because the current view of the enclosing unit
3157 -- is still a limited view.
3159 -------------------------
3160 -- Detect_And_Exchange --
3161 -------------------------
3163 procedure Detect_And_Exchange
(Id
: Entity_Id
) is
3164 Typ
: constant Entity_Id
:= Etype
(Id
);
3166 if From_Limited_With
(Typ
)
3167 and then Has_Non_Limited_View
(Typ
)
3168 and then not From_Limited_With
(Scope
(Typ
))
3171 Result
:= New_Elmt_List
;
3174 Prepend_Elmt
(Typ
, Result
);
3175 Prepend_Elmt
(Id
, Result
);
3176 Set_Etype
(Id
, Non_Limited_View
(Typ
));
3178 end Detect_And_Exchange
;
3184 -- Start of processing for Exchange_Limited_Views
3187 -- Do not process subprogram bodies as they already use the non-
3188 -- limited view of types.
3190 if not Ekind_In
(Subp_Id
, E_Function
, E_Procedure
) then
3194 -- Examine all formals and swap views when applicable
3196 Formal
:= First_Formal
(Subp_Id
);
3197 while Present
(Formal
) loop
3198 Detect_And_Exchange
(Formal
);
3200 Next_Formal
(Formal
);
3203 -- Process the return type of a function
3205 if Ekind
(Subp_Id
) = E_Function
then
3206 Detect_And_Exchange
(Subp_Id
);
3210 end Exchange_Limited_Views
;
3212 -------------------------------------
3213 -- Is_Private_Concurrent_Primitive --
3214 -------------------------------------
3216 function Is_Private_Concurrent_Primitive
3217 (Subp_Id
: Entity_Id
) return Boolean
3219 Formal_Typ
: Entity_Id
;
3222 if Present
(First_Formal
(Subp_Id
)) then
3223 Formal_Typ
:= Etype
(First_Formal
(Subp_Id
));
3225 if Is_Concurrent_Record_Type
(Formal_Typ
) then
3226 if Is_Class_Wide_Type
(Formal_Typ
) then
3227 Formal_Typ
:= Root_Type
(Formal_Typ
);
3230 Formal_Typ
:= Corresponding_Concurrent_Type
(Formal_Typ
);
3233 -- The type of the first formal is a concurrent tagged type with
3237 Is_Concurrent_Type
(Formal_Typ
)
3238 and then Is_Tagged_Type
(Formal_Typ
)
3239 and then Has_Private_Declaration
(Formal_Typ
);
3243 end Is_Private_Concurrent_Primitive
;
3245 -------------------------
3246 -- Mask_Unfrozen_Types --
3247 -------------------------
3249 function Mask_Unfrozen_Types
(Spec_Id
: Entity_Id
) return Elist_Id
is
3250 Result
: Elist_Id
:= No_Elist
;
3252 function Mask_Type_Refs
(Node
: Node_Id
) return Traverse_Result
;
3253 -- Mask all types referenced in the subtree rooted at Node
3255 --------------------
3256 -- Mask_Type_Refs --
3257 --------------------
3259 function Mask_Type_Refs
(Node
: Node_Id
) return Traverse_Result
is
3260 procedure Mask_Type
(Typ
: Entity_Id
);
3261 -- ??? what does this do?
3267 procedure Mask_Type
(Typ
: Entity_Id
) is
3269 -- Skip Itypes created by the preanalysis
3272 and then Scope_Within_Or_Same
(Scope
(Typ
), Spec_Id
)
3277 if not Is_Frozen
(Typ
) then
3278 Set_Is_Frozen
(Typ
);
3279 Append_New_Elmt
(Typ
, Result
);
3283 -- Start of processing for Mask_Type_Refs
3286 if Is_Entity_Name
(Node
) and then Present
(Entity
(Node
)) then
3287 Mask_Type
(Etype
(Entity
(Node
)));
3289 if Ekind_In
(Entity
(Node
), E_Component
, E_Discriminant
) then
3290 Mask_Type
(Scope
(Entity
(Node
)));
3293 elsif Nkind_In
(Node
, N_Aggregate
, N_Null
, N_Type_Conversion
)
3294 and then Present
(Etype
(Node
))
3296 Mask_Type
(Etype
(Node
));
3302 procedure Mask_References
is new Traverse_Proc
(Mask_Type_Refs
);
3306 Return_Stmt
: constant Node_Id
:=
3307 First
(Statements
(Handled_Statement_Sequence
(N
)));
3309 -- Start of processing for Mask_Unfrozen_Types
3312 pragma Assert
(Nkind
(Return_Stmt
) = N_Simple_Return_Statement
);
3314 Mask_References
(Expression
(Return_Stmt
));
3317 end Mask_Unfrozen_Types
;
3319 ---------------------------
3320 -- Restore_Limited_Views --
3321 ---------------------------
3323 procedure Restore_Limited_Views
(Restore_List
: Elist_Id
) is
3324 Elmt
: Elmt_Id
:= First_Elmt
(Restore_List
);
3328 while Present
(Elmt
) loop
3331 Set_Etype
(Id
, Node
(Elmt
));
3334 end Restore_Limited_Views
;
3336 ----------------------------
3337 -- Set_Trivial_Subprogram --
3338 ----------------------------
3340 procedure Set_Trivial_Subprogram
(N
: Node_Id
) is
3341 Nxt
: constant Node_Id
:= Next
(N
);
3344 Set_Is_Trivial_Subprogram
(Body_Id
);
3346 if Present
(Spec_Id
) then
3347 Set_Is_Trivial_Subprogram
(Spec_Id
);
3351 and then Nkind
(Nxt
) = N_Simple_Return_Statement
3352 and then No
(Next
(Nxt
))
3353 and then Present
(Expression
(Nxt
))
3354 and then Is_Entity_Name
(Expression
(Nxt
))
3356 Set_Never_Set_In_Source
(Entity
(Expression
(Nxt
)), False);
3358 end Set_Trivial_Subprogram
;
3360 ---------------------------
3361 -- Unmask_Unfrozen_Types --
3362 ---------------------------
3364 procedure Unmask_Unfrozen_Types
(Unmask_List
: Elist_Id
) is
3365 Elmt
: Elmt_Id
:= First_Elmt
(Unmask_List
);
3368 while Present
(Elmt
) loop
3369 Set_Is_Frozen
(Node
(Elmt
), False);
3372 end Unmask_Unfrozen_Types
;
3374 ---------------------------------
3375 -- Verify_Overriding_Indicator --
3376 ---------------------------------
3378 procedure Verify_Overriding_Indicator
is
3380 if Must_Override
(Body_Spec
) then
3381 if Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3382 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3386 elsif not Present
(Overridden_Operation
(Spec_Id
)) then
3388 ("subprogram& is not overriding", Body_Spec
, Spec_Id
);
3390 -- Overriding indicators aren't allowed for protected subprogram
3391 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3392 -- this to a warning if -gnatd.E is enabled.
3394 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3395 Error_Msg_Warn
:= Error_To_Warning
;
3397 ("<<overriding indicator not allowed for protected "
3398 & "subprogram body", Body_Spec
);
3401 elsif Must_Not_Override
(Body_Spec
) then
3402 if Present
(Overridden_Operation
(Spec_Id
)) then
3404 ("subprogram& overrides inherited operation",
3405 Body_Spec
, Spec_Id
);
3407 elsif Nkind
(Spec_Id
) = N_Defining_Operator_Symbol
3408 and then Operator_Matches_Spec
(Spec_Id
, Spec_Id
)
3411 ("subprogram& overrides predefined operator ",
3412 Body_Spec
, Spec_Id
);
3414 -- Overriding indicators aren't allowed for protected subprogram
3415 -- bodies (see the Confirmation in Ada Comment AC95-00213). Change
3416 -- this to a warning if -gnatd.E is enabled.
3418 elsif Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
3419 Error_Msg_Warn
:= Error_To_Warning
;
3422 ("<<overriding indicator not allowed "
3423 & "for protected subprogram body", Body_Spec
);
3425 -- If this is not a primitive operation, then the overriding
3426 -- indicator is altogether illegal.
3428 elsif not Is_Primitive
(Spec_Id
) then
3430 ("overriding indicator only allowed "
3431 & "if subprogram is primitive", Body_Spec
);
3434 -- If checking the style rule and the operation overrides, then
3435 -- issue a warning about a missing overriding_indicator. Protected
3436 -- subprogram bodies are excluded from this style checking, since
3437 -- they aren't primitives (even though their declarations can
3438 -- override) and aren't allowed to have an overriding_indicator.
3441 and then Present
(Overridden_Operation
(Spec_Id
))
3442 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3444 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3445 Style
.Missing_Overriding
(N
, Body_Id
);
3448 and then Can_Override_Operator
(Spec_Id
)
3449 and then not In_Predefined_Unit
(Spec_Id
)
3451 pragma Assert
(Unit_Declaration_Node
(Body_Id
) = N
);
3452 Style
.Missing_Overriding
(N
, Body_Id
);
3454 end Verify_Overriding_Indicator
;
3458 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
3459 Saved_ISMP
: constant Boolean :=
3460 Ignore_SPARK_Mode_Pragmas_In_Instance
;
3461 -- Save the Ghost and SPARK mode-related data to restore on exit
3463 -- Start of processing for Analyze_Subprogram_Body_Helper
3466 -- A [generic] subprogram body freezes the contract of the nearest
3467 -- enclosing package body and all other contracts encountered in the
3468 -- same declarative part up to and excluding the subprogram body:
3470 -- package body Nearest_Enclosing_Package
3471 -- with Refined_State => (State => Constit)
3475 -- procedure Freezes_Enclosing_Package_Body
3476 -- with Refined_Depends => (Input => Constit) ...
3478 -- This ensures that any annotations referenced by the contract of the
3479 -- [generic] subprogram body are available. This form of freezing is
3480 -- decoupled from the usual Freeze_xxx mechanism because it must also
3481 -- work in the context of generics where normal freezing is disabled.
3483 -- Only bodies coming from source should cause this type of freezing.
3484 -- Expression functions that act as bodies and complete an initial
3485 -- declaration must be included in this category, hence the use of
3488 if Comes_From_Source
(Original_Node
(N
)) then
3489 Freeze_Previous_Contracts
(N
);
3492 -- Generic subprograms are handled separately. They always have a
3493 -- generic specification. Determine whether current scope has a
3494 -- previous declaration.
3496 -- If the subprogram body is defined within an instance of the same
3497 -- name, the instance appears as a package renaming, and will be hidden
3498 -- within the subprogram.
3500 if Present
(Prev_Id
)
3501 and then not Is_Overloadable
(Prev_Id
)
3502 and then (Nkind
(Parent
(Prev_Id
)) /= N_Package_Renaming_Declaration
3503 or else Comes_From_Source
(Prev_Id
))
3505 if Is_Generic_Subprogram
(Prev_Id
) then
3508 -- A subprogram body is Ghost when it is stand alone and subject
3509 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3510 -- the mode now to ensure that any nodes generated during analysis
3511 -- and expansion are properly marked as Ghost.
3513 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3515 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3516 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3518 Analyze_Generic_Subprogram_Body
(N
, Spec_Id
);
3520 if Nkind
(N
) = N_Subprogram_Body
then
3521 HSS
:= Handled_Statement_Sequence
(N
);
3522 Check_Missing_Return
;
3527 -- Otherwise a previous entity conflicts with the subprogram name.
3528 -- Attempting to enter name will post error.
3531 Enter_Name
(Body_Id
);
3535 -- Non-generic case, find the subprogram declaration, if one was seen,
3536 -- or enter new overloaded entity in the current scope. If the
3537 -- Current_Entity is the Body_Id itself, the unit is being analyzed as
3538 -- part of the context of one of its subunits. No need to redo the
3541 elsif Prev_Id
= Body_Id
and then Has_Completion
(Body_Id
) then
3545 Body_Id
:= Analyze_Subprogram_Specification
(Body_Spec
);
3547 if Nkind
(N
) = N_Subprogram_Body_Stub
3548 or else No
(Corresponding_Spec
(N
))
3550 if Is_Private_Concurrent_Primitive
(Body_Id
) then
3551 Spec_Id
:= Disambiguate_Spec
;
3553 -- A subprogram body is Ghost when it is stand alone and
3554 -- subject to pragma Ghost or when the corresponding spec is
3555 -- Ghost. Set the mode now to ensure that any nodes generated
3556 -- during analysis and expansion are properly marked as Ghost.
3558 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3561 Spec_Id
:= Find_Corresponding_Spec
(N
);
3563 -- A subprogram body is Ghost when it is stand alone and
3564 -- subject to pragma Ghost or when the corresponding spec is
3565 -- Ghost. Set the mode now to ensure that any nodes generated
3566 -- during analysis and expansion are properly marked as Ghost.
3568 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3570 -- In GNATprove mode, if the body has no previous spec, create
3571 -- one so that the inlining machinery can operate properly.
3572 -- Transfer aspects, if any, to the new spec, so that they
3573 -- are legal and can be processed ahead of the body.
3574 -- We make two copies of the given spec, one for the new
3575 -- declaration, and one for the body.
3577 if No
(Spec_Id
) and then GNATprove_Mode
3579 -- Inlining does not apply during pre-analysis of code
3581 and then Full_Analysis
3583 -- Inlining only applies to full bodies, not stubs
3585 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3587 -- Inlining only applies to bodies in the source code, not to
3588 -- those generated by the compiler. In particular, expression
3589 -- functions, whose body is generated by the compiler, are
3590 -- treated specially by GNATprove.
3592 and then Comes_From_Source
(Body_Id
)
3594 -- This cannot be done for a compilation unit, which is not
3595 -- in a context where we can insert a new spec.
3597 and then Is_List_Member
(N
)
3599 -- Inlining only applies to subprograms without contracts,
3600 -- as a contract is a sign that GNATprove should perform a
3601 -- modular analysis of the subprogram instead of a contextual
3602 -- analysis at each call site. The same test is performed in
3603 -- Inline.Can_Be_Inlined_In_GNATprove_Mode. It is repeated
3604 -- here in another form (because the contract has not been
3605 -- attached to the body) to avoid front-end errors in case
3606 -- pragmas are used instead of aspects, because the
3607 -- corresponding pragmas in the body would not be transferred
3608 -- to the spec, leading to legality errors.
3610 and then not Body_Has_Contract
3611 and then not Inside_A_Generic
3613 Build_Subprogram_Declaration
;
3615 -- If this is a function that returns a constrained array, and
3616 -- we are generating SPARK_For_C, create subprogram declaration
3617 -- to simplify subsequent C generation.
3620 and then Modify_Tree_For_C
3621 and then Nkind
(Body_Spec
) = N_Function_Specification
3622 and then Is_Array_Type
(Etype
(Body_Id
))
3623 and then Is_Constrained
(Etype
(Body_Id
))
3625 Build_Subprogram_Declaration
;
3629 -- If this is a duplicate body, no point in analyzing it
3631 if Error_Posted
(N
) then
3635 -- A subprogram body should cause freezing of its own declaration,
3636 -- but if there was no previous explicit declaration, then the
3637 -- subprogram will get frozen too late (there may be code within
3638 -- the body that depends on the subprogram having been frozen,
3639 -- such as uses of extra formals), so we force it to be frozen
3640 -- here. Same holds if the body and spec are compilation units.
3641 -- Finally, if the return type is an anonymous access to protected
3642 -- subprogram, it must be frozen before the body because its
3643 -- expansion has generated an equivalent type that is used when
3644 -- elaborating the body.
3646 -- An exception in the case of Ada 2012, AI05-177: The bodies
3647 -- created for expression functions do not freeze.
3650 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3652 Freeze_Before
(N
, Body_Id
);
3654 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3655 Freeze_Before
(N
, Spec_Id
);
3657 elsif Is_Access_Subprogram_Type
(Etype
(Body_Id
)) then
3658 Freeze_Before
(N
, Etype
(Body_Id
));
3662 Spec_Id
:= Corresponding_Spec
(N
);
3664 -- A subprogram body is Ghost when it is stand alone and subject
3665 -- to pragma Ghost or when the corresponding spec is Ghost. Set
3666 -- the mode now to ensure that any nodes generated during analysis
3667 -- and expansion are properly marked as Ghost.
3669 Mark_And_Set_Ghost_Body
(N
, Spec_Id
);
3673 -- Previously we scanned the body to look for nested subprograms, and
3674 -- rejected an inline directive if nested subprograms were present,
3675 -- because the back-end would generate conflicting symbols for the
3676 -- nested bodies. This is now unnecessary.
3678 -- Look ahead to recognize a pragma Inline that appears after the body
3680 Check_Inline_Pragma
(Spec_Id
);
3682 -- Deal with special case of a fully private operation in the body of
3683 -- the protected type. We must create a declaration for the subprogram,
3684 -- in order to attach the protected subprogram that will be used in
3685 -- internal calls. We exclude compiler generated bodies from the
3686 -- expander since the issue does not arise for those cases.
3689 and then Comes_From_Source
(N
)
3690 and then Is_Protected_Type
(Current_Scope
)
3692 Spec_Id
:= Build_Private_Protected_Declaration
(N
);
3695 -- If we are generating C and this is a function returning a constrained
3696 -- array type for which we must create a procedure with an extra out
3697 -- parameter, build and analyze the body now. The procedure declaration
3698 -- has already been created. We reuse the source body of the function,
3699 -- because in an instance it may contain global references that cannot
3700 -- be reanalyzed. The source function itself is not used any further,
3701 -- so we mark it as having a completion. If the subprogram is a stub the
3702 -- transformation is done later, when the proper body is analyzed.
3705 and then Modify_Tree_For_C
3706 and then Present
(Spec_Id
)
3707 and then Ekind
(Spec_Id
) = E_Function
3708 and then Nkind
(N
) /= N_Subprogram_Body_Stub
3709 and then Rewritten_For_C
(Spec_Id
)
3711 Set_Has_Completion
(Spec_Id
);
3713 Rewrite
(N
, Build_Procedure_Body_Form
(Spec_Id
, N
));
3716 -- The entity for the created procedure must remain invisible, so it
3717 -- does not participate in resolution of subsequent references to the
3720 Set_Is_Immediately_Visible
(Corresponding_Spec
(N
), False);
3724 -- If a separate spec is present, then deal with freezing issues
3726 if Present
(Spec_Id
) then
3727 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3728 Verify_Overriding_Indicator
;
3730 -- In general, the spec will be frozen when we start analyzing the
3731 -- body. However, for internally generated operations, such as
3732 -- wrapper functions for inherited operations with controlling
3733 -- results, the spec may not have been frozen by the time we expand
3734 -- the freeze actions that include the bodies. In particular, extra
3735 -- formals for accessibility or for return-in-place may need to be
3736 -- generated. Freeze nodes, if any, are inserted before the current
3737 -- body. These freeze actions are also needed in ASIS mode and in
3738 -- Compile_Only mode to enable the proper back-end type annotations.
3739 -- They are necessary in any case to insure order of elaboration
3742 if not Is_Frozen
(Spec_Id
)
3743 and then (Expander_Active
3745 or else (Operating_Mode
= Check_Semantics
3746 and then Serious_Errors_Detected
= 0))
3748 -- The body generated for an expression function that is not a
3749 -- completion is a freeze point neither for the profile nor for
3750 -- anything else. That's why, in order to prevent any freezing
3751 -- during analysis, we need to mask types declared outside the
3752 -- expression that are not yet frozen.
3754 if Nkind
(N
) = N_Subprogram_Body
3755 and then Was_Expression_Function
(N
)
3756 and then not Has_Completion
(Spec_Id
)
3758 Set_Is_Frozen
(Spec_Id
);
3759 Mask_Types
:= Mask_Unfrozen_Types
(Spec_Id
);
3761 Set_Has_Delayed_Freeze
(Spec_Id
);
3762 Freeze_Before
(N
, Spec_Id
);
3767 -- If the subprogram has a class-wide clone, build its body as a copy
3768 -- of the original body, and rewrite body of original subprogram as a
3769 -- wrapper that calls the clone.
3771 if Present
(Spec_Id
)
3772 and then Present
(Class_Wide_Clone
(Spec_Id
))
3773 and then (Comes_From_Source
(N
) or else Was_Expression_Function
(N
))
3775 Build_Class_Wide_Clone_Body
(Spec_Id
, N
);
3777 -- This is the new body for the existing primitive operation
3779 Rewrite
(N
, Build_Class_Wide_Clone_Call
3780 (Sloc
(N
), New_List
, Spec_Id
, Parent
(Spec_Id
)));
3781 Set_Has_Completion
(Spec_Id
, False);
3786 -- Place subprogram on scope stack, and make formals visible. If there
3787 -- is a spec, the visible entity remains that of the spec.
3789 if Present
(Spec_Id
) then
3790 Generate_Reference
(Spec_Id
, Body_Id
, 'b', Set_Ref
=> False);
3792 if Is_Child_Unit
(Spec_Id
) then
3793 Generate_Reference
(Spec_Id
, Scope
(Spec_Id
), 'k', False);
3797 Style
.Check_Identifier
(Body_Id
, Spec_Id
);
3800 Set_Is_Compilation_Unit
(Body_Id
, Is_Compilation_Unit
(Spec_Id
));
3801 Set_Is_Child_Unit
(Body_Id
, Is_Child_Unit
(Spec_Id
));
3803 if Is_Abstract_Subprogram
(Spec_Id
) then
3804 Error_Msg_N
("an abstract subprogram cannot have a body", N
);
3808 Set_Convention
(Body_Id
, Convention
(Spec_Id
));
3809 Set_Has_Completion
(Spec_Id
);
3811 if Is_Protected_Type
(Scope
(Spec_Id
)) then
3812 Prot_Typ
:= Scope
(Spec_Id
);
3815 -- If this is a body generated for a renaming, do not check for
3816 -- full conformance. The check is redundant, because the spec of
3817 -- the body is a copy of the spec in the renaming declaration,
3818 -- and the test can lead to spurious errors on nested defaults.
3820 if Present
(Spec_Decl
)
3821 and then not Comes_From_Source
(N
)
3823 (Nkind
(Original_Node
(Spec_Decl
)) =
3824 N_Subprogram_Renaming_Declaration
3825 or else (Present
(Corresponding_Body
(Spec_Decl
))
3827 Nkind
(Unit_Declaration_Node
3828 (Corresponding_Body
(Spec_Decl
))) =
3829 N_Subprogram_Renaming_Declaration
))
3833 -- Conversely, the spec may have been generated for specless body
3834 -- with an inline pragma. The entity comes from source, which is
3835 -- both semantically correct and necessary for proper inlining.
3836 -- The subprogram declaration itself is not in the source.
3838 elsif Comes_From_Source
(N
)
3839 and then Present
(Spec_Decl
)
3840 and then not Comes_From_Source
(Spec_Decl
)
3841 and then Has_Pragma_Inline
(Spec_Id
)
3848 Fully_Conformant
, True, Conformant
, Body_Id
);
3851 -- If the body is not fully conformant, we have to decide if we
3852 -- should analyze it or not. If it has a really messed up profile
3853 -- then we probably should not analyze it, since we will get too
3854 -- many bogus messages.
3856 -- Our decision is to go ahead in the non-fully conformant case
3857 -- only if it is at least mode conformant with the spec. Note
3858 -- that the call to Check_Fully_Conformant has issued the proper
3859 -- error messages to complain about the lack of conformance.
3862 and then not Mode_Conformant
(Body_Id
, Spec_Id
)
3868 if Spec_Id
/= Body_Id
then
3869 Reference_Body_Formals
(Spec_Id
, Body_Id
);
3872 Set_Ekind
(Body_Id
, E_Subprogram_Body
);
3874 if Nkind
(N
) = N_Subprogram_Body_Stub
then
3875 Set_Corresponding_Spec_Of_Stub
(N
, Spec_Id
);
3880 Set_Corresponding_Spec
(N
, Spec_Id
);
3882 -- Ada 2005 (AI-345): If the operation is a primitive operation
3883 -- of a concurrent type, the type of the first parameter has been
3884 -- replaced with the corresponding record, which is the proper
3885 -- run-time structure to use. However, within the body there may
3886 -- be uses of the formals that depend on primitive operations
3887 -- of the type (in particular calls in prefixed form) for which
3888 -- we need the original concurrent type. The operation may have
3889 -- several controlling formals, so the replacement must be done
3892 if Comes_From_Source
(Spec_Id
)
3893 and then Present
(First_Entity
(Spec_Id
))
3894 and then Ekind
(Etype
(First_Entity
(Spec_Id
))) = E_Record_Type
3895 and then Is_Tagged_Type
(Etype
(First_Entity
(Spec_Id
)))
3896 and then Present
(Interfaces
(Etype
(First_Entity
(Spec_Id
))))
3897 and then Present
(Corresponding_Concurrent_Type
3898 (Etype
(First_Entity
(Spec_Id
))))
3901 Typ
: constant Entity_Id
:= Etype
(First_Entity
(Spec_Id
));
3905 Form
:= First_Formal
(Spec_Id
);
3906 while Present
(Form
) loop
3907 if Etype
(Form
) = Typ
then
3908 Set_Etype
(Form
, Corresponding_Concurrent_Type
(Typ
));
3916 -- Make the formals visible, and place subprogram on scope stack.
3917 -- This is also the point at which we set Last_Real_Spec_Entity
3918 -- to mark the entities which will not be moved to the body.
3920 Install_Formals
(Spec_Id
);
3921 Last_Real_Spec_Entity
:= Last_Entity
(Spec_Id
);
3923 -- Within an instance, add local renaming declarations so that
3924 -- gdb can retrieve the values of actuals more easily. This is
3925 -- only relevant if generating code (and indeed we definitely
3926 -- do not want these definitions -gnatc mode, because that would
3929 if Is_Generic_Instance
(Spec_Id
)
3930 and then Is_Wrapper_Package
(Current_Scope
)
3931 and then Expander_Active
3933 Build_Subprogram_Instance_Renamings
(N
, Current_Scope
);
3936 Push_Scope
(Spec_Id
);
3938 -- Make sure that the subprogram is immediately visible. For
3939 -- child units that have no separate spec this is indispensable.
3940 -- Otherwise it is safe albeit redundant.
3942 Set_Is_Immediately_Visible
(Spec_Id
);
3945 Set_Corresponding_Body
(Unit_Declaration_Node
(Spec_Id
), Body_Id
);
3946 Set_Is_Obsolescent
(Body_Id
, Is_Obsolescent
(Spec_Id
));
3947 Set_Scope
(Body_Id
, Scope
(Spec_Id
));
3949 -- Case of subprogram body with no previous spec
3952 -- Check for style warning required
3956 -- Only apply check for source level subprograms for which checks
3957 -- have not been suppressed.
3959 and then Comes_From_Source
(Body_Id
)
3960 and then not Suppress_Style_Checks
(Body_Id
)
3962 -- No warnings within an instance
3964 and then not In_Instance
3966 -- No warnings for expression functions
3968 and then Nkind
(Original_Node
(N
)) /= N_Expression_Function
3970 Style
.Body_With_No_Spec
(N
);
3973 New_Overloaded_Entity
(Body_Id
);
3975 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
3976 Set_Acts_As_Spec
(N
);
3977 Generate_Definition
(Body_Id
);
3979 (Body_Id
, Body_Id
, 'b', Set_Ref
=> False, Force
=> True);
3981 -- If the body is an entry wrapper created for an entry with
3982 -- preconditions, it must be compiled in the context of the
3983 -- enclosing synchronized object, because it may mention other
3984 -- operations of the type.
3986 if Is_Entry_Wrapper
(Body_Id
) then
3988 Prot
: constant Entity_Id
:= Etype
(First_Entity
(Body_Id
));
3991 Install_Declarations
(Prot
);
3995 Install_Formals
(Body_Id
);
3997 Push_Scope
(Body_Id
);
4000 -- For stubs and bodies with no previous spec, generate references to
4003 Generate_Reference_To_Formals
(Body_Id
);
4006 -- Entry barrier functions are generated outside the protected type and
4007 -- should not carry the SPARK_Mode of the enclosing context.
4009 if Nkind
(N
) = N_Subprogram_Body
4010 and then Is_Entry_Barrier_Function
(N
)
4014 -- The body is generated as part of expression function expansion. When
4015 -- the expression function appears in the visible declarations of a
4016 -- package, the body is added to the private declarations. Since both
4017 -- declarative lists may be subject to a different SPARK_Mode, inherit
4018 -- the mode of the spec.
4020 -- package P with SPARK_Mode is
4021 -- function Expr_Func ... is (...); -- original
4022 -- [function Expr_Func ...;] -- generated spec
4025 -- pragma SPARK_Mode (Off);
4026 -- [function Expr_Func ... is return ...;] -- generated body
4027 -- end P; -- mode is ON
4029 elsif not Comes_From_Source
(N
)
4030 and then Present
(Spec_Id
)
4031 and then Is_Expression_Function
(Spec_Id
)
4033 Set_SPARK_Pragma
(Body_Id
, SPARK_Pragma
(Spec_Id
));
4034 Set_SPARK_Pragma_Inherited
4035 (Body_Id
, SPARK_Pragma_Inherited
(Spec_Id
));
4037 -- Set the SPARK_Mode from the current context (may be overwritten later
4038 -- with explicit pragma). Exclude the case where the SPARK_Mode appears
4039 -- initially on a stand-alone subprogram body, but is then relocated to
4040 -- a generated corresponding spec. In this scenario the mode is shared
4041 -- between the spec and body.
4043 elsif No
(SPARK_Pragma
(Body_Id
)) then
4044 Set_SPARK_Pragma
(Body_Id
, SPARK_Mode_Pragma
);
4045 Set_SPARK_Pragma_Inherited
(Body_Id
);
4048 -- A subprogram body may be instantiated or inlined at a later pass.
4049 -- Restore the state of Ignore_SPARK_Mode_Pragmas_In_Instance when it
4050 -- applied to the initial declaration of the body.
4052 if Present
(Spec_Id
) then
4053 if Ignore_SPARK_Mode_Pragmas
(Spec_Id
) then
4054 Ignore_SPARK_Mode_Pragmas_In_Instance
:= True;
4058 -- Save the state of flag Ignore_SPARK_Mode_Pragmas_In_Instance in
4059 -- case the body is instantiated or inlined later and out of context.
4060 -- The body uses this attribute to restore the value of the global
4063 if Ignore_SPARK_Mode_Pragmas_In_Instance
then
4064 Set_Ignore_SPARK_Mode_Pragmas
(Body_Id
);
4066 elsif Ignore_SPARK_Mode_Pragmas
(Body_Id
) then
4067 Ignore_SPARK_Mode_Pragmas_In_Instance
:= True;
4071 -- If this is the proper body of a stub, we must verify that the stub
4072 -- conforms to the body, and to the previous spec if one was present.
4073 -- We know already that the body conforms to that spec. This test is
4074 -- only required for subprograms that come from source.
4076 if Nkind
(Parent
(N
)) = N_Subunit
4077 and then Comes_From_Source
(N
)
4078 and then not Error_Posted
(Body_Id
)
4079 and then Nkind
(Corresponding_Stub
(Parent
(N
))) =
4080 N_Subprogram_Body_Stub
4083 Old_Id
: constant Entity_Id
:=
4085 (Specification
(Corresponding_Stub
(Parent
(N
))));
4087 Conformant
: Boolean := False;
4090 if No
(Spec_Id
) then
4091 Check_Fully_Conformant
(Body_Id
, Old_Id
);
4095 (Body_Id
, Old_Id
, Fully_Conformant
, False, Conformant
);
4097 if not Conformant
then
4099 -- The stub was taken to be a new declaration. Indicate that
4102 Set_Has_Completion
(Old_Id
, False);
4108 Set_Has_Completion
(Body_Id
);
4109 Check_Eliminated
(Body_Id
);
4111 -- Analyze any aspect specifications that appear on the subprogram body
4112 -- stub. Stop the analysis now as the stub does not have a declarative
4113 -- or a statement part, and it cannot be inlined.
4115 if Nkind
(N
) = N_Subprogram_Body_Stub
then
4116 if Has_Aspects
(N
) then
4117 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
4125 -- Note: Normally we don't do any inlining if expansion is off, since
4126 -- we won't generate code in any case. An exception arises in GNATprove
4127 -- mode where we want to expand some calls in place, even with expansion
4128 -- disabled, since the inlining eases formal verification.
4130 if not GNATprove_Mode
4131 and then Expander_Active
4132 and then Serious_Errors_Detected
= 0
4133 and then Present
(Spec_Id
)
4134 and then Has_Pragma_Inline
(Spec_Id
)
4136 -- Legacy implementation (relying on front-end inlining)
4138 if not Back_End_Inlining
then
4139 if (Has_Pragma_Inline_Always
(Spec_Id
)
4140 and then not Opt
.Disable_FE_Inline_Always
)
4141 or else (Front_End_Inlining
4142 and then not Opt
.Disable_FE_Inline
)
4144 Build_Body_To_Inline
(N
, Spec_Id
);
4147 -- New implementation (relying on back-end inlining)
4150 if Has_Pragma_Inline_Always
(Spec_Id
)
4151 or else Optimization_Level
> 0
4153 -- Handle function returning an unconstrained type
4155 if Comes_From_Source
(Body_Id
)
4156 and then Ekind
(Spec_Id
) = E_Function
4157 and then Returns_Unconstrained_Type
(Spec_Id
)
4159 -- If function builds in place, i.e. returns a limited type,
4160 -- inlining cannot be done.
4162 and then not Is_Limited_Type
(Etype
(Spec_Id
))
4164 Check_And_Split_Unconstrained_Function
(N
, Spec_Id
, Body_Id
);
4168 Subp_Body
: constant Node_Id
:=
4169 Unit_Declaration_Node
(Body_Id
);
4170 Subp_Decl
: constant List_Id
:= Declarations
(Subp_Body
);
4173 -- Do not pass inlining to the backend if the subprogram
4174 -- has declarations or statements which cannot be inlined
4175 -- by the backend. This check is done here to emit an
4176 -- error instead of the generic warning message reported
4177 -- by the GCC backend (ie. "function might not be
4180 if Present
(Subp_Decl
)
4181 and then Has_Excluded_Declaration
(Spec_Id
, Subp_Decl
)
4185 elsif Has_Excluded_Statement
4188 (Handled_Statement_Sequence
(Subp_Body
)))
4192 -- If the backend inlining is available then at this
4193 -- stage we only have to mark the subprogram as inlined.
4194 -- The expander will take care of registering it in the
4195 -- table of subprograms inlined by the backend a part of
4196 -- processing calls to it (cf. Expand_Call)
4199 Set_Is_Inlined
(Spec_Id
);
4206 -- In GNATprove mode, inline only when there is a separate subprogram
4207 -- declaration for now, as inlining of subprogram bodies acting as
4208 -- declarations, or subprogram stubs, are not supported by front-end
4209 -- inlining. This inlining should occur after analysis of the body, so
4210 -- that it is known whether the value of SPARK_Mode, which can be
4211 -- defined by a pragma inside the body, is applicable to the body.
4212 -- Inlining can be disabled with switch -gnatdm
4214 elsif GNATprove_Mode
4215 and then Full_Analysis
4216 and then not Inside_A_Generic
4217 and then Present
(Spec_Id
)
4219 Nkind
(Unit_Declaration_Node
(Spec_Id
)) = N_Subprogram_Declaration
4220 and then Body_Has_SPARK_Mode_On
4221 and then Can_Be_Inlined_In_GNATprove_Mode
(Spec_Id
, Body_Id
)
4222 and then not Body_Has_Contract
4223 and then not Debug_Flag_M
4225 Build_Body_To_Inline
(N
, Spec_Id
);
4228 -- When generating code, inherited pre/postconditions are handled when
4229 -- expanding the corresponding contract.
4231 -- Ada 2005 (AI-262): In library subprogram bodies, after the analysis
4232 -- of the specification we have to install the private withed units.
4233 -- This holds for child units as well.
4235 if Is_Compilation_Unit
(Body_Id
)
4236 or else Nkind
(Parent
(N
)) = N_Compilation_Unit
4238 Install_Private_With_Clauses
(Body_Id
);
4241 Check_Anonymous_Return
;
4243 -- Set the Protected_Formal field of each extra formal of the protected
4244 -- subprogram to reference the corresponding extra formal of the
4245 -- subprogram that implements it. For regular formals this occurs when
4246 -- the protected subprogram's declaration is expanded, but the extra
4247 -- formals don't get created until the subprogram is frozen. We need to
4248 -- do this before analyzing the protected subprogram's body so that any
4249 -- references to the original subprogram's extra formals will be changed
4250 -- refer to the implementing subprogram's formals (see Expand_Formal).
4252 if Present
(Spec_Id
)
4253 and then Is_Protected_Type
(Scope
(Spec_Id
))
4254 and then Present
(Protected_Body_Subprogram
(Spec_Id
))
4257 Impl_Subp
: constant Entity_Id
:=
4258 Protected_Body_Subprogram
(Spec_Id
);
4259 Prot_Ext_Formal
: Entity_Id
:= Extra_Formals
(Spec_Id
);
4260 Impl_Ext_Formal
: Entity_Id
:= Extra_Formals
(Impl_Subp
);
4263 while Present
(Prot_Ext_Formal
) loop
4264 pragma Assert
(Present
(Impl_Ext_Formal
));
4265 Set_Protected_Formal
(Prot_Ext_Formal
, Impl_Ext_Formal
);
4266 Next_Formal_With_Extras
(Prot_Ext_Formal
);
4267 Next_Formal_With_Extras
(Impl_Ext_Formal
);
4272 -- Now we can go on to analyze the body
4274 HSS
:= Handled_Statement_Sequence
(N
);
4275 Set_Actual_Subtypes
(N
, Current_Scope
);
4277 -- Add a declaration for the Protection object, renaming declarations
4278 -- for discriminals and privals and finally a declaration for the entry
4279 -- family index (if applicable). This form of early expansion is done
4280 -- when the Expander is active because Install_Private_Data_Declarations
4281 -- references entities which were created during regular expansion. The
4282 -- subprogram entity must come from source, and not be an internally
4283 -- generated subprogram.
4286 and then Present
(Prot_Typ
)
4287 and then Present
(Spec_Id
)
4288 and then Comes_From_Source
(Spec_Id
)
4289 and then not Is_Eliminated
(Spec_Id
)
4291 Install_Private_Data_Declarations
4292 (Sloc
(N
), Spec_Id
, Prot_Typ
, N
, Declarations
(N
));
4295 -- Ada 2012 (AI05-0151): Incomplete types coming from a limited context
4296 -- may now appear in parameter and result profiles. Since the analysis
4297 -- of a subprogram body may use the parameter and result profile of the
4298 -- spec, swap any limited views with their non-limited counterpart.
4300 if Ada_Version
>= Ada_2012
and then Present
(Spec_Id
) then
4301 Exch_Views
:= Exchange_Limited_Views
(Spec_Id
);
4304 -- If the return type is an anonymous access type whose designated type
4305 -- is the limited view of a class-wide type and the non-limited view is
4306 -- available, update the return type accordingly.
4308 if Ada_Version
>= Ada_2005
and then Present
(Spec_Id
) then
4314 Rtyp
:= Etype
(Spec_Id
);
4316 if Ekind
(Rtyp
) = E_Anonymous_Access_Type
then
4317 Etyp
:= Directly_Designated_Type
(Rtyp
);
4319 if Is_Class_Wide_Type
(Etyp
)
4320 and then From_Limited_With
(Etyp
)
4323 Set_Directly_Designated_Type
(Rtyp
, Available_View
(Etyp
));
4329 -- Analyze any aspect specifications that appear on the subprogram body
4331 if Has_Aspects
(N
) then
4332 Analyze_Aspect_Specifications_On_Body_Or_Stub
(N
);
4335 Analyze_Declarations
(Declarations
(N
));
4337 -- Verify that the SPARK_Mode of the body agrees with that of its spec
4339 if Present
(Spec_Id
) and then Present
(SPARK_Pragma
(Body_Id
)) then
4340 if Present
(SPARK_Pragma
(Spec_Id
)) then
4341 if Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Spec_Id
)) = Off
4343 Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Body_Id
)) = On
4345 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4346 Error_Msg_N
("incorrect application of SPARK_Mode#", N
);
4347 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Spec_Id
));
4349 ("\value Off was set for SPARK_Mode on & #", N
, Spec_Id
);
4352 elsif Nkind
(Parent
(Parent
(Spec_Id
))) = N_Subprogram_Body_Stub
then
4356 Error_Msg_Sloc
:= Sloc
(SPARK_Pragma
(Body_Id
));
4357 Error_Msg_N
("incorrect application of SPARK_Mode #", N
);
4358 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
4360 ("\no value was set for SPARK_Mode on & #", N
, Spec_Id
);
4364 -- A subprogram body freezes its own contract. Analyze the contract
4365 -- after the declarations of the body have been processed as pragmas
4366 -- are now chained on the contract of the subprogram body.
4368 Analyze_Entry_Or_Subprogram_Body_Contract
(Body_Id
);
4370 -- Check completion, and analyze the statements
4373 Inspect_Deferred_Constant_Completion
(Declarations
(N
));
4376 -- Deal with end of scope processing for the body
4378 Process_End_Label
(HSS
, 't', Current_Scope
);
4379 Update_Use_Clause_Chain
;
4382 -- If we are compiling an entry wrapper, remove the enclosing
4383 -- synchronized object from the stack.
4385 if Is_Entry_Wrapper
(Body_Id
) then
4389 Check_Subprogram_Order
(N
);
4390 Set_Analyzed
(Body_Id
);
4392 -- If we have a separate spec, then the analysis of the declarations
4393 -- caused the entities in the body to be chained to the spec id, but
4394 -- we want them chained to the body id. Only the formal parameters
4395 -- end up chained to the spec id in this case.
4397 if Present
(Spec_Id
) then
4399 -- We must conform to the categorization of our spec
4401 Validate_Categorization_Dependency
(N
, Spec_Id
);
4403 -- And if this is a child unit, the parent units must conform
4405 if Is_Child_Unit
(Spec_Id
) then
4406 Validate_Categorization_Dependency
4407 (Unit_Declaration_Node
(Spec_Id
), Spec_Id
);
4410 -- Here is where we move entities from the spec to the body
4412 -- Case where there are entities that stay with the spec
4414 if Present
(Last_Real_Spec_Entity
) then
4416 -- No body entities (happens when the only real spec entities come
4417 -- from precondition and postcondition pragmas).
4419 if No
(Last_Entity
(Body_Id
)) then
4420 Set_First_Entity
(Body_Id
, Next_Entity
(Last_Real_Spec_Entity
));
4422 -- Body entities present (formals), so chain stuff past them
4426 (Last_Entity
(Body_Id
), Next_Entity
(Last_Real_Spec_Entity
));
4429 Set_Next_Entity
(Last_Real_Spec_Entity
, Empty
);
4430 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4431 Set_Last_Entity
(Spec_Id
, Last_Real_Spec_Entity
);
4433 -- Case where there are no spec entities, in this case there can be
4434 -- no body entities either, so just move everything.
4436 -- If the body is generated for an expression function, it may have
4437 -- been preanalyzed already, if 'access was applied to it.
4440 if Nkind
(Original_Node
(Unit_Declaration_Node
(Spec_Id
))) /=
4441 N_Expression_Function
4443 pragma Assert
(No
(Last_Entity
(Body_Id
)));
4447 Set_First_Entity
(Body_Id
, First_Entity
(Spec_Id
));
4448 Set_Last_Entity
(Body_Id
, Last_Entity
(Spec_Id
));
4449 Set_First_Entity
(Spec_Id
, Empty
);
4450 Set_Last_Entity
(Spec_Id
, Empty
);
4454 Check_Missing_Return
;
4456 -- Now we are going to check for variables that are never modified in
4457 -- the body of the procedure. But first we deal with a special case
4458 -- where we want to modify this check. If the body of the subprogram
4459 -- starts with a raise statement or its equivalent, or if the body
4460 -- consists entirely of a null statement, then it is pretty obvious that
4461 -- it is OK to not reference the parameters. For example, this might be
4462 -- the following common idiom for a stubbed function: statement of the
4463 -- procedure raises an exception. In particular this deals with the
4464 -- common idiom of a stubbed function, which appears something like:
4466 -- function F (A : Integer) return Some_Type;
4469 -- raise Program_Error;
4473 -- Here the purpose of X is simply to satisfy the annoying requirement
4474 -- in Ada that there be at least one return, and we certainly do not
4475 -- want to go posting warnings on X that it is not initialized. On
4476 -- the other hand, if X is entirely unreferenced that should still
4479 -- What we do is to detect these cases, and if we find them, flag the
4480 -- subprogram as being Is_Trivial_Subprogram and then use that flag to
4481 -- suppress unwanted warnings. For the case of the function stub above
4482 -- we have a special test to set X as apparently assigned to suppress
4489 -- Skip call markers installed by the ABE mechanism, labels, and
4490 -- Push_xxx_Error_Label to find the first real statement.
4492 Stm
:= First
(Statements
(HSS
));
4493 while Nkind_In
(Stm
, N_Call_Marker
, N_Label
)
4494 or else Nkind
(Stm
) in N_Push_xxx_Label
4499 -- Do the test on the original statement before expansion
4502 Ostm
: constant Node_Id
:= Original_Node
(Stm
);
4505 -- If explicit raise statement, turn on flag
4507 if Nkind
(Ostm
) = N_Raise_Statement
then
4508 Set_Trivial_Subprogram
(Stm
);
4510 -- If null statement, and no following statements, turn on flag
4512 elsif Nkind
(Stm
) = N_Null_Statement
4513 and then Comes_From_Source
(Stm
)
4514 and then No
(Next
(Stm
))
4516 Set_Trivial_Subprogram
(Stm
);
4518 -- Check for explicit call cases which likely raise an exception
4520 elsif Nkind
(Ostm
) = N_Procedure_Call_Statement
then
4521 if Is_Entity_Name
(Name
(Ostm
)) then
4523 Ent
: constant Entity_Id
:= Entity
(Name
(Ostm
));
4526 -- If the procedure is marked No_Return, then likely it
4527 -- raises an exception, but in any case it is not coming
4528 -- back here, so turn on the flag.
4531 and then Ekind
(Ent
) = E_Procedure
4532 and then No_Return
(Ent
)
4534 Set_Trivial_Subprogram
(Stm
);
4542 -- Check for variables that are never modified
4549 -- If there is a separate spec, then transfer Never_Set_In_Source
4550 -- flags from out parameters to the corresponding entities in the
4551 -- body. The reason we do that is we want to post error flags on
4552 -- the body entities, not the spec entities.
4554 if Present
(Spec_Id
) then
4555 E1
:= First_Entity
(Spec_Id
);
4556 while Present
(E1
) loop
4557 if Ekind
(E1
) = E_Out_Parameter
then
4558 E2
:= First_Entity
(Body_Id
);
4559 while Present
(E2
) loop
4560 exit when Chars
(E1
) = Chars
(E2
);
4564 if Present
(E2
) then
4565 Set_Never_Set_In_Source
(E2
, Never_Set_In_Source
(E1
));
4573 -- Check references in body
4575 Check_References
(Body_Id
);
4578 -- Check for nested subprogram, and mark outer level subprogram if so
4584 if Present
(Spec_Id
) then
4591 Ent
:= Enclosing_Subprogram
(Ent
);
4592 exit when No
(Ent
) or else Is_Subprogram
(Ent
);
4595 if Present
(Ent
) then
4596 Set_Has_Nested_Subprogram
(Ent
);
4600 -- Restore the limited views in the spec, if any, to let the back end
4601 -- process it without running into circularities.
4603 if Exch_Views
/= No_Elist
then
4604 Restore_Limited_Views
(Exch_Views
);
4607 if Mask_Types
/= No_Elist
then
4608 Unmask_Unfrozen_Types
(Mask_Types
);
4611 if Present
(Desig_View
) then
4612 Set_Directly_Designated_Type
(Etype
(Spec_Id
), Desig_View
);
4616 Ignore_SPARK_Mode_Pragmas_In_Instance
:= Saved_ISMP
;
4617 Restore_Ghost_Mode
(Saved_GM
);
4618 end Analyze_Subprogram_Body_Helper
;
4620 ------------------------------------
4621 -- Analyze_Subprogram_Declaration --
4622 ------------------------------------
4624 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
) is
4625 Scop
: constant Entity_Id
:= Current_Scope
;
4626 Designator
: Entity_Id
;
4628 Is_Completion
: Boolean;
4629 -- Indicates whether a null procedure declaration is a completion
4632 -- Null procedures are not allowed in SPARK
4634 if Nkind
(Specification
(N
)) = N_Procedure_Specification
4635 and then Null_Present
(Specification
(N
))
4637 Check_SPARK_05_Restriction
("null procedure is not allowed", N
);
4639 -- Null procedures are allowed in protected types, following the
4640 -- recent AI12-0147.
4642 if Is_Protected_Type
(Current_Scope
)
4643 and then Ada_Version
< Ada_2012
4645 Error_Msg_N
("protected operation cannot be a null procedure", N
);
4648 Analyze_Null_Procedure
(N
, Is_Completion
);
4650 -- The null procedure acts as a body, nothing further is needed
4652 if Is_Completion
then
4657 Designator
:= Analyze_Subprogram_Specification
(Specification
(N
));
4659 -- A reference may already have been generated for the unit name, in
4660 -- which case the following call is redundant. However it is needed for
4661 -- declarations that are the rewriting of an expression function.
4663 Generate_Definition
(Designator
);
4665 -- Set the SPARK mode from the current context (may be overwritten later
4666 -- with explicit pragma). This is not done for entry barrier functions
4667 -- because they are generated outside the protected type and should not
4668 -- carry the mode of the enclosing context.
4670 if Nkind
(N
) = N_Subprogram_Declaration
4671 and then Is_Entry_Barrier_Function
(N
)
4676 Set_SPARK_Pragma
(Designator
, SPARK_Mode_Pragma
);
4677 Set_SPARK_Pragma_Inherited
(Designator
);
4680 -- Save the state of flag Ignore_SPARK_Mode_Pragmas_In_Instance in case
4681 -- the body of this subprogram is instantiated or inlined later and out
4682 -- of context. The body uses this attribute to restore the value of the
4685 if Ignore_SPARK_Mode_Pragmas_In_Instance
then
4686 Set_Ignore_SPARK_Mode_Pragmas
(Designator
);
4689 -- Preserve relevant elaboration-related attributes of the context which
4690 -- are no longer available or very expensive to recompute once analysis,
4691 -- resolution, and expansion are over.
4693 Mark_Elaboration_Attributes
4694 (N_Id
=> Designator
,
4697 if Debug_Flag_C
then
4698 Write_Str
("==> subprogram spec ");
4699 Write_Name
(Chars
(Designator
));
4700 Write_Str
(" from ");
4701 Write_Location
(Sloc
(N
));
4706 Validate_RCI_Subprogram_Declaration
(N
);
4707 New_Overloaded_Entity
(Designator
);
4708 Check_Delayed_Subprogram
(Designator
);
4710 -- If the type of the first formal of the current subprogram is a non-
4711 -- generic tagged private type, mark the subprogram as being a private
4712 -- primitive. Ditto if this is a function with controlling result, and
4713 -- the return type is currently private. In both cases, the type of the
4714 -- controlling argument or result must be in the current scope for the
4715 -- operation to be primitive.
4717 if Has_Controlling_Result
(Designator
)
4718 and then Is_Private_Type
(Etype
(Designator
))
4719 and then Scope
(Etype
(Designator
)) = Current_Scope
4720 and then not Is_Generic_Actual_Type
(Etype
(Designator
))
4722 Set_Is_Private_Primitive
(Designator
);
4724 elsif Present
(First_Formal
(Designator
)) then
4726 Formal_Typ
: constant Entity_Id
:=
4727 Etype
(First_Formal
(Designator
));
4729 Set_Is_Private_Primitive
(Designator
,
4730 Is_Tagged_Type
(Formal_Typ
)
4731 and then Scope
(Formal_Typ
) = Current_Scope
4732 and then Is_Private_Type
(Formal_Typ
)
4733 and then not Is_Generic_Actual_Type
(Formal_Typ
));
4737 -- Ada 2005 (AI-251): Abstract interface primitives must be abstract
4740 if Ada_Version
>= Ada_2005
4741 and then Comes_From_Source
(N
)
4742 and then Is_Dispatching_Operation
(Designator
)
4749 if Has_Controlling_Result
(Designator
) then
4750 Etyp
:= Etype
(Designator
);
4753 E
:= First_Entity
(Designator
);
4755 and then Is_Formal
(E
)
4756 and then not Is_Controlling_Formal
(E
)
4764 if Is_Access_Type
(Etyp
) then
4765 Etyp
:= Directly_Designated_Type
(Etyp
);
4768 if Is_Interface
(Etyp
)
4769 and then not Is_Abstract_Subprogram
(Designator
)
4770 and then not (Ekind
(Designator
) = E_Procedure
4771 and then Null_Present
(Specification
(N
)))
4773 Error_Msg_Name_1
:= Chars
(Defining_Entity
(N
));
4775 -- Specialize error message based on procedures vs. functions,
4776 -- since functions can't be null subprograms.
4778 if Ekind
(Designator
) = E_Procedure
then
4780 ("interface procedure % must be abstract or null", N
);
4783 ("interface function % must be abstract", N
);
4789 -- What is the following code for, it used to be
4791 -- ??? Set_Suppress_Elaboration_Checks
4792 -- ??? (Designator, Elaboration_Checks_Suppressed (Designator));
4794 -- The following seems equivalent, but a bit dubious
4796 if Elaboration_Checks_Suppressed
(Designator
) then
4797 Set_Kill_Elaboration_Checks
(Designator
);
4800 if Scop
/= Standard_Standard
and then not Is_Child_Unit
(Designator
) then
4801 Set_Categorization_From_Scope
(Designator
, Scop
);
4804 -- For a compilation unit, check for library-unit pragmas
4806 Push_Scope
(Designator
);
4807 Set_Categorization_From_Pragmas
(N
);
4808 Validate_Categorization_Dependency
(N
, Designator
);
4812 -- For a compilation unit, set body required. This flag will only be
4813 -- reset if a valid Import or Interface pragma is processed later on.
4815 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4816 Set_Body_Required
(Parent
(N
), True);
4818 if Ada_Version
>= Ada_2005
4819 and then Nkind
(Specification
(N
)) = N_Procedure_Specification
4820 and then Null_Present
(Specification
(N
))
4823 ("null procedure cannot be declared at library level", N
);
4827 Generate_Reference_To_Formals
(Designator
);
4828 Check_Eliminated
(Designator
);
4830 if Debug_Flag_C
then
4832 Write_Str
("<== subprogram spec ");
4833 Write_Name
(Chars
(Designator
));
4834 Write_Str
(" from ");
4835 Write_Location
(Sloc
(N
));
4839 if Is_Protected_Type
(Current_Scope
) then
4841 -- Indicate that this is a protected operation, because it may be
4842 -- used in subsequent declarations within the protected type.
4844 Set_Convention
(Designator
, Convention_Protected
);
4847 List_Inherited_Pre_Post_Aspects
(Designator
);
4849 if Has_Aspects
(N
) then
4850 Analyze_Aspect_Specifications
(N
, Designator
);
4852 end Analyze_Subprogram_Declaration
;
4854 --------------------------------------
4855 -- Analyze_Subprogram_Specification --
4856 --------------------------------------
4858 -- Reminder: N here really is a subprogram specification (not a subprogram
4859 -- declaration). This procedure is called to analyze the specification in
4860 -- both subprogram bodies and subprogram declarations (specs).
4862 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
is
4863 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean;
4864 -- Determine whether entity E denotes the spec or body of an invariant
4867 ------------------------------------
4868 -- Is_Invariant_Procedure_Or_Body --
4869 ------------------------------------
4871 function Is_Invariant_Procedure_Or_Body
(E
: Entity_Id
) return Boolean is
4872 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
4876 if Nkind
(Decl
) = N_Subprogram_Body
then
4877 Spec
:= Corresponding_Spec
(Decl
);
4884 and then Ekind
(Spec
) = E_Procedure
4885 and then (Is_Partial_Invariant_Procedure
(Spec
)
4886 or else Is_Invariant_Procedure
(Spec
));
4887 end Is_Invariant_Procedure_Or_Body
;
4891 Designator
: constant Entity_Id
:= Defining_Entity
(N
);
4892 Formals
: constant List_Id
:= Parameter_Specifications
(N
);
4894 -- Start of processing for Analyze_Subprogram_Specification
4897 -- User-defined operator is not allowed in SPARK, except as a renaming
4899 if Nkind
(Defining_Unit_Name
(N
)) = N_Defining_Operator_Symbol
4900 and then Nkind
(Parent
(N
)) /= N_Subprogram_Renaming_Declaration
4902 Check_SPARK_05_Restriction
4903 ("user-defined operator is not allowed", N
);
4906 -- Proceed with analysis. Do not emit a cross-reference entry if the
4907 -- specification comes from an expression function, because it may be
4908 -- the completion of a previous declaration. If it is not, the cross-
4909 -- reference entry will be emitted for the new subprogram declaration.
4911 if Nkind
(Parent
(N
)) /= N_Expression_Function
then
4912 Generate_Definition
(Designator
);
4915 if Nkind
(N
) = N_Function_Specification
then
4916 Set_Ekind
(Designator
, E_Function
);
4917 Set_Mechanism
(Designator
, Default_Mechanism
);
4919 Set_Ekind
(Designator
, E_Procedure
);
4920 Set_Etype
(Designator
, Standard_Void_Type
);
4923 -- Flag Is_Inlined_Always is True by default, and reversed to False for
4924 -- those subprograms which could be inlined in GNATprove mode (because
4925 -- Body_To_Inline is non-Empty) but should not be inlined.
4927 if GNATprove_Mode
then
4928 Set_Is_Inlined_Always
(Designator
);
4931 -- Introduce new scope for analysis of the formals and the return type
4933 Set_Scope
(Designator
, Current_Scope
);
4935 if Present
(Formals
) then
4936 Push_Scope
(Designator
);
4937 Process_Formals
(Formals
, N
);
4939 -- Check dimensions in N for formals with default expression
4941 Analyze_Dimension_Formals
(N
, Formals
);
4943 -- Ada 2005 (AI-345): If this is an overriding operation of an
4944 -- inherited interface operation, and the controlling type is
4945 -- a synchronized type, replace the type with its corresponding
4946 -- record, to match the proper signature of an overriding operation.
4947 -- Same processing for an access parameter whose designated type is
4948 -- derived from a synchronized interface.
4950 -- This modification is not done for invariant procedures because
4951 -- the corresponding record may not necessarely be visible when the
4952 -- concurrent type acts as the full view of a private type.
4955 -- type Prot is private with Type_Invariant => ...;
4956 -- procedure ConcInvariant (Obj : Prot);
4958 -- protected type Prot is ...;
4959 -- type Concurrent_Record_Prot is record ...;
4960 -- procedure ConcInvariant (Obj : Prot) is
4962 -- end ConcInvariant;
4965 -- In the example above, both the spec and body of the invariant
4966 -- procedure must utilize the private type as the controlling type.
4968 if Ada_Version
>= Ada_2005
4969 and then not Is_Invariant_Procedure_Or_Body
(Designator
)
4973 Formal_Typ
: Entity_Id
;
4974 Rec_Typ
: Entity_Id
;
4975 Desig_Typ
: Entity_Id
;
4978 Formal
:= First_Formal
(Designator
);
4979 while Present
(Formal
) loop
4980 Formal_Typ
:= Etype
(Formal
);
4982 if Is_Concurrent_Type
(Formal_Typ
)
4983 and then Present
(Corresponding_Record_Type
(Formal_Typ
))
4985 Rec_Typ
:= Corresponding_Record_Type
(Formal_Typ
);
4987 if Present
(Interfaces
(Rec_Typ
)) then
4988 Set_Etype
(Formal
, Rec_Typ
);
4991 elsif Ekind
(Formal_Typ
) = E_Anonymous_Access_Type
then
4992 Desig_Typ
:= Designated_Type
(Formal_Typ
);
4994 if Is_Concurrent_Type
(Desig_Typ
)
4995 and then Present
(Corresponding_Record_Type
(Desig_Typ
))
4997 Rec_Typ
:= Corresponding_Record_Type
(Desig_Typ
);
4999 if Present
(Interfaces
(Rec_Typ
)) then
5000 Set_Directly_Designated_Type
(Formal_Typ
, Rec_Typ
);
5005 Next_Formal
(Formal
);
5012 -- The subprogram scope is pushed and popped around the processing of
5013 -- the return type for consistency with call above to Process_Formals
5014 -- (which itself can call Analyze_Return_Type), and to ensure that any
5015 -- itype created for the return type will be associated with the proper
5018 elsif Nkind
(N
) = N_Function_Specification
then
5019 Push_Scope
(Designator
);
5020 Analyze_Return_Type
(N
);
5026 if Nkind
(N
) = N_Function_Specification
then
5028 -- Deal with operator symbol case
5030 if Nkind
(Designator
) = N_Defining_Operator_Symbol
then
5031 Valid_Operator_Definition
(Designator
);
5034 May_Need_Actuals
(Designator
);
5036 -- Ada 2005 (AI-251): If the return type is abstract, verify that
5037 -- the subprogram is abstract also. This does not apply to renaming
5038 -- declarations, where abstractness is inherited, and to subprogram
5039 -- bodies generated for stream operations, which become renamings as
5042 -- In case of primitives associated with abstract interface types
5043 -- the check is applied later (see Analyze_Subprogram_Declaration).
5045 if not Nkind_In
(Original_Node
(Parent
(N
)),
5046 N_Abstract_Subprogram_Declaration
,
5047 N_Formal_Abstract_Subprogram_Declaration
,
5048 N_Subprogram_Renaming_Declaration
)
5050 if Is_Abstract_Type
(Etype
(Designator
))
5051 and then not Is_Interface
(Etype
(Designator
))
5054 ("function that returns abstract type must be abstract", N
);
5056 -- Ada 2012 (AI-0073): Extend this test to subprograms with an
5057 -- access result whose designated type is abstract.
5059 elsif Ada_Version
>= Ada_2012
5060 and then Nkind
(Result_Definition
(N
)) = N_Access_Definition
5062 not Is_Class_Wide_Type
(Designated_Type
(Etype
(Designator
)))
5063 and then Is_Abstract_Type
(Designated_Type
(Etype
(Designator
)))
5066 ("function whose access result designates abstract type "
5067 & "must be abstract", N
);
5073 end Analyze_Subprogram_Specification
;
5075 -----------------------
5076 -- Check_Conformance --
5077 -----------------------
5079 procedure Check_Conformance
5080 (New_Id
: Entity_Id
;
5082 Ctype
: Conformance_Type
;
5084 Conforms
: out Boolean;
5085 Err_Loc
: Node_Id
:= Empty
;
5086 Get_Inst
: Boolean := False;
5087 Skip_Controlling_Formals
: Boolean := False)
5089 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
);
5090 -- Sets Conforms to False. If Errmsg is False, then that's all it does.
5091 -- If Errmsg is True, then processing continues to post an error message
5092 -- for conformance error on given node. Two messages are output. The
5093 -- first message points to the previous declaration with a general "no
5094 -- conformance" message. The second is the detailed reason, supplied as
5095 -- Msg. The parameter N provide information for a possible & insertion
5096 -- in the message, and also provides the location for posting the
5097 -- message in the absence of a specified Err_Loc location.
5099 function Conventions_Match
5101 Id2
: Entity_Id
) return Boolean;
5102 -- Determine whether the conventions of arbitrary entities Id1 and Id2
5105 -----------------------
5106 -- Conformance_Error --
5107 -----------------------
5109 procedure Conformance_Error
(Msg
: String; N
: Node_Id
:= New_Id
) is
5116 if No
(Err_Loc
) then
5122 Error_Msg_Sloc
:= Sloc
(Old_Id
);
5125 when Type_Conformant
=>
5126 Error_Msg_N
-- CODEFIX
5127 ("not type conformant with declaration#!", Enode
);
5129 when Mode_Conformant
=>
5130 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5132 ("not mode conformant with operation inherited#!",
5136 ("not mode conformant with declaration#!", Enode
);
5139 when Subtype_Conformant
=>
5140 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5142 ("not subtype conformant with operation inherited#!",
5146 ("not subtype conformant with declaration#!", Enode
);
5149 when Fully_Conformant
=>
5150 if Nkind
(Parent
(Old_Id
)) = N_Full_Type_Declaration
then
5151 Error_Msg_N
-- CODEFIX
5152 ("not fully conformant with operation inherited#!",
5155 Error_Msg_N
-- CODEFIX
5156 ("not fully conformant with declaration#!", Enode
);
5160 Error_Msg_NE
(Msg
, Enode
, N
);
5162 end Conformance_Error
;
5164 -----------------------
5165 -- Conventions_Match --
5166 -----------------------
5168 function Conventions_Match
5170 Id2
: Entity_Id
) return Boolean
5173 -- Ignore the conventions of anonymous access-to-subprogram types
5174 -- and subprogram types because these are internally generated and
5175 -- the only way these may receive a convention is if they inherit
5176 -- the convention of a related subprogram.
5178 if Ekind_In
(Id1
, E_Anonymous_Access_Subprogram_Type
,
5181 Ekind_In
(Id2
, E_Anonymous_Access_Subprogram_Type
,
5186 -- Otherwise compare the conventions directly
5189 return Convention
(Id1
) = Convention
(Id2
);
5191 end Conventions_Match
;
5195 Old_Type
: constant Entity_Id
:= Etype
(Old_Id
);
5196 New_Type
: constant Entity_Id
:= Etype
(New_Id
);
5197 Old_Formal
: Entity_Id
;
5198 New_Formal
: Entity_Id
;
5199 Access_Types_Match
: Boolean;
5200 Old_Formal_Base
: Entity_Id
;
5201 New_Formal_Base
: Entity_Id
;
5203 -- Start of processing for Check_Conformance
5208 -- We need a special case for operators, since they don't appear
5211 if Ctype
= Type_Conformant
then
5212 if Ekind
(New_Id
) = E_Operator
5213 and then Operator_Matches_Spec
(New_Id
, Old_Id
)
5219 -- If both are functions/operators, check return types conform
5221 if Old_Type
/= Standard_Void_Type
5223 New_Type
/= Standard_Void_Type
5225 -- If we are checking interface conformance we omit controlling
5226 -- arguments and result, because we are only checking the conformance
5227 -- of the remaining parameters.
5229 if Has_Controlling_Result
(Old_Id
)
5230 and then Has_Controlling_Result
(New_Id
)
5231 and then Skip_Controlling_Formals
5235 elsif not Conforming_Types
(Old_Type
, New_Type
, Ctype
, Get_Inst
) then
5236 if Ctype
>= Subtype_Conformant
5237 and then not Predicates_Match
(Old_Type
, New_Type
)
5240 ("\predicate of return type does not match!", New_Id
);
5243 ("\return type does not match!", New_Id
);
5249 -- Ada 2005 (AI-231): In case of anonymous access types check the
5250 -- null-exclusion and access-to-constant attributes match.
5252 if Ada_Version
>= Ada_2005
5253 and then Ekind
(Etype
(Old_Type
)) = E_Anonymous_Access_Type
5255 (Can_Never_Be_Null
(Old_Type
) /= Can_Never_Be_Null
(New_Type
)
5256 or else Is_Access_Constant
(Etype
(Old_Type
)) /=
5257 Is_Access_Constant
(Etype
(New_Type
)))
5259 Conformance_Error
("\return type does not match!", New_Id
);
5263 -- If either is a function/operator and the other isn't, error
5265 elsif Old_Type
/= Standard_Void_Type
5266 or else New_Type
/= Standard_Void_Type
5268 Conformance_Error
("\functions can only match functions!", New_Id
);
5272 -- In subtype conformant case, conventions must match (RM 6.3.1(16)).
5273 -- If this is a renaming as body, refine error message to indicate that
5274 -- the conflict is with the original declaration. If the entity is not
5275 -- frozen, the conventions don't have to match, the one of the renamed
5276 -- entity is inherited.
5278 if Ctype
>= Subtype_Conformant
then
5279 if not Conventions_Match
(Old_Id
, New_Id
) then
5280 if not Is_Frozen
(New_Id
) then
5283 elsif Present
(Err_Loc
)
5284 and then Nkind
(Err_Loc
) = N_Subprogram_Renaming_Declaration
5285 and then Present
(Corresponding_Spec
(Err_Loc
))
5287 Error_Msg_Name_1
:= Chars
(New_Id
);
5289 Name_Ada
+ Convention_Id
'Pos (Convention
(New_Id
));
5290 Conformance_Error
("\prior declaration for% has convention %!");
5293 Conformance_Error
("\calling conventions do not match!");
5298 elsif Is_Formal_Subprogram
(Old_Id
)
5299 or else Is_Formal_Subprogram
(New_Id
)
5301 Conformance_Error
("\formal subprograms not allowed!");
5306 -- Deal with parameters
5308 -- Note: we use the entity information, rather than going directly
5309 -- to the specification in the tree. This is not only simpler, but
5310 -- absolutely necessary for some cases of conformance tests between
5311 -- operators, where the declaration tree simply does not exist.
5313 Old_Formal
:= First_Formal
(Old_Id
);
5314 New_Formal
:= First_Formal
(New_Id
);
5315 while Present
(Old_Formal
) and then Present
(New_Formal
) loop
5316 if Is_Controlling_Formal
(Old_Formal
)
5317 and then Is_Controlling_Formal
(New_Formal
)
5318 and then Skip_Controlling_Formals
5320 -- The controlling formals will have different types when
5321 -- comparing an interface operation with its match, but both
5322 -- or neither must be access parameters.
5324 if Is_Access_Type
(Etype
(Old_Formal
))
5326 Is_Access_Type
(Etype
(New_Formal
))
5328 goto Skip_Controlling_Formal
;
5331 ("\access parameter does not match!", New_Formal
);
5335 -- Ada 2012: Mode conformance also requires that formal parameters
5336 -- be both aliased, or neither.
5338 if Ctype
>= Mode_Conformant
and then Ada_Version
>= Ada_2012
then
5339 if Is_Aliased
(Old_Formal
) /= Is_Aliased
(New_Formal
) then
5341 ("\aliased parameter mismatch!", New_Formal
);
5345 if Ctype
= Fully_Conformant
then
5347 -- Names must match. Error message is more accurate if we do
5348 -- this before checking that the types of the formals match.
5350 if Chars
(Old_Formal
) /= Chars
(New_Formal
) then
5351 Conformance_Error
("\name& does not match!", New_Formal
);
5353 -- Set error posted flag on new formal as well to stop
5354 -- junk cascaded messages in some cases.
5356 Set_Error_Posted
(New_Formal
);
5360 -- Null exclusion must match
5362 if Null_Exclusion_Present
(Parent
(Old_Formal
))
5364 Null_Exclusion_Present
(Parent
(New_Formal
))
5366 -- Only give error if both come from source. This should be
5367 -- investigated some time, since it should not be needed ???
5369 if Comes_From_Source
(Old_Formal
)
5371 Comes_From_Source
(New_Formal
)
5374 ("\null exclusion for& does not match", New_Formal
);
5376 -- Mark error posted on the new formal to avoid duplicated
5377 -- complaint about types not matching.
5379 Set_Error_Posted
(New_Formal
);
5384 -- Ada 2005 (AI-423): Possible access [sub]type and itype match. This
5385 -- case occurs whenever a subprogram is being renamed and one of its
5386 -- parameters imposes a null exclusion. For example:
5388 -- type T is null record;
5389 -- type Acc_T is access T;
5390 -- subtype Acc_T_Sub is Acc_T;
5392 -- procedure P (Obj : not null Acc_T_Sub); -- itype
5393 -- procedure Ren_P (Obj : Acc_T_Sub) -- subtype
5396 Old_Formal_Base
:= Etype
(Old_Formal
);
5397 New_Formal_Base
:= Etype
(New_Formal
);
5400 Old_Formal_Base
:= Get_Instance_Of
(Old_Formal_Base
);
5401 New_Formal_Base
:= Get_Instance_Of
(New_Formal_Base
);
5404 Access_Types_Match
:= Ada_Version
>= Ada_2005
5406 -- Ensure that this rule is only applied when New_Id is a
5407 -- renaming of Old_Id.
5409 and then Nkind
(Parent
(Parent
(New_Id
))) =
5410 N_Subprogram_Renaming_Declaration
5411 and then Nkind
(Name
(Parent
(Parent
(New_Id
)))) in N_Has_Entity
5412 and then Present
(Entity
(Name
(Parent
(Parent
(New_Id
)))))
5413 and then Entity
(Name
(Parent
(Parent
(New_Id
)))) = Old_Id
5415 -- Now handle the allowed access-type case
5417 and then Is_Access_Type
(Old_Formal_Base
)
5418 and then Is_Access_Type
(New_Formal_Base
)
5420 -- The type kinds must match. The only exception occurs with
5421 -- multiple generics of the form:
5424 -- type F is private; type A is private;
5425 -- type F_Ptr is access F; type A_Ptr is access A;
5426 -- with proc F_P (X : F_Ptr); with proc A_P (X : A_Ptr);
5427 -- package F_Pack is ... package A_Pack is
5428 -- package F_Inst is
5429 -- new F_Pack (A, A_Ptr, A_P);
5431 -- When checking for conformance between the parameters of A_P
5432 -- and F_P, the type kinds of F_Ptr and A_Ptr will not match
5433 -- because the compiler has transformed A_Ptr into a subtype of
5434 -- F_Ptr. We catch this case in the code below.
5436 and then (Ekind
(Old_Formal_Base
) = Ekind
(New_Formal_Base
)
5438 (Is_Generic_Type
(Old_Formal_Base
)
5439 and then Is_Generic_Type
(New_Formal_Base
)
5440 and then Is_Internal
(New_Formal_Base
)
5441 and then Etype
(Etype
(New_Formal_Base
)) =
5443 and then Directly_Designated_Type
(Old_Formal_Base
) =
5444 Directly_Designated_Type
(New_Formal_Base
)
5445 and then ((Is_Itype
(Old_Formal_Base
)
5446 and then Can_Never_Be_Null
(Old_Formal_Base
))
5448 (Is_Itype
(New_Formal_Base
)
5449 and then Can_Never_Be_Null
(New_Formal_Base
)));
5451 -- Types must always match. In the visible part of an instance,
5452 -- usual overloading rules for dispatching operations apply, and
5453 -- we check base types (not the actual subtypes).
5455 if In_Instance_Visible_Part
5456 and then Is_Dispatching_Operation
(New_Id
)
5458 if not Conforming_Types
5459 (T1
=> Base_Type
(Etype
(Old_Formal
)),
5460 T2
=> Base_Type
(Etype
(New_Formal
)),
5462 Get_Inst
=> Get_Inst
)
5463 and then not Access_Types_Match
5465 Conformance_Error
("\type of & does not match!", New_Formal
);
5469 elsif not Conforming_Types
5470 (T1
=> Old_Formal_Base
,
5471 T2
=> New_Formal_Base
,
5473 Get_Inst
=> Get_Inst
)
5474 and then not Access_Types_Match
5476 -- Don't give error message if old type is Any_Type. This test
5477 -- avoids some cascaded errors, e.g. in case of a bad spec.
5479 if Errmsg
and then Old_Formal_Base
= Any_Type
then
5482 if Ctype
>= Subtype_Conformant
5484 not Predicates_Match
(Old_Formal_Base
, New_Formal_Base
)
5487 ("\predicate of & does not match!", New_Formal
);
5490 ("\type of & does not match!", New_Formal
);
5492 if not Dimensions_Match
(Old_Formal_Base
, New_Formal_Base
)
5494 Error_Msg_N
("\dimensions mismatch!", New_Formal
);
5502 -- For mode conformance, mode must match
5504 if Ctype
>= Mode_Conformant
then
5505 if Parameter_Mode
(Old_Formal
) /= Parameter_Mode
(New_Formal
) then
5506 if not Ekind_In
(New_Id
, E_Function
, E_Procedure
)
5507 or else not Is_Primitive_Wrapper
(New_Id
)
5509 Conformance_Error
("\mode of & does not match!", New_Formal
);
5513 T
: constant Entity_Id
:= Find_Dispatching_Type
(New_Id
);
5515 if Is_Protected_Type
(Corresponding_Concurrent_Type
(T
))
5517 Error_Msg_PT
(New_Id
, Ultimate_Alias
(Old_Id
));
5520 ("\mode of & does not match!", New_Formal
);
5527 -- Part of mode conformance for access types is having the same
5528 -- constant modifier.
5530 elsif Access_Types_Match
5531 and then Is_Access_Constant
(Old_Formal_Base
) /=
5532 Is_Access_Constant
(New_Formal_Base
)
5535 ("\constant modifier does not match!", New_Formal
);
5540 if Ctype
>= Subtype_Conformant
then
5542 -- Ada 2005 (AI-231): In case of anonymous access types check
5543 -- the null-exclusion and access-to-constant attributes must
5544 -- match. For null exclusion, we test the types rather than the
5545 -- formals themselves, since the attribute is only set reliably
5546 -- on the formals in the Ada 95 case, and we exclude the case
5547 -- where Old_Formal is marked as controlling, to avoid errors
5548 -- when matching completing bodies with dispatching declarations
5549 -- (access formals in the bodies aren't marked Can_Never_Be_Null).
5551 if Ada_Version
>= Ada_2005
5552 and then Ekind
(Etype
(Old_Formal
)) = E_Anonymous_Access_Type
5553 and then Ekind
(Etype
(New_Formal
)) = E_Anonymous_Access_Type
5555 ((Can_Never_Be_Null
(Etype
(Old_Formal
)) /=
5556 Can_Never_Be_Null
(Etype
(New_Formal
))
5558 not Is_Controlling_Formal
(Old_Formal
))
5560 Is_Access_Constant
(Etype
(Old_Formal
)) /=
5561 Is_Access_Constant
(Etype
(New_Formal
)))
5563 -- Do not complain if error already posted on New_Formal. This
5564 -- avoids some redundant error messages.
5566 and then not Error_Posted
(New_Formal
)
5568 -- It is allowed to omit the null-exclusion in case of stream
5569 -- attribute subprograms. We recognize stream subprograms
5570 -- through their TSS-generated suffix.
5573 TSS_Name
: constant TSS_Name_Type
:= Get_TSS_Name
(New_Id
);
5576 if TSS_Name
/= TSS_Stream_Read
5577 and then TSS_Name
/= TSS_Stream_Write
5578 and then TSS_Name
/= TSS_Stream_Input
5579 and then TSS_Name
/= TSS_Stream_Output
5581 -- Here we have a definite conformance error. It is worth
5582 -- special casing the error message for the case of a
5583 -- controlling formal (which excludes null).
5585 if Is_Controlling_Formal
(New_Formal
) then
5586 Error_Msg_Node_2
:= Scope
(New_Formal
);
5588 ("\controlling formal & of & excludes null, "
5589 & "declaration must exclude null as well",
5592 -- Normal case (couldn't we give more detail here???)
5596 ("\type of & does not match!", New_Formal
);
5605 -- Full conformance checks
5607 if Ctype
= Fully_Conformant
then
5609 -- We have checked already that names match
5611 if Parameter_Mode
(Old_Formal
) = E_In_Parameter
then
5613 -- Check default expressions for in parameters
5616 NewD
: constant Boolean :=
5617 Present
(Default_Value
(New_Formal
));
5618 OldD
: constant Boolean :=
5619 Present
(Default_Value
(Old_Formal
));
5621 if NewD
or OldD
then
5623 -- The old default value has been analyzed because the
5624 -- current full declaration will have frozen everything
5625 -- before. The new default value has not been analyzed,
5626 -- so analyze it now before we check for conformance.
5629 Push_Scope
(New_Id
);
5630 Preanalyze_Spec_Expression
5631 (Default_Value
(New_Formal
), Etype
(New_Formal
));
5635 if not (NewD
and OldD
)
5636 or else not Fully_Conformant_Expressions
5637 (Default_Value
(Old_Formal
),
5638 Default_Value
(New_Formal
))
5641 ("\default expression for & does not match!",
5650 -- A couple of special checks for Ada 83 mode. These checks are
5651 -- skipped if either entity is an operator in package Standard,
5652 -- or if either old or new instance is not from the source program.
5654 if Ada_Version
= Ada_83
5655 and then Sloc
(Old_Id
) > Standard_Location
5656 and then Sloc
(New_Id
) > Standard_Location
5657 and then Comes_From_Source
(Old_Id
)
5658 and then Comes_From_Source
(New_Id
)
5661 Old_Param
: constant Node_Id
:= Declaration_Node
(Old_Formal
);
5662 New_Param
: constant Node_Id
:= Declaration_Node
(New_Formal
);
5665 -- Explicit IN must be present or absent in both cases. This
5666 -- test is required only in the full conformance case.
5668 if In_Present
(Old_Param
) /= In_Present
(New_Param
)
5669 and then Ctype
= Fully_Conformant
5672 ("\(Ada 83) IN must appear in both declarations",
5677 -- Grouping (use of comma in param lists) must be the same
5678 -- This is where we catch a misconformance like:
5681 -- A : Integer; B : Integer
5683 -- which are represented identically in the tree except
5684 -- for the setting of the flags More_Ids and Prev_Ids.
5686 if More_Ids
(Old_Param
) /= More_Ids
(New_Param
)
5687 or else Prev_Ids
(Old_Param
) /= Prev_Ids
(New_Param
)
5690 ("\grouping of & does not match!", New_Formal
);
5696 -- This label is required when skipping controlling formals
5698 <<Skip_Controlling_Formal
>>
5700 Next_Formal
(Old_Formal
);
5701 Next_Formal
(New_Formal
);
5704 if Present
(Old_Formal
) then
5705 Conformance_Error
("\too few parameters!");
5708 elsif Present
(New_Formal
) then
5709 Conformance_Error
("\too many parameters!", New_Formal
);
5712 end Check_Conformance
;
5714 -----------------------
5715 -- Check_Conventions --
5716 -----------------------
5718 procedure Check_Conventions
(Typ
: Entity_Id
) is
5719 Ifaces_List
: Elist_Id
;
5721 procedure Check_Convention
(Op
: Entity_Id
);
5722 -- Verify that the convention of inherited dispatching operation Op is
5723 -- consistent among all subprograms it overrides. In order to minimize
5724 -- the search, Search_From is utilized to designate a specific point in
5725 -- the list rather than iterating over the whole list once more.
5727 ----------------------
5728 -- Check_Convention --
5729 ----------------------
5731 procedure Check_Convention
(Op
: Entity_Id
) is
5732 Op_Conv
: constant Convention_Id
:= Convention
(Op
);
5733 Iface_Conv
: Convention_Id
;
5734 Iface_Elmt
: Elmt_Id
;
5735 Iface_Prim_Elmt
: Elmt_Id
;
5736 Iface_Prim
: Entity_Id
;
5739 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5740 while Present
(Iface_Elmt
) loop
5742 First_Elmt
(Primitive_Operations
(Node
(Iface_Elmt
)));
5743 while Present
(Iface_Prim_Elmt
) loop
5744 Iface_Prim
:= Node
(Iface_Prim_Elmt
);
5745 Iface_Conv
:= Convention
(Iface_Prim
);
5747 if Is_Interface_Conformant
(Typ
, Iface_Prim
, Op
)
5748 and then Iface_Conv
/= Op_Conv
5751 ("inconsistent conventions in primitive operations", Typ
);
5753 Error_Msg_Name_1
:= Chars
(Op
);
5754 Error_Msg_Name_2
:= Get_Convention_Name
(Op_Conv
);
5755 Error_Msg_Sloc
:= Sloc
(Op
);
5757 if Comes_From_Source
(Op
) or else No
(Alias
(Op
)) then
5758 if not Present
(Overridden_Operation
(Op
)) then
5759 Error_Msg_N
("\\primitive % defined #", Typ
);
5762 ("\\overriding operation % with "
5763 & "convention % defined #", Typ
);
5766 else pragma Assert
(Present
(Alias
(Op
)));
5767 Error_Msg_Sloc
:= Sloc
(Alias
(Op
));
5768 Error_Msg_N
("\\inherited operation % with "
5769 & "convention % defined #", Typ
);
5772 Error_Msg_Name_1
:= Chars
(Op
);
5773 Error_Msg_Name_2
:= Get_Convention_Name
(Iface_Conv
);
5774 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
5775 Error_Msg_N
("\\overridden operation % with "
5776 & "convention % defined #", Typ
);
5778 -- Avoid cascading errors
5783 Next_Elmt
(Iface_Prim_Elmt
);
5786 Next_Elmt
(Iface_Elmt
);
5788 end Check_Convention
;
5792 Prim_Op
: Entity_Id
;
5793 Prim_Op_Elmt
: Elmt_Id
;
5795 -- Start of processing for Check_Conventions
5798 if not Has_Interfaces
(Typ
) then
5802 Collect_Interfaces
(Typ
, Ifaces_List
);
5804 -- The algorithm checks every overriding dispatching operation against
5805 -- all the corresponding overridden dispatching operations, detecting
5806 -- differences in conventions.
5808 Prim_Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5809 while Present
(Prim_Op_Elmt
) loop
5810 Prim_Op
:= Node
(Prim_Op_Elmt
);
5812 -- A small optimization: skip the predefined dispatching operations
5813 -- since they always have the same convention.
5815 if not Is_Predefined_Dispatching_Operation
(Prim_Op
) then
5816 Check_Convention
(Prim_Op
);
5819 Next_Elmt
(Prim_Op_Elmt
);
5821 end Check_Conventions
;
5823 ------------------------------
5824 -- Check_Delayed_Subprogram --
5825 ------------------------------
5827 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
) is
5828 procedure Possible_Freeze
(T
: Entity_Id
);
5829 -- T is the type of either a formal parameter or of the return type. If
5830 -- T is not yet frozen and needs a delayed freeze, then the subprogram
5831 -- itself must be delayed.
5833 ---------------------
5834 -- Possible_Freeze --
5835 ---------------------
5837 procedure Possible_Freeze
(T
: Entity_Id
) is
5838 Scop
: constant Entity_Id
:= Scope
(Designator
);
5841 -- If the subprogram appears within a package instance (which may be
5842 -- the wrapper package of a subprogram instance) the freeze node for
5843 -- that package will freeze the subprogram at the proper place, so
5844 -- do not emit a freeze node for the subprogram, given that it may
5845 -- appear in the wrong scope.
5847 if Ekind
(Scop
) = E_Package
5848 and then not Comes_From_Source
(Scop
)
5849 and then Is_Generic_Instance
(Scop
)
5853 elsif Has_Delayed_Freeze
(T
) and then not Is_Frozen
(T
) then
5854 Set_Has_Delayed_Freeze
(Designator
);
5856 elsif Is_Access_Type
(T
)
5857 and then Has_Delayed_Freeze
(Designated_Type
(T
))
5858 and then not Is_Frozen
(Designated_Type
(T
))
5860 Set_Has_Delayed_Freeze
(Designator
);
5862 end Possible_Freeze
;
5868 -- Start of processing for Check_Delayed_Subprogram
5871 -- All subprograms, including abstract subprograms, may need a freeze
5872 -- node if some formal type or the return type needs one.
5874 Possible_Freeze
(Etype
(Designator
));
5875 Possible_Freeze
(Base_Type
(Etype
(Designator
))); -- needed ???
5877 -- Need delayed freeze if any of the formal types themselves need a
5878 -- delayed freeze and are not yet frozen.
5880 F
:= First_Formal
(Designator
);
5881 while Present
(F
) loop
5882 Possible_Freeze
(Etype
(F
));
5883 Possible_Freeze
(Base_Type
(Etype
(F
))); -- needed ???
5887 -- Mark functions that return by reference. Note that it cannot be done
5888 -- for delayed_freeze subprograms because the underlying returned type
5889 -- may not be known yet (for private types).
5891 if not Has_Delayed_Freeze
(Designator
) and then Expander_Active
then
5893 Typ
: constant Entity_Id
:= Etype
(Designator
);
5894 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
5897 if Is_Limited_View
(Typ
) then
5898 Set_Returns_By_Ref
(Designator
);
5900 elsif Present
(Utyp
) and then CW_Or_Has_Controlled_Part
(Utyp
) then
5901 Set_Returns_By_Ref
(Designator
);
5905 end Check_Delayed_Subprogram
;
5907 ------------------------------------
5908 -- Check_Discriminant_Conformance --
5909 ------------------------------------
5911 procedure Check_Discriminant_Conformance
5916 Old_Discr
: Entity_Id
:= First_Discriminant
(Prev
);
5917 New_Discr
: Node_Id
:= First
(Discriminant_Specifications
(N
));
5918 New_Discr_Id
: Entity_Id
;
5919 New_Discr_Type
: Entity_Id
;
5921 procedure Conformance_Error
(Msg
: String; N
: Node_Id
);
5922 -- Post error message for conformance error on given node. Two messages
5923 -- are output. The first points to the previous declaration with a
5924 -- general "no conformance" message. The second is the detailed reason,
5925 -- supplied as Msg. The parameter N provide information for a possible
5926 -- & insertion in the message.
5928 -----------------------
5929 -- Conformance_Error --
5930 -----------------------
5932 procedure Conformance_Error
(Msg
: String; N
: Node_Id
) is
5934 Error_Msg_Sloc
:= Sloc
(Prev_Loc
);
5935 Error_Msg_N
-- CODEFIX
5936 ("not fully conformant with declaration#!", N
);
5937 Error_Msg_NE
(Msg
, N
, N
);
5938 end Conformance_Error
;
5940 -- Start of processing for Check_Discriminant_Conformance
5943 while Present
(Old_Discr
) and then Present
(New_Discr
) loop
5944 New_Discr_Id
:= Defining_Identifier
(New_Discr
);
5946 -- The subtype mark of the discriminant on the full type has not
5947 -- been analyzed so we do it here. For an access discriminant a new
5950 if Nkind
(Discriminant_Type
(New_Discr
)) = N_Access_Definition
then
5952 Access_Definition
(N
, Discriminant_Type
(New_Discr
));
5955 Analyze
(Discriminant_Type
(New_Discr
));
5956 New_Discr_Type
:= Etype
(Discriminant_Type
(New_Discr
));
5958 -- Ada 2005: if the discriminant definition carries a null
5959 -- exclusion, create an itype to check properly for consistency
5960 -- with partial declaration.
5962 if Is_Access_Type
(New_Discr_Type
)
5963 and then Null_Exclusion_Present
(New_Discr
)
5966 Create_Null_Excluding_Itype
5967 (T
=> New_Discr_Type
,
5968 Related_Nod
=> New_Discr
,
5969 Scope_Id
=> Current_Scope
);
5973 if not Conforming_Types
5974 (Etype
(Old_Discr
), New_Discr_Type
, Fully_Conformant
)
5976 Conformance_Error
("type of & does not match!", New_Discr_Id
);
5979 -- Treat the new discriminant as an occurrence of the old one,
5980 -- for navigation purposes, and fill in some semantic
5981 -- information, for completeness.
5983 Generate_Reference
(Old_Discr
, New_Discr_Id
, 'r');
5984 Set_Etype
(New_Discr_Id
, Etype
(Old_Discr
));
5985 Set_Scope
(New_Discr_Id
, Scope
(Old_Discr
));
5990 if Chars
(Old_Discr
) /= Chars
(Defining_Identifier
(New_Discr
)) then
5991 Conformance_Error
("name & does not match!", New_Discr_Id
);
5995 -- Default expressions must match
5998 NewD
: constant Boolean :=
5999 Present
(Expression
(New_Discr
));
6000 OldD
: constant Boolean :=
6001 Present
(Expression
(Parent
(Old_Discr
)));
6004 if NewD
or OldD
then
6006 -- The old default value has been analyzed and expanded,
6007 -- because the current full declaration will have frozen
6008 -- everything before. The new default values have not been
6009 -- expanded, so expand now to check conformance.
6012 Preanalyze_Spec_Expression
6013 (Expression
(New_Discr
), New_Discr_Type
);
6016 if not (NewD
and OldD
)
6017 or else not Fully_Conformant_Expressions
6018 (Expression
(Parent
(Old_Discr
)),
6019 Expression
(New_Discr
))
6023 ("default expression for & does not match!",
6030 -- In Ada 83 case, grouping must match: (A,B : X) /= (A : X; B : X)
6032 if Ada_Version
= Ada_83
then
6034 Old_Disc
: constant Node_Id
:= Declaration_Node
(Old_Discr
);
6037 -- Grouping (use of comma in param lists) must be the same
6038 -- This is where we catch a misconformance like:
6041 -- A : Integer; B : Integer
6043 -- which are represented identically in the tree except
6044 -- for the setting of the flags More_Ids and Prev_Ids.
6046 if More_Ids
(Old_Disc
) /= More_Ids
(New_Discr
)
6047 or else Prev_Ids
(Old_Disc
) /= Prev_Ids
(New_Discr
)
6050 ("grouping of & does not match!", New_Discr_Id
);
6056 Next_Discriminant
(Old_Discr
);
6060 if Present
(Old_Discr
) then
6061 Conformance_Error
("too few discriminants!", Defining_Identifier
(N
));
6064 elsif Present
(New_Discr
) then
6066 ("too many discriminants!", Defining_Identifier
(New_Discr
));
6069 end Check_Discriminant_Conformance
;
6071 ----------------------------
6072 -- Check_Fully_Conformant --
6073 ----------------------------
6075 procedure Check_Fully_Conformant
6076 (New_Id
: Entity_Id
;
6078 Err_Loc
: Node_Id
:= Empty
)
6081 pragma Warnings
(Off
, Result
);
6084 (New_Id
, Old_Id
, Fully_Conformant
, True, Result
, Err_Loc
);
6085 end Check_Fully_Conformant
;
6087 --------------------------
6088 -- Check_Limited_Return --
6089 --------------------------
6091 procedure Check_Limited_Return
6097 -- Ada 2005 (AI-318-02): Return-by-reference types have been removed and
6098 -- replaced by anonymous access results. This is an incompatibility with
6099 -- Ada 95. Not clear whether this should be enforced yet or perhaps
6100 -- controllable with special switch. ???
6102 -- A limited interface that is not immutably limited is OK
6104 if Is_Limited_Interface
(R_Type
)
6106 not (Is_Task_Interface
(R_Type
)
6107 or else Is_Protected_Interface
(R_Type
)
6108 or else Is_Synchronized_Interface
(R_Type
))
6112 elsif Is_Limited_Type
(R_Type
)
6113 and then not Is_Interface
(R_Type
)
6114 and then Comes_From_Source
(N
)
6115 and then not In_Instance_Body
6116 and then not OK_For_Limited_Init_In_05
(R_Type
, Expr
)
6118 -- Error in Ada 2005
6120 if Ada_Version
>= Ada_2005
6121 and then not Debug_Flag_Dot_L
6122 and then not GNAT_Mode
6125 ("(Ada 2005) cannot copy object of a limited type "
6126 & "(RM-2005 6.5(5.5/2))", Expr
);
6128 if Is_Limited_View
(R_Type
) then
6130 ("\return by reference not permitted in Ada 2005", Expr
);
6133 -- Warn in Ada 95 mode, to give folks a heads up about this
6136 -- In GNAT mode, this is just a warning, to allow it to be evilly
6137 -- turned off. Otherwise it is a real error.
6139 -- In a generic context, simplify the warning because it makes no
6140 -- sense to discuss pass-by-reference or copy.
6142 elsif Warn_On_Ada_2005_Compatibility
or GNAT_Mode
then
6143 if Inside_A_Generic
then
6145 ("return of limited object not permitted in Ada 2005 "
6146 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
6148 elsif Is_Limited_View
(R_Type
) then
6150 ("return by reference not permitted in Ada 2005 "
6151 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
6154 ("cannot copy object of a limited type in Ada 2005 "
6155 & "(RM-2005 6.5(5.5/2))?y?", Expr
);
6158 -- Ada 95 mode, and compatibility warnings disabled
6161 pragma Assert
(Ada_Version
<= Ada_95
);
6162 pragma Assert
(not (Warn_On_Ada_2005_Compatibility
or GNAT_Mode
));
6163 return; -- skip continuation messages below
6166 if not Inside_A_Generic
then
6168 ("\consider switching to return of access type", Expr
);
6169 Explain_Limited_Type
(R_Type
, Expr
);
6172 end Check_Limited_Return
;
6174 ---------------------------
6175 -- Check_Mode_Conformant --
6176 ---------------------------
6178 procedure Check_Mode_Conformant
6179 (New_Id
: Entity_Id
;
6181 Err_Loc
: Node_Id
:= Empty
;
6182 Get_Inst
: Boolean := False)
6185 pragma Warnings
(Off
, Result
);
6188 (New_Id
, Old_Id
, Mode_Conformant
, True, Result
, Err_Loc
, Get_Inst
);
6189 end Check_Mode_Conformant
;
6191 --------------------------------
6192 -- Check_Overriding_Indicator --
6193 --------------------------------
6195 procedure Check_Overriding_Indicator
6197 Overridden_Subp
: Entity_Id
;
6198 Is_Primitive
: Boolean)
6204 -- No overriding indicator for literals
6206 if Ekind
(Subp
) = E_Enumeration_Literal
then
6209 elsif Ekind
(Subp
) = E_Entry
then
6210 Decl
:= Parent
(Subp
);
6212 -- No point in analyzing a malformed operator
6214 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
6215 and then Error_Posted
(Subp
)
6220 Decl
:= Unit_Declaration_Node
(Subp
);
6223 if Nkind_In
(Decl
, N_Subprogram_Body
,
6224 N_Subprogram_Body_Stub
,
6225 N_Subprogram_Declaration
,
6226 N_Abstract_Subprogram_Declaration
,
6227 N_Subprogram_Renaming_Declaration
)
6229 Spec
:= Specification
(Decl
);
6231 elsif Nkind
(Decl
) = N_Entry_Declaration
then
6238 -- The overriding operation is type conformant with the overridden one,
6239 -- but the names of the formals are not required to match. If the names
6240 -- appear permuted in the overriding operation, this is a possible
6241 -- source of confusion that is worth diagnosing. Controlling formals
6242 -- often carry names that reflect the type, and it is not worthwhile
6243 -- requiring that their names match.
6245 if Present
(Overridden_Subp
)
6246 and then Nkind
(Subp
) /= N_Defining_Operator_Symbol
6253 Form1
:= First_Formal
(Subp
);
6254 Form2
:= First_Formal
(Overridden_Subp
);
6256 -- If the overriding operation is a synchronized operation, skip
6257 -- the first parameter of the overridden operation, which is
6258 -- implicit in the new one. If the operation is declared in the
6259 -- body it is not primitive and all formals must match.
6261 if Is_Concurrent_Type
(Scope
(Subp
))
6262 and then Is_Tagged_Type
(Scope
(Subp
))
6263 and then not Has_Completion
(Scope
(Subp
))
6265 Form2
:= Next_Formal
(Form2
);
6268 if Present
(Form1
) then
6269 Form1
:= Next_Formal
(Form1
);
6270 Form2
:= Next_Formal
(Form2
);
6273 while Present
(Form1
) loop
6274 if not Is_Controlling_Formal
(Form1
)
6275 and then Present
(Next_Formal
(Form2
))
6276 and then Chars
(Form1
) = Chars
(Next_Formal
(Form2
))
6278 Error_Msg_Node_2
:= Alias
(Overridden_Subp
);
6279 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
6281 ("& does not match corresponding formal of&#",
6286 Next_Formal
(Form1
);
6287 Next_Formal
(Form2
);
6292 -- If there is an overridden subprogram, then check that there is no
6293 -- "not overriding" indicator, and mark the subprogram as overriding.
6294 -- This is not done if the overridden subprogram is marked as hidden,
6295 -- which can occur for the case of inherited controlled operations
6296 -- (see Derive_Subprogram), unless the inherited subprogram's parent
6297 -- subprogram is not itself hidden. (Note: This condition could probably
6298 -- be simplified, leaving out the testing for the specific controlled
6299 -- cases, but it seems safer and clearer this way, and echoes similar
6300 -- special-case tests of this kind in other places.)
6302 if Present
(Overridden_Subp
)
6303 and then (not Is_Hidden
(Overridden_Subp
)
6305 (Nam_In
(Chars
(Overridden_Subp
), Name_Initialize
,
6308 and then Present
(Alias
(Overridden_Subp
))
6309 and then not Is_Hidden
(Alias
(Overridden_Subp
))))
6311 if Must_Not_Override
(Spec
) then
6312 Error_Msg_Sloc
:= Sloc
(Overridden_Subp
);
6314 if Ekind
(Subp
) = E_Entry
then
6316 ("entry & overrides inherited operation #", Spec
, Subp
);
6319 ("subprogram & overrides inherited operation #", Spec
, Subp
);
6322 -- Special-case to fix a GNAT oddity: Limited_Controlled is declared
6323 -- as an extension of Root_Controlled, and thus has a useless Adjust
6324 -- operation. This operation should not be inherited by other limited
6325 -- controlled types. An explicit Adjust for them is not overriding.
6327 elsif Must_Override
(Spec
)
6328 and then Chars
(Overridden_Subp
) = Name_Adjust
6329 and then Is_Limited_Type
(Etype
(First_Formal
(Subp
)))
6330 and then Present
(Alias
(Overridden_Subp
))
6331 and then In_Predefined_Unit
(Alias
(Overridden_Subp
))
6334 (Unit_File_Name
(Get_Source_Unit
(Alias
(Overridden_Subp
))));
6335 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6337 elsif Is_Subprogram
(Subp
) then
6338 if Is_Init_Proc
(Subp
) then
6341 elsif No
(Overridden_Operation
(Subp
)) then
6343 -- For entities generated by Derive_Subprograms the overridden
6344 -- operation is the inherited primitive (which is available
6345 -- through the attribute alias)
6347 if (Is_Dispatching_Operation
(Subp
)
6348 or else Is_Dispatching_Operation
(Overridden_Subp
))
6349 and then not Comes_From_Source
(Overridden_Subp
)
6350 and then Find_Dispatching_Type
(Overridden_Subp
) =
6351 Find_Dispatching_Type
(Subp
)
6352 and then Present
(Alias
(Overridden_Subp
))
6353 and then Comes_From_Source
(Alias
(Overridden_Subp
))
6355 Set_Overridden_Operation
(Subp
, Alias
(Overridden_Subp
));
6356 Inherit_Subprogram_Contract
(Subp
, Alias
(Overridden_Subp
));
6359 Set_Overridden_Operation
(Subp
, Overridden_Subp
);
6360 Inherit_Subprogram_Contract
(Subp
, Overridden_Subp
);
6365 -- If primitive flag is set or this is a protected operation, then
6366 -- the operation is overriding at the point of its declaration, so
6367 -- warn if necessary. Otherwise it may have been declared before the
6368 -- operation it overrides and no check is required.
6371 and then not Must_Override
(Spec
)
6372 and then (Is_Primitive
6373 or else Ekind
(Scope
(Subp
)) = E_Protected_Type
)
6375 Style
.Missing_Overriding
(Decl
, Subp
);
6378 -- If Subp is an operator, it may override a predefined operation, if
6379 -- it is defined in the same scope as the type to which it applies.
6380 -- In that case Overridden_Subp is empty because of our implicit
6381 -- representation for predefined operators. We have to check whether the
6382 -- signature of Subp matches that of a predefined operator. Note that
6383 -- first argument provides the name of the operator, and the second
6384 -- argument the signature that may match that of a standard operation.
6385 -- If the indicator is overriding, then the operator must match a
6386 -- predefined signature, because we know already that there is no
6387 -- explicit overridden operation.
6389 elsif Nkind
(Subp
) = N_Defining_Operator_Symbol
then
6390 if Must_Not_Override
(Spec
) then
6392 -- If this is not a primitive or a protected subprogram, then
6393 -- "not overriding" is illegal.
6396 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6398 Error_Msg_N
("overriding indicator only allowed "
6399 & "if subprogram is primitive", Subp
);
6401 elsif Can_Override_Operator
(Subp
) then
6403 ("subprogram& overrides predefined operator ", Spec
, Subp
);
6406 elsif Must_Override
(Spec
) then
6407 if No
(Overridden_Operation
(Subp
))
6408 and then not Can_Override_Operator
(Subp
)
6410 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6413 elsif not Error_Posted
(Subp
)
6414 and then Style_Check
6415 and then Can_Override_Operator
(Subp
)
6416 and then not In_Predefined_Unit
(Subp
)
6418 -- If style checks are enabled, indicate that the indicator is
6419 -- missing. However, at the point of declaration, the type of
6420 -- which this is a primitive operation may be private, in which
6421 -- case the indicator would be premature.
6423 if Has_Private_Declaration
(Etype
(Subp
))
6424 or else Has_Private_Declaration
(Etype
(First_Formal
(Subp
)))
6428 Style
.Missing_Overriding
(Decl
, Subp
);
6432 elsif Must_Override
(Spec
) then
6433 if Ekind
(Subp
) = E_Entry
then
6434 Error_Msg_NE
("entry & is not overriding", Spec
, Subp
);
6436 Error_Msg_NE
("subprogram & is not overriding", Spec
, Subp
);
6439 -- If the operation is marked "not overriding" and it's not primitive
6440 -- then an error is issued, unless this is an operation of a task or
6441 -- protected type (RM05-8.3.1(3/2-4/2)). Error cases where "overriding"
6442 -- has been specified have already been checked above.
6444 elsif Must_Not_Override
(Spec
)
6445 and then not Is_Primitive
6446 and then Ekind
(Subp
) /= E_Entry
6447 and then Ekind
(Scope
(Subp
)) /= E_Protected_Type
6450 ("overriding indicator only allowed if subprogram is primitive",
6454 end Check_Overriding_Indicator
;
6460 -- Note: this procedure needs to know far too much about how the expander
6461 -- messes with exceptions. The use of the flag Exception_Junk and the
6462 -- incorporation of knowledge of Exp_Ch11.Expand_Local_Exception_Handlers
6463 -- works, but is not very clean. It would be better if the expansion
6464 -- routines would leave Original_Node working nicely, and we could use
6465 -- Original_Node here to ignore all the peculiar expander messing ???
6467 procedure Check_Returns
6471 Proc
: Entity_Id
:= Empty
)
6475 procedure Check_Statement_Sequence
(L
: List_Id
);
6476 -- Internal recursive procedure to check a list of statements for proper
6477 -- termination by a return statement (or a transfer of control or a
6478 -- compound statement that is itself internally properly terminated).
6480 ------------------------------
6481 -- Check_Statement_Sequence --
6482 ------------------------------
6484 procedure Check_Statement_Sequence
(L
: List_Id
) is
6489 function Assert_False
return Boolean;
6490 -- Returns True if Last_Stm is a pragma Assert (False) that has been
6491 -- rewritten as a null statement when assertions are off. The assert
6492 -- is not active, but it is still enough to kill the warning.
6498 function Assert_False
return Boolean is
6499 Orig
: constant Node_Id
:= Original_Node
(Last_Stm
);
6502 if Nkind
(Orig
) = N_Pragma
6503 and then Pragma_Name
(Orig
) = Name_Assert
6504 and then not Error_Posted
(Orig
)
6507 Arg
: constant Node_Id
:=
6508 First
(Pragma_Argument_Associations
(Orig
));
6509 Exp
: constant Node_Id
:= Expression
(Arg
);
6511 return Nkind
(Exp
) = N_Identifier
6512 and then Chars
(Exp
) = Name_False
;
6522 Raise_Exception_Call
: Boolean;
6523 -- Set True if statement sequence terminated by Raise_Exception call
6524 -- or a Reraise_Occurrence call.
6526 -- Start of processing for Check_Statement_Sequence
6529 Raise_Exception_Call
:= False;
6531 -- Get last real statement
6533 Last_Stm
:= Last
(L
);
6535 -- Deal with digging out exception handler statement sequences that
6536 -- have been transformed by the local raise to goto optimization.
6537 -- See Exp_Ch11.Expand_Local_Exception_Handlers for details. If this
6538 -- optimization has occurred, we are looking at something like:
6541 -- original stmts in block
6545 -- goto L1; | omitted if No_Exception_Propagation
6550 -- goto L3; -- skip handler when exception not raised
6552 -- <<L1>> -- target label for local exception
6566 -- and what we have to do is to dig out the estmts1 and estmts2
6567 -- sequences (which were the original sequences of statements in
6568 -- the exception handlers) and check them.
6570 if Nkind
(Last_Stm
) = N_Label
and then Exception_Junk
(Last_Stm
) then
6575 exit when Nkind
(Stm
) /= N_Block_Statement
;
6576 exit when not Exception_Junk
(Stm
);
6579 exit when Nkind
(Stm
) /= N_Label
;
6580 exit when not Exception_Junk
(Stm
);
6581 Check_Statement_Sequence
6582 (Statements
(Handled_Statement_Sequence
(Next
(Stm
))));
6587 exit when Nkind
(Stm
) /= N_Goto_Statement
;
6588 exit when not Exception_Junk
(Stm
);
6592 -- Don't count pragmas
6594 while Nkind
(Last_Stm
) = N_Pragma
6596 -- Don't count call to SS_Release (can happen after Raise_Exception)
6599 (Nkind
(Last_Stm
) = N_Procedure_Call_Statement
6601 Nkind
(Name
(Last_Stm
)) = N_Identifier
6603 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_SS_Release
))
6605 -- Don't count exception junk
6608 (Nkind_In
(Last_Stm
, N_Goto_Statement
,
6610 N_Object_Declaration
)
6611 and then Exception_Junk
(Last_Stm
))
6612 or else Nkind
(Last_Stm
) in N_Push_xxx_Label
6613 or else Nkind
(Last_Stm
) in N_Pop_xxx_Label
6615 -- Inserted code, such as finalization calls, is irrelevant: we only
6616 -- need to check original source.
6618 or else Is_Rewrite_Insertion
(Last_Stm
)
6623 -- Here we have the "real" last statement
6625 Kind
:= Nkind
(Last_Stm
);
6627 -- Transfer of control, OK. Note that in the No_Return procedure
6628 -- case, we already diagnosed any explicit return statements, so
6629 -- we can treat them as OK in this context.
6631 if Is_Transfer
(Last_Stm
) then
6634 -- Check cases of explicit non-indirect procedure calls
6636 elsif Kind
= N_Procedure_Call_Statement
6637 and then Is_Entity_Name
(Name
(Last_Stm
))
6639 -- Check call to Raise_Exception procedure which is treated
6640 -- specially, as is a call to Reraise_Occurrence.
6642 -- We suppress the warning in these cases since it is likely that
6643 -- the programmer really does not expect to deal with the case
6644 -- of Null_Occurrence, and thus would find a warning about a
6645 -- missing return curious, and raising Program_Error does not
6646 -- seem such a bad behavior if this does occur.
6648 -- Note that in the Ada 2005 case for Raise_Exception, the actual
6649 -- behavior will be to raise Constraint_Error (see AI-329).
6651 if Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Raise_Exception
)
6653 Is_RTE
(Entity
(Name
(Last_Stm
)), RE_Reraise_Occurrence
)
6655 Raise_Exception_Call
:= True;
6657 -- For Raise_Exception call, test first argument, if it is
6658 -- an attribute reference for a 'Identity call, then we know
6659 -- that the call cannot possibly return.
6662 Arg
: constant Node_Id
:=
6663 Original_Node
(First_Actual
(Last_Stm
));
6665 if Nkind
(Arg
) = N_Attribute_Reference
6666 and then Attribute_Name
(Arg
) = Name_Identity
6673 -- If statement, need to look inside if there is an else and check
6674 -- each constituent statement sequence for proper termination.
6676 elsif Kind
= N_If_Statement
6677 and then Present
(Else_Statements
(Last_Stm
))
6679 Check_Statement_Sequence
(Then_Statements
(Last_Stm
));
6680 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6682 if Present
(Elsif_Parts
(Last_Stm
)) then
6684 Elsif_Part
: Node_Id
:= First
(Elsif_Parts
(Last_Stm
));
6687 while Present
(Elsif_Part
) loop
6688 Check_Statement_Sequence
(Then_Statements
(Elsif_Part
));
6696 -- Case statement, check each case for proper termination
6698 elsif Kind
= N_Case_Statement
then
6702 Case_Alt
:= First_Non_Pragma
(Alternatives
(Last_Stm
));
6703 while Present
(Case_Alt
) loop
6704 Check_Statement_Sequence
(Statements
(Case_Alt
));
6705 Next_Non_Pragma
(Case_Alt
);
6711 -- Block statement, check its handled sequence of statements
6713 elsif Kind
= N_Block_Statement
then
6719 (Handled_Statement_Sequence
(Last_Stm
), Mode
, Err1
);
6728 -- Loop statement. If there is an iteration scheme, we can definitely
6729 -- fall out of the loop. Similarly if there is an exit statement, we
6730 -- can fall out. In either case we need a following return.
6732 elsif Kind
= N_Loop_Statement
then
6733 if Present
(Iteration_Scheme
(Last_Stm
))
6734 or else Has_Exit
(Entity
(Identifier
(Last_Stm
)))
6738 -- A loop with no exit statement or iteration scheme is either
6739 -- an infinite loop, or it has some other exit (raise/return).
6740 -- In either case, no warning is required.
6746 -- Timed entry call, check entry call and delay alternatives
6748 -- Note: in expanded code, the timed entry call has been converted
6749 -- to a set of expanded statements on which the check will work
6750 -- correctly in any case.
6752 elsif Kind
= N_Timed_Entry_Call
then
6754 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6755 DCA
: constant Node_Id
:= Delay_Alternative
(Last_Stm
);
6758 -- If statement sequence of entry call alternative is missing,
6759 -- then we can definitely fall through, and we post the error
6760 -- message on the entry call alternative itself.
6762 if No
(Statements
(ECA
)) then
6765 -- If statement sequence of delay alternative is missing, then
6766 -- we can definitely fall through, and we post the error
6767 -- message on the delay alternative itself.
6769 -- Note: if both ECA and DCA are missing the return, then we
6770 -- post only one message, should be enough to fix the bugs.
6771 -- If not we will get a message next time on the DCA when the
6774 elsif No
(Statements
(DCA
)) then
6777 -- Else check both statement sequences
6780 Check_Statement_Sequence
(Statements
(ECA
));
6781 Check_Statement_Sequence
(Statements
(DCA
));
6786 -- Conditional entry call, check entry call and else part
6788 -- Note: in expanded code, the conditional entry call has been
6789 -- converted to a set of expanded statements on which the check
6790 -- will work correctly in any case.
6792 elsif Kind
= N_Conditional_Entry_Call
then
6794 ECA
: constant Node_Id
:= Entry_Call_Alternative
(Last_Stm
);
6797 -- If statement sequence of entry call alternative is missing,
6798 -- then we can definitely fall through, and we post the error
6799 -- message on the entry call alternative itself.
6801 if No
(Statements
(ECA
)) then
6804 -- Else check statement sequence and else part
6807 Check_Statement_Sequence
(Statements
(ECA
));
6808 Check_Statement_Sequence
(Else_Statements
(Last_Stm
));
6814 -- If we fall through, issue appropriate message
6818 -- Kill warning if last statement is a raise exception call,
6819 -- or a pragma Assert (False). Note that with assertions enabled,
6820 -- such a pragma has been converted into a raise exception call
6821 -- already, so the Assert_False is for the assertions off case.
6823 if not Raise_Exception_Call
and then not Assert_False
then
6825 -- In GNATprove mode, it is an error to have a missing return
6827 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6829 -- Issue error message or warning
6832 ("RETURN statement missing following this statement<<!",
6835 ("\Program_Error ]<<!", Last_Stm
);
6838 -- Note: we set Err even though we have not issued a warning
6839 -- because we still have a case of a missing return. This is
6840 -- an extremely marginal case, probably will never be noticed
6841 -- but we might as well get it right.
6845 -- Otherwise we have the case of a procedure marked No_Return
6848 if not Raise_Exception_Call
then
6849 if GNATprove_Mode
then
6851 ("implied return after this statement would have raised "
6852 & "Program_Error", Last_Stm
);
6854 -- In normal compilation mode, do not warn on a generated call
6855 -- (e.g. in the body of a renaming as completion).
6857 elsif Comes_From_Source
(Last_Stm
) then
6859 ("implied return after this statement will raise "
6860 & "Program_Error??", Last_Stm
);
6863 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6865 ("\procedure & is marked as No_Return<<!", Last_Stm
, Proc
);
6869 RE
: constant Node_Id
:=
6870 Make_Raise_Program_Error
(Sloc
(Last_Stm
),
6871 Reason
=> PE_Implicit_Return
);
6873 Insert_After
(Last_Stm
, RE
);
6877 end Check_Statement_Sequence
;
6879 -- Start of processing for Check_Returns
6883 Check_Statement_Sequence
(Statements
(HSS
));
6885 if Present
(Exception_Handlers
(HSS
)) then
6886 Handler
:= First_Non_Pragma
(Exception_Handlers
(HSS
));
6887 while Present
(Handler
) loop
6888 Check_Statement_Sequence
(Statements
(Handler
));
6889 Next_Non_Pragma
(Handler
);
6894 ----------------------------
6895 -- Check_Subprogram_Order --
6896 ----------------------------
6898 procedure Check_Subprogram_Order
(N
: Node_Id
) is
6900 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean;
6901 -- This is used to check if S1 > S2 in the sense required by this test,
6902 -- for example nameab < namec, but name2 < name10.
6904 -----------------------------
6905 -- Subprogram_Name_Greater --
6906 -----------------------------
6908 function Subprogram_Name_Greater
(S1
, S2
: String) return Boolean is
6913 -- Deal with special case where names are identical except for a
6914 -- numerical suffix. These are handled specially, taking the numeric
6915 -- ordering from the suffix into account.
6918 while S1
(L1
) in '0' .. '9' loop
6923 while S2
(L2
) in '0' .. '9' loop
6927 -- If non-numeric parts non-equal, do straight compare
6929 if S1
(S1
'First .. L1
) /= S2
(S2
'First .. L2
) then
6932 -- If non-numeric parts equal, compare suffixed numeric parts. Note
6933 -- that a missing suffix is treated as numeric zero in this test.
6937 while L1
< S1
'Last loop
6939 N1
:= N1
* 10 + Character'Pos (S1
(L1
)) - Character'Pos ('0');
6943 while L2
< S2
'Last loop
6945 N2
:= N2
* 10 + Character'Pos (S2
(L2
)) - Character'Pos ('0');
6950 end Subprogram_Name_Greater
;
6952 -- Start of processing for Check_Subprogram_Order
6955 -- Check body in alpha order if this is option
6958 and then Style_Check_Order_Subprograms
6959 and then Nkind
(N
) = N_Subprogram_Body
6960 and then Comes_From_Source
(N
)
6961 and then In_Extended_Main_Source_Unit
(N
)
6965 renames Scope_Stack
.Table
6966 (Scope_Stack
.Last
).Last_Subprogram_Name
;
6968 Body_Id
: constant Entity_Id
:=
6969 Defining_Entity
(Specification
(N
));
6972 Get_Decoded_Name_String
(Chars
(Body_Id
));
6975 if Subprogram_Name_Greater
6976 (LSN
.all, Name_Buffer
(1 .. Name_Len
))
6978 Style
.Subprogram_Not_In_Alpha_Order
(Body_Id
);
6984 LSN
:= new String'(Name_Buffer (1 .. Name_Len));
6987 end Check_Subprogram_Order;
6989 ------------------------------
6990 -- Check_Subtype_Conformant --
6991 ------------------------------
6993 procedure Check_Subtype_Conformant
6994 (New_Id : Entity_Id;
6996 Err_Loc : Node_Id := Empty;
6997 Skip_Controlling_Formals : Boolean := False;
6998 Get_Inst : Boolean := False)
7001 pragma Warnings (Off, Result);
7004 (New_Id, Old_Id, Subtype_Conformant, True, Result, Err_Loc,
7005 Skip_Controlling_Formals => Skip_Controlling_Formals,
7006 Get_Inst => Get_Inst);
7007 end Check_Subtype_Conformant;
7009 -----------------------------------
7010 -- Check_Synchronized_Overriding --
7011 -----------------------------------
7013 procedure Check_Synchronized_Overriding
7014 (Def_Id : Entity_Id;
7015 Overridden_Subp : out Entity_Id)
7017 Ifaces_List : Elist_Id;
7021 function Matches_Prefixed_View_Profile
7022 (Prim_Params : List_Id;
7023 Iface_Params : List_Id) return Boolean;
7024 -- Determine whether a subprogram's parameter profile Prim_Params
7025 -- matches that of a potentially overridden interface subprogram
7026 -- Iface_Params. Also determine if the type of first parameter of
7027 -- Iface_Params is an implemented interface.
7029 -----------------------------------
7030 -- Matches_Prefixed_View_Profile --
7031 -----------------------------------
7033 function Matches_Prefixed_View_Profile
7034 (Prim_Params : List_Id;
7035 Iface_Params : List_Id) return Boolean
7037 function Is_Implemented
7038 (Ifaces_List : Elist_Id;
7039 Iface : Entity_Id) return Boolean;
7040 -- Determine if Iface is implemented by the current task or
7043 --------------------
7044 -- Is_Implemented --
7045 --------------------
7047 function Is_Implemented
7048 (Ifaces_List : Elist_Id;
7049 Iface : Entity_Id) return Boolean
7051 Iface_Elmt : Elmt_Id;
7054 Iface_Elmt := First_Elmt (Ifaces_List);
7055 while Present (Iface_Elmt) loop
7056 if Node (Iface_Elmt) = Iface then
7060 Next_Elmt (Iface_Elmt);
7068 Iface_Id : Entity_Id;
7069 Iface_Param : Node_Id;
7070 Iface_Typ : Entity_Id;
7071 Prim_Id : Entity_Id;
7072 Prim_Param : Node_Id;
7073 Prim_Typ : Entity_Id;
7075 -- Start of processing for Matches_Prefixed_View_Profile
7078 Iface_Param := First (Iface_Params);
7079 Iface_Typ := Etype (Defining_Identifier (Iface_Param));
7081 if Is_Access_Type (Iface_Typ) then
7082 Iface_Typ := Designated_Type (Iface_Typ);
7085 Prim_Param := First (Prim_Params);
7087 -- The first parameter of the potentially overridden subprogram must
7088 -- be an interface implemented by Prim.
7090 if not Is_Interface (Iface_Typ)
7091 or else not Is_Implemented (Ifaces_List, Iface_Typ)
7096 -- The checks on the object parameters are done, so move on to the
7097 -- rest of the parameters.
7099 if not In_Scope then
7100 Prim_Param := Next (Prim_Param);
7103 Iface_Param := Next (Iface_Param);
7104 while Present (Iface_Param) and then Present (Prim_Param) loop
7105 Iface_Id := Defining_Identifier (Iface_Param);
7106 Iface_Typ := Find_Parameter_Type (Iface_Param);
7108 Prim_Id := Defining_Identifier (Prim_Param);
7109 Prim_Typ := Find_Parameter_Type (Prim_Param);
7111 if Ekind (Iface_Typ) = E_Anonymous_Access_Type
7112 and then Ekind (Prim_Typ) = E_Anonymous_Access_Type
7113 and then Is_Concurrent_Type (Designated_Type (Prim_Typ))
7115 Iface_Typ := Designated_Type (Iface_Typ);
7116 Prim_Typ := Designated_Type (Prim_Typ);
7119 -- Case of multiple interface types inside a parameter profile
7121 -- (Obj_Param : in out Iface; ...; Param : Iface)
7123 -- If the interface type is implemented, then the matching type in
7124 -- the primitive should be the implementing record type.
7126 if Ekind (Iface_Typ) = E_Record_Type
7127 and then Is_Interface (Iface_Typ)
7128 and then Is_Implemented (Ifaces_List, Iface_Typ)
7130 if Prim_Typ /= Typ then
7134 -- The two parameters must be both mode and subtype conformant
7136 elsif Ekind (Iface_Id) /= Ekind (Prim_Id)
7138 Conforming_Types (Iface_Typ, Prim_Typ, Subtype_Conformant)
7147 -- One of the two lists contains more parameters than the other
7149 if Present (Iface_Param) or else Present (Prim_Param) then
7154 end Matches_Prefixed_View_Profile;
7156 -- Start of processing for Check_Synchronized_Overriding
7159 Overridden_Subp := Empty;
7161 -- Def_Id must be an entry or a subprogram. We should skip predefined
7162 -- primitives internally generated by the front end; however at this
7163 -- stage predefined primitives are still not fully decorated. As a
7164 -- minor optimization we skip here internally generated subprograms.
7166 if (Ekind (Def_Id) /= E_Entry
7167 and then Ekind (Def_Id) /= E_Function
7168 and then Ekind (Def_Id) /= E_Procedure)
7169 or else not Comes_From_Source (Def_Id)
7174 -- Search for the concurrent declaration since it contains the list of
7175 -- all implemented interfaces. In this case, the subprogram is declared
7176 -- within the scope of a protected or a task type.
7178 if Present (Scope (Def_Id))
7179 and then Is_Concurrent_Type (Scope (Def_Id))
7180 and then not Is_Generic_Actual_Type (Scope (Def_Id))
7182 Typ := Scope (Def_Id);
7185 -- The enclosing scope is not a synchronized type and the subprogram
7188 elsif No (First_Formal (Def_Id)) then
7191 -- The subprogram has formals and hence it may be a primitive of a
7195 Typ := Etype (First_Formal (Def_Id));
7197 if Is_Access_Type (Typ) then
7198 Typ := Directly_Designated_Type (Typ);
7201 if Is_Concurrent_Type (Typ)
7202 and then not Is_Generic_Actual_Type (Typ)
7206 -- This case occurs when the concurrent type is declared within a
7207 -- generic unit. As a result the corresponding record has been built
7208 -- and used as the type of the first formal, we just have to retrieve
7209 -- the corresponding concurrent type.
7211 elsif Is_Concurrent_Record_Type (Typ)
7212 and then not Is_Class_Wide_Type (Typ)
7213 and then Present (Corresponding_Concurrent_Type (Typ))
7215 Typ := Corresponding_Concurrent_Type (Typ);
7223 -- There is no overriding to check if this is an inherited operation in
7224 -- a type derivation for a generic actual.
7226 Collect_Interfaces (Typ, Ifaces_List);
7228 if Is_Empty_Elmt_List (Ifaces_List) then
7232 -- Determine whether entry or subprogram Def_Id overrides a primitive
7233 -- operation that belongs to one of the interfaces in Ifaces_List.
7236 Candidate : Entity_Id := Empty;
7237 Hom : Entity_Id := Empty;
7238 Subp : Entity_Id := Empty;
7241 -- Traverse the homonym chain, looking for a potentially overridden
7242 -- subprogram that belongs to an implemented interface.
7244 Hom := Current_Entity_In_Scope (Def_Id);
7245 while Present (Hom) loop
7249 or else not Is_Overloadable (Subp)
7250 or else not Is_Primitive (Subp)
7251 or else not Is_Dispatching_Operation (Subp)
7252 or else not Present (Find_Dispatching_Type (Subp))
7253 or else not Is_Interface (Find_Dispatching_Type (Subp))
7257 -- Entries and procedures can override abstract or null interface
7260 elsif Ekind_In (Def_Id, E_Entry, E_Procedure)
7261 and then Ekind (Subp) = E_Procedure
7262 and then Matches_Prefixed_View_Profile
7263 (Parameter_Specifications (Parent (Def_Id)),
7264 Parameter_Specifications (Parent (Subp)))
7268 -- For an overridden subprogram Subp, check whether the mode
7269 -- of its first parameter is correct depending on the kind of
7270 -- synchronized type.
7273 Formal : constant Node_Id := First_Formal (Candidate);
7276 -- In order for an entry or a protected procedure to
7277 -- override, the first parameter of the overridden routine
7278 -- must be of mode "out", "in out", or access-to-variable.
7280 if Ekind_In (Candidate, E_Entry, E_Procedure)
7281 and then Is_Protected_Type (Typ)
7282 and then Ekind (Formal) /= E_In_Out_Parameter
7283 and then Ekind (Formal) /= E_Out_Parameter
7284 and then Nkind (Parameter_Type (Parent (Formal))) /=
7289 -- All other cases are OK since a task entry or routine does
7290 -- not have a restriction on the mode of the first parameter
7291 -- of the overridden interface routine.
7294 Overridden_Subp := Candidate;
7299 -- Functions can override abstract interface functions
7301 elsif Ekind (Def_Id) = E_Function
7302 and then Ekind (Subp) = E_Function
7303 and then Matches_Prefixed_View_Profile
7304 (Parameter_Specifications (Parent (Def_Id)),
7305 Parameter_Specifications (Parent (Subp)))
7306 and then Etype (Def_Id) = Etype (Subp)
7310 -- If an inherited subprogram is implemented by a protected
7311 -- function, then the first parameter of the inherited
7312 -- subprogram shall be of mode in, but not an access-to-
7313 -- variable parameter (RM 9.4(11/9)).
7315 if Present (First_Formal (Subp))
7316 and then Ekind (First_Formal (Subp)) = E_In_Parameter
7318 (not Is_Access_Type (Etype (First_Formal (Subp)))
7320 Is_Access_Constant (Etype (First_Formal (Subp))))
7322 Overridden_Subp := Subp;
7327 Hom := Homonym (Hom);
7330 -- After examining all candidates for overriding, we are left with
7331 -- the best match, which is a mode-incompatible interface routine.
7333 if In_Scope and then Present (Candidate) then
7334 Error_Msg_PT (Def_Id, Candidate);
7337 Overridden_Subp := Candidate;
7340 end Check_Synchronized_Overriding;
7342 ---------------------------
7343 -- Check_Type_Conformant --
7344 ---------------------------
7346 procedure Check_Type_Conformant
7347 (New_Id : Entity_Id;
7349 Err_Loc : Node_Id := Empty)
7352 pragma Warnings (Off, Result);
7355 (New_Id, Old_Id, Type_Conformant, True, Result, Err_Loc);
7356 end Check_Type_Conformant;
7358 ---------------------------
7359 -- Can_Override_Operator --
7360 ---------------------------
7362 function Can_Override_Operator (Subp : Entity_Id) return Boolean is
7366 if Nkind (Subp) /= N_Defining_Operator_Symbol then
7370 Typ := Base_Type (Etype (First_Formal (Subp)));
7372 -- Check explicitly that the operation is a primitive of the type
7374 return Operator_Matches_Spec (Subp, Subp)
7375 and then not Is_Generic_Type (Typ)
7376 and then Scope (Subp) = Scope (Typ)
7377 and then not Is_Class_Wide_Type (Typ);
7379 end Can_Override_Operator;
7381 ----------------------
7382 -- Conforming_Types --
7383 ----------------------
7385 function Conforming_Types
7388 Ctype : Conformance_Type;
7389 Get_Inst : Boolean := False) return Boolean
7391 function Base_Types_Match
7393 Typ_2 : Entity_Id) return Boolean;
7394 -- If neither Typ_1 nor Typ_2 are generic actual types, or if they are
7395 -- in different scopes (e.g. parent and child instances), then verify
7396 -- that the base types are equal. Otherwise Typ_1 and Typ_2 must be on
7397 -- the same subtype chain. The whole purpose of this procedure is to
7398 -- prevent spurious ambiguities in an instantiation that may arise if
7399 -- two distinct generic types are instantiated with the same actual.
7401 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id;
7402 -- An access parameter can designate an incomplete type. If the
7403 -- incomplete type is the limited view of a type from a limited_
7404 -- with_clause, check whether the non-limited view is available.
7405 -- If it is a (non-limited) incomplete type, get the full view.
7407 function Matches_Limited_With_View
7409 Typ_2 : Entity_Id) return Boolean;
7410 -- Returns True if and only if either Typ_1 denotes a limited view of
7411 -- Typ_2 or Typ_2 denotes a limited view of Typ_1. This can arise when
7412 -- the limited with view of a type is used in a subprogram declaration
7413 -- and the subprogram body is in the scope of a regular with clause for
7414 -- the same unit. In such a case, the two type entities are considered
7415 -- identical for purposes of conformance checking.
7417 ----------------------
7418 -- Base_Types_Match --
7419 ----------------------
7421 function Base_Types_Match
7423 Typ_2 : Entity_Id) return Boolean
7425 Base_1 : constant Entity_Id := Base_Type (Typ_1);
7426 Base_2 : constant Entity_Id := Base_Type (Typ_2);
7429 if Typ_1 = Typ_2 then
7432 elsif Base_1 = Base_2 then
7434 -- The following is too permissive. A more precise test should
7435 -- check that the generic actual is an ancestor subtype of the
7438 -- See code in Find_Corresponding_Spec that applies an additional
7439 -- filter to handle accidental amiguities in instances.
7442 not Is_Generic_Actual_Type (Typ_1)
7443 or else not Is_Generic_Actual_Type (Typ_2)
7444 or else Scope (Typ_1) /= Scope (Typ_2);
7446 -- If Typ_2 is a generic actual type it is declared as the subtype of
7447 -- the actual. If that actual is itself a subtype we need to use its
7448 -- own base type to check for compatibility.
7450 elsif Ekind (Base_2) = Ekind (Typ_2)
7451 and then Base_1 = Base_Type (Base_2)
7455 elsif Ekind (Base_1) = Ekind (Typ_1)
7456 and then Base_2 = Base_Type (Base_1)
7463 end Base_Types_Match;
7465 --------------------------
7466 -- Find_Designated_Type --
7467 --------------------------
7469 function Find_Designated_Type (Typ : Entity_Id) return Entity_Id is
7473 Desig := Directly_Designated_Type (Typ);
7475 if Ekind (Desig) = E_Incomplete_Type then
7477 -- If regular incomplete type, get full view if available
7479 if Present (Full_View (Desig)) then
7480 Desig := Full_View (Desig);
7482 -- If limited view of a type, get non-limited view if available,
7483 -- and check again for a regular incomplete type.
7485 elsif Present (Non_Limited_View (Desig)) then
7486 Desig := Get_Full_View (Non_Limited_View (Desig));
7491 end Find_Designated_Type;
7493 -------------------------------
7494 -- Matches_Limited_With_View --
7495 -------------------------------
7497 function Matches_Limited_With_View
7499 Typ_2 : Entity_Id) return Boolean
7501 function Is_Matching_Limited_View
7503 View : Entity_Id) return Boolean;
7504 -- Determine whether non-limited view View denotes type Typ in some
7505 -- conformant fashion.
7507 ------------------------------
7508 -- Is_Matching_Limited_View --
7509 ------------------------------
7511 function Is_Matching_Limited_View
7513 View : Entity_Id) return Boolean
7515 Root_Typ : Entity_Id;
7516 Root_View : Entity_Id;
7519 -- The non-limited view directly denotes the type
7524 -- The type is a subtype of the non-limited view
7526 elsif Is_Subtype_Of (Typ, View) then
7529 -- Both the non-limited view and the type denote class-wide types
7531 elsif Is_Class_Wide_Type (Typ)
7532 and then Is_Class_Wide_Type (View)
7534 Root_Typ := Root_Type (Typ);
7535 Root_View := Root_Type (View);
7537 if Root_Typ = Root_View then
7540 -- An incomplete tagged type and its full view may receive two
7541 -- distinct class-wide types when the related package has not
7542 -- been analyzed yet.
7545 -- type T is tagged; -- CW_1
7546 -- type T is tagged null record; -- CW_2
7549 -- This is because the package lacks any semantic information
7550 -- that may eventually link both views of T. As a consequence,
7551 -- a client of the limited view of Pack will see CW_2 while a
7552 -- client of the non-limited view of Pack will see CW_1.
7554 elsif Is_Incomplete_Type (Root_Typ)
7555 and then Present (Full_View (Root_Typ))
7556 and then Full_View (Root_Typ) = Root_View
7560 elsif Is_Incomplete_Type (Root_View)
7561 and then Present (Full_View (Root_View))
7562 and then Full_View (Root_View) = Root_Typ
7569 end Is_Matching_Limited_View;
7571 -- Start of processing for Matches_Limited_With_View
7574 -- In some cases a type imported through a limited_with clause, and
7575 -- its non-limited view are both visible, for example in an anonymous
7576 -- access-to-class-wide type in a formal, or when building the body
7577 -- for a subprogram renaming after the subprogram has been frozen.
7578 -- In these cases both entities designate the same type. In addition,
7579 -- if one of them is an actual in an instance, it may be a subtype of
7580 -- the non-limited view of the other.
7582 if From_Limited_With (Typ_1)
7583 and then From_Limited_With (Typ_2)
7584 and then Available_View (Typ_1) = Available_View (Typ_2)
7588 elsif From_Limited_With (Typ_1) then
7589 return Is_Matching_Limited_View (Typ_2, Available_View (Typ_1));
7591 elsif From_Limited_With (Typ_2) then
7592 return Is_Matching_Limited_View (Typ_1, Available_View (Typ_2));
7597 end Matches_Limited_With_View;
7601 Are_Anonymous_Access_To_Subprogram_Types : Boolean := False;
7603 Type_1 : Entity_Id := T1;
7604 Type_2 : Entity_Id := T2;
7606 -- Start of processing for Conforming_Types
7609 -- The context is an instance association for a formal access-to-
7610 -- subprogram type; the formal parameter types require mapping because
7611 -- they may denote other formal parameters of the generic unit.
7614 Type_1 := Get_Instance_Of (T1);
7615 Type_2 := Get_Instance_Of (T2);
7618 -- If one of the types is a view of the other introduced by a limited
7619 -- with clause, treat these as conforming for all purposes.
7621 if Matches_Limited_With_View (T1, T2) then
7624 elsif Base_Types_Match (Type_1, Type_2) then
7625 if Ctype <= Mode_Conformant then
7630 Subtypes_Statically_Match (Type_1, Type_2)
7631 and then Dimensions_Match (Type_1, Type_2);
7634 elsif Is_Incomplete_Or_Private_Type (Type_1)
7635 and then Present (Full_View (Type_1))
7636 and then Base_Types_Match (Full_View (Type_1), Type_2)
7639 Ctype <= Mode_Conformant
7640 or else Subtypes_Statically_Match (Full_View (Type_1), Type_2);
7642 elsif Ekind (Type_2) = E_Incomplete_Type
7643 and then Present (Full_View (Type_2))
7644 and then Base_Types_Match (Type_1, Full_View (Type_2))
7647 Ctype <= Mode_Conformant
7648 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7650 elsif Is_Private_Type (Type_2)
7651 and then In_Instance
7652 and then Present (Full_View (Type_2))
7653 and then Base_Types_Match (Type_1, Full_View (Type_2))
7656 Ctype <= Mode_Conformant
7657 or else Subtypes_Statically_Match (Type_1, Full_View (Type_2));
7659 -- Another confusion between views in a nested instance with an
7660 -- actual private type whose full view is not in scope.
7662 elsif Ekind (Type_2) = E_Private_Subtype
7663 and then In_Instance
7664 and then Etype (Type_2) = Type_1
7668 -- In Ada 2012, incomplete types (including limited views) can appear
7669 -- as actuals in instantiations, where they are conformant to the
7670 -- corresponding incomplete formal.
7672 elsif Is_Incomplete_Type (Type_1)
7673 and then Is_Incomplete_Type (Type_2)
7674 and then In_Instance
7675 and then (Used_As_Generic_Actual (Type_1)
7676 or else Used_As_Generic_Actual (Type_2))
7681 -- Ada 2005 (AI-254): Anonymous access-to-subprogram types must be
7682 -- treated recursively because they carry a signature. As far as
7683 -- conformance is concerned, convention plays no role, and either
7684 -- or both could be access to protected subprograms.
7686 Are_Anonymous_Access_To_Subprogram_Types :=
7687 Ekind_In (Type_1, E_Anonymous_Access_Subprogram_Type,
7688 E_Anonymous_Access_Protected_Subprogram_Type)
7690 Ekind_In (Type_2, E_Anonymous_Access_Subprogram_Type,
7691 E_Anonymous_Access_Protected_Subprogram_Type);
7693 -- Test anonymous access type case. For this case, static subtype
7694 -- matching is required for mode conformance (RM 6.3.1(15)). We check
7695 -- the base types because we may have built internal subtype entities
7696 -- to handle null-excluding types (see Process_Formals).
7698 if (Ekind (Base_Type (Type_1)) = E_Anonymous_Access_Type
7700 Ekind (Base_Type (Type_2)) = E_Anonymous_Access_Type)
7702 -- Ada 2005 (AI-254)
7704 or else Are_Anonymous_Access_To_Subprogram_Types
7707 Desig_1 : Entity_Id;
7708 Desig_2 : Entity_Id;
7711 -- In Ada 2005, access constant indicators must match for
7712 -- subtype conformance.
7714 if Ada_Version >= Ada_2005
7715 and then Ctype >= Subtype_Conformant
7717 Is_Access_Constant (Type_1) /= Is_Access_Constant (Type_2)
7722 Desig_1 := Find_Designated_Type (Type_1);
7723 Desig_2 := Find_Designated_Type (Type_2);
7725 -- If the context is an instance association for a formal
7726 -- access-to-subprogram type; formal access parameter designated
7727 -- types require mapping because they may denote other formal
7728 -- parameters of the generic unit.
7731 Desig_1 := Get_Instance_Of (Desig_1);
7732 Desig_2 := Get_Instance_Of (Desig_2);
7735 -- It is possible for a Class_Wide_Type to be introduced for an
7736 -- incomplete type, in which case there is a separate class_ wide
7737 -- type for the full view. The types conform if their Etypes
7738 -- conform, i.e. one may be the full view of the other. This can
7739 -- only happen in the context of an access parameter, other uses
7740 -- of an incomplete Class_Wide_Type are illegal.
7742 if Is_Class_Wide_Type (Desig_1)
7744 Is_Class_Wide_Type (Desig_2)
7748 (Etype (Base_Type (Desig_1)),
7749 Etype (Base_Type (Desig_2)), Ctype);
7751 elsif Are_Anonymous_Access_To_Subprogram_Types then
7752 if Ada_Version < Ada_2005 then
7754 Ctype = Type_Conformant
7755 or else Subtypes_Statically_Match (Desig_1, Desig_2);
7757 -- We must check the conformance of the signatures themselves
7761 Conformant : Boolean;
7764 (Desig_1, Desig_2, Ctype, False, Conformant);
7769 -- A limited view of an actual matches the corresponding
7770 -- incomplete formal.
7772 elsif Ekind (Desig_2) = E_Incomplete_Subtype
7773 and then From_Limited_With (Desig_2)
7774 and then Used_As_Generic_Actual (Etype (Desig_2))
7779 return Base_Type (Desig_1) = Base_Type (Desig_2)
7780 and then (Ctype = Type_Conformant
7782 Subtypes_Statically_Match (Desig_1, Desig_2));
7786 -- Otherwise definitely no match
7789 if ((Ekind (Type_1) = E_Anonymous_Access_Type
7790 and then Is_Access_Type (Type_2))
7791 or else (Ekind (Type_2) = E_Anonymous_Access_Type
7792 and then Is_Access_Type (Type_1)))
7795 (Designated_Type (Type_1), Designated_Type (Type_2), Ctype)
7797 May_Hide_Profile := True;
7802 end Conforming_Types;
7804 --------------------------
7805 -- Create_Extra_Formals --
7806 --------------------------
7808 procedure Create_Extra_Formals (E : Entity_Id) is
7809 First_Extra : Entity_Id := Empty;
7811 Last_Extra : Entity_Id := Empty;
7813 function Add_Extra_Formal
7814 (Assoc_Entity : Entity_Id;
7817 Suffix : String) return Entity_Id;
7818 -- Add an extra formal to the current list of formals and extra formals.
7819 -- The extra formal is added to the end of the list of extra formals,
7820 -- and also returned as the result. These formals are always of mode IN.
7821 -- The new formal has the type Typ, is declared in Scope, and its name
7822 -- is given by a concatenation of the name of Assoc_Entity and Suffix.
7823 -- The following suffixes are currently used. They should not be changed
7824 -- without coordinating with CodePeer, which makes use of these to
7825 -- provide better messages.
7827 -- O denotes the Constrained bit.
7828 -- L denotes the accessibility level.
7829 -- BIP_xxx denotes an extra formal for a build-in-place function. See
7830 -- the full list in exp_ch6.BIP_Formal_Kind.
7832 ----------------------
7833 -- Add_Extra_Formal --
7834 ----------------------
7836 function Add_Extra_Formal
7837 (Assoc_Entity : Entity_Id;
7840 Suffix : String) return Entity_Id
7842 EF : constant Entity_Id :=
7843 Make_Defining_Identifier (Sloc (Assoc_Entity),
7844 Chars => New_External_Name (Chars (Assoc_Entity),
7848 -- A little optimization. Never generate an extra formal for the
7849 -- _init operand of an initialization procedure, since it could
7852 if Chars (Formal) = Name_uInit then
7856 Set_Ekind (EF, E_In_Parameter);
7857 Set_Actual_Subtype (EF, Typ);
7858 Set_Etype (EF, Typ);
7859 Set_Scope (EF, Scope);
7860 Set_Mechanism (EF, Default_Mechanism);
7861 Set_Formal_Validity (EF);
7863 if No (First_Extra) then
7865 Set_Extra_Formals (Scope, EF);
7868 if Present (Last_Extra) then
7869 Set_Extra_Formal (Last_Extra, EF);
7875 end Add_Extra_Formal;
7879 Formal_Type : Entity_Id;
7880 P_Formal : Entity_Id := Empty;
7882 -- Start of processing for Create_Extra_Formals
7885 -- We never generate extra formals if expansion is not active because we
7886 -- don't need them unless we are generating code.
7888 if not Expander_Active then
7892 -- No need to generate extra formals in interface thunks whose target
7893 -- primitive has no extra formals.
7895 if Is_Thunk (E) and then No (Extra_Formals (Thunk_Entity (E))) then
7899 -- If this is a derived subprogram then the subtypes of the parent
7900 -- subprogram's formal parameters will be used to determine the need
7901 -- for extra formals.
7903 if Is_Overloadable (E) and then Present (Alias (E)) then
7904 P_Formal := First_Formal (Alias (E));
7907 Formal := First_Formal (E);
7908 while Present (Formal) loop
7909 Last_Extra := Formal;
7910 Next_Formal (Formal);
7913 -- If Extra_Formals were already created, don't do it again. This
7914 -- situation may arise for subprogram types created as part of
7915 -- dispatching calls (see Expand_Dispatching_Call).
7917 if Present (Last_Extra) and then Present (Extra_Formal (Last_Extra)) then
7921 -- If the subprogram is a predefined dispatching subprogram then don't
7922 -- generate any extra constrained or accessibility level formals. In
7923 -- general we suppress these for internal subprograms (by not calling
7924 -- Freeze_Subprogram and Create_Extra_Formals at all), but internally
7925 -- generated stream attributes do get passed through because extra
7926 -- build-in-place formals are needed in some cases (limited 'Input
).
7928 if Is_Predefined_Internal_Operation
(E
) then
7929 goto Test_For_Func_Result_Extras
;
7932 Formal
:= First_Formal
(E
);
7933 while Present
(Formal
) loop
7935 -- Create extra formal for supporting the attribute 'Constrained.
7936 -- The case of a private type view without discriminants also
7937 -- requires the extra formal if the underlying type has defaulted
7940 if Ekind
(Formal
) /= E_In_Parameter
then
7941 if Present
(P_Formal
) then
7942 Formal_Type
:= Etype
(P_Formal
);
7944 Formal_Type
:= Etype
(Formal
);
7947 -- Do not produce extra formals for Unchecked_Union parameters.
7948 -- Jump directly to the end of the loop.
7950 if Is_Unchecked_Union
(Base_Type
(Formal_Type
)) then
7951 goto Skip_Extra_Formal_Generation
;
7954 if not Has_Discriminants
(Formal_Type
)
7955 and then Ekind
(Formal_Type
) in Private_Kind
7956 and then Present
(Underlying_Type
(Formal_Type
))
7958 Formal_Type
:= Underlying_Type
(Formal_Type
);
7961 -- Suppress the extra formal if formal's subtype is constrained or
7962 -- indefinite, or we're compiling for Ada 2012 and the underlying
7963 -- type is tagged and limited. In Ada 2012, a limited tagged type
7964 -- can have defaulted discriminants, but 'Constrained is required
7965 -- to return True, so the formal is never needed (see AI05-0214).
7966 -- Note that this ensures consistency of calling sequences for
7967 -- dispatching operations when some types in a class have defaults
7968 -- on discriminants and others do not (and requiring the extra
7969 -- formal would introduce distributed overhead).
7971 -- If the type does not have a completion yet, treat as prior to
7972 -- Ada 2012 for consistency.
7974 if Has_Discriminants
(Formal_Type
)
7975 and then not Is_Constrained
(Formal_Type
)
7976 and then Is_Definite_Subtype
(Formal_Type
)
7977 and then (Ada_Version
< Ada_2012
7978 or else No
(Underlying_Type
(Formal_Type
))
7980 (Is_Limited_Type
(Formal_Type
)
7983 (Underlying_Type
(Formal_Type
)))))
7985 Set_Extra_Constrained
7986 (Formal
, Add_Extra_Formal
(Formal
, Standard_Boolean
, E
, "O"));
7990 -- Create extra formal for supporting accessibility checking. This
7991 -- is done for both anonymous access formals and formals of named
7992 -- access types that are marked as controlling formals. The latter
7993 -- case can occur when Expand_Dispatching_Call creates a subprogram
7994 -- type and substitutes the types of access-to-class-wide actuals
7995 -- for the anonymous access-to-specific-type of controlling formals.
7996 -- Base_Type is applied because in cases where there is a null
7997 -- exclusion the formal may have an access subtype.
7999 -- This is suppressed if we specifically suppress accessibility
8000 -- checks at the package level for either the subprogram, or the
8001 -- package in which it resides. However, we do not suppress it
8002 -- simply if the scope has accessibility checks suppressed, since
8003 -- this could cause trouble when clients are compiled with a
8004 -- different suppression setting. The explicit checks at the
8005 -- package level are safe from this point of view.
8007 if (Ekind
(Base_Type
(Etype
(Formal
))) = E_Anonymous_Access_Type
8008 or else (Is_Controlling_Formal
(Formal
)
8009 and then Is_Access_Type
(Base_Type
(Etype
(Formal
)))))
8011 (Explicit_Suppress
(E
, Accessibility_Check
)
8013 Explicit_Suppress
(Scope
(E
), Accessibility_Check
))
8016 or else Present
(Extra_Accessibility
(P_Formal
)))
8018 Set_Extra_Accessibility
8019 (Formal
, Add_Extra_Formal
(Formal
, Standard_Natural
, E
, "L"));
8022 -- This label is required when skipping extra formal generation for
8023 -- Unchecked_Union parameters.
8025 <<Skip_Extra_Formal_Generation
>>
8027 if Present
(P_Formal
) then
8028 Next_Formal
(P_Formal
);
8031 Next_Formal
(Formal
);
8034 <<Test_For_Func_Result_Extras
>>
8036 -- Ada 2012 (AI05-234): "the accessibility level of the result of a
8037 -- function call is ... determined by the point of call ...".
8039 if Needs_Result_Accessibility_Level
(E
) then
8040 Set_Extra_Accessibility_Of_Result
8041 (E
, Add_Extra_Formal
(E
, Standard_Natural
, E
, "L"));
8044 -- Ada 2005 (AI-318-02): In the case of build-in-place functions, add
8045 -- appropriate extra formals. See type Exp_Ch6.BIP_Formal_Kind.
8047 if Is_Build_In_Place_Function
(E
) then
8049 Result_Subt
: constant Entity_Id
:= Etype
(E
);
8050 Full_Subt
: constant Entity_Id
:= Available_View
(Result_Subt
);
8051 Formal_Typ
: Entity_Id
;
8052 Subp_Decl
: Node_Id
;
8053 Discard
: Entity_Id
;
8056 -- In the case of functions with unconstrained result subtypes,
8057 -- add a 4-state formal indicating whether the return object is
8058 -- allocated by the caller (1), or should be allocated by the
8059 -- callee on the secondary stack (2), in the global heap (3), or
8060 -- in a user-defined storage pool (4). For the moment we just use
8061 -- Natural for the type of this formal. Note that this formal
8062 -- isn't usually needed in the case where the result subtype is
8063 -- constrained, but it is needed when the function has a tagged
8064 -- result, because generally such functions can be called in a
8065 -- dispatching context and such calls must be handled like calls
8066 -- to a class-wide function.
8068 if Needs_BIP_Alloc_Form
(E
) then
8071 (E
, Standard_Natural
,
8072 E
, BIP_Formal_Suffix
(BIP_Alloc_Form
));
8074 -- Add BIP_Storage_Pool, in case BIP_Alloc_Form indicates to
8075 -- use a user-defined pool. This formal is not added on
8076 -- ZFP as those targets do not support pools.
8078 if RTE_Available
(RE_Root_Storage_Pool_Ptr
) then
8081 (E
, RTE
(RE_Root_Storage_Pool_Ptr
),
8082 E
, BIP_Formal_Suffix
(BIP_Storage_Pool
));
8086 -- In the case of functions whose result type needs finalization,
8087 -- add an extra formal which represents the finalization master.
8089 if Needs_BIP_Finalization_Master
(E
) then
8092 (E
, RTE
(RE_Finalization_Master_Ptr
),
8093 E
, BIP_Formal_Suffix
(BIP_Finalization_Master
));
8096 -- When the result type contains tasks, add two extra formals: the
8097 -- master of the tasks to be created, and the caller's activation
8100 if Has_Task
(Full_Subt
) then
8103 (E
, RTE
(RE_Master_Id
),
8104 E
, BIP_Formal_Suffix
(BIP_Task_Master
));
8107 (E
, RTE
(RE_Activation_Chain_Access
),
8108 E
, BIP_Formal_Suffix
(BIP_Activation_Chain
));
8111 -- All build-in-place functions get an extra formal that will be
8112 -- passed the address of the return object within the caller.
8115 Create_Itype
(E_Anonymous_Access_Type
, E
, Scope_Id
=> Scope
(E
));
8117 -- Incomplete_View_From_Limited_With is needed here because
8118 -- gigi gets confused if the designated type is the full view
8119 -- coming from a limited-with'ed package. In the normal case,
8120 -- (no limited with) Incomplete_View_From_Limited_With
8121 -- returns Result_Subt.
8123 Set_Directly_Designated_Type
8124 (Formal_Typ
, Incomplete_View_From_Limited_With
(Result_Subt
));
8125 Set_Etype
(Formal_Typ
, Formal_Typ
);
8126 Set_Depends_On_Private
8127 (Formal_Typ
, Has_Private_Component
(Formal_Typ
));
8128 Set_Is_Public
(Formal_Typ
, Is_Public
(Scope
(Formal_Typ
)));
8129 Set_Is_Access_Constant
(Formal_Typ
, False);
8131 -- Ada 2005 (AI-50217): Propagate the attribute that indicates
8132 -- the designated type comes from the limited view (for back-end
8135 Set_From_Limited_With
8136 (Formal_Typ
, From_Limited_With
(Result_Subt
));
8138 Layout_Type
(Formal_Typ
);
8140 -- Force the definition of the Itype in case of internal function
8141 -- calls within the same or nested scope.
8143 if Is_Subprogram_Or_Generic_Subprogram
(E
) then
8144 Subp_Decl
:= Parent
(E
);
8146 -- The insertion point for an Itype reference should be after
8147 -- the unit declaration node of the subprogram. An exception
8148 -- to this are inherited operations from a parent type in which
8149 -- case the derived type acts as their parent.
8151 if Nkind_In
(Subp_Decl
, N_Function_Specification
,
8152 N_Procedure_Specification
)
8154 Subp_Decl
:= Parent
(Subp_Decl
);
8157 Build_Itype_Reference
(Formal_Typ
, Subp_Decl
);
8162 (E
, Formal_Typ
, E
, BIP_Formal_Suffix
(BIP_Object_Access
));
8166 -- If this is an instance of a generic, we need to have extra formals
8169 if Is_Generic_Instance
(E
) and then Present
(Alias
(E
)) then
8170 Set_Extra_Formals
(Alias
(E
), Extra_Formals
(E
));
8172 end Create_Extra_Formals
;
8174 -----------------------------
8175 -- Enter_Overloaded_Entity --
8176 -----------------------------
8178 procedure Enter_Overloaded_Entity
(S
: Entity_Id
) is
8179 function Matches_Predefined_Op
return Boolean;
8180 -- This returns an approximation of whether S matches a predefined
8181 -- operator, based on the operator symbol, and the parameter and result
8182 -- types. The rules are scattered throughout chapter 4 of the Ada RM.
8184 ---------------------------
8185 -- Matches_Predefined_Op --
8186 ---------------------------
8188 function Matches_Predefined_Op
return Boolean is
8189 Formal_1
: constant Entity_Id
:= First_Formal
(S
);
8190 Formal_2
: constant Entity_Id
:= Next_Formal
(Formal_1
);
8191 Op
: constant Name_Id
:= Chars
(S
);
8192 Result_Type
: constant Entity_Id
:= Base_Type
(Etype
(S
));
8193 Type_1
: constant Entity_Id
:= Base_Type
(Etype
(Formal_1
));
8198 if Present
(Formal_2
) then
8200 Type_2
: constant Entity_Id
:= Base_Type
(Etype
(Formal_2
));
8203 -- All but "&" and "**" have same-types parameters
8212 if Type_1
/= Type_2
then
8217 -- Check parameter and result types
8225 Is_Boolean_Type
(Result_Type
)
8226 and then Result_Type
= Type_1
;
8232 Is_Integer_Type
(Result_Type
)
8233 and then Result_Type
= Type_1
;
8241 Is_Numeric_Type
(Result_Type
)
8242 and then Result_Type
= Type_1
;
8248 Is_Boolean_Type
(Result_Type
)
8249 and then not Is_Limited_Type
(Type_1
);
8257 Is_Boolean_Type
(Result_Type
)
8258 and then (Is_Array_Type
(Type_1
)
8259 or else Is_Scalar_Type
(Type_1
));
8261 when Name_Op_Concat
=>
8262 return Is_Array_Type
(Result_Type
);
8264 when Name_Op_Expon
=>
8266 (Is_Integer_Type
(Result_Type
)
8267 or else Is_Floating_Point_Type
(Result_Type
))
8268 and then Result_Type
= Type_1
8269 and then Type_2
= Standard_Integer
;
8272 raise Program_Error
;
8285 Is_Numeric_Type
(Result_Type
)
8286 and then Result_Type
= Type_1
;
8290 Is_Boolean_Type
(Result_Type
)
8291 and then Result_Type
= Type_1
;
8294 raise Program_Error
;
8297 end Matches_Predefined_Op
;
8301 E
: Entity_Id
:= Current_Entity_In_Scope
(S
);
8302 C_E
: Entity_Id
:= Current_Entity
(S
);
8304 -- Start of processing for Enter_Overloaded_Entity
8308 Set_Has_Homonym
(E
);
8309 Set_Has_Homonym
(S
);
8312 Set_Is_Immediately_Visible
(S
);
8313 Set_Scope
(S
, Current_Scope
);
8315 -- Chain new entity if front of homonym in current scope, so that
8316 -- homonyms are contiguous.
8318 if Present
(E
) and then E
/= C_E
then
8319 while Homonym
(C_E
) /= E
loop
8320 C_E
:= Homonym
(C_E
);
8323 Set_Homonym
(C_E
, S
);
8327 Set_Current_Entity
(S
);
8332 if Is_Inherited_Operation
(S
) then
8333 Append_Inherited_Subprogram
(S
);
8335 Append_Entity
(S
, Current_Scope
);
8338 Set_Public_Status
(S
);
8340 if Debug_Flag_E
then
8341 Write_Str
("New overloaded entity chain: ");
8342 Write_Name
(Chars
(S
));
8345 while Present
(E
) loop
8346 Write_Str
(" "); Write_Int
(Int
(E
));
8353 -- Generate warning for hiding
8356 and then Comes_From_Source
(S
)
8357 and then In_Extended_Main_Source_Unit
(S
)
8364 -- Warn unless genuine overloading. Do not emit warning on
8365 -- hiding predefined operators in Standard (these are either an
8366 -- (artifact of our implicit declarations, or simple noise) but
8367 -- keep warning on a operator defined on a local subtype, because
8368 -- of the real danger that different operators may be applied in
8369 -- various parts of the program.
8371 -- Note that if E and S have the same scope, there is never any
8372 -- hiding. Either the two conflict, and the program is illegal,
8373 -- or S is overriding an implicit inherited subprogram.
8375 if Scope
(E
) /= Scope
(S
)
8376 and then (not Is_Overloadable
(E
)
8377 or else Subtype_Conformant
(E
, S
))
8378 and then (Is_Immediately_Visible
(E
)
8379 or else Is_Potentially_Use_Visible
(S
))
8381 if Scope
(E
) = Standard_Standard
then
8382 if Nkind
(S
) = N_Defining_Operator_Symbol
8383 and then Scope
(Base_Type
(Etype
(First_Formal
(S
)))) /=
8385 and then Matches_Predefined_Op
8388 ("declaration of & hides predefined operator?h?", S
);
8391 -- E not immediately within Standard
8394 Error_Msg_Sloc
:= Sloc
(E
);
8395 Error_Msg_N
("declaration of & hides one #?h?", S
);
8400 end Enter_Overloaded_Entity
;
8402 -----------------------------
8403 -- Check_Untagged_Equality --
8404 -----------------------------
8406 procedure Check_Untagged_Equality
(Eq_Op
: Entity_Id
) is
8407 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Eq_Op
));
8408 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Eq_Op
);
8412 -- This check applies only if we have a subprogram declaration with an
8413 -- untagged record type.
8415 if Nkind
(Decl
) /= N_Subprogram_Declaration
8416 or else not Is_Record_Type
(Typ
)
8417 or else Is_Tagged_Type
(Typ
)
8422 -- In Ada 2012 case, we will output errors or warnings depending on
8423 -- the setting of debug flag -gnatd.E.
8425 if Ada_Version
>= Ada_2012
then
8426 Error_Msg_Warn
:= Debug_Flag_Dot_EE
;
8428 -- In earlier versions of Ada, nothing to do unless we are warning on
8429 -- Ada 2012 incompatibilities (Warn_On_Ada_2012_Incompatibility set).
8432 if not Warn_On_Ada_2012_Compatibility
then
8437 -- Cases where the type has already been frozen
8439 if Is_Frozen
(Typ
) then
8441 -- If the type is not declared in a package, or if we are in the body
8442 -- of the package or in some other scope, the new operation is not
8443 -- primitive, and therefore legal, though suspicious. Should we
8444 -- generate a warning in this case ???
8446 if Ekind
(Scope
(Typ
)) /= E_Package
8447 or else Scope
(Typ
) /= Current_Scope
8451 -- If the type is a generic actual (sub)type, the operation is not
8452 -- primitive either because the base type is declared elsewhere.
8454 elsif Is_Generic_Actual_Type
(Typ
) then
8457 -- Here we have a definite error of declaration after freezing
8460 if Ada_Version
>= Ada_2012
then
8462 ("equality operator must be declared before type & is "
8463 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)<<", Eq_Op
, Typ
);
8465 -- In Ada 2012 mode with error turned to warning, output one
8466 -- more warning to warn that the equality operation may not
8467 -- compose. This is the consequence of ignoring the error.
8469 if Error_Msg_Warn
then
8470 Error_Msg_N
("\equality operation may not compose??", Eq_Op
);
8475 ("equality operator must be declared before type& is "
8476 & "frozen (RM 4.5.2 (9.8)) (Ada 2012)?y?", Eq_Op
, Typ
);
8479 -- If we are in the package body, we could just move the
8480 -- declaration to the package spec, so add a message saying that.
8482 if In_Package_Body
(Scope
(Typ
)) then
8483 if Ada_Version
>= Ada_2012
then
8485 ("\move declaration to package spec<<", Eq_Op
);
8488 ("\move declaration to package spec (Ada 2012)?y?", Eq_Op
);
8491 -- Otherwise try to find the freezing point
8494 Obj_Decl
:= Next
(Parent
(Typ
));
8495 while Present
(Obj_Decl
) and then Obj_Decl
/= Decl
loop
8496 if Nkind
(Obj_Decl
) = N_Object_Declaration
8497 and then Etype
(Defining_Identifier
(Obj_Decl
)) = Typ
8499 -- Freezing point, output warnings
8501 if Ada_Version
>= Ada_2012
then
8503 ("type& is frozen by declaration??", Obj_Decl
, Typ
);
8505 ("\an equality operator cannot be declared after "
8510 ("type& is frozen by declaration (Ada 2012)?y?",
8513 ("\an equality operator cannot be declared after "
8514 & "this point (Ada 2012)?y?",
8526 -- Here if type is not frozen yet. It is illegal to have a primitive
8527 -- equality declared in the private part if the type is visible.
8529 elsif not In_Same_List
(Parent
(Typ
), Decl
)
8530 and then not Is_Limited_Type
(Typ
)
8532 -- Shouldn't we give an RM reference here???
8534 if Ada_Version
>= Ada_2012
then
8536 ("equality operator appears too late<<", Eq_Op
);
8539 ("equality operator appears too late (Ada 2012)?y?", Eq_Op
);
8542 -- No error detected
8547 end Check_Untagged_Equality
;
8549 -----------------------------
8550 -- Find_Corresponding_Spec --
8551 -----------------------------
8553 function Find_Corresponding_Spec
8555 Post_Error
: Boolean := True) return Entity_Id
8557 Spec
: constant Node_Id
:= Specification
(N
);
8558 Designator
: constant Entity_Id
:= Defining_Entity
(Spec
);
8562 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean;
8563 -- Even if fully conformant, a body may depend on a generic actual when
8564 -- the spec does not, or vice versa, in which case they were distinct
8565 -- entities in the generic.
8567 -------------------------------
8568 -- Different_Generic_Profile --
8569 -------------------------------
8571 function Different_Generic_Profile
(E
: Entity_Id
) return Boolean is
8574 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean;
8575 -- Check that the types of corresponding formals have the same
8576 -- generic actual if any. We have to account for subtypes of a
8577 -- generic formal, declared between a spec and a body, which may
8578 -- appear distinct in an instance but matched in the generic, and
8579 -- the subtype may be used either in the spec or the body of the
8580 -- subprogram being checked.
8582 -------------------------
8583 -- Same_Generic_Actual --
8584 -------------------------
8586 function Same_Generic_Actual
(T1
, T2
: Entity_Id
) return Boolean is
8588 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean;
8589 -- Predicate to check whether S1 is a subtype of S2 in the source
8592 -------------------------
8593 -- Is_Declared_Subtype --
8594 -------------------------
8596 function Is_Declared_Subtype
(S1
, S2
: Entity_Id
) return Boolean is
8598 return Comes_From_Source
(Parent
(S1
))
8599 and then Nkind
(Parent
(S1
)) = N_Subtype_Declaration
8600 and then Is_Entity_Name
(Subtype_Indication
(Parent
(S1
)))
8601 and then Entity
(Subtype_Indication
(Parent
(S1
))) = S2
;
8602 end Is_Declared_Subtype
;
8604 -- Start of processing for Same_Generic_Actual
8607 return Is_Generic_Actual_Type
(T1
) = Is_Generic_Actual_Type
(T2
)
8608 or else Is_Declared_Subtype
(T1
, T2
)
8609 or else Is_Declared_Subtype
(T2
, T1
);
8610 end Same_Generic_Actual
;
8612 -- Start of processing for Different_Generic_Profile
8615 if not In_Instance
then
8618 elsif Ekind
(E
) = E_Function
8619 and then not Same_Generic_Actual
(Etype
(E
), Etype
(Designator
))
8624 F1
:= First_Formal
(Designator
);
8625 F2
:= First_Formal
(E
);
8626 while Present
(F1
) loop
8627 if not Same_Generic_Actual
(Etype
(F1
), Etype
(F2
)) then
8636 end Different_Generic_Profile
;
8638 -- Start of processing for Find_Corresponding_Spec
8641 E
:= Current_Entity
(Designator
);
8642 while Present
(E
) loop
8644 -- We are looking for a matching spec. It must have the same scope,
8645 -- and the same name, and either be type conformant, or be the case
8646 -- of a library procedure spec and its body (which belong to one
8647 -- another regardless of whether they are type conformant or not).
8649 if Scope
(E
) = Current_Scope
then
8650 if Current_Scope
= Standard_Standard
8651 or else (Ekind
(E
) = Ekind
(Designator
)
8652 and then Type_Conformant
(E
, Designator
))
8654 -- Within an instantiation, we know that spec and body are
8655 -- subtype conformant, because they were subtype conformant in
8656 -- the generic. We choose the subtype-conformant entity here as
8657 -- well, to resolve spurious ambiguities in the instance that
8658 -- were not present in the generic (i.e. when two different
8659 -- types are given the same actual). If we are looking for a
8660 -- spec to match a body, full conformance is expected.
8664 -- Inherit the convention and "ghostness" of the matching
8665 -- spec to ensure proper full and subtype conformance.
8667 Set_Convention
(Designator
, Convention
(E
));
8669 -- Skip past subprogram bodies and subprogram renamings that
8670 -- may appear to have a matching spec, but that aren't fully
8671 -- conformant with it. That can occur in cases where an
8672 -- actual type causes unrelated homographs in the instance.
8674 if Nkind_In
(N
, N_Subprogram_Body
,
8675 N_Subprogram_Renaming_Declaration
)
8676 and then Present
(Homonym
(E
))
8677 and then not Fully_Conformant
(Designator
, E
)
8681 elsif not Subtype_Conformant
(Designator
, E
) then
8684 elsif Different_Generic_Profile
(E
) then
8689 -- Ada 2012 (AI05-0165): For internally generated bodies of
8690 -- null procedures locate the internally generated spec. We
8691 -- enforce mode conformance since a tagged type may inherit
8692 -- from interfaces several null primitives which differ only
8693 -- in the mode of the formals.
8695 if not (Comes_From_Source
(E
))
8696 and then Is_Null_Procedure
(E
)
8697 and then not Mode_Conformant
(Designator
, E
)
8701 -- For null procedures coming from source that are completions,
8702 -- analysis of the generated body will establish the link.
8704 elsif Comes_From_Source
(E
)
8705 and then Nkind
(Spec
) = N_Procedure_Specification
8706 and then Null_Present
(Spec
)
8710 -- Expression functions can be completions, but cannot be
8711 -- completed by an explicit body.
8713 elsif Comes_From_Source
(E
)
8714 and then Comes_From_Source
(N
)
8715 and then Nkind
(N
) = N_Subprogram_Body
8716 and then Nkind
(Original_Node
(Unit_Declaration_Node
(E
))) =
8717 N_Expression_Function
8719 Error_Msg_Sloc
:= Sloc
(E
);
8720 Error_Msg_N
("body conflicts with expression function#", N
);
8723 elsif not Has_Completion
(E
) then
8724 if Nkind
(N
) /= N_Subprogram_Body_Stub
then
8725 Set_Corresponding_Spec
(N
, E
);
8728 Set_Has_Completion
(E
);
8731 elsif Nkind
(Parent
(N
)) = N_Subunit
then
8733 -- If this is the proper body of a subunit, the completion
8734 -- flag is set when analyzing the stub.
8738 -- If E is an internal function with a controlling result that
8739 -- was created for an operation inherited by a null extension,
8740 -- it may be overridden by a body without a previous spec (one
8741 -- more reason why these should be shunned). In that case we
8742 -- remove the generated body if present, because the current
8743 -- one is the explicit overriding.
8745 elsif Ekind
(E
) = E_Function
8746 and then Ada_Version
>= Ada_2005
8747 and then not Comes_From_Source
(E
)
8748 and then Has_Controlling_Result
(E
)
8749 and then Is_Null_Extension
(Etype
(E
))
8750 and then Comes_From_Source
(Spec
)
8752 Set_Has_Completion
(E
, False);
8755 and then Nkind
(Parent
(E
)) = N_Function_Specification
8758 (Unit_Declaration_Node
8759 (Corresponding_Body
(Unit_Declaration_Node
(E
))));
8763 -- If expansion is disabled, or if the wrapper function has
8764 -- not been generated yet, this a late body overriding an
8765 -- inherited operation, or it is an overriding by some other
8766 -- declaration before the controlling result is frozen. In
8767 -- either case this is a declaration of a new entity.
8773 -- If the body already exists, then this is an error unless
8774 -- the previous declaration is the implicit declaration of a
8775 -- derived subprogram. It is also legal for an instance to
8776 -- contain type conformant overloadable declarations (but the
8777 -- generic declaration may not), per 8.3(26/2).
8779 elsif No
(Alias
(E
))
8780 and then not Is_Intrinsic_Subprogram
(E
)
8781 and then not In_Instance
8784 Error_Msg_Sloc
:= Sloc
(E
);
8786 if Is_Imported
(E
) then
8788 ("body not allowed for imported subprogram & declared#",
8791 Error_Msg_NE
("duplicate body for & declared#", N
, E
);
8795 -- Child units cannot be overloaded, so a conformance mismatch
8796 -- between body and a previous spec is an error.
8798 elsif Is_Child_Unit
(E
)
8800 Nkind
(Unit_Declaration_Node
(Designator
)) = N_Subprogram_Body
8802 Nkind
(Parent
(Unit_Declaration_Node
(Designator
))) =
8807 ("body of child unit does not match previous declaration", N
);
8815 -- On exit, we know that no previous declaration of subprogram exists
8818 end Find_Corresponding_Spec
;
8820 ----------------------
8821 -- Fully_Conformant --
8822 ----------------------
8824 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
8827 Check_Conformance
(New_Id
, Old_Id
, Fully_Conformant
, False, Result
);
8829 end Fully_Conformant
;
8831 ----------------------------------
8832 -- Fully_Conformant_Expressions --
8833 ----------------------------------
8835 function Fully_Conformant_Expressions
8836 (Given_E1
: Node_Id
;
8837 Given_E2
: Node_Id
) return Boolean
8839 E1
: constant Node_Id
:= Original_Node
(Given_E1
);
8840 E2
: constant Node_Id
:= Original_Node
(Given_E2
);
8841 -- We always test conformance on original nodes, since it is possible
8842 -- for analysis and/or expansion to make things look as though they
8843 -- conform when they do not, e.g. by converting 1+2 into 3.
8845 function FCE
(Given_E1
, Given_E2
: Node_Id
) return Boolean
8846 renames Fully_Conformant_Expressions
;
8848 function FCL
(L1
, L2
: List_Id
) return Boolean;
8849 -- Compare elements of two lists for conformance. Elements have to be
8850 -- conformant, and actuals inserted as default parameters do not match
8851 -- explicit actuals with the same value.
8853 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean;
8854 -- Compare an operator node with a function call
8860 function FCL
(L1
, L2
: List_Id
) return Boolean is
8864 if L1
= No_List
then
8870 if L2
= No_List
then
8876 -- Compare two lists, skipping rewrite insertions (we want to compare
8877 -- the original trees, not the expanded versions).
8880 if Is_Rewrite_Insertion
(N1
) then
8882 elsif Is_Rewrite_Insertion
(N2
) then
8888 elsif not FCE
(N1
, N2
) then
8901 function FCO
(Op_Node
, Call_Node
: Node_Id
) return Boolean is
8902 Actuals
: constant List_Id
:= Parameter_Associations
(Call_Node
);
8907 or else Entity
(Op_Node
) /= Entity
(Name
(Call_Node
))
8912 Act
:= First
(Actuals
);
8914 if Nkind
(Op_Node
) in N_Binary_Op
then
8915 if not FCE
(Left_Opnd
(Op_Node
), Act
) then
8922 return Present
(Act
)
8923 and then FCE
(Right_Opnd
(Op_Node
), Act
)
8924 and then No
(Next
(Act
));
8928 -- Start of processing for Fully_Conformant_Expressions
8931 -- Nonconformant if paren count does not match. Note: if some idiot
8932 -- complains that we don't do this right for more than 3 levels of
8933 -- parentheses, they will be treated with the respect they deserve.
8935 if Paren_Count
(E1
) /= Paren_Count
(E2
) then
8938 -- If same entities are referenced, then they are conformant even if
8939 -- they have different forms (RM 8.3.1(19-20)).
8941 elsif Is_Entity_Name
(E1
) and then Is_Entity_Name
(E2
) then
8942 if Present
(Entity
(E1
)) then
8943 return Entity
(E1
) = Entity
(E2
)
8945 -- One may be a discriminant that has been replaced by the
8946 -- corresponding discriminal.
8949 (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
8950 and then Ekind
(Entity
(E1
)) = E_Discriminant
8951 and then Ekind
(Entity
(E2
)) = E_In_Parameter
)
8953 -- The discriminant of a protected type is transformed into
8954 -- a local constant and then into a parameter of a protected
8958 (Ekind
(Entity
(E1
)) = E_Constant
8959 and then Ekind
(Entity
(E2
)) = E_In_Parameter
8960 and then Present
(Discriminal_Link
(Entity
(E1
)))
8961 and then Discriminal_Link
(Entity
(E1
)) =
8962 Discriminal_Link
(Entity
(E2
)))
8964 -- AI12-050: The loop variables of quantified expressions
8965 -- match if they have the same identifier, even though they
8966 -- are different entities.
8969 (Chars
(Entity
(E1
)) = Chars
(Entity
(E2
))
8970 and then Ekind
(Entity
(E1
)) = E_Loop_Parameter
8971 and then Ekind
(Entity
(E2
)) = E_Loop_Parameter
);
8973 elsif Nkind
(E1
) = N_Expanded_Name
8974 and then Nkind
(E2
) = N_Expanded_Name
8975 and then Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8976 and then Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8978 return Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
));
8981 -- Identifiers in component associations don't always have
8982 -- entities, but their names must conform.
8984 return Nkind
(E1
) = N_Identifier
8985 and then Nkind
(E2
) = N_Identifier
8986 and then Chars
(E1
) = Chars
(E2
);
8989 elsif Nkind
(E1
) = N_Character_Literal
8990 and then Nkind
(E2
) = N_Expanded_Name
8992 return Nkind
(Selector_Name
(E2
)) = N_Character_Literal
8993 and then Chars
(E1
) = Chars
(Selector_Name
(E2
));
8995 elsif Nkind
(E2
) = N_Character_Literal
8996 and then Nkind
(E1
) = N_Expanded_Name
8998 return Nkind
(Selector_Name
(E1
)) = N_Character_Literal
8999 and then Chars
(E2
) = Chars
(Selector_Name
(E1
));
9001 elsif Nkind
(E1
) in N_Op
and then Nkind
(E2
) = N_Function_Call
then
9002 return FCO
(E1
, E2
);
9004 elsif Nkind
(E2
) in N_Op
and then Nkind
(E1
) = N_Function_Call
then
9005 return FCO
(E2
, E1
);
9007 -- Otherwise we must have the same syntactic entity
9009 elsif Nkind
(E1
) /= Nkind
(E2
) then
9012 -- At this point, we specialize by node type
9018 FCL
(Expressions
(E1
), Expressions
(E2
))
9020 FCL
(Component_Associations
(E1
),
9021 Component_Associations
(E2
));
9024 if Nkind
(Expression
(E1
)) = N_Qualified_Expression
9026 Nkind
(Expression
(E2
)) = N_Qualified_Expression
9028 return FCE
(Expression
(E1
), Expression
(E2
));
9030 -- Check that the subtype marks and any constraints
9035 Indic1
: constant Node_Id
:= Expression
(E1
);
9036 Indic2
: constant Node_Id
:= Expression
(E2
);
9041 if Nkind
(Indic1
) /= N_Subtype_Indication
then
9043 Nkind
(Indic2
) /= N_Subtype_Indication
9044 and then Entity
(Indic1
) = Entity
(Indic2
);
9046 elsif Nkind
(Indic2
) /= N_Subtype_Indication
then
9048 Nkind
(Indic1
) /= N_Subtype_Indication
9049 and then Entity
(Indic1
) = Entity
(Indic2
);
9052 if Entity
(Subtype_Mark
(Indic1
)) /=
9053 Entity
(Subtype_Mark
(Indic2
))
9058 Elt1
:= First
(Constraints
(Constraint
(Indic1
)));
9059 Elt2
:= First
(Constraints
(Constraint
(Indic2
)));
9060 while Present
(Elt1
) and then Present
(Elt2
) loop
9061 if not FCE
(Elt1
, Elt2
) then
9074 when N_Attribute_Reference
=>
9076 Attribute_Name
(E1
) = Attribute_Name
(E2
)
9077 and then FCL
(Expressions
(E1
), Expressions
(E2
));
9081 Entity
(E1
) = Entity
(E2
)
9082 and then FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
9083 and then FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
9085 when N_Membership_Test
9089 FCE
(Left_Opnd
(E1
), Left_Opnd
(E2
))
9091 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
9093 when N_Case_Expression
=>
9099 if not FCE
(Expression
(E1
), Expression
(E2
)) then
9103 Alt1
:= First
(Alternatives
(E1
));
9104 Alt2
:= First
(Alternatives
(E2
));
9106 if Present
(Alt1
) /= Present
(Alt2
) then
9108 elsif No
(Alt1
) then
9112 if not FCE
(Expression
(Alt1
), Expression
(Alt2
))
9113 or else not FCL
(Discrete_Choices
(Alt1
),
9114 Discrete_Choices
(Alt2
))
9125 when N_Character_Literal
=>
9127 Char_Literal_Value
(E1
) = Char_Literal_Value
(E2
);
9129 when N_Component_Association
=>
9131 FCL
(Choices
(E1
), Choices
(E2
))
9133 FCE
(Expression
(E1
), Expression
(E2
));
9135 when N_Explicit_Dereference
=>
9137 FCE
(Prefix
(E1
), Prefix
(E2
));
9139 when N_Extension_Aggregate
=>
9141 FCL
(Expressions
(E1
), Expressions
(E2
))
9142 and then Null_Record_Present
(E1
) =
9143 Null_Record_Present
(E2
)
9144 and then FCL
(Component_Associations
(E1
),
9145 Component_Associations
(E2
));
9147 when N_Function_Call
=>
9149 FCE
(Name
(E1
), Name
(E2
))
9151 FCL
(Parameter_Associations
(E1
),
9152 Parameter_Associations
(E2
));
9154 when N_If_Expression
=>
9156 FCL
(Expressions
(E1
), Expressions
(E2
));
9158 when N_Indexed_Component
=>
9160 FCE
(Prefix
(E1
), Prefix
(E2
))
9162 FCL
(Expressions
(E1
), Expressions
(E2
));
9164 when N_Integer_Literal
=>
9165 return (Intval
(E1
) = Intval
(E2
));
9170 when N_Operator_Symbol
=>
9172 Chars
(E1
) = Chars
(E2
);
9174 when N_Others_Choice
=>
9177 when N_Parameter_Association
=>
9179 Chars
(Selector_Name
(E1
)) = Chars
(Selector_Name
(E2
))
9180 and then FCE
(Explicit_Actual_Parameter
(E1
),
9181 Explicit_Actual_Parameter
(E2
));
9183 when N_Qualified_Expression
9185 | N_Unchecked_Type_Conversion
9188 FCE
(Subtype_Mark
(E1
), Subtype_Mark
(E2
))
9190 FCE
(Expression
(E1
), Expression
(E2
));
9192 when N_Quantified_Expression
=>
9193 if not FCE
(Condition
(E1
), Condition
(E2
)) then
9197 if Present
(Loop_Parameter_Specification
(E1
))
9198 and then Present
(Loop_Parameter_Specification
(E2
))
9201 L1
: constant Node_Id
:=
9202 Loop_Parameter_Specification
(E1
);
9203 L2
: constant Node_Id
:=
9204 Loop_Parameter_Specification
(E2
);
9208 Reverse_Present
(L1
) = Reverse_Present
(L2
)
9210 FCE
(Defining_Identifier
(L1
),
9211 Defining_Identifier
(L2
))
9213 FCE
(Discrete_Subtype_Definition
(L1
),
9214 Discrete_Subtype_Definition
(L2
));
9217 elsif Present
(Iterator_Specification
(E1
))
9218 and then Present
(Iterator_Specification
(E2
))
9221 I1
: constant Node_Id
:= Iterator_Specification
(E1
);
9222 I2
: constant Node_Id
:= Iterator_Specification
(E2
);
9226 FCE
(Defining_Identifier
(I1
),
9227 Defining_Identifier
(I2
))
9229 Of_Present
(I1
) = Of_Present
(I2
)
9231 Reverse_Present
(I1
) = Reverse_Present
(I2
)
9232 and then FCE
(Name
(I1
), Name
(I2
))
9233 and then FCE
(Subtype_Indication
(I1
),
9234 Subtype_Indication
(I2
));
9237 -- The quantified expressions used different specifications to
9238 -- walk their respective ranges.
9246 FCE
(Low_Bound
(E1
), Low_Bound
(E2
))
9248 FCE
(High_Bound
(E1
), High_Bound
(E2
));
9250 when N_Real_Literal
=>
9251 return (Realval
(E1
) = Realval
(E2
));
9253 when N_Selected_Component
=>
9255 FCE
(Prefix
(E1
), Prefix
(E2
))
9257 FCE
(Selector_Name
(E1
), Selector_Name
(E2
));
9261 FCE
(Prefix
(E1
), Prefix
(E2
))
9263 FCE
(Discrete_Range
(E1
), Discrete_Range
(E2
));
9265 when N_String_Literal
=>
9267 S1
: constant String_Id
:= Strval
(E1
);
9268 S2
: constant String_Id
:= Strval
(E2
);
9269 L1
: constant Nat
:= String_Length
(S1
);
9270 L2
: constant Nat
:= String_Length
(S2
);
9277 for J
in 1 .. L1
loop
9278 if Get_String_Char
(S1
, J
) /=
9279 Get_String_Char
(S2
, J
)
9291 Entity
(E1
) = Entity
(E2
)
9293 FCE
(Right_Opnd
(E1
), Right_Opnd
(E2
));
9295 -- All other node types cannot appear in this context. Strictly
9296 -- we should raise a fatal internal error. Instead we just ignore
9297 -- the nodes. This means that if anyone makes a mistake in the
9298 -- expander and mucks an expression tree irretrievably, the result
9299 -- will be a failure to detect a (probably very obscure) case
9300 -- of non-conformance, which is better than bombing on some
9301 -- case where two expressions do in fact conform.
9307 end Fully_Conformant_Expressions
;
9309 ----------------------------------------
9310 -- Fully_Conformant_Discrete_Subtypes --
9311 ----------------------------------------
9313 function Fully_Conformant_Discrete_Subtypes
9314 (Given_S1
: Node_Id
;
9315 Given_S2
: Node_Id
) return Boolean
9317 S1
: constant Node_Id
:= Original_Node
(Given_S1
);
9318 S2
: constant Node_Id
:= Original_Node
(Given_S2
);
9320 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean;
9321 -- Special-case for a bound given by a discriminant, which in the body
9322 -- is replaced with the discriminal of the enclosing type.
9324 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean;
9325 -- Check both bounds
9327 -----------------------
9328 -- Conforming_Bounds --
9329 -----------------------
9331 function Conforming_Bounds
(B1
, B2
: Node_Id
) return Boolean is
9333 if Is_Entity_Name
(B1
)
9334 and then Is_Entity_Name
(B2
)
9335 and then Ekind
(Entity
(B1
)) = E_Discriminant
9337 return Chars
(B1
) = Chars
(B2
);
9340 return Fully_Conformant_Expressions
(B1
, B2
);
9342 end Conforming_Bounds
;
9344 -----------------------
9345 -- Conforming_Ranges --
9346 -----------------------
9348 function Conforming_Ranges
(R1
, R2
: Node_Id
) return Boolean is
9351 Conforming_Bounds
(Low_Bound
(R1
), Low_Bound
(R2
))
9353 Conforming_Bounds
(High_Bound
(R1
), High_Bound
(R2
));
9354 end Conforming_Ranges
;
9356 -- Start of processing for Fully_Conformant_Discrete_Subtypes
9359 if Nkind
(S1
) /= Nkind
(S2
) then
9362 elsif Is_Entity_Name
(S1
) then
9363 return Entity
(S1
) = Entity
(S2
);
9365 elsif Nkind
(S1
) = N_Range
then
9366 return Conforming_Ranges
(S1
, S2
);
9368 elsif Nkind
(S1
) = N_Subtype_Indication
then
9370 Entity
(Subtype_Mark
(S1
)) = Entity
(Subtype_Mark
(S2
))
9373 (Range_Expression
(Constraint
(S1
)),
9374 Range_Expression
(Constraint
(S2
)));
9378 end Fully_Conformant_Discrete_Subtypes
;
9380 --------------------
9381 -- Install_Entity --
9382 --------------------
9384 procedure Install_Entity
(E
: Entity_Id
) is
9385 Prev
: constant Entity_Id
:= Current_Entity
(E
);
9387 Set_Is_Immediately_Visible
(E
);
9388 Set_Current_Entity
(E
);
9389 Set_Homonym
(E
, Prev
);
9392 ---------------------
9393 -- Install_Formals --
9394 ---------------------
9396 procedure Install_Formals
(Id
: Entity_Id
) is
9399 F
:= First_Formal
(Id
);
9400 while Present
(F
) loop
9404 end Install_Formals
;
9406 -----------------------------
9407 -- Is_Interface_Conformant --
9408 -----------------------------
9410 function Is_Interface_Conformant
9411 (Tagged_Type
: Entity_Id
;
9412 Iface_Prim
: Entity_Id
;
9413 Prim
: Entity_Id
) return Boolean
9415 -- The operation may in fact be an inherited (implicit) operation
9416 -- rather than the original interface primitive, so retrieve the
9417 -- ultimate ancestor.
9419 Iface
: constant Entity_Id
:=
9420 Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
));
9421 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
9423 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
;
9424 -- Return the controlling formal of Prim
9426 ------------------------
9427 -- Controlling_Formal --
9428 ------------------------
9430 function Controlling_Formal
(Prim
: Entity_Id
) return Entity_Id
is
9434 E
:= First_Entity
(Prim
);
9435 while Present
(E
) loop
9436 if Is_Formal
(E
) and then Is_Controlling_Formal
(E
) then
9444 end Controlling_Formal
;
9448 Iface_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Iface_Prim
);
9449 Prim_Ctrl_F
: constant Entity_Id
:= Controlling_Formal
(Prim
);
9451 -- Start of processing for Is_Interface_Conformant
9454 pragma Assert
(Is_Subprogram
(Iface_Prim
)
9455 and then Is_Subprogram
(Prim
)
9456 and then Is_Dispatching_Operation
(Iface_Prim
)
9457 and then Is_Dispatching_Operation
(Prim
));
9459 pragma Assert
(Is_Interface
(Iface
)
9460 or else (Present
(Alias
(Iface_Prim
))
9463 (Find_Dispatching_Type
(Ultimate_Alias
(Iface_Prim
)))));
9465 if Prim
= Iface_Prim
9466 or else not Is_Subprogram
(Prim
)
9467 or else Ekind
(Prim
) /= Ekind
(Iface_Prim
)
9468 or else not Is_Dispatching_Operation
(Prim
)
9469 or else Scope
(Prim
) /= Scope
(Tagged_Type
)
9471 or else Base_Type
(Typ
) /= Base_Type
(Tagged_Type
)
9472 or else not Primitive_Names_Match
(Iface_Prim
, Prim
)
9476 -- The mode of the controlling formals must match
9478 elsif Present
(Iface_Ctrl_F
)
9479 and then Present
(Prim_Ctrl_F
)
9480 and then Ekind
(Iface_Ctrl_F
) /= Ekind
(Prim_Ctrl_F
)
9484 -- Case of a procedure, or a function whose result type matches the
9485 -- result type of the interface primitive, or a function that has no
9486 -- controlling result (I or access I).
9488 elsif Ekind
(Iface_Prim
) = E_Procedure
9489 or else Etype
(Prim
) = Etype
(Iface_Prim
)
9490 or else not Has_Controlling_Result
(Prim
)
9492 return Type_Conformant
9493 (Iface_Prim
, Prim
, Skip_Controlling_Formals
=> True);
9495 -- Case of a function returning an interface, or an access to one. Check
9496 -- that the return types correspond.
9498 elsif Implements_Interface
(Typ
, Iface
) then
9499 if (Ekind
(Etype
(Prim
)) = E_Anonymous_Access_Type
)
9501 (Ekind
(Etype
(Iface_Prim
)) = E_Anonymous_Access_Type
)
9506 Type_Conformant
(Prim
, Ultimate_Alias
(Iface_Prim
),
9507 Skip_Controlling_Formals
=> True);
9513 end Is_Interface_Conformant
;
9515 ---------------------------------
9516 -- Is_Non_Overriding_Operation --
9517 ---------------------------------
9519 function Is_Non_Overriding_Operation
9520 (Prev_E
: Entity_Id
;
9521 New_E
: Entity_Id
) return Boolean
9525 G_Typ
: Entity_Id
:= Empty
;
9527 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
;
9528 -- If F_Type is a derived type associated with a generic actual subtype,
9529 -- then return its Generic_Parent_Type attribute, else return Empty.
9531 function Types_Correspond
9532 (P_Type
: Entity_Id
;
9533 N_Type
: Entity_Id
) return Boolean;
9534 -- Returns true if and only if the types (or designated types in the
9535 -- case of anonymous access types) are the same or N_Type is derived
9536 -- directly or indirectly from P_Type.
9538 -----------------------------
9539 -- Get_Generic_Parent_Type --
9540 -----------------------------
9542 function Get_Generic_Parent_Type
(F_Typ
: Entity_Id
) return Entity_Id
is
9548 if Is_Derived_Type
(F_Typ
)
9549 and then Nkind
(Parent
(F_Typ
)) = N_Full_Type_Declaration
9551 -- The tree must be traversed to determine the parent subtype in
9552 -- the generic unit, which unfortunately isn't always available
9553 -- via semantic attributes. ??? (Note: The use of Original_Node
9554 -- is needed for cases where a full derived type has been
9557 -- If the parent type is a scalar type, the derivation creates
9558 -- an anonymous base type for it, and the source type is its
9561 if Is_Scalar_Type
(F_Typ
)
9562 and then not Comes_From_Source
(F_Typ
)
9566 (Original_Node
(Parent
(First_Subtype
(F_Typ
))));
9568 Defn
:= Type_Definition
(Original_Node
(Parent
(F_Typ
)));
9570 if Nkind
(Defn
) = N_Derived_Type_Definition
then
9571 Indic
:= Subtype_Indication
(Defn
);
9573 if Nkind
(Indic
) = N_Subtype_Indication
then
9574 G_Typ
:= Entity
(Subtype_Mark
(Indic
));
9576 G_Typ
:= Entity
(Indic
);
9579 if Nkind
(Parent
(G_Typ
)) = N_Subtype_Declaration
9580 and then Present
(Generic_Parent_Type
(Parent
(G_Typ
)))
9582 return Generic_Parent_Type
(Parent
(G_Typ
));
9588 end Get_Generic_Parent_Type
;
9590 ----------------------
9591 -- Types_Correspond --
9592 ----------------------
9594 function Types_Correspond
9595 (P_Type
: Entity_Id
;
9596 N_Type
: Entity_Id
) return Boolean
9598 Prev_Type
: Entity_Id
:= Base_Type
(P_Type
);
9599 New_Type
: Entity_Id
:= Base_Type
(N_Type
);
9602 if Ekind
(Prev_Type
) = E_Anonymous_Access_Type
then
9603 Prev_Type
:= Designated_Type
(Prev_Type
);
9606 if Ekind
(New_Type
) = E_Anonymous_Access_Type
then
9607 New_Type
:= Designated_Type
(New_Type
);
9610 if Prev_Type
= New_Type
then
9613 elsif not Is_Class_Wide_Type
(New_Type
) then
9614 while Etype
(New_Type
) /= New_Type
loop
9615 New_Type
:= Etype
(New_Type
);
9617 if New_Type
= Prev_Type
then
9623 end Types_Correspond
;
9625 -- Start of processing for Is_Non_Overriding_Operation
9628 -- In the case where both operations are implicit derived subprograms
9629 -- then neither overrides the other. This can only occur in certain
9630 -- obscure cases (e.g., derivation from homographs created in a generic
9633 if Present
(Alias
(Prev_E
)) and then Present
(Alias
(New_E
)) then
9636 elsif Ekind
(Current_Scope
) = E_Package
9637 and then Is_Generic_Instance
(Current_Scope
)
9638 and then In_Private_Part
(Current_Scope
)
9639 and then Comes_From_Source
(New_E
)
9641 -- We examine the formals and result type of the inherited operation,
9642 -- to determine whether their type is derived from (the instance of)
9643 -- a generic type. The first such formal or result type is the one
9646 Formal
:= First_Formal
(Prev_E
);
9648 while Present
(Formal
) loop
9649 F_Typ
:= Base_Type
(Etype
(Formal
));
9651 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
9652 F_Typ
:= Designated_Type
(F_Typ
);
9655 G_Typ
:= Get_Generic_Parent_Type
(F_Typ
);
9656 exit when Present
(G_Typ
);
9658 Next_Formal
(Formal
);
9661 -- If the function dispatches on result check the result type
9663 if No
(G_Typ
) and then Ekind
(Prev_E
) = E_Function
then
9664 G_Typ
:= Get_Generic_Parent_Type
(Base_Type
(Etype
(Prev_E
)));
9671 -- If the generic type is a private type, then the original operation
9672 -- was not overriding in the generic, because there was no primitive
9673 -- operation to override.
9675 if Nkind
(Parent
(G_Typ
)) = N_Formal_Type_Declaration
9676 and then Nkind
(Formal_Type_Definition
(Parent
(G_Typ
))) =
9677 N_Formal_Private_Type_Definition
9681 -- The generic parent type is the ancestor of a formal derived
9682 -- type declaration. We need to check whether it has a primitive
9683 -- operation that should be overridden by New_E in the generic.
9687 P_Formal
: Entity_Id
;
9688 N_Formal
: Entity_Id
;
9692 Prim_Elt
: Elmt_Id
:= First_Elmt
(Primitive_Operations
(G_Typ
));
9695 while Present
(Prim_Elt
) loop
9696 P_Prim
:= Node
(Prim_Elt
);
9698 if Chars
(P_Prim
) = Chars
(New_E
)
9699 and then Ekind
(P_Prim
) = Ekind
(New_E
)
9701 P_Formal
:= First_Formal
(P_Prim
);
9702 N_Formal
:= First_Formal
(New_E
);
9703 while Present
(P_Formal
) and then Present
(N_Formal
) loop
9704 P_Typ
:= Etype
(P_Formal
);
9705 N_Typ
:= Etype
(N_Formal
);
9707 if not Types_Correspond
(P_Typ
, N_Typ
) then
9711 Next_Entity
(P_Formal
);
9712 Next_Entity
(N_Formal
);
9715 -- Found a matching primitive operation belonging to the
9716 -- formal ancestor type, so the new subprogram is
9720 and then No
(N_Formal
)
9721 and then (Ekind
(New_E
) /= E_Function
9724 (Etype
(P_Prim
), Etype
(New_E
)))
9730 Next_Elmt
(Prim_Elt
);
9733 -- If no match found, then the new subprogram does not override
9734 -- in the generic (nor in the instance).
9736 -- If the type in question is not abstract, and the subprogram
9737 -- is, this will be an error if the new operation is in the
9738 -- private part of the instance. Emit a warning now, which will
9739 -- make the subsequent error message easier to understand.
9741 if Present
(F_Typ
) and then not Is_Abstract_Type
(F_Typ
)
9742 and then Is_Abstract_Subprogram
(Prev_E
)
9743 and then In_Private_Part
(Current_Scope
)
9745 Error_Msg_Node_2
:= F_Typ
;
9747 ("private operation& in generic unit does not override "
9748 & "any primitive operation of& (RM 12.3 (18))??",
9758 end Is_Non_Overriding_Operation
;
9760 -------------------------------------
9761 -- List_Inherited_Pre_Post_Aspects --
9762 -------------------------------------
9764 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
) is
9766 if Opt
.List_Inherited_Aspects
9767 and then Is_Subprogram_Or_Generic_Subprogram
(E
)
9770 Subps
: constant Subprogram_List
:= Inherited_Subprograms
(E
);
9775 for Index
in Subps
'Range loop
9776 Items
:= Contract
(Subps
(Index
));
9778 if Present
(Items
) then
9779 Prag
:= Pre_Post_Conditions
(Items
);
9780 while Present
(Prag
) loop
9781 Error_Msg_Sloc
:= Sloc
(Prag
);
9783 if Class_Present
(Prag
)
9784 and then not Split_PPC
(Prag
)
9786 if Pragma_Name
(Prag
) = Name_Precondition
then
9788 ("info: & inherits `Pre''Class` aspect from "
9792 ("info: & inherits `Post''Class` aspect from "
9797 Prag
:= Next_Pragma
(Prag
);
9803 end List_Inherited_Pre_Post_Aspects
;
9805 ------------------------------
9806 -- Make_Inequality_Operator --
9807 ------------------------------
9809 -- S is the defining identifier of an equality operator. We build a
9810 -- subprogram declaration with the right signature. This operation is
9811 -- intrinsic, because it is always expanded as the negation of the
9812 -- call to the equality function.
9814 procedure Make_Inequality_Operator
(S
: Entity_Id
) is
9815 Loc
: constant Source_Ptr
:= Sloc
(S
);
9818 Op_Name
: Entity_Id
;
9820 FF
: constant Entity_Id
:= First_Formal
(S
);
9821 NF
: constant Entity_Id
:= Next_Formal
(FF
);
9824 -- Check that equality was properly defined, ignore call if not
9831 A
: constant Entity_Id
:=
9832 Make_Defining_Identifier
(Sloc
(FF
),
9833 Chars
=> Chars
(FF
));
9835 B
: constant Entity_Id
:=
9836 Make_Defining_Identifier
(Sloc
(NF
),
9837 Chars
=> Chars
(NF
));
9840 Op_Name
:= Make_Defining_Operator_Symbol
(Loc
, Name_Op_Ne
);
9842 Formals
:= New_List
(
9843 Make_Parameter_Specification
(Loc
,
9844 Defining_Identifier
=> A
,
9846 New_Occurrence_Of
(Etype
(First_Formal
(S
)),
9847 Sloc
(Etype
(First_Formal
(S
))))),
9849 Make_Parameter_Specification
(Loc
,
9850 Defining_Identifier
=> B
,
9852 New_Occurrence_Of
(Etype
(Next_Formal
(First_Formal
(S
))),
9853 Sloc
(Etype
(Next_Formal
(First_Formal
(S
)))))));
9856 Make_Subprogram_Declaration
(Loc
,
9858 Make_Function_Specification
(Loc
,
9859 Defining_Unit_Name
=> Op_Name
,
9860 Parameter_Specifications
=> Formals
,
9861 Result_Definition
=>
9862 New_Occurrence_Of
(Standard_Boolean
, Loc
)));
9864 -- Insert inequality right after equality if it is explicit or after
9865 -- the derived type when implicit. These entities are created only
9866 -- for visibility purposes, and eventually replaced in the course
9867 -- of expansion, so they do not need to be attached to the tree and
9868 -- seen by the back-end. Keeping them internal also avoids spurious
9869 -- freezing problems. The declaration is inserted in the tree for
9870 -- analysis, and removed afterwards. If the equality operator comes
9871 -- from an explicit declaration, attach the inequality immediately
9872 -- after. Else the equality is inherited from a derived type
9873 -- declaration, so insert inequality after that declaration.
9875 if No
(Alias
(S
)) then
9876 Insert_After
(Unit_Declaration_Node
(S
), Decl
);
9877 elsif Is_List_Member
(Parent
(S
)) then
9878 Insert_After
(Parent
(S
), Decl
);
9880 Insert_After
(Parent
(Etype
(First_Formal
(S
))), Decl
);
9883 Mark_Rewrite_Insertion
(Decl
);
9884 Set_Is_Intrinsic_Subprogram
(Op_Name
);
9887 Set_Has_Completion
(Op_Name
);
9888 Set_Corresponding_Equality
(Op_Name
, S
);
9889 Set_Is_Abstract_Subprogram
(Op_Name
, Is_Abstract_Subprogram
(S
));
9891 end Make_Inequality_Operator
;
9893 ----------------------
9894 -- May_Need_Actuals --
9895 ----------------------
9897 procedure May_Need_Actuals
(Fun
: Entity_Id
) is
9902 F
:= First_Formal
(Fun
);
9904 while Present
(F
) loop
9905 if No
(Default_Value
(F
)) then
9913 Set_Needs_No_Actuals
(Fun
, B
);
9914 end May_Need_Actuals
;
9916 ---------------------
9917 -- Mode_Conformant --
9918 ---------------------
9920 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean is
9923 Check_Conformance
(New_Id
, Old_Id
, Mode_Conformant
, False, Result
);
9925 end Mode_Conformant
;
9927 ---------------------------
9928 -- New_Overloaded_Entity --
9929 ---------------------------
9931 procedure New_Overloaded_Entity
9933 Derived_Type
: Entity_Id
:= Empty
)
9935 Overridden_Subp
: Entity_Id
:= Empty
;
9936 -- Set if the current scope has an operation that is type-conformant
9937 -- with S, and becomes hidden by S.
9939 Is_Primitive_Subp
: Boolean;
9940 -- Set to True if the new subprogram is primitive
9943 -- Entity that S overrides
9945 Prev_Vis
: Entity_Id
:= Empty
;
9946 -- Predecessor of E in Homonym chain
9948 procedure Check_For_Primitive_Subprogram
9949 (Is_Primitive
: out Boolean;
9950 Is_Overriding
: Boolean := False);
9951 -- If the subprogram being analyzed is a primitive operation of the type
9952 -- of a formal or result, set the Has_Primitive_Operations flag on the
9953 -- type, and set Is_Primitive to True (otherwise set to False). Set the
9954 -- corresponding flag on the entity itself for later use.
9956 function Has_Matching_Entry_Or_Subprogram
(E
: Entity_Id
) return Boolean;
9957 -- True if a) E is a subprogram whose first formal is a concurrent type
9958 -- defined in the scope of E that has some entry or subprogram whose
9959 -- profile matches E, or b) E is an internally built dispatching
9960 -- subprogram of a protected type and there is a matching subprogram
9961 -- defined in the enclosing scope of the protected type, or c) E is
9962 -- an entry of a synchronized type and a matching procedure has been
9963 -- previously defined in the enclosing scope of the synchronized type.
9965 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean;
9966 -- Check that E is declared in the private part of the current package,
9967 -- or in the package body, where it may hide a previous declaration.
9968 -- We can't use In_Private_Part by itself because this flag is also
9969 -- set when freezing entities, so we must examine the place of the
9970 -- declaration in the tree, and recognize wrapper packages as well.
9972 function Is_Overriding_Alias
9974 New_E
: Entity_Id
) return Boolean;
9975 -- Check whether new subprogram and old subprogram are both inherited
9976 -- from subprograms that have distinct dispatch table entries. This can
9977 -- occur with derivations from instances with accidental homonyms. The
9978 -- function is conservative given that the converse is only true within
9979 -- instances that contain accidental overloadings.
9981 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
);
9982 -- Report conflict between entities S and E
9984 ------------------------------------
9985 -- Check_For_Primitive_Subprogram --
9986 ------------------------------------
9988 procedure Check_For_Primitive_Subprogram
9989 (Is_Primitive
: out Boolean;
9990 Is_Overriding
: Boolean := False)
9996 function Visible_Part_Type
(T
: Entity_Id
) return Boolean;
9997 -- Returns true if T is declared in the visible part of the current
9998 -- package scope; otherwise returns false. Assumes that T is declared
10001 procedure Check_Private_Overriding
(T
: Entity_Id
);
10002 -- Checks that if a primitive abstract subprogram of a visible
10003 -- abstract type is declared in a private part, then it must override
10004 -- an abstract subprogram declared in the visible part. Also checks
10005 -- that if a primitive function with a controlling result is declared
10006 -- in a private part, then it must override a function declared in
10007 -- the visible part.
10009 ------------------------------
10010 -- Check_Private_Overriding --
10011 ------------------------------
10013 procedure Check_Private_Overriding
(T
: Entity_Id
) is
10014 function Overrides_Private_Part_Op
return Boolean;
10015 -- This detects the special case where the overriding subprogram
10016 -- is overriding a subprogram that was declared in the same
10017 -- private part. That case is illegal by 3.9.3(10).
10019 function Overrides_Visible_Function
10020 (Partial_View
: Entity_Id
) return Boolean;
10021 -- True if S overrides a function in the visible part. The
10022 -- overridden function could be explicitly or implicitly declared.
10024 -------------------------------
10025 -- Overrides_Private_Part_Op --
10026 -------------------------------
10028 function Overrides_Private_Part_Op
return Boolean is
10029 Over_Decl
: constant Node_Id
:=
10030 Unit_Declaration_Node
(Overridden_Operation
(S
));
10031 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(S
);
10034 pragma Assert
(Is_Overriding
);
10036 (Nkind
(Over_Decl
) = N_Abstract_Subprogram_Declaration
);
10038 (Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
);
10040 return In_Same_List
(Over_Decl
, Subp_Decl
);
10041 end Overrides_Private_Part_Op
;
10043 --------------------------------
10044 -- Overrides_Visible_Function --
10045 --------------------------------
10047 function Overrides_Visible_Function
10048 (Partial_View
: Entity_Id
) return Boolean
10051 if not Is_Overriding
or else not Has_Homonym
(S
) then
10055 if not Present
(Partial_View
) then
10059 -- Search through all the homonyms H of S in the current
10060 -- package spec, and return True if we find one that matches.
10061 -- Note that Parent (H) will be the declaration of the
10062 -- partial view of T for a match.
10065 H
: Entity_Id
:= S
;
10069 exit when not Present
(H
) or else Scope
(H
) /= Scope
(S
);
10073 N_Private_Extension_Declaration
,
10074 N_Private_Type_Declaration
)
10075 and then Defining_Identifier
(Parent
(H
)) = Partial_View
10083 end Overrides_Visible_Function
;
10085 -- Start of processing for Check_Private_Overriding
10088 if Is_Package_Or_Generic_Package
(Current_Scope
)
10089 and then In_Private_Part
(Current_Scope
)
10090 and then Visible_Part_Type
(T
)
10091 and then not In_Instance
10093 if Is_Abstract_Type
(T
)
10094 and then Is_Abstract_Subprogram
(S
)
10095 and then (not Is_Overriding
10096 or else not Is_Abstract_Subprogram
(E
)
10097 or else Overrides_Private_Part_Op
)
10100 ("abstract subprograms must be visible (RM 3.9.3(10))!",
10103 elsif Ekind
(S
) = E_Function
then
10105 Partial_View
: constant Entity_Id
:=
10106 Incomplete_Or_Partial_View
(T
);
10109 if not Overrides_Visible_Function
(Partial_View
) then
10111 -- Here, S is "function ... return T;" declared in
10112 -- the private part, not overriding some visible
10113 -- operation. That's illegal in the tagged case
10114 -- (but not if the private type is untagged).
10116 if ((Present
(Partial_View
)
10117 and then Is_Tagged_Type
(Partial_View
))
10118 or else (not Present
(Partial_View
)
10119 and then Is_Tagged_Type
(T
)))
10120 and then T
= Base_Type
(Etype
(S
))
10123 ("private function with tagged result must"
10124 & " override visible-part function", S
);
10126 ("\move subprogram to the visible part"
10127 & " (RM 3.9.3(10))", S
);
10129 -- AI05-0073: extend this test to the case of a
10130 -- function with a controlling access result.
10132 elsif Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
10133 and then Is_Tagged_Type
(Designated_Type
(Etype
(S
)))
10135 not Is_Class_Wide_Type
10136 (Designated_Type
(Etype
(S
)))
10137 and then Ada_Version
>= Ada_2012
10140 ("private function with controlling access "
10141 & "result must override visible-part function",
10144 ("\move subprogram to the visible part"
10145 & " (RM 3.9.3(10))", S
);
10151 end Check_Private_Overriding
;
10153 -----------------------
10154 -- Visible_Part_Type --
10155 -----------------------
10157 function Visible_Part_Type
(T
: Entity_Id
) return Boolean is
10158 P
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(T
));
10161 -- If the entity is a private type, then it must be declared in a
10164 if Ekind
(T
) in Private_Kind
then
10167 elsif Is_Type
(T
) and then Has_Private_Declaration
(T
) then
10170 elsif Is_List_Member
(Declaration_Node
(T
))
10171 and then List_Containing
(Declaration_Node
(T
)) =
10172 Visible_Declarations
(Specification
(P
))
10179 end Visible_Part_Type
;
10181 -- Start of processing for Check_For_Primitive_Subprogram
10184 Is_Primitive
:= False;
10186 if not Comes_From_Source
(S
) then
10189 -- If subprogram is at library level, it is not primitive operation
10191 elsif Current_Scope
= Standard_Standard
then
10194 elsif (Is_Package_Or_Generic_Package
(Current_Scope
)
10195 and then not In_Package_Body
(Current_Scope
))
10196 or else Is_Overriding
10198 -- For function, check return type
10200 if Ekind
(S
) = E_Function
then
10201 if Ekind
(Etype
(S
)) = E_Anonymous_Access_Type
then
10202 F_Typ
:= Designated_Type
(Etype
(S
));
10204 F_Typ
:= Etype
(S
);
10207 B_Typ
:= Base_Type
(F_Typ
);
10209 if Scope
(B_Typ
) = Current_Scope
10210 and then not Is_Class_Wide_Type
(B_Typ
)
10211 and then not Is_Generic_Type
(B_Typ
)
10213 Is_Primitive
:= True;
10214 Set_Has_Primitive_Operations
(B_Typ
);
10215 Set_Is_Primitive
(S
);
10216 Check_Private_Overriding
(B_Typ
);
10218 -- The Ghost policy in effect at the point of declaration
10219 -- or a tagged type and a primitive operation must match
10220 -- (SPARK RM 6.9(16)).
10222 Check_Ghost_Primitive
(S
, B_Typ
);
10226 -- For all subprograms, check formals
10228 Formal
:= First_Formal
(S
);
10229 while Present
(Formal
) loop
10230 if Ekind
(Etype
(Formal
)) = E_Anonymous_Access_Type
then
10231 F_Typ
:= Designated_Type
(Etype
(Formal
));
10233 F_Typ
:= Etype
(Formal
);
10236 B_Typ
:= Base_Type
(F_Typ
);
10238 if Ekind
(B_Typ
) = E_Access_Subtype
then
10239 B_Typ
:= Base_Type
(B_Typ
);
10242 if Scope
(B_Typ
) = Current_Scope
10243 and then not Is_Class_Wide_Type
(B_Typ
)
10244 and then not Is_Generic_Type
(B_Typ
)
10246 Is_Primitive
:= True;
10247 Set_Is_Primitive
(S
);
10248 Set_Has_Primitive_Operations
(B_Typ
);
10249 Check_Private_Overriding
(B_Typ
);
10251 -- The Ghost policy in effect at the point of declaration
10252 -- of a tagged type and a primitive operation must match
10253 -- (SPARK RM 6.9(16)).
10255 Check_Ghost_Primitive
(S
, B_Typ
);
10258 Next_Formal
(Formal
);
10261 -- Special case: An equality function can be redefined for a type
10262 -- occurring in a declarative part, and won't otherwise be treated as
10263 -- a primitive because it doesn't occur in a package spec and doesn't
10264 -- override an inherited subprogram. It's important that we mark it
10265 -- primitive so it can be returned by Collect_Primitive_Operations
10266 -- and be used in composing the equality operation of later types
10267 -- that have a component of the type.
10269 elsif Chars
(S
) = Name_Op_Eq
10270 and then Etype
(S
) = Standard_Boolean
10272 B_Typ
:= Base_Type
(Etype
(First_Formal
(S
)));
10274 if Scope
(B_Typ
) = Current_Scope
10276 Base_Type
(Etype
(Next_Formal
(First_Formal
(S
)))) = B_Typ
10277 and then not Is_Limited_Type
(B_Typ
)
10279 Is_Primitive
:= True;
10280 Set_Is_Primitive
(S
);
10281 Set_Has_Primitive_Operations
(B_Typ
);
10282 Check_Private_Overriding
(B_Typ
);
10284 -- The Ghost policy in effect at the point of declaration of a
10285 -- tagged type and a primitive operation must match
10286 -- (SPARK RM 6.9(16)).
10288 Check_Ghost_Primitive
(S
, B_Typ
);
10291 end Check_For_Primitive_Subprogram
;
10293 --------------------------------------
10294 -- Has_Matching_Entry_Or_Subprogram --
10295 --------------------------------------
10297 function Has_Matching_Entry_Or_Subprogram
10298 (E
: Entity_Id
) return Boolean
10300 function Check_Conforming_Parameters
10301 (E1_Param
: Node_Id
;
10302 E2_Param
: Node_Id
) return Boolean;
10303 -- Starting from the given parameters, check that all the parameters
10304 -- of two entries or subprograms are subtype conformant. Used to skip
10305 -- the check on the controlling argument.
10307 function Matching_Entry_Or_Subprogram
10308 (Conc_Typ
: Entity_Id
;
10309 Subp
: Entity_Id
) return Entity_Id
;
10310 -- Return the first entry or subprogram of the given concurrent type
10311 -- whose name matches the name of Subp and has a profile conformant
10312 -- with Subp; return Empty if not found.
10314 function Matching_Dispatching_Subprogram
10315 (Conc_Typ
: Entity_Id
;
10316 Ent
: Entity_Id
) return Entity_Id
;
10317 -- Return the first dispatching primitive of Conc_Type defined in the
10318 -- enclosing scope of Conc_Type (i.e. before the full definition of
10319 -- this concurrent type) whose name matches the entry Ent and has a
10320 -- profile conformant with the profile of the corresponding (not yet
10321 -- built) dispatching primitive of Ent; return Empty if not found.
10323 function Matching_Original_Protected_Subprogram
10324 (Prot_Typ
: Entity_Id
;
10325 Subp
: Entity_Id
) return Entity_Id
;
10326 -- Return the first subprogram defined in the enclosing scope of
10327 -- Prot_Typ (before the full definition of this protected type)
10328 -- whose name matches the original name of Subp and has a profile
10329 -- conformant with the profile of Subp; return Empty if not found.
10331 ---------------------------------
10332 -- Check_Confirming_Parameters --
10333 ---------------------------------
10335 function Check_Conforming_Parameters
10336 (E1_Param
: Node_Id
;
10337 E2_Param
: Node_Id
) return Boolean
10339 Param_E1
: Node_Id
:= E1_Param
;
10340 Param_E2
: Node_Id
:= E2_Param
;
10343 while Present
(Param_E1
) and then Present
(Param_E2
) loop
10344 if Ekind
(Defining_Identifier
(Param_E1
)) /=
10345 Ekind
(Defining_Identifier
(Param_E2
))
10348 (Find_Parameter_Type
(Param_E1
),
10349 Find_Parameter_Type
(Param_E2
),
10350 Subtype_Conformant
)
10359 -- The candidate is not valid if one of the two lists contains
10360 -- more parameters than the other
10362 return No
(Param_E1
) and then No
(Param_E2
);
10363 end Check_Conforming_Parameters
;
10365 ----------------------------------
10366 -- Matching_Entry_Or_Subprogram --
10367 ----------------------------------
10369 function Matching_Entry_Or_Subprogram
10370 (Conc_Typ
: Entity_Id
;
10371 Subp
: Entity_Id
) return Entity_Id
10376 E
:= First_Entity
(Conc_Typ
);
10377 while Present
(E
) loop
10378 if Chars
(Subp
) = Chars
(E
)
10379 and then (Ekind
(E
) = E_Entry
or else Is_Subprogram
(E
))
10381 Check_Conforming_Parameters
10382 (First
(Parameter_Specifications
(Parent
(E
))),
10383 Next
(First
(Parameter_Specifications
(Parent
(Subp
)))))
10392 end Matching_Entry_Or_Subprogram
;
10394 -------------------------------------
10395 -- Matching_Dispatching_Subprogram --
10396 -------------------------------------
10398 function Matching_Dispatching_Subprogram
10399 (Conc_Typ
: Entity_Id
;
10400 Ent
: Entity_Id
) return Entity_Id
10405 -- Search for entities in the enclosing scope of this synchonized
10408 pragma Assert
(Is_Concurrent_Type
(Conc_Typ
));
10409 Push_Scope
(Scope
(Conc_Typ
));
10410 E
:= Current_Entity_In_Scope
(Ent
);
10413 while Present
(E
) loop
10414 if Scope
(E
) = Scope
(Conc_Typ
)
10415 and then Comes_From_Source
(E
)
10416 and then Ekind
(E
) = E_Procedure
10417 and then Present
(First_Entity
(E
))
10418 and then Is_Controlling_Formal
(First_Entity
(E
))
10419 and then Etype
(First_Entity
(E
)) = Conc_Typ
10421 Check_Conforming_Parameters
10422 (First
(Parameter_Specifications
(Parent
(Ent
))),
10423 Next
(First
(Parameter_Specifications
(Parent
(E
)))))
10432 end Matching_Dispatching_Subprogram
;
10434 --------------------------------------------
10435 -- Matching_Original_Protected_Subprogram --
10436 --------------------------------------------
10438 function Matching_Original_Protected_Subprogram
10439 (Prot_Typ
: Entity_Id
;
10440 Subp
: Entity_Id
) return Entity_Id
10442 ICF
: constant Boolean :=
10443 Is_Controlling_Formal
(First_Entity
(Subp
));
10447 -- Temporarily decorate the first parameter of Subp as controlling
10448 -- formal, required to invoke Subtype_Conformant.
10450 Set_Is_Controlling_Formal
(First_Entity
(Subp
));
10453 Current_Entity_In_Scope
(Original_Protected_Subprogram
(Subp
));
10455 while Present
(E
) loop
10456 if Scope
(E
) = Scope
(Prot_Typ
)
10457 and then Comes_From_Source
(E
)
10458 and then Ekind
(Subp
) = Ekind
(E
)
10459 and then Present
(First_Entity
(E
))
10460 and then Is_Controlling_Formal
(First_Entity
(E
))
10461 and then Etype
(First_Entity
(E
)) = Prot_Typ
10462 and then Subtype_Conformant
(Subp
, E
,
10463 Skip_Controlling_Formals
=> True)
10465 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
10472 Set_Is_Controlling_Formal
(First_Entity
(Subp
), ICF
);
10475 end Matching_Original_Protected_Subprogram
;
10477 -- Start of processing for Has_Matching_Entry_Or_Subprogram
10480 -- Case 1: E is a subprogram whose first formal is a concurrent type
10481 -- defined in the scope of E that has an entry or subprogram whose
10482 -- profile matches E.
10484 if Comes_From_Source
(E
)
10485 and then Is_Subprogram
(E
)
10486 and then Present
(First_Entity
(E
))
10487 and then Is_Concurrent_Record_Type
(Etype
(First_Entity
(E
)))
10490 Scope
(Corresponding_Concurrent_Type
10491 (Etype
(First_Entity
(E
))))
10494 (Matching_Entry_Or_Subprogram
10495 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10498 Report_Conflict
(E
,
10499 Matching_Entry_Or_Subprogram
10500 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10505 -- Case 2: E is an internally built dispatching subprogram of a
10506 -- protected type and there is a subprogram defined in the enclosing
10507 -- scope of the protected type that has the original name of E and
10508 -- its profile is conformant with the profile of E. We check the
10509 -- name of the original protected subprogram associated with E since
10510 -- the expander builds dispatching primitives of protected functions
10511 -- and procedures with other names (see Exp_Ch9.Build_Selected_Name).
10513 elsif not Comes_From_Source
(E
)
10514 and then Is_Subprogram
(E
)
10515 and then Present
(First_Entity
(E
))
10516 and then Is_Concurrent_Record_Type
(Etype
(First_Entity
(E
)))
10517 and then Present
(Original_Protected_Subprogram
(E
))
10520 (Matching_Original_Protected_Subprogram
10521 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10524 Report_Conflict
(E
,
10525 Matching_Original_Protected_Subprogram
10526 (Corresponding_Concurrent_Type
(Etype
(First_Entity
(E
))),
10530 -- Case 3: E is an entry of a synchronized type and a matching
10531 -- procedure has been previously defined in the enclosing scope
10532 -- of the synchronized type.
10534 elsif Comes_From_Source
(E
)
10535 and then Ekind
(E
) = E_Entry
10537 Present
(Matching_Dispatching_Subprogram
(Current_Scope
, E
))
10539 Report_Conflict
(E
,
10540 Matching_Dispatching_Subprogram
(Current_Scope
, E
));
10545 end Has_Matching_Entry_Or_Subprogram
;
10547 ----------------------------
10548 -- Is_Private_Declaration --
10549 ----------------------------
10551 function Is_Private_Declaration
(E
: Entity_Id
) return Boolean is
10552 Decl
: constant Node_Id
:= Unit_Declaration_Node
(E
);
10553 Priv_Decls
: List_Id
;
10556 if Is_Package_Or_Generic_Package
(Current_Scope
)
10557 and then In_Private_Part
(Current_Scope
)
10560 Private_Declarations
(Package_Specification
(Current_Scope
));
10562 return In_Package_Body
(Current_Scope
)
10564 (Is_List_Member
(Decl
)
10565 and then List_Containing
(Decl
) = Priv_Decls
)
10566 or else (Nkind
(Parent
(Decl
)) = N_Package_Specification
10568 Is_Compilation_Unit
10569 (Defining_Entity
(Parent
(Decl
)))
10570 and then List_Containing
(Parent
(Parent
(Decl
))) =
10575 end Is_Private_Declaration
;
10577 --------------------------
10578 -- Is_Overriding_Alias --
10579 --------------------------
10581 function Is_Overriding_Alias
10582 (Old_E
: Entity_Id
;
10583 New_E
: Entity_Id
) return Boolean
10585 AO
: constant Entity_Id
:= Alias
(Old_E
);
10586 AN
: constant Entity_Id
:= Alias
(New_E
);
10589 return Scope
(AO
) /= Scope
(AN
)
10590 or else No
(DTC_Entity
(AO
))
10591 or else No
(DTC_Entity
(AN
))
10592 or else DT_Position
(AO
) = DT_Position
(AN
);
10593 end Is_Overriding_Alias
;
10595 ---------------------
10596 -- Report_Conflict --
10597 ---------------------
10599 procedure Report_Conflict
(S
: Entity_Id
; E
: Entity_Id
) is
10601 Error_Msg_Sloc
:= Sloc
(E
);
10603 -- Generate message, with useful additional warning if in generic
10605 if Is_Generic_Unit
(E
) then
10606 Error_Msg_N
("previous generic unit cannot be overloaded", S
);
10607 Error_Msg_N
("\& conflicts with declaration#", S
);
10609 Error_Msg_N
("& conflicts with declaration#", S
);
10611 end Report_Conflict
;
10613 -- Start of processing for New_Overloaded_Entity
10616 -- We need to look for an entity that S may override. This must be a
10617 -- homonym in the current scope, so we look for the first homonym of
10618 -- S in the current scope as the starting point for the search.
10620 E
:= Current_Entity_In_Scope
(S
);
10622 -- Ada 2005 (AI-251): Derivation of abstract interface primitives.
10623 -- They are directly added to the list of primitive operations of
10624 -- Derived_Type, unless this is a rederivation in the private part
10625 -- of an operation that was already derived in the visible part of
10626 -- the current package.
10628 if Ada_Version
>= Ada_2005
10629 and then Present
(Derived_Type
)
10630 and then Present
(Alias
(S
))
10631 and then Is_Dispatching_Operation
(Alias
(S
))
10632 and then Present
(Find_Dispatching_Type
(Alias
(S
)))
10633 and then Is_Interface
(Find_Dispatching_Type
(Alias
(S
)))
10635 -- For private types, when the full-view is processed we propagate to
10636 -- the full view the non-overridden entities whose attribute "alias"
10637 -- references an interface primitive. These entities were added by
10638 -- Derive_Subprograms to ensure that interface primitives are
10641 -- Inside_Freeze_Actions is non zero when S corresponds with an
10642 -- internal entity that links an interface primitive with its
10643 -- covering primitive through attribute Interface_Alias (see
10644 -- Add_Internal_Interface_Entities).
10646 if Inside_Freezing_Actions
= 0
10647 and then Is_Package_Or_Generic_Package
(Current_Scope
)
10648 and then In_Private_Part
(Current_Scope
)
10649 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
10650 and then Nkind
(Parent
(S
)) = N_Full_Type_Declaration
10651 and then Full_View
(Defining_Identifier
(Parent
(E
)))
10652 = Defining_Identifier
(Parent
(S
))
10653 and then Alias
(E
) = Alias
(S
)
10655 Check_Operation_From_Private_View
(S
, E
);
10656 Set_Is_Dispatching_Operation
(S
);
10661 Enter_Overloaded_Entity
(S
);
10662 Check_Dispatching_Operation
(S
, Empty
);
10663 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10669 -- For synchronized types check conflicts of this entity with previously
10670 -- defined entities.
10672 if Ada_Version
>= Ada_2005
10673 and then Has_Matching_Entry_Or_Subprogram
(S
)
10678 -- If there is no homonym then this is definitely not overriding
10681 Enter_Overloaded_Entity
(S
);
10682 Check_Dispatching_Operation
(S
, Empty
);
10683 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
10685 -- If subprogram has an explicit declaration, check whether it has an
10686 -- overriding indicator.
10688 if Comes_From_Source
(S
) then
10689 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10691 -- (Ada 2012: AI05-0125-1): If S is a dispatching operation then
10692 -- it may have overridden some hidden inherited primitive. Update
10693 -- Overridden_Subp to avoid spurious errors when checking the
10694 -- overriding indicator.
10696 if Ada_Version
>= Ada_2012
10697 and then No
(Overridden_Subp
)
10698 and then Is_Dispatching_Operation
(S
)
10699 and then Present
(Overridden_Operation
(S
))
10701 Overridden_Subp
:= Overridden_Operation
(S
);
10704 Check_Overriding_Indicator
10705 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
10707 -- The Ghost policy in effect at the point of declaration of a
10708 -- parent subprogram and an overriding subprogram must match
10709 -- (SPARK RM 6.9(17)).
10711 Check_Ghost_Overriding
(S
, Overridden_Subp
);
10714 -- If there is a homonym that is not overloadable, then we have an
10715 -- error, except for the special cases checked explicitly below.
10717 elsif not Is_Overloadable
(E
) then
10719 -- Check for spurious conflict produced by a subprogram that has the
10720 -- same name as that of the enclosing generic package. The conflict
10721 -- occurs within an instance, between the subprogram and the renaming
10722 -- declaration for the package. After the subprogram, the package
10723 -- renaming declaration becomes hidden.
10725 if Ekind
(E
) = E_Package
10726 and then Present
(Renamed_Object
(E
))
10727 and then Renamed_Object
(E
) = Current_Scope
10728 and then Nkind
(Parent
(Renamed_Object
(E
))) =
10729 N_Package_Specification
10730 and then Present
(Generic_Parent
(Parent
(Renamed_Object
(E
))))
10733 Set_Is_Immediately_Visible
(E
, False);
10734 Enter_Overloaded_Entity
(S
);
10735 Set_Homonym
(S
, Homonym
(E
));
10736 Check_Dispatching_Operation
(S
, Empty
);
10737 Check_Overriding_Indicator
(S
, Empty
, Is_Primitive
=> False);
10739 -- If the subprogram is implicit it is hidden by the previous
10740 -- declaration. However if it is dispatching, it must appear in the
10741 -- dispatch table anyway, because it can be dispatched to even if it
10742 -- cannot be called directly.
10744 elsif Present
(Alias
(S
)) and then not Comes_From_Source
(S
) then
10745 Set_Scope
(S
, Current_Scope
);
10747 if Is_Dispatching_Operation
(Alias
(S
)) then
10748 Check_Dispatching_Operation
(S
, Empty
);
10754 Report_Conflict
(S
, E
);
10758 -- E exists and is overloadable
10761 Check_Synchronized_Overriding
(S
, Overridden_Subp
);
10763 -- Loop through E and its homonyms to determine if any of them is
10764 -- the candidate for overriding by S.
10766 while Present
(E
) loop
10768 -- Definitely not interesting if not in the current scope
10770 if Scope
(E
) /= Current_Scope
then
10773 -- A function can overload the name of an abstract state. The
10774 -- state can be viewed as a function with a profile that cannot
10775 -- be matched by anything.
10777 elsif Ekind
(S
) = E_Function
10778 and then Ekind
(E
) = E_Abstract_State
10780 Enter_Overloaded_Entity
(S
);
10783 -- Ada 2012 (AI05-0165): For internally generated bodies of null
10784 -- procedures locate the internally generated spec. We enforce
10785 -- mode conformance since a tagged type may inherit from
10786 -- interfaces several null primitives which differ only in
10787 -- the mode of the formals.
10789 elsif not Comes_From_Source
(S
)
10790 and then Is_Null_Procedure
(S
)
10791 and then not Mode_Conformant
(E
, S
)
10795 -- Check if we have type conformance
10797 elsif Type_Conformant
(E
, S
) then
10799 -- If the old and new entities have the same profile and one
10800 -- is not the body of the other, then this is an error, unless
10801 -- one of them is implicitly declared.
10803 -- There are some cases when both can be implicit, for example
10804 -- when both a literal and a function that overrides it are
10805 -- inherited in a derivation, or when an inherited operation
10806 -- of a tagged full type overrides the inherited operation of
10807 -- a private extension. Ada 83 had a special rule for the
10808 -- literal case. In Ada 95, the later implicit operation hides
10809 -- the former, and the literal is always the former. In the
10810 -- odd case where both are derived operations declared at the
10811 -- same point, both operations should be declared, and in that
10812 -- case we bypass the following test and proceed to the next
10813 -- part. This can only occur for certain obscure cases in
10814 -- instances, when an operation on a type derived from a formal
10815 -- private type does not override a homograph inherited from
10816 -- the actual. In subsequent derivations of such a type, the
10817 -- DT positions of these operations remain distinct, if they
10820 if Present
(Alias
(S
))
10821 and then (No
(Alias
(E
))
10822 or else Comes_From_Source
(E
)
10823 or else Is_Abstract_Subprogram
(S
)
10825 (Is_Dispatching_Operation
(E
)
10826 and then Is_Overriding_Alias
(E
, S
)))
10827 and then Ekind
(E
) /= E_Enumeration_Literal
10829 -- When an derived operation is overloaded it may be due to
10830 -- the fact that the full view of a private extension
10831 -- re-inherits. It has to be dealt with.
10833 if Is_Package_Or_Generic_Package
(Current_Scope
)
10834 and then In_Private_Part
(Current_Scope
)
10836 Check_Operation_From_Private_View
(S
, E
);
10839 -- In any case the implicit operation remains hidden by the
10840 -- existing declaration, which is overriding. Indicate that
10841 -- E overrides the operation from which S is inherited.
10843 if Present
(Alias
(S
)) then
10844 Set_Overridden_Operation
(E
, Alias
(S
));
10845 Inherit_Subprogram_Contract
(E
, Alias
(S
));
10848 Set_Overridden_Operation
(E
, S
);
10849 Inherit_Subprogram_Contract
(E
, S
);
10852 if Comes_From_Source
(E
) then
10853 Check_Overriding_Indicator
(E
, S
, Is_Primitive
=> False);
10855 -- The Ghost policy in effect at the point of declaration
10856 -- of a parent subprogram and an overriding subprogram
10857 -- must match (SPARK RM 6.9(17)).
10859 Check_Ghost_Overriding
(E
, S
);
10864 -- Within an instance, the renaming declarations for actual
10865 -- subprograms may become ambiguous, but they do not hide each
10868 elsif Ekind
(E
) /= E_Entry
10869 and then not Comes_From_Source
(E
)
10870 and then not Is_Generic_Instance
(E
)
10871 and then (Present
(Alias
(E
))
10872 or else Is_Intrinsic_Subprogram
(E
))
10873 and then (not In_Instance
10874 or else No
(Parent
(E
))
10875 or else Nkind
(Unit_Declaration_Node
(E
)) /=
10876 N_Subprogram_Renaming_Declaration
)
10878 -- A subprogram child unit is not allowed to override an
10879 -- inherited subprogram (10.1.1(20)).
10881 if Is_Child_Unit
(S
) then
10883 ("child unit overrides inherited subprogram in parent",
10888 if Is_Non_Overriding_Operation
(E
, S
) then
10889 Enter_Overloaded_Entity
(S
);
10891 if No
(Derived_Type
)
10892 or else Is_Tagged_Type
(Derived_Type
)
10894 Check_Dispatching_Operation
(S
, Empty
);
10900 -- E is a derived operation or an internal operator which
10901 -- is being overridden. Remove E from further visibility.
10902 -- Furthermore, if E is a dispatching operation, it must be
10903 -- replaced in the list of primitive operations of its type
10904 -- (see Override_Dispatching_Operation).
10906 Overridden_Subp
:= E
;
10912 Prev
:= First_Entity
(Current_Scope
);
10913 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
10914 Next_Entity
(Prev
);
10917 -- It is possible for E to be in the current scope and
10918 -- yet not in the entity chain. This can only occur in a
10919 -- generic context where E is an implicit concatenation
10920 -- in the formal part, because in a generic body the
10921 -- entity chain starts with the formals.
10923 -- In GNATprove mode, a wrapper for an operation with
10924 -- axiomatization may be a homonym of another declaration
10925 -- for an actual subprogram (needs refinement ???).
10929 and then GNATprove_Mode
10931 Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
10932 N_Subprogram_Renaming_Declaration
10936 pragma Assert
(Chars
(E
) = Name_Op_Concat
);
10941 -- E must be removed both from the entity_list of the
10942 -- current scope, and from the visibility chain.
10944 if Debug_Flag_E
then
10945 Write_Str
("Override implicit operation ");
10946 Write_Int
(Int
(E
));
10950 -- If E is a predefined concatenation, it stands for four
10951 -- different operations. As a result, a single explicit
10952 -- declaration does not hide it. In a possible ambiguous
10953 -- situation, Disambiguate chooses the user-defined op,
10954 -- so it is correct to retain the previous internal one.
10956 if Chars
(E
) /= Name_Op_Concat
10957 or else Ekind
(E
) /= E_Operator
10959 -- For nondispatching derived operations that are
10960 -- overridden by a subprogram declared in the private
10961 -- part of a package, we retain the derived subprogram
10962 -- but mark it as not immediately visible. If the
10963 -- derived operation was declared in the visible part
10964 -- then this ensures that it will still be visible
10965 -- outside the package with the proper signature
10966 -- (calls from outside must also be directed to this
10967 -- version rather than the overriding one, unlike the
10968 -- dispatching case). Calls from inside the package
10969 -- will still resolve to the overriding subprogram
10970 -- since the derived one is marked as not visible
10971 -- within the package.
10973 -- If the private operation is dispatching, we achieve
10974 -- the overriding by keeping the implicit operation
10975 -- but setting its alias to be the overriding one. In
10976 -- this fashion the proper body is executed in all
10977 -- cases, but the original signature is used outside
10980 -- If the overriding is not in the private part, we
10981 -- remove the implicit operation altogether.
10983 if Is_Private_Declaration
(S
) then
10984 if not Is_Dispatching_Operation
(E
) then
10985 Set_Is_Immediately_Visible
(E
, False);
10987 -- Work done in Override_Dispatching_Operation,
10988 -- so nothing else needs to be done here.
10994 -- Find predecessor of E in Homonym chain
10996 if E
= Current_Entity
(E
) then
10999 Prev_Vis
:= Current_Entity
(E
);
11000 while Homonym
(Prev_Vis
) /= E
loop
11001 Prev_Vis
:= Homonym
(Prev_Vis
);
11005 if Prev_Vis
/= Empty
then
11007 -- Skip E in the visibility chain
11009 Set_Homonym
(Prev_Vis
, Homonym
(E
));
11012 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
11015 Set_Next_Entity
(Prev
, Next_Entity
(E
));
11017 if No
(Next_Entity
(Prev
)) then
11018 Set_Last_Entity
(Current_Scope
, Prev
);
11023 Enter_Overloaded_Entity
(S
);
11025 -- For entities generated by Derive_Subprograms the
11026 -- overridden operation is the inherited primitive
11027 -- (which is available through the attribute alias).
11029 if not (Comes_From_Source
(E
))
11030 and then Is_Dispatching_Operation
(E
)
11031 and then Find_Dispatching_Type
(E
) =
11032 Find_Dispatching_Type
(S
)
11033 and then Present
(Alias
(E
))
11034 and then Comes_From_Source
(Alias
(E
))
11036 Set_Overridden_Operation
(S
, Alias
(E
));
11037 Inherit_Subprogram_Contract
(S
, Alias
(E
));
11039 -- Normal case of setting entity as overridden
11041 -- Note: Static_Initialization and Overridden_Operation
11042 -- attributes use the same field in subprogram entities.
11043 -- Static_Initialization is only defined for internal
11044 -- initialization procedures, where Overridden_Operation
11045 -- is irrelevant. Therefore the setting of this attribute
11046 -- must check whether the target is an init_proc.
11048 elsif not Is_Init_Proc
(S
) then
11049 Set_Overridden_Operation
(S
, E
);
11050 Inherit_Subprogram_Contract
(S
, E
);
11053 Check_Overriding_Indicator
(S
, E
, Is_Primitive
=> True);
11055 -- The Ghost policy in effect at the point of declaration
11056 -- of a parent subprogram and an overriding subprogram
11057 -- must match (SPARK RM 6.9(17)).
11059 Check_Ghost_Overriding
(S
, E
);
11061 -- If S is a user-defined subprogram or a null procedure
11062 -- expanded to override an inherited null procedure, or a
11063 -- predefined dispatching primitive then indicate that E
11064 -- overrides the operation from which S is inherited.
11066 if Comes_From_Source
(S
)
11068 (Present
(Parent
(S
))
11070 Nkind
(Parent
(S
)) = N_Procedure_Specification
11072 Null_Present
(Parent
(S
)))
11074 (Present
(Alias
(E
))
11076 Is_Predefined_Dispatching_Operation
(Alias
(E
)))
11078 if Present
(Alias
(E
)) then
11079 Set_Overridden_Operation
(S
, Alias
(E
));
11080 Inherit_Subprogram_Contract
(S
, Alias
(E
));
11084 if Is_Dispatching_Operation
(E
) then
11086 -- An overriding dispatching subprogram inherits the
11087 -- convention of the overridden subprogram (AI-117).
11089 Set_Convention
(S
, Convention
(E
));
11090 Check_Dispatching_Operation
(S
, E
);
11093 Check_Dispatching_Operation
(S
, Empty
);
11096 Check_For_Primitive_Subprogram
11097 (Is_Primitive_Subp
, Is_Overriding
=> True);
11098 goto Check_Inequality
;
11101 -- Apparent redeclarations in instances can occur when two
11102 -- formal types get the same actual type. The subprograms in
11103 -- in the instance are legal, even if not callable from the
11104 -- outside. Calls from within are disambiguated elsewhere.
11105 -- For dispatching operations in the visible part, the usual
11106 -- rules apply, and operations with the same profile are not
11107 -- legal (B830001).
11109 elsif (In_Instance_Visible_Part
11110 and then not Is_Dispatching_Operation
(E
))
11111 or else In_Instance_Not_Visible
11115 -- Here we have a real error (identical profile)
11118 Error_Msg_Sloc
:= Sloc
(E
);
11120 -- Avoid cascaded errors if the entity appears in
11121 -- subsequent calls.
11123 Set_Scope
(S
, Current_Scope
);
11125 -- Generate error, with extra useful warning for the case
11126 -- of a generic instance with no completion.
11128 if Is_Generic_Instance
(S
)
11129 and then not Has_Completion
(E
)
11132 ("instantiation cannot provide body for&", S
);
11133 Error_Msg_N
("\& conflicts with declaration#", S
);
11135 Error_Msg_N
("& conflicts with declaration#", S
);
11142 -- If one subprogram has an access parameter and the other
11143 -- a parameter of an access type, calls to either might be
11144 -- ambiguous. Verify that parameters match except for the
11145 -- access parameter.
11147 if May_Hide_Profile
then
11153 F1
:= First_Formal
(S
);
11154 F2
:= First_Formal
(E
);
11155 while Present
(F1
) and then Present
(F2
) loop
11156 if Is_Access_Type
(Etype
(F1
)) then
11157 if not Is_Access_Type
(Etype
(F2
))
11158 or else not Conforming_Types
11159 (Designated_Type
(Etype
(F1
)),
11160 Designated_Type
(Etype
(F2
)),
11163 May_Hide_Profile
:= False;
11167 not Conforming_Types
11168 (Etype
(F1
), Etype
(F2
), Type_Conformant
)
11170 May_Hide_Profile
:= False;
11177 if May_Hide_Profile
11181 Error_Msg_NE
("calls to& may be ambiguous??", S
, S
);
11190 -- On exit, we know that S is a new entity
11192 Enter_Overloaded_Entity
(S
);
11193 Check_For_Primitive_Subprogram
(Is_Primitive_Subp
);
11194 Check_Overriding_Indicator
11195 (S
, Overridden_Subp
, Is_Primitive
=> Is_Primitive_Subp
);
11197 -- The Ghost policy in effect at the point of declaration of a parent
11198 -- subprogram and an overriding subprogram must match
11199 -- (SPARK RM 6.9(17)).
11201 Check_Ghost_Overriding
(S
, Overridden_Subp
);
11203 -- Overloading is not allowed in SPARK, except for operators
11205 if Nkind
(S
) /= N_Defining_Operator_Symbol
then
11206 Error_Msg_Sloc
:= Sloc
(Homonym
(S
));
11207 Check_SPARK_05_Restriction
11208 ("overloading not allowed with entity#", S
);
11211 -- If S is a derived operation for an untagged type then by
11212 -- definition it's not a dispatching operation (even if the parent
11213 -- operation was dispatching), so Check_Dispatching_Operation is not
11214 -- called in that case.
11216 if No
(Derived_Type
)
11217 or else Is_Tagged_Type
(Derived_Type
)
11219 Check_Dispatching_Operation
(S
, Empty
);
11223 -- If this is a user-defined equality operator that is not a derived
11224 -- subprogram, create the corresponding inequality. If the operation is
11225 -- dispatching, the expansion is done elsewhere, and we do not create
11226 -- an explicit inequality operation.
11228 <<Check_Inequality
>>
11229 if Chars
(S
) = Name_Op_Eq
11230 and then Etype
(S
) = Standard_Boolean
11231 and then Present
(Parent
(S
))
11232 and then not Is_Dispatching_Operation
(S
)
11234 Make_Inequality_Operator
(S
);
11235 Check_Untagged_Equality
(S
);
11237 end New_Overloaded_Entity
;
11239 ---------------------
11240 -- Process_Formals --
11241 ---------------------
11243 procedure Process_Formals
11245 Related_Nod
: Node_Id
)
11247 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean;
11248 -- Determine whether an access type designates a type coming from a
11251 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean;
11252 -- Check whether the default has a class-wide type. After analysis the
11253 -- default has the type of the formal, so we must also check explicitly
11254 -- for an access attribute.
11256 ----------------------------------
11257 -- Designates_From_Limited_With --
11258 ----------------------------------
11260 function Designates_From_Limited_With
(Typ
: Entity_Id
) return Boolean is
11261 Desig
: Entity_Id
:= Typ
;
11264 if Is_Access_Type
(Desig
) then
11265 Desig
:= Directly_Designated_Type
(Desig
);
11268 if Is_Class_Wide_Type
(Desig
) then
11269 Desig
:= Root_Type
(Desig
);
11273 Ekind
(Desig
) = E_Incomplete_Type
11274 and then From_Limited_With
(Desig
);
11275 end Designates_From_Limited_With
;
11277 ---------------------------
11278 -- Is_Class_Wide_Default --
11279 ---------------------------
11281 function Is_Class_Wide_Default
(D
: Node_Id
) return Boolean is
11283 return Is_Class_Wide_Type
(Designated_Type
(Etype
(D
)))
11284 or else (Nkind
(D
) = N_Attribute_Reference
11285 and then Attribute_Name
(D
) = Name_Access
11286 and then Is_Class_Wide_Type
(Etype
(Prefix
(D
))));
11287 end Is_Class_Wide_Default
;
11291 Context
: constant Node_Id
:= Parent
(Parent
(T
));
11293 Formal
: Entity_Id
;
11294 Formal_Type
: Entity_Id
;
11295 Param_Spec
: Node_Id
;
11298 Num_Out_Params
: Nat
:= 0;
11299 First_Out_Param
: Entity_Id
:= Empty
;
11300 -- Used for setting Is_Only_Out_Parameter
11302 -- Start of processing for Process_Formals
11305 -- In order to prevent premature use of the formals in the same formal
11306 -- part, the Ekind is left undefined until all default expressions are
11307 -- analyzed. The Ekind is established in a separate loop at the end.
11309 Param_Spec
:= First
(T
);
11310 while Present
(Param_Spec
) loop
11311 Formal
:= Defining_Identifier
(Param_Spec
);
11312 Set_Never_Set_In_Source
(Formal
, True);
11313 Enter_Name
(Formal
);
11315 -- Case of ordinary parameters
11317 if Nkind
(Parameter_Type
(Param_Spec
)) /= N_Access_Definition
then
11318 Find_Type
(Parameter_Type
(Param_Spec
));
11319 Ptype
:= Parameter_Type
(Param_Spec
);
11321 if Ptype
= Error
then
11325 Formal_Type
:= Entity
(Ptype
);
11327 if Is_Incomplete_Type
(Formal_Type
)
11329 (Is_Class_Wide_Type
(Formal_Type
)
11330 and then Is_Incomplete_Type
(Root_Type
(Formal_Type
)))
11332 -- Ada 2005 (AI-326): Tagged incomplete types allowed in
11333 -- primitive operations, as long as their completion is
11334 -- in the same declarative part. If in the private part
11335 -- this means that the type cannot be a Taft-amendment type.
11336 -- Check is done on package exit. For access to subprograms,
11337 -- the use is legal for Taft-amendment types.
11339 -- Ada 2012: tagged incomplete types are allowed as generic
11340 -- formal types. They do not introduce dependencies and the
11341 -- corresponding generic subprogram does not have a delayed
11342 -- freeze, because it does not need a freeze node. However,
11343 -- it is still the case that untagged incomplete types cannot
11344 -- be Taft-amendment types and must be completed in private
11345 -- part, so the subprogram must appear in the list of private
11346 -- dependents of the type.
11348 if Is_Tagged_Type
(Formal_Type
)
11349 or else (Ada_Version
>= Ada_2012
11350 and then not From_Limited_With
(Formal_Type
)
11351 and then not Is_Generic_Type
(Formal_Type
))
11353 if Ekind
(Scope
(Current_Scope
)) = E_Package
11354 and then not Is_Generic_Type
(Formal_Type
)
11355 and then not Is_Class_Wide_Type
(Formal_Type
)
11358 (Parent
(T
), N_Access_Function_Definition
,
11359 N_Access_Procedure_Definition
)
11361 Append_Elmt
(Current_Scope
,
11362 Private_Dependents
(Base_Type
(Formal_Type
)));
11364 -- Freezing is delayed to ensure that Register_Prim
11365 -- will get called for this operation, which is needed
11366 -- in cases where static dispatch tables aren't built.
11367 -- (Note that the same is done for controlling access
11368 -- parameter cases in function Access_Definition.)
11370 if not Is_Thunk
(Current_Scope
) then
11371 Set_Has_Delayed_Freeze
(Current_Scope
);
11376 elsif not Nkind_In
(Parent
(T
), N_Access_Function_Definition
,
11377 N_Access_Procedure_Definition
)
11379 -- AI05-0151: Tagged incomplete types are allowed in all
11380 -- formal parts. Untagged incomplete types are not allowed
11381 -- in bodies. Limited views of either kind are not allowed
11382 -- if there is no place at which the non-limited view can
11383 -- become available.
11385 -- Incomplete formal untagged types are not allowed in
11386 -- subprogram bodies (but are legal in their declarations).
11387 -- This excludes bodies created for null procedures, which
11388 -- are basic declarations.
11390 if Is_Generic_Type
(Formal_Type
)
11391 and then not Is_Tagged_Type
(Formal_Type
)
11392 and then Nkind
(Parent
(Related_Nod
)) = N_Subprogram_Body
11395 ("invalid use of formal incomplete type", Param_Spec
);
11397 elsif Ada_Version
>= Ada_2012
then
11398 if Is_Tagged_Type
(Formal_Type
)
11399 and then (not From_Limited_With
(Formal_Type
)
11400 or else not In_Package_Body
)
11404 elsif Nkind_In
(Context
, N_Accept_Statement
,
11405 N_Accept_Alternative
,
11407 or else (Nkind
(Context
) = N_Subprogram_Body
11408 and then Comes_From_Source
(Context
))
11411 ("invalid use of untagged incomplete type &",
11412 Ptype
, Formal_Type
);
11417 ("invalid use of incomplete type&",
11418 Param_Spec
, Formal_Type
);
11420 -- Further checks on the legality of incomplete types
11421 -- in formal parts are delayed until the freeze point
11422 -- of the enclosing subprogram or access to subprogram.
11426 elsif Ekind
(Formal_Type
) = E_Void
then
11428 ("premature use of&",
11429 Parameter_Type
(Param_Spec
), Formal_Type
);
11432 -- Ada 2012 (AI-142): Handle aliased parameters
11434 if Ada_Version
>= Ada_2012
11435 and then Aliased_Present
(Param_Spec
)
11437 Set_Is_Aliased
(Formal
);
11440 -- Ada 2005 (AI-231): Create and decorate an internal subtype
11441 -- declaration corresponding to the null-excluding type of the
11442 -- formal in the enclosing scope. Finally, replace the parameter
11443 -- type of the formal with the internal subtype.
11445 if Ada_Version
>= Ada_2005
11446 and then Null_Exclusion_Present
(Param_Spec
)
11448 if not Is_Access_Type
(Formal_Type
) then
11450 ("`NOT NULL` allowed only for an access type", Param_Spec
);
11453 if Can_Never_Be_Null
(Formal_Type
)
11454 and then Comes_From_Source
(Related_Nod
)
11457 ("`NOT NULL` not allowed (& already excludes null)",
11458 Param_Spec
, Formal_Type
);
11462 Create_Null_Excluding_Itype
11464 Related_Nod
=> Related_Nod
,
11465 Scope_Id
=> Scope
(Current_Scope
));
11467 -- If the designated type of the itype is an itype that is
11468 -- not frozen yet, we set the Has_Delayed_Freeze attribute
11469 -- on the access subtype, to prevent order-of-elaboration
11470 -- issues in the backend.
11473 -- type T is access procedure;
11474 -- procedure Op (O : not null T);
11476 if Is_Itype
(Directly_Designated_Type
(Formal_Type
))
11478 not Is_Frozen
(Directly_Designated_Type
(Formal_Type
))
11480 Set_Has_Delayed_Freeze
(Formal_Type
);
11485 -- An access formal type
11489 Access_Definition
(Related_Nod
, Parameter_Type
(Param_Spec
));
11491 -- No need to continue if we already notified errors
11493 if not Present
(Formal_Type
) then
11497 -- Ada 2005 (AI-254)
11500 AD
: constant Node_Id
:=
11501 Access_To_Subprogram_Definition
11502 (Parameter_Type
(Param_Spec
));
11504 if Present
(AD
) and then Protected_Present
(AD
) then
11506 Replace_Anonymous_Access_To_Protected_Subprogram
11512 Set_Etype
(Formal
, Formal_Type
);
11514 -- Deal with default expression if present
11516 Default
:= Expression
(Param_Spec
);
11518 if Present
(Default
) then
11519 Check_SPARK_05_Restriction
11520 ("default expression is not allowed", Default
);
11522 if Out_Present
(Param_Spec
) then
11524 ("default initialization only allowed for IN parameters",
11528 -- Do the special preanalysis of the expression (see section on
11529 -- "Handling of Default Expressions" in the spec of package Sem).
11531 Preanalyze_Spec_Expression
(Default
, Formal_Type
);
11533 -- An access to constant cannot be the default for
11534 -- an access parameter that is an access to variable.
11536 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11537 and then not Is_Access_Constant
(Formal_Type
)
11538 and then Is_Access_Type
(Etype
(Default
))
11539 and then Is_Access_Constant
(Etype
(Default
))
11542 ("formal that is access to variable cannot be initialized "
11543 & "with an access-to-constant expression", Default
);
11546 -- Check that the designated type of an access parameter's default
11547 -- is not a class-wide type unless the parameter's designated type
11548 -- is also class-wide.
11550 if Ekind
(Formal_Type
) = E_Anonymous_Access_Type
11551 and then not Designates_From_Limited_With
(Formal_Type
)
11552 and then Is_Class_Wide_Default
(Default
)
11553 and then not Is_Class_Wide_Type
(Designated_Type
(Formal_Type
))
11556 ("access to class-wide expression not allowed here", Default
);
11559 -- Check incorrect use of dynamically tagged expressions
11561 if Is_Tagged_Type
(Formal_Type
) then
11562 Check_Dynamically_Tagged_Expression
11564 Typ
=> Formal_Type
,
11565 Related_Nod
=> Default
);
11569 -- Ada 2005 (AI-231): Static checks
11571 if Ada_Version
>= Ada_2005
11572 and then Is_Access_Type
(Etype
(Formal
))
11573 and then Can_Never_Be_Null
(Etype
(Formal
))
11575 Null_Exclusion_Static_Checks
(Param_Spec
);
11578 -- The following checks are relevant only when SPARK_Mode is on as
11579 -- these are not standard Ada legality rules.
11581 if SPARK_Mode
= On
then
11582 if Ekind_In
(Scope
(Formal
), E_Function
, E_Generic_Function
) then
11584 -- A function cannot have a parameter of mode IN OUT or OUT
11587 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
11589 ("function cannot have parameter of mode `OUT` or "
11590 & "`IN OUT`", Formal
);
11593 -- A procedure cannot have an effectively volatile formal
11594 -- parameter of mode IN because it behaves as a constant
11595 -- (SPARK RM 7.1.3(6)). -- ??? maybe 7.1.3(4)
11597 elsif Ekind
(Scope
(Formal
)) = E_Procedure
11598 and then Ekind
(Formal
) = E_In_Parameter
11599 and then Is_Effectively_Volatile
(Formal
)
11602 ("formal parameter of mode `IN` cannot be volatile", Formal
);
11610 -- If this is the formal part of a function specification, analyze the
11611 -- subtype mark in the context where the formals are visible but not
11612 -- yet usable, and may hide outer homographs.
11614 if Nkind
(Related_Nod
) = N_Function_Specification
then
11615 Analyze_Return_Type
(Related_Nod
);
11618 -- Now set the kind (mode) of each formal
11620 Param_Spec
:= First
(T
);
11621 while Present
(Param_Spec
) loop
11622 Formal
:= Defining_Identifier
(Param_Spec
);
11623 Set_Formal_Mode
(Formal
);
11625 if Ekind
(Formal
) = E_In_Parameter
then
11626 Set_Default_Value
(Formal
, Expression
(Param_Spec
));
11628 if Present
(Expression
(Param_Spec
)) then
11629 Default
:= Expression
(Param_Spec
);
11631 if Is_Scalar_Type
(Etype
(Default
)) then
11632 if Nkind
(Parameter_Type
(Param_Spec
)) /=
11633 N_Access_Definition
11635 Formal_Type
:= Entity
(Parameter_Type
(Param_Spec
));
11639 (Related_Nod
, Parameter_Type
(Param_Spec
));
11642 Apply_Scalar_Range_Check
(Default
, Formal_Type
);
11646 elsif Ekind
(Formal
) = E_Out_Parameter
then
11647 Num_Out_Params
:= Num_Out_Params
+ 1;
11649 if Num_Out_Params
= 1 then
11650 First_Out_Param
:= Formal
;
11653 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
11654 Num_Out_Params
:= Num_Out_Params
+ 1;
11657 -- Skip remaining processing if formal type was in error
11659 if Etype
(Formal
) = Any_Type
or else Error_Posted
(Formal
) then
11660 goto Next_Parameter
;
11663 -- Force call by reference if aliased
11666 Conv
: constant Convention_Id
:= Convention
(Etype
(Formal
));
11668 if Is_Aliased
(Formal
) then
11669 Set_Mechanism
(Formal
, By_Reference
);
11671 -- Warn if user asked this to be passed by copy
11673 if Conv
= Convention_Ada_Pass_By_Copy
then
11675 ("cannot pass aliased parameter & by copy??", Formal
);
11678 -- Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
11680 elsif Conv
= Convention_Ada_Pass_By_Copy
then
11681 Set_Mechanism
(Formal
, By_Copy
);
11683 elsif Conv
= Convention_Ada_Pass_By_Reference
then
11684 Set_Mechanism
(Formal
, By_Reference
);
11692 if Present
(First_Out_Param
) and then Num_Out_Params
= 1 then
11693 Set_Is_Only_Out_Parameter
(First_Out_Param
);
11695 end Process_Formals
;
11697 ----------------------------
11698 -- Reference_Body_Formals --
11699 ----------------------------
11701 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
) is
11706 if Error_Posted
(Spec
) then
11710 -- Iterate over both lists. They may be of different lengths if the two
11711 -- specs are not conformant.
11713 Fs
:= First_Formal
(Spec
);
11714 Fb
:= First_Formal
(Bod
);
11715 while Present
(Fs
) and then Present
(Fb
) loop
11716 Generate_Reference
(Fs
, Fb
, 'b');
11718 if Style_Check
then
11719 Style
.Check_Identifier
(Fb
, Fs
);
11722 Set_Spec_Entity
(Fb
, Fs
);
11723 Set_Referenced
(Fs
, False);
11727 end Reference_Body_Formals
;
11729 -------------------------
11730 -- Set_Actual_Subtypes --
11731 -------------------------
11733 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
) is
11735 Formal
: Entity_Id
;
11737 First_Stmt
: Node_Id
:= Empty
;
11738 AS_Needed
: Boolean;
11741 -- If this is an empty initialization procedure, no need to create
11742 -- actual subtypes (small optimization).
11744 if Ekind
(Subp
) = E_Procedure
and then Is_Null_Init_Proc
(Subp
) then
11747 -- Within a predicate function we do not want to generate local
11748 -- subtypes that may generate nested predicate functions.
11750 elsif Is_Subprogram
(Subp
) and then Is_Predicate_Function
(Subp
) then
11754 -- The subtype declarations may freeze the formals. The body generated
11755 -- for an expression function is not a freeze point, so do not emit
11756 -- these declarations (small loss of efficiency in rare cases).
11758 if Nkind
(N
) = N_Subprogram_Body
11759 and then Was_Expression_Function
(N
)
11764 Formal
:= First_Formal
(Subp
);
11765 while Present
(Formal
) loop
11766 T
:= Etype
(Formal
);
11768 -- We never need an actual subtype for a constrained formal
11770 if Is_Constrained
(T
) then
11771 AS_Needed
:= False;
11773 -- If we have unknown discriminants, then we do not need an actual
11774 -- subtype, or more accurately we cannot figure it out. Note that
11775 -- all class-wide types have unknown discriminants.
11777 elsif Has_Unknown_Discriminants
(T
) then
11778 AS_Needed
:= False;
11780 -- At this stage we have an unconstrained type that may need an
11781 -- actual subtype. For sure the actual subtype is needed if we have
11782 -- an unconstrained array type. However, in an instance, the type
11783 -- may appear as a subtype of the full view, while the actual is
11784 -- in fact private (in which case no actual subtype is needed) so
11785 -- check the kind of the base type.
11787 elsif Is_Array_Type
(Base_Type
(T
)) then
11790 -- The only other case needing an actual subtype is an unconstrained
11791 -- record type which is an IN parameter (we cannot generate actual
11792 -- subtypes for the OUT or IN OUT case, since an assignment can
11793 -- change the discriminant values. However we exclude the case of
11794 -- initialization procedures, since discriminants are handled very
11795 -- specially in this context, see the section entitled "Handling of
11796 -- Discriminants" in Einfo.
11798 -- We also exclude the case of Discrim_SO_Functions (functions used
11799 -- in front-end layout mode for size/offset values), since in such
11800 -- functions only discriminants are referenced, and not only are such
11801 -- subtypes not needed, but they cannot always be generated, because
11802 -- of order of elaboration issues.
11804 elsif Is_Record_Type
(T
)
11805 and then Ekind
(Formal
) = E_In_Parameter
11806 and then Chars
(Formal
) /= Name_uInit
11807 and then not Is_Unchecked_Union
(T
)
11808 and then not Is_Discrim_SO_Function
(Subp
)
11812 -- All other cases do not need an actual subtype
11815 AS_Needed
:= False;
11818 -- Generate actual subtypes for unconstrained arrays and
11819 -- unconstrained discriminated records.
11822 if Nkind
(N
) = N_Accept_Statement
then
11824 -- If expansion is active, the formal is replaced by a local
11825 -- variable that renames the corresponding entry of the
11826 -- parameter block, and it is this local variable that may
11827 -- require an actual subtype.
11829 if Expander_Active
then
11830 Decl
:= Build_Actual_Subtype
(T
, Renamed_Object
(Formal
));
11832 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11835 if Present
(Handled_Statement_Sequence
(N
)) then
11837 First
(Statements
(Handled_Statement_Sequence
(N
)));
11838 Prepend
(Decl
, Statements
(Handled_Statement_Sequence
(N
)));
11839 Mark_Rewrite_Insertion
(Decl
);
11841 -- If the accept statement has no body, there will be no
11842 -- reference to the actuals, so no need to compute actual
11849 Decl
:= Build_Actual_Subtype
(T
, Formal
);
11850 Prepend
(Decl
, Declarations
(N
));
11851 Mark_Rewrite_Insertion
(Decl
);
11854 -- The declaration uses the bounds of an existing object, and
11855 -- therefore needs no constraint checks.
11857 Analyze
(Decl
, Suppress
=> All_Checks
);
11858 Set_Is_Actual_Subtype
(Defining_Identifier
(Decl
));
11860 -- We need to freeze manually the generated type when it is
11861 -- inserted anywhere else than in a declarative part.
11863 if Present
(First_Stmt
) then
11864 Insert_List_Before_And_Analyze
(First_Stmt
,
11865 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11867 -- Ditto if the type has a dynamic predicate, because the
11868 -- generated function will mention the actual subtype. The
11869 -- predicate may come from an explicit aspect of be inherited.
11871 elsif Has_Predicates
(T
) then
11872 Insert_List_Before_And_Analyze
(Decl
,
11873 Freeze_Entity
(Defining_Identifier
(Decl
), N
));
11876 if Nkind
(N
) = N_Accept_Statement
11877 and then Expander_Active
11879 Set_Actual_Subtype
(Renamed_Object
(Formal
),
11880 Defining_Identifier
(Decl
));
11882 Set_Actual_Subtype
(Formal
, Defining_Identifier
(Decl
));
11886 Next_Formal
(Formal
);
11888 end Set_Actual_Subtypes
;
11890 ---------------------
11891 -- Set_Formal_Mode --
11892 ---------------------
11894 procedure Set_Formal_Mode
(Formal_Id
: Entity_Id
) is
11895 Spec
: constant Node_Id
:= Parent
(Formal_Id
);
11896 Id
: constant Entity_Id
:= Scope
(Formal_Id
);
11899 -- Note: we set Is_Known_Valid for IN parameters and IN OUT parameters
11900 -- since we ensure that corresponding actuals are always valid at the
11901 -- point of the call.
11903 if Out_Present
(Spec
) then
11904 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
11905 or else Is_Subprogram_Or_Generic_Subprogram
(Id
)
11907 Set_Has_Out_Or_In_Out_Parameter
(Id
, True);
11910 if Ekind_In
(Id
, E_Function
, E_Generic_Function
) then
11912 -- [IN] OUT parameters allowed for functions in Ada 2012
11914 if Ada_Version
>= Ada_2012
then
11916 -- Even in Ada 2012 operators can only have IN parameters
11918 if Is_Operator_Symbol_Name
(Chars
(Scope
(Formal_Id
))) then
11919 Error_Msg_N
("operators can only have IN parameters", Spec
);
11922 if In_Present
(Spec
) then
11923 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11925 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11928 -- But not in earlier versions of Ada
11931 Error_Msg_N
("functions can only have IN parameters", Spec
);
11932 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11935 elsif In_Present
(Spec
) then
11936 Set_Ekind
(Formal_Id
, E_In_Out_Parameter
);
11939 Set_Ekind
(Formal_Id
, E_Out_Parameter
);
11940 Set_Never_Set_In_Source
(Formal_Id
, True);
11941 Set_Is_True_Constant
(Formal_Id
, False);
11942 Set_Current_Value
(Formal_Id
, Empty
);
11946 Set_Ekind
(Formal_Id
, E_In_Parameter
);
11949 -- Set Is_Known_Non_Null for access parameters since the language
11950 -- guarantees that access parameters are always non-null. We also set
11951 -- Can_Never_Be_Null, since there is no way to change the value.
11953 if Nkind
(Parameter_Type
(Spec
)) = N_Access_Definition
then
11955 -- Ada 2005 (AI-231): In Ada 95, access parameters are always non-
11956 -- null; In Ada 2005, only if then null_exclusion is explicit.
11958 if Ada_Version
< Ada_2005
11959 or else Can_Never_Be_Null
(Etype
(Formal_Id
))
11961 Set_Is_Known_Non_Null
(Formal_Id
);
11962 Set_Can_Never_Be_Null
(Formal_Id
);
11965 -- Ada 2005 (AI-231): Null-exclusion access subtype
11967 elsif Is_Access_Type
(Etype
(Formal_Id
))
11968 and then Can_Never_Be_Null
(Etype
(Formal_Id
))
11970 Set_Is_Known_Non_Null
(Formal_Id
);
11972 -- We can also set Can_Never_Be_Null (thus preventing some junk
11973 -- access checks) for the case of an IN parameter, which cannot
11974 -- be changed, or for an IN OUT parameter, which can be changed but
11975 -- not to a null value. But for an OUT parameter, the initial value
11976 -- passed in can be null, so we can't set this flag in that case.
11978 if Ekind
(Formal_Id
) /= E_Out_Parameter
then
11979 Set_Can_Never_Be_Null
(Formal_Id
);
11983 Set_Mechanism
(Formal_Id
, Default_Mechanism
);
11984 Set_Formal_Validity
(Formal_Id
);
11985 end Set_Formal_Mode
;
11987 -------------------------
11988 -- Set_Formal_Validity --
11989 -------------------------
11991 procedure Set_Formal_Validity
(Formal_Id
: Entity_Id
) is
11993 -- If no validity checking, then we cannot assume anything about the
11994 -- validity of parameters, since we do not know there is any checking
11995 -- of the validity on the call side.
11997 if not Validity_Checks_On
then
12000 -- If validity checking for parameters is enabled, this means we are
12001 -- not supposed to make any assumptions about argument values.
12003 elsif Validity_Check_Parameters
then
12006 -- If we are checking in parameters, we will assume that the caller is
12007 -- also checking parameters, so we can assume the parameter is valid.
12009 elsif Ekind
(Formal_Id
) = E_In_Parameter
12010 and then Validity_Check_In_Params
12012 Set_Is_Known_Valid
(Formal_Id
, True);
12014 -- Similar treatment for IN OUT parameters
12016 elsif Ekind
(Formal_Id
) = E_In_Out_Parameter
12017 and then Validity_Check_In_Out_Params
12019 Set_Is_Known_Valid
(Formal_Id
, True);
12021 end Set_Formal_Validity
;
12023 ------------------------
12024 -- Subtype_Conformant --
12025 ------------------------
12027 function Subtype_Conformant
12028 (New_Id
: Entity_Id
;
12029 Old_Id
: Entity_Id
;
12030 Skip_Controlling_Formals
: Boolean := False) return Boolean
12034 Check_Conformance
(New_Id
, Old_Id
, Subtype_Conformant
, False, Result
,
12035 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
12037 end Subtype_Conformant
;
12039 ---------------------
12040 -- Type_Conformant --
12041 ---------------------
12043 function Type_Conformant
12044 (New_Id
: Entity_Id
;
12045 Old_Id
: Entity_Id
;
12046 Skip_Controlling_Formals
: Boolean := False) return Boolean
12050 May_Hide_Profile
:= False;
12052 (New_Id
, Old_Id
, Type_Conformant
, False, Result
,
12053 Skip_Controlling_Formals
=> Skip_Controlling_Formals
);
12055 end Type_Conformant
;
12057 -------------------------------
12058 -- Valid_Operator_Definition --
12059 -------------------------------
12061 procedure Valid_Operator_Definition
(Designator
: Entity_Id
) is
12064 Id
: constant Name_Id
:= Chars
(Designator
);
12068 F
:= First_Formal
(Designator
);
12069 while Present
(F
) loop
12072 if Present
(Default_Value
(F
)) then
12074 ("default values not allowed for operator parameters",
12077 -- For function instantiations that are operators, we must check
12078 -- separately that the corresponding generic only has in-parameters.
12079 -- For subprogram declarations this is done in Set_Formal_Mode. Such
12080 -- an error could not arise in earlier versions of the language.
12082 elsif Ekind
(F
) /= E_In_Parameter
then
12083 Error_Msg_N
("operators can only have IN parameters", F
);
12089 -- Verify that user-defined operators have proper number of arguments
12090 -- First case of operators which can only be unary
12092 if Nam_In
(Id
, Name_Op_Not
, Name_Op_Abs
) then
12095 -- Case of operators which can be unary or binary
12097 elsif Nam_In
(Id
, Name_Op_Add
, Name_Op_Subtract
) then
12098 N_OK
:= (N
in 1 .. 2);
12100 -- All other operators can only be binary
12108 ("incorrect number of arguments for operator", Designator
);
12112 and then Base_Type
(Etype
(Designator
)) = Standard_Boolean
12113 and then not Is_Intrinsic_Subprogram
(Designator
)
12116 ("explicit definition of inequality not allowed", Designator
);
12118 end Valid_Operator_Definition
;