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