1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Types
; use Types
;
29 type Conformance_Type
is
30 (Type_Conformant
, Mode_Conformant
, Subtype_Conformant
, Fully_Conformant
);
31 pragma Ordered
(Conformance_Type
);
32 -- Conformance type used in conformance checks between specs and bodies,
33 -- and for overriding. The literals match the RM definitions of the
34 -- corresponding terms. This is an ordered type, since each conformance
35 -- type is stronger than the ones preceding it.
37 procedure Analyze_Abstract_Subprogram_Declaration
(N
: Node_Id
);
38 procedure Analyze_Expression_Function
(N
: Node_Id
);
39 procedure Analyze_Extended_Return_Statement
(N
: Node_Id
);
40 procedure Analyze_Function_Call
(N
: Node_Id
);
41 procedure Analyze_Operator_Symbol
(N
: Node_Id
);
42 procedure Analyze_Parameter_Association
(N
: Node_Id
);
43 procedure Analyze_Procedure_Call
(N
: Node_Id
);
44 procedure Analyze_Return_When_Statement
(N
: Node_Id
);
45 procedure Analyze_Simple_Return_Statement
(N
: Node_Id
);
46 procedure Analyze_Subprogram_Declaration
(N
: Node_Id
);
47 procedure Analyze_Subprogram_Body
(N
: Node_Id
);
49 function Analyze_Subprogram_Specification
(N
: Node_Id
) return Entity_Id
;
50 -- Analyze subprogram specification in both subprogram declarations
51 -- and body declarations. Returns the defining entity for the
54 function Can_Override_Operator
(Subp
: Entity_Id
) return Boolean;
55 -- Returns true if Subp can override a predefined operator
57 procedure Check_Conventions
(Typ
: Entity_Id
);
58 -- Ada 2005 (AI-430): Check that the conventions of all inherited and
59 -- overridden dispatching operations of type Typ are consistent with their
60 -- respective counterparts.
62 procedure Check_Delayed_Subprogram
(Designator
: Entity_Id
);
63 -- Designator can be a E_Subprogram_Type, E_Procedure or E_Function. If a
64 -- type in its profile depends on a private type without a full
65 -- declaration, indicate that the subprogram or type is delayed.
67 procedure Check_Discriminant_Conformance
71 -- Check that the discriminants of a full type N fully conform to the
72 -- discriminants of the corresponding partial view Prev. Prev_Loc indicates
73 -- the source location of the partial view, which may be different than
74 -- Prev in the case of private types.
76 procedure Check_Formal_Subprogram_Conformance
79 Err_Loc
: Node_Id
:= Empty
);
80 -- Check RM 6.3.1(17/3): the profile of a generic formal subprogram is not
81 -- subtype conformant with any other profile and post an error message if
82 -- either New_Id or Old_Id denotes a formal subprogram, with the flag being
83 -- placed on the Err_Loc node if it is specified, and on New_Id if not. See
84 -- also spec of Check_Fully_Conformant below for New_Id and Old_Id usage.
86 procedure Check_Fully_Conformant
89 Err_Loc
: Node_Id
:= Empty
);
90 -- Check that two callable entities (subprograms, entries, literals)
91 -- are fully conformant, post error message if not (RM 6.3.1(17)) with
92 -- the flag being placed on the Err_Loc node if it is specified, and
93 -- on the appropriate component of the New_Id construct if not. Note:
94 -- when checking spec/body conformance, New_Id must be the body entity
95 -- and Old_Id is the spec entity (the code in the implementation relies
96 -- on this ordering, and in any case, this makes sense, since if flags
97 -- are to be placed on the construct, they clearly belong on the body.
99 procedure Check_Mode_Conformant
102 Err_Loc
: Node_Id
:= Empty
;
103 Get_Inst
: Boolean := False);
104 -- Check that two callable entities (subprograms, entries, literals)
105 -- are mode conformant, post error message if not (RM 6.3.1(15)) with
106 -- the flag being placed on the Err_Loc node if it is specified, and
107 -- on the appropriate component of the New_Id construct if not. The
108 -- argument Get_Inst is set to True when this is a check against a
109 -- formal access-to-subprogram type, indicating that mapping of types
112 procedure Check_Overriding_Indicator
114 Overridden_Subp
: Entity_Id
;
115 Is_Primitive
: Boolean);
116 -- Verify the consistency of an overriding_indicator given for subprogram
117 -- declaration, body, renaming, or instantiation. Overridden_Subp is set
118 -- if the scope where we are introducing the subprogram contains a
119 -- type-conformant subprogram that becomes hidden by the new subprogram.
120 -- Is_Primitive indicates whether the subprogram is primitive.
122 procedure Check_Subtype_Conformant
125 Err_Loc
: Node_Id
:= Empty
;
126 Skip_Controlling_Formals
: Boolean := False;
127 Get_Inst
: Boolean := False);
128 -- Check that two callable entities (subprograms, entries, literals)
129 -- are subtype conformant, post error message if not (RM 6.3.1(16)),
130 -- the flag being placed on the Err_Loc node if it is specified, and
131 -- on the appropriate component of the New_Id construct if not.
132 -- Skip_Controlling_Formals is True when checking the conformance of
133 -- a subprogram that implements an interface operation. In that case,
134 -- only the non-controlling formals can (and must) be examined. The
135 -- argument Get_Inst is set to True when this is a check against a
136 -- formal access-to-subprogram type, indicating that mapping of types
139 procedure Check_Synchronized_Overriding
141 Overridden_Subp
: out Entity_Id
);
142 -- First determine if Def_Id is an entry or a subprogram either defined in
143 -- the scope of a task or protected type, or that is a primitive of such
144 -- a type. Check whether Def_Id overrides a subprogram of an interface
145 -- implemented by the synchronized type, returning the overridden entity
148 procedure Check_Type_Conformant
151 Err_Loc
: Node_Id
:= Empty
);
152 -- Check that two callable entities (subprograms, entries, literals)
153 -- are type conformant, post error message if not (RM 6.3.1(14)) with
154 -- the flag being placed on the Err_Loc node if it is specified, and
155 -- on the appropriate component of the New_Id construct if not.
157 function Conforming_Types
160 Ctype
: Conformance_Type
;
161 Get_Inst
: Boolean := False) return Boolean;
162 -- Check that the types of two formal parameters are conforming. In most
163 -- cases this is just a name comparison, but within an instance it involves
164 -- generic actual types, and in the presence of anonymous access types
165 -- it must examine the designated types. The argument Get_Inst is set to
166 -- True when this is a check against a formal access-to-subprogram type,
167 -- indicating that mapping of types is needed.
169 procedure Create_Extra_Formals
(E
: Entity_Id
);
170 -- For each parameter of a subprogram or entry that requires an additional
171 -- formal (such as for access parameters and indefinite discriminated
172 -- parameters), creates the appropriate formal and attach it to its
173 -- associated parameter. Each extra formal will also be appended to
174 -- the end of Subp's parameter list (with each subsequent extra formal
175 -- being attached to the preceding extra formal).
177 function Extra_Formals_Match_OK
179 Ref_E
: Entity_Id
) return Boolean;
180 -- Return True if the extra formals of the given entities match. E is a
181 -- subprogram, and Ref_E is the reference entity that will be used to check
182 -- the extra formals of E: a subprogram type or another subprogram. For
183 -- example, if E is a dispatching primitive of a tagged type then Ref_E
184 -- may be the overridden primitive of its parent type or its ultimate
185 -- renamed entity; however, if E is a subprogram to which 'Access is
186 -- applied then Ref_E is its corresponding subprogram type. Used in
189 function Extra_Formals_OK
(E
: Entity_Id
) return Boolean;
190 -- Return True if the decoration of the attributes associated with extra
191 -- formals are properly set. Used in assertions.
193 function Find_Corresponding_Spec
195 Post_Error
: Boolean := True) return Entity_Id
;
196 -- Use the subprogram specification in the body to retrieve the previous
197 -- subprogram declaration, if any.
199 function Fully_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean;
200 -- Determine whether two callable entities (subprograms, entries,
201 -- literals) are fully conformant (RM 6.3.1(17))
203 function Fully_Conformant_Expressions
206 Report
: Boolean := False) return Boolean;
207 -- Determines if two (non-empty) expressions are fully conformant
208 -- as defined by (RM 6.3.1(18-21))
210 function Fully_Conformant_Discrete_Subtypes
212 Given_S2
: Node_Id
) return Boolean;
213 -- Determines if two subtype definitions are fully conformant. Used
214 -- for entry family conformance checks (RM 6.3.1 (24)).
216 function Has_BIP_Formals
(E
: Entity_Id
) return Boolean;
217 -- Determines if a given entity has build-in-place formals
219 procedure Install_Entity
(E
: Entity_Id
);
220 -- Place a single entity on the visibility chain
222 procedure Install_Formals
(Id
: Entity_Id
);
223 -- On entry to a subprogram body, make the formals visible. Note that
224 -- simply placing the subprogram on the scope stack is not sufficient:
225 -- the formals must become the current entities for their names. This
226 -- procedure is also used to get visibility to the formals when analyzing
227 -- preconditions and postconditions appearing in the spec.
229 function Is_Interface_Conformant
230 (Tagged_Type
: Entity_Id
;
231 Iface_Prim
: Entity_Id
;
232 Prim
: Entity_Id
) return Boolean;
233 -- Returns true if both primitives have a matching name (including support
234 -- for names of inherited private primitives --which have suffix 'P'), they
235 -- are type conformant, and Prim is defined in the scope of Tagged_Type.
236 -- Special management is done for functions returning interfaces.
238 procedure List_Inherited_Pre_Post_Aspects
(E
: Entity_Id
);
239 -- E is the entity for a subprogram or generic subprogram spec. This call
240 -- lists all inherited Pre/Post aspects if List_Inherited_Pre_Post is True.
242 procedure May_Need_Actuals
(Fun
: Entity_Id
);
243 -- Flag functions that can be called without parameters, i.e. those that
244 -- have no parameters, or those for which defaults exist for all parameters
245 -- Used for subprogram declarations and for access subprogram declarations,
246 -- where they apply to the anonymous designated type. On return the flag
247 -- Set_Needs_No_Actuals is set appropriately in Fun.
249 function Mode_Conformant
(New_Id
, Old_Id
: Entity_Id
) return Boolean;
250 -- Determine whether two callable entities (subprograms, entries,
251 -- literals) are mode conformant (RM 6.3.1(15))
253 procedure New_Overloaded_Entity
255 Derived_Type
: Entity_Id
:= Empty
);
256 -- Process new overloaded entity. Overloaded entities are created by
257 -- enumeration type declarations, subprogram specifications, entry
258 -- declarations, and (implicitly) by type derivations. If Derived_Type
259 -- is non-empty then this is a subprogram derived for that type.
261 procedure Process_Formals
(T
: List_Id
; Related_Nod
: Node_Id
);
262 -- Enter the formals in the scope of the subprogram or entry, and
263 -- analyze default expressions if any. The implicit types created for
264 -- access parameter are attached to the Related_Nod which comes from the
267 procedure Reference_Body_Formals
(Spec
: Entity_Id
; Bod
: Entity_Id
);
268 -- If there is a separate spec for a subprogram or generic subprogram, the
269 -- formals of the body are treated as references to the corresponding
270 -- formals of the spec. This reference does not count as an actual use of
271 -- the formal, in order to diagnose formals that are unused in the body.
272 -- This procedure is also used in renaming_as_body declarations, where
273 -- the formals of the specification must be treated as body formals that
274 -- correspond to the previous subprogram declaration, and not as new
275 -- entities with their defining entry in the cross-reference information.
277 procedure Set_Actual_Subtypes
(N
: Node_Id
; Subp
: Entity_Id
);
278 -- If the formals of a subprogram are unconstrained, build a subtype
279 -- declaration that uses the bounds or discriminants of the actual to
280 -- construct an actual subtype for them. This is an optimization that
281 -- is done only in some cases where the actual subtype cannot change
282 -- during execution of the subprogram. By setting the actual subtype
283 -- once, we avoid recomputing it unnecessarily.
285 function Subtype_Conformant
288 Skip_Controlling_Formals
: Boolean := False) return Boolean;
289 -- Determine whether two callable entities (subprograms, entries, literals)
290 -- are subtype conformant (RM 6.3.1(16)). Skip_Controlling_Formals is True
291 -- when checking the conformance of a subprogram that implements an
292 -- interface operation. In that case, only the non-controlling formals
293 -- can (and must) be examined.
295 function Type_Conformant
298 Skip_Controlling_Formals
: Boolean := False) return Boolean;
299 -- Determine whether two callable entities (subprograms, entries, literals)
300 -- are type conformant (RM 6.3.1(14)). Skip_Controlling_Formals is True
301 -- when checking the conformance of a subprogram that implements an
302 -- interface operation. In that case, only the non-controlling formals
303 -- can (and must) be examined.
305 procedure Valid_Operator_Definition
(Designator
: Entity_Id
);
306 -- Verify that an operator definition has the proper number of formals