Debian Codegraph @

gcc/ada/sem_ch3.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 3 --
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
28 package Sem_Ch3 is
29 procedure Analyze_Component_Declaration (N : Node_Id);
30 procedure Analyze_Full_Type_Declaration (N : Node_Id);
31 procedure Analyze_Incomplete_Type_Decl (N : Node_Id);
32 procedure Analyze_Itype_Reference (N : Node_Id);
33 procedure Analyze_Number_Declaration (N : Node_Id);
34 procedure Analyze_Object_Declaration (N : Node_Id);
35 procedure Analyze_Others_Choice (N : Node_Id);
36 procedure Analyze_Private_Extension_Declaration (N : Node_Id);
37 procedure Analyze_Subtype_Indication (N : Node_Id);
38 procedure Analyze_Variant_Part (N : Node_Id);
39
40 procedure Analyze_Subtype_Declaration
41 (N : Node_Id;
42 Skip : Boolean := False);
43 -- Called to analyze a subtype declaration. The parameter Skip is used for
44 -- Ada 2005 (AI-412). We set to True in order to avoid reentering the
45 -- defining identifier of N when analyzing a rewritten incomplete subtype
46 -- declaration.
47
48 function Access_Definition
49 (Related_Nod : Node_Id;
50 N : Node_Id) return Entity_Id;
51 -- An access definition defines a general access type for a formal
52 -- parameter. The procedure is called when processing formals, when the
53 -- current scope is the subprogram. The Implicit type is attached to the
54 -- Related_Nod put into the enclosing scope, so that the only entities
55 -- defined in the spec are the formals themselves.
56
57 procedure Access_Subprogram_Declaration
58 (T_Name : Entity_Id;
59 T_Def : Node_Id);
60 -- The subprogram specification yields the signature of an implicit
61 -- type, whose Ekind is Access_Subprogram_Type. This implicit type is the
62 -- designated type of the declared access type. In subprogram calls, the
63 -- signature of the implicit type works like the profile of a regular
64 -- subprogram.
65
66 procedure Add_Internal_Interface_Entities (Tagged_Type : Entity_Id);
67 -- Add to the list of primitives of Tagged_Type the internal entities
68 -- associated with covered interface primitives. These entities link the
69 -- interface primitives with the tagged type primitives that cover them.
70
71 procedure Analyze_Declarations (L : List_Id);
72 -- Called to analyze a list of declarations. Also performs necessary
73 -- freezing actions (such as freezing remaining unfrozen entities at
74 -- the end of declarative parts), resolves usage names in aspects, and
75 -- analyzes contracts that require delay until after freezing is done.
76
77 procedure Analyze_Interface_Declaration (T : Entity_Id; Def : Node_Id);
78 -- Analyze an interface declaration or a formal interface declaration
79
80 procedure Array_Type_Declaration (T : in out Entity_Id; Def : Node_Id);
81 -- Process an array type declaration. If the array is constrained, we
82 -- create an implicit parent array type, with the same index types and
83 -- component type.
84
85 procedure Access_Type_Declaration (T : Entity_Id; Def : Node_Id);
86 -- Process an access type declaration
87
88 procedure Build_Access_Subprogram_Wrapper (Decl : Node_Id);
89 -- When an access-to-subprogram type has pre/postconditions, we build a
90 -- subprogram that includes these contracts and is invoked by an indirect
91 -- call through the corresponding access type.
92
93 procedure Build_Itype_Reference (Ityp : Entity_Id; Nod : Node_Id);
94 -- Create a reference to an internal type, for use by Gigi. The back-end
95 -- elaborates itypes on demand, i.e. when their first use is seen. This can
96 -- lead to scope anomalies if the first use is within a scope that is
97 -- nested within the scope that contains the point of definition of the
98 -- itype. The Itype_Reference node forces the elaboration of the itype
99 -- in the proper scope. The node is inserted after Nod, which is the
100 -- enclosing declaration that generated Ityp.
101 --
102 -- A related mechanism is used during expansion, for itypes created in
103 -- branches of conditionals. See Ensure_Defined in exp_util. Could both
104 -- mechanisms be merged ???
105
106 procedure Check_Abstract_Overriding (T : Entity_Id);
107 -- Check that all abstract subprograms inherited from T's parent type have
108 -- been overridden as required, and that nonabstract subprograms have not
109 -- been incorrectly overridden with an abstract subprogram.
110
111 procedure Check_Aliased_Component_Types (T : Entity_Id);
112 -- Given an array type or record type T, check that if the type is
113 -- nonlimited, then the nominal subtype of any components of T that
114 -- have discriminants must be constrained.
115
116 procedure Check_Completion (Body_Id : Node_Id := Empty);
117 -- At the end of a declarative part, verify that all entities that require
118 -- completion have received one. If Body_Id is absent, the error indicating
119 -- a missing completion is placed on the declaration that needs completion.
120 -- If Body_Id is present, it is the defining identifier of a package body,
121 -- and errors are posted on that node, rather than on the declarations that
122 -- require completion in the package declaration.
123
124 procedure Check_CPP_Type_Has_No_Defaults (T : Entity_Id);
125 -- Check that components of imported CPP type T do not have default
126 -- expressions because the constructor (if any) is on the C++ side.
127
128 procedure Derive_Subprogram
129 (New_Subp : out Entity_Id;
130 Parent_Subp : Entity_Id;
131 Derived_Type : Entity_Id;
132 Parent_Type : Entity_Id;
133 Actual_Subp : Entity_Id := Empty);
134 -- Derive the subprogram Parent_Subp from Parent_Type, and replace the
135 -- subsidiary subtypes with the derived type to build the specification of
136 -- the inherited subprogram (returned in New_Subp). For tagged types, the
137 -- derived subprogram is aliased to that of the actual (in the case where
138 -- Actual_Subp is nonempty) rather than to the corresponding subprogram of
139 -- the parent type.
140
141 procedure Derive_Subprograms
142 (Parent_Type : Entity_Id;
143 Derived_Type : Entity_Id;
144 Generic_Actual : Entity_Id := Empty);
145 -- To complete type derivation, collect/retrieve the primitive operations
146 -- of the parent type, and replace the subsidiary subtypes with the derived
147 -- type, to build the specs of the inherited ops. For generic actuals, the
148 -- mapping of the primitive operations to those of the parent type is also
149 -- done by rederiving the operations within the instance. For tagged types,
150 -- the derived subprograms are aliased to those of the actual, not those of
151 -- the ancestor.
152 --
153 -- Note: one might expect this to be private to the package body, but there
154 -- is one rather unusual usage in package Exp_Dist.
155
156 function Find_Hidden_Interface
157 (Src : Elist_Id;
158 Dest : Elist_Id) return Entity_Id;
159 -- Ada 2005: Determine whether the interfaces in list Src are all present
160 -- in the list Dest. Return the first differing interface, or Empty
161 -- otherwise.
162
163 function Find_Type_Of_Subtype_Indic (S : Node_Id) return Entity_Id;
164 -- Given a subtype indication S (which is really an N_Subtype_Indication
165 -- node or a plain N_Identifier), find the type of the subtype mark.
166
167 function Find_Type_Name (N : Node_Id) return Entity_Id;
168 -- Enter the identifier in a type definition, or find the entity already
169 -- declared, in the case of the full declaration of an incomplete or
170 -- private type. If the previous declaration is tagged then the class-wide
171 -- entity is propagated to the identifier to prevent multiple incompatible
172 -- class-wide types that may be created for self-referential anonymous
173 -- access components.
174
175 function Get_Discriminant_Value
176 (Discriminant : Entity_Id;
177 Typ_For_Constraint : Entity_Id;
178 Constraint : Elist_Id) return Node_Id;
179 -- Given a discriminant Discriminant occurring somewhere up the derivation
180 -- tree from Typ_For_Constraint and a Constraint, return the expression
181 -- corresponding to that discriminant in the constraint that specifies its
182 -- value.
183
184 function Is_Visible_Component
185 (C : Entity_Id;
186 N : Node_Id := Empty) return Boolean;
187 -- Determines if a record component C is visible in the present context.
188 -- Note that even though component C could appear in the entity chain of a
189 -- record type, C may not be visible in the current context. For instance,
190 -- C may be a component inherited in the full view of a private extension
191 -- which is not visible in the current context.
192 --
193 -- If present, N is the selected component of which C is the selector. If
194 -- the prefix of N is a type conversion inserted for a discriminant check,
195 -- C is automatically visible.
196
197 procedure Make_Index
198 (N : Node_Id;
199 Related_Nod : Node_Id;
200 Related_Id : Entity_Id := Empty;
201 Suffix_Index : Pos := 1);
202 -- Process an index that is given in an array declaration, an entry
203 -- family declaration or a loop iteration. The index is given by an index
204 -- declaration (a 'box'), or by a discrete range. The later can be the name
205 -- of a discrete type, or a subtype indication.
206 --
207 -- Related_Nod is the node where the potential generated implicit types
208 -- will be inserted. The next last parameters are used for creating the
209 -- name.
210
211 procedure Make_Class_Wide_Type (T : Entity_Id);
212 -- A Class_Wide_Type is created for each tagged type definition. The
213 -- attributes of a class-wide type are inherited from those of the type T.
214 -- If T is introduced by a private declaration, the corresponding class
215 -- wide type is created at the same time, and therefore there is a private
216 -- and a full declaration for the class-wide type as well.
217
218 function OK_For_Limited_Init_In_05
219 (Typ : Entity_Id;
220 Exp : Node_Id) return Boolean;
221 -- Presuming Exp is an expression of an inherently limited type Typ,
222 -- returns True if the expression is allowed in an initialization context
223 -- by the rules of Ada 2005. We use the rule in RM-7.5(2.1/2), "...it is an
224 -- aggregate, a function_call, or a parenthesized expression or qualified
225 -- expression whose operand is permitted...". Note that in Ada 95 mode,
226 -- we sometimes wish to give warnings based on whether the program _would_
227 -- be legal in Ada 2005. Note that Exp must already have been resolved,
228 -- so we can know whether it's a function call (as opposed to an indexed
229 -- component, for example). In the case where Typ is a limited interface's
230 -- class-wide type, then the expression is allowed to be of any kind if its
231 -- type is a nonlimited descendant of the interface.
232
233 function OK_For_Limited_Init
234 (Typ : Entity_Id;
235 Exp : Node_Id) return Boolean;
236 -- Always False in Ada 95 mode. Equivalent to OK_For_Limited_Init_In_05 in
237 -- Ada 2005 mode.
238
239 procedure Preanalyze_Assert_Expression (N : Node_Id; T : Entity_Id);
240 -- Wrapper on Preanalyze_Spec_Expression for assertion expressions, so that
241 -- In_Assertion_Expr can be properly adjusted.
242 --
243 -- This routine must not be called when N is the root of a subtree that is
244 -- not in its final place since it freezes static expression entities,
245 -- which would be misplaced in the tree. Preanalyze_And_Resolve must be
246 -- used in such a case to avoid reporting spurious errors.
247
248 procedure Preanalyze_Assert_Expression (N : Node_Id);
249 -- Similar to the above, but without forcing N to be of a particular type
250
251 procedure Preanalyze_Spec_Expression (N : Node_Id; T : Entity_Id);
252 -- Default and per object expressions do not freeze their components, and
253 -- must be analyzed and resolved accordingly. The analysis is done by
254 -- calling the Preanalyze_And_Resolve routine and setting the global
255 -- In_Spec_Expression flag. See the documentation section entitled
256 -- "Handling of Default and Per-Object Expressions" in sem.ads for full
257 -- details. N is the expression to be analyzed, T is the expected type.
258 -- This mechanism is also used for aspect specifications that have an
259 -- expression parameter that needs similar preanalysis.
260 --
261 -- This routine must not be called when N is the root of a subtree that is
262 -- not in its final place since it freezes static expression entities,
263 -- which would be misplaced in the tree. Preanalyze_And_Resolve must be
264 -- used in such a case to avoid reporting spurious errors.
265
266 procedure Process_Full_View (N : Node_Id; Full_T, Priv_T : Entity_Id);
267 -- Process some semantic actions when the full view of a private type is
268 -- encountered and analyzed. The first action is to create the full views
269 -- of the dependant private subtypes. The second action is to recopy the
270 -- primitive operations of the private view (in the tagged case).
271 -- N is the N_Full_Type_Declaration node.
272 --
273 -- Full_T is the full view of the type whose full declaration is in N.
274 --
275 -- Priv_T is the private view of the type whose full declaration is in N.
276
277 procedure Process_Range_Expr_In_Decl
278 (R : Node_Id;
279 T : Entity_Id;
280 Subtyp : Entity_Id := Empty;
281 Check_List : List_Id := No_List);
282 -- Process a range expression that appears in a declaration context. The
283 -- range is analyzed and resolved with the base type of the given type, and
284 -- an appropriate check for expressions in non-static contexts made on the
285 -- bounds. R is analyzed and resolved using T, so the caller should if
286 -- necessary link R into the tree before the call, and in particular in the
287 -- case of a subtype declaration, it is appropriate to set the parent
288 -- pointer of R so that the types get properly frozen. Check_List is used
289 -- when the subprogram is called from Build_Record_Init_Proc and is used to
290 -- return a set of constraint checking statements generated by the Checks
291 -- package.
292 --
293 -- If Subtyp is given, then the range is for the named subtype Subtyp, and
294 -- in this case the bounds are captured if necessary using this name.
295
296 function Process_Subtype
297 (S : Node_Id;
298 Related_Nod : Node_Id;
299 Related_Id : Entity_Id := Empty;
300 Suffix : Character := ' ') return Entity_Id;
301 -- Process a subtype indication S and return corresponding entity.
302 -- Related_Nod is the node where the potential generated implicit types
303 -- will be inserted. The Related_Id and Suffix parameters are used to
304 -- build the associated Implicit type name.
305
306 procedure Process_Discriminants
307 (N : Node_Id;
308 Prev : Entity_Id := Empty);
309 -- Process the discriminants contained in an N_Full_Type_Declaration or
310 -- N_Incomplete_Type_Decl node N. If the declaration is a completion, Prev
311 -- is entity on the partial view, on which references are posted. However,
312 -- note that Process_Discriminants is called for a completion only if
313 -- partial view had no discriminants (else we just check conformance
314 -- between the two views and do not call Process_Discriminants again
315 -- for the completion).
316
317 function Replace_Anonymous_Access_To_Protected_Subprogram
318 (N : Node_Id) return Entity_Id;
319 -- Ada 2005 (AI-254): Create and decorate an internal full type declaration
320 -- for an anonymous access to protected subprogram. For a record component
321 -- declaration, the type is created in the enclosing scope, for an array
322 -- type declaration or an object declaration it is simply placed ahead of
323 -- this declaration.
324
325 procedure Set_Completion_Referenced (E : Entity_Id);
326 -- If E is the completion of a private or incomplete type declaration,
327 -- or the completion of a deferred constant declaration, mark the entity
328 -- as referenced. Warnings on unused entities, if needed, go on the
329 -- partial view.
330
331 end Sem_Ch3;