1 |
281 |
jeremybenn |
------------------------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-- GNAT COMPILER COMPONENTS --
|
4 |
|
|
-- --
|
5 |
|
|
-- P A R . C H 1 2 --
|
6 |
|
|
-- --
|
7 |
|
|
-- B o d y --
|
8 |
|
|
-- --
|
9 |
|
|
-- Copyright (C) 1992-2009, 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 |
|
|
pragma Style_Checks (All_Checks);
|
27 |
|
|
-- Turn off subprogram body ordering check. Subprograms are in order
|
28 |
|
|
-- by RM section rather than alphabetical
|
29 |
|
|
|
30 |
|
|
separate (Par)
|
31 |
|
|
package body Ch12 is
|
32 |
|
|
|
33 |
|
|
-- Local functions, used only in this chapter
|
34 |
|
|
|
35 |
|
|
function P_Formal_Derived_Type_Definition return Node_Id;
|
36 |
|
|
function P_Formal_Discrete_Type_Definition return Node_Id;
|
37 |
|
|
function P_Formal_Fixed_Point_Definition return Node_Id;
|
38 |
|
|
function P_Formal_Floating_Point_Definition return Node_Id;
|
39 |
|
|
function P_Formal_Modular_Type_Definition return Node_Id;
|
40 |
|
|
function P_Formal_Package_Declaration return Node_Id;
|
41 |
|
|
function P_Formal_Private_Type_Definition return Node_Id;
|
42 |
|
|
function P_Formal_Signed_Integer_Type_Definition return Node_Id;
|
43 |
|
|
function P_Formal_Subprogram_Declaration return Node_Id;
|
44 |
|
|
function P_Formal_Type_Declaration return Node_Id;
|
45 |
|
|
function P_Formal_Type_Definition return Node_Id;
|
46 |
|
|
function P_Generic_Association return Node_Id;
|
47 |
|
|
|
48 |
|
|
procedure P_Formal_Object_Declarations (Decls : List_Id);
|
49 |
|
|
-- Scans one or more formal object declarations and appends them to
|
50 |
|
|
-- Decls. Scans more than one declaration only in the case where the
|
51 |
|
|
-- source has a declaration with multiple defining identifiers.
|
52 |
|
|
|
53 |
|
|
--------------------------------
|
54 |
|
|
-- 12.1 Generic (also 8.5.5) --
|
55 |
|
|
--------------------------------
|
56 |
|
|
|
57 |
|
|
-- This routine parses either one of the forms of a generic declaration
|
58 |
|
|
-- or a generic renaming declaration.
|
59 |
|
|
|
60 |
|
|
-- GENERIC_DECLARATION ::=
|
61 |
|
|
-- GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
|
62 |
|
|
|
63 |
|
|
-- GENERIC_SUBPROGRAM_DECLARATION ::=
|
64 |
|
|
-- GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION;
|
65 |
|
|
|
66 |
|
|
-- GENERIC_PACKAGE_DECLARATION ::=
|
67 |
|
|
-- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION;
|
68 |
|
|
|
69 |
|
|
-- GENERIC_FORMAL_PART ::=
|
70 |
|
|
-- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
|
71 |
|
|
|
72 |
|
|
-- GENERIC_RENAMING_DECLARATION ::=
|
73 |
|
|
-- generic package DEFINING_PROGRAM_UNIT_NAME
|
74 |
|
|
-- renames generic_package_NAME
|
75 |
|
|
-- | generic procedure DEFINING_PROGRAM_UNIT_NAME
|
76 |
|
|
-- renames generic_procedure_NAME
|
77 |
|
|
-- | generic function DEFINING_PROGRAM_UNIT_NAME
|
78 |
|
|
-- renames generic_function_NAME
|
79 |
|
|
|
80 |
|
|
-- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
|
81 |
|
|
-- FORMAL_OBJECT_DECLARATION
|
82 |
|
|
-- | FORMAL_TYPE_DECLARATION
|
83 |
|
|
-- | FORMAL_SUBPROGRAM_DECLARATION
|
84 |
|
|
-- | FORMAL_PACKAGE_DECLARATION
|
85 |
|
|
|
86 |
|
|
-- The caller has checked that the initial token is GENERIC
|
87 |
|
|
|
88 |
|
|
-- Error recovery: can raise Error_Resync
|
89 |
|
|
|
90 |
|
|
function P_Generic return Node_Id is
|
91 |
|
|
Gen_Sloc : constant Source_Ptr := Token_Ptr;
|
92 |
|
|
Gen_Decl : Node_Id;
|
93 |
|
|
Decl_Node : Node_Id;
|
94 |
|
|
Decls : List_Id;
|
95 |
|
|
Def_Unit : Node_Id;
|
96 |
|
|
Ren_Token : Token_Type;
|
97 |
|
|
Scan_State : Saved_Scan_State;
|
98 |
|
|
|
99 |
|
|
begin
|
100 |
|
|
Scan; -- past GENERIC
|
101 |
|
|
|
102 |
|
|
if Token = Tok_Private then
|
103 |
|
|
Error_Msg_SC -- CODEFIX
|
104 |
|
|
("PRIVATE goes before GENERIC, not after");
|
105 |
|
|
Scan; -- past junk PRIVATE token
|
106 |
|
|
end if;
|
107 |
|
|
|
108 |
|
|
Save_Scan_State (Scan_State); -- at token past GENERIC
|
109 |
|
|
|
110 |
|
|
-- Check for generic renaming declaration case
|
111 |
|
|
|
112 |
|
|
if Token = Tok_Package
|
113 |
|
|
or else Token = Tok_Function
|
114 |
|
|
or else Token = Tok_Procedure
|
115 |
|
|
then
|
116 |
|
|
Ren_Token := Token;
|
117 |
|
|
Scan; -- scan past PACKAGE, FUNCTION or PROCEDURE
|
118 |
|
|
|
119 |
|
|
if Token = Tok_Identifier then
|
120 |
|
|
Def_Unit := P_Defining_Program_Unit_Name;
|
121 |
|
|
|
122 |
|
|
Check_Misspelling_Of (Tok_Renames);
|
123 |
|
|
|
124 |
|
|
if Token = Tok_Renames then
|
125 |
|
|
if Ren_Token = Tok_Package then
|
126 |
|
|
Decl_Node := New_Node
|
127 |
|
|
(N_Generic_Package_Renaming_Declaration, Gen_Sloc);
|
128 |
|
|
|
129 |
|
|
elsif Ren_Token = Tok_Procedure then
|
130 |
|
|
Decl_Node := New_Node
|
131 |
|
|
(N_Generic_Procedure_Renaming_Declaration, Gen_Sloc);
|
132 |
|
|
|
133 |
|
|
else -- Ren_Token = Tok_Function then
|
134 |
|
|
Decl_Node := New_Node
|
135 |
|
|
(N_Generic_Function_Renaming_Declaration, Gen_Sloc);
|
136 |
|
|
end if;
|
137 |
|
|
|
138 |
|
|
Scan; -- past RENAMES
|
139 |
|
|
Set_Defining_Unit_Name (Decl_Node, Def_Unit);
|
140 |
|
|
Set_Name (Decl_Node, P_Name);
|
141 |
|
|
TF_Semicolon;
|
142 |
|
|
return Decl_Node;
|
143 |
|
|
end if;
|
144 |
|
|
end if;
|
145 |
|
|
end if;
|
146 |
|
|
|
147 |
|
|
-- Fall through if this is *not* a generic renaming declaration
|
148 |
|
|
|
149 |
|
|
Restore_Scan_State (Scan_State);
|
150 |
|
|
Decls := New_List;
|
151 |
|
|
|
152 |
|
|
-- Loop through generic parameter declarations and use clauses
|
153 |
|
|
|
154 |
|
|
Decl_Loop : loop
|
155 |
|
|
P_Pragmas_Opt (Decls);
|
156 |
|
|
|
157 |
|
|
if Token = Tok_Private then
|
158 |
|
|
Error_Msg_S ("generic private child packages not permitted");
|
159 |
|
|
Scan; -- past PRIVATE
|
160 |
|
|
end if;
|
161 |
|
|
|
162 |
|
|
if Token = Tok_Use then
|
163 |
|
|
Append (P_Use_Clause, Decls);
|
164 |
|
|
else
|
165 |
|
|
-- Parse a generic parameter declaration
|
166 |
|
|
|
167 |
|
|
if Token = Tok_Identifier then
|
168 |
|
|
P_Formal_Object_Declarations (Decls);
|
169 |
|
|
|
170 |
|
|
elsif Token = Tok_Type then
|
171 |
|
|
Append (P_Formal_Type_Declaration, Decls);
|
172 |
|
|
|
173 |
|
|
elsif Token = Tok_With then
|
174 |
|
|
Scan; -- past WITH
|
175 |
|
|
|
176 |
|
|
if Token = Tok_Package then
|
177 |
|
|
Append (P_Formal_Package_Declaration, Decls);
|
178 |
|
|
|
179 |
|
|
elsif Token = Tok_Procedure or Token = Tok_Function then
|
180 |
|
|
Append (P_Formal_Subprogram_Declaration, Decls);
|
181 |
|
|
|
182 |
|
|
else
|
183 |
|
|
Error_Msg_BC -- CODEFIX
|
184 |
|
|
("FUNCTION, PROCEDURE or PACKAGE expected here");
|
185 |
|
|
Resync_Past_Semicolon;
|
186 |
|
|
end if;
|
187 |
|
|
|
188 |
|
|
elsif Token = Tok_Subtype then
|
189 |
|
|
Error_Msg_SC ("subtype declaration not allowed " &
|
190 |
|
|
"as generic parameter declaration!");
|
191 |
|
|
Resync_Past_Semicolon;
|
192 |
|
|
|
193 |
|
|
else
|
194 |
|
|
exit Decl_Loop;
|
195 |
|
|
end if;
|
196 |
|
|
end if;
|
197 |
|
|
|
198 |
|
|
end loop Decl_Loop;
|
199 |
|
|
|
200 |
|
|
-- Generic formal part is scanned, scan out subprogram or package spec
|
201 |
|
|
|
202 |
|
|
if Token = Tok_Package then
|
203 |
|
|
Gen_Decl := New_Node (N_Generic_Package_Declaration, Gen_Sloc);
|
204 |
|
|
Set_Specification (Gen_Decl, P_Package (Pf_Spcn));
|
205 |
|
|
else
|
206 |
|
|
Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
|
207 |
|
|
|
208 |
|
|
Set_Specification (Gen_Decl, P_Subprogram_Specification);
|
209 |
|
|
|
210 |
|
|
if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
|
211 |
|
|
N_Defining_Program_Unit_Name
|
212 |
|
|
and then Scope.Last > 0
|
213 |
|
|
then
|
214 |
|
|
Error_Msg_SP ("child unit allowed only at library level");
|
215 |
|
|
end if;
|
216 |
|
|
TF_Semicolon;
|
217 |
|
|
end if;
|
218 |
|
|
|
219 |
|
|
Set_Generic_Formal_Declarations (Gen_Decl, Decls);
|
220 |
|
|
return Gen_Decl;
|
221 |
|
|
end P_Generic;
|
222 |
|
|
|
223 |
|
|
-------------------------------
|
224 |
|
|
-- 12.1 Generic Declaration --
|
225 |
|
|
-------------------------------
|
226 |
|
|
|
227 |
|
|
-- Parsed by P_Generic (12.1)
|
228 |
|
|
|
229 |
|
|
------------------------------------------
|
230 |
|
|
-- 12.1 Generic Subprogram Declaration --
|
231 |
|
|
------------------------------------------
|
232 |
|
|
|
233 |
|
|
-- Parsed by P_Generic (12.1)
|
234 |
|
|
|
235 |
|
|
---------------------------------------
|
236 |
|
|
-- 12.1 Generic Package Declaration --
|
237 |
|
|
---------------------------------------
|
238 |
|
|
|
239 |
|
|
-- Parsed by P_Generic (12.1)
|
240 |
|
|
|
241 |
|
|
-------------------------------
|
242 |
|
|
-- 12.1 Generic Formal Part --
|
243 |
|
|
-------------------------------
|
244 |
|
|
|
245 |
|
|
-- Parsed by P_Generic (12.1)
|
246 |
|
|
|
247 |
|
|
-------------------------------------------------
|
248 |
|
|
-- 12.1 Generic Formal Parameter Declaration --
|
249 |
|
|
-------------------------------------------------
|
250 |
|
|
|
251 |
|
|
-- Parsed by P_Generic (12.1)
|
252 |
|
|
|
253 |
|
|
---------------------------------
|
254 |
|
|
-- 12.3 Generic Instantiation --
|
255 |
|
|
---------------------------------
|
256 |
|
|
|
257 |
|
|
-- Generic package instantiation parsed by P_Package (7.1)
|
258 |
|
|
-- Generic procedure instantiation parsed by P_Subprogram (6.1)
|
259 |
|
|
-- Generic function instantiation parsed by P_Subprogram (6.1)
|
260 |
|
|
|
261 |
|
|
-------------------------------
|
262 |
|
|
-- 12.3 Generic Actual Part --
|
263 |
|
|
-------------------------------
|
264 |
|
|
|
265 |
|
|
-- GENERIC_ACTUAL_PART ::=
|
266 |
|
|
-- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
|
267 |
|
|
|
268 |
|
|
-- Returns a list of generic associations, or Empty if none are present
|
269 |
|
|
|
270 |
|
|
-- Error recovery: cannot raise Error_Resync
|
271 |
|
|
|
272 |
|
|
function P_Generic_Actual_Part_Opt return List_Id is
|
273 |
|
|
Association_List : List_Id;
|
274 |
|
|
|
275 |
|
|
begin
|
276 |
|
|
-- Figure out if a generic actual part operation is present. Clearly
|
277 |
|
|
-- there is no generic actual part if the current token is semicolon
|
278 |
|
|
|
279 |
|
|
if Token = Tok_Semicolon then
|
280 |
|
|
return No_List;
|
281 |
|
|
|
282 |
|
|
-- If we don't have a left paren, then we have an error, and the job
|
283 |
|
|
-- is to figure out whether a left paren or semicolon was intended.
|
284 |
|
|
-- We assume a missing left paren (and hence a generic actual part
|
285 |
|
|
-- present) if the current token is not on a new line, or if it is
|
286 |
|
|
-- indented from the subprogram token. Otherwise assume missing
|
287 |
|
|
-- semicolon (which will be diagnosed by caller) and no generic part
|
288 |
|
|
|
289 |
|
|
elsif Token /= Tok_Left_Paren
|
290 |
|
|
and then Token_Is_At_Start_Of_Line
|
291 |
|
|
and then Start_Column <= Scope.Table (Scope.Last).Ecol
|
292 |
|
|
then
|
293 |
|
|
return No_List;
|
294 |
|
|
|
295 |
|
|
-- Otherwise we have a generic actual part (either a left paren is
|
296 |
|
|
-- present, or we have decided that there must be a missing left paren)
|
297 |
|
|
|
298 |
|
|
else
|
299 |
|
|
Association_List := New_List;
|
300 |
|
|
T_Left_Paren;
|
301 |
|
|
|
302 |
|
|
loop
|
303 |
|
|
Append (P_Generic_Association, Association_List);
|
304 |
|
|
exit when not Comma_Present;
|
305 |
|
|
end loop;
|
306 |
|
|
|
307 |
|
|
T_Right_Paren;
|
308 |
|
|
return Association_List;
|
309 |
|
|
end if;
|
310 |
|
|
|
311 |
|
|
end P_Generic_Actual_Part_Opt;
|
312 |
|
|
|
313 |
|
|
-------------------------------
|
314 |
|
|
-- 12.3 Generic Association --
|
315 |
|
|
-------------------------------
|
316 |
|
|
|
317 |
|
|
-- GENERIC_ASSOCIATION ::=
|
318 |
|
|
-- [generic_formal_parameter_SELECTOR_NAME =>]
|
319 |
|
|
-- EXPLICIT_GENERIC_ACTUAL_PARAMETER
|
320 |
|
|
|
321 |
|
|
-- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
|
322 |
|
|
-- EXPRESSION | variable_NAME | subprogram_NAME
|
323 |
|
|
-- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
|
324 |
|
|
|
325 |
|
|
-- Error recovery: cannot raise Error_Resync
|
326 |
|
|
|
327 |
|
|
function P_Generic_Association return Node_Id is
|
328 |
|
|
Scan_State : Saved_Scan_State;
|
329 |
|
|
Param_Name_Node : Node_Id;
|
330 |
|
|
Generic_Assoc_Node : Node_Id;
|
331 |
|
|
|
332 |
|
|
begin
|
333 |
|
|
Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
|
334 |
|
|
|
335 |
|
|
-- Ada2005: an association can be given by: others => <>
|
336 |
|
|
|
337 |
|
|
if Token = Tok_Others then
|
338 |
|
|
if Ada_Version < Ada_05 then
|
339 |
|
|
Error_Msg_SP
|
340 |
|
|
("partial parametrization of formal packages" &
|
341 |
|
|
" is an Ada 2005 extension");
|
342 |
|
|
Error_Msg_SP
|
343 |
|
|
("\unit must be compiled with -gnat05 switch");
|
344 |
|
|
end if;
|
345 |
|
|
|
346 |
|
|
Scan; -- past OTHERS
|
347 |
|
|
|
348 |
|
|
if Token /= Tok_Arrow then
|
349 |
|
|
Error_Msg_BC ("expect arrow after others");
|
350 |
|
|
else
|
351 |
|
|
Scan; -- past arrow
|
352 |
|
|
end if;
|
353 |
|
|
|
354 |
|
|
if Token /= Tok_Box then
|
355 |
|
|
Error_Msg_BC ("expect Box after arrow");
|
356 |
|
|
else
|
357 |
|
|
Scan; -- past box
|
358 |
|
|
end if;
|
359 |
|
|
|
360 |
|
|
-- Source position of the others choice is beginning of construct
|
361 |
|
|
|
362 |
|
|
return New_Node (N_Others_Choice, Sloc (Generic_Assoc_Node));
|
363 |
|
|
end if;
|
364 |
|
|
|
365 |
|
|
if Token in Token_Class_Desig then
|
366 |
|
|
Param_Name_Node := Token_Node;
|
367 |
|
|
Save_Scan_State (Scan_State); -- at designator
|
368 |
|
|
Scan; -- past simple name or operator symbol
|
369 |
|
|
|
370 |
|
|
if Token = Tok_Arrow then
|
371 |
|
|
Scan; -- past arrow
|
372 |
|
|
Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
|
373 |
|
|
else
|
374 |
|
|
Restore_Scan_State (Scan_State); -- to designator
|
375 |
|
|
end if;
|
376 |
|
|
end if;
|
377 |
|
|
|
378 |
|
|
-- In Ada 2005 the actual can be a box
|
379 |
|
|
|
380 |
|
|
if Token = Tok_Box then
|
381 |
|
|
Scan;
|
382 |
|
|
Set_Box_Present (Generic_Assoc_Node);
|
383 |
|
|
Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, Empty);
|
384 |
|
|
|
385 |
|
|
else
|
386 |
|
|
Set_Explicit_Generic_Actual_Parameter
|
387 |
|
|
(Generic_Assoc_Node, P_Expression);
|
388 |
|
|
end if;
|
389 |
|
|
|
390 |
|
|
return Generic_Assoc_Node;
|
391 |
|
|
end P_Generic_Association;
|
392 |
|
|
|
393 |
|
|
---------------------------------------------
|
394 |
|
|
-- 12.3 Explicit Generic Actual Parameter --
|
395 |
|
|
---------------------------------------------
|
396 |
|
|
|
397 |
|
|
-- Parsed by P_Generic_Association (12.3)
|
398 |
|
|
|
399 |
|
|
--------------------------------------
|
400 |
|
|
-- 12.4 Formal Object Declarations --
|
401 |
|
|
--------------------------------------
|
402 |
|
|
|
403 |
|
|
-- FORMAL_OBJECT_DECLARATION ::=
|
404 |
|
|
-- DEFINING_IDENTIFIER_LIST :
|
405 |
|
|
-- MODE [NULL_EXCLUSION] SUBTYPE_MARK [:= DEFAULT_EXPRESSION];
|
406 |
|
|
-- | DEFINING_IDENTIFIER_LIST :
|
407 |
|
|
-- MODE ACCESS_DEFINITION [:= DEFAULT_EXPRESSION];
|
408 |
|
|
|
409 |
|
|
-- The caller has checked that the initial token is an identifier
|
410 |
|
|
|
411 |
|
|
-- Error recovery: cannot raise Error_Resync
|
412 |
|
|
|
413 |
|
|
procedure P_Formal_Object_Declarations (Decls : List_Id) is
|
414 |
|
|
Decl_Node : Node_Id;
|
415 |
|
|
Ident : Nat;
|
416 |
|
|
Not_Null_Present : Boolean := False;
|
417 |
|
|
Num_Idents : Nat;
|
418 |
|
|
Scan_State : Saved_Scan_State;
|
419 |
|
|
|
420 |
|
|
Idents : array (Int range 1 .. 4096) of Entity_Id;
|
421 |
|
|
-- This array holds the list of defining identifiers. The upper bound
|
422 |
|
|
-- of 4096 is intended to be essentially infinite, and we do not even
|
423 |
|
|
-- bother to check for it being exceeded.
|
424 |
|
|
|
425 |
|
|
begin
|
426 |
|
|
Idents (1) := P_Defining_Identifier (C_Comma_Colon);
|
427 |
|
|
Num_Idents := 1;
|
428 |
|
|
|
429 |
|
|
while Comma_Present loop
|
430 |
|
|
Num_Idents := Num_Idents + 1;
|
431 |
|
|
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
|
432 |
|
|
end loop;
|
433 |
|
|
|
434 |
|
|
T_Colon;
|
435 |
|
|
|
436 |
|
|
-- If there are multiple identifiers, we repeatedly scan the
|
437 |
|
|
-- type and initialization expression information by resetting
|
438 |
|
|
-- the scan pointer (so that we get completely separate trees
|
439 |
|
|
-- for each occurrence).
|
440 |
|
|
|
441 |
|
|
if Num_Idents > 1 then
|
442 |
|
|
Save_Scan_State (Scan_State);
|
443 |
|
|
end if;
|
444 |
|
|
|
445 |
|
|
-- Loop through defining identifiers in list
|
446 |
|
|
|
447 |
|
|
Ident := 1;
|
448 |
|
|
Ident_Loop : loop
|
449 |
|
|
Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
|
450 |
|
|
Set_Defining_Identifier (Decl_Node, Idents (Ident));
|
451 |
|
|
P_Mode (Decl_Node);
|
452 |
|
|
|
453 |
|
|
Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-423)
|
454 |
|
|
|
455 |
|
|
-- Ada 2005 (AI-423): Formal object with an access definition
|
456 |
|
|
|
457 |
|
|
if Token = Tok_Access then
|
458 |
|
|
|
459 |
|
|
-- The access definition is still parsed and set even though
|
460 |
|
|
-- the compilation may not use the proper switch. This action
|
461 |
|
|
-- ensures the required local error recovery.
|
462 |
|
|
|
463 |
|
|
Set_Access_Definition (Decl_Node,
|
464 |
|
|
P_Access_Definition (Not_Null_Present));
|
465 |
|
|
|
466 |
|
|
if Ada_Version < Ada_05 then
|
467 |
|
|
Error_Msg_SP
|
468 |
|
|
("access definition not allowed in formal object " &
|
469 |
|
|
"declaration");
|
470 |
|
|
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
|
471 |
|
|
end if;
|
472 |
|
|
|
473 |
|
|
-- Formal object with a subtype mark
|
474 |
|
|
|
475 |
|
|
else
|
476 |
|
|
Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
|
477 |
|
|
Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
|
478 |
|
|
end if;
|
479 |
|
|
|
480 |
|
|
No_Constraint;
|
481 |
|
|
Set_Default_Expression (Decl_Node, Init_Expr_Opt);
|
482 |
|
|
|
483 |
|
|
if Ident > 1 then
|
484 |
|
|
Set_Prev_Ids (Decl_Node, True);
|
485 |
|
|
end if;
|
486 |
|
|
|
487 |
|
|
if Ident < Num_Idents then
|
488 |
|
|
Set_More_Ids (Decl_Node, True);
|
489 |
|
|
end if;
|
490 |
|
|
|
491 |
|
|
Append (Decl_Node, Decls);
|
492 |
|
|
|
493 |
|
|
exit Ident_Loop when Ident = Num_Idents;
|
494 |
|
|
Ident := Ident + 1;
|
495 |
|
|
Restore_Scan_State (Scan_State);
|
496 |
|
|
end loop Ident_Loop;
|
497 |
|
|
|
498 |
|
|
TF_Semicolon;
|
499 |
|
|
end P_Formal_Object_Declarations;
|
500 |
|
|
|
501 |
|
|
-----------------------------------
|
502 |
|
|
-- 12.5 Formal Type Declaration --
|
503 |
|
|
-----------------------------------
|
504 |
|
|
|
505 |
|
|
-- FORMAL_TYPE_DECLARATION ::=
|
506 |
|
|
-- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
|
507 |
|
|
-- is FORMAL_TYPE_DEFINITION;
|
508 |
|
|
|
509 |
|
|
-- The caller has checked that the initial token is TYPE
|
510 |
|
|
|
511 |
|
|
-- Error recovery: cannot raise Error_Resync
|
512 |
|
|
|
513 |
|
|
function P_Formal_Type_Declaration return Node_Id is
|
514 |
|
|
Decl_Node : Node_Id;
|
515 |
|
|
Def_Node : Node_Id;
|
516 |
|
|
|
517 |
|
|
begin
|
518 |
|
|
Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
|
519 |
|
|
Scan; -- past TYPE
|
520 |
|
|
Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
|
521 |
|
|
|
522 |
|
|
if P_Unknown_Discriminant_Part_Opt then
|
523 |
|
|
Set_Unknown_Discriminants_Present (Decl_Node, True);
|
524 |
|
|
else
|
525 |
|
|
Set_Discriminant_Specifications
|
526 |
|
|
(Decl_Node, P_Known_Discriminant_Part_Opt);
|
527 |
|
|
end if;
|
528 |
|
|
|
529 |
|
|
T_Is;
|
530 |
|
|
|
531 |
|
|
Def_Node := P_Formal_Type_Definition;
|
532 |
|
|
|
533 |
|
|
if Def_Node /= Error then
|
534 |
|
|
Set_Formal_Type_Definition (Decl_Node, Def_Node);
|
535 |
|
|
TF_Semicolon;
|
536 |
|
|
|
537 |
|
|
else
|
538 |
|
|
Decl_Node := Error;
|
539 |
|
|
|
540 |
|
|
-- If we have semicolon, skip it to avoid cascaded errors
|
541 |
|
|
|
542 |
|
|
if Token = Tok_Semicolon then
|
543 |
|
|
Scan;
|
544 |
|
|
end if;
|
545 |
|
|
end if;
|
546 |
|
|
|
547 |
|
|
return Decl_Node;
|
548 |
|
|
end P_Formal_Type_Declaration;
|
549 |
|
|
|
550 |
|
|
----------------------------------
|
551 |
|
|
-- 12.5 Formal Type Definition --
|
552 |
|
|
----------------------------------
|
553 |
|
|
|
554 |
|
|
-- FORMAL_TYPE_DEFINITION ::=
|
555 |
|
|
-- FORMAL_PRIVATE_TYPE_DEFINITION
|
556 |
|
|
-- | FORMAL_DERIVED_TYPE_DEFINITION
|
557 |
|
|
-- | FORMAL_DISCRETE_TYPE_DEFINITION
|
558 |
|
|
-- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
|
559 |
|
|
-- | FORMAL_MODULAR_TYPE_DEFINITION
|
560 |
|
|
-- | FORMAL_FLOATING_POINT_DEFINITION
|
561 |
|
|
-- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
|
562 |
|
|
-- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
|
563 |
|
|
-- | FORMAL_ARRAY_TYPE_DEFINITION
|
564 |
|
|
-- | FORMAL_ACCESS_TYPE_DEFINITION
|
565 |
|
|
-- | FORMAL_INTERFACE_TYPE_DEFINITION
|
566 |
|
|
|
567 |
|
|
-- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
|
568 |
|
|
|
569 |
|
|
-- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
|
570 |
|
|
|
571 |
|
|
-- FORMAL_INTERFACE_TYPE_DEFINITION ::= INTERFACE_TYPE_DEFINITION
|
572 |
|
|
|
573 |
|
|
function P_Formal_Type_Definition return Node_Id is
|
574 |
|
|
Scan_State : Saved_Scan_State;
|
575 |
|
|
Typedef_Node : Node_Id;
|
576 |
|
|
|
577 |
|
|
begin
|
578 |
|
|
if Token_Name = Name_Abstract then
|
579 |
|
|
Check_95_Keyword (Tok_Abstract, Tok_Tagged);
|
580 |
|
|
end if;
|
581 |
|
|
|
582 |
|
|
if Token_Name = Name_Tagged then
|
583 |
|
|
Check_95_Keyword (Tok_Tagged, Tok_Private);
|
584 |
|
|
Check_95_Keyword (Tok_Tagged, Tok_Limited);
|
585 |
|
|
end if;
|
586 |
|
|
|
587 |
|
|
case Token is
|
588 |
|
|
|
589 |
|
|
-- Mostly we can tell what we have from the initial token. The one
|
590 |
|
|
-- exception is ABSTRACT, where we have to scan ahead to see if we
|
591 |
|
|
-- have a formal derived type or a formal private type definition.
|
592 |
|
|
|
593 |
|
|
-- In addition, in Ada 2005 LIMITED may appear after abstract, so
|
594 |
|
|
-- that the lookahead must be extended by one more token.
|
595 |
|
|
|
596 |
|
|
when Tok_Abstract =>
|
597 |
|
|
Save_Scan_State (Scan_State);
|
598 |
|
|
Scan; -- past ABSTRACT
|
599 |
|
|
|
600 |
|
|
if Token = Tok_New then
|
601 |
|
|
Restore_Scan_State (Scan_State); -- to ABSTRACT
|
602 |
|
|
return P_Formal_Derived_Type_Definition;
|
603 |
|
|
|
604 |
|
|
elsif Token = Tok_Limited then
|
605 |
|
|
Scan; -- past LIMITED
|
606 |
|
|
|
607 |
|
|
if Token = Tok_New then
|
608 |
|
|
Restore_Scan_State (Scan_State); -- to ABSTRACT
|
609 |
|
|
return P_Formal_Derived_Type_Definition;
|
610 |
|
|
|
611 |
|
|
else
|
612 |
|
|
Restore_Scan_State (Scan_State); -- to ABSTRACT
|
613 |
|
|
return P_Formal_Private_Type_Definition;
|
614 |
|
|
end if;
|
615 |
|
|
|
616 |
|
|
-- Ada 2005 (AI-443): Abstract synchronized formal derived type
|
617 |
|
|
|
618 |
|
|
elsif Token = Tok_Synchronized then
|
619 |
|
|
Restore_Scan_State (Scan_State); -- to ABSTRACT
|
620 |
|
|
return P_Formal_Derived_Type_Definition;
|
621 |
|
|
|
622 |
|
|
else
|
623 |
|
|
Restore_Scan_State (Scan_State); -- to ABSTRACT
|
624 |
|
|
return P_Formal_Private_Type_Definition;
|
625 |
|
|
end if;
|
626 |
|
|
|
627 |
|
|
when Tok_Access =>
|
628 |
|
|
return P_Access_Type_Definition;
|
629 |
|
|
|
630 |
|
|
when Tok_Array =>
|
631 |
|
|
return P_Array_Type_Definition;
|
632 |
|
|
|
633 |
|
|
when Tok_Delta =>
|
634 |
|
|
return P_Formal_Fixed_Point_Definition;
|
635 |
|
|
|
636 |
|
|
when Tok_Digits =>
|
637 |
|
|
return P_Formal_Floating_Point_Definition;
|
638 |
|
|
|
639 |
|
|
when Tok_Interface => -- Ada 2005 (AI-251)
|
640 |
|
|
return P_Interface_Type_Definition (Abstract_Present => False);
|
641 |
|
|
|
642 |
|
|
when Tok_Left_Paren =>
|
643 |
|
|
return P_Formal_Discrete_Type_Definition;
|
644 |
|
|
|
645 |
|
|
when Tok_Limited =>
|
646 |
|
|
Save_Scan_State (Scan_State);
|
647 |
|
|
Scan; -- past LIMITED
|
648 |
|
|
|
649 |
|
|
if Token = Tok_Interface then
|
650 |
|
|
Typedef_Node :=
|
651 |
|
|
P_Interface_Type_Definition (Abstract_Present => False);
|
652 |
|
|
Set_Limited_Present (Typedef_Node);
|
653 |
|
|
return Typedef_Node;
|
654 |
|
|
|
655 |
|
|
elsif Token = Tok_New then
|
656 |
|
|
Restore_Scan_State (Scan_State); -- to LIMITED
|
657 |
|
|
return P_Formal_Derived_Type_Definition;
|
658 |
|
|
|
659 |
|
|
else
|
660 |
|
|
if Token = Tok_Abstract then
|
661 |
|
|
Error_Msg_SC -- CODEFIX
|
662 |
|
|
("ABSTRACT must come before LIMITED");
|
663 |
|
|
Scan; -- past improper ABSTRACT
|
664 |
|
|
|
665 |
|
|
if Token = Tok_New then
|
666 |
|
|
Restore_Scan_State (Scan_State); -- to LIMITED
|
667 |
|
|
return P_Formal_Derived_Type_Definition;
|
668 |
|
|
|
669 |
|
|
else
|
670 |
|
|
Restore_Scan_State (Scan_State);
|
671 |
|
|
return P_Formal_Private_Type_Definition;
|
672 |
|
|
end if;
|
673 |
|
|
end if;
|
674 |
|
|
|
675 |
|
|
Restore_Scan_State (Scan_State);
|
676 |
|
|
return P_Formal_Private_Type_Definition;
|
677 |
|
|
end if;
|
678 |
|
|
|
679 |
|
|
when Tok_Mod =>
|
680 |
|
|
return P_Formal_Modular_Type_Definition;
|
681 |
|
|
|
682 |
|
|
when Tok_New =>
|
683 |
|
|
return P_Formal_Derived_Type_Definition;
|
684 |
|
|
|
685 |
|
|
when Tok_Not =>
|
686 |
|
|
if P_Null_Exclusion then
|
687 |
|
|
Typedef_Node := P_Access_Type_Definition;
|
688 |
|
|
Set_Null_Exclusion_Present (Typedef_Node);
|
689 |
|
|
return Typedef_Node;
|
690 |
|
|
|
691 |
|
|
else
|
692 |
|
|
Error_Msg_SC ("expect valid formal access definition!");
|
693 |
|
|
Resync_Past_Semicolon;
|
694 |
|
|
return Error;
|
695 |
|
|
end if;
|
696 |
|
|
|
697 |
|
|
when Tok_Private |
|
698 |
|
|
Tok_Tagged =>
|
699 |
|
|
return P_Formal_Private_Type_Definition;
|
700 |
|
|
|
701 |
|
|
when Tok_Range =>
|
702 |
|
|
return P_Formal_Signed_Integer_Type_Definition;
|
703 |
|
|
|
704 |
|
|
when Tok_Record =>
|
705 |
|
|
Error_Msg_SC ("record not allowed in generic type definition!");
|
706 |
|
|
Discard_Junk_Node (P_Record_Definition);
|
707 |
|
|
return Error;
|
708 |
|
|
|
709 |
|
|
-- Ada 2005 (AI-345): Task, Protected or Synchronized interface or
|
710 |
|
|
-- (AI-443): Synchronized formal derived type declaration.
|
711 |
|
|
|
712 |
|
|
when Tok_Protected |
|
713 |
|
|
Tok_Synchronized |
|
714 |
|
|
Tok_Task =>
|
715 |
|
|
|
716 |
|
|
declare
|
717 |
|
|
Saved_Token : constant Token_Type := Token;
|
718 |
|
|
|
719 |
|
|
begin
|
720 |
|
|
Scan; -- past TASK, PROTECTED or SYNCHRONIZED
|
721 |
|
|
|
722 |
|
|
-- Synchronized derived type
|
723 |
|
|
|
724 |
|
|
if Token = Tok_New then
|
725 |
|
|
Typedef_Node := P_Formal_Derived_Type_Definition;
|
726 |
|
|
|
727 |
|
|
if Saved_Token = Tok_Synchronized then
|
728 |
|
|
Set_Synchronized_Present (Typedef_Node);
|
729 |
|
|
else
|
730 |
|
|
Error_Msg_SC ("invalid kind of formal derived type");
|
731 |
|
|
end if;
|
732 |
|
|
|
733 |
|
|
-- Interface
|
734 |
|
|
|
735 |
|
|
else
|
736 |
|
|
Typedef_Node :=
|
737 |
|
|
P_Interface_Type_Definition (Abstract_Present => False);
|
738 |
|
|
|
739 |
|
|
case Saved_Token is
|
740 |
|
|
when Tok_Task =>
|
741 |
|
|
Set_Task_Present (Typedef_Node);
|
742 |
|
|
|
743 |
|
|
when Tok_Protected =>
|
744 |
|
|
Set_Protected_Present (Typedef_Node);
|
745 |
|
|
|
746 |
|
|
when Tok_Synchronized =>
|
747 |
|
|
Set_Synchronized_Present (Typedef_Node);
|
748 |
|
|
|
749 |
|
|
when others =>
|
750 |
|
|
null;
|
751 |
|
|
end case;
|
752 |
|
|
end if;
|
753 |
|
|
|
754 |
|
|
return Typedef_Node;
|
755 |
|
|
end;
|
756 |
|
|
|
757 |
|
|
when others =>
|
758 |
|
|
Error_Msg_BC ("expecting generic type definition here");
|
759 |
|
|
Resync_Past_Semicolon;
|
760 |
|
|
return Error;
|
761 |
|
|
|
762 |
|
|
end case;
|
763 |
|
|
end P_Formal_Type_Definition;
|
764 |
|
|
|
765 |
|
|
--------------------------------------------
|
766 |
|
|
-- 12.5.1 Formal Private Type Definition --
|
767 |
|
|
--------------------------------------------
|
768 |
|
|
|
769 |
|
|
-- FORMAL_PRIVATE_TYPE_DEFINITION ::=
|
770 |
|
|
-- [[abstract] tagged] [limited] private
|
771 |
|
|
|
772 |
|
|
-- The caller has checked the initial token is PRIVATE, ABSTRACT,
|
773 |
|
|
-- TAGGED or LIMITED
|
774 |
|
|
|
775 |
|
|
-- Error recovery: cannot raise Error_Resync
|
776 |
|
|
|
777 |
|
|
function P_Formal_Private_Type_Definition return Node_Id is
|
778 |
|
|
Def_Node : Node_Id;
|
779 |
|
|
|
780 |
|
|
begin
|
781 |
|
|
Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
|
782 |
|
|
|
783 |
|
|
if Token = Tok_Abstract then
|
784 |
|
|
Scan; -- past ABSTRACT
|
785 |
|
|
|
786 |
|
|
if Token_Name = Name_Tagged then
|
787 |
|
|
Check_95_Keyword (Tok_Tagged, Tok_Private);
|
788 |
|
|
Check_95_Keyword (Tok_Tagged, Tok_Limited);
|
789 |
|
|
end if;
|
790 |
|
|
|
791 |
|
|
if Token /= Tok_Tagged then
|
792 |
|
|
Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
|
793 |
|
|
else
|
794 |
|
|
Set_Abstract_Present (Def_Node, True);
|
795 |
|
|
end if;
|
796 |
|
|
end if;
|
797 |
|
|
|
798 |
|
|
if Token = Tok_Tagged then
|
799 |
|
|
Set_Tagged_Present (Def_Node, True);
|
800 |
|
|
Scan; -- past TAGGED
|
801 |
|
|
end if;
|
802 |
|
|
|
803 |
|
|
if Token = Tok_Limited then
|
804 |
|
|
Set_Limited_Present (Def_Node, True);
|
805 |
|
|
Scan; -- past LIMITED
|
806 |
|
|
end if;
|
807 |
|
|
|
808 |
|
|
if Token = Tok_Abstract then
|
809 |
|
|
if Prev_Token = Tok_Tagged then
|
810 |
|
|
Error_Msg_SC -- CODEFIX
|
811 |
|
|
("ABSTRACT must come before TAGGED");
|
812 |
|
|
elsif Prev_Token = Tok_Limited then
|
813 |
|
|
Error_Msg_SC -- CODEFIX
|
814 |
|
|
("ABSTRACT must come before LIMITED");
|
815 |
|
|
end if;
|
816 |
|
|
|
817 |
|
|
Resync_Past_Semicolon;
|
818 |
|
|
|
819 |
|
|
elsif Token = Tok_Tagged then
|
820 |
|
|
Error_Msg_SC -- CODEFIX
|
821 |
|
|
("TAGGED must come before LIMITED");
|
822 |
|
|
Resync_Past_Semicolon;
|
823 |
|
|
end if;
|
824 |
|
|
|
825 |
|
|
Set_Sloc (Def_Node, Token_Ptr);
|
826 |
|
|
T_Private;
|
827 |
|
|
return Def_Node;
|
828 |
|
|
end P_Formal_Private_Type_Definition;
|
829 |
|
|
|
830 |
|
|
--------------------------------------------
|
831 |
|
|
-- 12.5.1 Formal Derived Type Definition --
|
832 |
|
|
--------------------------------------------
|
833 |
|
|
|
834 |
|
|
-- FORMAL_DERIVED_TYPE_DEFINITION ::=
|
835 |
|
|
-- [abstract] [limited | synchronized]
|
836 |
|
|
-- new SUBTYPE_MARK [[and INTERFACE_LIST] with private]
|
837 |
|
|
|
838 |
|
|
-- The caller has checked the initial token(s) is/are NEW, ABSTRACT NEW,
|
839 |
|
|
-- or LIMITED NEW, ABSTRACT LIMITED NEW, SYNCHRONIZED NEW or ABSTRACT
|
840 |
|
|
-- SYNCHRONIZED NEW.
|
841 |
|
|
|
842 |
|
|
-- Error recovery: cannot raise Error_Resync
|
843 |
|
|
|
844 |
|
|
function P_Formal_Derived_Type_Definition return Node_Id is
|
845 |
|
|
Def_Node : Node_Id;
|
846 |
|
|
|
847 |
|
|
begin
|
848 |
|
|
Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
|
849 |
|
|
|
850 |
|
|
if Token = Tok_Abstract then
|
851 |
|
|
Set_Abstract_Present (Def_Node);
|
852 |
|
|
Scan; -- past ABSTRACT
|
853 |
|
|
end if;
|
854 |
|
|
|
855 |
|
|
if Token = Tok_Limited then
|
856 |
|
|
Set_Limited_Present (Def_Node);
|
857 |
|
|
Scan; -- past LIMITED
|
858 |
|
|
|
859 |
|
|
if Ada_Version < Ada_05 then
|
860 |
|
|
Error_Msg_SP
|
861 |
|
|
("LIMITED in derived type is an Ada 2005 extension");
|
862 |
|
|
Error_Msg_SP
|
863 |
|
|
("\unit must be compiled with -gnat05 switch");
|
864 |
|
|
end if;
|
865 |
|
|
|
866 |
|
|
elsif Token = Tok_Synchronized then
|
867 |
|
|
Set_Synchronized_Present (Def_Node);
|
868 |
|
|
Scan; -- past SYNCHRONIZED
|
869 |
|
|
|
870 |
|
|
if Ada_Version < Ada_05 then
|
871 |
|
|
Error_Msg_SP
|
872 |
|
|
("SYNCHRONIZED in derived type is an Ada 2005 extension");
|
873 |
|
|
Error_Msg_SP
|
874 |
|
|
("\unit must be compiled with -gnat05 switch");
|
875 |
|
|
end if;
|
876 |
|
|
end if;
|
877 |
|
|
|
878 |
|
|
if Token = Tok_Abstract then
|
879 |
|
|
Scan; -- past ABSTRACT, diagnosed already in caller.
|
880 |
|
|
end if;
|
881 |
|
|
|
882 |
|
|
Scan; -- past NEW;
|
883 |
|
|
Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
|
884 |
|
|
No_Constraint;
|
885 |
|
|
|
886 |
|
|
-- Ada 2005 (AI-251): Deal with interfaces
|
887 |
|
|
|
888 |
|
|
if Token = Tok_And then
|
889 |
|
|
Scan; -- past AND
|
890 |
|
|
|
891 |
|
|
if Ada_Version < Ada_05 then
|
892 |
|
|
Error_Msg_SP
|
893 |
|
|
("abstract interface is an Ada 2005 extension");
|
894 |
|
|
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
|
895 |
|
|
end if;
|
896 |
|
|
|
897 |
|
|
Set_Interface_List (Def_Node, New_List);
|
898 |
|
|
|
899 |
|
|
loop
|
900 |
|
|
Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
|
901 |
|
|
exit when Token /= Tok_And;
|
902 |
|
|
Scan; -- past AND
|
903 |
|
|
end loop;
|
904 |
|
|
end if;
|
905 |
|
|
|
906 |
|
|
if Token = Tok_With then
|
907 |
|
|
Scan; -- past WITH
|
908 |
|
|
Set_Private_Present (Def_Node, True);
|
909 |
|
|
T_Private;
|
910 |
|
|
|
911 |
|
|
elsif Token = Tok_Tagged then
|
912 |
|
|
Scan;
|
913 |
|
|
|
914 |
|
|
if Token = Tok_Private then
|
915 |
|
|
Error_Msg_SC ("TAGGED should be WITH");
|
916 |
|
|
Set_Private_Present (Def_Node, True);
|
917 |
|
|
T_Private;
|
918 |
|
|
else
|
919 |
|
|
Ignore (Tok_Tagged);
|
920 |
|
|
end if;
|
921 |
|
|
end if;
|
922 |
|
|
|
923 |
|
|
return Def_Node;
|
924 |
|
|
end P_Formal_Derived_Type_Definition;
|
925 |
|
|
|
926 |
|
|
---------------------------------------------
|
927 |
|
|
-- 12.5.2 Formal Discrete Type Definition --
|
928 |
|
|
---------------------------------------------
|
929 |
|
|
|
930 |
|
|
-- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
|
931 |
|
|
|
932 |
|
|
-- The caller has checked the initial token is left paren
|
933 |
|
|
|
934 |
|
|
-- Error recovery: cannot raise Error_Resync
|
935 |
|
|
|
936 |
|
|
function P_Formal_Discrete_Type_Definition return Node_Id is
|
937 |
|
|
Def_Node : Node_Id;
|
938 |
|
|
|
939 |
|
|
begin
|
940 |
|
|
Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
|
941 |
|
|
Scan; -- past left paren
|
942 |
|
|
T_Box;
|
943 |
|
|
T_Right_Paren;
|
944 |
|
|
return Def_Node;
|
945 |
|
|
end P_Formal_Discrete_Type_Definition;
|
946 |
|
|
|
947 |
|
|
---------------------------------------------------
|
948 |
|
|
-- 12.5.2 Formal Signed Integer Type Definition --
|
949 |
|
|
---------------------------------------------------
|
950 |
|
|
|
951 |
|
|
-- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
|
952 |
|
|
|
953 |
|
|
-- The caller has checked the initial token is RANGE
|
954 |
|
|
|
955 |
|
|
-- Error recovery: cannot raise Error_Resync
|
956 |
|
|
|
957 |
|
|
function P_Formal_Signed_Integer_Type_Definition return Node_Id is
|
958 |
|
|
Def_Node : Node_Id;
|
959 |
|
|
|
960 |
|
|
begin
|
961 |
|
|
Def_Node :=
|
962 |
|
|
New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
|
963 |
|
|
Scan; -- past RANGE
|
964 |
|
|
T_Box;
|
965 |
|
|
return Def_Node;
|
966 |
|
|
end P_Formal_Signed_Integer_Type_Definition;
|
967 |
|
|
|
968 |
|
|
--------------------------------------------
|
969 |
|
|
-- 12.5.2 Formal Modular Type Definition --
|
970 |
|
|
--------------------------------------------
|
971 |
|
|
|
972 |
|
|
-- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
|
973 |
|
|
|
974 |
|
|
-- The caller has checked the initial token is MOD
|
975 |
|
|
|
976 |
|
|
-- Error recovery: cannot raise Error_Resync
|
977 |
|
|
|
978 |
|
|
function P_Formal_Modular_Type_Definition return Node_Id is
|
979 |
|
|
Def_Node : Node_Id;
|
980 |
|
|
|
981 |
|
|
begin
|
982 |
|
|
Def_Node :=
|
983 |
|
|
New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
|
984 |
|
|
Scan; -- past MOD
|
985 |
|
|
T_Box;
|
986 |
|
|
return Def_Node;
|
987 |
|
|
end P_Formal_Modular_Type_Definition;
|
988 |
|
|
|
989 |
|
|
----------------------------------------------
|
990 |
|
|
-- 12.5.2 Formal Floating Point Definition --
|
991 |
|
|
----------------------------------------------
|
992 |
|
|
|
993 |
|
|
-- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
|
994 |
|
|
|
995 |
|
|
-- The caller has checked the initial token is DIGITS
|
996 |
|
|
|
997 |
|
|
-- Error recovery: cannot raise Error_Resync
|
998 |
|
|
|
999 |
|
|
function P_Formal_Floating_Point_Definition return Node_Id is
|
1000 |
|
|
Def_Node : Node_Id;
|
1001 |
|
|
|
1002 |
|
|
begin
|
1003 |
|
|
Def_Node :=
|
1004 |
|
|
New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
|
1005 |
|
|
Scan; -- past DIGITS
|
1006 |
|
|
T_Box;
|
1007 |
|
|
return Def_Node;
|
1008 |
|
|
end P_Formal_Floating_Point_Definition;
|
1009 |
|
|
|
1010 |
|
|
-------------------------------------------
|
1011 |
|
|
-- 12.5.2 Formal Fixed Point Definition --
|
1012 |
|
|
-------------------------------------------
|
1013 |
|
|
|
1014 |
|
|
-- This routine parses either a formal ordinary fixed point definition
|
1015 |
|
|
-- or a formal decimal fixed point definition:
|
1016 |
|
|
|
1017 |
|
|
-- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
|
1018 |
|
|
|
1019 |
|
|
-- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
|
1020 |
|
|
|
1021 |
|
|
-- The caller has checked the initial token is DELTA
|
1022 |
|
|
|
1023 |
|
|
-- Error recovery: cannot raise Error_Resync
|
1024 |
|
|
|
1025 |
|
|
function P_Formal_Fixed_Point_Definition return Node_Id is
|
1026 |
|
|
Def_Node : Node_Id;
|
1027 |
|
|
Delta_Sloc : Source_Ptr;
|
1028 |
|
|
|
1029 |
|
|
begin
|
1030 |
|
|
Delta_Sloc := Token_Ptr;
|
1031 |
|
|
Scan; -- past DELTA
|
1032 |
|
|
T_Box;
|
1033 |
|
|
|
1034 |
|
|
if Token = Tok_Digits then
|
1035 |
|
|
Def_Node :=
|
1036 |
|
|
New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
|
1037 |
|
|
Scan; -- past DIGITS
|
1038 |
|
|
T_Box;
|
1039 |
|
|
else
|
1040 |
|
|
Def_Node :=
|
1041 |
|
|
New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
|
1042 |
|
|
end if;
|
1043 |
|
|
|
1044 |
|
|
return Def_Node;
|
1045 |
|
|
end P_Formal_Fixed_Point_Definition;
|
1046 |
|
|
|
1047 |
|
|
----------------------------------------------------
|
1048 |
|
|
-- 12.5.2 Formal Ordinary Fixed Point Definition --
|
1049 |
|
|
----------------------------------------------------
|
1050 |
|
|
|
1051 |
|
|
-- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
|
1052 |
|
|
|
1053 |
|
|
---------------------------------------------------
|
1054 |
|
|
-- 12.5.2 Formal Decimal Fixed Point Definition --
|
1055 |
|
|
---------------------------------------------------
|
1056 |
|
|
|
1057 |
|
|
-- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
|
1058 |
|
|
|
1059 |
|
|
------------------------------------------
|
1060 |
|
|
-- 12.5.3 Formal Array Type Definition --
|
1061 |
|
|
------------------------------------------
|
1062 |
|
|
|
1063 |
|
|
-- Parsed by P_Formal_Type_Definition (12.5)
|
1064 |
|
|
|
1065 |
|
|
-------------------------------------------
|
1066 |
|
|
-- 12.5.4 Formal Access Type Definition --
|
1067 |
|
|
-------------------------------------------
|
1068 |
|
|
|
1069 |
|
|
-- Parsed by P_Formal_Type_Definition (12.5)
|
1070 |
|
|
|
1071 |
|
|
-----------------------------------------
|
1072 |
|
|
-- 12.6 Formal Subprogram Declaration --
|
1073 |
|
|
-----------------------------------------
|
1074 |
|
|
|
1075 |
|
|
-- FORMAL_SUBPROGRAM_DECLARATION ::=
|
1076 |
|
|
-- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
|
1077 |
|
|
-- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
|
1078 |
|
|
|
1079 |
|
|
-- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
|
1080 |
|
|
-- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
|
1081 |
|
|
|
1082 |
|
|
-- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
|
1083 |
|
|
-- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT];
|
1084 |
|
|
|
1085 |
|
|
-- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
|
1086 |
|
|
|
1087 |
|
|
-- DEFAULT_NAME ::= NAME | null
|
1088 |
|
|
|
1089 |
|
|
-- The caller has checked that the initial tokens are WITH FUNCTION or
|
1090 |
|
|
-- WITH PROCEDURE, and the initial WITH has been scanned out.
|
1091 |
|
|
|
1092 |
|
|
-- A null default is an Ada 2005 feature
|
1093 |
|
|
|
1094 |
|
|
-- Error recovery: cannot raise Error_Resync
|
1095 |
|
|
|
1096 |
|
|
function P_Formal_Subprogram_Declaration return Node_Id is
|
1097 |
|
|
Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
|
1098 |
|
|
Spec_Node : constant Node_Id := P_Subprogram_Specification;
|
1099 |
|
|
Def_Node : Node_Id;
|
1100 |
|
|
|
1101 |
|
|
begin
|
1102 |
|
|
if Token = Tok_Is then
|
1103 |
|
|
T_Is; -- past IS, skip extra IS or ";"
|
1104 |
|
|
|
1105 |
|
|
if Token = Tok_Abstract then
|
1106 |
|
|
Def_Node :=
|
1107 |
|
|
New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
|
1108 |
|
|
Scan; -- past ABSTRACT
|
1109 |
|
|
|
1110 |
|
|
if Ada_Version < Ada_05 then
|
1111 |
|
|
Error_Msg_SP
|
1112 |
|
|
("formal abstract subprograms are an Ada 2005 extension");
|
1113 |
|
|
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
|
1114 |
|
|
end if;
|
1115 |
|
|
|
1116 |
|
|
else
|
1117 |
|
|
Def_Node :=
|
1118 |
|
|
New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
|
1119 |
|
|
end if;
|
1120 |
|
|
|
1121 |
|
|
Set_Specification (Def_Node, Spec_Node);
|
1122 |
|
|
|
1123 |
|
|
if Token = Tok_Semicolon then
|
1124 |
|
|
Scan; -- past ";"
|
1125 |
|
|
|
1126 |
|
|
elsif Token = Tok_Box then
|
1127 |
|
|
Set_Box_Present (Def_Node, True);
|
1128 |
|
|
Scan; -- past <>
|
1129 |
|
|
T_Semicolon;
|
1130 |
|
|
|
1131 |
|
|
elsif Token = Tok_Null then
|
1132 |
|
|
if Ada_Version < Ada_05 then
|
1133 |
|
|
Error_Msg_SP
|
1134 |
|
|
("null default subprograms are an Ada 2005 extension");
|
1135 |
|
|
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
|
1136 |
|
|
end if;
|
1137 |
|
|
|
1138 |
|
|
if Nkind (Spec_Node) = N_Procedure_Specification then
|
1139 |
|
|
Set_Null_Present (Spec_Node);
|
1140 |
|
|
else
|
1141 |
|
|
Error_Msg_SP ("only procedures can be null");
|
1142 |
|
|
end if;
|
1143 |
|
|
|
1144 |
|
|
Scan; -- past NULL
|
1145 |
|
|
T_Semicolon;
|
1146 |
|
|
|
1147 |
|
|
else
|
1148 |
|
|
Set_Default_Name (Def_Node, P_Name);
|
1149 |
|
|
T_Semicolon;
|
1150 |
|
|
end if;
|
1151 |
|
|
|
1152 |
|
|
else
|
1153 |
|
|
Def_Node :=
|
1154 |
|
|
New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
|
1155 |
|
|
Set_Specification (Def_Node, Spec_Node);
|
1156 |
|
|
T_Semicolon;
|
1157 |
|
|
end if;
|
1158 |
|
|
|
1159 |
|
|
return Def_Node;
|
1160 |
|
|
end P_Formal_Subprogram_Declaration;
|
1161 |
|
|
|
1162 |
|
|
------------------------------
|
1163 |
|
|
-- 12.6 Subprogram Default --
|
1164 |
|
|
------------------------------
|
1165 |
|
|
|
1166 |
|
|
-- Parsed by P_Formal_Procedure_Declaration (12.6)
|
1167 |
|
|
|
1168 |
|
|
------------------------
|
1169 |
|
|
-- 12.6 Default Name --
|
1170 |
|
|
------------------------
|
1171 |
|
|
|
1172 |
|
|
-- Parsed by P_Formal_Procedure_Declaration (12.6)
|
1173 |
|
|
|
1174 |
|
|
--------------------------------------
|
1175 |
|
|
-- 12.7 Formal Package Declaration --
|
1176 |
|
|
--------------------------------------
|
1177 |
|
|
|
1178 |
|
|
-- FORMAL_PACKAGE_DECLARATION ::=
|
1179 |
|
|
-- with package DEFINING_IDENTIFIER
|
1180 |
|
|
-- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
|
1181 |
|
|
|
1182 |
|
|
-- FORMAL_PACKAGE_ACTUAL_PART ::=
|
1183 |
|
|
-- ([OTHERS =>] <>) |
|
1184 |
|
|
-- [GENERIC_ACTUAL_PART]
|
1185 |
|
|
-- (FORMAL_PACKAGE_ASSOCIATION {, FORMAL_PACKAGE_ASSOCIATION}
|
1186 |
|
|
-- [, OTHERS => <>)
|
1187 |
|
|
|
1188 |
|
|
-- FORMAL_PACKAGE_ASSOCIATION ::=
|
1189 |
|
|
-- GENERIC_ASSOCIATION
|
1190 |
|
|
-- | GENERIC_FORMAL_PARAMETER_SELECTOR_NAME => <>
|
1191 |
|
|
|
1192 |
|
|
-- The caller has checked that the initial tokens are WITH PACKAGE,
|
1193 |
|
|
-- and the initial WITH has been scanned out (so Token = Tok_Package).
|
1194 |
|
|
|
1195 |
|
|
-- Error recovery: cannot raise Error_Resync
|
1196 |
|
|
|
1197 |
|
|
function P_Formal_Package_Declaration return Node_Id is
|
1198 |
|
|
Def_Node : Node_Id;
|
1199 |
|
|
Scan_State : Saved_Scan_State;
|
1200 |
|
|
|
1201 |
|
|
begin
|
1202 |
|
|
Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
|
1203 |
|
|
Scan; -- past PACKAGE
|
1204 |
|
|
Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
|
1205 |
|
|
T_Is;
|
1206 |
|
|
T_New;
|
1207 |
|
|
Set_Name (Def_Node, P_Qualified_Simple_Name);
|
1208 |
|
|
|
1209 |
|
|
if Token = Tok_Left_Paren then
|
1210 |
|
|
Save_Scan_State (Scan_State); -- at the left paren
|
1211 |
|
|
Scan; -- past the left paren
|
1212 |
|
|
|
1213 |
|
|
if Token = Tok_Box then
|
1214 |
|
|
Set_Box_Present (Def_Node, True);
|
1215 |
|
|
Scan; -- past box
|
1216 |
|
|
T_Right_Paren;
|
1217 |
|
|
|
1218 |
|
|
else
|
1219 |
|
|
Restore_Scan_State (Scan_State); -- to the left paren
|
1220 |
|
|
Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
|
1221 |
|
|
end if;
|
1222 |
|
|
end if;
|
1223 |
|
|
|
1224 |
|
|
T_Semicolon;
|
1225 |
|
|
return Def_Node;
|
1226 |
|
|
end P_Formal_Package_Declaration;
|
1227 |
|
|
|
1228 |
|
|
--------------------------------------
|
1229 |
|
|
-- 12.7 Formal Package Actual Part --
|
1230 |
|
|
--------------------------------------
|
1231 |
|
|
|
1232 |
|
|
-- Parsed by P_Formal_Package_Declaration (12.7)
|
1233 |
|
|
|
1234 |
|
|
end Ch12;
|