* sh.h (REG_CLASS_FROM_LETTER): Change to:
[official-gcc.git] / gcc / ada / par-ch12.adb
blob2b9adaf73ae4e7b1155e6b20b1e583828e1162c7
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-2001 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);
203 Set_Specification (Gen_Decl, P_Subprogram_Specification);
204 TF_Semicolon;
205 end if;
207 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
208 return Gen_Decl;
209 end P_Generic;
211 -------------------------------
212 -- 12.1 Generic Declaration --
213 -------------------------------
215 -- Parsed by P_Generic (12.1)
217 ------------------------------------------
218 -- 12.1 Generic Subprogram Declaration --
219 ------------------------------------------
221 -- Parsed by P_Generic (12.1)
223 ---------------------------------------
224 -- 12.1 Generic Package Declaration --
225 ---------------------------------------
227 -- Parsed by P_Generic (12.1)
229 -------------------------------
230 -- 12.1 Generic Formal Part --
231 -------------------------------
233 -- Parsed by P_Generic (12.1)
235 -------------------------------------------------
236 -- 12.1 Generic Formal Parameter Declaration --
237 -------------------------------------------------
239 -- Parsed by P_Generic (12.1)
241 ---------------------------------
242 -- 12.3 Generic Instantiation --
243 ---------------------------------
245 -- Generic package instantiation parsed by P_Package (7.1)
246 -- Generic procedure instantiation parsed by P_Subprogram (6.1)
247 -- Generic function instantiation parsed by P_Subprogram (6.1)
249 -------------------------------
250 -- 12.3 Generic Actual Part --
251 -------------------------------
253 -- GENERIC_ACTUAL_PART ::=
254 -- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
256 -- Returns a list of generic associations, or Empty if none are present
258 -- Error recovery: cannot raise Error_Resync
260 function P_Generic_Actual_Part_Opt return List_Id is
261 Association_List : List_Id;
263 begin
264 -- Figure out if a generic actual part operation is present. Clearly
265 -- there is no generic actual part if the current token is semicolon
267 if Token = Tok_Semicolon then
268 return No_List;
270 -- If we don't have a left paren, then we have an error, and the job
271 -- is to figure out whether a left paren or semicolon was intended.
272 -- We assume a missing left paren (and hence a generic actual part
273 -- present) if the current token is not on a new line, or if it is
274 -- indented from the subprogram token. Otherwise assume missing
275 -- semicolon (which will be diagnosed by caller) and no generic part
277 elsif Token /= Tok_Left_Paren
278 and then Token_Is_At_Start_Of_Line
279 and then Start_Column <= Scope.Table (Scope.Last).Ecol
280 then
281 return No_List;
283 -- Otherwise we have a generic actual part (either a left paren is
284 -- present, or we have decided that there must be a missing left paren)
286 else
287 Association_List := New_List;
288 T_Left_Paren;
290 loop
291 Append (P_Generic_Association, Association_List);
292 exit when not Comma_Present;
293 end loop;
295 T_Right_Paren;
296 return Association_List;
297 end if;
299 end P_Generic_Actual_Part_Opt;
301 -------------------------------
302 -- 12.3 Generic Association --
303 -------------------------------
305 -- GENERIC_ASSOCIATION ::=
306 -- [generic_formal_parameter_SELECTOR_NAME =>]
307 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER
309 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
310 -- EXPRESSION | variable_NAME | subprogram_NAME
311 -- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
313 -- Error recovery: cannot raise Error_Resync
315 function P_Generic_Association return Node_Id is
316 Scan_State : Saved_Scan_State;
317 Param_Name_Node : Node_Id;
318 Generic_Assoc_Node : Node_Id;
320 begin
321 Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
323 if Token in Token_Class_Desig then
324 Param_Name_Node := Token_Node;
325 Save_Scan_State (Scan_State); -- at designator
326 Scan; -- past simple name or operator symbol
328 if Token = Tok_Arrow then
329 Scan; -- past arrow
330 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
331 else
332 Restore_Scan_State (Scan_State); -- to designator
333 end if;
334 end if;
336 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, P_Expression);
337 return Generic_Assoc_Node;
338 end P_Generic_Association;
340 ---------------------------------------------
341 -- 12.3 Explicit Generic Actual Parameter --
342 ---------------------------------------------
344 -- Parsed by P_Generic_Association (12.3)
346 --------------------------------------
347 -- 12.4 Formal Object Declarations --
348 --------------------------------------
350 -- FORMAL_OBJECT_DECLARATION ::=
351 -- DEFINING_IDENTIFIER_LIST :
352 -- MODE SUBTYPE_MARK [:= DEFAULT_EXPRESSION];
354 -- The caller has checked that the initial token is an identifier
356 -- Error recovery: cannot raise Error_Resync
358 procedure P_Formal_Object_Declarations (Decls : List_Id) is
359 Decl_Node : Node_Id;
360 Scan_State : Saved_Scan_State;
361 Num_Idents : Nat;
362 Ident : Nat;
364 Idents : array (Int range 1 .. 4096) of Entity_Id;
365 -- This array holds the list of defining identifiers. The upper bound
366 -- of 4096 is intended to be essentially infinite, and we do not even
367 -- bother to check for it being exceeded.
369 begin
370 Idents (1) := P_Defining_Identifier;
371 Num_Idents := 1;
373 while Comma_Present loop
374 Num_Idents := Num_Idents + 1;
375 Idents (Num_Idents) := P_Defining_Identifier;
376 end loop;
378 T_Colon;
380 -- If there are multiple identifiers, we repeatedly scan the
381 -- type and initialization expression information by resetting
382 -- the scan pointer (so that we get completely separate trees
383 -- for each occurrence).
385 if Num_Idents > 1 then
386 Save_Scan_State (Scan_State);
387 end if;
389 -- Loop through defining identifiers in list
391 Ident := 1;
392 Ident_Loop : loop
393 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
394 Set_Defining_Identifier (Decl_Node, Idents (Ident));
395 P_Mode (Decl_Node);
396 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
397 No_Constraint;
398 Set_Expression (Decl_Node, Init_Expr_Opt);
400 if Ident > 1 then
401 Set_Prev_Ids (Decl_Node, True);
402 end if;
404 if Ident < Num_Idents then
405 Set_More_Ids (Decl_Node, True);
406 end if;
408 Append (Decl_Node, Decls);
410 exit Ident_Loop when Ident = Num_Idents;
411 Ident := Ident + 1;
412 Restore_Scan_State (Scan_State);
413 end loop Ident_Loop;
415 TF_Semicolon;
416 end P_Formal_Object_Declarations;
418 -----------------------------------
419 -- 12.5 Formal Type Declaration --
420 -----------------------------------
422 -- FORMAL_TYPE_DECLARATION ::=
423 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
424 -- is FORMAL_TYPE_DEFINITION;
426 -- The caller has checked that the initial token is TYPE
428 -- Error recovery: cannot raise Error_Resync
430 function P_Formal_Type_Declaration return Node_Id is
431 Decl_Node : Node_Id;
432 Def_Node : Node_Id;
434 begin
435 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
436 Scan; -- past TYPE
437 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
439 if P_Unknown_Discriminant_Part_Opt then
440 Set_Unknown_Discriminants_Present (Decl_Node, True);
441 else
442 Set_Discriminant_Specifications
443 (Decl_Node, P_Known_Discriminant_Part_Opt);
444 end if;
446 T_Is;
448 Def_Node := P_Formal_Type_Definition;
450 if Def_Node /= Error then
451 Set_Formal_Type_Definition (Decl_Node, Def_Node);
452 TF_Semicolon;
454 else
455 Decl_Node := Error;
457 -- If we have semicolon, skip it to avoid cascaded errors
459 if Token = Tok_Semicolon then
460 Scan;
461 end if;
462 end if;
464 return Decl_Node;
465 end P_Formal_Type_Declaration;
467 ----------------------------------
468 -- 12.5 Formal Type Definition --
469 ----------------------------------
471 -- FORMAL_TYPE_DEFINITION ::=
472 -- FORMAL_PRIVATE_TYPE_DEFINITION
473 -- | FORMAL_DERIVED_TYPE_DEFINITION
474 -- | FORMAL_DISCRETE_TYPE_DEFINITION
475 -- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
476 -- | FORMAL_MODULAR_TYPE_DEFINITION
477 -- | FORMAL_FLOATING_POINT_DEFINITION
478 -- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
479 -- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
480 -- | FORMAL_ARRAY_TYPE_DEFINITION
481 -- | FORMAL_ACCESS_TYPE_DEFINITION
483 -- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
485 -- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
487 function P_Formal_Type_Definition return Node_Id is
488 Scan_State : Saved_Scan_State;
490 begin
491 if Token_Name = Name_Abstract then
492 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
493 end if;
495 if Token_Name = Name_Tagged then
496 Check_95_Keyword (Tok_Tagged, Tok_Private);
497 Check_95_Keyword (Tok_Tagged, Tok_Limited);
498 end if;
500 case Token is
502 -- Mostly we can tell what we have from the initial token. The one
503 -- exception is ABSTRACT, where we have to scan ahead to see if we
504 -- have a formal derived type or a formal private type definition.
506 when Tok_Abstract =>
507 Save_Scan_State (Scan_State);
508 Scan; -- past ABSTRACT
510 if Token = Tok_New then
511 Restore_Scan_State (Scan_State); -- to ABSTRACT
512 return P_Formal_Derived_Type_Definition;
514 else
515 Restore_Scan_State (Scan_State); -- to ABSTRACT
516 return P_Formal_Private_Type_Definition;
517 end if;
519 when Tok_Private | Tok_Limited | Tok_Tagged =>
520 return P_Formal_Private_Type_Definition;
522 when Tok_New =>
523 return P_Formal_Derived_Type_Definition;
525 when Tok_Left_Paren =>
526 return P_Formal_Discrete_Type_Definition;
528 when Tok_Range =>
529 return P_Formal_Signed_Integer_Type_Definition;
531 when Tok_Mod =>
532 return P_Formal_Modular_Type_Definition;
534 when Tok_Digits =>
535 return P_Formal_Floating_Point_Definition;
537 when Tok_Delta =>
538 return P_Formal_Fixed_Point_Definition;
540 when Tok_Array =>
541 return P_Array_Type_Definition;
543 when Tok_Access =>
544 return P_Access_Type_Definition;
546 when Tok_Record =>
547 Error_Msg_SC ("record not allowed in generic type definition!");
548 Discard_Junk_Node (P_Record_Definition);
549 return Error;
551 when others =>
552 Error_Msg_BC ("expecting generic type definition here");
553 Resync_Past_Semicolon;
554 return Error;
556 end case;
557 end P_Formal_Type_Definition;
559 --------------------------------------------
560 -- 12.5.1 Formal Private Type Definition --
561 --------------------------------------------
563 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
564 -- [[abstract] tagged] [limited] private
566 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
567 -- TAGGED or LIMITED
569 -- Error recovery: cannot raise Error_Resync
571 function P_Formal_Private_Type_Definition return Node_Id is
572 Def_Node : Node_Id;
574 begin
575 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
577 if Token = Tok_Abstract then
578 Scan; -- past ABSTRACT
580 if Token_Name = Name_Tagged then
581 Check_95_Keyword (Tok_Tagged, Tok_Private);
582 Check_95_Keyword (Tok_Tagged, Tok_Limited);
583 end if;
585 if Token /= Tok_Tagged then
586 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
587 else
588 Set_Abstract_Present (Def_Node, True);
589 end if;
590 end if;
592 if Token = Tok_Tagged then
593 Set_Tagged_Present (Def_Node, True);
594 Scan; -- past TAGGED
595 end if;
597 if Token = Tok_Limited then
598 Set_Limited_Present (Def_Node, True);
599 Scan; -- past LIMITED
600 end if;
602 Set_Sloc (Def_Node, Token_Ptr);
603 T_Private;
604 return Def_Node;
605 end P_Formal_Private_Type_Definition;
607 --------------------------------------------
608 -- 12.5.1 Formal Derived Type Definition --
609 --------------------------------------------
611 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
612 -- [abstract] new SUBTYPE_MARK [with private]
614 -- The caller has checked the initial token(s) is/are NEW or ASTRACT NEW
616 -- Error recovery: cannot raise Error_Resync
618 function P_Formal_Derived_Type_Definition return Node_Id is
619 Def_Node : Node_Id;
621 begin
622 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
624 if Token = Tok_Abstract then
625 Set_Abstract_Present (Def_Node);
626 Scan; -- past ABSTRACT
627 end if;
629 Scan; -- past NEW;
630 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
631 No_Constraint;
633 if Token = Tok_With then
634 Scan; -- past WITH
635 Set_Private_Present (Def_Node, True);
636 T_Private;
638 elsif Token = Tok_Tagged then
639 Scan;
641 if Token = Tok_Private then
642 Error_Msg_SC ("TAGGED should be WITH");
643 Set_Private_Present (Def_Node, True);
644 T_Private;
645 else
646 Ignore (Tok_Tagged);
647 end if;
648 end if;
650 return Def_Node;
651 end P_Formal_Derived_Type_Definition;
653 ---------------------------------------------
654 -- 12.5.2 Formal Discrete Type Definition --
655 ---------------------------------------------
657 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
659 -- The caller has checked the initial token is left paren
661 -- Error recovery: cannot raise Error_Resync
663 function P_Formal_Discrete_Type_Definition return Node_Id is
664 Def_Node : Node_Id;
666 begin
667 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
668 Scan; -- past left paren
669 T_Box;
670 T_Right_Paren;
671 return Def_Node;
672 end P_Formal_Discrete_Type_Definition;
674 ---------------------------------------------------
675 -- 12.5.2 Formal Signed Integer Type Definition --
676 ---------------------------------------------------
678 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
680 -- The caller has checked the initial token is RANGE
682 -- Error recovery: cannot raise Error_Resync
684 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
685 Def_Node : Node_Id;
687 begin
688 Def_Node :=
689 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
690 Scan; -- past RANGE
691 T_Box;
692 return Def_Node;
693 end P_Formal_Signed_Integer_Type_Definition;
695 --------------------------------------------
696 -- 12.5.2 Formal Modular Type Definition --
697 --------------------------------------------
699 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
701 -- The caller has checked the initial token is MOD
703 -- Error recovery: cannot raise Error_Resync
705 function P_Formal_Modular_Type_Definition return Node_Id is
706 Def_Node : Node_Id;
708 begin
709 Def_Node :=
710 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
711 Scan; -- past MOD
712 T_Box;
713 return Def_Node;
714 end P_Formal_Modular_Type_Definition;
716 ----------------------------------------------
717 -- 12.5.2 Formal Floating Point Definition --
718 ----------------------------------------------
720 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
722 -- The caller has checked the initial token is DIGITS
724 -- Error recovery: cannot raise Error_Resync
726 function P_Formal_Floating_Point_Definition return Node_Id is
727 Def_Node : Node_Id;
729 begin
730 Def_Node :=
731 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
732 Scan; -- past DIGITS
733 T_Box;
734 return Def_Node;
735 end P_Formal_Floating_Point_Definition;
737 -------------------------------------------
738 -- 12.5.2 Formal Fixed Point Definition --
739 -------------------------------------------
741 -- This routine parses either a formal ordinary fixed point definition
742 -- or a formal decimal fixed point definition:
744 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
746 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
748 -- The caller has checked the initial token is DELTA
750 -- Error recovery: cannot raise Error_Resync
752 function P_Formal_Fixed_Point_Definition return Node_Id is
753 Def_Node : Node_Id;
754 Delta_Sloc : Source_Ptr;
756 begin
757 Delta_Sloc := Token_Ptr;
758 Scan; -- past DELTA
759 T_Box;
761 if Token = Tok_Digits then
762 Def_Node :=
763 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
764 Scan; -- past DIGITS
765 T_Box;
766 else
767 Def_Node :=
768 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
769 end if;
771 return Def_Node;
772 end P_Formal_Fixed_Point_Definition;
774 ----------------------------------------------------
775 -- 12.5.2 Formal Ordinary Fixed Point Definition --
776 ----------------------------------------------------
778 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
780 ---------------------------------------------------
781 -- 12.5.2 Formal Decimal Fixed Point Definition --
782 ---------------------------------------------------
784 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
786 ------------------------------------------
787 -- 12.5.3 Formal Array Type Definition --
788 ------------------------------------------
790 -- Parsed by P_Formal_Type_Definition (12.5)
792 -------------------------------------------
793 -- 12.5.4 Formal Access Type Definition --
794 -------------------------------------------
796 -- Parsed by P_Formal_Type_Definition (12.5)
798 -----------------------------------------
799 -- 12.6 Formal Subprogram Declaration --
800 -----------------------------------------
802 -- FORMAL_SUBPROGRAM_DECLARATION ::=
803 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
805 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
807 -- DEFAULT_NAME ::= NAME
809 -- The caller has checked that the initial tokens are WITH FUNCTION or
810 -- WITH PROCEDURE, and the initial WITH has been scanned out.
812 -- Note: we separate this into two procedures because the name is allowed
813 -- to be an operator symbol for a function, but not for a procedure.
815 -- Error recovery: cannot raise Error_Resync
817 function P_Formal_Subprogram_Declaration return Node_Id is
818 Def_Node : Node_Id;
820 begin
821 Def_Node := New_Node (N_Formal_Subprogram_Declaration, Prev_Token_Ptr);
822 Set_Specification (Def_Node, P_Subprogram_Specification);
824 if Token = Tok_Is then
825 T_Is; -- past IS, skip extra IS or ";"
827 if Token = Tok_Box then
828 Set_Box_Present (Def_Node, True);
829 Scan; -- past <>
831 else
832 Set_Default_Name (Def_Node, P_Name);
833 end if;
835 end if;
837 T_Semicolon;
838 return Def_Node;
839 end P_Formal_Subprogram_Declaration;
841 ------------------------------
842 -- 12.6 Subprogram Default --
843 ------------------------------
845 -- Parsed by P_Formal_Procedure_Declaration (12.6)
847 ------------------------
848 -- 12.6 Default Name --
849 ------------------------
851 -- Parsed by P_Formal_Procedure_Declaration (12.6)
853 --------------------------------------
854 -- 12.7 Formal Package Declaration --
855 --------------------------------------
857 -- FORMAL_PACKAGE_DECLARATION ::=
858 -- with package DEFINING_IDENTIFIER
859 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
861 -- FORMAL_PACKAGE_ACTUAL_PART ::=
862 -- (<>) | [GENERIC_ACTUAL_PART]
864 -- The caller has checked that the initial tokens are WITH PACKAGE,
865 -- and the initial WITH has been scanned out (so Token = Tok_Package).
867 -- Error recovery: cannot raise Error_Resync
869 function P_Formal_Package_Declaration return Node_Id is
870 Def_Node : Node_Id;
871 Scan_State : Saved_Scan_State;
873 begin
874 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
875 Scan; -- past PACKAGE
876 Set_Defining_Identifier (Def_Node, P_Defining_Identifier);
877 T_Is;
878 T_New;
879 Set_Name (Def_Node, P_Qualified_Simple_Name);
881 if Token = Tok_Left_Paren then
882 Save_Scan_State (Scan_State); -- at the left paren
883 Scan; -- past the left paren
885 if Token = Tok_Box then
886 Set_Box_Present (Def_Node, True);
887 Scan; -- past box
888 T_Right_Paren;
890 else
891 Restore_Scan_State (Scan_State); -- to the left paren
892 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
893 end if;
894 end if;
896 T_Semicolon;
897 return Def_Node;
898 end P_Formal_Package_Declaration;
900 --------------------------------------
901 -- 12.7 Formal Package Actual Part --
902 --------------------------------------
904 -- Parsed by P_Formal_Package_Declaration (12.7)
906 end Ch12;