Debian Codegraph @

gcc/ada/par-ch9.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P A R . C H 9 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order by RM
28 -- section rather than alphabetical.
29
30 separate (Par)
31 package body Ch9 is
32
33 -- Local subprograms, used only in this chapter
34
35 function P_Accept_Alternative return Node_Id;
36 function P_Delay_Alternative return Node_Id;
37 function P_Delay_Relative_Statement return Node_Id;
38 function P_Delay_Until_Statement return Node_Id;
39 function P_Entry_Barrier return Node_Id;
40 function P_Entry_Body_Formal_Part return Node_Id;
41 function P_Entry_Declaration return Node_Id;
42 function P_Entry_Index_Specification return Node_Id;
43 function P_Protected_Definition return Node_Id;
44 function P_Protected_Operation_Declaration_Opt return Node_Id;
45 function P_Protected_Operation_Items return List_Id;
46 function P_Task_Items return List_Id;
47 function P_Task_Definition return Node_Id;
48
49 -----------------------------
50 -- 9.1 Task (also 10.1.3) --
51 -----------------------------
52
53 -- TASK_TYPE_DECLARATION ::=
54 -- task type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
55 -- [ASPECT_SPECIFICATIONS]
56 -- [is [new INTERFACE_LIST with] TASK_DEFINITION];
57
58 -- SINGLE_TASK_DECLARATION ::=
59 -- task DEFINING_IDENTIFIER
60 -- [ASPECT_SPECIFICATIONS]
61 -- [is [new INTERFACE_LIST with] TASK_DEFINITION];
62
63 -- TASK_BODY ::=
64 -- task body DEFINING_IDENTIFIER [ASPECT_SPECIFICATIONS] is
65 -- DECLARATIVE_PART
66 -- begin
67 -- HANDLED_SEQUENCE_OF_STATEMENTS
68 -- end [task_IDENTIFIER]
69
70 -- TASK_BODY_STUB ::=
71 -- task body DEFINING_IDENTIFIER is separate
72 -- [ASPECT_SPECIFICATIONS];
73
74 -- This routine scans out a task declaration, task body, or task stub
75
76 -- The caller has checked that the initial token is TASK and scanned
77 -- past it, so that Token is set to the token after TASK
78
79 -- Error recovery: cannot raise Error_Resync
80
81 function P_Task return Node_Id is
82 Aspect_Sloc : Source_Ptr := No_Location;
83 Name_Node : Node_Id;
84 Task_Node : Node_Id;
85 Task_Sloc : Source_Ptr;
86
87 Dummy_Node : constant Node_Id := New_Node (N_Task_Body, Token_Ptr);
88 -- Placeholder node used to hold legal or prematurely declared aspect
89 -- specifications. Depending on the context, the aspect specifications
90 -- may be moved to a new node.
91
92 begin
93 Push_Scope_Stack;
94 Scopes (Scope.Last).Etyp := E_Name;
95 Scopes (Scope.Last).Ecol := Start_Column;
96 Scopes (Scope.Last).Sloc := Token_Ptr;
97 Scopes (Scope.Last).Lreq := False;
98 Task_Sloc := Prev_Token_Ptr;
99
100 if Token = Tok_Body then
101 Scan; -- past BODY
102 Name_Node := P_Defining_Identifier (C_Is);
103 Scopes (Scope.Last).Labl := Name_Node;
104
105 if Token = Tok_Left_Paren then
106 Error_Msg_SC ("discriminant part not allowed in task body");
107 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
108 end if;
109
110 if Aspect_Specifications_Present then
111 Aspect_Sloc := Token_Ptr;
112 P_Aspect_Specifications (Dummy_Node, Semicolon => False);
113 end if;
114
115 TF_Is;
116
117 -- Task stub
118
119 if Token = Tok_Separate then
120 Scan; -- past SEPARATE
121 Task_Node := New_Node (N_Task_Body_Stub, Task_Sloc);
122 Set_Defining_Identifier (Task_Node, Name_Node);
123
124 if Has_Aspects (Dummy_Node) then
125 Error_Msg
126 ("aspect specifications must come after SEPARATE",
127 Aspect_Sloc);
128 end if;
129
130 P_Aspect_Specifications (Task_Node, Semicolon => False);
131 TF_Semicolon;
132 Pop_Scope_Stack; -- remove unused entry
133
134 -- Task body
135
136 else
137 Task_Node := New_Node (N_Task_Body, Task_Sloc);
138 Set_Defining_Identifier (Task_Node, Name_Node);
139
140 -- Move the aspect specifications to the body node
141
142 Move_Aspects (From => Dummy_Node, To => Task_Node);
143
144 Parse_Decls_Begin_End (Task_Node);
145
146 -- The statement list of a task body needs to include at least a
147 -- null statement, so if a parsing error produces an empty list,
148 -- patch it now.
149
150 if No (First (Statements
151 (Handled_Statement_Sequence (Task_Node))))
152 then
153 Set_Statements (Handled_Statement_Sequence (Task_Node),
154 New_List (Make_Null_Statement (Token_Ptr)));
155 end if;
156 end if;
157
158 return Task_Node;
159
160 -- Otherwise we must have a task declaration
161
162 else
163 if Token = Tok_Type then
164 Scan; -- past TYPE
165 Task_Node := New_Node (N_Task_Type_Declaration, Task_Sloc);
166 Name_Node := P_Defining_Identifier;
167 Set_Defining_Identifier (Task_Node, Name_Node);
168 Scopes (Scope.Last).Labl := Name_Node;
169
170 Set_Discriminant_Specifications
171 (Task_Node, P_Known_Discriminant_Part_Opt);
172
173 else
174 Task_Node := New_Node (N_Single_Task_Declaration, Task_Sloc);
175 Name_Node := P_Defining_Identifier (C_Is);
176 Set_Defining_Identifier (Task_Node, Name_Node);
177 Scopes (Scope.Last).Labl := Name_Node;
178
179 if Token = Tok_Left_Paren then
180 Error_Msg_SC ("discriminant part not allowed for single task");
181 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
182 end if;
183 end if;
184
185 -- Scan aspect specifications, don't eat the semicolon, since it
186 -- might not be there if we have an IS.
187
188 P_Aspect_Specifications (Task_Node, Semicolon => False);
189
190 -- Parse optional task definition. Note that P_Task_Definition scans
191 -- out the semicolon and possible aspect specifications as well as
192 -- the task definition itself.
193
194 if Token = Tok_Semicolon then
195
196 -- A little check, if the next token after semicolon is Entry,
197 -- then surely the semicolon should really be IS
198
199 Scan; -- past semicolon
200
201 if Token = Tok_Entry then
202 Error_Msg_SP -- CODEFIX
203 ("|"";"" should be IS");
204 Set_Task_Definition (Task_Node, P_Task_Definition);
205 else
206 Pop_Scope_Stack; -- Remove unused entry
207 end if;
208
209 -- Here we have a task definition
210
211 else
212 TF_Is; -- must have IS if no semicolon
213
214 -- Ada 2005 (AI-345)
215
216 if Token = Tok_New then
217 Scan; -- past NEW
218
219 Error_Msg_Ada_2005_Extension ("task interface");
220
221 Set_Interface_List (Task_Node, New_List);
222
223 loop
224 Append (P_Qualified_Simple_Name, Interface_List (Task_Node));
225 exit when Token /= Tok_And;
226 Scan; -- past AND
227 end loop;
228
229 if Token /= Tok_With then
230 Error_Msg_SC -- CODEFIX
231 ("WITH expected");
232 end if;
233
234 Scan; -- past WITH
235
236 if Token = Tok_Private then
237 Error_Msg_SP -- CODEFIX
238 ("PRIVATE not allowed in task type declaration");
239 end if;
240 end if;
241
242 Set_Task_Definition (Task_Node, P_Task_Definition);
243 end if;
244
245 return Task_Node;
246 end if;
247 end P_Task;
248
249 --------------------------------
250 -- 9.1 Task Type Declaration --
251 --------------------------------
252
253 -- Parsed by P_Task (9.1)
254
255 ----------------------------------
256 -- 9.1 Single Task Declaration --
257 ----------------------------------
258
259 -- Parsed by P_Task (9.1)
260
261 --------------------------
262 -- 9.1 Task Definition --
263 --------------------------
264
265 -- TASK_DEFINITION ::=
266 -- {TASK_ITEM}
267 -- [private
268 -- {TASK_ITEM}]
269 -- end [task_IDENTIFIER];
270
271 -- The caller has already made the scope stack entry
272
273 -- Note: there is a small deviation from official syntax here in that we
274 -- regard the semicolon after end as part of the Task_Definition, and in
275 -- the official syntax, it's part of the enclosing declaration. The reason
276 -- for this deviation is that otherwise the end processing would have to
277 -- be special cased, which would be a nuisance.
278
279 -- Error recovery: cannot raise Error_Resync
280
281 function P_Task_Definition return Node_Id is
282 Def_Node : Node_Id;
283
284 begin
285 Def_Node := New_Node (N_Task_Definition, Token_Ptr);
286 Set_Visible_Declarations (Def_Node, P_Task_Items);
287
288 if Token = Tok_Private then
289 Scan; -- past PRIVATE
290 Set_Private_Declarations (Def_Node, P_Task_Items);
291
292 -- Deal gracefully with multiple PRIVATE parts
293
294 while Token = Tok_Private loop
295 Error_Msg_SC ("only one private part allowed per task");
296 Scan; -- past PRIVATE
297 Append_List (P_Task_Items, Private_Declarations (Def_Node));
298 end loop;
299 end if;
300
301 End_Statements (Def_Node);
302 return Def_Node;
303 end P_Task_Definition;
304
305 --------------------
306 -- 9.1 Task Item --
307 --------------------
308
309 -- TASK_ITEM ::= ENTRY_DECLARATION | REPRESENTATION_CLAUSE
310
311 -- This subprogram scans a (possibly empty) list of task items and pragmas
312
313 -- Error recovery: cannot raise Error_Resync
314
315 -- Note: a pragma can also be returned in this position
316
317 function P_Task_Items return List_Id is
318 Items : List_Id;
319 Item_Node : Node_Id;
320 Decl_Sloc : Source_Ptr;
321
322 begin
323 -- Get rid of active SIS entry from outer scope. This means we will
324 -- miss some nested cases, but it doesn't seem worth the effort. See
325 -- discussion in Par for further details
326
327 SIS_Entry_Active := False;
328
329 -- Loop to scan out task items
330
331 Items := New_List;
332
333 Decl_Loop : loop
334 Decl_Sloc := Token_Ptr;
335
336 if Token = Tok_Pragma then
337 P_Pragmas_Opt (Items);
338
339 -- Ada 2005 (AI-397): Reserved words NOT and OVERRIDING may begin an
340 -- entry declaration.
341
342 elsif Token in Tok_Entry | Tok_Not | Tok_Overriding then
343 Append (P_Entry_Declaration, Items);
344
345 elsif Token = Tok_For then
346
347 -- Representation clause in task declaration. The only rep clause
348 -- which is legal in a protected declaration is an address clause,
349 -- so that is what we try to scan out.
350
351 Item_Node := P_Representation_Clause;
352
353 if Nkind (Item_Node) = N_At_Clause then
354 Append (Item_Node, Items);
355
356 elsif Nkind (Item_Node) = N_Attribute_Definition_Clause
357 and then Chars (Item_Node) = Name_Address
358 then
359 Append (Item_Node, Items);
360
361 else
362 Error_Msg
363 ("the only representation clause " &
364 "allowed here is an address clause!", Decl_Sloc);
365 end if;
366
367 elsif Token = Tok_Identifier
368 or else Token in Token_Class_Declk
369 then
370 Error_Msg_SC ("illegal declaration in task definition");
371 Resync_Past_Semicolon;
372
373 else
374 exit Decl_Loop;
375 end if;
376 end loop Decl_Loop;
377
378 return Items;
379 end P_Task_Items;
380
381 --------------------
382 -- 9.1 Task Body --
383 --------------------
384
385 -- Parsed by P_Task (9.1)
386
387 ----------------------------------
388 -- 9.4 Protected (also 10.1.3) --
389 ----------------------------------
390
391 -- PROTECTED_TYPE_DECLARATION ::=
392 -- protected type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART]
393 -- [ASPECT_SPECIFICATIONS]
394 -- is [new INTERFACE_LIST with] PROTECTED_DEFINITION;
395
396 -- SINGLE_PROTECTED_DECLARATION ::=
397 -- protected DEFINING_IDENTIFIER
398 -- [ASPECT_SPECIFICATIONS]
399 -- is [new INTERFACE_LIST with] PROTECTED_DEFINITION;
400
401 -- PROTECTED_BODY ::=
402 -- protected body DEFINING_IDENTIFIER
403 -- [ASPECT_SPECIFICATIONS]
404 -- is
405 -- {PROTECTED_OPERATION_ITEM}
406 -- end [protected_IDENTIFIER];
407
408 -- PROTECTED_BODY_STUB ::=
409 -- protected body DEFINING_IDENTIFIER is separate
410 -- [ASPECT_SPECIFICATIONS];
411
412 -- This routine scans out a protected declaration, protected body
413 -- or a protected stub.
414
415 -- The caller has checked that the initial token is PROTECTED and
416 -- scanned past it, so Token is set to the following token.
417
418 -- Error recovery: cannot raise Error_Resync
419
420 function P_Protected return Node_Id is
421 Aspect_Sloc : Source_Ptr := No_Location;
422 Name_Node : Node_Id;
423 Protected_Node : Node_Id;
424 Protected_Sloc : Source_Ptr;
425 Scan_State : Saved_Scan_State;
426
427 Dummy_Node : constant Node_Id := New_Node (N_Protected_Body, Token_Ptr);
428 -- Placeholder node used to hold legal or prematurely declared aspect
429 -- specifications. Depending on the context, the aspect specifications
430 -- may be moved to a new node.
431
432 begin
433 Push_Scope_Stack;
434 Scopes (Scope.Last).Etyp := E_Name;
435 Scopes (Scope.Last).Ecol := Start_Column;
436 Scopes (Scope.Last).Lreq := False;
437 Protected_Sloc := Prev_Token_Ptr;
438
439 if Token = Tok_Body then
440 Scan; -- past BODY
441 Name_Node := P_Defining_Identifier (C_Is);
442 Scopes (Scope.Last).Labl := Name_Node;
443
444 if Token = Tok_Left_Paren then
445 Error_Msg_SC ("discriminant part not allowed in protected body");
446 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
447 end if;
448
449 if Aspect_Specifications_Present then
450 Aspect_Sloc := Token_Ptr;
451 P_Aspect_Specifications (Dummy_Node, Semicolon => False);
452 end if;
453
454 TF_Is;
455
456 -- Protected stub
457
458 if Token = Tok_Separate then
459 Scan; -- past SEPARATE
460
461 Protected_Node := New_Node (N_Protected_Body_Stub, Protected_Sloc);
462 Set_Defining_Identifier (Protected_Node, Name_Node);
463
464 if Has_Aspects (Dummy_Node) then
465 Error_Msg
466 ("aspect specifications must come after SEPARATE",
467 Aspect_Sloc);
468 end if;
469
470 P_Aspect_Specifications (Protected_Node, Semicolon => False);
471 TF_Semicolon;
472 Pop_Scope_Stack; -- remove unused entry
473
474 -- Protected body
475
476 else
477 Protected_Node := New_Node (N_Protected_Body, Protected_Sloc);
478 Set_Defining_Identifier (Protected_Node, Name_Node);
479
480 Move_Aspects (From => Dummy_Node, To => Protected_Node);
481 Set_Declarations (Protected_Node, P_Protected_Operation_Items);
482 End_Statements (Protected_Node);
483 end if;
484
485 return Protected_Node;
486
487 -- Otherwise we must have a protected declaration
488
489 else
490 if Token = Tok_Type then
491 Scan; -- past TYPE
492 Protected_Node :=
493 New_Node (N_Protected_Type_Declaration, Protected_Sloc);
494 Name_Node := P_Defining_Identifier (C_Is);
495 Set_Defining_Identifier (Protected_Node, Name_Node);
496 Scopes (Scope.Last).Labl := Name_Node;
497 Set_Discriminant_Specifications
498 (Protected_Node, P_Known_Discriminant_Part_Opt);
499
500 else
501 Protected_Node :=
502 New_Node (N_Single_Protected_Declaration, Protected_Sloc);
503 Name_Node := P_Defining_Identifier (C_Is);
504 Set_Defining_Identifier (Protected_Node, Name_Node);
505
506 if Token = Tok_Left_Paren then
507 Error_Msg_SC
508 ("discriminant part not allowed for single protected");
509 Discard_Junk_List (P_Known_Discriminant_Part_Opt);
510 end if;
511
512 Scopes (Scope.Last).Labl := Name_Node;
513 end if;
514
515 P_Aspect_Specifications (Protected_Node, Semicolon => False);
516
517 -- Check for semicolon not followed by IS, this is something like
518
519 -- protected type r;
520
521 -- where we want
522
523 -- protected type r IS END;
524
525 if Token = Tok_Semicolon then
526 Save_Scan_State (Scan_State); -- at semicolon
527 Scan; -- past semicolon
528
529 if Token /= Tok_Is then
530 Restore_Scan_State (Scan_State);
531 Error_Msg_SC -- CODEFIX
532 ("missing IS");
533 Set_Protected_Definition (Protected_Node,
534 Make_Protected_Definition (Token_Ptr,
535 Visible_Declarations => Empty_List,
536 End_Label => Empty));
537
538 SIS_Entry_Active := False;
539 End_Statements
540 (Protected_Definition (Protected_Node), Protected_Node);
541 return Protected_Node;
542 end if;
543
544 Error_Msg_SP -- CODEFIX
545 ("|extra ""("" ignored");
546 end if;
547
548 T_Is;
549
550 -- Ada 2005 (AI-345)
551
552 if Token = Tok_New then
553 Scan; -- past NEW
554
555 Error_Msg_Ada_2005_Extension ("protected interface");
556
557 Set_Interface_List (Protected_Node, New_List);
558
559 loop
560 Append (P_Qualified_Simple_Name,
561 Interface_List (Protected_Node));
562
563 exit when Token /= Tok_And;
564 Scan; -- past AND
565 end loop;
566
567 if Token /= Tok_With then
568 Error_Msg_SC -- CODEFIX
569 ("WITH expected");
570 end if;
571
572 Scan; -- past WITH
573 end if;
574
575 Set_Protected_Definition (Protected_Node, P_Protected_Definition);
576 return Protected_Node;
577 end if;
578 end P_Protected;
579
580 -------------------------------------
581 -- 9.4 Protected Type Declaration --
582 -------------------------------------
583
584 -- Parsed by P_Protected (9.4)
585
586 ---------------------------------------
587 -- 9.4 Single Protected Declaration --
588 ---------------------------------------
589
590 -- Parsed by P_Protected (9.4)
591
592 -------------------------------
593 -- 9.4 Protected Definition --
594 -------------------------------
595
596 -- PROTECTED_DEFINITION ::=
597 -- {PROTECTED_OPERATION_DECLARATION}
598 -- [private
599 -- {PROTECTED_ELEMENT_DECLARATION}]
600 -- end [protected_IDENTIFIER]
601
602 -- PROTECTED_ELEMENT_DECLARATION ::=
603 -- PROTECTED_OPERATION_DECLARATION
604 -- | COMPONENT_DECLARATION
605
606 -- The caller has already established the scope stack entry
607
608 -- Error recovery: cannot raise Error_Resync
609
610 function P_Protected_Definition return Node_Id is
611 Def_Node : Node_Id;
612 Item_Node : Node_Id;
613 Priv_Decls : List_Id;
614 Vis_Decls : List_Id;
615
616 begin
617 Def_Node := New_Node (N_Protected_Definition, Token_Ptr);
618
619 -- Get rid of active SIS entry from outer scope. This means we will
620 -- miss some nested cases, but it doesn't seem worth the effort. See
621 -- discussion in Par for further details
622
623 SIS_Entry_Active := False;
624
625 -- Loop to scan visible declarations (protected operation declarations)
626
627 Vis_Decls := New_List;
628 Set_Visible_Declarations (Def_Node, Vis_Decls);
629
630 -- Flag and discard all pragmas which cannot appear in the protected
631 -- definition. Note that certain pragmas are still allowed as long as
632 -- they apply to entries, entry families, or protected subprograms.
633
634 P_Pragmas_Opt (Vis_Decls);
635
636 loop
637 Item_Node := P_Protected_Operation_Declaration_Opt;
638
639 if Present (Item_Node) then
640 Append (Item_Node, Vis_Decls);
641 end if;
642
643 P_Pragmas_Opt (Vis_Decls);
644
645 exit when No (Item_Node);
646 end loop;
647
648 -- Deal with PRIVATE part (including graceful handling of multiple
649 -- PRIVATE parts).
650
651 Private_Loop : while Token = Tok_Private loop
652 Priv_Decls := Private_Declarations (Def_Node);
653
654 if Present (Priv_Decls) then
655 Error_Msg_SC ("duplicate private part");
656 else
657 Priv_Decls := New_List;
658 Set_Private_Declarations (Def_Node, Priv_Decls);
659 end if;
660
661 Scan; -- past PRIVATE
662
663 -- Flag and discard all pragmas which cannot appear in the protected
664 -- definition. Note that certain pragmas are still allowed as long as
665 -- they apply to entries, entry families, or protected subprograms.
666
667 P_Pragmas_Opt (Priv_Decls);
668
669 Declaration_Loop : loop
670 if Token = Tok_Identifier then
671 P_Component_Items (Priv_Decls);
672 P_Pragmas_Opt (Priv_Decls);
673
674 else
675 Item_Node := P_Protected_Operation_Declaration_Opt;
676
677 if Present (Item_Node) then
678 Append (Item_Node, Priv_Decls);
679 end if;
680
681 P_Pragmas_Opt (Priv_Decls);
682
683 exit Declaration_Loop when No (Item_Node);
684 end if;
685 end loop Declaration_Loop;
686 end loop Private_Loop;
687
688 End_Statements (Def_Node);
689 return Def_Node;
690 end P_Protected_Definition;
691
692 ------------------------------------------
693 -- 9.4 Protected Operation Declaration --
694 ------------------------------------------
695
696 -- PROTECTED_OPERATION_DECLARATION ::=
697 -- SUBPROGRAM_DECLARATION
698 -- | ENTRY_DECLARATION
699 -- | REPRESENTATION_CLAUSE
700
701 -- Error recovery: cannot raise Error_Resync
702
703 -- Note: a pragma can also be returned in this position
704
705 -- We are not currently permitting representation clauses to appear as
706 -- protected operation declarations, do we have to rethink this???
707
708 function P_Protected_Operation_Declaration_Opt return Node_Id is
709 L : List_Id;
710 P : Source_Ptr;
711
712 function P_Entry_Or_Subprogram_With_Indicator return Node_Id;
713 -- Ada 2005 (AI-397): Parse an entry or a subprogram with an overriding
714 -- indicator. The caller has checked that the initial token is NOT or
715 -- OVERRIDING.
716
717 ------------------------------------------
718 -- P_Entry_Or_Subprogram_With_Indicator --
719 ------------------------------------------
720
721 function P_Entry_Or_Subprogram_With_Indicator return Node_Id is
722 Decl : Node_Id := Error;
723 Is_Overriding : Boolean := False;
724 Not_Overriding : Boolean := False;
725
726 begin
727 if Token = Tok_Not then
728 Scan; -- past NOT
729
730 if Token = Tok_Overriding then
731 Scan; -- past OVERRIDING
732 Not_Overriding := True;
733 else
734 Error_Msg_SC -- CODEFIX
735 ("OVERRIDING expected!");
736 end if;
737
738 else
739 Scan; -- past OVERRIDING
740 Is_Overriding := True;
741 end if;
742
743 if Is_Overriding or else Not_Overriding then
744 if Ada_Version < Ada_2005 then
745 Error_Msg_Ada_2005_Extension ("overriding indicator");
746
747 elsif Token = Tok_Entry then
748 Decl := P_Entry_Declaration;
749
750 Set_Must_Override (Decl, Is_Overriding);
751 Set_Must_Not_Override (Decl, Not_Overriding);
752
753 elsif Token in Tok_Function | Tok_Procedure then
754 Decl := P_Subprogram (Pf_Decl_Pexp);
755
756 Set_Must_Override (Specification (Decl), Is_Overriding);
757 Set_Must_Not_Override (Specification (Decl), Not_Overriding);
758
759 else
760 Error_Msg_SC -- CODEFIX
761 ("ENTRY, FUNCTION or PROCEDURE expected!");
762 end if;
763 end if;
764
765 return Decl;
766 end P_Entry_Or_Subprogram_With_Indicator;
767
768 Result : Node_Id := Empty;
769
770 -- Start of processing for P_Protected_Operation_Declaration_Opt
771
772 begin
773 -- This loop runs more than once only when a junk declaration is skipped
774
775 loop
776 case Token is
777 when Tok_Pragma =>
778 Result := P_Pragma;
779 exit;
780
781 when Tok_Not
782 | Tok_Overriding
783 =>
784 Result := P_Entry_Or_Subprogram_With_Indicator;
785 exit;
786
787 when Tok_Entry =>
788 Result := P_Entry_Declaration;
789 exit;
790
791 when Tok_Function
792 | Tok_Procedure
793 =>
794 Result := P_Subprogram (Pf_Decl_Pexp);
795 exit;
796
797 when Tok_Identifier =>
798 L := New_List;
799 P := Token_Ptr;
800 Skip_Declaration (L);
801
802 if Nkind (First (L)) = N_Object_Declaration then
803 Error_Msg
804 ("component must be declared in private part of " &
805 "protected type", P);
806 else
807 Error_Msg
808 ("illegal declaration in protected definition", P);
809 end if;
810 -- Continue looping
811
812 when Tok_For =>
813 Error_Msg_SC
814 ("representation clause not allowed in protected definition");
815 Resync_Past_Semicolon;
816 -- Continue looping
817
818 when others =>
819 if Token in Token_Class_Declk then
820 Error_Msg_SC ("illegal declaration in protected definition");
821 Resync_Past_Semicolon;
822
823 -- Return now to avoid cascaded messages if next declaration
824 -- is a valid component declaration.
825
826 Result := Error;
827 end if;
828
829 exit;
830 end case;
831 end loop;
832
833 if Nkind (Result) = N_Subprogram_Declaration
834 and then Nkind (Specification (Result)) =
835 N_Procedure_Specification
836 and then Null_Present (Specification (Result))
837 then
838 Error_Msg_N
839 ("protected operation cannot be a null procedure",
840 Null_Statement (Specification (Result)));
841 end if;
842
843 return Result;
844 end P_Protected_Operation_Declaration_Opt;
845
846 -----------------------------------
847 -- 9.4 Protected Operation Item --
848 -----------------------------------
849
850 -- PROTECTED_OPERATION_ITEM ::=
851 -- SUBPROGRAM_DECLARATION
852 -- | SUBPROGRAM_BODY
853 -- | ENTRY_BODY
854 -- | REPRESENTATION_CLAUSE
855
856 -- This procedure parses and returns a list of protected operation items
857
858 -- We are not currently permitting representation clauses to appear
859 -- as protected operation items, do we have to rethink this???
860
861 function P_Protected_Operation_Items return List_Id is
862 Item_List : List_Id;
863
864 begin
865 Item_List := New_List;
866
867 loop
868 if Token = Tok_Entry or else Bad_Spelling_Of (Tok_Entry) then
869 Append (P_Entry_Body, Item_List);
870
871 -- If the operation starts with procedure, function, or an overriding
872 -- indicator ("overriding" or "not overriding"), parse a subprogram.
873
874 elsif Token = Tok_Function or else Bad_Spelling_Of (Tok_Function)
875 or else
876 Token = Tok_Procedure or else Bad_Spelling_Of (Tok_Procedure)
877 or else
878 Token = Tok_Overriding or else Bad_Spelling_Of (Tok_Overriding)
879 or else
880 Token = Tok_Not or else Bad_Spelling_Of (Tok_Not)
881 then
882 Append (P_Subprogram (Pf_Decl_Pbod_Pexp), Item_List);
883
884 elsif Token = Tok_Pragma or else Bad_Spelling_Of (Tok_Pragma) then
885 P_Pragmas_Opt (Item_List);
886
887 elsif Token = Tok_Private or else Bad_Spelling_Of (Tok_Private) then
888 Error_Msg_SC ("PRIVATE not allowed in protected body");
889 Scan; -- past PRIVATE
890
891 elsif Token = Tok_Identifier then
892 Error_Msg_SC ("all components must be declared in spec!");
893 Resync_Past_Semicolon;
894
895 elsif Token in Token_Class_Declk then
896 Error_Msg_SC ("declaration not allowed in protected body");
897 Resync_Past_Semicolon;
898
899 else
900 exit;
901 end if;
902 end loop;
903
904 return Item_List;
905 end P_Protected_Operation_Items;
906
907 ------------------------------
908 -- 9.5.2 Entry Declaration --
909 ------------------------------
910
911 -- ENTRY_DECLARATION ::=
912 -- [OVERRIDING_INDICATOR]
913 -- entry DEFINING_IDENTIFIER
914 -- [(DISCRETE_SUBTYPE_DEFINITION)] PARAMETER_PROFILE
915 -- [ASPECT_SPECIFICATIONS];
916
917 -- The caller has checked that the initial token is ENTRY, NOT or
918 -- OVERRIDING.
919
920 -- Error recovery: cannot raise Error_Resync
921
922 function P_Entry_Declaration return Node_Id is
923 Decl_Node : Node_Id;
924 Scan_State : Saved_Scan_State;
925
926 -- Flags for optional overriding indication. Two flags are needed,
927 -- to distinguish positive and negative overriding indicators from
928 -- the absence of any indicator.
929
930 Is_Overriding : Boolean := False;
931 Not_Overriding : Boolean := False;
932
933 begin
934 -- Ada 2005 (AI-397): Scan leading overriding indicator
935
936 if Token = Tok_Not then
937 Scan; -- past NOT
938
939 if Token = Tok_Overriding then
940 Scan; -- part OVERRIDING
941 Not_Overriding := True;
942 else
943 Error_Msg_SC -- CODEFIX
944 ("OVERRIDING expected!");
945 end if;
946
947 elsif Token = Tok_Overriding then
948 Scan; -- part OVERRIDING
949 Is_Overriding := True;
950 end if;
951
952 if Is_Overriding or else Not_Overriding then
953 if Ada_Version < Ada_2005 then
954 Error_Msg_Ada_2005_Extension ("overriding indicator");
955 elsif Token /= Tok_Entry then
956 Error_Msg_SC -- CODEFIX
957 ("ENTRY expected!");
958 end if;
959 end if;
960
961 Decl_Node := New_Node (N_Entry_Declaration, Token_Ptr);
962 Scan; -- past ENTRY
963
964 Set_Defining_Identifier
965 (Decl_Node, P_Defining_Identifier (C_Left_Paren_Semicolon));
966
967 -- If left paren, could be (Discrete_Subtype_Definition) or Formal_Part
968
969 if Token = Tok_Left_Paren then
970 Scan; -- past (
971
972 -- If identifier after left paren, could still be either
973
974 if Token = Tok_Identifier then
975 Save_Scan_State (Scan_State); -- at Id
976 Scan; -- past Id
977
978 -- If comma or colon after Id, must be Formal_Part
979
980 if Token in Tok_Comma | Tok_Colon then
981 Restore_Scan_State (Scan_State); -- to Id
982 Set_Parameter_Specifications (Decl_Node, P_Formal_Part);
983
984 -- Else if Id without comma or colon, must be discrete subtype
985 -- defn
986
987 else
988 Restore_Scan_State (Scan_State); -- to Id
989 Set_Discrete_Subtype_Definition
990 (Decl_Node, P_Discrete_Subtype_Definition);
991 T_Right_Paren;
992 Set_Parameter_Specifications (Decl_Node, P_Parameter_Profile);
993 end if;
994
995 -- If no Id, must be discrete subtype definition
996
997 else
998 Set_Discrete_Subtype_Definition
999 (Decl_Node, P_Discrete_Subtype_Definition);
1000 T_Right_Paren;
1001 Set_Parameter_Specifications (Decl_Node, P_Parameter_Profile);
1002 end if;
1003 end if;
1004
1005 if Is_Overriding then
1006 Set_Must_Override (Decl_Node);
1007 elsif Not_Overriding then
1008 Set_Must_Not_Override (Decl_Node);
1009 end if;
1010
1011 -- Error recovery check for illegal return
1012
1013 if Token = Tok_Return then
1014 Error_Msg_SC ("entry cannot have return value!");
1015 Scan;
1016 Discard_Junk_Node (P_Subtype_Indication);
1017 end if;
1018
1019 -- Error recovery check for improper use of entry barrier in spec
1020
1021 if Token = Tok_When then
1022 Error_Msg_SC ("barrier not allowed here (belongs in body)");
1023 Scan; -- past WHEN;
1024 Discard_Junk_Node (P_Expression_No_Right_Paren);
1025 end if;
1026
1027 P_Aspect_Specifications (Decl_Node, Semicolon => True);
1028 return Decl_Node;
1029
1030 exception
1031 when Error_Resync =>
1032 Resync_Past_Semicolon;
1033 return Error;
1034 end P_Entry_Declaration;
1035
1036 -----------------------------
1037 -- 9.5.2 Accept Statement --
1038 -----------------------------
1039
1040 -- ACCEPT_STATEMENT ::=
1041 -- accept entry_DIRECT_NAME
1042 -- [(ENTRY_INDEX)] PARAMETER_PROFILE [do
1043 -- HANDLED_SEQUENCE_OF_STATEMENTS
1044 -- end [entry_IDENTIFIER]];
1045
1046 -- The caller has checked that the initial token is ACCEPT
1047
1048 -- Error recovery: cannot raise Error_Resync. If an error occurs, the
1049 -- scan is resynchronized past the next semicolon and control returns.
1050
1051 function P_Accept_Statement return Node_Id is
1052 Scan_State : Saved_Scan_State;
1053 Accept_Node : Node_Id;
1054 Hand_Seq : Node_Id;
1055
1056 begin
1057 Push_Scope_Stack;
1058 Scopes (Scope.Last).Sloc := Token_Ptr;
1059 Scopes (Scope.Last).Ecol := Start_Column;
1060
1061 Accept_Node := New_Node (N_Accept_Statement, Token_Ptr);
1062 Scan; -- past ACCEPT
1063 Scopes (Scope.Last).Labl := Token_Node;
1064
1065 Set_Entry_Direct_Name (Accept_Node, P_Identifier (C_Do));
1066
1067 -- Left paren could be (Entry_Index) or Formal_Part, determine which
1068
1069 if Token = Tok_Left_Paren then
1070 Save_Scan_State (Scan_State); -- at left paren
1071 Scan; -- past left paren
1072
1073 -- If first token after left paren not identifier, then Entry_Index
1074
1075 if Token /= Tok_Identifier then
1076 Set_Entry_Index (Accept_Node, P_Expression);
1077 T_Right_Paren;
1078 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
1079
1080 -- First token after left paren is identifier, could be either case
1081
1082 else -- Token = Tok_Identifier
1083 Scan; -- past identifier
1084
1085 -- If identifier followed by comma or colon, must be Formal_Part
1086
1087 if Token in Tok_Comma | Tok_Colon then
1088 Restore_Scan_State (Scan_State); -- to left paren
1089 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
1090
1091 -- If identifier not followed by comma/colon, must be entry index
1092
1093 else
1094 Restore_Scan_State (Scan_State); -- to left paren
1095 Scan; -- past left paren (again)
1096 Set_Entry_Index (Accept_Node, P_Expression);
1097 T_Right_Paren;
1098 Set_Parameter_Specifications (Accept_Node, P_Parameter_Profile);
1099 end if;
1100 end if;
1101 end if;
1102
1103 -- Scan out DO if present
1104
1105 if Token = Tok_Do then
1106 Scopes (Scope.Last).Etyp := E_Name;
1107 Scopes (Scope.Last).Lreq := False;
1108 Scan; -- past DO
1109 Hand_Seq := P_Handled_Sequence_Of_Statements;
1110 Set_Handled_Statement_Sequence (Accept_Node, Hand_Seq);
1111 End_Statements (Handled_Statement_Sequence (Accept_Node));
1112
1113 -- Exception handlers not allowed in Ada 95 node
1114
1115 if Present (Exception_Handlers (Hand_Seq)) then
1116 if Ada_Version = Ada_83 then
1117 Error_Msg_N
1118 ("(Ada 83) exception handlers in accept not allowed",
1119 First_Non_Pragma (Exception_Handlers (Hand_Seq)));
1120 end if;
1121 end if;
1122
1123 else
1124 Pop_Scope_Stack; -- discard unused entry
1125 TF_Semicolon;
1126 end if;
1127
1128 return Accept_Node;
1129
1130 -- If error, resynchronize past semicolon
1131
1132 exception
1133 when Error_Resync =>
1134 Resync_Past_Semicolon;
1135 Pop_Scope_Stack; -- discard unused entry
1136 return Error;
1137 end P_Accept_Statement;
1138
1139 ------------------------
1140 -- 9.5.2 Entry Index --
1141 ------------------------
1142
1143 -- Parsed by P_Expression (4.4)
1144
1145 --------------------------
1146 -- 9.5.2 Entry Barrier --
1147 --------------------------
1148
1149 -- ENTRY_BARRIER ::= when CONDITION
1150
1151 -- Error_Recovery: cannot raise Error_Resync
1152
1153 function P_Entry_Barrier return Node_Id is
1154 Bnode : Node_Id;
1155
1156 begin
1157 if Token = Tok_When then
1158 Scan; -- past WHEN;
1159 Bnode := P_Expression_No_Right_Paren;
1160
1161 if Token = Tok_Colon_Equal then
1162 Error_Msg_SC -- CODEFIX
1163 ("|"":="" should be ""=""");
1164 Scan;
1165 Bnode := P_Expression_No_Right_Paren;
1166 end if;
1167
1168 else
1169 T_When; -- to give error message
1170 Bnode := Error;
1171 end if;
1172
1173 return Bnode;
1174 end P_Entry_Barrier;
1175
1176 -----------------------
1177 -- 9.5.2 Entry Body --
1178 -----------------------
1179
1180 -- ENTRY_BODY ::=
1181 -- entry DEFINING_IDENTIFIER ENTRY_BODY_FORMAL_PART
1182 -- [ASPECT_SPECIFICATIONS] ENTRY_BARRIER
1183 -- is
1184 -- DECLARATIVE_PART
1185 -- begin
1186 -- HANDLED_SEQUENCE_OF_STATEMENTS
1187 -- end [entry_IDENTIFIER];
1188
1189 -- The caller has checked that the initial token is ENTRY
1190
1191 -- Error_Recovery: cannot raise Error_Resync
1192
1193 function P_Entry_Body return Node_Id is
1194 Dummy_Node : Node_Id;
1195 Entry_Node : Node_Id;
1196 Formal_Part_Node : Node_Id;
1197 Name_Node : Node_Id;
1198
1199 begin
1200 Push_Scope_Stack;
1201 Entry_Node := New_Node (N_Entry_Body, Token_Ptr);
1202 Scan; -- past ENTRY
1203
1204 Scopes (Scope.Last).Ecol := Start_Column;
1205 Scopes (Scope.Last).Lreq := False;
1206 Scopes (Scope.Last).Etyp := E_Name;
1207 Scopes (Scope.Last).Sloc := Token_Ptr;
1208
1209 Name_Node := P_Defining_Identifier;
1210 Set_Defining_Identifier (Entry_Node, Name_Node);
1211 Scopes (Scope.Last).Labl := Name_Node;
1212
1213 Formal_Part_Node := P_Entry_Body_Formal_Part;
1214 Set_Entry_Body_Formal_Part (Entry_Node, Formal_Part_Node);
1215
1216 -- Ada 2012 (AI12-0169): Aspect specifications may appear on an entry
1217 -- body immediately after the formal part. Do not parse the aspect
1218 -- specifications directly because the "when" of the entry barrier may
1219 -- be interpreted as a misused "with".
1220
1221 if Token = Tok_With then
1222 P_Aspect_Specifications (Entry_Node, Semicolon => False);
1223 end if;
1224
1225 Set_Condition (Formal_Part_Node, P_Entry_Barrier);
1226
1227 -- Detect an illegal placement of aspect specifications following the
1228 -- entry barrier.
1229
1230 -- entry E ... when Barrier with Aspect is
1231
1232 if Token = Tok_With then
1233 Error_Msg_SC ("aspect specifications must come before entry barrier");
1234
1235 -- Consume the illegal aspects to allow for parsing to continue
1236
1237 Dummy_Node := New_Node (N_Entry_Body, Sloc (Entry_Node));
1238 P_Aspect_Specifications (Dummy_Node, Semicolon => False);
1239 end if;
1240
1241 TF_Is;
1242 Parse_Decls_Begin_End (Entry_Node);
1243
1244 return Entry_Node;
1245 end P_Entry_Body;
1246
1247 -----------------------------------
1248 -- 9.5.2 Entry Body Formal Part --
1249 -----------------------------------
1250
1251 -- ENTRY_BODY_FORMAL_PART ::=
1252 -- [(ENTRY_INDEX_SPECIFICATION)] [PARAMETER_PART]
1253
1254 -- Error_Recovery: cannot raise Error_Resync
1255
1256 function P_Entry_Body_Formal_Part return Node_Id is
1257 Fpart_Node : Node_Id;
1258 Scan_State : Saved_Scan_State;
1259
1260 begin
1261 Fpart_Node := New_Node (N_Entry_Body_Formal_Part, Token_Ptr);
1262
1263 -- See if entry index specification present, and if so parse it
1264
1265 if Token = Tok_Left_Paren then
1266 Save_Scan_State (Scan_State); -- at left paren
1267 Scan; -- past left paren
1268
1269 if Token = Tok_For then
1270 Set_Entry_Index_Specification
1271 (Fpart_Node, P_Entry_Index_Specification);
1272 T_Right_Paren;
1273 else
1274 Restore_Scan_State (Scan_State); -- to left paren
1275 end if;
1276
1277 -- Check for (common?) case of left paren omitted before FOR. This
1278 -- is a tricky case, because the corresponding missing left paren
1279 -- can cause real havoc if a formal part is present which gets
1280 -- treated as part of the discrete subtype definition of the
1281 -- entry index specification, so just give error and resynchronize
1282
1283 elsif Token = Tok_For then
1284 T_Left_Paren; -- to give error message
1285 Resync_To_When;
1286 end if;
1287
1288 Set_Parameter_Specifications (Fpart_Node, P_Parameter_Profile);
1289 return Fpart_Node;
1290 end P_Entry_Body_Formal_Part;
1291
1292 --------------------------------------
1293 -- 9.5.2 Entry Index Specification --
1294 --------------------------------------
1295
1296 -- ENTRY_INDEX_SPECIFICATION ::=
1297 -- for DEFINING_IDENTIFIER in DISCRETE_SUBTYPE_DEFINITION
1298 -- [ASPECT_SPECIFICATION]
1299
1300 -- Error recovery: can raise Error_Resync
1301
1302 function P_Entry_Index_Specification return Node_Id is
1303 Iterator_Node : Node_Id;
1304
1305 begin
1306 Iterator_Node := New_Node (N_Entry_Index_Specification, Token_Ptr);
1307 T_For; -- past FOR
1308 Set_Defining_Identifier (Iterator_Node, P_Defining_Identifier (C_In));
1309 T_In;
1310 Set_Discrete_Subtype_Definition
1311 (Iterator_Node, P_Discrete_Subtype_Definition);
1312
1313 if Token = Tok_With then
1314 P_Aspect_Specifications (Iterator_Node, Semicolon => False);
1315 end if;
1316
1317 return Iterator_Node;
1318 end P_Entry_Index_Specification;
1319
1320 ---------------------------------
1321 -- 9.5.3 Entry Call Statement --
1322 ---------------------------------
1323
1324 -- Parsed by P_Name (4.1). Within a select, an entry call is parsed
1325 -- by P_Select_Statement (9.7)
1326
1327 ------------------------------
1328 -- 9.5.4 Requeue Statement --
1329 ------------------------------
1330
1331 -- REQUEUE_STATEMENT ::= requeue entry_NAME [with abort];
1332
1333 -- The caller has checked that the initial token is requeue
1334
1335 -- Error recovery: can raise Error_Resync
1336
1337 function P_Requeue_Statement return Node_Id is
1338 Requeue_Node : Node_Id;
1339
1340 begin
1341 Requeue_Node := New_Node (N_Requeue_Statement, Token_Ptr);
1342 Scan; -- past REQUEUE
1343 Set_Name (Requeue_Node, P_Name);
1344
1345 if Token = Tok_With then
1346 Scan; -- past WITH
1347 T_Abort;
1348 Set_Abort_Present (Requeue_Node, True);
1349 end if;
1350
1351 TF_Semicolon;
1352 return Requeue_Node;
1353 end P_Requeue_Statement;
1354
1355 --------------------------
1356 -- 9.6 Delay Statement --
1357 --------------------------
1358
1359 -- DELAY_STATEMENT ::=
1360 -- DELAY_UNTIL_STATEMENT
1361 -- | DELAY_RELATIVE_STATEMENT
1362
1363 -- The caller has checked that the initial token is DELAY
1364
1365 -- Error recovery: cannot raise Error_Resync
1366
1367 function P_Delay_Statement return Node_Id is
1368 begin
1369 Scan; -- past DELAY
1370
1371 -- The following check for delay until misused in Ada 83 doesn't catch
1372 -- all cases, but it's good enough to catch most of them.
1373
1374 if Token_Name = Name_Until then
1375 Check_95_Keyword (Tok_Until, Tok_Left_Paren);
1376 Check_95_Keyword (Tok_Until, Tok_Identifier);
1377 end if;
1378
1379 if Token = Tok_Until then
1380 return P_Delay_Until_Statement;
1381 else
1382 return P_Delay_Relative_Statement;
1383 end if;
1384 end P_Delay_Statement;
1385
1386 --------------------------------
1387 -- 9.6 Delay Until Statement --
1388 --------------------------------
1389
1390 -- DELAY_UNTIL_STATEMENT ::= delay until delay_EXPRESSION;
1391
1392 -- The caller has checked that the initial token is DELAY, scanned it
1393 -- out and checked that the current token is UNTIL
1394
1395 -- Error recovery: cannot raise Error_Resync
1396
1397 function P_Delay_Until_Statement return Node_Id is
1398 Delay_Node : Node_Id;
1399
1400 begin
1401 Delay_Node := New_Node (N_Delay_Until_Statement, Prev_Token_Ptr);
1402 Scan; -- past UNTIL
1403 Set_Expression (Delay_Node, P_Expression_No_Right_Paren);
1404 TF_Semicolon;
1405 return Delay_Node;
1406 end P_Delay_Until_Statement;
1407
1408 -----------------------------------
1409 -- 9.6 Delay Relative Statement --
1410 -----------------------------------
1411
1412 -- DELAY_RELATIVE_STATEMENT ::= delay delay_EXPRESSION;
1413
1414 -- The caller has checked that the initial token is DELAY, scanned it
1415 -- out and determined that the current token is not UNTIL
1416
1417 -- Error recovery: cannot raise Error_Resync
1418
1419 function P_Delay_Relative_Statement return Node_Id is
1420 Delay_Node : Node_Id;
1421
1422 begin
1423 Delay_Node := New_Node (N_Delay_Relative_Statement, Prev_Token_Ptr);
1424 Set_Expression (Delay_Node, P_Expression_No_Right_Paren);
1425 Check_Simple_Expression_In_Ada_83 (Expression (Delay_Node));
1426 TF_Semicolon;
1427 return Delay_Node;
1428 end P_Delay_Relative_Statement;
1429
1430 ---------------------------
1431 -- 9.7 Select Statement --
1432 ---------------------------
1433
1434 -- SELECT_STATEMENT ::=
1435 -- SELECTIVE_ACCEPT
1436 -- | TIMED_ENTRY_CALL
1437 -- | CONDITIONAL_ENTRY_CALL
1438 -- | ASYNCHRONOUS_SELECT
1439
1440 -- SELECTIVE_ACCEPT ::=
1441 -- select
1442 -- [GUARD]
1443 -- SELECT_ALTERNATIVE
1444 -- {or
1445 -- [GUARD]
1446 -- SELECT_ALTERNATIVE
1447 -- [else
1448 -- SEQUENCE_OF_STATEMENTS]
1449 -- end select;
1450
1451 -- GUARD ::= when CONDITION =>
1452
1453 -- Note: the guard preceding a select alternative is included as part
1454 -- of the node generated for a selective accept alternative.
1455
1456 -- SELECT_ALTERNATIVE ::=
1457 -- ACCEPT_ALTERNATIVE
1458 -- | DELAY_ALTERNATIVE
1459 -- | TERMINATE_ALTERNATIVE
1460
1461 -- TIMED_ENTRY_CALL ::=
1462 -- select
1463 -- ENTRY_CALL_ALTERNATIVE
1464 -- or
1465 -- DELAY_ALTERNATIVE
1466 -- end select;
1467
1468 -- CONDITIONAL_ENTRY_CALL ::=
1469 -- select
1470 -- ENTRY_CALL_ALTERNATIVE
1471 -- else
1472 -- SEQUENCE_OF_STATEMENTS
1473 -- end select;
1474
1475 -- ENTRY_CALL_ALTERNATIVE ::=
1476 -- ENTRY_CALL_STATEMENT [SEQUENCE_OF_STATEMENTS]
1477
1478 -- ASYNCHRONOUS_SELECT ::=
1479 -- select
1480 -- TRIGGERING_ALTERNATIVE
1481 -- then abort
1482 -- ABORTABLE_PART
1483 -- end select;
1484
1485 -- TRIGGERING_ALTERNATIVE ::=
1486 -- TRIGGERING_STATEMENT [SEQUENCE_OF_STATEMENTS]
1487
1488 -- TRIGGERING_STATEMENT ::= ENTRY_CALL_STATEMENT | DELAY_STATEMENT
1489
1490 -- The caller has checked that the initial token is SELECT
1491
1492 -- Error recovery: can raise Error_Resync
1493
1494 function P_Select_Statement return Node_Id is
1495 Select_Node : Node_Id;
1496 Select_Sloc : Source_Ptr;
1497 Stmnt_Sloc : Source_Ptr;
1498 Ecall_Node : Node_Id;
1499 Alternative : Node_Id;
1500 Select_Pragmas : List_Id;
1501 Alt_Pragmas : List_Id;
1502 Statement_List : List_Id;
1503 Alt_List : List_Id;
1504 Cond_Expr : Node_Id;
1505 Delay_Stmnt : Node_Id;
1506
1507 begin
1508 Push_Scope_Stack;
1509 Scopes (Scope.Last).Etyp := E_Select;
1510 Scopes (Scope.Last).Ecol := Start_Column;
1511 Scopes (Scope.Last).Sloc := Token_Ptr;
1512 Scopes (Scope.Last).Labl := Error;
1513
1514 Select_Sloc := Token_Ptr;
1515 Scan; -- past SELECT
1516 Stmnt_Sloc := Token_Ptr;
1517 Select_Pragmas := P_Pragmas_Opt;
1518
1519 -- If first token after select is designator, then we have an entry
1520 -- call, which must be the start of a conditional entry call, timed
1521 -- entry call or asynchronous select
1522
1523 if Token in Token_Class_Desig then
1524
1525 -- Scan entry call statement
1526
1527 begin
1528 Ecall_Node := P_Name;
1529
1530 -- ?? The following two clauses exactly parallel code in ch5
1531 -- and should be combined sometime
1532
1533 if Nkind (Ecall_Node) = N_Indexed_Component then
1534 declare
1535 Prefix_Node : constant Node_Id := Prefix (Ecall_Node);
1536 Exprs_Node : constant List_Id := Expressions (Ecall_Node);
1537
1538 begin
1539 Change_Node (Ecall_Node, N_Procedure_Call_Statement);
1540 Set_Name (Ecall_Node, Prefix_Node);
1541 Set_Parameter_Associations (Ecall_Node, Exprs_Node);
1542 end;
1543
1544 elsif Nkind (Ecall_Node) = N_Function_Call then
1545 declare
1546 Fname_Node : constant Node_Id := Name (Ecall_Node);
1547 Params_List : constant List_Id :=
1548 Parameter_Associations (Ecall_Node);
1549
1550 begin
1551 Change_Node (Ecall_Node, N_Procedure_Call_Statement);
1552 Set_Name (Ecall_Node, Fname_Node);
1553 Set_Parameter_Associations (Ecall_Node, Params_List);
1554 end;
1555
1556 elsif Nkind (Ecall_Node) = N_Identifier
1557 or else Nkind (Ecall_Node) = N_Selected_Component
1558 then
1559 -- Case of a call to a parameterless entry
1560
1561 declare
1562 C_Node : constant Node_Id :=
1563 New_Node (N_Procedure_Call_Statement, Stmnt_Sloc);
1564 begin
1565 Set_Name (C_Node, Ecall_Node);
1566 Set_Parameter_Associations (C_Node, No_List);
1567 Ecall_Node := C_Node;
1568 end;
1569 end if;
1570
1571 TF_Semicolon;
1572
1573 exception
1574 when Error_Resync =>
1575 Resync_Past_Semicolon;
1576 return Error;
1577 end;
1578
1579 Statement_List := P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm);
1580
1581 -- OR follows, we have a timed entry call
1582
1583 if Token = Tok_Or then
1584 Scan; -- past OR
1585 Alt_Pragmas := P_Pragmas_Opt;
1586
1587 Select_Node := New_Node (N_Timed_Entry_Call, Select_Sloc);
1588 Set_Entry_Call_Alternative (Select_Node,
1589 Make_Entry_Call_Alternative (Stmnt_Sloc,
1590 Entry_Call_Statement => Ecall_Node,
1591 Pragmas_Before => Select_Pragmas,
1592 Statements => Statement_List));
1593
1594 -- Only possibility is delay alternative. If we have anything
1595 -- else, give message, and treat as conditional entry call.
1596
1597 if Token /= Tok_Delay then
1598 Error_Msg_SC
1599 ("only allowed alternative in timed entry call is delay!");
1600 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1601 Set_Delay_Alternative (Select_Node, Error);
1602
1603 else
1604 Set_Delay_Alternative (Select_Node, P_Delay_Alternative);
1605 Set_Pragmas_Before
1606 (Delay_Alternative (Select_Node), Alt_Pragmas);
1607 end if;
1608
1609 -- ELSE follows, we have a conditional entry call
1610
1611 elsif Token = Tok_Else then
1612 Scan; -- past ELSE
1613 Select_Node := New_Node (N_Conditional_Entry_Call, Select_Sloc);
1614
1615 Set_Entry_Call_Alternative (Select_Node,
1616 Make_Entry_Call_Alternative (Stmnt_Sloc,
1617 Entry_Call_Statement => Ecall_Node,
1618 Pragmas_Before => Select_Pragmas,
1619 Statements => Statement_List));
1620
1621 Set_Else_Statements
1622 (Select_Node, P_Sequence_Of_Statements (SS_Sreq));
1623
1624 -- Only remaining case is THEN ABORT (asynchronous select)
1625
1626 elsif Token = Tok_Abort then
1627 Select_Node :=
1628 Make_Asynchronous_Select (Select_Sloc,
1629 Triggering_Alternative =>
1630 Make_Triggering_Alternative (Stmnt_Sloc,
1631 Triggering_Statement => Ecall_Node,
1632 Pragmas_Before => Select_Pragmas,
1633 Statements => Statement_List),
1634 Abortable_Part => P_Abortable_Part);
1635
1636 -- Else error
1637
1638 else
1639 if Ada_Version = Ada_83 then
1640 Error_Msg_BC ("OR or ELSE expected");
1641 else
1642 Error_Msg_BC ("OR or ELSE or `THEN ABORT` expected");
1643 end if;
1644
1645 Select_Node := Error;
1646 end if;
1647
1648 End_Statements;
1649
1650 -- Here we have a selective accept or an asynchronous select (first
1651 -- token after SELECT is other than a designator token).
1652
1653 else
1654 -- If we have delay with no guard, could be asynchronous select
1655
1656 if Token = Tok_Delay then
1657 Delay_Stmnt := P_Delay_Statement;
1658 Statement_List := P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm);
1659
1660 -- Asynchronous select
1661
1662 if Token = Tok_Abort then
1663 Select_Node :=
1664 Make_Asynchronous_Select (Select_Sloc,
1665 Triggering_Alternative =>
1666 Make_Triggering_Alternative (Stmnt_Sloc,
1667 Triggering_Statement => Delay_Stmnt,
1668 Pragmas_Before => Select_Pragmas,
1669 Statements => Statement_List),
1670 Abortable_Part => P_Abortable_Part);
1671
1672 End_Statements;
1673 return Select_Node;
1674
1675 -- Delay which was not an asynchronous select. Must be a selective
1676 -- accept, and since at least one accept statement is required,
1677 -- we must have at least one OR phrase present.
1678
1679 else
1680 Alt_List := New_List (
1681 Make_Delay_Alternative (Stmnt_Sloc,
1682 Delay_Statement => Delay_Stmnt,
1683 Pragmas_Before => Select_Pragmas,
1684 Statements => Statement_List));
1685 T_Or;
1686 Alt_Pragmas := P_Pragmas_Opt;
1687 end if;
1688
1689 -- If not a delay statement, then must be another possibility for
1690 -- a selective accept alternative, or perhaps a guard is present
1691
1692 else
1693 Alt_List := New_List;
1694 Alt_Pragmas := Select_Pragmas;
1695 end if;
1696
1697 Select_Node := New_Node (N_Selective_Accept, Select_Sloc);
1698 Set_Select_Alternatives (Select_Node, Alt_List);
1699
1700 -- Scan out selective accept alternatives. On entry to this loop,
1701 -- we are just past a SELECT or OR token, and any pragmas that
1702 -- immediately follow the SELECT or OR are in Alt_Pragmas.
1703
1704 loop
1705 if Token = Tok_When then
1706
1707 if Present (Alt_Pragmas) then
1708 Error_Msg_SC ("pragmas may not precede guard");
1709 end if;
1710
1711 Scan; -- past WHEN
1712 Cond_Expr := P_Expression_No_Right_Paren;
1713 T_Arrow;
1714 Alt_Pragmas := P_Pragmas_Opt;
1715
1716 else
1717 Cond_Expr := Empty;
1718 end if;
1719
1720 if Token = Tok_Accept then
1721 Alternative := P_Accept_Alternative;
1722
1723 -- Check for junk attempt at asynchronous select using
1724 -- an Accept alternative as the triggering statement
1725
1726 if Token = Tok_Abort
1727 and then Is_Empty_List (Alt_List)
1728 and then No (Cond_Expr)
1729 then
1730 Error_Msg
1731 ("triggering statement must be entry call or delay",
1732 Sloc (Alternative));
1733 Scan; -- past junk ABORT
1734 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1735 End_Statements;
1736 return Error;
1737 end if;
1738
1739 elsif Token = Tok_Delay then
1740 Alternative := P_Delay_Alternative;
1741
1742 elsif Token = Tok_Terminate then
1743 Alternative := P_Terminate_Alternative;
1744
1745 else
1746 Error_Msg_SC
1747 ("select alternative (ACCEPT, ABORT, DELAY) expected");
1748 Alternative := Error;
1749
1750 if Token = Tok_Semicolon then
1751 Scan; -- past junk semicolon
1752 end if;
1753 end if;
1754
1755 -- THEN ABORT at this stage is just junk
1756
1757 if Token = Tok_Abort then
1758 Error_Msg_SP ("misplaced `THEN ABORT`");
1759 Scan; -- past junk ABORT
1760 Discard_Junk_List (P_Sequence_Of_Statements (SS_Sreq));
1761 End_Statements;
1762 return Error;
1763
1764 else
1765 if Alternative /= Error then
1766 Set_Condition (Alternative, Cond_Expr);
1767 Set_Pragmas_Before (Alternative, Alt_Pragmas);
1768 Append (Alternative, Alt_List);
1769 end if;
1770
1771 exit when Token /= Tok_Or;
1772 end if;
1773
1774 T_Or;
1775 Alt_Pragmas := P_Pragmas_Opt;
1776 end loop;
1777
1778 if Token = Tok_Else then
1779 Scan; -- past ELSE
1780 Set_Else_Statements
1781 (Select_Node, P_Sequence_Of_Statements (SS_Ortm_Sreq));
1782
1783 if Token = Tok_Or then
1784 Error_Msg_SC ("select alternative cannot follow else part!");
1785 end if;
1786 end if;
1787
1788 End_Statements;
1789 end if;
1790
1791 return Select_Node;
1792 end P_Select_Statement;
1793
1794 -----------------------------
1795 -- 9.7.1 Selective Accept --
1796 -----------------------------
1797
1798 -- Parsed by P_Select_Statement (9.7)
1799
1800 ------------------
1801 -- 9.7.1 Guard --
1802 ------------------
1803
1804 -- Parsed by P_Select_Statement (9.7)
1805
1806 -------------------------------
1807 -- 9.7.1 Select Alternative --
1808 -------------------------------
1809
1810 -- SELECT_ALTERNATIVE ::=
1811 -- ACCEPT_ALTERNATIVE
1812 -- | DELAY_ALTERNATIVE
1813 -- | TERMINATE_ALTERNATIVE
1814
1815 -- Note: the guard preceding a select alternative is included as part
1816 -- of the node generated for a selective accept alternative.
1817
1818 -- Error recovery: cannot raise Error_Resync
1819
1820 -------------------------------
1821 -- 9.7.1 Accept Alternative --
1822 -------------------------------
1823
1824 -- ACCEPT_ALTERNATIVE ::=
1825 -- ACCEPT_STATEMENT [SEQUENCE_OF_STATEMENTS]
1826
1827 -- Error_Recovery: Cannot raise Error_Resync
1828
1829 -- Note: the caller is responsible for setting the Pragmas_Before
1830 -- field of the returned N_Terminate_Alternative node.
1831
1832 function P_Accept_Alternative return Node_Id is
1833 Accept_Alt_Node : Node_Id;
1834
1835 begin
1836 Accept_Alt_Node := New_Node (N_Accept_Alternative, Token_Ptr);
1837 Set_Accept_Statement (Accept_Alt_Node, P_Accept_Statement);
1838
1839 -- Note: the reason that we accept THEN ABORT as a terminator for
1840 -- the sequence of statements is for error recovery which allows
1841 -- for misuse of an accept statement as a triggering statement.
1842
1843 Set_Statements
1844 (Accept_Alt_Node, P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm));
1845 return Accept_Alt_Node;
1846 end P_Accept_Alternative;
1847
1848 ------------------------------
1849 -- 9.7.1 Delay Alternative --
1850 ------------------------------
1851
1852 -- DELAY_ALTERNATIVE ::=
1853 -- DELAY_STATEMENT [SEQUENCE_OF_STATEMENTS]
1854
1855 -- Error_Recovery: Cannot raise Error_Resync
1856
1857 -- Note: the caller is responsible for setting the Pragmas_Before
1858 -- field of the returned N_Terminate_Alternative node.
1859
1860 function P_Delay_Alternative return Node_Id is
1861 Delay_Alt_Node : Node_Id;
1862
1863 begin
1864 Delay_Alt_Node := New_Node (N_Delay_Alternative, Token_Ptr);
1865 Set_Delay_Statement (Delay_Alt_Node, P_Delay_Statement);
1866
1867 -- Note: the reason that we accept THEN ABORT as a terminator for
1868 -- the sequence of statements is for error recovery which allows
1869 -- for misuse of an accept statement as a triggering statement.
1870
1871 Set_Statements
1872 (Delay_Alt_Node, P_Sequence_Of_Statements (SS_Eltm_Ortm_Tatm));
1873 return Delay_Alt_Node;
1874 end P_Delay_Alternative;
1875
1876 ----------------------------------
1877 -- 9.7.1 Terminate Alternative --
1878 ----------------------------------
1879
1880 -- TERMINATE_ALTERNATIVE ::= terminate;
1881
1882 -- Error_Recovery: Cannot raise Error_Resync
1883
1884 -- Note: the caller is responsible for setting the Pragmas_Before
1885 -- field of the returned N_Terminate_Alternative node.
1886
1887 function P_Terminate_Alternative return Node_Id is
1888 Terminate_Alt_Node : Node_Id;
1889
1890 begin
1891 Terminate_Alt_Node := New_Node (N_Terminate_Alternative, Token_Ptr);
1892 Scan; -- past TERMINATE
1893 TF_Semicolon;
1894
1895 -- For all other select alternatives, the sequence of statements
1896 -- after the alternative statement will swallow up any pragmas
1897 -- coming in this position. But the terminate alternative has no
1898 -- sequence of statements, so the pragmas here must be treated
1899 -- specially.
1900
1901 Set_Pragmas_After (Terminate_Alt_Node, P_Pragmas_Opt);
1902 return Terminate_Alt_Node;
1903 end P_Terminate_Alternative;
1904
1905 -----------------------------
1906 -- 9.7.2 Timed Entry Call --
1907 -----------------------------
1908
1909 -- Parsed by P_Select_Statement (9.7)
1910
1911 -----------------------------------
1912 -- 9.7.2 Entry Call Alternative --
1913 -----------------------------------
1914
1915 -- Parsed by P_Select_Statement (9.7)
1916
1917 -----------------------------------
1918 -- 9.7.3 Conditional Entry Call --
1919 -----------------------------------
1920
1921 -- Parsed by P_Select_Statement (9.7)
1922
1923 --------------------------------
1924 -- 9.7.4 Asynchronous Select --
1925 --------------------------------
1926
1927 -- Parsed by P_Select_Statement (9.7)
1928
1929 -----------------------------------
1930 -- 9.7.4 Triggering Alternative --
1931 -----------------------------------
1932
1933 -- Parsed by P_Select_Statement (9.7)
1934
1935 ---------------------------------
1936 -- 9.7.4 Triggering Statement --
1937 ---------------------------------
1938
1939 -- Parsed by P_Select_Statement (9.7)
1940
1941 ---------------------------
1942 -- 9.7.4 Abortable Part --
1943 ---------------------------
1944
1945 -- ABORTABLE_PART ::= SEQUENCE_OF_STATEMENTS
1946
1947 -- The caller has verified that THEN ABORT is present, and Token is
1948 -- pointing to the ABORT on entry (or if not, then we have an error)
1949
1950 -- Error recovery: cannot raise Error_Resync
1951
1952 function P_Abortable_Part return Node_Id is
1953 Abortable_Part_Node : Node_Id;
1954
1955 begin
1956 Abortable_Part_Node := New_Node (N_Abortable_Part, Token_Ptr);
1957 T_Abort; -- scan past ABORT
1958
1959 if Ada_Version = Ada_83 then
1960 Error_Msg_SP ("(Ada 83) asynchronous select not allowed!");
1961 end if;
1962
1963 Set_Statements (Abortable_Part_Node, P_Sequence_Of_Statements (SS_Sreq));
1964 return Abortable_Part_Node;
1965 end P_Abortable_Part;
1966
1967 --------------------------
1968 -- 9.8 Abort Statement --
1969 --------------------------
1970
1971 -- ABORT_STATEMENT ::= abort task_NAME {, task_NAME};
1972
1973 -- The caller has checked that the initial token is ABORT
1974
1975 -- Error recovery: cannot raise Error_Resync
1976
1977 function P_Abort_Statement return Node_Id is
1978 Abort_Node : Node_Id;
1979
1980 begin
1981 Abort_Node := New_Node (N_Abort_Statement, Token_Ptr);
1982 Scan; -- past ABORT
1983 Set_Names (Abort_Node, New_List);
1984
1985 loop
1986 Append (P_Name, Names (Abort_Node));
1987 exit when Token /= Tok_Comma;
1988 Scan; -- past comma
1989 end loop;
1990
1991 TF_Semicolon;
1992 return Abort_Node;
1993 end P_Abort_Statement;
1994
1995 end Ch9;