2005-03-23 Daniel Berlin <dberlin@dberlin.org>
[official-gcc.git] / gcc / ada / par-ch12.adb
blob56ec4a15f39cc5fb74e7343358040da83a52cfcb
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-2005 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 pragma Style_Checks (All_Checks);
28 -- Turn off subprogram body ordering check. Subprograms are in order
29 -- by RM section rather than alphabetical
31 separate (Par)
32 package body Ch12 is
34 -- Local functions, used only in this chapter
36 function P_Formal_Derived_Type_Definition return Node_Id;
37 function P_Formal_Discrete_Type_Definition return Node_Id;
38 function P_Formal_Fixed_Point_Definition return Node_Id;
39 function P_Formal_Floating_Point_Definition return Node_Id;
40 function P_Formal_Modular_Type_Definition return Node_Id;
41 function P_Formal_Package_Declaration return Node_Id;
42 function P_Formal_Private_Type_Definition return Node_Id;
43 function P_Formal_Signed_Integer_Type_Definition return Node_Id;
44 function P_Formal_Subprogram_Declaration return Node_Id;
45 function P_Formal_Type_Declaration return Node_Id;
46 function P_Formal_Type_Definition return Node_Id;
47 function P_Generic_Association return Node_Id;
49 procedure P_Formal_Object_Declarations (Decls : List_Id);
50 -- Scans one or more formal object declarations and appends them to
51 -- Decls. Scans more than one declaration only in the case where the
52 -- source has a declaration with multiple defining identifiers.
54 --------------------------------
55 -- 12.1 Generic (also 8.5.5) --
56 --------------------------------
58 -- This routine parses either one of the forms of a generic declaration
59 -- or a generic renaming declaration.
61 -- GENERIC_DECLARATION ::=
62 -- GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
64 -- GENERIC_SUBPROGRAM_DECLARATION ::=
65 -- GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION;
67 -- GENERIC_PACKAGE_DECLARATION ::=
68 -- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION;
70 -- GENERIC_FORMAL_PART ::=
71 -- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
73 -- GENERIC_RENAMING_DECLARATION ::=
74 -- generic package DEFINING_PROGRAM_UNIT_NAME
75 -- renames generic_package_NAME
76 -- | generic procedure DEFINING_PROGRAM_UNIT_NAME
77 -- renames generic_procedure_NAME
78 -- | generic function DEFINING_PROGRAM_UNIT_NAME
79 -- renames generic_function_NAME
81 -- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
82 -- FORMAL_OBJECT_DECLARATION
83 -- | FORMAL_TYPE_DECLARATION
84 -- | FORMAL_SUBPROGRAM_DECLARATION
85 -- | FORMAL_PACKAGE_DECLARATION
87 -- The caller has checked that the initial token is GENERIC
89 -- Error recovery: can raise Error_Resync
91 function P_Generic return Node_Id is
92 Gen_Sloc : constant Source_Ptr := Token_Ptr;
93 Gen_Decl : Node_Id;
94 Decl_Node : Node_Id;
95 Decls : List_Id;
96 Def_Unit : Node_Id;
97 Ren_Token : Token_Type;
98 Scan_State : Saved_Scan_State;
100 begin
101 Scan; -- past GENERIC
103 if Token = Tok_Private then
104 Error_Msg_SC ("PRIVATE goes before GENERIC, not after");
105 Scan; -- past junk PRIVATE token
106 end if;
108 Save_Scan_State (Scan_State); -- at token past GENERIC
110 -- Check for generic renaming declaration case
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
119 if Token = Tok_Identifier then
120 Def_Unit := P_Defining_Program_Unit_Name;
122 Check_Misspelling_Of (Tok_Renames);
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);
129 elsif Ren_Token = Tok_Procedure then
130 Decl_Node := New_Node
131 (N_Generic_Procedure_Renaming_Declaration, Gen_Sloc);
133 else -- Ren_Token = Tok_Function then
134 Decl_Node := New_Node
135 (N_Generic_Function_Renaming_Declaration, Gen_Sloc);
136 end if;
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;
147 -- Fall through if this is *not* a generic renaming declaration
149 Restore_Scan_State (Scan_State);
150 Decls := New_List;
152 -- Loop through generic parameter declarations and use clauses
154 Decl_Loop : loop
155 P_Pragmas_Opt (Decls);
156 Ignore (Tok_Private);
158 if Token = Tok_Use then
159 Append (P_Use_Clause, Decls);
160 else
161 -- Parse a generic parameter declaration
163 if Token = Tok_Identifier then
164 P_Formal_Object_Declarations (Decls);
166 elsif Token = Tok_Type then
167 Append (P_Formal_Type_Declaration, Decls);
169 elsif Token = Tok_With then
170 Scan; -- past WITH
172 if Token = Tok_Package then
173 Append (P_Formal_Package_Declaration, Decls);
175 elsif Token = Tok_Procedure or Token = Tok_Function then
176 Append (P_Formal_Subprogram_Declaration, Decls);
178 else
179 Error_Msg_BC
180 ("FUNCTION, PROCEDURE or PACKAGE expected here");
181 Resync_Past_Semicolon;
182 end if;
184 elsif Token = Tok_Subtype then
185 Error_Msg_SC ("subtype declaration not allowed " &
186 "as generic parameter declaration!");
187 Resync_Past_Semicolon;
189 else
190 exit Decl_Loop;
191 end if;
192 end if;
194 end loop Decl_Loop;
196 -- Generic formal part is scanned, scan out subprogram or package spec
198 if Token = Tok_Package then
199 Gen_Decl := New_Node (N_Generic_Package_Declaration, Gen_Sloc);
200 Set_Specification (Gen_Decl, P_Package (Pf_Spcn));
201 else
202 Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
204 Set_Specification (Gen_Decl, P_Subprogram_Specification);
206 if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
207 N_Defining_Program_Unit_Name
208 and then Scope.Last > 0
209 then
210 Error_Msg_SP ("child unit allowed only at library level");
211 end if;
212 TF_Semicolon;
213 end if;
215 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
216 return Gen_Decl;
217 end P_Generic;
219 -------------------------------
220 -- 12.1 Generic Declaration --
221 -------------------------------
223 -- Parsed by P_Generic (12.1)
225 ------------------------------------------
226 -- 12.1 Generic Subprogram Declaration --
227 ------------------------------------------
229 -- Parsed by P_Generic (12.1)
231 ---------------------------------------
232 -- 12.1 Generic Package Declaration --
233 ---------------------------------------
235 -- Parsed by P_Generic (12.1)
237 -------------------------------
238 -- 12.1 Generic Formal Part --
239 -------------------------------
241 -- Parsed by P_Generic (12.1)
243 -------------------------------------------------
244 -- 12.1 Generic Formal Parameter Declaration --
245 -------------------------------------------------
247 -- Parsed by P_Generic (12.1)
249 ---------------------------------
250 -- 12.3 Generic Instantiation --
251 ---------------------------------
253 -- Generic package instantiation parsed by P_Package (7.1)
254 -- Generic procedure instantiation parsed by P_Subprogram (6.1)
255 -- Generic function instantiation parsed by P_Subprogram (6.1)
257 -------------------------------
258 -- 12.3 Generic Actual Part --
259 -------------------------------
261 -- GENERIC_ACTUAL_PART ::=
262 -- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
264 -- Returns a list of generic associations, or Empty if none are present
266 -- Error recovery: cannot raise Error_Resync
268 function P_Generic_Actual_Part_Opt return List_Id is
269 Association_List : List_Id;
271 begin
272 -- Figure out if a generic actual part operation is present. Clearly
273 -- there is no generic actual part if the current token is semicolon
275 if Token = Tok_Semicolon then
276 return No_List;
278 -- If we don't have a left paren, then we have an error, and the job
279 -- is to figure out whether a left paren or semicolon was intended.
280 -- We assume a missing left paren (and hence a generic actual part
281 -- present) if the current token is not on a new line, or if it is
282 -- indented from the subprogram token. Otherwise assume missing
283 -- semicolon (which will be diagnosed by caller) and no generic part
285 elsif Token /= Tok_Left_Paren
286 and then Token_Is_At_Start_Of_Line
287 and then Start_Column <= Scope.Table (Scope.Last).Ecol
288 then
289 return No_List;
291 -- Otherwise we have a generic actual part (either a left paren is
292 -- present, or we have decided that there must be a missing left paren)
294 else
295 Association_List := New_List;
296 T_Left_Paren;
298 loop
299 Append (P_Generic_Association, Association_List);
300 exit when not Comma_Present;
301 end loop;
303 T_Right_Paren;
304 return Association_List;
305 end if;
307 end P_Generic_Actual_Part_Opt;
309 -------------------------------
310 -- 12.3 Generic Association --
311 -------------------------------
313 -- GENERIC_ASSOCIATION ::=
314 -- [generic_formal_parameter_SELECTOR_NAME =>]
315 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER
317 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
318 -- EXPRESSION | variable_NAME | subprogram_NAME
319 -- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
321 -- Error recovery: cannot raise Error_Resync
323 function P_Generic_Association return Node_Id is
324 Scan_State : Saved_Scan_State;
325 Param_Name_Node : Node_Id;
326 Generic_Assoc_Node : Node_Id;
328 begin
329 Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
331 if Token in Token_Class_Desig then
332 Param_Name_Node := Token_Node;
333 Save_Scan_State (Scan_State); -- at designator
334 Scan; -- past simple name or operator symbol
336 if Token = Tok_Arrow then
337 Scan; -- past arrow
338 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
339 else
340 Restore_Scan_State (Scan_State); -- to designator
341 end if;
342 end if;
344 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, P_Expression);
345 return Generic_Assoc_Node;
346 end P_Generic_Association;
348 ---------------------------------------------
349 -- 12.3 Explicit Generic Actual Parameter --
350 ---------------------------------------------
352 -- Parsed by P_Generic_Association (12.3)
354 --------------------------------------
355 -- 12.4 Formal Object Declarations --
356 --------------------------------------
358 -- FORMAL_OBJECT_DECLARATION ::=
359 -- DEFINING_IDENTIFIER_LIST :
360 -- MODE SUBTYPE_MARK [:= DEFAULT_EXPRESSION];
362 -- The caller has checked that the initial token is an identifier
364 -- Error recovery: cannot raise Error_Resync
366 procedure P_Formal_Object_Declarations (Decls : List_Id) is
367 Decl_Node : Node_Id;
368 Scan_State : Saved_Scan_State;
369 Num_Idents : Nat;
370 Ident : Nat;
372 Idents : array (Int range 1 .. 4096) of Entity_Id;
373 -- This array holds the list of defining identifiers. The upper bound
374 -- of 4096 is intended to be essentially infinite, and we do not even
375 -- bother to check for it being exceeded.
377 begin
378 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
379 Num_Idents := 1;
381 while Comma_Present loop
382 Num_Idents := Num_Idents + 1;
383 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
384 end loop;
386 T_Colon;
388 -- If there are multiple identifiers, we repeatedly scan the
389 -- type and initialization expression information by resetting
390 -- the scan pointer (so that we get completely separate trees
391 -- for each occurrence).
393 if Num_Idents > 1 then
394 Save_Scan_State (Scan_State);
395 end if;
397 -- Loop through defining identifiers in list
399 Ident := 1;
400 Ident_Loop : loop
401 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
402 Set_Defining_Identifier (Decl_Node, Idents (Ident));
403 P_Mode (Decl_Node);
404 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
405 No_Constraint;
406 Set_Expression (Decl_Node, Init_Expr_Opt);
408 if Ident > 1 then
409 Set_Prev_Ids (Decl_Node, True);
410 end if;
412 if Ident < Num_Idents then
413 Set_More_Ids (Decl_Node, True);
414 end if;
416 Append (Decl_Node, Decls);
418 exit Ident_Loop when Ident = Num_Idents;
419 Ident := Ident + 1;
420 Restore_Scan_State (Scan_State);
421 end loop Ident_Loop;
423 TF_Semicolon;
424 end P_Formal_Object_Declarations;
426 -----------------------------------
427 -- 12.5 Formal Type Declaration --
428 -----------------------------------
430 -- FORMAL_TYPE_DECLARATION ::=
431 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
432 -- is FORMAL_TYPE_DEFINITION;
434 -- The caller has checked that the initial token is TYPE
436 -- Error recovery: cannot raise Error_Resync
438 function P_Formal_Type_Declaration return Node_Id is
439 Decl_Node : Node_Id;
440 Def_Node : Node_Id;
442 begin
443 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
444 Scan; -- past TYPE
445 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
447 if P_Unknown_Discriminant_Part_Opt then
448 Set_Unknown_Discriminants_Present (Decl_Node, True);
449 else
450 Set_Discriminant_Specifications
451 (Decl_Node, P_Known_Discriminant_Part_Opt);
452 end if;
454 T_Is;
456 Def_Node := P_Formal_Type_Definition;
458 if Def_Node /= Error then
459 Set_Formal_Type_Definition (Decl_Node, Def_Node);
460 TF_Semicolon;
462 else
463 Decl_Node := Error;
465 -- If we have semicolon, skip it to avoid cascaded errors
467 if Token = Tok_Semicolon then
468 Scan;
469 end if;
470 end if;
472 return Decl_Node;
473 end P_Formal_Type_Declaration;
475 ----------------------------------
476 -- 12.5 Formal Type Definition --
477 ----------------------------------
479 -- FORMAL_TYPE_DEFINITION ::=
480 -- FORMAL_PRIVATE_TYPE_DEFINITION
481 -- | FORMAL_DERIVED_TYPE_DEFINITION
482 -- | FORMAL_DISCRETE_TYPE_DEFINITION
483 -- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
484 -- | FORMAL_MODULAR_TYPE_DEFINITION
485 -- | FORMAL_FLOATING_POINT_DEFINITION
486 -- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
487 -- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
488 -- | FORMAL_ARRAY_TYPE_DEFINITION
489 -- | FORMAL_ACCESS_TYPE_DEFINITION
490 -- | FORMAL_INTERFACE_TYPE_DEFINITION
492 -- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
494 -- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
496 -- FORMAL_INTERFACE_TYPE_DEFINITION ::= INTERFACE_TYPE_DEFINITION
498 function P_Formal_Type_Definition return Node_Id is
499 Scan_State : Saved_Scan_State;
500 Typedef_Node : Node_Id;
502 begin
503 if Token_Name = Name_Abstract then
504 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
505 end if;
507 if Token_Name = Name_Tagged then
508 Check_95_Keyword (Tok_Tagged, Tok_Private);
509 Check_95_Keyword (Tok_Tagged, Tok_Limited);
510 end if;
512 case Token is
514 -- Mostly we can tell what we have from the initial token. The one
515 -- exception is ABSTRACT, where we have to scan ahead to see if we
516 -- have a formal derived type or a formal private type definition.
518 when Tok_Abstract =>
519 Save_Scan_State (Scan_State);
520 Scan; -- past ABSTRACT
522 if Token = Tok_New then
523 Restore_Scan_State (Scan_State); -- to ABSTRACT
524 return P_Formal_Derived_Type_Definition;
526 else
527 Restore_Scan_State (Scan_State); -- to ABSTRACT
528 return P_Formal_Private_Type_Definition;
529 end if;
531 when Tok_Access =>
532 return P_Access_Type_Definition;
534 when Tok_Array =>
535 return P_Array_Type_Definition;
537 when Tok_Delta =>
538 return P_Formal_Fixed_Point_Definition;
540 when Tok_Digits =>
541 return P_Formal_Floating_Point_Definition;
543 when Tok_Interface => -- Ada 2005 (AI-251)
544 return P_Interface_Type_Definition (Is_Synchronized => False);
546 when Tok_Left_Paren =>
547 return P_Formal_Discrete_Type_Definition;
549 when Tok_Limited =>
550 Save_Scan_State (Scan_State);
551 Scan; -- past LIMITED
553 if Token = Tok_Interface then
554 Typedef_Node := P_Interface_Type_Definition
555 (Is_Synchronized => False);
556 Set_Limited_Present (Typedef_Node);
557 return Typedef_Node;
559 else
560 Restore_Scan_State (Scan_State);
561 return P_Formal_Private_Type_Definition;
562 end if;
564 when Tok_Mod =>
565 return P_Formal_Modular_Type_Definition;
567 when Tok_New =>
568 return P_Formal_Derived_Type_Definition;
570 when Tok_Private |
571 Tok_Tagged =>
572 return P_Formal_Private_Type_Definition;
574 when Tok_Range =>
575 return P_Formal_Signed_Integer_Type_Definition;
577 when Tok_Record =>
578 Error_Msg_SC ("record not allowed in generic type definition!");
579 Discard_Junk_Node (P_Record_Definition);
580 return Error;
582 -- Ada 2005 (AI-345)
584 when Tok_Protected |
585 Tok_Synchronized |
586 Tok_Task =>
588 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
590 declare
591 Saved_Token : constant Token_Type := Token;
593 begin
594 Typedef_Node := P_Interface_Type_Definition
595 (Is_Synchronized => True);
597 case Saved_Token is
598 when Tok_Task =>
599 Set_Task_Present (Typedef_Node);
601 when Tok_Protected =>
602 Set_Protected_Present (Typedef_Node);
604 when Tok_Synchronized =>
605 Set_Synchronized_Present (Typedef_Node);
607 when others =>
608 null;
609 end case;
611 return Typedef_Node;
612 end;
614 when others =>
615 Error_Msg_BC ("expecting generic type definition here");
616 Resync_Past_Semicolon;
617 return Error;
619 end case;
620 end P_Formal_Type_Definition;
622 --------------------------------------------
623 -- 12.5.1 Formal Private Type Definition --
624 --------------------------------------------
626 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
627 -- [[abstract] tagged] [limited] private
629 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
630 -- TAGGED or LIMITED
632 -- Error recovery: cannot raise Error_Resync
634 function P_Formal_Private_Type_Definition return Node_Id is
635 Def_Node : Node_Id;
637 begin
638 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
640 if Token = Tok_Abstract then
641 Scan; -- past ABSTRACT
643 if Token_Name = Name_Tagged then
644 Check_95_Keyword (Tok_Tagged, Tok_Private);
645 Check_95_Keyword (Tok_Tagged, Tok_Limited);
646 end if;
648 if Token /= Tok_Tagged then
649 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
650 else
651 Set_Abstract_Present (Def_Node, True);
652 end if;
653 end if;
655 if Token = Tok_Tagged then
656 Set_Tagged_Present (Def_Node, True);
657 Scan; -- past TAGGED
658 end if;
660 if Token = Tok_Limited then
661 Set_Limited_Present (Def_Node, True);
662 Scan; -- past LIMITED
663 end if;
665 Set_Sloc (Def_Node, Token_Ptr);
666 T_Private;
667 return Def_Node;
668 end P_Formal_Private_Type_Definition;
670 --------------------------------------------
671 -- 12.5.1 Formal Derived Type Definition --
672 --------------------------------------------
674 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
675 -- [abstract] new SUBTYPE_MARK [[AND interface_list] with private]
677 -- The caller has checked the initial token(s) is/are NEW or ASTRACT NEW
679 -- Error recovery: cannot raise Error_Resync
681 function P_Formal_Derived_Type_Definition return Node_Id is
682 Def_Node : Node_Id;
684 begin
685 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
687 if Token = Tok_Abstract then
688 Set_Abstract_Present (Def_Node);
689 Scan; -- past ABSTRACT
690 end if;
692 Scan; -- past NEW;
693 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
694 No_Constraint;
696 -- Ada 2005 (AI-251): Deal with interfaces
698 if Token = Tok_And then
699 Scan; -- past AND
701 if Ada_Version < Ada_05 then
702 Error_Msg_SP
703 ("abstract interface is an Ada 2005 extension");
704 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
705 end if;
707 Set_Interface_List (Def_Node, New_List);
709 loop
710 Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
711 exit when Token /= Tok_And;
712 Scan; -- past AND
713 end loop;
714 end if;
716 if Token = Tok_With then
717 Scan; -- past WITH
718 Set_Private_Present (Def_Node, True);
719 T_Private;
721 elsif Token = Tok_Tagged then
722 Scan;
724 if Token = Tok_Private then
725 Error_Msg_SC ("TAGGED should be WITH");
726 Set_Private_Present (Def_Node, True);
727 T_Private;
728 else
729 Ignore (Tok_Tagged);
730 end if;
731 end if;
733 return Def_Node;
734 end P_Formal_Derived_Type_Definition;
736 ---------------------------------------------
737 -- 12.5.2 Formal Discrete Type Definition --
738 ---------------------------------------------
740 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
742 -- The caller has checked the initial token is left paren
744 -- Error recovery: cannot raise Error_Resync
746 function P_Formal_Discrete_Type_Definition return Node_Id is
747 Def_Node : Node_Id;
749 begin
750 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
751 Scan; -- past left paren
752 T_Box;
753 T_Right_Paren;
754 return Def_Node;
755 end P_Formal_Discrete_Type_Definition;
757 ---------------------------------------------------
758 -- 12.5.2 Formal Signed Integer Type Definition --
759 ---------------------------------------------------
761 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
763 -- The caller has checked the initial token is RANGE
765 -- Error recovery: cannot raise Error_Resync
767 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
768 Def_Node : Node_Id;
770 begin
771 Def_Node :=
772 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
773 Scan; -- past RANGE
774 T_Box;
775 return Def_Node;
776 end P_Formal_Signed_Integer_Type_Definition;
778 --------------------------------------------
779 -- 12.5.2 Formal Modular Type Definition --
780 --------------------------------------------
782 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
784 -- The caller has checked the initial token is MOD
786 -- Error recovery: cannot raise Error_Resync
788 function P_Formal_Modular_Type_Definition return Node_Id is
789 Def_Node : Node_Id;
791 begin
792 Def_Node :=
793 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
794 Scan; -- past MOD
795 T_Box;
796 return Def_Node;
797 end P_Formal_Modular_Type_Definition;
799 ----------------------------------------------
800 -- 12.5.2 Formal Floating Point Definition --
801 ----------------------------------------------
803 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
805 -- The caller has checked the initial token is DIGITS
807 -- Error recovery: cannot raise Error_Resync
809 function P_Formal_Floating_Point_Definition return Node_Id is
810 Def_Node : Node_Id;
812 begin
813 Def_Node :=
814 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
815 Scan; -- past DIGITS
816 T_Box;
817 return Def_Node;
818 end P_Formal_Floating_Point_Definition;
820 -------------------------------------------
821 -- 12.5.2 Formal Fixed Point Definition --
822 -------------------------------------------
824 -- This routine parses either a formal ordinary fixed point definition
825 -- or a formal decimal fixed point definition:
827 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
829 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
831 -- The caller has checked the initial token is DELTA
833 -- Error recovery: cannot raise Error_Resync
835 function P_Formal_Fixed_Point_Definition return Node_Id is
836 Def_Node : Node_Id;
837 Delta_Sloc : Source_Ptr;
839 begin
840 Delta_Sloc := Token_Ptr;
841 Scan; -- past DELTA
842 T_Box;
844 if Token = Tok_Digits then
845 Def_Node :=
846 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
847 Scan; -- past DIGITS
848 T_Box;
849 else
850 Def_Node :=
851 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
852 end if;
854 return Def_Node;
855 end P_Formal_Fixed_Point_Definition;
857 ----------------------------------------------------
858 -- 12.5.2 Formal Ordinary Fixed Point Definition --
859 ----------------------------------------------------
861 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
863 ---------------------------------------------------
864 -- 12.5.2 Formal Decimal Fixed Point Definition --
865 ---------------------------------------------------
867 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
869 ------------------------------------------
870 -- 12.5.3 Formal Array Type Definition --
871 ------------------------------------------
873 -- Parsed by P_Formal_Type_Definition (12.5)
875 -------------------------------------------
876 -- 12.5.4 Formal Access Type Definition --
877 -------------------------------------------
879 -- Parsed by P_Formal_Type_Definition (12.5)
881 -----------------------------------------
882 -- 12.6 Formal Subprogram Declaration --
883 -----------------------------------------
885 -- FORMAL_SUBPROGRAM_DECLARATION ::=
886 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
887 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
889 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
890 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
892 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
893 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT];
895 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
897 -- DEFAULT_NAME ::= NAME
899 -- The caller has checked that the initial tokens are WITH FUNCTION or
900 -- WITH PROCEDURE, and the initial WITH has been scanned out.
902 -- Error recovery: cannot raise Error_Resync
904 function P_Formal_Subprogram_Declaration return Node_Id is
905 Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
906 Spec_Node : constant Node_Id := P_Subprogram_Specification;
907 Def_Node : Node_Id;
909 begin
910 if Token = Tok_Is then
911 T_Is; -- past IS, skip extra IS or ";"
913 if Token = Tok_Abstract then
914 Def_Node :=
915 New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
916 Scan; -- past ABSTRACT
918 if Ada_Version < Ada_05 then
919 Error_Msg_SP
920 ("formal abstract subprograms are an Ada 2005 extension");
921 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
922 end if;
924 else
925 Def_Node :=
926 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
927 end if;
929 Set_Specification (Def_Node, Spec_Node);
931 if Token = Tok_Semicolon then
932 Scan; -- past ";"
934 elsif Token = Tok_Box then
935 Set_Box_Present (Def_Node, True);
936 Scan; -- past <>
937 T_Semicolon;
939 else
940 Set_Default_Name (Def_Node, P_Name);
941 T_Semicolon;
942 end if;
944 else
945 Def_Node :=
946 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
947 Set_Specification (Def_Node, Spec_Node);
948 T_Semicolon;
949 end if;
951 return Def_Node;
952 end P_Formal_Subprogram_Declaration;
954 ------------------------------
955 -- 12.6 Subprogram Default --
956 ------------------------------
958 -- Parsed by P_Formal_Procedure_Declaration (12.6)
960 ------------------------
961 -- 12.6 Default Name --
962 ------------------------
964 -- Parsed by P_Formal_Procedure_Declaration (12.6)
966 --------------------------------------
967 -- 12.7 Formal Package Declaration --
968 --------------------------------------
970 -- FORMAL_PACKAGE_DECLARATION ::=
971 -- with package DEFINING_IDENTIFIER
972 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
974 -- FORMAL_PACKAGE_ACTUAL_PART ::=
975 -- (<>) | [GENERIC_ACTUAL_PART]
977 -- The caller has checked that the initial tokens are WITH PACKAGE,
978 -- and the initial WITH has been scanned out (so Token = Tok_Package).
980 -- Error recovery: cannot raise Error_Resync
982 function P_Formal_Package_Declaration return Node_Id is
983 Def_Node : Node_Id;
984 Scan_State : Saved_Scan_State;
986 begin
987 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
988 Scan; -- past PACKAGE
989 Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
990 T_Is;
991 T_New;
992 Set_Name (Def_Node, P_Qualified_Simple_Name);
994 if Token = Tok_Left_Paren then
995 Save_Scan_State (Scan_State); -- at the left paren
996 Scan; -- past the left paren
998 if Token = Tok_Box then
999 Set_Box_Present (Def_Node, True);
1000 Scan; -- past box
1001 T_Right_Paren;
1003 else
1004 Restore_Scan_State (Scan_State); -- to the left paren
1005 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
1006 end if;
1007 end if;
1009 T_Semicolon;
1010 return Def_Node;
1011 end P_Formal_Package_Declaration;
1013 --------------------------------------
1014 -- 12.7 Formal Package Actual Part --
1015 --------------------------------------
1017 -- Parsed by P_Formal_Package_Declaration (12.7)
1019 end Ch12;