Debian Codegraph @

gcc/ada/sem_ch6.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 6 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Types; use Types;
27 package Sem_Ch6 is
28
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.
36
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);
48
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
52 -- specification N.
53
54 procedure Analyze_SPARK_Subprogram_Specification (N : Node_Id);
55 -- Check SPARK legality rules that require that the specification has been
56 -- analyzed already.
57
58 function Can_Override_Operator (Subp : Entity_Id) return Boolean;
59 -- Returns true if Subp can override a predefined operator
60
61 procedure Check_Conventions (Typ : Entity_Id);
62 -- Ada 2005 (AI-430): Check that the conventions of all inherited and
63 -- overridden dispatching operations of type Typ are consistent with their
64 -- respective counterparts.
65
66 procedure Check_Delayed_Subprogram (Designator : Entity_Id);
67 -- Designator can be a E_Subprogram_Type, E_Procedure or E_Function. Set
68 -- Has_Delayed_Freeze on Designator if its freezing needs to be delayed.
69
70 procedure Check_Discriminant_Conformance
71 (N : Node_Id;
72 Prev : Entity_Id;
73 Prev_Loc : Node_Id);
74 -- Check that the discriminants of a full type N fully conform to the
75 -- discriminants of the corresponding partial view Prev. Prev_Loc indicates
76 -- the source location of the partial view, which may be different than
77 -- Prev in the case of private types.
78
79 procedure Check_Formal_Subprogram_Conformance
80 (New_Id : Entity_Id;
81 Old_Id : Entity_Id;
82 Err_Loc : Node_Id := Empty);
83 -- Check RM 6.3.1(17/3): the profile of a generic formal subprogram is not
84 -- subtype conformant with any other profile and post an error message if
85 -- either New_Id or Old_Id denotes a formal subprogram, with the flag being
86 -- placed on the Err_Loc node if it is specified, and on New_Id if not. See
87 -- also spec of Check_Fully_Conformant below for New_Id and Old_Id usage.
88
89 procedure Check_Fully_Conformant
90 (New_Id : Entity_Id;
91 Old_Id : Entity_Id;
92 Err_Loc : Node_Id := Empty);
93 -- Check that two callable entities (subprograms, entries, literals)
94 -- are fully conformant, post error message if not (RM 6.3.1(17)) with
95 -- the flag being placed on the Err_Loc node if it is specified, and
96 -- on the appropriate component of the New_Id construct if not. Note:
97 -- when checking spec/body conformance, New_Id must be the body entity
98 -- and Old_Id is the spec entity (the code in the implementation relies
99 -- on this ordering, and in any case, this makes sense, since if flags
100 -- are to be placed on the construct, they clearly belong on the body.
101
102 procedure Check_Mode_Conformant
103 (New_Id : Entity_Id;
104 Old_Id : Entity_Id;
105 Err_Loc : Node_Id := Empty;
106 Get_Inst : Boolean := False);
107 -- Check that two callable entities (subprograms, entries, literals)
108 -- are mode conformant, post error message if not (RM 6.3.1(15)) with
109 -- the flag being placed on the Err_Loc node if it is specified, and
110 -- on the appropriate component of the New_Id construct if not. The
111 -- argument Get_Inst is set to True when this is a check against a
112 -- formal access-to-subprogram type, indicating that mapping of types
113 -- is needed.
114
115 procedure Check_Overriding_Indicator
116 (Subp : Entity_Id;
117 Overridden_Subp : Entity_Id;
118 Is_Primitive : Boolean);
119 -- Verify the consistency of an overriding_indicator given for subprogram
120 -- declaration, body, renaming, or instantiation. Overridden_Subp is set
121 -- if the scope where we are introducing the subprogram contains a
122 -- type-conformant subprogram that becomes hidden by the new subprogram.
123 -- Is_Primitive indicates whether the subprogram is primitive.
124
125 procedure Check_Subtype_Conformant
126 (New_Id : Entity_Id;
127 Old_Id : Entity_Id;
128 Err_Loc : Node_Id := Empty;
129 Skip_Controlling_Formals : Boolean := False;
130 Get_Inst : Boolean := False);
131 -- Check that two callable entities (subprograms, entries, literals)
132 -- are subtype conformant, post error message if not (RM 6.3.1(16)),
133 -- the flag being placed on the Err_Loc node if it is specified, and
134 -- on the appropriate component of the New_Id construct if not.
135 -- Skip_Controlling_Formals is True when checking the conformance of
136 -- a subprogram that implements an interface operation. In that case,
137 -- only the non-controlling formals can (and must) be examined. The
138 -- argument Get_Inst is set to True when this is a check against a
139 -- formal access-to-subprogram type, indicating that mapping of types
140 -- is needed.
141
142 procedure Check_Synchronized_Overriding
143 (Def_Id : Entity_Id;
144 Overridden_Subp : out Entity_Id);
145 -- First determine if Def_Id is an entry or a subprogram either defined in
146 -- the scope of a task or protected type, or that is a primitive of such
147 -- a type. Check whether Def_Id overrides a subprogram of an interface
148 -- implemented by the synchronized type, returning the overridden entity
149 -- or Empty.
150
151 procedure Check_Type_Conformant
152 (New_Id : Entity_Id;
153 Old_Id : Entity_Id;
154 Err_Loc : Node_Id := Empty);
155 -- Check that two callable entities (subprograms, entries, literals)
156 -- are type conformant, post error message if not (RM 6.3.1(14)) with
157 -- the flag being placed on the Err_Loc node if it is specified, and
158 -- on the appropriate component of the New_Id construct if not.
159
160 function Conforming_Types
161 (T1 : Entity_Id;
162 T2 : Entity_Id;
163 Ctype : Conformance_Type;
164 Get_Inst : Boolean := False) return Boolean;
165 -- Check that the types of two formal parameters are conforming. In most
166 -- cases this is just a name comparison, but within an instance it involves
167 -- generic actual types, and in the presence of anonymous access types
168 -- it must examine the designated types. The argument Get_Inst is set to
169 -- True when this is a check against a formal access-to-subprogram type,
170 -- indicating that mapping of types is needed.
171
172 procedure Create_Extra_Formals (E : Entity_Id);
173 -- For each parameter of a subprogram or entry that requires an additional
174 -- formal (such as for access parameters and indefinite discriminated
175 -- parameters), creates the appropriate formal and attach it to its
176 -- associated parameter. Each extra formal will also be appended to
177 -- the end of Subp's parameter list (with each subsequent extra formal
178 -- being attached to the preceding extra formal).
179
180 function Extra_Formals_Match_OK
181 (E : Entity_Id;
182 Ref_E : Entity_Id) return Boolean;
183 -- Return True if the extra formals of the given entities match. E is a
184 -- subprogram, and Ref_E is the reference entity that will be used to check
185 -- the extra formals of E: a subprogram type or another subprogram. For
186 -- example, if E is a dispatching primitive of a tagged type then Ref_E
187 -- may be the overridden primitive of its parent type or its ultimate
188 -- renamed entity; however, if E is a subprogram to which 'Access is
189 -- applied then Ref_E is its corresponding subprogram type. Used in
190 -- assertions.
191
192 function Extra_Formals_OK (E : Entity_Id) return Boolean;
193 -- Return True if the decoration of the attributes associated with extra
194 -- formals are properly set. Used in assertions.
195
196 function Find_Corresponding_Spec
197 (N : Node_Id;
198 Post_Error : Boolean := True) return Entity_Id;
199 -- Use the subprogram specification in the body to retrieve the previous
200 -- subprogram declaration, if any.
201
202 function Fully_Conformant (New_Id, Old_Id : Entity_Id) return Boolean;
203 -- Determine whether two callable entities (subprograms, entries,
204 -- literals) are fully conformant (RM 6.3.1(17))
205
206 function Fully_Conformant_Expressions
207 (Given_E1 : Node_Id;
208 Given_E2 : Node_Id;
209 Report : Boolean := False) return Boolean;
210 -- Determines if two (non-empty) expressions are fully conformant
211 -- as defined by (RM 6.3.1(18-21))
212
213 function Fully_Conformant_Discrete_Subtypes
214 (Given_S1 : Node_Id;
215 Given_S2 : Node_Id) return Boolean;
216 -- Determines if two subtype definitions are fully conformant. Used
217 -- for entry family conformance checks (RM 6.3.1 (24)).
218
219 function Has_BIP_Formals (E : Entity_Id) return Boolean;
220 -- Determines if a given entity has build-in-place formals
221
222 procedure Install_Entity (E : Entity_Id);
223 -- Place a single entity on the visibility chain
224
225 procedure Install_Formals (Id : Entity_Id);
226 -- On entry to a subprogram body, make the formals visible. Note that
227 -- simply placing the subprogram on the scope stack is not sufficient:
228 -- the formals must become the current entities for their names. This
229 -- procedure is also used to get visibility to the formals when analyzing
230 -- preconditions and postconditions appearing in the spec.
231
232 function Is_Interface_Conformant
233 (Tagged_Type : Entity_Id;
234 Iface_Prim : Entity_Id;
235 Prim : Entity_Id) return Boolean;
236 -- Returns true if both primitives have a matching name (including support
237 -- for names of inherited private primitives --which have suffix 'P'), they
238 -- are type conformant, and Prim is defined in the scope of Tagged_Type.
239 -- Special management is done for functions returning interfaces.
240
241 procedure List_Inherited_Pre_Post_Aspects (E : Entity_Id);
242 -- E is the entity for a subprogram or generic subprogram spec. This call
243 -- lists all inherited Pre/Post aspects if List_Inherited_Pre_Post is True.
244
245 procedure May_Need_Actuals (Fun : Entity_Id);
246 -- Flag functions that can be called without parameters, i.e. those that
247 -- have no parameters, or those for which defaults exist for all parameters
248 -- Used for subprogram declarations and for access subprogram declarations,
249 -- where they apply to the anonymous designated type. On return the flag
250 -- Set_Needs_No_Actuals is set appropriately in Fun.
251
252 function Mode_Conformant (New_Id, Old_Id : Entity_Id) return Boolean;
253 -- Determine whether two callable entities (subprograms, entries,
254 -- literals) are mode conformant (RM 6.3.1(15))
255
256 procedure New_Overloaded_Entity
257 (S : Entity_Id;
258 Derived_Type : Entity_Id := Empty);
259 -- Process new overloaded entity. Overloaded entities are created by
260 -- enumeration type declarations, subprogram specifications, entry
261 -- declarations, and (implicitly) by type derivations. If Derived_Type
262 -- is non-empty then this is a subprogram derived for that type.
263
264 procedure Process_Formals (T : List_Id; Related_Nod : Node_Id);
265 -- Enter the formals in the scope of the subprogram or entry, and
266 -- analyze default expressions if any. The implicit types created for
267 -- access parameter are attached to the Related_Nod which comes from the
268 -- context.
269
270 procedure Reference_Body_Formals (Spec : Entity_Id; Bod : Entity_Id);
271 -- If there is a separate spec for a subprogram or generic subprogram, the
272 -- formals of the body are treated as references to the corresponding
273 -- formals of the spec. This reference does not count as an actual use of
274 -- the formal, in order to diagnose formals that are unused in the body.
275 -- This procedure is also used in renaming_as_body declarations, where
276 -- the formals of the specification must be treated as body formals that
277 -- correspond to the previous subprogram declaration, and not as new
278 -- entities with their defining entry in the cross-reference information.
279
280 procedure Set_Actual_Subtypes (N : Node_Id; Subp : Entity_Id);
281 -- If the formals of a subprogram are unconstrained, build a subtype
282 -- declaration that uses the bounds or discriminants of the actual to
283 -- construct an actual subtype for them. This is an optimization that
284 -- is done only in some cases where the actual subtype cannot change
285 -- during execution of the subprogram. By setting the actual subtype
286 -- once, we avoid recomputing it unnecessarily.
287
288 function Subtype_Conformant
289 (New_Id : Entity_Id;
290 Old_Id : Entity_Id;
291 Skip_Controlling_Formals : Boolean := False) return Boolean;
292 -- Determine whether two callable entities (subprograms, entries, literals)
293 -- are subtype conformant (RM 6.3.1(16)). Skip_Controlling_Formals is True
294 -- when checking the conformance of a subprogram that implements an
295 -- interface operation. In that case, only the non-controlling formals
296 -- can (and must) be examined.
297
298 function Type_Conformant
299 (New_Id : Entity_Id;
300 Old_Id : Entity_Id;
301 Skip_Controlling_Formals : Boolean := False) return Boolean;
302 -- Determine whether two callable entities (subprograms, entries, literals)
303 -- are type conformant (RM 6.3.1(14)). Skip_Controlling_Formals is True
304 -- when checking the conformance of a subprogram that implements an
305 -- interface operation. In that case, only the non-controlling formals
306 -- can (and must) be examined.
307
308 procedure Valid_Operator_Definition (Designator : Entity_Id);
309 -- Verify that an operator definition has the proper number of formals
310
311 end Sem_Ch6;