Add assember CFI directives to millicode division and remainder routines.
[official-gcc.git] / gcc / ada / par-ch12.adb
bloba35260f4602c35be523ae2f3fa4e69698822a66e
1 ------------------------------------------------------------------------------
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-2023, 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 ------------------------------------------------------------------------------
26 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order
28 -- by RM section rather than alphabetical
30 separate (Par)
31 package body Ch12 is
33 -- Local functions, used only in this chapter
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;
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.
53 --------------------------------
54 -- 12.1 Generic (also 8.5.5) --
55 --------------------------------
57 -- This routine parses either one of the forms of a generic declaration
58 -- or a generic renaming declaration.
60 -- GENERIC_DECLARATION ::=
61 -- GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
63 -- GENERIC_SUBPROGRAM_DECLARATION ::=
64 -- GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION
65 -- [ASPECT_SPECIFICATIONS];
67 -- GENERIC_PACKAGE_DECLARATION ::=
68 -- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION
69 -- [ASPECT_SPECIFICATIONS];
71 -- GENERIC_FORMAL_PART ::=
72 -- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
74 -- GENERIC_RENAMING_DECLARATION ::=
75 -- generic package DEFINING_PROGRAM_UNIT_NAME
76 -- renames generic_package_NAME
77 -- [ASPECT_SPECIFICATIONS];
78 -- | generic procedure DEFINING_PROGRAM_UNIT_NAME
79 -- renames generic_procedure_NAME
80 -- [ASPECT_SPECIFICATIONS];
81 -- | generic function DEFINING_PROGRAM_UNIT_NAME
82 -- renames generic_function_NAME
83 -- [ASPECT_SPECIFICATIONS];
85 -- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
86 -- FORMAL_OBJECT_DECLARATION
87 -- | FORMAL_TYPE_DECLARATION
88 -- | FORMAL_SUBPROGRAM_DECLARATION
89 -- | FORMAL_PACKAGE_DECLARATION
91 -- The caller has checked that the initial token is GENERIC
93 -- Error recovery: can raise Error_Resync
95 function P_Generic return Node_Id is
96 Gen_Sloc : constant Source_Ptr := Token_Ptr;
97 Gen_Decl : Node_Id;
98 Decl_Node : Node_Id;
99 Decls : List_Id;
100 Def_Unit : Node_Id;
101 Ren_Token : Token_Type;
102 Scan_State : Saved_Scan_State;
104 begin
105 Scan; -- past GENERIC
107 if Token = Tok_Private then
108 Error_Msg_SC -- CODEFIX
109 ("PRIVATE goes before GENERIC, not after");
110 Scan; -- past junk PRIVATE token
111 end if;
113 Save_Scan_State (Scan_State); -- at token past GENERIC
115 -- Check for generic renaming declaration case
117 if Token in Tok_Package | Tok_Function | Tok_Procedure then
118 Ren_Token := Token;
119 Scan; -- scan past PACKAGE, FUNCTION or PROCEDURE
121 if Token = Tok_Identifier then
122 Def_Unit := P_Defining_Program_Unit_Name;
124 Check_Misspelling_Of (Tok_Renames);
126 if Token = Tok_Renames then
127 if Ren_Token = Tok_Package then
128 Decl_Node := New_Node
129 (N_Generic_Package_Renaming_Declaration, Gen_Sloc);
131 elsif Ren_Token = Tok_Procedure then
132 Decl_Node := New_Node
133 (N_Generic_Procedure_Renaming_Declaration, Gen_Sloc);
135 else -- Ren_Token = Tok_Function then
136 Decl_Node := New_Node
137 (N_Generic_Function_Renaming_Declaration, Gen_Sloc);
138 end if;
140 Scan; -- past RENAMES
141 Set_Defining_Unit_Name (Decl_Node, Def_Unit);
142 Set_Name (Decl_Node, P_Name);
144 P_Aspect_Specifications (Decl_Node, Semicolon => False);
145 TF_Semicolon;
146 return Decl_Node;
147 end if;
148 end if;
149 end if;
151 -- Fall through if this is *not* a generic renaming declaration
153 Restore_Scan_State (Scan_State);
154 Decls := New_List;
156 -- Loop through generic parameter declarations and use clauses
158 Decl_Loop : loop
159 P_Pragmas_Opt (Decls);
161 if Token = Tok_Private then
162 Error_Msg_S ("generic private child packages not permitted");
163 Scan; -- past PRIVATE
164 end if;
166 if Token = Tok_Use then
167 P_Use_Clause (Decls);
169 else
170 -- Parse a generic parameter declaration
172 if Token = Tok_Identifier then
173 P_Formal_Object_Declarations (Decls);
175 elsif Token = Tok_Type then
176 Append (P_Formal_Type_Declaration, Decls);
178 elsif Token = Tok_With then
179 Scan; -- past WITH
181 if Token = Tok_Package then
182 Append (P_Formal_Package_Declaration, Decls);
184 elsif Token in Tok_Procedure | Tok_Function then
185 Append (P_Formal_Subprogram_Declaration, Decls);
187 else
188 Error_Msg_BC -- CODEFIX
189 ("FUNCTION, PROCEDURE or PACKAGE expected here");
190 Resync_Past_Semicolon;
191 end if;
193 elsif Token = Tok_Subtype then
194 Error_Msg_SC ("subtype declaration not allowed " &
195 "as generic parameter declaration!");
196 Resync_Past_Semicolon;
198 else
199 exit Decl_Loop;
200 end if;
201 end if;
202 end loop Decl_Loop;
204 -- Generic formal part is scanned, scan out subprogram or package spec
206 if Token = Tok_Package then
207 Gen_Decl := New_Node (N_Generic_Package_Declaration, Gen_Sloc);
208 Set_Specification (Gen_Decl, P_Package (Pf_Spcn));
210 -- Aspects have been parsed by the package spec. Move them to the
211 -- generic declaration where they belong.
213 Move_Aspects (Specification (Gen_Decl), Gen_Decl);
215 else
216 Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
217 Set_Specification (Gen_Decl, P_Subprogram_Specification);
219 if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
220 N_Defining_Program_Unit_Name
221 and then Scope.Last > 0
222 then
223 Error_Msg_SP ("child unit allowed only at library level");
224 end if;
226 P_Aspect_Specifications (Gen_Decl);
227 end if;
229 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
230 return Gen_Decl;
231 end P_Generic;
233 -------------------------------
234 -- 12.1 Generic Declaration --
235 -------------------------------
237 -- Parsed by P_Generic (12.1)
239 ------------------------------------------
240 -- 12.1 Generic Subprogram Declaration --
241 ------------------------------------------
243 -- Parsed by P_Generic (12.1)
245 ---------------------------------------
246 -- 12.1 Generic Package Declaration --
247 ---------------------------------------
249 -- Parsed by P_Generic (12.1)
251 -------------------------------
252 -- 12.1 Generic Formal Part --
253 -------------------------------
255 -- Parsed by P_Generic (12.1)
257 -------------------------------------------------
258 -- 12.1 Generic Formal Parameter Declaration --
259 -------------------------------------------------
261 -- Parsed by P_Generic (12.1)
263 ---------------------------------
264 -- 12.3 Generic Instantiation --
265 ---------------------------------
267 -- Generic package instantiation parsed by P_Package (7.1)
268 -- Generic procedure instantiation parsed by P_Subprogram (6.1)
269 -- Generic function instantiation parsed by P_Subprogram (6.1)
271 -------------------------------
272 -- 12.3 Generic Actual Part --
273 -------------------------------
275 -- GENERIC_ACTUAL_PART ::=
276 -- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
278 -- Returns a list of generic associations, or Empty if none are present
280 -- Error recovery: cannot raise Error_Resync
282 function P_Generic_Actual_Part_Opt return List_Id is
283 Association_List : List_Id;
285 begin
286 -- Figure out if a generic actual part operation is present. Clearly
287 -- there is no generic actual part if the current token is semicolon
288 -- or if we have aspect specifications present.
290 if Token = Tok_Semicolon or else Aspect_Specifications_Present then
291 return No_List;
293 -- If we don't have a left paren, then we have an error, and the job
294 -- is to figure out whether a left paren or semicolon was intended.
295 -- We assume a missing left paren (and hence a generic actual part
296 -- present) if the current token is not on a new line, or if it is
297 -- indented from the subprogram token. Otherwise assume missing
298 -- semicolon (which will be diagnosed by caller) and no generic part
300 elsif Token /= Tok_Left_Paren
301 and then Token_Is_At_Start_Of_Line
302 and then Start_Column <= Scopes (Scope.Last).Ecol
303 then
304 return No_List;
306 -- Otherwise we have a generic actual part (either a left paren is
307 -- present, or we have decided that there must be a missing left paren)
309 else
310 Association_List := New_List;
311 T_Left_Paren;
313 loop
314 Append (P_Generic_Association, Association_List);
315 exit when not Comma_Present;
316 end loop;
318 T_Right_Paren;
319 return Association_List;
320 end if;
322 end P_Generic_Actual_Part_Opt;
324 -------------------------------
325 -- 12.3 Generic Association --
326 -------------------------------
328 -- GENERIC_ASSOCIATION ::=
329 -- [generic_formal_parameter_SELECTOR_NAME =>]
330 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER
332 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
333 -- EXPRESSION | variable_NAME | subprogram_NAME
334 -- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
336 -- Error recovery: cannot raise Error_Resync
338 function P_Generic_Association return Node_Id is
339 Scan_State : Saved_Scan_State;
340 Param_Name_Node : Node_Id;
341 Generic_Assoc_Node : Node_Id;
343 begin
344 Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
346 -- Ada 2005: an association can be given by: others => <>
348 if Token = Tok_Others then
349 Error_Msg_Ada_2005_Extension
350 ("partial parameterization of formal package");
352 Scan; -- past OTHERS
354 if Token /= Tok_Arrow then
355 Error_Msg_BC ("expect `='>` after OTHERS");
356 else
357 Scan; -- past arrow
358 end if;
360 if Token /= Tok_Box then
361 Error_Msg_BC ("expect `'<'>` after `='>`");
362 else
363 Scan; -- past box
364 end if;
366 -- Source position of the others choice is beginning of construct
368 return New_Node (N_Others_Choice, Sloc (Generic_Assoc_Node));
369 end if;
371 if Token in Token_Class_Desig then
372 Param_Name_Node := Token_Node;
373 Save_Scan_State (Scan_State); -- at designator
374 Scan; -- past simple name or operator symbol
376 if Token = Tok_Arrow then
377 Scan; -- past arrow
378 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
379 else
380 Restore_Scan_State (Scan_State); -- to designator
381 end if;
382 end if;
384 -- In Ada 2005 the actual can be a box
386 if Token = Tok_Box then
387 Scan;
388 Set_Box_Present (Generic_Assoc_Node);
389 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, Empty);
391 else
392 Set_Explicit_Generic_Actual_Parameter
393 (Generic_Assoc_Node, P_Expression);
394 end if;
396 return Generic_Assoc_Node;
397 end P_Generic_Association;
399 ---------------------------------------------
400 -- 12.3 Explicit Generic Actual Parameter --
401 ---------------------------------------------
403 -- Parsed by P_Generic_Association (12.3)
405 --------------------------------------
406 -- 12.4 Formal Object Declarations --
407 --------------------------------------
409 -- FORMAL_OBJECT_DECLARATION ::=
410 -- DEFINING_IDENTIFIER_LIST :
411 -- MODE [NULL_EXCLUSION] SUBTYPE_MARK [:= DEFAULT_EXPRESSION]
412 -- [ASPECT_SPECIFICATIONS];
413 -- | DEFINING_IDENTIFIER_LIST :
414 -- MODE ACCESS_DEFINITION [:= DEFAULT_EXPRESSION];
415 -- [ASPECT_SPECIFICATIONS];
417 -- The caller has checked that the initial token is an identifier
419 -- Error recovery: cannot raise Error_Resync
421 procedure P_Formal_Object_Declarations (Decls : List_Id) is
422 Decl_Node : Node_Id;
423 Ident : Pos;
424 Not_Null_Present : Boolean := False;
425 Num_Idents : Pos;
426 Scan_State : Saved_Scan_State;
428 Idents : array (Pos range 1 .. 4096) of Entity_Id;
429 -- This array holds the list of defining identifiers. The upper bound
430 -- of 4096 is intended to be essentially infinite, and we do not even
431 -- bother to check for it being exceeded.
433 begin
434 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
435 Num_Idents := 1;
436 while Comma_Present loop
437 Num_Idents := Num_Idents + 1;
438 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
439 end loop;
441 T_Colon;
443 -- If there are multiple identifiers, we repeatedly scan the
444 -- type and initialization expression information by resetting
445 -- the scan pointer (so that we get completely separate trees
446 -- for each occurrence).
448 if Num_Idents > 1 then
449 Save_Scan_State (Scan_State);
450 end if;
452 -- Loop through defining identifiers in list
454 Ident := 1;
455 Ident_Loop : loop
456 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
457 Set_Defining_Identifier (Decl_Node, Idents (Ident));
458 P_Mode (Decl_Node);
460 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-423)
462 -- Ada 2005 (AI-423): Formal object with an access definition
464 if Token = Tok_Access then
466 -- The access definition is still parsed and set even though
467 -- the compilation may not use the proper switch. This action
468 -- ensures the required local error recovery.
470 Set_Access_Definition (Decl_Node,
471 P_Access_Definition (Not_Null_Present));
473 Error_Msg_Ada_2005_Extension
474 ("access definition in formal object declaration");
476 -- Formal object with a subtype mark
478 else
479 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
480 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
481 end if;
483 No_Constraint;
484 Set_Default_Expression (Decl_Node, Init_Expr_Opt);
485 P_Aspect_Specifications (Decl_Node);
487 if Ident > 1 then
488 Set_Prev_Ids (Decl_Node, True);
489 end if;
491 if Ident < Num_Idents then
492 Set_More_Ids (Decl_Node, True);
493 end if;
495 Append (Decl_Node, Decls);
497 exit Ident_Loop when Ident = Num_Idents;
498 Ident := Ident + 1;
499 Restore_Scan_State (Scan_State);
500 end loop Ident_Loop;
501 end P_Formal_Object_Declarations;
503 -----------------------------------
504 -- 12.5 Formal Type Declaration --
505 -----------------------------------
507 -- FORMAL_TYPE_DECLARATION ::=
508 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
509 -- is FORMAL_TYPE_DEFINITION
510 -- [ASPECT_SPECIFICATIONS];
512 -- The caller has checked that the initial token is TYPE
514 -- Error recovery: cannot raise Error_Resync
516 function P_Formal_Type_Declaration return Node_Id is
517 Decl_Node : Node_Id;
518 Def_Node : Node_Id;
520 begin
521 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
522 Scan; -- past TYPE
523 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
525 if P_Unknown_Discriminant_Part_Opt then
526 Set_Unknown_Discriminants_Present (Decl_Node, True);
527 else
528 Set_Discriminant_Specifications
529 (Decl_Node, P_Known_Discriminant_Part_Opt);
530 end if;
532 if Token = Tok_Semicolon then
534 -- Ada 2012: Incomplete formal type
536 Scan; -- past semicolon
538 Error_Msg_Ada_2012_Feature
539 ("formal incomplete type", Sloc (Decl_Node));
541 Set_Formal_Type_Definition
542 (Decl_Node,
543 New_Node (N_Formal_Incomplete_Type_Definition, Token_Ptr));
544 return Decl_Node;
546 else
547 T_Is;
548 end if;
550 Def_Node := P_Formal_Type_Definition;
552 if Nkind (Def_Node) = N_Formal_Incomplete_Type_Definition then
553 Error_Msg_Ada_2012_Feature
554 ("formal incomplete type", Sloc (Decl_Node));
555 end if;
557 if Def_Node /= Error then
558 Set_Formal_Type_Definition (Decl_Node, Def_Node);
560 if Token = Tok_Or then
561 Error_Msg_Ada_2022_Feature
562 ("default for formal type", Sloc (Decl_Node));
563 Scan; -- Past OR
565 if Token /= Tok_Use then
566 Error_Msg_SC ("missing USE for default subtype");
567 else
568 Scan; -- Past USE
569 Set_Default_Subtype_Mark (Decl_Node, P_Name);
570 end if;
571 end if;
573 P_Aspect_Specifications (Decl_Node);
575 else
576 Decl_Node := Error;
578 -- If we have aspect specifications, skip them
580 if Aspect_Specifications_Present then
581 P_Aspect_Specifications (Error);
583 -- If we have semicolon, skip it to avoid cascaded errors
585 elsif Token = Tok_Semicolon then
586 Scan; -- past semicolon
587 end if;
588 end if;
590 return Decl_Node;
591 end P_Formal_Type_Declaration;
593 ----------------------------------
594 -- 12.5 Formal Type Definition --
595 ----------------------------------
597 -- FORMAL_TYPE_DEFINITION ::=
598 -- FORMAL_PRIVATE_TYPE_DEFINITION
599 -- | FORMAL_INCOMPLETE_TYPE_DEFINITION
600 -- | FORMAL_DERIVED_TYPE_DEFINITION
601 -- | FORMAL_DISCRETE_TYPE_DEFINITION
602 -- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
603 -- | FORMAL_MODULAR_TYPE_DEFINITION
604 -- | FORMAL_FLOATING_POINT_DEFINITION
605 -- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
606 -- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
607 -- | FORMAL_ARRAY_TYPE_DEFINITION
608 -- | FORMAL_ACCESS_TYPE_DEFINITION
609 -- | FORMAL_INTERFACE_TYPE_DEFINITION
611 -- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
613 -- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
615 -- FORMAL_INTERFACE_TYPE_DEFINITION ::= INTERFACE_TYPE_DEFINITION
617 function P_Formal_Type_Definition return Node_Id is
618 Scan_State : Saved_Scan_State;
619 Typedef_Node : Node_Id;
621 begin
622 if Token_Name = Name_Abstract then
623 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
624 end if;
626 if Token_Name = Name_Tagged then
627 Check_95_Keyword (Tok_Tagged, Tok_Private);
628 Check_95_Keyword (Tok_Tagged, Tok_Limited);
629 end if;
631 case Token is
633 -- Mostly we can tell what we have from the initial token. The one
634 -- exception is ABSTRACT, where we have to scan ahead to see if we
635 -- have a formal derived type or a formal private type definition.
637 -- In addition, in Ada 2005 LIMITED may appear after abstract, so
638 -- that the lookahead must be extended by one more token.
640 when Tok_Abstract =>
641 Save_Scan_State (Scan_State);
642 Scan; -- past ABSTRACT
644 if Token = Tok_New then
645 Restore_Scan_State (Scan_State); -- to ABSTRACT
646 return P_Formal_Derived_Type_Definition;
648 elsif Token = Tok_Limited then
649 Scan; -- past LIMITED
651 if Token = Tok_New then
652 Restore_Scan_State (Scan_State); -- to ABSTRACT
653 return P_Formal_Derived_Type_Definition;
655 else
656 Restore_Scan_State (Scan_State); -- to ABSTRACT
657 return P_Formal_Private_Type_Definition;
658 end if;
660 -- Ada 2005 (AI-443): Abstract synchronized formal derived type
662 elsif Token = Tok_Synchronized then
663 Restore_Scan_State (Scan_State); -- to ABSTRACT
664 return P_Formal_Derived_Type_Definition;
666 else
667 Restore_Scan_State (Scan_State); -- to ABSTRACT
668 return P_Formal_Private_Type_Definition;
669 end if;
671 when Tok_Access =>
672 return P_Access_Type_Definition;
674 when Tok_Array =>
675 return P_Array_Type_Definition;
677 when Tok_Delta =>
678 return P_Formal_Fixed_Point_Definition;
680 when Tok_Digits =>
681 return P_Formal_Floating_Point_Definition;
683 when Tok_Interface => -- Ada 2005 (AI-251)
684 return P_Interface_Type_Definition (Abstract_Present => False);
686 when Tok_Left_Paren =>
687 return P_Formal_Discrete_Type_Definition;
689 when Tok_Limited =>
690 Save_Scan_State (Scan_State);
691 Scan; -- past LIMITED
693 if Token = Tok_Interface then
694 Typedef_Node :=
695 P_Interface_Type_Definition (Abstract_Present => False);
696 Set_Limited_Present (Typedef_Node);
697 return Typedef_Node;
699 elsif Token = Tok_New then
700 Restore_Scan_State (Scan_State); -- to LIMITED
701 return P_Formal_Derived_Type_Definition;
703 else
704 if Token = Tok_Abstract then
705 Error_Msg_SC -- CODEFIX
706 ("ABSTRACT must come before LIMITED");
707 Scan; -- past improper ABSTRACT
709 if Token = Tok_New then
710 Restore_Scan_State (Scan_State); -- to LIMITED
711 return P_Formal_Derived_Type_Definition;
713 else
714 Restore_Scan_State (Scan_State);
715 return P_Formal_Private_Type_Definition;
716 end if;
717 end if;
719 Restore_Scan_State (Scan_State);
720 return P_Formal_Private_Type_Definition;
721 end if;
723 when Tok_Mod =>
724 return P_Formal_Modular_Type_Definition;
726 when Tok_New =>
727 return P_Formal_Derived_Type_Definition;
729 when Tok_Not =>
730 if P_Null_Exclusion then
731 Typedef_Node := P_Access_Type_Definition;
732 Set_Null_Exclusion_Present (Typedef_Node);
733 return Typedef_Node;
735 else
736 Error_Msg_SC ("expect valid formal access definition!");
737 Resync_Past_Semicolon;
738 return Error;
739 end if;
741 when Tok_Or =>
742 -- Ada_2022: incomplete type with default
743 return
744 New_Node (N_Formal_Incomplete_Type_Definition, Token_Ptr);
746 when Tok_Private =>
747 return P_Formal_Private_Type_Definition;
749 when Tok_Tagged =>
750 if Next_Token_Is (Tok_Semicolon)
751 or else Next_Token_Is (Tok_Or)
752 then
753 Typedef_Node :=
754 New_Node (N_Formal_Incomplete_Type_Definition, Token_Ptr);
755 Set_Tagged_Present (Typedef_Node);
757 Scan; -- past tagged
758 return Typedef_Node;
760 else
761 return P_Formal_Private_Type_Definition;
762 end if;
764 when Tok_Range =>
765 return P_Formal_Signed_Integer_Type_Definition;
767 when Tok_Record =>
768 Error_Msg_SC ("record not allowed in generic type definition!");
769 Discard_Junk_Node (P_Record_Definition);
770 return Error;
772 -- Ada 2005 (AI-345): Task, Protected or Synchronized interface or
773 -- (AI-443): Synchronized formal derived type declaration.
775 when Tok_Protected
776 | Tok_Synchronized
777 | Tok_Task
779 declare
780 Saved_Token : constant Token_Type := Token;
782 begin
783 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
785 -- Synchronized derived type
787 if Token = Tok_New then
788 Typedef_Node := P_Formal_Derived_Type_Definition;
790 if Saved_Token = Tok_Synchronized then
791 Set_Synchronized_Present (Typedef_Node);
792 else
793 Error_Msg_SC ("invalid kind of formal derived type");
794 end if;
796 -- Interface
798 else
799 Typedef_Node :=
800 P_Interface_Type_Definition (Abstract_Present => False);
802 case Saved_Token is
803 when Tok_Task =>
804 Set_Task_Present (Typedef_Node);
806 when Tok_Protected =>
807 Set_Protected_Present (Typedef_Node);
809 when Tok_Synchronized =>
810 Set_Synchronized_Present (Typedef_Node);
812 when others =>
813 null;
814 end case;
815 end if;
817 return Typedef_Node;
818 end;
820 when others =>
821 Error_Msg_BC ("expecting generic type definition here");
822 Resync_Past_Semicolon;
823 return Error;
824 end case;
825 end P_Formal_Type_Definition;
827 --------------------------------------------
828 -- 12.5.1 Formal Private Type Definition --
829 --------------------------------------------
831 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
832 -- [[abstract] tagged] [limited] private
834 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
835 -- TAGGED or LIMITED
837 -- Error recovery: cannot raise Error_Resync
839 function P_Formal_Private_Type_Definition return Node_Id is
840 Def_Node : Node_Id;
842 begin
843 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
845 if Token = Tok_Abstract then
846 Scan; -- past ABSTRACT
848 if Token_Name = Name_Tagged then
849 Check_95_Keyword (Tok_Tagged, Tok_Private);
850 Check_95_Keyword (Tok_Tagged, Tok_Limited);
851 end if;
853 if Token /= Tok_Tagged then
854 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
855 else
856 Set_Abstract_Present (Def_Node, True);
857 end if;
858 end if;
860 if Token = Tok_Tagged then
861 Set_Tagged_Present (Def_Node, True);
862 Scan; -- past TAGGED
863 end if;
865 if Token = Tok_Limited then
866 Set_Limited_Present (Def_Node, True);
867 Scan; -- past LIMITED
868 end if;
870 if Token = Tok_Abstract then
871 if Prev_Token = Tok_Tagged then
872 Error_Msg_SC -- CODEFIX
873 ("ABSTRACT must come before TAGGED");
874 elsif Prev_Token = Tok_Limited then
875 Error_Msg_SC -- CODEFIX
876 ("ABSTRACT must come before LIMITED");
877 end if;
879 Resync_Past_Semicolon;
881 elsif Token = Tok_Tagged then
882 Error_Msg_SC -- CODEFIX
883 ("TAGGED must come before LIMITED");
884 Resync_Past_Semicolon;
885 end if;
887 Set_Sloc (Def_Node, Token_Ptr);
888 T_Private;
890 if Token = Tok_Tagged then -- CODEFIX
891 Error_Msg_SC ("TAGGED must come before PRIVATE");
892 Scan; -- past TAGGED
894 elsif Token = Tok_Abstract then -- CODEFIX
895 Error_Msg_SC ("`ABSTRACT TAGGED` must come before PRIVATE");
896 Scan; -- past ABSTRACT
898 if Token = Tok_Tagged then
899 Scan; -- past TAGGED
900 end if;
901 end if;
903 return Def_Node;
904 end P_Formal_Private_Type_Definition;
906 --------------------------------------------
907 -- 12.5.1 Formal Derived Type Definition --
908 --------------------------------------------
910 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
911 -- [abstract] [limited | synchronized]
912 -- new SUBTYPE_MARK [[and INTERFACE_LIST] with private]
914 -- The caller has checked the initial token(s) is/are NEW, ABSTRACT NEW,
915 -- or LIMITED NEW, ABSTRACT LIMITED NEW, SYNCHRONIZED NEW or ABSTRACT
916 -- SYNCHRONIZED NEW.
918 -- Error recovery: cannot raise Error_Resync
920 function P_Formal_Derived_Type_Definition return Node_Id is
921 Def_Node : Node_Id;
923 begin
924 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
926 if Token = Tok_Abstract then
927 Set_Abstract_Present (Def_Node);
928 Scan; -- past ABSTRACT
929 end if;
931 if Token = Tok_Limited then
932 Set_Limited_Present (Def_Node);
933 Scan; -- past LIMITED
935 Error_Msg_Ada_2005_Extension ("LIMITED in derived type");
937 elsif Token = Tok_Synchronized then
938 Set_Synchronized_Present (Def_Node);
939 Scan; -- past SYNCHRONIZED
941 Error_Msg_Ada_2005_Extension ("SYNCHRONIZED in derived type");
942 end if;
944 if Token = Tok_Abstract then
945 Scan; -- past ABSTRACT, diagnosed already in caller.
946 end if;
948 Scan; -- past NEW;
949 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
950 No_Constraint;
952 -- Ada 2005 (AI-251): Deal with interfaces
954 if Token = Tok_And then
955 Scan; -- past AND
957 Error_Msg_Ada_2005_Extension ("abstract interface");
959 Set_Interface_List (Def_Node, New_List);
961 loop
962 Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
963 exit when Token /= Tok_And;
964 Scan; -- past AND
965 end loop;
966 end if;
968 if Token = Tok_With then
970 if Next_Token_Is (Tok_Private) then
971 Scan; -- past WITH
972 Set_Private_Present (Def_Node, True);
973 T_Private;
974 else
975 -- Formal type has aspect specifications, parsed later.
976 -- Otherwise this is a formal derived type. Note that it may
977 -- also include later aspect specifications, as in:
979 -- type DT is new T with private with Atomic;
981 Error_Msg_Ada_2022_Feature
982 ("formal type with aspect specification", Token_Ptr);
984 return Def_Node;
985 end if;
987 elsif Token = Tok_Tagged then
988 Scan;
990 if Token = Tok_Private then
991 Error_Msg_SC -- CODEFIX
992 ("TAGGED should be WITH");
993 Set_Private_Present (Def_Node, True);
994 T_Private;
995 else
996 Ignore (Tok_Tagged);
997 end if;
998 end if;
1000 return Def_Node;
1001 end P_Formal_Derived_Type_Definition;
1003 ---------------------------------------------
1004 -- 12.5.2 Formal Discrete Type Definition --
1005 ---------------------------------------------
1007 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
1009 -- The caller has checked the initial token is left paren
1011 -- Error recovery: cannot raise Error_Resync
1013 function P_Formal_Discrete_Type_Definition return Node_Id is
1014 Def_Node : Node_Id;
1016 begin
1017 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
1018 Scan; -- past left paren
1019 T_Box;
1020 T_Right_Paren;
1021 return Def_Node;
1022 end P_Formal_Discrete_Type_Definition;
1024 ---------------------------------------------------
1025 -- 12.5.2 Formal Signed Integer Type Definition --
1026 ---------------------------------------------------
1028 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
1030 -- The caller has checked the initial token is RANGE
1032 -- Error recovery: cannot raise Error_Resync
1034 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
1035 Def_Node : Node_Id;
1037 begin
1038 Def_Node :=
1039 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
1040 Scan; -- past RANGE
1041 T_Box;
1042 return Def_Node;
1043 end P_Formal_Signed_Integer_Type_Definition;
1045 --------------------------------------------
1046 -- 12.5.2 Formal Modular Type Definition --
1047 --------------------------------------------
1049 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
1051 -- The caller has checked the initial token is MOD
1053 -- Error recovery: cannot raise Error_Resync
1055 function P_Formal_Modular_Type_Definition return Node_Id is
1056 Def_Node : Node_Id;
1058 begin
1059 Def_Node :=
1060 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
1061 Scan; -- past MOD
1062 T_Box;
1063 return Def_Node;
1064 end P_Formal_Modular_Type_Definition;
1066 ----------------------------------------------
1067 -- 12.5.2 Formal Floating Point Definition --
1068 ----------------------------------------------
1070 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
1072 -- The caller has checked the initial token is DIGITS
1074 -- Error recovery: cannot raise Error_Resync
1076 function P_Formal_Floating_Point_Definition return Node_Id is
1077 Def_Node : Node_Id;
1079 begin
1080 Def_Node :=
1081 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
1082 Scan; -- past DIGITS
1083 T_Box;
1084 return Def_Node;
1085 end P_Formal_Floating_Point_Definition;
1087 -------------------------------------------
1088 -- 12.5.2 Formal Fixed Point Definition --
1089 -------------------------------------------
1091 -- This routine parses either a formal ordinary fixed point definition
1092 -- or a formal decimal fixed point definition:
1094 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
1096 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
1098 -- The caller has checked the initial token is DELTA
1100 -- Error recovery: cannot raise Error_Resync
1102 function P_Formal_Fixed_Point_Definition return Node_Id is
1103 Def_Node : Node_Id;
1104 Delta_Sloc : Source_Ptr;
1106 begin
1107 Delta_Sloc := Token_Ptr;
1108 Scan; -- past DELTA
1109 T_Box;
1111 if Token = Tok_Digits then
1112 Def_Node :=
1113 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
1114 Scan; -- past DIGITS
1115 T_Box;
1116 else
1117 Def_Node :=
1118 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
1119 end if;
1121 return Def_Node;
1122 end P_Formal_Fixed_Point_Definition;
1124 ----------------------------------------------------
1125 -- 12.5.2 Formal Ordinary Fixed Point Definition --
1126 ----------------------------------------------------
1128 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1130 ---------------------------------------------------
1131 -- 12.5.2 Formal Decimal Fixed Point Definition --
1132 ---------------------------------------------------
1134 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1136 ------------------------------------------
1137 -- 12.5.3 Formal Array Type Definition --
1138 ------------------------------------------
1140 -- Parsed by P_Formal_Type_Definition (12.5)
1142 -------------------------------------------
1143 -- 12.5.4 Formal Access Type Definition --
1144 -------------------------------------------
1146 -- Parsed by P_Formal_Type_Definition (12.5)
1148 -----------------------------------------
1149 -- 12.6 Formal Subprogram Declaration --
1150 -----------------------------------------
1152 -- FORMAL_SUBPROGRAM_DECLARATION ::=
1153 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
1154 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
1156 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
1157 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT]
1158 -- [ASPECT_SPECIFICATIONS];
1160 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
1161 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT]
1162 -- [ASPECT_SPECIFICATIONS];
1164 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
1165 -- | ( EXPRESSION ) -- Allowed as extension (-gnatX)
1167 -- DEFAULT_NAME ::= NAME | null
1169 -- The caller has checked that the initial tokens are WITH FUNCTION or
1170 -- WITH PROCEDURE, and the initial WITH has been scanned out.
1172 -- A null default is an Ada 2005 feature
1174 -- Error recovery: cannot raise Error_Resync
1176 function P_Formal_Subprogram_Declaration return Node_Id is
1177 Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
1178 Spec_Node : constant Node_Id := P_Subprogram_Specification;
1179 Def_Node : Node_Id;
1181 begin
1182 if Token = Tok_Is then
1183 T_Is; -- past IS, skip extra IS or ";"
1185 if Token = Tok_Abstract then
1186 Def_Node :=
1187 New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
1188 Scan; -- past ABSTRACT
1190 Error_Msg_Ada_2005_Extension ("formal abstract subprogram");
1192 else
1193 Def_Node :=
1194 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1195 end if;
1197 Set_Specification (Def_Node, Spec_Node);
1199 if Token = Tok_Semicolon then
1200 null;
1202 elsif Aspect_Specifications_Present then
1203 null;
1205 elsif Token = Tok_Box then
1206 Set_Box_Present (Def_Node, True);
1207 Scan; -- past <>
1209 elsif Token = Tok_Null then
1210 Error_Msg_Ada_2005_Extension ("null default subprogram");
1212 if Nkind (Spec_Node) = N_Procedure_Specification then
1213 Set_Null_Present (Spec_Node);
1214 else
1215 Error_Msg_SP ("only procedures can be null");
1216 end if;
1218 Scan; -- past NULL
1220 -- When extensions are enabled, a formal function can have a default
1221 -- given by a parenthesized expression (expression function syntax).
1223 elsif Token = Tok_Left_Paren then
1224 Error_Msg_GNAT_Extension
1225 ("expression default for formal subprograms", Token_Ptr);
1227 if Nkind (Spec_Node) = N_Function_Specification then
1228 Scan; -- past "("
1230 Set_Expression (Def_Node, P_Expression);
1232 if Token /= Tok_Right_Paren then
1233 Error_Msg_SC ("missing "")"" at end of expression default");
1234 else
1235 Scan; -- past ")"
1236 end if;
1238 else
1239 Error_Msg_SP
1240 ("only functions can specify a default expression");
1241 end if;
1243 else
1244 Set_Default_Name (Def_Node, P_Name);
1245 end if;
1247 else
1248 Def_Node :=
1249 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1250 Set_Specification (Def_Node, Spec_Node);
1251 end if;
1253 P_Aspect_Specifications (Def_Node);
1254 return Def_Node;
1255 end P_Formal_Subprogram_Declaration;
1257 ------------------------------
1258 -- 12.6 Subprogram Default --
1259 ------------------------------
1261 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1263 ------------------------
1264 -- 12.6 Default Name --
1265 ------------------------
1267 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1269 --------------------------------------
1270 -- 12.7 Formal Package Declaration --
1271 --------------------------------------
1273 -- FORMAL_PACKAGE_DECLARATION ::=
1274 -- with package DEFINING_IDENTIFIER
1275 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART
1276 -- [ASPECT_SPECIFICATIONS];
1278 -- FORMAL_PACKAGE_ACTUAL_PART ::=
1279 -- ([OTHERS =>] <>) |
1280 -- [GENERIC_ACTUAL_PART]
1281 -- (FORMAL_PACKAGE_ASSOCIATION {, FORMAL_PACKAGE_ASSOCIATION}
1282 -- [, OTHERS => <>)
1284 -- FORMAL_PACKAGE_ASSOCIATION ::=
1285 -- GENERIC_ASSOCIATION
1286 -- | GENERIC_FORMAL_PARAMETER_SELECTOR_NAME => <>
1288 -- The caller has checked that the initial tokens are WITH PACKAGE,
1289 -- and the initial WITH has been scanned out (so Token = Tok_Package).
1291 -- Error recovery: cannot raise Error_Resync
1293 function P_Formal_Package_Declaration return Node_Id is
1294 Def_Node : Node_Id;
1295 Scan_State : Saved_Scan_State;
1297 begin
1298 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
1299 Scan; -- past PACKAGE
1300 Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
1301 T_Is;
1302 T_New;
1303 Set_Name (Def_Node, P_Qualified_Simple_Name);
1305 if Token = Tok_Left_Paren then
1306 Save_Scan_State (Scan_State); -- at the left paren
1307 Scan; -- past the left paren
1309 if Token = Tok_Box then
1310 Set_Box_Present (Def_Node, True);
1311 Scan; -- past box
1312 T_Right_Paren;
1314 else
1315 Restore_Scan_State (Scan_State); -- to the left paren
1316 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
1317 end if;
1318 end if;
1320 P_Aspect_Specifications (Def_Node);
1321 return Def_Node;
1322 end P_Formal_Package_Declaration;
1324 --------------------------------------
1325 -- 12.7 Formal Package Actual Part --
1326 --------------------------------------
1328 -- Parsed by P_Formal_Package_Declaration (12.7)
1330 end Ch12;